Skip to content

Commit 7626743

Browse files
committed
added support for PKCS#11 alt provider for EC TLS 1.3
1 parent ff55bc9 commit 7626743

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tls/src/main/java/org/bouncycastle/tls/crypto/impl/jcajce/JcaTlsCrypto.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,11 @@ public JcaJceHelper getHelper()
12621262
return helper;
12631263
}
12641264

1265+
public JcaJceHelper getAltHelper()
1266+
{
1267+
return altHelper;
1268+
}
1269+
12651270
protected TlsBlockCipherImpl createCBCBlockCipherImpl(TlsCryptoParameters cryptoParams, String algorithm,
12661271
int cipherKeySize, boolean forEncryption)
12671272
throws GeneralSecurityException

tls/src/main/java/org/bouncycastle/tls/crypto/impl/jcajce/JcaTlsECDSA13Signer.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.security.GeneralSecurityException;
5+
import java.security.InvalidKeyException;
56
import java.security.PrivateKey;
67
import java.security.Signature;
78

@@ -57,6 +58,21 @@ public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] h
5758
signer.update(hash, 0, hash.length);
5859
return signer.sign();
5960
}
61+
catch (InvalidKeyException e)
62+
{
63+
// try with PKCS#11 (usually) alternative provider
64+
try
65+
{
66+
Signature signer = crypto.getAltHelper().createSignature("NoneWithECDSA");
67+
signer.initSign(privateKey, crypto.getSecureRandom());
68+
signer.update(hash, 0, hash.length);
69+
return signer.sign();
70+
}
71+
catch (GeneralSecurityException ex)
72+
{
73+
throw new TlsFatalAlert(AlertDescription.internal_error, ex);
74+
}
75+
}
6076
catch (GeneralSecurityException e)
6177
{
6278
throw new TlsFatalAlert(AlertDescription.internal_error, e);

0 commit comments

Comments
 (0)