create keys with minimal keyrings being constructed in between

This commit is contained in:
Ashley Hughes 2014-01-31 15:19:59 +00:00
parent 7897c6fadd
commit de6a515ca5
3 changed files with 25 additions and 8 deletions

View File

@ -80,9 +80,27 @@ public class PgpConversionHelper {
* @return * @return
*/ */
public static PGPSecretKey BytesToPGPSecretKey(byte[] keyBytes) { public static PGPSecretKey BytesToPGPSecretKey(byte[] keyBytes) {
PGPSecretKey key = BytesToPGPSecretKeyList(keyBytes).get(0); PGPObjectFactory factory = new PGPObjectFactory(keyBytes);
Object obj = null;
try {
obj = factory.nextObject();
} catch (IOException e) {
Log.e(Constants.TAG, "Error while converting to PGPSecretKey!", e);
}
PGPSecretKey secKey = null;
if(obj instanceof PGPSecretKey) {
if ((secKey = (PGPSecretKey)obj ) == null) {
Log.e(Constants.TAG, "No keys given!");
}
} else if(obj instanceof PGPSecretKeyRing) { //master keys are sent as keyrings
PGPSecretKeyRing keyRing = null;
if ((keyRing = (PGPSecretKeyRing)obj) == null) {
Log.e(Constants.TAG, "No keys given!");
}
secKey = keyRing.getSecretKey();
}
return key; return secKey;
} }
/** /**

View File

@ -193,19 +193,18 @@ public class EditKeyActivity extends SherlockFragmentActivity {
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
// get new key from data bundle returned from service // get new key from data bundle returned from service
Bundle data = message.getData(); Bundle data = message.getData();
PGPSecretKeyRing masterKey = (PGPSecretKey) PgpConversionHelper PGPSecretKey masterKey = (PGPSecretKey) PgpConversionHelper
.BytesToPGPKey(data .BytesToPGPSecretKey(data
.getByteArray(KeychainIntentService.RESULT_NEW_KEY)); .getByteArray(KeychainIntentService.RESULT_NEW_KEY));
PGPSecretKey subKey = (PGPSecretKey) PgpConversionHelper PGPSecretKey subKey = (PGPSecretKey) PgpConversionHelper
.BytesToPGPKey(data .BytesToPGPSecretKey(data
.getByteArray(KeychainIntentService.RESULT_NEW_KEY2)); .getByteArray(KeychainIntentService.RESULT_NEW_KEY2));
// add master key // add master key
mKeys.add(maskterKey); mKeys.add(masterKey);
mKeysUsages.add(Id.choice.usage.sign_only); //TODO: get from key flags mKeysUsages.add(Id.choice.usage.sign_only); //TODO: get from key flags
// add sub key // add sub key
subIt.next(); // masterkey
mKeys.add(subKey); mKeys.add(subKey);
mKeysUsages.add(Id.choice.usage.encrypt_only); //TODO: get from key flags mKeysUsages.add(Id.choice.usage.encrypt_only); //TODO: get from key flags

View File

@ -324,7 +324,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
// get new key from data bundle returned from service // get new key from data bundle returned from service
Bundle data = message.getData(); Bundle data = message.getData();
PGPSecretKey newKey = (PGPSecretKey) PgpConversionHelper PGPSecretKey newKey = (PGPSecretKey) PgpConversionHelper
.BytesToPGPKey(data .BytesToPGPSecretKey(data
.getByteArray(KeychainIntentService.RESULT_NEW_KEY)); .getByteArray(KeychainIntentService.RESULT_NEW_KEY));
// add view with new key // add view with new key