mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-25 08:28:50 -05:00
ditch useless PgpKeyHelper.getMasterKey methods
This commit is contained in:
parent
34fca975d7
commit
428e94bb57
@ -241,7 +241,7 @@ public class PgpDecryptVerify {
|
||||
// TODO: improve this code! get master key directly!
|
||||
PGPSecretKeyRing secretKeyRing =
|
||||
ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, encData.getKeyID());
|
||||
long masterKeyId = PgpKeyHelper.getMasterKey(secretKeyRing).getKeyID();
|
||||
long masterKeyId = secretKeyRing.getSecretKey().getKeyID();
|
||||
Log.d(Constants.TAG, "encData.getKeyID():" + encData.getKeyID());
|
||||
Log.d(Constants.TAG, "allowedKeyIds: " + mAllowedKeyIds);
|
||||
Log.d(Constants.TAG, "masterKeyId: " + masterKeyId);
|
||||
@ -375,7 +375,7 @@ public class PgpDecryptVerify {
|
||||
PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId(
|
||||
mContext, signatureKeyId);
|
||||
if (signKeyRing != null) {
|
||||
userId = PgpKeyHelper.getMainUserId(PgpKeyHelper.getMasterKey(signKeyRing));
|
||||
userId = PgpKeyHelper.getMainUserId(signKeyRing.getPublicKey());
|
||||
}
|
||||
signatureResult.setUserId(userId);
|
||||
break;
|
||||
@ -559,7 +559,7 @@ public class PgpDecryptVerify {
|
||||
PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId(mContext,
|
||||
signatureKeyId);
|
||||
if (signKeyRing != null) {
|
||||
userId = PgpKeyHelper.getMainUserId(PgpKeyHelper.getMasterKey(signKeyRing));
|
||||
userId = PgpKeyHelper.getMainUserId(signKeyRing.getPublicKey());
|
||||
}
|
||||
signatureResult.setUserId(userId);
|
||||
break;
|
||||
@ -624,7 +624,7 @@ public class PgpDecryptVerify {
|
||||
signatureKeyId);
|
||||
PGPPublicKey mKey = null;
|
||||
if (signKeyRing != null) {
|
||||
mKey = PgpKeyHelper.getMasterKey(signKeyRing);
|
||||
mKey = signKeyRing.getPublicKey();
|
||||
}
|
||||
|
||||
if (signature.getKeyID() != mKey.getKeyID()) {
|
||||
|
@ -60,34 +60,6 @@ public class PgpKeyHelper {
|
||||
return key.getPublicKey().getCreationTime();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static PGPPublicKey getMasterKey(PGPPublicKeyRing keyRing) {
|
||||
if (keyRing == null) {
|
||||
return null;
|
||||
}
|
||||
for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(keyRing.getPublicKeys())) {
|
||||
if (key.isMasterKey()) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static PGPSecretKey getMasterKey(PGPSecretKeyRing keyRing) {
|
||||
if (keyRing == null) {
|
||||
return null;
|
||||
}
|
||||
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(keyRing.getSecretKeys())) {
|
||||
if (key.isMasterKey()) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static PGPSecretKey getKeyNum(PGPSecretKeyRing keyRing, long num) {
|
||||
long cnt = 0;
|
||||
|
@ -306,7 +306,7 @@ public class PgpSignEncrypt {
|
||||
signatureGenerator = new PGPSignatureGenerator(contentSignerBuilder);
|
||||
signatureGenerator.init(signatureType, signaturePrivateKey);
|
||||
|
||||
String userId = PgpKeyHelper.getMainUserId(PgpKeyHelper.getMasterKey(signingKeyRing));
|
||||
String userId = PgpKeyHelper.getMainUserId(signingKeyRing.getSecretKey());
|
||||
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
|
||||
spGen.setSignerUserID(false, userId);
|
||||
signatureGenerator.setHashedSubpackets(spGen.generate());
|
||||
@ -505,7 +505,7 @@ public class PgpSignEncrypt {
|
||||
signatureGenerator.init(type, signaturePrivateKey);
|
||||
|
||||
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
|
||||
String userId = PgpKeyHelper.getMainUserId(PgpKeyHelper.getMasterKey(signingKeyRing));
|
||||
String userId = PgpKeyHelper.getMainUserId(signingKeyRing.getSecretKey());
|
||||
spGen.setSignerUserID(false, userId);
|
||||
signatureGenerator.setHashedSubpackets(spGen.generate());
|
||||
}
|
||||
|
@ -260,30 +260,6 @@ public class ProviderHelper {
|
||||
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Private helper method
|
||||
*/
|
||||
private static ArrayList<Long> getKeyRingsMasterKeyIds(Context context, Uri queryUri) {
|
||||
Cursor cursor = context.getContentResolver().query(queryUri,
|
||||
new String[]{KeyRings.MASTER_KEY_ID}, null, null, null);
|
||||
|
||||
ArrayList<Long> masterKeyIds = new ArrayList<Long>();
|
||||
if (cursor != null) {
|
||||
int masterKeyIdCol = cursor.getColumnIndex(KeyRings.MASTER_KEY_ID);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
masterKeyIds.add(cursor.getLong(masterKeyIdCol));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return masterKeyIds;
|
||||
}
|
||||
|
||||
public static void deletePublicKeyRing(Context context, long masterKeyId) {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
cr.delete(KeyRings.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
|
||||
@ -294,38 +270,6 @@ public class ProviderHelper {
|
||||
cr.delete(KeyRings.buildSecretKeyRingUri(Long.toString(masterKeyId)), null, null);
|
||||
}
|
||||
|
||||
public static boolean getMasterKeyCanCertify(Context context, Uri queryUri) {
|
||||
// TODO redo
|
||||
|
||||
return false;
|
||||
|
||||
/*
|
||||
String[] projection = new String[]{
|
||||
KeyRings.MASTER_KEY_ID,
|
||||
"(SELECT COUNT(sign_keys." + Keys._ID + ") FROM " + Tables.KEYS
|
||||
+ " AS sign_keys WHERE sign_keys." + Keys.KEY_RING_ROW_ID + " = "
|
||||
+ KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings._ID
|
||||
+ " AND sign_keys." + Keys.CAN_CERTIFY + " = '1' AND " + Keys.IS_MASTER_KEY
|
||||
+ " = 1) AS sign",};
|
||||
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
Cursor cursor = cr.query(queryUri, projection, null, null, null);
|
||||
|
||||
long masterKeyId = -1;
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int masterKeyIdCol = cursor.getColumnIndex("sign");
|
||||
|
||||
masterKeyId = cursor.getLong(masterKeyIdCol);
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return (masterKeyId > 0);
|
||||
*/
|
||||
}
|
||||
|
||||
public static boolean hasSecretKeyByMasterKeyId(Context context, long masterKeyId) {
|
||||
Uri queryUri = KeyRings.buildSecretKeyRingUri(Long.toString(masterKeyId));
|
||||
// see if we can get our master key id back from the uri
|
||||
@ -336,8 +280,16 @@ public class ProviderHelper {
|
||||
* Get master key id of key
|
||||
*/
|
||||
public static long getMasterKeyId(Context context, Uri queryUri) {
|
||||
String[] projection = new String[]{KeyRings.MASTER_KEY_ID};
|
||||
Cursor cursor = context.getContentResolver().query(queryUri, projection, null, null, null);
|
||||
// try extracting from the uri first
|
||||
try {
|
||||
return Long.parseLong(queryUri.getPathSegments().get(1));
|
||||
} catch(NumberFormatException e) {
|
||||
// didn't work? oh well.
|
||||
}
|
||||
|
||||
Cursor cursor = context.getContentResolver().query(queryUri, new String[] {
|
||||
KeyRings.MASTER_KEY_ID
|
||||
}, null, null, null);
|
||||
|
||||
long masterKeyId = 0;
|
||||
try {
|
||||
|
@ -174,7 +174,7 @@ public class PassphraseCacheService extends Service {
|
||||
if (keyRing == null) {
|
||||
return null;
|
||||
}
|
||||
PGPSecretKey masterKey = PgpKeyHelper.getMasterKey(keyRing);
|
||||
PGPSecretKey masterKey = keyRing.getSecretKey();
|
||||
if (masterKey == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -276,8 +276,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
|
||||
// get master key id using row id
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
||||
|
||||
mMasterCanSign = ProviderHelper.getMasterKeyCanCertify(this, mDataUri);
|
||||
finallyEdit(masterKeyId);
|
||||
}
|
||||
}
|
||||
@ -347,8 +345,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
}
|
||||
return true;
|
||||
case R.id.menu_key_edit_delete:
|
||||
long rowId= ProviderHelper.getRowId(this,mDataUri);
|
||||
Uri convertUri = KeychainContract.KeyRings.buildSecretKeyRingUri(Long.toString(rowId));
|
||||
Uri convertUri = KeychainContract.KeyRings.buildSecretKeyRingUri(mDataUri);
|
||||
// Message is received after key is deleted
|
||||
Handler returnHandler = new Handler() {
|
||||
@Override
|
||||
@ -374,7 +371,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
PGPSecretKey masterKey = null;
|
||||
mKeyRing = ProviderHelper.getPGPSecretKeyRing(this, masterKeyId);
|
||||
if (mKeyRing != null) {
|
||||
masterKey = PgpKeyHelper.getMasterKey(mKeyRing);
|
||||
masterKey = mKeyRing.getSecretKey();
|
||||
mMasterCanSign = PgpKeyHelper.isCertificationKey(mKeyRing.getSecretKey());
|
||||
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) {
|
||||
mKeys.add(key);
|
||||
mKeysUsages.add(-1); // get usage when view is created
|
||||
@ -382,6 +380,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
} else {
|
||||
Log.e(Constants.TAG, "Keyring not found with masterKeyId: " + masterKeyId);
|
||||
Toast.makeText(this, R.string.error_no_secret_key_found, Toast.LENGTH_LONG).show();
|
||||
// TODO
|
||||
}
|
||||
if (masterKey != null) {
|
||||
boolean isSet = false;
|
||||
|
@ -145,7 +145,7 @@ public class EncryptAsymmetricFragment extends Fragment {
|
||||
preselectedSignatureKeyId);
|
||||
PGPSecretKey masterKey;
|
||||
if (keyRing != null) {
|
||||
masterKey = PgpKeyHelper.getMasterKey(keyRing);
|
||||
masterKey = keyRing.getSecretKey();
|
||||
if (masterKey != null) {
|
||||
Vector<PGPSecretKey> signKeys = PgpKeyHelper.getUsableSigningKeys(keyRing);
|
||||
if (signKeys.size() > 0) {
|
||||
@ -166,7 +166,7 @@ public class EncryptAsymmetricFragment extends Fragment {
|
||||
if (keyRing == null) {
|
||||
continue;
|
||||
}
|
||||
masterKey = PgpKeyHelper.getMasterKey(keyRing);
|
||||
masterKey = keyRing.getPublicKey();
|
||||
if (masterKey == null) {
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user