File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
main/java/org/bouncycastle/openpgp
test/java/org/bouncycastle/openpgp/test Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -323,6 +323,16 @@ public long getKeyID()
323323 return pub .getKeyID ();
324324 }
325325
326+ /**
327+ * Return the S2K usage associated with this key.
328+ *
329+ * @return the key's S2K usage
330+ */
331+ public int getS2KUsage ()
332+ {
333+ return secret .getS2KUsage ();
334+ }
335+
326336 /**
327337 * Return the S2K used to process this key
328338 *
@@ -682,6 +692,10 @@ public static PGPSecretKey copyWithNewPassword(
682692 }
683693 else
684694 {
695+ if (s2kUsage == SecretKeyPacket .USAGE_NONE )
696+ {
697+ s2kUsage = SecretKeyPacket .USAGE_CHECKSUM ;
698+ }
685699 if (key .secret .getPublicKeyPacket ().getVersion () < 4 )
686700 {
687701 // Version 2 or 3 - RSA Keys only
Original file line number Diff line number Diff line change 1111import javax .crypto .Cipher ;
1212
1313import org .bouncycastle .bcpg .HashAlgorithmTags ;
14+ import org .bouncycastle .bcpg .SecretKeyPacket ;
1415import org .bouncycastle .bcpg .SymmetricKeyAlgorithmTags ;
1516import org .bouncycastle .jce .provider .BouncyCastleProvider ;
1617import org .bouncycastle .jce .spec .ElGamalParameterSpec ;
@@ -2355,9 +2356,9 @@ private void rewrapTest()
23552356 // this should succeed
23562357 PGPPrivateKey privTmp = pgpKey .extractPrivateKey (null );
23572358
2358- if (pgpKey .getKeyID () != oldKeyID )
2359+ if (pgpKey .getKeyID () != oldKeyID || pgpKey . getS2KUsage () != SecretKeyPacket . USAGE_NONE )
23592360 {
2360- fail ("key ID mismatch" );
2361+ fail ("usage/ key ID mismatch" );
23612362 }
23622363 }
23632364
@@ -2379,9 +2380,9 @@ private void rewrapTest()
23792380 // this should succeed
23802381 PGPPrivateKey privTmp = pgpKey .extractPrivateKey (new JcePBESecretKeyDecryptorBuilder (new JcaPGPDigestCalculatorProviderBuilder ().setProvider ("BC" ).build ()).setProvider ("BC" ).build (newPass ));
23812382
2382- if (pgpKey .getKeyID () != oldKeyID )
2383+ if (pgpKey .getKeyID () != oldKeyID || pgpKey . getS2KUsage () != SecretKeyPacket . USAGE_CHECKSUM )
23832384 {
2384- fail ("key ID mismatch" );
2385+ fail ("usage/ key ID mismatch" );
23852386 }
23862387 }
23872388 }
You can’t perform that action at this time.
0 commit comments