Support non-raw verification of server key exchange
import org.bouncycastle.tls.crypto.TlsHash;
import org.bouncycastle.tls.crypto.TlsSecret;
import org.bouncycastle.tls.crypto.TlsStreamSigner;
+import org.bouncycastle.tls.crypto.TlsStreamVerifier;
import org.bouncycastle.tls.crypto.TlsVerifier;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Integers;
@@ -1112,14 +1113,14 @@ public static ASN1ObjectIdentifier getOIDForHashAlgorithm(short hashAlgorithm)
return h.calculateHash();
}
- static void sendSignatureInput(TlsContext context, DigestInputBuffer buf, TlsStreamSigner streamSigner)
+ static void sendSignatureInput(TlsContext context, DigestInputBuffer buf, OutputStream output)
throws IOException
{
SecurityParameters securityParameters = context.getSecurityParameters();
- OutputStream output = streamSigner.getOutputStream();
// NOTE: The implicit copy here is intended (and important)
output.write(Arrays.concatenate(securityParameters.clientRandom, securityParameters.serverRandom));
buf.copyTo(output);
+ output.close();
}
static DigitallySigned generateCertificateVerify(TlsContext context, TlsCredentialedSigner credentialedSigner,
@@ -1167,7 +1168,7 @@ static DigitallySigned generateServerKeyExchangeSignature(TlsContext context, Tl
byte[] signature;
if (streamSigner != null)
{
- sendSignatureInput(context, buf, streamSigner);
+ sendSignatureInput(context, buf, streamSigner.getOutputStream());
signature = streamSigner.getSignature();
}
else
@@ -1181,10 +1182,22 @@ static DigitallySigned generateServerKeyExchangeSignature(TlsContext context, Tl
static void verifyServerKeyExchangeSignature(TlsContext context, TlsVerifier tlsVerifier, DigestInputBuffer buf,
DigitallySigned signedParams) throws IOException
+ {
+ TlsStreamVerifier streamVerifier = tlsVerifier.getStreamVerifier(signedParams);
+
+ boolean verified;
+ if (streamVerifier != null)
+ {
+ sendSignatureInput(context, buf, streamVerifier.getOutputStream());
+ verified = streamVerifier.isVerified();
+ }
+ else
{
byte[] hash = TlsUtils.calculateSignatureHash(context, signedParams.getAlgorithm(), buf);
+ verified = tlsVerifier.verifyRawSignature(signedParams, hash);
+ }
- if (!tlsVerifier.verifyRawSignature(signedParams, hash))
+ if (!verified)
{
throw new TlsFatalAlert(AlertDescription.decrypt_error);
}
