mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
parent
86d9266a44
commit
8714f56cdc
@ -620,12 +620,19 @@ public class PgpDecryptVerify {
|
|||||||
// go through all signatures
|
// go through all signatures
|
||||||
// and find out for which signature we have a key in our database
|
// and find out for which signature we have a key in our database
|
||||||
Long masterKeyId = null;
|
Long masterKeyId = null;
|
||||||
|
String primaryUserId = null;
|
||||||
int signatureIndex = 0;
|
int signatureIndex = 0;
|
||||||
for (int i = 0; i < sigList.size(); ++i) {
|
for (int i = 0; i < sigList.size(); ++i) {
|
||||||
try {
|
try {
|
||||||
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(
|
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(
|
||||||
Long.toString(sigList.get(i).getKeyID()));
|
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;
|
signatureIndex = i;
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
Log.d(Constants.TAG, "key not found!");
|
Log.d(Constants.TAG, "key not found!");
|
||||||
@ -652,9 +659,8 @@ public class PgpDecryptVerify {
|
|||||||
|
|
||||||
signatureResultBuilder.signatureAvailable(true);
|
signatureResultBuilder.signatureAvailable(true);
|
||||||
signatureResultBuilder.knownKey(true);
|
signatureResultBuilder.knownKey(true);
|
||||||
// TODO: uses the first user id not primary user id
|
signatureResultBuilder.userId(primaryUserId);
|
||||||
signatureResultBuilder.userId(PgpKeyHelper.getMainUserId(publicKeyRing.getPublicKey()));
|
signatureResultBuilder.keyId(masterKeyId);
|
||||||
signatureResultBuilder.keyId(publicKeyRing.getPublicKey().getKeyID());
|
|
||||||
|
|
||||||
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
|
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
|
||||||
new JcaPGPContentVerifierBuilderProvider()
|
new JcaPGPContentVerifierBuilderProvider()
|
||||||
|
@ -225,30 +225,6 @@ public class PgpKeyHelper {
|
|||||||
return signingKeys.get(0);
|
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) {
|
public static int getKeyUsage(PGPSecretKey key) {
|
||||||
return getKeyUsage(key.getPublicKey());
|
return getKeyUsage(key.getPublicKey());
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
|
|||||||
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
|
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.util.InputData;
|
import org.sufficientlysecure.keychain.util.InputData;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -281,9 +282,12 @@ public class PgpSignEncrypt {
|
|||||||
PGPSecretKey signingKey = null;
|
PGPSecretKey signingKey = null;
|
||||||
PGPSecretKeyRing signingKeyRing = null;
|
PGPSecretKeyRing signingKeyRing = null;
|
||||||
PGPPrivateKey signaturePrivateKey = null;
|
PGPPrivateKey signaturePrivateKey = null;
|
||||||
|
String signingUserId = null;
|
||||||
if (enableSignature) {
|
if (enableSignature) {
|
||||||
try {
|
try {
|
||||||
signingKeyRing = mProviderHelper.getPGPSecretKeyRing(mSignatureMasterKeyId);
|
signingKeyRing = mProviderHelper.getPGPSecretKeyRing(mSignatureMasterKeyId);
|
||||||
|
signingUserId = (String) mProviderHelper.getUnifiedData(mSignatureMasterKeyId,
|
||||||
|
KeychainContract.KeyRings.USER_ID, ProviderHelper.FIELD_TYPE_STRING);
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
throw new NoSigningKeyException();
|
throw new NoSigningKeyException();
|
||||||
}
|
}
|
||||||
@ -369,9 +373,8 @@ public class PgpSignEncrypt {
|
|||||||
signatureGenerator = new PGPSignatureGenerator(contentSignerBuilder);
|
signatureGenerator = new PGPSignatureGenerator(contentSignerBuilder);
|
||||||
signatureGenerator.init(signatureType, signaturePrivateKey);
|
signatureGenerator.init(signatureType, signaturePrivateKey);
|
||||||
|
|
||||||
String userId = PgpKeyHelper.getMainUserId(signingKeyRing.getSecretKey());
|
|
||||||
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
|
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
|
||||||
spGen.setSignerUserID(false, userId);
|
spGen.setSignerUserID(false, signingUserId);
|
||||||
signatureGenerator.setHashedSubpackets(spGen.generate());
|
signatureGenerator.setHashedSubpackets(spGen.generate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -134,13 +135,17 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
alert.setTitle(R.string.title_authentication);
|
alert.setTitle(R.string.title_authentication);
|
||||||
|
|
||||||
final PGPSecretKey secretKey;
|
final PGPSecretKey secretKey;
|
||||||
|
final String userId;
|
||||||
|
|
||||||
if (secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none) {
|
if (secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none) {
|
||||||
secretKey = null;
|
secretKey = null;
|
||||||
alert.setMessage(R.string.passphrase_for_symmetric_encryption);
|
alert.setMessage(R.string.passphrase_for_symmetric_encryption);
|
||||||
} else {
|
} else {
|
||||||
try {
|
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) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
alert.setTitle(R.string.title_key_not_found);
|
alert.setTitle(R.string.title_key_not_found);
|
||||||
alert.setMessage(getString(R.string.key_not_found, secretKeyId));
|
alert.setMessage(getString(R.string.key_not_found, secretKeyId));
|
||||||
@ -154,8 +159,6 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
return alert.create();
|
return alert.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
String userId = PgpKeyHelper.getMainUserIdSafe(activity, secretKey);
|
|
||||||
|
|
||||||
Log.d(Constants.TAG, "User id: '" + userId + "'");
|
Log.d(Constants.TAG, "User id: '" + userId + "'");
|
||||||
alert.setMessage(getString(R.string.passphrase_for, userId));
|
alert.setMessage(getString(R.string.passphrase_for, userId));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user