mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-04 19:45:59 +01:00
More progress!
This commit is contained in:
parent
8c49d37e1f
commit
44169ecf64
5 changed files with 117 additions and 16 deletions
|
@ -15,27 +15,37 @@ import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||||
import org.pgpainless.algorithm.SignatureType;
|
import org.pgpainless.algorithm.SignatureType;
|
||||||
import org.pgpainless.exception.WrongPassphraseException;
|
import org.pgpainless.exception.WrongPassphraseException;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.signature.subpackets.SelfSignatureSubpackets;
|
import org.pgpainless.signature.subpackets.CertificationSubpackets;
|
||||||
|
|
||||||
public class CertificationSignatureBuilder extends AbstractSignatureBuilder<CertificationSignatureBuilder> {
|
public class CertificationSignatureBuilder extends AbstractSignatureBuilder<CertificationSignatureBuilder> {
|
||||||
|
|
||||||
public CertificationSignatureBuilder(PGPSecretKey certificationKey, SecretKeyRingProtector protector) throws WrongPassphraseException {
|
public CertificationSignatureBuilder(PGPSecretKey certificationKey, SecretKeyRingProtector protector)
|
||||||
super(SignatureType.GENERIC_CERTIFICATION, certificationKey, protector);
|
throws WrongPassphraseException {
|
||||||
|
this(SignatureType.GENERIC_CERTIFICATION, certificationKey, protector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CertificationSignatureBuilder(PGPSecretKey certificationKey, SecretKeyRingProtector protector, PGPSignature archetypeSignature) throws WrongPassphraseException {
|
public CertificationSignatureBuilder(SignatureType signatureType, PGPSecretKey signingKey, SecretKeyRingProtector protector)
|
||||||
|
throws WrongPassphraseException {
|
||||||
|
super(signatureType, signingKey, protector);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CertificationSignatureBuilder(
|
||||||
|
PGPSecretKey certificationKey,
|
||||||
|
SecretKeyRingProtector protector,
|
||||||
|
PGPSignature archetypeSignature)
|
||||||
|
throws WrongPassphraseException {
|
||||||
super(certificationKey, protector, archetypeSignature);
|
super(certificationKey, protector, archetypeSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelfSignatureSubpackets getHashedSubpackets() {
|
public CertificationSubpackets getHashedSubpackets() {
|
||||||
return hashedSubpackets;
|
return hashedSubpackets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelfSignatureSubpackets getUnhashedSubpackets() {
|
public CertificationSubpackets getUnhashedSubpackets() {
|
||||||
return unhashedSubpackets;
|
return unhashedSubpackets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyCallback(@Nullable SelfSignatureSubpackets.Callback callback) {
|
public void applyCallback(@Nullable CertificationSubpackets.Callback callback) {
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.modifyHashedSubpackets(getHashedSubpackets());
|
callback.modifyHashedSubpackets(getHashedSubpackets());
|
||||||
callback.modifyUnhashedSubpackets(getUnhashedSubpackets());
|
callback.modifyUnhashedSubpackets(getUnhashedSubpackets());
|
||||||
|
@ -46,7 +56,8 @@ public class CertificationSignatureBuilder extends AbstractSignatureBuilder<Cert
|
||||||
return buildAndInitSignatureGenerator().generateCertification(userId, certifiedKey);
|
return buildAndInitSignatureGenerator().generateCertification(userId, certifiedKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PGPSignature build(PGPPublicKey certifiedKey, PGPUserAttributeSubpacketVector userAttribute) throws PGPException {
|
public PGPSignature build(PGPPublicKey certifiedKey, PGPUserAttributeSubpacketVector userAttribute)
|
||||||
|
throws PGPException {
|
||||||
return buildAndInitSignatureGenerator().generateCertification(userAttribute, certifiedKey);
|
return buildAndInitSignatureGenerator().generateCertification(userAttribute, certifiedKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package org.pgpainless.signature.builder;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
|
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||||
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||||
|
import org.pgpainless.algorithm.SignatureType;
|
||||||
|
import org.pgpainless.exception.WrongPassphraseException;
|
||||||
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
|
import org.pgpainless.signature.subpackets.SelfSignatureSubpackets;
|
||||||
|
|
||||||
|
public class SelfSignatureBuilder extends AbstractSignatureBuilder<SelfSignatureBuilder> {
|
||||||
|
|
||||||
|
public SelfSignatureBuilder(PGPSecretKey signingKey, SecretKeyRingProtector protector) throws WrongPassphraseException {
|
||||||
|
this(SignatureType.GENERIC_CERTIFICATION, signingKey, protector);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelfSignatureBuilder(SignatureType signatureType, PGPSecretKey signingKey, SecretKeyRingProtector protector)
|
||||||
|
throws WrongPassphraseException {
|
||||||
|
super(signatureType, signingKey, protector);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelfSignatureBuilder(
|
||||||
|
PGPSecretKey primaryKey,
|
||||||
|
SecretKeyRingProtector primaryKeyProtector,
|
||||||
|
PGPSignature oldCertification)
|
||||||
|
throws WrongPassphraseException {
|
||||||
|
super(primaryKey, primaryKeyProtector, oldCertification);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelfSignatureSubpackets getHashedSubpackets() {
|
||||||
|
return hashedSubpackets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelfSignatureSubpackets getUnhashedSubpackets() {
|
||||||
|
return unhashedSubpackets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyCallback(@Nullable SelfSignatureSubpackets.Callback callback) {
|
||||||
|
if (callback != null) {
|
||||||
|
callback.modifyHashedSubpackets(getHashedSubpackets());
|
||||||
|
callback.modifyUnhashedSubpackets(getUnhashedSubpackets());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PGPSignature build(PGPPublicKey certifiedKey, String userId) throws PGPException {
|
||||||
|
return buildAndInitSignatureGenerator().generateCertification(userId, certifiedKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PGPSignature build(PGPPublicKey certifiedKey, PGPUserAttributeSubpacketVector userAttribute)
|
||||||
|
throws PGPException {
|
||||||
|
return buildAndInitSignatureGenerator().generateCertification(userAttribute, certifiedKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isValidSignatureType(SignatureType type) {
|
||||||
|
switch (type) {
|
||||||
|
case GENERIC_CERTIFICATION:
|
||||||
|
case NO_CERTIFICATION:
|
||||||
|
case CASUAL_CERTIFICATION:
|
||||||
|
case POSITIVE_CERTIFICATION:
|
||||||
|
case DIRECT_KEY:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import org.pgpainless.algorithm.SignatureType;
|
||||||
import org.pgpainless.exception.WrongPassphraseException;
|
import org.pgpainless.exception.WrongPassphraseException;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.signature.subpackets.BaseSignatureSubpackets;
|
import org.pgpainless.signature.subpackets.BaseSignatureSubpackets;
|
||||||
|
import org.pgpainless.signature.subpackets.CertificationSubpackets;
|
||||||
import org.pgpainless.signature.subpackets.SelfSignatureSubpackets;
|
import org.pgpainless.signature.subpackets.SelfSignatureSubpackets;
|
||||||
|
|
||||||
public final class SignatureFactory {
|
public final class SignatureFactory {
|
||||||
|
@ -29,8 +30,8 @@ public final class SignatureFactory {
|
||||||
@Nullable SelfSignatureSubpackets.Callback subkeyBindingSubpacketsCallback,
|
@Nullable SelfSignatureSubpackets.Callback subkeyBindingSubpacketsCallback,
|
||||||
KeyFlag... flags) throws WrongPassphraseException {
|
KeyFlag... flags) throws WrongPassphraseException {
|
||||||
if (hasSignDataFlag(flags)) {
|
if (hasSignDataFlag(flags)) {
|
||||||
throw new IllegalArgumentException("Binding a subkey with SIGN_DATA flag requires primary key backsig." +
|
throw new IllegalArgumentException("Binding a subkey with SIGN_DATA flag requires primary key backsig.\n" +
|
||||||
"Please use the method bindSigningSubkey().");
|
"Please use the method bindSigningSubkey() instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return bindSubkey(primaryKey, primaryKeyProtector, subkeyBindingSubpacketsCallback, flags);
|
return bindSubkey(primaryKey, primaryKeyProtector, subkeyBindingSubpacketsCallback, flags);
|
||||||
|
@ -85,25 +86,26 @@ public final class SignatureFactory {
|
||||||
return primaryKeyBinder;
|
return primaryKeyBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CertificationSignatureBuilder selfCertifyUserId(
|
public static SelfSignatureBuilder selfCertifyUserId(
|
||||||
PGPSecretKey primaryKey,
|
PGPSecretKey primaryKey,
|
||||||
SecretKeyRingProtector primaryKeyProtector,
|
SecretKeyRingProtector primaryKeyProtector,
|
||||||
@Nullable SelfSignatureSubpackets.Callback selfSignatureCallback,
|
@Nullable SelfSignatureSubpackets.Callback selfSignatureCallback,
|
||||||
KeyFlag... flags) throws WrongPassphraseException {
|
KeyFlag... flags) throws WrongPassphraseException {
|
||||||
|
|
||||||
CertificationSignatureBuilder certifier = new CertificationSignatureBuilder(primaryKey, primaryKeyProtector);
|
SelfSignatureBuilder certifier = new SelfSignatureBuilder(SignatureType.POSITIVE_CERTIFICATION, primaryKey, primaryKeyProtector);
|
||||||
certifier.getHashedSubpackets().setKeyFlags(flags);
|
certifier.getHashedSubpackets().setKeyFlags(flags);
|
||||||
|
|
||||||
certifier.applyCallback(selfSignatureCallback);
|
certifier.applyCallback(selfSignatureCallback);
|
||||||
|
|
||||||
return certifier;
|
return certifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CertificationSignatureBuilder renewSelfCertification(
|
public static SelfSignatureBuilder renewSelfCertification(
|
||||||
PGPSecretKey primaryKey,
|
PGPSecretKey primaryKey,
|
||||||
SecretKeyRingProtector primaryKeyProtector,
|
SecretKeyRingProtector primaryKeyProtector,
|
||||||
@Nullable SelfSignatureSubpackets.Callback selfSignatureCallback,
|
@Nullable SelfSignatureSubpackets.Callback selfSignatureCallback,
|
||||||
PGPSignature oldCertification) throws WrongPassphraseException {
|
PGPSignature oldCertification) throws WrongPassphraseException {
|
||||||
CertificationSignatureBuilder certifier = new CertificationSignatureBuilder(
|
SelfSignatureBuilder certifier = new SelfSignatureBuilder(
|
||||||
primaryKey, primaryKeyProtector, oldCertification);
|
primaryKey, primaryKeyProtector, oldCertification);
|
||||||
|
|
||||||
certifier.applyCallback(selfSignatureCallback);
|
certifier.applyCallback(selfSignatureCallback);
|
||||||
|
@ -111,6 +113,18 @@ public final class SignatureFactory {
|
||||||
return certifier;
|
return certifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CertificationSignatureBuilder certifyUserId(
|
||||||
|
PGPSecretKey signingKey,
|
||||||
|
SecretKeyRingProtector signingKeyProtector,
|
||||||
|
@Nullable CertificationSubpackets.Callback subpacketsCallback)
|
||||||
|
throws WrongPassphraseException {
|
||||||
|
CertificationSignatureBuilder certifier = new CertificationSignatureBuilder(signingKey, signingKeyProtector);
|
||||||
|
|
||||||
|
certifier.applyCallback(subpacketsCallback);
|
||||||
|
|
||||||
|
return certifier;
|
||||||
|
}
|
||||||
|
|
||||||
public static UniversalSignatureBuilder universalSignature(
|
public static UniversalSignatureBuilder universalSignature(
|
||||||
SignatureType signatureType,
|
SignatureType signatureType,
|
||||||
PGPSecretKey signingKey,
|
PGPSecretKey signingKey,
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.pgpainless.key.info.KeyRingInfo;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.signature.builder.CertificationSignatureBuilder;
|
import org.pgpainless.signature.builder.CertificationSignatureBuilder;
|
||||||
import org.pgpainless.signature.builder.DirectKeySignatureBuilder;
|
import org.pgpainless.signature.builder.DirectKeySignatureBuilder;
|
||||||
|
import org.pgpainless.signature.builder.SelfSignatureBuilder;
|
||||||
|
|
||||||
public class ProofUtil {
|
public class ProofUtil {
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ public class ProofUtil {
|
||||||
throw new NoSuchElementException("No previous valid user-id certification found.");
|
throw new NoSuchElementException("No previous valid user-id certification found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
CertificationSignatureBuilder sigBuilder = new CertificationSignatureBuilder(certificationKey, protector, previousCertification);
|
SelfSignatureBuilder sigBuilder = new SelfSignatureBuilder(certificationKey, protector, previousCertification);
|
||||||
for (Proof proof : proofs) {
|
for (Proof proof : proofs) {
|
||||||
sigBuilder.getHashedSubpackets().addNotationData(false, proof.getNotationName(), proof.getNotationValue());
|
sigBuilder.getHashedSubpackets().addNotationData(false, proof.getNotationName(), proof.getNotationValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||||
import org.pgpainless.key.util.RevocationAttributes;
|
import org.pgpainless.key.util.RevocationAttributes;
|
||||||
|
|
||||||
public class SignatureSubpacketGeneratorWrapper
|
public class SignatureSubpacketGeneratorWrapper
|
||||||
implements BaseSignatureSubpackets, SelfSignatureSubpackets, RevocationSignatureSubpackets {
|
implements BaseSignatureSubpackets, SelfSignatureSubpackets, CertificationSubpackets, RevocationSignatureSubpackets {
|
||||||
|
|
||||||
private SignatureCreationTime signatureCreationTime;
|
private SignatureCreationTime signatureCreationTime;
|
||||||
private SignatureExpirationTime signatureExpirationTime;
|
private SignatureExpirationTime signatureExpirationTime;
|
||||||
|
|
Loading…
Reference in a new issue