mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 04:22:18 -05:00
improve robustness of SecretKeyType handling
This commit is contained in:
parent
c8f788b925
commit
c4d392051c
@ -123,9 +123,10 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SecretKeyType getSecretKeyType() {
|
public SecretKeyType getSecretKeyType() {
|
||||||
if (mSecretKey.getS2K() != null && mSecretKey.getS2K().getType() == S2K.GNU_DUMMY_S2K) {
|
S2K s2k = mSecretKey.getS2K();
|
||||||
|
if (s2k != null && s2k.getType() == S2K.GNU_DUMMY_S2K) {
|
||||||
// divert to card is special
|
// divert to card is special
|
||||||
if (mSecretKey.getS2K().getProtectionMode() == S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD) {
|
if (s2k.getProtectionMode() == S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD) {
|
||||||
return SecretKeyType.DIVERT_TO_CARD;
|
return SecretKeyType.DIVERT_TO_CARD;
|
||||||
}
|
}
|
||||||
// no matter the exact protection mode, it's some kind of dummy key
|
// no matter the exact protection mode, it's some kind of dummy key
|
||||||
@ -156,9 +157,10 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
|||||||
*/
|
*/
|
||||||
public boolean unlock(Passphrase passphrase) throws PgpGeneralException {
|
public boolean unlock(Passphrase passphrase) throws PgpGeneralException {
|
||||||
// handle keys on OpenPGP cards like they were unlocked
|
// handle keys on OpenPGP cards like they were unlocked
|
||||||
if (mSecretKey.getS2K() != null
|
S2K s2k = mSecretKey.getS2K();
|
||||||
&& mSecretKey.getS2K().getType() == S2K.GNU_DUMMY_S2K
|
if (s2k != null
|
||||||
&& mSecretKey.getS2K().getProtectionMode() == S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD) {
|
&& s2k.getType() == S2K.GNU_DUMMY_S2K
|
||||||
|
&& s2k.getProtectionMode() == S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD) {
|
||||||
mPrivateKeyState = PRIVATE_KEY_STATE_DIVERT_TO_CARD;
|
mPrivateKeyState = PRIVATE_KEY_STATE_DIVERT_TO_CARD;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1478,13 +1478,13 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
private static boolean isDummy(PGPSecretKey secretKey) {
|
private static boolean isDummy(PGPSecretKey secretKey) {
|
||||||
S2K s2k = secretKey.getS2K();
|
S2K s2k = secretKey.getS2K();
|
||||||
return s2k.getType() == S2K.GNU_DUMMY_S2K
|
return s2k != null && s2k.getType() == S2K.GNU_DUMMY_S2K
|
||||||
&& s2k.getProtectionMode() == S2K.GNU_PROTECTION_MODE_NO_PRIVATE_KEY;
|
&& s2k.getProtectionMode() != S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isDivertToCard(PGPSecretKey secretKey) {
|
private static boolean isDivertToCard(PGPSecretKey secretKey) {
|
||||||
S2K s2k = secretKey.getS2K();
|
S2K s2k = secretKey.getS2K();
|
||||||
return s2k.getType() == S2K.GNU_DUMMY_S2K
|
return s2k != null && s2k.getType() == S2K.GNU_DUMMY_S2K
|
||||||
&& s2k.getProtectionMode() == S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD;
|
&& s2k.getProtectionMode() == S2K.GNU_PROTECTION_MODE_DIVERT_TO_CARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,7 +831,7 @@ public class ProviderHelper {
|
|||||||
mIndent -= 1;
|
mIndent -= 1;
|
||||||
|
|
||||||
// this implicitly leaves all keys which were not in the secret key ring
|
// this implicitly leaves all keys which were not in the secret key ring
|
||||||
// with has_secret = 0
|
// with has_secret = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
log(LogType.MSG_IS_SUCCESS);
|
log(LogType.MSG_IS_SUCCESS);
|
||||||
|
Loading…
Reference in New Issue
Block a user