From 318005dbb6318a68bc9728aa35920bf603084b35 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 22 Sep 2017 00:22:15 +0200 Subject: [PATCH] load keys from sd card during consolidate --- .../provider/KeyWritableRepository.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java index 162ad24ed..33dd0f4f5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeyWritableRepository.java @@ -1091,7 +1091,7 @@ public class KeyWritableRepository extends KeyRepository { final Cursor cursor = mContentResolver.query( KeyRingData.buildPublicKeyRingUri(), - new String[]{KeyRingData.KEY_RING_DATA}, null, null, null); + new String[]{KeyRingData.MASTER_KEY_ID, KeyRingData.KEY_RING_DATA}, null, null, null); if (cursor == null) { log.add(LogType.MSG_CON_ERROR_DB, indent); @@ -1113,7 +1113,21 @@ public class KeyWritableRepository extends KeyRepository { if (cursor.isAfterLast()) { return false; } - ring = ParcelableKeyRing.createFromEncodedBytes(cursor.getBlob(0)); + + long masterKeyId = cursor.getLong(0); + byte[] keyBytes = cursor.getBlob(1); + if (keyBytes == null) { + try { + keyBytes = mLocalPublicKeyStorage.readPublicKey(masterKeyId); + } catch (IOException e) { + Log.e(Constants.TAG, "Failed reading key data!", e); + } + } + if (keyBytes == null) { + throw new IllegalStateException("Lost a key! This should never happen!"); + } + + ring = ParcelableKeyRing.createFromEncodedBytes(keyBytes); cursor.moveToNext(); return true; }