use of org.jboss.netty.handler.ssl.util.SelfSignedCertificate in project graylog2-server by Graylog2.
the class AbstractTcpTransport method getBaseChannelHandlers.
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> baseChannelHandlers = super.getBaseChannelHandlers(input);
final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = Maps.newLinkedHashMap();
baseChannelHandlers.put("connection-counter", Callables.returning(connectionCounter));
if (!tlsEnable) {
return baseChannelHandlers;
}
if (!tlsCertFile.exists() || !tlsKeyFile.exists()) {
LOG.warn("TLS key file or certificate file does not exist, creating a self-signed certificate for input [{}/{}].", input.getName(), input.getId());
final String tmpDir = System.getProperty("java.io.tmpdir");
checkState(tmpDir != null, "The temporary directory must not be null!");
final Path tmpPath = Paths.get(tmpDir);
if (!Files.isDirectory(tmpPath) || !Files.isWritable(tmpPath)) {
throw new IllegalStateException("Couldn't write to temporary directory: " + tmpPath.toAbsolutePath());
}
try {
final SelfSignedCertificate ssc = new SelfSignedCertificate(configuration.getString(CK_BIND_ADDRESS) + ":" + configuration.getString(CK_PORT));
tlsCertFile = ssc.certificate();
tlsKeyFile = ssc.privateKey();
} catch (CertificateException e) {
LOG.error(String.format(Locale.ENGLISH, "Problem creating a self-signed certificate for input [%s/%s].", input.getName(), input.getId()), e);
return baseChannelHandlers;
}
}
if (tlsCertFile.exists() && tlsKeyFile.exists()) {
handlerList.put("tls", buildSslHandlerCallable());
}
LOG.info("Enabled TLS for input [{}/{}]. key-file=\"{}\" cert-file=\"{}\"", input.getName(), input.getId(), tlsKeyFile, tlsCertFile);
handlerList.putAll(baseChannelHandlers);
return handlerList;
}
Aggregations