Skip to content

Instantly share code, notes, and snippets.

@edpichler
Created January 29, 2014 10:48
Show Gist options
  • Save edpichler/8685637 to your computer and use it in GitHub Desktop.
Save edpichler/8685637 to your computer and use it in GitHub Desktop.
Ler certificado digital em Java
publicclass LerCertificado extends HttpServlet {
protectedvoid doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("");
out.println("ServletLerCertificado");
out.println("");
out.println("Certificado digital:");
String cipherSuite = (String) request.getAttribute("javax.servlet.request.cipher_suite");
if (cipherSuite != null) {
java.security.cert.X509Certificate certChain[] = (java.security.cert.X509Certificate[])
request.getAttribute("javax.servlet.request.X509Certificate");
System.out.println("Array size: " + certChain.length);
if (certChain != null) {
for (int i = 0; i < certChain.length; i++) {
String certInfo = "Client Certificate [" + i + "] = " + certChain[i].toString();
out.println(certInfo);
}
}
} else {
out.println("Cliente sem Certificado Digital");
}
out.println("");//new line
out.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment