mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
make everything work again
This commit is contained in:
parent
e27048fe73
commit
d891f75339
@ -197,7 +197,7 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UncachedKeyRing buildNewSecretKey(
|
public Pair<UncachedKeyRing,UncachedKeyRing> buildNewSecretKey(
|
||||||
OldSaveKeyringParcel saveParcel)
|
OldSaveKeyringParcel saveParcel)
|
||||||
throws PgpGeneralMsgIdException, PGPException, SignatureException, IOException {
|
throws PgpGeneralMsgIdException, PGPException, SignatureException, IOException {
|
||||||
|
|
||||||
@ -336,8 +336,9 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PGPSecretKeyRing secretKeyRing = keyGen.generateSecretKeyRing();
|
PGPSecretKeyRing secretKeyRing = keyGen.generateSecretKeyRing();
|
||||||
|
PGPPublicKeyRing publicKeyRing = keyGen.generatePublicKeyRing();
|
||||||
|
|
||||||
return new UncachedKeyRing(secretKeyRing);
|
return new Pair(new UncachedKeyRing(secretKeyRing), new UncachedKeyRing(publicKeyRing));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,6 @@ public class ProviderHelper {
|
|||||||
return (WrappedSecretKeyRing) getWrappedKeyRing(queryUri, true);
|
return (WrappedSecretKeyRing) getWrappedKeyRing(queryUri, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private KeyRing getWrappedKeyRing(Uri queryUri, boolean secret) throws NotFoundException {
|
private KeyRing getWrappedKeyRing(Uri queryUri, boolean secret) throws NotFoundException {
|
||||||
Cursor cursor = mContentResolver.query(queryUri,
|
Cursor cursor = mContentResolver.query(queryUri,
|
||||||
new String[]{
|
new String[]{
|
||||||
@ -203,6 +202,9 @@ public class ProviderHelper {
|
|||||||
boolean hasAnySecret = cursor.getInt(0) > 0;
|
boolean hasAnySecret = cursor.getInt(0) > 0;
|
||||||
int verified = cursor.getInt(1);
|
int verified = cursor.getInt(1);
|
||||||
byte[] blob = cursor.getBlob(2);
|
byte[] blob = cursor.getBlob(2);
|
||||||
|
if(secret &! hasAnySecret) {
|
||||||
|
throw new NotFoundException("Secret key not available!");
|
||||||
|
}
|
||||||
return secret
|
return secret
|
||||||
? new WrappedSecretKeyRing(blob, hasAnySecret, verified)
|
? new WrappedSecretKeyRing(blob, hasAnySecret, verified)
|
||||||
: new WrappedPublicKeyRing(blob, hasAnySecret, verified);
|
: new WrappedPublicKeyRing(blob, hasAnySecret, verified);
|
||||||
@ -221,6 +223,11 @@ public class ProviderHelper {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void savePublicKeyRing(UncachedKeyRing keyRing) throws IOException {
|
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();
|
UncachedPublicKey masterKey = keyRing.getPublicKey();
|
||||||
long masterKeyId = masterKey.getKeyId();
|
long masterKeyId = masterKey.getKeyId();
|
||||||
|
|
||||||
@ -373,6 +380,11 @@ public class ProviderHelper {
|
|||||||
* is already in the database!
|
* is already in the database!
|
||||||
*/
|
*/
|
||||||
public void saveSecretKeyRing(UncachedKeyRing keyRing) throws IOException {
|
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();
|
long masterKeyId = keyRing.getMasterKeyId();
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -417,7 +429,7 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
// save public keyring
|
// save public keyring
|
||||||
savePublicKeyRing(pubRing);
|
savePublicKeyRing(pubRing);
|
||||||
savePublicKeyRing(secRing);
|
saveSecretKeyRing(secRing);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -520,18 +520,19 @@ public class KeychainIntentService extends IntentService
|
|||||||
} else {
|
} else {
|
||||||
PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 90, 100));
|
PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 90, 100));
|
||||||
try {
|
try {
|
||||||
WrappedSecretKeyRing privkey = providerHelper.getWrappedSecretKeyRing(masterKeyId);
|
WrappedSecretKeyRing seckey = providerHelper.getWrappedSecretKeyRing(masterKeyId);
|
||||||
WrappedPublicKeyRing pubkey = providerHelper.getWrappedPublicKeyRing(masterKeyId);
|
WrappedPublicKeyRing pubkey = providerHelper.getWrappedPublicKeyRing(masterKeyId);
|
||||||
|
|
||||||
PgpKeyOperation.Pair<UncachedKeyRing,UncachedKeyRing> pair =
|
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);
|
setProgress(R.string.progress_saving_key_ring, 90, 100);
|
||||||
providerHelper.saveKeyRing(pair.first, pair.second);
|
providerHelper.saveKeyRing(pair.first, pair.second);
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
UncachedKeyRing ring = keyOperations.buildNewSecretKey(saveParcel); //new Keyring
|
PgpKeyOperation.Pair<UncachedKeyRing,UncachedKeyRing> pair =
|
||||||
|
keyOperations.buildNewSecretKey(saveParcel); //new Keyring
|
||||||
// save the pair
|
// save the pair
|
||||||
setProgress(R.string.progress_saving_key_ring, 90, 100);
|
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);
|
setProgress(R.string.progress_done, 100, 100);
|
||||||
|
Loading…
Reference in New Issue
Block a user