protected java.security.cert.X509Certificate[] getX509Certificates(SSLSession session)
			throws IOException {
		Certificate[] certs = null;
		try {
			certs = session.getPeerCertificates();
		} catch (Throwable t) {
			log.debug("Error getting client certs", t);
			return null;
		}
		if (certs == null)
			return null;

		java.security.cert.X509Certificate[] x509Certs = new java.security.cert.X509Certificate[certs.length];
		for (int i = 0; i < certs.length; i++) {
			if (certs[i] instanceof java.security.cert.X509Certificate) {
				// always currently true with the JSSE 1.1.x
				x509Certs[i] = (java.security.cert.X509Certificate) certs[i];
			} else {
				try {
					byte[] buffer = certs[i].getEncoded();
					CertificateFactory cf = CertificateFactory.getInstance("X.509");
					ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
					x509Certs[i] = (java.security.cert.X509Certificate) cf
							.generateCertificate(stream);
				} catch (Exception ex) {
					log.info("Error translating cert " + certs[i], ex);
					return null;
				}
			}
			if (log.isTraceEnabled())
				log.trace("Cert #" + i + " = " + x509Certs[i]);
		}
		if (x509Certs.length < 1)
			return null;
		return x509Certs;
	}