org.bouncycastle.tls.HandshakeMessageOutput Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bctls-fips Show documentation
Show all versions of bctls-fips Show documentation
The Bouncy Castle Java APIs for the TLS, including a JSSE provider. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.
package org.bouncycastle.tls;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
class HandshakeMessageOutput
extends ByteArrayOutputStream
{
static int getLength(int bodyLength)
{
return 4 + bodyLength;
}
static void send(TlsProtocol protocol, short handshakeType, byte[] body)
throws IOException
{
HandshakeMessageOutput message = new HandshakeMessageOutput(handshakeType, body.length);
message.write(body);
message.send(protocol);
}
HandshakeMessageOutput(short handshakeType) throws IOException
{
this(handshakeType, 60);
}
HandshakeMessageOutput(short handshakeType, int bodyLength) throws IOException
{
super(getLength(bodyLength));
TlsUtils.checkUint8(handshakeType);
TlsUtils.writeUint8(handshakeType, this);
// Reserve space for length
count += 3;
}
void send(TlsProtocol protocol) throws IOException
{
// Patch actual length back in
int bodyLength = count - 4;
TlsUtils.checkUint24(bodyLength);
TlsUtils.writeUint24(bodyLength, buf, 1);
protocol.writeHandshakeMessage(buf, 0, count);
buf = null;
}
void prepareClientHello(TlsHandshakeHash handshakeHash, int bindersSize) throws IOException
{
// Patch actual length back in
int bodyLength = count - 4 + bindersSize;
TlsUtils.checkUint24(bodyLength);
TlsUtils.writeUint24(bodyLength, buf, 1);
handshakeHash.update(buf, 0, count);
}
void sendClientHello(TlsClientProtocol clientProtocol, TlsHandshakeHash handshakeHash, int bindersSize)
throws IOException
{
if (bindersSize > 0)
{
handshakeHash.update(buf, count - bindersSize, bindersSize);
}
clientProtocol.writeHandshakeMessage(buf, 0, count);
buf = null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy