make everything work again

This commit is contained in:
Vincent Breitmoser 2014-05-31 12:58:35 +02:00
parent e27048fe73
commit d891f75339
3 changed files with 22 additions and 8 deletions

View File

@ -197,7 +197,7 @@ public class PgpKeyOperation {
}
}
public UncachedKeyRing buildNewSecretKey(
public Pair<UncachedKeyRing,UncachedKeyRing> buildNewSecretKey(
OldSaveKeyringParcel saveParcel)
throws PgpGeneralMsgIdException, PGPException, SignatureException, IOException {
@ -336,8 +336,9 @@ public class PgpKeyOperation {
}
PGPSecretKeyRing secretKeyRing = keyGen.generateSecretKeyRing();
PGPPublicKeyRing publicKeyRing = keyGen.generatePublicKeyRing();
return new UncachedKeyRing(secretKeyRing);
return new Pair(new UncachedKeyRing(secretKeyRing), new UncachedKeyRing(publicKeyRing));
}

View File

@ -187,7 +187,6 @@ public class ProviderHelper {
return (WrappedSecretKeyRing) getWrappedKeyRing(queryUri, true);
}
private KeyRing getWrappedKeyRing(Uri queryUri, boolean secret) throws NotFoundException {
Cursor cursor = mContentResolver.query(queryUri,
new String[]{
@ -203,6 +202,9 @@ public class ProviderHelper {
boolean hasAnySecret = cursor.getInt(0) > 0;
int verified = cursor.getInt(1);
byte[] blob = cursor.getBlob(2);
if(secret &! hasAnySecret) {
throw new NotFoundException("Secret key not available!");
}
return secret
? new WrappedSecretKeyRing(blob, hasAnySecret, verified)
: new WrappedPublicKeyRing(blob, hasAnySecret, verified);
@ -221,6 +223,11 @@ public class ProviderHelper {
*/
@SuppressWarnings("unchecked")
public void savePublicKeyRing(UncachedKeyRing keyRing) throws IOException {
if (keyRing.isSecret()) {
throw new RuntimeException("Tried to save secret keyring as public! " +
"This is a bug, please file a bug report.");
}
UncachedPublicKey masterKey = keyRing.getPublicKey();
long masterKeyId = masterKey.getKeyId();
@ -373,6 +380,11 @@ public class ProviderHelper {
* is already in the database!
*/
public void saveSecretKeyRing(UncachedKeyRing keyRing) throws IOException {
if (!keyRing.isSecret()) {
throw new RuntimeException("Tried to save publkc keyring as secret! " +
"This is a bug, please file a bug report.");
}
long masterKeyId = keyRing.getMasterKeyId();
{
@ -417,7 +429,7 @@ public class ProviderHelper {
// save public keyring
savePublicKeyRing(pubRing);
savePublicKeyRing(secRing);
saveSecretKeyRing(secRing);
}
/**

View File

@ -520,18 +520,19 @@ public class KeychainIntentService extends IntentService
} else {
PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 90, 100));
try {
WrappedSecretKeyRing privkey = providerHelper.getWrappedSecretKeyRing(masterKeyId);
WrappedSecretKeyRing seckey = providerHelper.getWrappedSecretKeyRing(masterKeyId);
WrappedPublicKeyRing pubkey = providerHelper.getWrappedPublicKeyRing(masterKeyId);
PgpKeyOperation.Pair<UncachedKeyRing,UncachedKeyRing> pair =
keyOperations.buildSecretKey(privkey, pubkey, saveParcel); // edit existing
keyOperations.buildSecretKey(seckey, pubkey, saveParcel); // edit existing
setProgress(R.string.progress_saving_key_ring, 90, 100);
providerHelper.saveKeyRing(pair.first, pair.second);
} catch (ProviderHelper.NotFoundException e) {
UncachedKeyRing ring = keyOperations.buildNewSecretKey(saveParcel); //new Keyring
PgpKeyOperation.Pair<UncachedKeyRing,UncachedKeyRing> pair =
keyOperations.buildNewSecretKey(saveParcel); //new Keyring
// save the pair
setProgress(R.string.progress_saving_key_ring, 90, 100);
providerHelper.savePublicKeyRing(ring);
providerHelper.saveKeyRing(pair.first, pair.second);
}
setProgress(R.string.progress_done, 100, 100);