aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain
diff options
context:
space:
mode:
authorAshley Hughes <spirit.returned@gmail.com>2014-01-30 15:43:08 +0000
committerAshley Hughes <spirit.returned@gmail.com>2014-01-30 15:43:08 +0000
commit9f38c1436c1d22212a72c40f477e6b2aa2d367c5 (patch)
tree670173a037dc3c96cae65f6811fed5280e9cc7c3 /OpenPGP-Keychain
parent4119757699083889c8288960c7581a3060bd60c1 (diff)
downloadopen-keychain-9f38c1436c1d22212a72c40f477e6b2aa2d367c5.tar.gz
open-keychain-9f38c1436c1d22212a72c40f477e6b2aa2d367c5.tar.bz2
open-keychain-9f38c1436c1d22212a72c40f477e6b2aa2d367c5.zip
save work
Diffstat (limited to 'OpenPGP-Keychain')
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java46
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java10
2 files changed, 12 insertions, 44 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
index d6f130682..85c3ed9d2 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
@@ -103,15 +103,12 @@ public class PgpKeyOperation {
}
/**
- * Creates new secret key. The returned PGPSecretKeyRing contains only one newly generated key
- * when this key is the new masterkey. If a masterkey is supplied in the parameters
- * PGPSecretKeyRing contains the masterkey and the new key as a subkey (certified by the
- * masterkey).
+ * Creates new secret key.
*
* @param algorithmChoice
* @param keySize
* @param passPhrase
- * @param masterSecretKey
+ * @param isMasterKey
* @return
* @throws NoSuchAlgorithmException
* @throws PGPException
@@ -119,9 +116,9 @@ public class PgpKeyOperation {
* @throws PgpGeneralException
* @throws InvalidAlgorithmParameterException
*/
- public PGPSecretKeyRing createKey(int algorithmChoice, int keySize, String passPhrase,
- PGPSecretKey masterSecretKey) throws NoSuchAlgorithmException, PGPException,
- NoSuchProviderException, PgpGeneralException, InvalidAlgorithmParameterException {
+ public PGPSecretKey createKey(int algorithmChoice, int keySize, String passPhrase,
+ boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException,
+ PgpGeneralException, InvalidAlgorithmParameterException {
if (keySize < 512) {
throw new PgpGeneralException(mContext.getString(R.string.error_key_size_minimum512bit));
@@ -143,7 +140,7 @@ public class PgpKeyOperation {
}
case Id.choice.algorithm.elgamal: {
- if (masterSecretKey == null) {
+ if (isMasterKey) {
throw new PgpGeneralException(
mContext.getString(R.string.error_master_key_must_not_be_el_gamal));
}
@@ -183,36 +180,11 @@ public class PgpKeyOperation {
PBESecretKeyEncryptor keyEncryptor = new JcePBESecretKeyEncryptorBuilder(
PGPEncryptedData.CAST5, sha1Calc)
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
- PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
- Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
-
- PGPKeyRingGenerator ringGen = null;
- PGPContentSignerBuilder certificationSignerBuilder = null;
- if (masterSecretKey == null) {
- certificationSignerBuilder = new JcaPGPContentSignerBuilder(keyPair.getPublicKey()
- .getAlgorithm(), HashAlgorithmTags.SHA1);
-
- // build keyRing with only this one master key in it!
- ringGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, keyPair, "",
- sha1Calc, null, null, certificationSignerBuilder, keyEncryptor);
- } else {
- PGPPublicKey masterPublicKey = masterSecretKey.getPublicKey();
- PGPPrivateKey masterPrivateKey = masterSecretKey.extractPrivateKey(keyDecryptor);
- PGPKeyPair masterKeyPair = new PGPKeyPair(masterPublicKey, masterPrivateKey);
-
- certificationSignerBuilder = new JcaPGPContentSignerBuilder(masterKeyPair
- .getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1);
-
- // build keyRing with master key and new key as subkey (certified by masterkey)
- ringGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, masterKeyPair,
- "", sha1Calc, null, null, certificationSignerBuilder, keyEncryptor);
-
- ringGen.addSubKey(keyPair);
- }
- PGPSecretKeyRing secKeyRing = ringGen.generateSecretKeyRing();
+ PGPSecretKey secKey = new PGPSecretKey(keyPair.getPrivateKey(), keyPair.getPublicKey(),
+ sha1Calc, isMasterKey, keyEncryptor);
- return secKeyRing;
+ return secKey;
}
public void changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase,
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
index b02e08dda..5c67e289c 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -561,21 +561,17 @@ public class KeychainIntentService extends IntentService implements ProgressDial
int algorithm = data.getInt(GENERATE_KEY_ALGORITHM);
String passphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
int keysize = data.getInt(GENERATE_KEY_KEY_SIZE);
- PGPSecretKey masterKey = null;
- if (data.containsKey(GENERATE_KEY_MASTER_KEY)) {
- masterKey = PgpConversionHelper.BytesToPGPSecretKey(data
- .getByteArray(GENERATE_KEY_MASTER_KEY));
- }
+ boolean masterKey = data.getBoolean(GENERATE_KEY_MASTER_KEY);
/* Operation */
PgpKeyOperation keyOperations = new PgpKeyOperation(this, this);
- PGPSecretKeyRing newKeyRing = keyOperations.createKey(algorithm, keysize,
+ PGPSecretKey newKey = keyOperations.createKey(algorithm, keysize,
passphrase, masterKey);
/* Output */
Bundle resultData = new Bundle();
resultData.putByteArray(RESULT_NEW_KEY,
- PgpConversionHelper.PGPSecretKeyRingToBytes(newKeyRing));
+ PgpConversionHelper.PGPSecretKeyToBytes(newKey));
OtherHelper.logDebugBundle(resultData, "resultData");