if (!(actual.getSocket() instanceof SSLSocket))
return;
SSLSocket socket = (SSLSocket) actual.getSocket();
// Look up the current SSLSession
SSLSession session = socket.getSession();
if (session == null)
return;
// if (debug >= 2)
// log(" expose: Has current SSLSession");
// Expose the cipher suite and key size
String cipherSuite = session.getCipherSuite();
if (cipherSuite != null)
request.getRequest().setAttribute(Globals.CIPHER_SUITE_ATTR,
cipherSuite);
Integer keySize = (Integer) session.getValue(Globals.KEY_SIZE_ATTR);
if (keySize == null) {
int size = 0;
for (int i = 0; i < ciphers.length; i++) {
if (cipherSuite.indexOf(ciphers[i].phrase) >= 0) {
size = ciphers[i].keySize;
break;
}
}
keySize = new Integer(size);
session.putValue(Globals.KEY_SIZE_ATTR, keySize);
}
request.getRequest().setAttribute(Globals.KEY_SIZE_ATTR,
keySize);
// if (debug >= 2)
// log(" expose: Has cipher suite " + cipherSuite +
// " and key size " + keySize);
// Expose ssl_session (getId)
byte [] ssl_session = session.getId();
if (ssl_session!=null) {
StringBuffer buf=new StringBuffer("");
for(int x=0; x<ssl_session.length; x++) {
String digit=Integer.toHexString((int)ssl_session[x]);
if (digit.length()<2) buf.append('0');
if (digit.length()>2) digit=digit.substring(digit.length()-2);
buf.append(digit);
}
request.getRequest().setAttribute(
"javax.servlet.request.ssl_session",
buf.toString());
}
// If we have cached certificates, return them
Object cached = session.getValue(Globals.CERTIFICATES_ATTR);
if (cached != null) {
// if (debug >= 2)
// log(" expose: Has cached certificates");
request.getRequest().setAttribute(Globals.CERTIFICATES_ATTR,
cached);
return;
}
// Convert JSSE's certificate format to the ones we need
X509Certificate jsseCerts[] = null;
java.security.cert.X509Certificate x509Certs[] = null;
try {
jsseCerts = session.getPeerCertificateChain();
if (jsseCerts == null)
jsseCerts = new X509Certificate[0];
x509Certs =
new java.security.cert.X509Certificate[jsseCerts.length];
for (int i = 0; i < x509Certs.length; i++) {
byte buffer[] = jsseCerts[i].getEncoded();
CertificateFactory cf =
CertificateFactory.getInstance("X.509");
ByteArrayInputStream stream =
new ByteArrayInputStream(buffer);
x509Certs[i] = (java.security.cert.X509Certificate)
cf.generateCertificate(stream);
}
} catch (Throwable t) {
return;
}
// Expose these certificates as a request attribute
if ((x509Certs == null) || (x509Certs.length < 1))
return;
session.putValue(Globals.CERTIFICATES_ATTR, x509Certs);
log(" expose: Exposing converted certificates");
request.getRequest().setAttribute(Globals.CERTIFICATES_ATTR,
x509Certs);
}