mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-10 11:05:06 -05:00
parent
86d9266a44
commit
8714f56cdc
@ -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()
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user