mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-01-31 15:10:19 -05:00
move getPublicKey into abstract WrappedKeyRing (also, fix getPrimaryUserId)
This commit is contained in:
parent
848043a481
commit
64b87f75be
@ -258,7 +258,7 @@ public class PgpDecryptVerify {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// get subkey which has been used for this encryption packet
|
// get subkey which has been used for this encryption packet
|
||||||
secretEncryptionKey = secretKeyRing.getSubKey(encData.getKeyID());
|
secretEncryptionKey = secretKeyRing.getSecretKey(encData.getKeyID());
|
||||||
if (secretEncryptionKey == null) {
|
if (secretEncryptionKey == null) {
|
||||||
// continue with the next packet in the while loop
|
// continue with the next packet in the while loop
|
||||||
continue;
|
continue;
|
||||||
@ -393,7 +393,7 @@ public class PgpDecryptVerify {
|
|||||||
signingRing = mProviderHelper.getWrappedPublicKeyRing(
|
signingRing = mProviderHelper.getWrappedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
|
||||||
);
|
);
|
||||||
signingKey = signingRing.getSubkey(sigKeyId);
|
signingKey = signingRing.getPublicKey(sigKeyId);
|
||||||
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!");
|
||||||
@ -578,7 +578,7 @@ public class PgpDecryptVerify {
|
|||||||
signingRing = mProviderHelper.getWrappedPublicKeyRing(
|
signingRing = mProviderHelper.getWrappedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(sigKeyId)
|
||||||
);
|
);
|
||||||
signingKey = signingRing.getSubkey(sigKeyId);
|
signingKey = signingRing.getPublicKey(sigKeyId);
|
||||||
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!");
|
||||||
|
@ -39,7 +39,7 @@ public abstract class WrappedKeyRing extends KeyRing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPrimaryUserId() throws PgpGeneralException {
|
public String getPrimaryUserId() throws PgpGeneralException {
|
||||||
return (String) getRing().getPublicKey().getUserIDs().next();
|
return getPublicKey().getPrimaryUserId();
|
||||||
};
|
};
|
||||||
|
|
||||||
public boolean isRevoked() throws PgpGeneralException {
|
public boolean isRevoked() throws PgpGeneralException {
|
||||||
@ -101,6 +101,14 @@ public abstract class WrappedKeyRing extends KeyRing {
|
|||||||
|
|
||||||
abstract public IterableIterator<WrappedPublicKey> publicKeyIterator();
|
abstract public IterableIterator<WrappedPublicKey> publicKeyIterator();
|
||||||
|
|
||||||
|
public WrappedPublicKey getPublicKey() {
|
||||||
|
return new WrappedPublicKey(this, getRing().getPublicKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public WrappedPublicKey getPublicKey(long id) {
|
||||||
|
return new WrappedPublicKey(this, getRing().getPublicKey(id));
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] getEncoded() throws IOException {
|
public byte[] getEncoded() throws IOException {
|
||||||
return getRing().getEncoded();
|
return getRing().getEncoded();
|
||||||
}
|
}
|
||||||
|
@ -44,14 +44,6 @@ public class WrappedPublicKeyRing extends WrappedKeyRing {
|
|||||||
getRing().encode(stream);
|
getRing().encode(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WrappedPublicKey getSubkey() {
|
|
||||||
return new WrappedPublicKey(this, getRing().getPublicKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
public WrappedPublicKey getSubkey(long id) {
|
|
||||||
return new WrappedPublicKey(this, getRing().getPublicKey(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Getter that returns the subkey that should be used for signing. */
|
/** Getter that returns the subkey that should be used for signing. */
|
||||||
WrappedPublicKey getEncryptionSubKey() throws PgpGeneralException {
|
WrappedPublicKey getEncryptionSubKey() throws PgpGeneralException {
|
||||||
PGPPublicKey key = getRing().getPublicKey(getEncryptId());
|
PGPPublicKey key = getRing().getPublicKey(getEncryptId());
|
||||||
|
@ -175,7 +175,7 @@ public class WrappedSecretKey extends WrappedPublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the master subkey (which we certify for)
|
// get the master subkey (which we certify for)
|
||||||
PGPPublicKey publicKey = publicKeyRing.getSubkey().getPublicKey();
|
PGPPublicKey publicKey = publicKeyRing.getPublicKey().getPublicKey();
|
||||||
|
|
||||||
// fetch public key ring, add the certification and return it
|
// fetch public key ring, add the certification and return it
|
||||||
for (String userId : new IterableIterator<String>(userIds.iterator())) {
|
for (String userId : new IterableIterator<String>(userIds.iterator())) {
|
||||||
|
@ -41,11 +41,11 @@ public class WrappedSecretKeyRing extends WrappedKeyRing {
|
|||||||
return mRing;
|
return mRing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WrappedSecretKey getSubKey() {
|
public WrappedSecretKey getSecretKey() {
|
||||||
return new WrappedSecretKey(this, mRing.getSecretKey());
|
return new WrappedSecretKey(this, mRing.getSecretKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
public WrappedSecretKey getSubKey(long id) {
|
public WrappedSecretKey getSecretKey(long id) {
|
||||||
return new WrappedSecretKey(this, mRing.getSecretKey(id));
|
return new WrappedSecretKey(this, mRing.getSecretKey(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ public class ProviderHelper {
|
|||||||
byte[] blob = cursor.getBlob(3);
|
byte[] blob = cursor.getBlob(3);
|
||||||
if (blob != null) {
|
if (blob != null) {
|
||||||
result.put(masterKeyId,
|
result.put(masterKeyId,
|
||||||
new WrappedPublicKeyRing(blob, hasAnySecret, verified).getSubkey());
|
new WrappedPublicKeyRing(blob, hasAnySecret, verified).getPublicKey());
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
|||||||
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
|
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
|
||||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedPublicKey;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
|
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedSecretKey;
|
import org.sufficientlysecure.keychain.pgp.WrappedSecretKey;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
|
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
|
||||||
@ -546,7 +545,7 @@ public class KeychainIntentService extends IntentService
|
|||||||
ProviderHelper providerHelper = new ProviderHelper(this);
|
ProviderHelper providerHelper = new ProviderHelper(this);
|
||||||
WrappedPublicKeyRing publicRing = providerHelper.getWrappedPublicKeyRing(pubKeyId);
|
WrappedPublicKeyRing publicRing = providerHelper.getWrappedPublicKeyRing(pubKeyId);
|
||||||
WrappedSecretKeyRing secretKeyRing = providerHelper.getWrappedSecretKeyRing(masterKeyId);
|
WrappedSecretKeyRing secretKeyRing = providerHelper.getWrappedSecretKeyRing(masterKeyId);
|
||||||
WrappedSecretKey certificationKey = secretKeyRing.getSubKey();
|
WrappedSecretKey certificationKey = secretKeyRing.getSecretKey();
|
||||||
if(!certificationKey.unlock(signaturePassphrase)) {
|
if(!certificationKey.unlock(signaturePassphrase)) {
|
||||||
throw new PgpGeneralException("Error extracting key (bad passphrase?)");
|
throw new PgpGeneralException("Error extracting key (bad passphrase?)");
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ public class EditKeyActivityOld extends ActionBarActivity implements EditorListe
|
|||||||
Uri secretUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
|
Uri secretUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
|
||||||
WrappedSecretKeyRing keyRing = new ProviderHelper(this).getWrappedSecretKeyRing(secretUri);
|
WrappedSecretKeyRing keyRing = new ProviderHelper(this).getWrappedSecretKeyRing(secretUri);
|
||||||
|
|
||||||
mMasterCanSign = keyRing.getSubKey().canCertify();
|
mMasterCanSign = keyRing.getSecretKey().canCertify();
|
||||||
for (WrappedSecretKey key : keyRing.secretKeyIterator()) {
|
for (WrappedSecretKey key : keyRing.secretKeyIterator()) {
|
||||||
// Turn into uncached instance
|
// Turn into uncached instance
|
||||||
mKeys.add(key.getUncached());
|
mKeys.add(key.getUncached());
|
||||||
@ -288,7 +288,7 @@ public class EditKeyActivityOld extends ActionBarActivity implements EditorListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isSet = false;
|
boolean isSet = false;
|
||||||
for (String userId : keyRing.getSubKey().getUserIds()) {
|
for (String userId : keyRing.getSecretKey().getUserIds()) {
|
||||||
Log.d(Constants.TAG, "Added userId " + userId);
|
Log.d(Constants.TAG, "Added userId " + userId);
|
||||||
if (!isSet) {
|
if (!isSet) {
|
||||||
isSet = true;
|
isSet = true;
|
||||||
|
@ -149,8 +149,8 @@ public class ViewCertActivity extends ActionBarActivity
|
|||||||
providerHelper.getWrappedPublicKeyRing(sig.getKeyId());
|
providerHelper.getWrappedPublicKeyRing(sig.getKeyId());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sig.init(signerRing.getSubkey());
|
sig.init(signerRing.getPublicKey());
|
||||||
if (sig.verifySignature(signeeRing.getSubkey(), signeeUid)) {
|
if (sig.verifySignature(signeeRing.getPublicKey(), signeeUid)) {
|
||||||
mStatus.setText(R.string.cert_verify_ok);
|
mStatus.setText(R.string.cert_verify_ok);
|
||||||
mStatus.setTextColor(getResources().getColor(R.color.result_green));
|
mStatus.setTextColor(getResources().getColor(R.color.result_green));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user