mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 18:40:19 -05:00
Fallback if no primary user id exists
This commit is contained in:
parent
64b87f75be
commit
d3c54d5f12
@ -250,7 +250,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
|
|
||||||
mHashCode = key.hashCode();
|
mHashCode = key.hashCode();
|
||||||
|
|
||||||
mPrimaryUserId = key.getPrimaryUserId();
|
mPrimaryUserId = key.getPrimaryUserIdWithFallback();
|
||||||
mUserIds = key.getUnorderedUserIds();
|
mUserIds = key.getUnorderedUserIds();
|
||||||
|
|
||||||
// if there was no user id flagged as primary, use the first one
|
// if there was no user id flagged as primary, use the first one
|
||||||
|
@ -22,8 +22,10 @@ public abstract class KeyRing {
|
|||||||
|
|
||||||
abstract public String getPrimaryUserId() throws PgpGeneralException;
|
abstract public String getPrimaryUserId() throws PgpGeneralException;
|
||||||
|
|
||||||
public String[] getSplitPrimaryUserId() throws PgpGeneralException {
|
abstract public String getPrimaryUserIdWithFallback() throws PgpGeneralException;
|
||||||
return splitUserId(getPrimaryUserId());
|
|
||||||
|
public String[] getSplitPrimaryUserIdWithFallback() throws PgpGeneralException {
|
||||||
|
return splitUserId(getPrimaryUserIdWithFallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public boolean isRevoked() throws PgpGeneralException;
|
abstract public boolean isRevoked() throws PgpGeneralException;
|
||||||
|
@ -409,7 +409,7 @@ public class PgpDecryptVerify {
|
|||||||
signatureResultBuilder.knownKey(true);
|
signatureResultBuilder.knownKey(true);
|
||||||
signatureResultBuilder.keyId(signingRing.getMasterKeyId());
|
signatureResultBuilder.keyId(signingRing.getMasterKeyId());
|
||||||
try {
|
try {
|
||||||
signatureResultBuilder.userId(signingRing.getPrimaryUserId());
|
signatureResultBuilder.userId(signingRing.getPrimaryUserIdWithFallback());
|
||||||
} catch(PgpGeneralException e) {
|
} catch(PgpGeneralException e) {
|
||||||
Log.d(Constants.TAG, "No primary user id in key " + signingRing.getMasterKeyId());
|
Log.d(Constants.TAG, "No primary user id in key " + signingRing.getMasterKeyId());
|
||||||
}
|
}
|
||||||
@ -596,7 +596,7 @@ public class PgpDecryptVerify {
|
|||||||
signatureResultBuilder.knownKey(true);
|
signatureResultBuilder.knownKey(true);
|
||||||
signatureResultBuilder.keyId(signingRing.getMasterKeyId());
|
signatureResultBuilder.keyId(signingRing.getMasterKeyId());
|
||||||
try {
|
try {
|
||||||
signatureResultBuilder.userId(signingRing.getPrimaryUserId());
|
signatureResultBuilder.userId(signingRing.getPrimaryUserIdWithFallback());
|
||||||
} catch(PgpGeneralException e) {
|
} catch(PgpGeneralException e) {
|
||||||
Log.d(Constants.TAG, "No primary user id in key " + signingRing.getMasterKeyId());
|
Log.d(Constants.TAG, "No primary user id in key " + signingRing.getMasterKeyId());
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,17 @@ public class UncachedPublicKey {
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns primary user id if existing. If not, return first encountered user id.
|
||||||
|
*/
|
||||||
|
public String getPrimaryUserIdWithFallback() {
|
||||||
|
String userId = getPrimaryUserId();
|
||||||
|
if (userId == null) {
|
||||||
|
userId = (String) mPublicKey.getUserIDs().next();
|
||||||
|
}
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<String> getUnorderedUserIds() {
|
public ArrayList<String> getUnorderedUserIds() {
|
||||||
ArrayList<String> userIds = new ArrayList<String>();
|
ArrayList<String> userIds = new ArrayList<String>();
|
||||||
for (String userId : new IterableIterator<String>(mPublicKey.getUserIDs())) {
|
for (String userId : new IterableIterator<String>(mPublicKey.getUserIDs())) {
|
||||||
|
@ -40,7 +40,11 @@ public abstract class WrappedKeyRing extends KeyRing {
|
|||||||
|
|
||||||
public String getPrimaryUserId() throws PgpGeneralException {
|
public String getPrimaryUserId() throws PgpGeneralException {
|
||||||
return getPublicKey().getPrimaryUserId();
|
return getPublicKey().getPrimaryUserId();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
public String getPrimaryUserIdWithFallback() throws PgpGeneralException {
|
||||||
|
return getPublicKey().getPrimaryUserIdWithFallback();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isRevoked() throws PgpGeneralException {
|
public boolean isRevoked() throws PgpGeneralException {
|
||||||
// Is the master key revoked?
|
// Is the master key revoked?
|
||||||
|
@ -97,7 +97,7 @@ public class WrappedSecretKey extends WrappedPublicKey {
|
|||||||
signatureGenerator.init(signatureType, mPrivateKey);
|
signatureGenerator.init(signatureType, mPrivateKey);
|
||||||
|
|
||||||
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
|
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
|
||||||
spGen.setSignerUserID(false, mRing.getPrimaryUserId());
|
spGen.setSignerUserID(false, mRing.getPrimaryUserIdWithFallback());
|
||||||
signatureGenerator.setHashedSubpackets(spGen.generate());
|
signatureGenerator.setHashedSubpackets(spGen.generate());
|
||||||
return signatureGenerator;
|
return signatureGenerator;
|
||||||
} catch(PGPException e) {
|
} catch(PGPException e) {
|
||||||
|
@ -70,6 +70,10 @@ public class CachedPublicKeyRing extends KeyRing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPrimaryUserIdWithFallback() throws PgpGeneralException {
|
||||||
|
return getPrimaryUserId();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isRevoked() throws PgpGeneralException {
|
public boolean isRevoked() throws PgpGeneralException {
|
||||||
try {
|
try {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
|
@ -351,7 +351,7 @@ public class KeychainIntentService extends IntentService
|
|||||||
// cache new passphrase
|
// cache new passphrase
|
||||||
if (saveParcel.mNewPassphrase != null) {
|
if (saveParcel.mNewPassphrase != null) {
|
||||||
PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(),
|
PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(),
|
||||||
saveParcel.mNewPassphrase, ring.getPublicKey().getPrimaryUserId());
|
saveParcel.mNewPassphrase, ring.getPublicKey().getPrimaryUserIdWithFallback());
|
||||||
}
|
}
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
sendErrorToHandler(e);
|
sendErrorToHandler(e);
|
||||||
|
@ -191,7 +191,7 @@ public class PassphraseCacheService extends Service {
|
|||||||
Log.d(Constants.TAG, "Key has no passphrase! Caches and returns empty passphrase!");
|
Log.d(Constants.TAG, "Key has no passphrase! Caches and returns empty passphrase!");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addCachedPassphrase(this, keyId, "", key.getPrimaryUserId());
|
addCachedPassphrase(this, keyId, "", key.getPrimaryUserIdWithFallback());
|
||||||
} catch (PgpGeneralException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.d(Constants.TAG, "PgpGeneralException occured");
|
Log.d(Constants.TAG, "PgpGeneralException occured");
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ public class EncryptAsymmetricFragment extends Fragment {
|
|||||||
String[] userId;
|
String[] userId;
|
||||||
try {
|
try {
|
||||||
userId = mProviderHelper.getCachedPublicKeyRing(
|
userId = mProviderHelper.getCachedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingUri(mSecretKeyId)).getSplitPrimaryUserId();
|
KeyRings.buildUnifiedKeyRingUri(mSecretKeyId)).getSplitPrimaryUserIdWithFallback();
|
||||||
} catch (PgpGeneralException e) {
|
} catch (PgpGeneralException e) {
|
||||||
userId = null;
|
userId = null;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
// above can't be statically verified to have been set in all cases because
|
// above can't be statically verified to have been set in all cases because
|
||||||
// the catch clause doesn't return.
|
// the catch clause doesn't return.
|
||||||
try {
|
try {
|
||||||
userId = secretRing.getPrimaryUserId();
|
userId = secretRing.getPrimaryUserIdWithFallback();
|
||||||
} catch (PgpGeneralException e) {
|
} catch (PgpGeneralException e) {
|
||||||
userId = null;
|
userId = null;
|
||||||
}
|
}
|
||||||
@ -232,7 +232,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase,
|
PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase,
|
||||||
secretRing.getPrimaryUserId());
|
secretRing.getPrimaryUserIdWithFallback());
|
||||||
} catch(PgpGeneralException e) {
|
} catch(PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "adding of a passhrase failed", e);
|
Log.e(Constants.TAG, "adding of a passhrase failed", e);
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
if (unlockedSecretKey.getKeyId() != masterKeyId) {
|
if (unlockedSecretKey.getKeyId() != masterKeyId) {
|
||||||
PassphraseCacheService.addCachedPassphrase(
|
PassphraseCacheService.addCachedPassphrase(
|
||||||
activity, unlockedSecretKey.getKeyId(), passphrase,
|
activity, unlockedSecretKey.getKeyId(), passphrase,
|
||||||
unlockedSecretKey.getPrimaryUserId());
|
unlockedSecretKey.getPrimaryUserIdWithFallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
// also return passphrase back to activity
|
// also return passphrase back to activity
|
||||||
|
Loading…
Reference in New Issue
Block a user