com.fitbur.bouncycastle.crypto.tls.SessionParameters Maven / Gradle / Ivy
package com.fitbur.bouncycastle.crypto.tls;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import com.fitbur.bouncycastle.util.Arrays;
public final class SessionParameters
{
public static final class Builder
{
private int cipherSuite = -1;
private short com.fitburpressionAlgorithm = -1;
private byte[] masterSecret = null;
private Certificate peerCertificate = null;
private byte[] encodedServerExtensions = null;
public Builder()
{
}
public SessionParameters build()
{
validate(this.cipherSuite >= 0, "cipherSuite");
validate(this.com.fitburpressionAlgorithm >= 0, "com.fitburpressionAlgorithm");
validate(this.masterSecret != null, "masterSecret");
return new SessionParameters(cipherSuite, com.fitburpressionAlgorithm, masterSecret, peerCertificate,
encodedServerExtensions);
}
public Builder setCipherSuite(int cipherSuite)
{
this.cipherSuite = cipherSuite;
return this;
}
public Builder setCompressionAlgorithm(short com.fitburpressionAlgorithm)
{
this.com.fitburpressionAlgorithm = com.fitburpressionAlgorithm;
return this;
}
public Builder setMasterSecret(byte[] masterSecret)
{
this.masterSecret = masterSecret;
return this;
}
public Builder setPeerCertificate(Certificate peerCertificate)
{
this.peerCertificate = peerCertificate;
return this;
}
public Builder setServerExtensions(Hashtable serverExtensions)
throws IOException
{
if (serverExtensions == null)
{
encodedServerExtensions = null;
}
else
{
ByteArrayOutputStream buf = new ByteArrayOutputStream();
TlsProtocol.writeExtensions(buf, serverExtensions);
encodedServerExtensions = buf.toByteArray();
}
return this;
}
private void validate(boolean condition, String parameter)
{
if (!condition)
{
throw new IllegalStateException("Required session parameter '" + parameter + "' not configured");
}
}
}
private int cipherSuite;
private short com.fitburpressionAlgorithm;
private byte[] masterSecret;
private Certificate peerCertificate;
private byte[] encodedServerExtensions;
private SessionParameters(int cipherSuite, short com.fitburpressionAlgorithm, byte[] masterSecret,
Certificate peerCertificate, byte[] encodedServerExtensions)
{
this.cipherSuite = cipherSuite;
this.com.fitburpressionAlgorithm = com.fitburpressionAlgorithm;
this.masterSecret = Arrays.clone(masterSecret);
this.peerCertificate = peerCertificate;
this.encodedServerExtensions = encodedServerExtensions;
}
public void clear()
{
if (this.masterSecret != null)
{
Arrays.fill(this.masterSecret, (byte)0);
}
}
public SessionParameters copy()
{
return new SessionParameters(cipherSuite, com.fitburpressionAlgorithm, masterSecret, peerCertificate,
encodedServerExtensions);
}
public int getCipherSuite()
{
return cipherSuite;
}
public short getCompressionAlgorithm()
{
return com.fitburpressionAlgorithm;
}
public byte[] getMasterSecret()
{
return masterSecret;
}
public Certificate getPeerCertificate()
{
return peerCertificate;
}
public Hashtable readServerExtensions() throws IOException
{
if (encodedServerExtensions == null)
{
return null;
}
ByteArrayInputStream buf = new ByteArrayInputStream(encodedServerExtensions);
return TlsProtocol.readExtensions(buf);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy