Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,10 @@ protected synchronized byte[] engineSign() throws SignatureException {
"Invalid signature algorithm type");
}

} catch (WolfCryptException e) {
throw new SignatureException(keyTypeToString(this.keyType) +
" sign failed: " + e.getMessage(), e);

} finally {
/* Zeroize message digest and DER encoding before refs drop */
zeroArray(digest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.wolfssl.wolfcrypt.Rsa;
import com.wolfssl.wolfcrypt.Fips;
import com.wolfssl.wolfcrypt.FeatureDetect;
import com.wolfssl.wolfcrypt.WolfCryptException;
import com.wolfssl.provider.jce.WolfCryptProvider;
import com.wolfssl.wolfcrypt.test.TimedTestWatcher;

Expand Down Expand Up @@ -2205,6 +2206,41 @@ public void testRsaPssRejectsUnsupportedMgf1Digest()
}
}

@Test
public void testRsaPssSignNativeErrorThrowsSignatureException()
throws Exception {

if (!enabledAlgos.contains("RSASSA-PSS") ||
!com.wolfssl.wolfcrypt.FeatureDetect.RsaPssEnabled()) {
/* Skip if RSA-PSS not enabled at JCE or native level */
return;
}

byte[] toSignBuf = "Everyone gets Friday off.".getBytes();

KeyPair pair = rsaPair;
assertNotNull(pair);

/* Salt as long as the modulus, native sign rejects on all builds */
int saltLen =
((RSAKey)pair.getPrivate()).getModulus().bitLength() / 8;

Signature signer = Signature.getInstance("RSASSA-PSS", "wolfJCE");
signer.setParameter(new PSSParameterSpec("SHA-256", "MGF1",
MGF1ParameterSpec.SHA256, saltLen, 1));
signer.initSign(pair.getPrivate());
signer.update(toSignBuf, 0, toSignBuf.length);

try {
signer.sign();
fail("Should throw SignatureException on native sign error");

} catch (SignatureException e) {
assertTrue("Native error should be preserved as cause",
e.getCause() instanceof WolfCryptException);
}
}

@Test
public void testRsaPssMultipleUpdates()
throws Exception {
Expand Down
Loading