mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-14 20:59:39 +02:00
Ignore GNU_DUMMY_S2K
This commit is contained in:
parent
ec653150f8
commit
3c32bf607b
3 changed files with 35 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2021 Paul Schaub.
|
* Copyright 2021 Paul Schaub.
|
||||||
|
* Copyright 2021 Flowcrypt a.s.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -62,6 +63,16 @@ public class KeyInfo {
|
||||||
return secretKey == null || isDecrypted(secretKey);
|
return secretKey == null || isDecrypted(secretKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns indication that a contained secret key has S2K of a type GNU_DUMMY_S2K.
|
||||||
|
*
|
||||||
|
* @return true if secret key has S2K of a type GNU_DUMMY_S2K, false if there is public key only,
|
||||||
|
* or S2K on the secret key is absent or not of a type GNU_DUMMY_S2K.
|
||||||
|
*/
|
||||||
|
public boolean hasGnuDummyS2K() {
|
||||||
|
return secretKey != null && hasGnuDummyS2K(secretKey);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getCurveName(PGPPublicKey publicKey) {
|
public static String getCurveName(PGPPublicKey publicKey) {
|
||||||
PublicKeyAlgorithm algorithm = PublicKeyAlgorithm.fromId(publicKey.getAlgorithm());
|
PublicKeyAlgorithm algorithm = PublicKeyAlgorithm.fromId(publicKey.getAlgorithm());
|
||||||
ECPublicBCPGKey key;
|
ECPublicBCPGKey key;
|
||||||
|
@ -95,7 +106,7 @@ public class KeyInfo {
|
||||||
* @return true if secret key is encrypted, false otherwise.
|
* @return true if secret key is encrypted, false otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isEncrypted(PGPSecretKey secretKey) {
|
public static boolean isEncrypted(PGPSecretKey secretKey) {
|
||||||
return secretKey.getS2KUsage() != 0 && secretKey.getS2K().getType() != S2K.GNU_DUMMY_S2K;
|
return secretKey.getS2KUsage() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,6 +116,17 @@ public class KeyInfo {
|
||||||
* @return true if secret key is encrypted, false otherwise.
|
* @return true if secret key is encrypted, false otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isDecrypted(PGPSecretKey secretKey) {
|
public static boolean isDecrypted(PGPSecretKey secretKey) {
|
||||||
return secretKey.getS2KUsage() == 0 || secretKey.getS2K().getType() == S2K.GNU_DUMMY_S2K;
|
return secretKey.getS2KUsage() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns indication that a secret key has S2K of a type GNU_DUMMY_S2K.
|
||||||
|
*
|
||||||
|
* @param secretKey A secret key to examine.
|
||||||
|
* @return true if secret key has S2K of a type GNU_DUMMY_S2K, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean hasGnuDummyS2K(PGPSecretKey secretKey) {
|
||||||
|
final S2K s2k = secretKey.getS2K();
|
||||||
|
return s2k != null && s2k.getType() == S2K.GNU_DUMMY_S2K;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2020 Paul Schaub.
|
* Copyright 2020 Paul Schaub.
|
||||||
|
* Copyright 2021 Flowcrypt a.s.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -297,16 +298,17 @@ public class KeyRingInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true when every secret key on the key ring is not encrypted.
|
* Returns true when every secret key on the key ring is not encrypted.
|
||||||
* If there is at least one encrypted secret key on the ring, return false.
|
* If there is at least one encrypted secret key on the key ring, returns false.
|
||||||
* If the ring is a {@link PGPPublicKeyRing}, return true.
|
* If the key ring is a {@link PGPPublicKeyRing}, returns true.
|
||||||
|
* Sub-keys with S2K of a type GNU_DUMMY_S2K do not affect the result.
|
||||||
*
|
*
|
||||||
* @return true if all secret keys are unencrypted.
|
* @return true if all secret keys are unencrypted.
|
||||||
*/
|
*/
|
||||||
public boolean isFullyDecrypted() {
|
public boolean isFullyDecrypted() {
|
||||||
if (isSecretKey()) {
|
if (isSecretKey()) {
|
||||||
for (PGPSecretKey secretKey : getSecretKeys()) {
|
for (PGPSecretKey secretKey : getSecretKeys()) {
|
||||||
if (KeyInfo.isEncrypted(secretKey)) {
|
if (!KeyInfo.hasGnuDummyS2K(secretKey) && KeyInfo.isEncrypted(secretKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,15 +318,16 @@ public class KeyRingInfo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true when every secret key on the key ring is encrypted.
|
* Returns true when every secret key on the key ring is encrypted.
|
||||||
* If there is at least one not encrypted secret key on the ring, return false.
|
* If there is at least one not encrypted secret key on the key ring, returns false.
|
||||||
* If the ring is a {@link PGPPublicKeyRing}, return false.
|
* If the key ring is a {@link PGPPublicKeyRing}, returns false.
|
||||||
|
* Sub-keys with S2K of a type GNU_DUMMY_S2K do not affect a result.
|
||||||
*
|
*
|
||||||
* @return true if all secret keys are encrypted.
|
* @return true if all secret keys are encrypted.
|
||||||
*/
|
*/
|
||||||
public boolean isFullyEncrypted() {
|
public boolean isFullyEncrypted() {
|
||||||
if (isSecretKey()) {
|
if (isSecretKey()) {
|
||||||
for (PGPSecretKey secretKey : getSecretKeys()) {
|
for (PGPSecretKey secretKey : getSecretKeys()) {
|
||||||
if (KeyInfo.isDecrypted(secretKey)) {
|
if (!KeyInfo.hasGnuDummyS2K(secretKey) && KeyInfo.isDecrypted(secretKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2020 Paul Schaub.
|
* Copyright 2020 Paul Schaub.
|
||||||
|
* Copyright 2021 Flowcrypt a.s.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue