Copy to ClipboardCopied!Toggle word wrapToggle overflow
[Netty4-UsingBasicSSL/TLSconfigurationontheJettyComponent]] Showty Component에서 기본 SSL/TLS 구성 사용
JndiRegistry registry = new JndiRegistry(createJndiContext());
registry.bind("password", "changeit");
registry.bind("ksf", new File("src/test/resources/keystore.jks"));
registry.bind("tsf", new File("src/test/resources/keystore.jks"));
context.createRegistry(registry);
context.addRoutes(new RouteBuilder() {
public void configure() {
String netty_ssl_endpoint =
"netty4:tcp://0.0.0.0:5150?sync=true&ssl=true&passphrase=#password"
+ "&keyStoreFile=#ksf&trustStoreFile=#tsf";
String return_string =
"When You Go Home, Tell Them Of Us And Say,"
+ "For Your Tomorrow, We Gave Our Today.";
from(netty_ssl_endpoint)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(return_string);
}
}
}
});
JndiRegistry registry = new JndiRegistry(createJndiContext());
registry.bind("password", "changeit");
registry.bind("ksf", new File("src/test/resources/keystore.jks"));
registry.bind("tsf", new File("src/test/resources/keystore.jks"));
context.createRegistry(registry);
context.addRoutes(new RouteBuilder() {
public void configure() {
String netty_ssl_endpoint =
"netty4:tcp://0.0.0.0:5150?sync=true&ssl=true&passphrase=#password"
+ "&keyStoreFile=#ksf&trustStoreFile=#tsf";
String return_string =
"When You Go Home, Tell Them Of Us And Say,"
+ "For Your Tomorrow, We Gave Our Today.";
from(netty_ssl_endpoint)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(return_string);
}
}
}
});
Copy to ClipboardCopied!Toggle word wrapToggle overflow
SSLSession 및 클라이언트 인증서에 액세스
클라이언트 인증서에 대한 세부 정보를 가져와야 하는 경우 javax.net.ssl.SSLSession 에 액세스할 수 있습니다. ssl=true 인 경우 Netty4 구성 요소는 다음과 같이 Camel Message의 헤더로 SSLSession 을 저장합니다.
SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class);
// get the first certificate which is client certificate
javax.security.cert.X509Certificate cert = session.getPeerCertificateChain()[0];
Principal principal = cert.getSubjectDN();
SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class);
// get the first certificate which is client certificate
javax.security.cert.X509Certificate cert = session.getPeerCertificateChain()[0];
Principal principal = cert.getSubjectDN();
Copy to ClipboardCopied!Toggle word wrapToggle overflow
클라이언트를 인증하기 위해 needClientAuth=true 를 설정해야 합니다. 그렇지 않으면 SSLSession 에서 클라이언트 인증서에 대한 정보에 액세스할 수 없으며 예외 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated. 클라이언트 인증서가 만료되었거나 유효하지 않은 경우에도 이 예외가 발생할 수 있습니다.
작은 정보
sslClientCertHeaders 옵션을 true 로 설정하면 Camel Message를 헤더로 보강하고 클라이언트 인증서에 대한 세부 정보가 있습니다. 예를 들어 제목 이름은 CamelNettySSLClientCertSubjectName 헤더에서 쉽게 사용할 수 있습니다.
특정 경우에는 netty 파이프라인에 인코더 및 디코더 체인을 추가해야 할 수 있습니다. camel netty 엔드포인트에 여러 개의 codecs를 추가하려면 'encoders' 및 'decoders' uri 매개 변수를 사용해야 합니다. 파이프라인에 추가해야 하는 참조( ChannelUpstreamHandler 및 ChannelDownstreamHandlers 목록)를 제공하는 데 사용되는 'encoder' 및 'decoder' 매개변수와 같이 사용됩니다. 인코더가 지정되면 인코더 매개변수가 무시되며 디코더 및 디코더 매개 변수가 무시됩니다.
참고
공유 불가능한 인코더/디코더/디코더를 사용하는 방법에 대해 자세히 알아보십시오.
엔드포인트를 생성할 때 이를 해결할 수 있도록 Camel의 레지스트리에 codecs 목록을 추가해야 합니다.
ChannelHandlerFactory lengthDecoder = ChannelHandlerFactories.newLengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4);
StringDecoder stringDecoder = new StringDecoder();
registry.bind("length-decoder", lengthDecoder);
registry.bind("string-decoder", stringDecoder);
LengthFieldPrepender lengthEncoder = new LengthFieldPrepender(4);
StringEncoder stringEncoder = new StringEncoder();
registry.bind("length-encoder", lengthEncoder);
registry.bind("string-encoder", stringEncoder);
List<ChannelHandler> decoders = new ArrayList<ChannelHandler>();
decoders.add(lengthDecoder);
decoders.add(stringDecoder);
List<ChannelHandler> encoders = new ArrayList<ChannelHandler>();
encoders.add(lengthEncoder);
encoders.add(stringEncoder);
registry.bind("encoders", encoders);
registry.bind("decoders", decoders);
ChannelHandlerFactory lengthDecoder = ChannelHandlerFactories.newLengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4);
StringDecoder stringDecoder = new StringDecoder();
registry.bind("length-decoder", lengthDecoder);
registry.bind("string-decoder", stringDecoder);
LengthFieldPrepender lengthEncoder = new LengthFieldPrepender(4);
StringEncoder stringEncoder = new StringEncoder();
registry.bind("length-encoder", lengthEncoder);
registry.bind("string-encoder", stringEncoder);
List<ChannelHandler> decoders = new ArrayList<ChannelHandler>();
decoders.add(lengthDecoder);
decoders.add(stringDecoder);
List<ChannelHandler> encoders = new ArrayList<ChannelHandler>();
encoders.add(lengthEncoder);
encoders.add(stringEncoder);
registry.bind("encoders", encoders);
registry.bind("decoders", decoders);
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Spring의 네이티브 컬렉션 지원을 사용하여 애플리케이션 컨텍스트에서 codec 목록을 지정할 수 있습니다.