1 18 19 package org.apache.activemq.transport.tcp; 20 21 import org.apache.activemq.command.Command; 22 import org.apache.activemq.command.ConnectionInfo; 23 import org.apache.activemq.wireformat.WireFormat; 24 25 import java.io.IOException ; 26 import java.net.URI ; 27 import java.net.UnknownHostException ; 28 import java.security.cert.X509Certificate ; 29 30 import javax.net.ssl.SSLPeerUnverifiedException; 31 import javax.net.ssl.SSLSession; 32 import javax.net.ssl.SSLSocket; 33 import javax.net.ssl.SSLSocketFactory; 34 35 45 public class SslTransport extends TcpTransport { 46 59 public SslTransport(WireFormat wireFormat, SSLSocketFactory socketFactory, URI remoteLocation, URI localLocation, boolean needClientAuth) throws IOException { 60 super(wireFormat, socketFactory, remoteLocation, localLocation); 61 if (this.socket != null) { 62 ((SSLSocket)this.socket).setNeedClientAuth(needClientAuth); 63 } 64 } 65 66 76 public SslTransport(WireFormat wireFormat, SSLSocket socket) throws IOException { 77 super(wireFormat, socket); 78 } 79 80 85 public void doConsume(Command command) { 86 if ( command instanceof ConnectionInfo ) { 90 ConnectionInfo connectionInfo = (ConnectionInfo)command; 91 92 SSLSocket sslSocket = (SSLSocket)this.socket; 93 94 SSLSession sslSession = sslSocket.getSession(); 95 96 X509Certificate [] clientCertChain; 97 try { 98 clientCertChain = 99 (X509Certificate []) sslSession.getPeerCertificates(); 100 } catch(SSLPeerUnverifiedException e) { 101 clientCertChain = null; 102 } 103 104 connectionInfo.setTransportContext(clientCertChain); 105 } 106 107 super.doConsume(command); 108 } 109 110 113 public String toString() { 114 return "ssl://"+socket.getInetAddress()+":"+socket.getPort(); 115 } 116 117 } 118 119 | Popular Tags |