Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement OpenPGP Signature generation using PGPainless #48

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.nio.ByteBuffer;
import java.util.Objects;

import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.eclipse.packager.rpm.RpmSignatureTag;
import org.eclipse.packager.rpm.header.Header;
import org.pgpainless.PGPainless;
Expand All @@ -43,6 +45,8 @@ public class PgpHeaderSignatureProcessor implements SignatureProcessor {

private final long keyId;

private PGPSignature signature;

private byte[] value;

public PgpHeaderSignatureProcessor(final PGPSecretKeyRing secretKeys,
Expand Down Expand Up @@ -91,7 +95,8 @@ public void write(int i) throws IOException {
signingStream.close();
EncryptionResult result = signingStream.getResult();

this.value = result.getDetachedSignatures().flatten().iterator().next().getEncoded();
this.signature = result.getDetachedSignatures().flatten().iterator().next();
this.value = signature.getEncoded();
logger.info("RSA HEADER: {}", this.value);
} catch (final Exception e) {
throw new RuntimeException(e);
Expand All @@ -105,6 +110,24 @@ public void feedPayloadData(final ByteBuffer data) {

@Override
public void finish(final Header<RpmSignatureTag> signature) {
signature.putBlob(RpmSignatureTag.RSAHEADER, this.value);
switch (this.signature.getKeyAlgorithm()) {
// RSA
case PublicKeyAlgorithmTags.RSA_GENERAL:
case PublicKeyAlgorithmTags.RSA_ENCRYPT:
case PublicKeyAlgorithmTags.RSA_SIGN:
signature.putBlob(RpmSignatureTag.RSAHEADER, this.value);
vanitasvitae marked this conversation as resolved.
Show resolved Hide resolved
break;

// DSA
case PublicKeyAlgorithmTags.DSA:
case PublicKeyAlgorithmTags.ECDSA:
case PublicKeyAlgorithmTags.EDDSA_LEGACY:
vanitasvitae marked this conversation as resolved.
Show resolved Hide resolved
signature.putBlob(RpmSignatureTag.DSAHEADER, this.value);
break;

default:
throw new RuntimeException("Unsupported public key algorithm id: " + this.signature.getKeyAlgorithm());
}

}
}