diff options
4 files changed, 21 insertions, 33 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java index 96ab0404d..8d228ec96 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -620,12 +620,19 @@ public class PgpDecryptVerify { // go through all signatures // and find out for which signature we have a key in our database Long masterKeyId = null; + String primaryUserId = null; int signatureIndex = 0; for (int i = 0; i < sigList.size(); ++i) { try { Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri( Long.toString(sigList.get(i).getKeyID())); - masterKeyId = mProviderHelper.getMasterKeyId(uri); + Map<String, Object> data = mProviderHelper.getGenericData(uri, + new String[] { KeyRings.MASTER_KEY_ID, KeyRings.USER_ID }, + new int[] { ProviderHelper.FIELD_TYPE_INTEGER, + ProviderHelper.FIELD_TYPE_STRING } + ); + masterKeyId = (Long) data.get(KeyRings.MASTER_KEY_ID); + primaryUserId = (String) data.get(KeyRings.USER_ID); signatureIndex = i; } catch (ProviderHelper.NotFoundException e) { Log.d(Constants.TAG, "key not found!"); @@ -652,9 +659,8 @@ public class PgpDecryptVerify { signatureResultBuilder.signatureAvailable(true); signatureResultBuilder.knownKey(true); - // TODO: uses the first user id not primary user id - signatureResultBuilder.userId(PgpKeyHelper.getMainUserId(publicKeyRing.getPublicKey())); - signatureResultBuilder.keyId(publicKeyRing.getPublicKey().getKeyID()); + signatureResultBuilder.userId(primaryUserId); + signatureResultBuilder.keyId(masterKeyId); JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider() diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java index a467a4105..77a11165d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java @@ -225,30 +225,6 @@ public class PgpKeyHelper { return signingKeys.get(0); } - @SuppressWarnings("unchecked") - public static String getMainUserId(PGPPublicKey key) { - for (String userId : new IterableIterator<String>(key.getUserIDs())) { - return userId; - } - return null; - } - - @SuppressWarnings("unchecked") - public static String getMainUserId(PGPSecretKey key) { - for (String userId : new IterableIterator<String>(key.getUserIDs())) { - return userId; - } - return null; - } - - public static String getMainUserIdSafe(Context context, PGPSecretKey key) { - String userId = getMainUserId(key); - if (userId == null || userId.equals("")) { - userId = context.getString(R.string.user_id_no_name); - } - return userId; - } - public static int getKeyUsage(PGPSecretKey key) { return getKeyUsage(key.getPublicKey()); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index c61223fe2..2437cb0f0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -42,6 +42,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; @@ -281,9 +282,12 @@ public class PgpSignEncrypt { PGPSecretKey signingKey = null; PGPSecretKeyRing signingKeyRing = null; PGPPrivateKey signaturePrivateKey = null; + String signingUserId = null; if (enableSignature) { try { signingKeyRing = mProviderHelper.getPGPSecretKeyRing(mSignatureMasterKeyId); + signingUserId = (String) mProviderHelper.getUnifiedData(mSignatureMasterKeyId, + KeychainContract.KeyRings.USER_ID, ProviderHelper.FIELD_TYPE_STRING); } catch (ProviderHelper.NotFoundException e) { throw new NoSigningKeyException(); } @@ -369,9 +373,8 @@ public class PgpSignEncrypt { signatureGenerator = new PGPSignatureGenerator(contentSignerBuilder); signatureGenerator.init(signatureType, signaturePrivateKey); - String userId = PgpKeyHelper.getMainUserId(signingKeyRing.getSecretKey()); PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); - spGen.setSignerUserID(false, userId); + spGen.setSignerUserID(false, signingUserId); signatureGenerator.setHashedSubpackets(spGen.generate()); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 371673d90..9f18d26f0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -50,6 +50,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.util.Log; @@ -134,13 +135,17 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor alert.setTitle(R.string.title_authentication); final PGPSecretKey secretKey; + final String userId; if (secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none) { secretKey = null; alert.setMessage(R.string.passphrase_for_symmetric_encryption); } else { try { - secretKey = new ProviderHelper(activity).getPGPSecretKeyRing(secretKeyId).getSecretKey(); + ProviderHelper helper = new ProviderHelper(activity); + secretKey = helper.getPGPSecretKeyRing(secretKeyId).getSecretKey(); + userId = (String) helper.getUnifiedData(secretKeyId, + KeychainContract.KeyRings.USER_ID, ProviderHelper.FIELD_TYPE_STRING); } catch (ProviderHelper.NotFoundException e) { alert.setTitle(R.string.title_key_not_found); alert.setMessage(getString(R.string.key_not_found, secretKeyId)); @@ -154,8 +159,6 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor return alert.create(); } - String userId = PgpKeyHelper.getMainUserIdSafe(activity, secretKey); - Log.d(Constants.TAG, "User id: '" + userId + "'"); alert.setMessage(getString(R.string.passphrase_for, userId)); } |