aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-09-24 01:37:28 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-09-24 01:37:28 +0200
commitd588b13255a7b7391c5f782a464c44bee4a3391b (patch)
tree90d917ea9270fa53232498eb734be2eb14841825 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
parent07e8729abf448bc47589dc34cd0591bec489d161 (diff)
downloadopen-keychain-d588b13255a7b7391c5f782a464c44bee4a3391b.tar.gz
open-keychain-d588b13255a7b7391c5f782a464c44bee4a3391b.tar.bz2
open-keychain-d588b13255a7b7391c5f782a464c44bee4a3391b.zip
fix signatures produced by yubikey
The timestamp was only set on a second run. This led to a race condition whether the signature could be completed within the same timestamp. Fixes #834
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java27
1 files changed, 15 insertions, 12 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
index 4106ab73d..697808d2f 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java
@@ -199,14 +199,6 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
private PGPContentSignerBuilder getContentSignerBuilder(int hashAlgo, byte[] nfcSignedHash,
Date nfcCreationTimestamp) {
if (mPrivateKeyState == PRIVATE_KEY_STATE_DIVERT_TO_CARD) {
- // to sign using nfc PgpSignEncrypt is executed two times.
- // the first time it stops to return the PendingIntent for nfc connection and signing the hash
- // the second time the signed hash is used.
- // to get the same hash we cache the timestamp for the second round!
- if (nfcCreationTimestamp == null) {
- nfcCreationTimestamp = new Date();
- }
-
// use synchronous "NFC based" SignerBuilder
return new NfcSyncPGPContentSignerBuilder(
mSecretKey.getPublicKey().getAlgorithm(), hashAlgo,
@@ -226,6 +218,20 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) {
throw new PrivateKeyNotUnlockedException();
}
+ if (nfcSignedHash != null && nfcCreationTimestamp == null) {
+ throw new PgpGeneralException("Got nfc hash without timestamp!!");
+ }
+
+ // We explicitly create a signature creation timestamp in this place.
+ // That way, we can inject an artificial one from outside, ie the one
+ // used in previous runs of this function.
+ if (nfcCreationTimestamp == null) {
+ // to sign using nfc PgpSignEncrypt is executed two times.
+ // the first time it stops to return the PendingIntent for nfc connection and signing the hash
+ // the second time the signed hash is used.
+ // to get the same hash we cache the timestamp for the second round!
+ nfcCreationTimestamp = new Date();
+ }
PGPContentSignerBuilder contentSignerBuilder = getContentSignerBuilder(hashAlgo,
nfcSignedHash, nfcCreationTimestamp);
@@ -244,10 +250,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
spGen.setSignerUserID(false, mRing.getPrimaryUserIdWithFallback());
- if (nfcCreationTimestamp != null) {
- spGen.setSignatureCreationTime(false, nfcCreationTimestamp);
- Log.d(Constants.TAG, "For NFC: set sig creation time to " + nfcCreationTimestamp);
- }
+ spGen.setSignatureCreationTime(false, nfcCreationTimestamp);
signatureGenerator.setHashedSubpackets(spGen.generate());
return signatureGenerator;
} catch (PGPException e) {