re-inline cryptoInput variable

This commit is contained in:
Vincent Breitmoser
2015-03-20 14:10:00 +01:00
parent abce05d529
commit 6cf966b63f

View File

@@ -97,7 +97,6 @@ public class PgpKeyOperation {
private AtomicBoolean mCancelled; private AtomicBoolean mCancelled;
NfcSignOperationsBuilder mNfcSignOps; NfcSignOperationsBuilder mNfcSignOps;
private CryptoInputParcel mCryptoInput;
public PgpKeyOperation(Progressable progress) { public PgpKeyOperation(Progressable progress) {
super(); super();
@@ -111,7 +110,6 @@ public class PgpKeyOperation {
this(progress); this(progress);
mCancelled = cancelled; mCancelled = cancelled;
mNfcSignOps = new NfcSignOperationsBuilder(cryptoInput.getSignatureTime()); mNfcSignOps = new NfcSignOperationsBuilder(cryptoInput.getSignatureTime());
mCryptoInput = cryptoInput;
} }
private boolean checkCancelled() { private boolean checkCancelled() {
@@ -329,8 +327,8 @@ public class PgpKeyOperation {
masterSecretKey.getEncoded(), new JcaKeyFingerprintCalculator()); masterSecretKey.getEncoded(), new JcaKeyFingerprintCalculator());
subProgressPush(50, 100); subProgressPush(50, 100);
mCryptoInput = new CryptoInputParcel(new Date(), new Passphrase("")); CryptoInputParcel cryptoInput = new CryptoInputParcel(new Date(), new Passphrase(""));
return internal(sKR, masterSecretKey, add.mFlags, add.mExpiry, saveParcel, log); return internal(sKR, masterSecretKey, add.mFlags, add.mExpiry, cryptoInput, saveParcel, log);
} catch (PGPException e) { } catch (PGPException e) {
log.add(LogType.MSG_CR_ERROR_INTERNAL_PGP, indent); log.add(LogType.MSG_CR_ERROR_INTERNAL_PGP, indent);
@@ -362,6 +360,7 @@ public class PgpKeyOperation {
* *
*/ */
public PgpEditKeyResult modifySecretKeyRing(CanonicalizedSecretKeyRing wsKR, public PgpEditKeyResult modifySecretKeyRing(CanonicalizedSecretKeyRing wsKR,
CryptoInputParcel cryptoInput,
SaveKeyringParcel saveParcel) { SaveKeyringParcel saveParcel) {
OperationLog log = new OperationLog(); OperationLog log = new OperationLog();
@@ -405,9 +404,9 @@ public class PgpKeyOperation {
} }
// Do we require a passphrase? If so, pass it along // Do we require a passphrase? If so, pass it along
if (!isDivertToCard(masterSecretKey) && !mCryptoInput.hasPassphrase()) { if (!isDivertToCard(masterSecretKey) && !cryptoInput.hasPassphrase()) {
return new PgpEditKeyResult(log, RequiredInputParcel.createRequiredPassphrase( return new PgpEditKeyResult(log, RequiredInputParcel.createRequiredPassphrase(
masterSecretKey.getKeyID(), mCryptoInput.getSignatureTime())); masterSecretKey.getKeyID(), cryptoInput.getSignatureTime()));
} }
// read masterKeyFlags, and use the same as before. // read masterKeyFlags, and use the same as before.
@@ -417,12 +416,13 @@ public class PgpKeyOperation {
Date expiryTime = wsKR.getPublicKey().getExpiryTime(); Date expiryTime = wsKR.getPublicKey().getExpiryTime();
long masterKeyExpiry = expiryTime != null ? expiryTime.getTime() / 1000 : 0L; long masterKeyExpiry = expiryTime != null ? expiryTime.getTime() / 1000 : 0L;
return internal(sKR, masterSecretKey, masterKeyFlags, masterKeyExpiry, saveParcel, log); return internal(sKR, masterSecretKey, masterKeyFlags, masterKeyExpiry, cryptoInput, saveParcel, log);
} }
private PgpEditKeyResult internal(PGPSecretKeyRing sKR, PGPSecretKey masterSecretKey, private PgpEditKeyResult internal(PGPSecretKeyRing sKR, PGPSecretKey masterSecretKey,
int masterKeyFlags, long masterKeyExpiry, int masterKeyFlags, long masterKeyExpiry,
CryptoInputParcel cryptoInput,
SaveKeyringParcel saveParcel, SaveKeyringParcel saveParcel,
OperationLog log) { OperationLog log) {
@@ -445,7 +445,7 @@ public class PgpKeyOperation {
{ {
try { try {
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(mCryptoInput.getPassphrase().getCharArray()); Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(cryptoInput.getPassphrase().getCharArray());
masterPrivateKey = masterSecretKey.extractPrivateKey(keyDecryptor); masterPrivateKey = masterSecretKey.extractPrivateKey(keyDecryptor);
} catch (PGPException e) { } catch (PGPException e) {
log.add(LogType.MSG_MF_UNLOCK_ERROR, indent + 1); log.add(LogType.MSG_MF_UNLOCK_ERROR, indent + 1);
@@ -507,8 +507,8 @@ public class PgpKeyOperation {
// generate and add new certificate // generate and add new certificate
try { try {
PGPSignature cert = generateUserIdSignature( PGPSignature cert = generateUserIdSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPrivateKey, masterPublicKey, userId, masterPrivateKey, masterPublicKey, userId,
isPrimary, masterKeyFlags, masterKeyExpiry); isPrimary, masterKeyFlags, masterKeyExpiry);
modifiedPublicKey = PGPPublicKey.addCertification(modifiedPublicKey, userId, cert); modifiedPublicKey = PGPPublicKey.addCertification(modifiedPublicKey, userId, cert);
@@ -543,8 +543,8 @@ public class PgpKeyOperation {
// generate and add new certificate // generate and add new certificate
try { try {
PGPSignature cert = generateUserAttributeSignature( PGPSignature cert = generateUserAttributeSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPrivateKey, masterPublicKey, vector); masterPrivateKey, masterPublicKey, vector);
modifiedPublicKey = PGPPublicKey.addCertification(modifiedPublicKey, vector, cert); modifiedPublicKey = PGPPublicKey.addCertification(modifiedPublicKey, vector, cert);
} catch (NfcInteractionNeeded e) { } catch (NfcInteractionNeeded e) {
@@ -579,8 +579,8 @@ public class PgpKeyOperation {
// take care of that here. // take care of that here.
try { try {
PGPSignature cert = generateRevocationSignature( PGPSignature cert = generateRevocationSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPrivateKey, masterPublicKey, userId); masterPrivateKey, masterPublicKey, userId);
modifiedPublicKey = PGPPublicKey.addCertification(modifiedPublicKey, userId, cert); modifiedPublicKey = PGPPublicKey.addCertification(modifiedPublicKey, userId, cert);
} catch (NfcInteractionNeeded e) { } catch (NfcInteractionNeeded e) {
@@ -657,8 +657,8 @@ public class PgpKeyOperation {
modifiedPublicKey, userId, currentCert); modifiedPublicKey, userId, currentCert);
try { try {
PGPSignature newCert = generateUserIdSignature( PGPSignature newCert = generateUserIdSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPrivateKey, masterPublicKey, userId, false, masterPrivateKey, masterPublicKey, userId, false,
masterKeyFlags, masterKeyExpiry); masterKeyFlags, masterKeyExpiry);
modifiedPublicKey = PGPPublicKey.addCertification( modifiedPublicKey = PGPPublicKey.addCertification(
@@ -680,8 +680,8 @@ public class PgpKeyOperation {
modifiedPublicKey, userId, currentCert); modifiedPublicKey, userId, currentCert);
try { try {
PGPSignature newCert = generateUserIdSignature( PGPSignature newCert = generateUserIdSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPrivateKey, masterPublicKey, userId, true, masterPrivateKey, masterPublicKey, userId, true,
masterKeyFlags, masterKeyExpiry); masterKeyFlags, masterKeyExpiry);
modifiedPublicKey = PGPPublicKey.addCertification( modifiedPublicKey = PGPPublicKey.addCertification(
@@ -777,7 +777,7 @@ public class PgpKeyOperation {
PGPPublicKey pKey = PGPPublicKey pKey =
updateMasterCertificates( updateMasterCertificates(
masterSecretKey, masterPrivateKey, masterPublicKey, masterSecretKey, masterPrivateKey, masterPublicKey,
flags, expiry, indent, log); flags, expiry, cryptoInput, indent, log);
if (pKey == null) { if (pKey == null) {
// error log entry has already been added by updateMasterCertificates itself // error log entry has already been added by updateMasterCertificates itself
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null); return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
@@ -816,11 +816,11 @@ public class PgpKeyOperation {
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder() PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder()
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(
mCryptoInput.getPassphrase().getCharArray()); cryptoInput.getPassphrase().getCharArray());
PGPPrivateKey subPrivateKey = sKey.extractPrivateKey(keyDecryptor); PGPPrivateKey subPrivateKey = sKey.extractPrivateKey(keyDecryptor);
PGPSignature sig = generateSubkeyBindingSignature( PGPSignature sig = generateSubkeyBindingSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPublicKey, masterPrivateKey, subPrivateKey, pKey, flags, expiry); masterPublicKey, masterPrivateKey, subPrivateKey, pKey, flags, expiry);
// generate and add new signature // generate and add new signature
@@ -849,8 +849,8 @@ public class PgpKeyOperation {
// generate and add new signature // generate and add new signature
try { try {
PGPSignature sig = generateRevocationSignature( PGPSignature sig = generateRevocationSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPublicKey, masterPrivateKey, pKey); masterPublicKey, masterPrivateKey, pKey);
pKey = PGPPublicKey.addCertification(pKey, sig); pKey = PGPPublicKey.addCertification(pKey, sig);
@@ -902,8 +902,8 @@ public class PgpKeyOperation {
PGPPublicKey pKey = keyPair.getPublicKey(); PGPPublicKey pKey = keyPair.getPublicKey();
try { try {
PGPSignature cert = generateSubkeyBindingSignature( PGPSignature cert = generateSubkeyBindingSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPublicKey, masterPrivateKey, keyPair.getPrivateKey(), pKey, masterPublicKey, masterPrivateKey, keyPair.getPrivateKey(), pKey,
add.mFlags, add.mExpiry); add.mFlags, add.mExpiry);
pKey = PGPPublicKey.addSubkeyBindingCertification(pKey, cert); pKey = PGPPublicKey.addSubkeyBindingCertification(pKey, cert);
@@ -919,7 +919,7 @@ public class PgpKeyOperation {
PgpConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc, PgpConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc,
PgpConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT) PgpConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT)
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build( .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(
mCryptoInput.getPassphrase().getCharArray()); cryptoInput.getPassphrase().getCharArray());
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder() PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder()
.build().get(PgpConstants.SECRET_KEY_SIGNATURE_CHECKSUM_HASH_ALGO); .build().get(PgpConstants.SECRET_KEY_SIGNATURE_CHECKSUM_HASH_ALGO);
@@ -947,7 +947,7 @@ public class PgpKeyOperation {
indent += 1; indent += 1;
sKR = applyNewUnlock(sKR, masterPublicKey, masterPrivateKey, sKR = applyNewUnlock(sKR, masterPublicKey, masterPrivateKey,
mCryptoInput.getPassphrase(), saveParcel.mNewUnlock, log, indent); cryptoInput.getPassphrase(), saveParcel.mNewUnlock, log, indent);
if (sKR == null) { if (sKR == null) {
// The error has been logged above, just return a bad state // The error has been logged above, just return a bad state
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null); return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
@@ -1149,7 +1149,7 @@ public class PgpKeyOperation {
PBESecretKeyEncryptor keyEncryptorNew = new JcePBESecretKeyEncryptorBuilder( PBESecretKeyEncryptor keyEncryptorNew = new JcePBESecretKeyEncryptorBuilder(
PgpConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc, PgpConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc,
PgpConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT) PgpConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT)
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.getCharArray()); .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(newPassphrase.getCharArray());
// noinspection unchecked // noinspection unchecked
for (PGPSecretKey sKey : new IterableIterator<PGPSecretKey>(sKR.getSecretKeys())) { for (PGPSecretKey sKey : new IterableIterator<PGPSecretKey>(sKR.getSecretKeys())) {
@@ -1203,7 +1203,9 @@ public class PgpKeyOperation {
private PGPPublicKey updateMasterCertificates( private PGPPublicKey updateMasterCertificates(
PGPSecretKey masterSecretKey, PGPPrivateKey masterPrivateKey, PGPSecretKey masterSecretKey, PGPPrivateKey masterPrivateKey,
PGPPublicKey masterPublicKey, PGPPublicKey masterPublicKey,
int flags, long expiry, int indent, OperationLog log) int flags, long expiry,
CryptoInputParcel cryptoInput,
int indent, OperationLog log)
throws PGPException, IOException, SignatureException { throws PGPException, IOException, SignatureException {
// keep track if we actually changed one // keep track if we actually changed one
@@ -1260,8 +1262,8 @@ public class PgpKeyOperation {
modifiedPublicKey, userId, currentCert); modifiedPublicKey, userId, currentCert);
try { try {
PGPSignature newCert = generateUserIdSignature( PGPSignature newCert = generateUserIdSignature(
getSignatureGenerator(masterSecretKey, mCryptoInput), getSignatureGenerator(masterSecretKey, cryptoInput),
mCryptoInput.getSignatureTime(), cryptoInput.getSignatureTime(),
masterPrivateKey, masterPublicKey, userId, isPrimary, flags, expiry); masterPrivateKey, masterPublicKey, userId, isPrimary, flags, expiry);
modifiedPublicKey = PGPPublicKey.addCertification( modifiedPublicKey = PGPPublicKey.addCertification(
modifiedPublicKey, userId, newCert); modifiedPublicKey, userId, newCert);