1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 14:22:05 +01:00

Implement revoking subkeys for key-ids as well

This commit is contained in:
Paul Schaub 2020-11-13 16:59:55 +01:00
parent 34d256d34e
commit 4dd2b2f71a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 15 additions and 14 deletions

View file

@ -59,7 +59,6 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.protection.passphrase_provider.SolitaryPassphraseProvider;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.key.util.SignatureUtils;
import org.pgpainless.util.NotYetImplementedException;
import org.pgpainless.util.Passphrase;
public class KeyRingEditor implements KeyRingEditorInterface {
@ -258,15 +257,24 @@ public class KeyRingEditor implements KeyRingEditorInterface {
@Override
public KeyRingEditorInterface revokeSubKey(OpenPgpV4Fingerprint fingerprint, SecretKeyRingProtector protector)
throws PGPException {
PGPSecretKey primaryKey = secretKeyRing.getSecretKey();
PGPPrivateKey privateKey = primaryKey.extractPrivateKey(protector.getDecryptor(primaryKey.getKeyID()));
PGPPublicKey revokeeSubKey = secretKeyRing.getPublicKey(fingerprint.getKeyId());
if (revokeeSubKey == null) {
throw new NoSuchElementException("No subkey with fingerprint " + fingerprint + " found.");
return revokeSubKey(fingerprint.getKeyId(), protector);
}
@Override
public KeyRingEditorInterface revokeSubKey(long subKeyId, SecretKeyRingProtector protector) throws PGPException {
PGPPublicKey revokeeSubKey = secretKeyRing.getPublicKey(subKeyId);
if (revokeeSubKey == null) {
throw new NoSuchElementException("No subkey with id " + Long.toHexString(subKeyId) + " found.");
}
secretKeyRing = revokeSubKey(protector, revokeeSubKey);
return this;
}
private PGPSecretKeyRing revokeSubKey(SecretKeyRingProtector protector, PGPPublicKey revokeeSubKey) throws PGPException {
PGPSecretKey primaryKey = secretKeyRing.getSecretKey();
PGPSignatureGenerator signatureGenerator = SignatureUtils.getSignatureGeneratorFor(primaryKey);
PGPPrivateKey privateKey = primaryKey.extractPrivateKey(protector.getDecryptor(primaryKey.getKeyID()));
signatureGenerator.init(SignatureType.SUBKEY_REVOCATION.getCode(), privateKey);
// Generate revocation
@ -276,14 +284,7 @@ public class KeyRingEditor implements KeyRingEditorInterface {
// Inject revoked public key into key ring
PGPPublicKeyRing publicKeyRing = KeyRingUtils.publicKeyRingFrom(secretKeyRing);
publicKeyRing = PGPPublicKeyRing.insertPublicKey(publicKeyRing, revokeeSubKey);
secretKeyRing = PGPSecretKeyRing.replacePublicKeys(secretKeyRing, publicKeyRing);
return this;
}
@Override
public KeyRingEditorInterface revokeSubKey(long subKeyId, SecretKeyRingProtector protector) {
throw new NotYetImplementedException();
return PGPSecretKeyRing.replacePublicKeys(secretKeyRing, publicKeyRing);
}
@Override

View file

@ -125,7 +125,7 @@ public interface KeyRingEditorInterface {
* @param subKeyId id of the subkey
* @return the builder
*/
KeyRingEditorInterface revokeSubKey(long subKeyId, SecretKeyRingProtector secretKeyRingProtector);
KeyRingEditorInterface revokeSubKey(long subKeyId, SecretKeyRingProtector secretKeyRingProtector) throws PGPException;
/**
* Change the passphrase of the whole key ring.