mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-14 04:45:04 -05:00
save work
This commit is contained in:
parent
4119757699
commit
9f38c1436c
@ -103,15 +103,12 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new secret key. The returned PGPSecretKeyRing contains only one newly generated key
|
* Creates new secret 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).
|
|
||||||
*
|
*
|
||||||
* @param algorithmChoice
|
* @param algorithmChoice
|
||||||
* @param keySize
|
* @param keySize
|
||||||
* @param passPhrase
|
* @param passPhrase
|
||||||
* @param masterSecretKey
|
* @param isMasterKey
|
||||||
* @return
|
* @return
|
||||||
* @throws NoSuchAlgorithmException
|
* @throws NoSuchAlgorithmException
|
||||||
* @throws PGPException
|
* @throws PGPException
|
||||||
@ -119,9 +116,9 @@ public class PgpKeyOperation {
|
|||||||
* @throws PgpGeneralException
|
* @throws PgpGeneralException
|
||||||
* @throws InvalidAlgorithmParameterException
|
* @throws InvalidAlgorithmParameterException
|
||||||
*/
|
*/
|
||||||
public PGPSecretKeyRing createKey(int algorithmChoice, int keySize, String passPhrase,
|
public PGPSecretKey createKey(int algorithmChoice, int keySize, String passPhrase,
|
||||||
PGPSecretKey masterSecretKey) throws NoSuchAlgorithmException, PGPException,
|
boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException,
|
||||||
NoSuchProviderException, PgpGeneralException, InvalidAlgorithmParameterException {
|
PgpGeneralException, InvalidAlgorithmParameterException {
|
||||||
|
|
||||||
if (keySize < 512) {
|
if (keySize < 512) {
|
||||||
throw new PgpGeneralException(mContext.getString(R.string.error_key_size_minimum512bit));
|
throw new PgpGeneralException(mContext.getString(R.string.error_key_size_minimum512bit));
|
||||||
@ -143,7 +140,7 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Id.choice.algorithm.elgamal: {
|
case Id.choice.algorithm.elgamal: {
|
||||||
if (masterSecretKey == null) {
|
if (isMasterKey) {
|
||||||
throw new PgpGeneralException(
|
throw new PgpGeneralException(
|
||||||
mContext.getString(R.string.error_master_key_must_not_be_el_gamal));
|
mContext.getString(R.string.error_master_key_must_not_be_el_gamal));
|
||||||
}
|
}
|
||||||
@ -183,36 +180,11 @@ public class PgpKeyOperation {
|
|||||||
PBESecretKeyEncryptor keyEncryptor = new JcePBESecretKeyEncryptorBuilder(
|
PBESecretKeyEncryptor keyEncryptor = new JcePBESecretKeyEncryptorBuilder(
|
||||||
PGPEncryptedData.CAST5, sha1Calc)
|
PGPEncryptedData.CAST5, sha1Calc)
|
||||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
|
.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;
|
PGPSecretKey secKey = new PGPSecretKey(keyPair.getPrivateKey(), keyPair.getPublicKey(),
|
||||||
PGPContentSignerBuilder certificationSignerBuilder = null;
|
sha1Calc, isMasterKey, keyEncryptor);
|
||||||
if (masterSecretKey == null) {
|
|
||||||
certificationSignerBuilder = new JcaPGPContentSignerBuilder(keyPair.getPublicKey()
|
|
||||||
.getAlgorithm(), HashAlgorithmTags.SHA1);
|
|
||||||
|
|
||||||
// build keyRing with only this one master key in it!
|
return secKey;
|
||||||
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();
|
|
||||||
|
|
||||||
return secKeyRing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase,
|
public void changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase,
|
||||||
|
@ -561,21 +561,17 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
|||||||
int algorithm = data.getInt(GENERATE_KEY_ALGORITHM);
|
int algorithm = data.getInt(GENERATE_KEY_ALGORITHM);
|
||||||
String passphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
|
String passphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
|
||||||
int keysize = data.getInt(GENERATE_KEY_KEY_SIZE);
|
int keysize = data.getInt(GENERATE_KEY_KEY_SIZE);
|
||||||
PGPSecretKey masterKey = null;
|
boolean masterKey = data.getBoolean(GENERATE_KEY_MASTER_KEY);
|
||||||
if (data.containsKey(GENERATE_KEY_MASTER_KEY)) {
|
|
||||||
masterKey = PgpConversionHelper.BytesToPGPSecretKey(data
|
|
||||||
.getByteArray(GENERATE_KEY_MASTER_KEY));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Operation */
|
/* Operation */
|
||||||
PgpKeyOperation keyOperations = new PgpKeyOperation(this, this);
|
PgpKeyOperation keyOperations = new PgpKeyOperation(this, this);
|
||||||
PGPSecretKeyRing newKeyRing = keyOperations.createKey(algorithm, keysize,
|
PGPSecretKey newKey = keyOperations.createKey(algorithm, keysize,
|
||||||
passphrase, masterKey);
|
passphrase, masterKey);
|
||||||
|
|
||||||
/* Output */
|
/* Output */
|
||||||
Bundle resultData = new Bundle();
|
Bundle resultData = new Bundle();
|
||||||
resultData.putByteArray(RESULT_NEW_KEY,
|
resultData.putByteArray(RESULT_NEW_KEY,
|
||||||
PgpConversionHelper.PGPSecretKeyRingToBytes(newKeyRing));
|
PgpConversionHelper.PGPSecretKeyToBytes(newKey));
|
||||||
|
|
||||||
OtherHelper.logDebugBundle(resultData, "resultData");
|
OtherHelper.logDebugBundle(resultData, "resultData");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user