package org.bouncycastle.crypto.tls;
import java.io.IOException;
public class PSKTlsClient
extends AbstractTlsClient
{
protected TlsDHVerifier dhVerifier;
protected TlsPSKIdentity pskIdentity;
public PSKTlsClient(TlsPSKIdentity pskIdentity)
{
this(new DefaultTlsCipherFactory(), pskIdentity);
}
public PSKTlsClient(TlsCipherFactory cipherFactory, TlsPSKIdentity pskIdentity)
{
this(cipherFactory, new DefaultTlsDHVerifier(), pskIdentity);
}
public PSKTlsClient(TlsCipherFactory cipherFactory, TlsDHVerifier dhVerifier, TlsPSKIdentity pskIdentity)
{
super(cipherFactory);
this.dhVerifier = dhVerifier;
this.pskIdentity = pskIdentity;
}
public int[] getCipherSuites()
{
return new int[]
{
CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256,
CipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
};
}
public TlsKeyExchange getKeyExchange() throws IOException
{
int keyExchangeAlgorithm = TlsUtils.getKeyExchangeAlgorithm(selectedCipherSuite);
switch (keyExchangeAlgorithm)
{
case KeyExchangeAlgorithm.DHE_PSK:
case KeyExchangeAlgorithm.ECDHE_PSK:
case KeyExchangeAlgorithm.PSK:
case KeyExchangeAlgorithm.RSA_PSK:
return createPSKKeyExchange(keyExchangeAlgorithm);
default:
throw new TlsFatalAlert(AlertDescription.internal_error);
}
}
public TlsAuthentication getAuthentication() throws IOException
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
protected TlsKeyExchange createPSKKeyExchange(int keyExchange)
{
return new TlsPSKKeyExchange(keyExchange, supportedSignatureAlgorithms, pskIdentity, null, dhVerifier, null,
namedCurves, clientECPointFormats, serverECPointFormats);
}
}