package org.glassfish.grizzly.ssl;
import java.io.IOException;
import java.util.concurrent.Future;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.Codec;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.Transformer;
public class SSLCodec implements Codec<Buffer, Buffer> {
private final SSLEngineConfigurator ;
private final SSLEngineConfigurator clientSSLEngineConfig;
private final Transformer<Buffer, Buffer> decoder;
private final Transformer<Buffer, Buffer> encoder;
public SSLCodec(SSLContextConfigurator config) {
this(config.createSSLContext(true));
}
public SSLCodec(SSLContext sslContext) {
decoder = new SSLDecoderTransformer();
encoder = new SSLEncoderTransformer();
serverSSLEngineConfig = new SSLEngineConfigurator(sslContext, false, false, false);
clientSSLEngineConfig = new SSLEngineConfigurator(sslContext, true, false, false);
}
@Override
public Transformer<Buffer, Buffer> getDecoder() {
return decoder;
}
@Override
public Transformer<Buffer, Buffer> getEncoder() {
return encoder;
}
public SSLEngineConfigurator getClientSSLEngineConfig() {
return clientSSLEngineConfig;
}
public SSLEngineConfigurator () {
return serverSSLEngineConfig;
}
public Future<SSLEngine> handshake(Connection connection) throws IOException {
return handshake(connection, clientSSLEngineConfig);
}
public Future<SSLEngine> handshake(Connection connection, SSLEngineConfigurator configurator) throws IOException {
return null;
}
}