List of usage examples for java.security.cert X509Certificate getNotAfter
public abstract Date getNotAfter();
From source file:MainClass.java
public static void main(String args[]) throws Exception { FileInputStream fr = new FileInputStream("sdo.cer"); CertificateFactory cf = CertificateFactory.getInstance("X509"); X509Certificate c = (X509Certificate) cf.generateCertificate(fr); System.out.println("\tCertificate for: " + c.getSubjectDN()); System.out.println("\tCertificate issued by: " + c.getIssuerDN()); System.out.println("\tThe certificate is valid from " + c.getNotBefore() + " to " + c.getNotAfter()); System.out.println("\tCertificate SN# " + c.getSerialNumber()); System.out.println("\tGenerated with " + c.getSigAlgName()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { CertificateFactory cf = CertificateFactory.getInstance("X.509"); FileInputStream in = new FileInputStream(args[0]); java.security.cert.Certificate c = cf.generateCertificate(in); in.close();/*from w ww . jav a 2 s . co m*/ X509Certificate t = (X509Certificate) c; System.out.println(t.getVersion()); System.out.println(t.getSerialNumber().toString(16)); System.out.println(t.getSubjectDN()); System.out.println(t.getIssuerDN()); System.out.println(t.getNotBefore()); System.out.println(t.getNotAfter()); System.out.println(t.getSigAlgName()); byte[] sig = t.getSignature(); System.out.println(new BigInteger(sig).toString(16)); PublicKey pk = t.getPublicKey(); byte[] pkenc = pk.getEncoded(); for (int i = 0; i < pkenc.length; i++) { System.out.print(pkenc[i] + ","); } }
From source file:org.rhq.enterprise.server.plugins.rhnhosted.RHNSSLCertReader.java
static public void main(String[] args) { if (args.length < 1) { System.out.println("Please re-run and specify an argument for the location of a RHN SSL Cert."); System.exit(0);//w w w. ja v a 2s . co m } String path = args[0]; System.out.println("path is " + path); String rawCert = null; try { rawCert = FileUtils.readFileToString(new File(path)); } catch (IOException e) { e.printStackTrace(); System.exit(0); } List<String> certs = RHNSSLCertReader.getCertText(rawCert); for (String cert : certs) { System.out.println("Parsed SSL Certificate: \n" + cert); } List<X509Certificate> sslCerts = new ArrayList<X509Certificate>(); try { sslCerts = getSSLCertificates(rawCert); } catch (CertificateException e) { e.printStackTrace(); System.exit(0); } for (X509Certificate c : sslCerts) { System.out.println("Cert SigAlgName = " + c.getSigAlgName()); System.out.println("Cert IssuerDN = " + c.getIssuerDN()); System.out.println("Cert NotAfter = " + c.getNotAfter()); System.out.println("Cert NotBefore = " + c.getNotBefore()); System.out.println("Cert PublicKey = " + c.getPublicKey()); System.out.println("Cert SubjectDN = " + c.getSubjectDN()); } }
From source file:Main.java
private static boolean verifyCertificateValidity(X509Certificate certificate) throws CertificateException { if (certificate != null) { if (certificate.getNotAfter().compareTo(new Date(System.currentTimeMillis())) >= 0) { return true; }//ww w. j a v a 2 s. co m throw new CertificateException("Certificate has expired and is not valid for signing document."); } return false; }
From source file:org.dcache.webdav.transfer.CredentialServiceClient.java
private static long calculateRemainingLifetime(X509Certificate[] certificates) { long earliestExpiry = Long.MAX_VALUE; for (X509Certificate certificate : certificates) { earliestExpiry = Math.min(earliestExpiry, certificate.getNotAfter().getTime()); }/*from w ww.jav a 2 s.com*/ long now = System.currentTimeMillis(); return (earliestExpiry <= now) ? 0 : earliestExpiry - now; }
From source file:net.ripe.rpki.commons.crypto.x509cert.X509CertificateUtil.java
public static ValidityPeriod getValidityPeriod(X509Certificate certificate) { return new ValidityPeriod(certificate.getNotBefore(), certificate.getNotAfter()); }
From source file:org.openhealthtools.openatna.net.ConnectionCertificateHandler.java
/** * For debuging only. Prints out keystore certificate chain. * * @param keystore Keystore to print out. * @throws KeyStoreException If the keystore is broken. *///from ww w .j a va 2 s . com public static void printTrustCerts(KeyStore keystore) throws KeyStoreException { Enumeration<String> aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); String message = "Trusted certificate '" + alias + "':"; Certificate trustedcert = keystore.getCertificate(alias); if (trustedcert != null && trustedcert instanceof X509Certificate) { X509Certificate cert = (X509Certificate) trustedcert; message += "\n Subject DN: " + cert.getSubjectDN(); message += "\n Signature Algorithm: " + cert.getSigAlgName(); message += "\n Valid from: " + cert.getNotBefore(); message += "\n Valid until: " + cert.getNotAfter(); message += "\n Issuer: " + cert.getIssuerDN(); } log.info(message); } }
From source file:org.apache.hadoop.hdfsproxy.ProxyUtil.java
static void checkServerCertsExpirationDays(Configuration conf, String hostname, int port) throws IOException { setupSslProps(conf);// w w w .j a v a 2s . c o m HttpsURLConnection connection = null; connection = openConnection(hostname, port, null); connection.connect(); X509Certificate[] serverCerts = (X509Certificate[]) connection.getServerCertificates(); Date curDate = new Date(); long curTime = curDate.getTime(); if (serverCerts != null) { for (X509Certificate cert : serverCerts) { StringBuffer sb = new StringBuffer(); sb.append("\n Server certificate Subject Name: " + cert.getSubjectX500Principal().getName()); Date expDate = cert.getNotAfter(); long expTime = expDate.getTime(); int dayOffSet = (int) ((expTime - curTime) / MM_SECONDS_PER_DAY); sb.append(" have " + dayOffSet + " days to expire"); if (dayOffSet < CERT_EXPIRATION_WARNING_THRESHOLD) LOG.warn(sb.toString()); else LOG.info(sb.toString()); } } else { LOG.info("\n No Server certs was found"); } if (connection != null) { connection.disconnect(); } }
From source file:org.glite.slcs.httpclient.ssl.ExtendedX509TrustManager.java
static private void dumpCertificate(X509Certificate cert) { LOG.debug("Certificate:"); LOG.debug(" Subject: " + cert.getSubjectDN()); LOG.debug(" Issuer: " + cert.getIssuerDN()); LOG.debug(" Valid from: " + cert.getNotBefore()); LOG.debug(" Valid until: " + cert.getNotAfter()); LOG.debug(" Fingerprint: " + getCertificateFingerprint(cert, "MD5")); }
From source file:org.openhealthtools.openatna.net.ConnectionCertificateHandler.java
/** * For debuging only. Prints out keystore certificate chain. * * @param keystore Keystore to print out. * @throws KeyStoreException If the keystore is broken. *//*from w w w . j a va2 s . com*/ public static void printKeyCertificates(KeyStore keystore) throws KeyStoreException { Enumeration<String> aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); Certificate[] certs = keystore.getCertificateChain(alias); if (certs != null) { String message = "Certificate chain '" + alias + "':"; int i = 1; for (Certificate cert : certs) { if (cert instanceof X509Certificate) { X509Certificate Xcert = (X509Certificate) cert; message += "\n Certificate " + i++ + ":"; message += "\n Subject DN: " + Xcert.getSubjectDN(); message += "\n Signature Algorithm: " + Xcert.getSigAlgName(); message += "\n Valid from: " + Xcert.getNotBefore(); message += "\n Valid until: " + Xcert.getNotAfter(); message += "\n Issuer: " + Xcert.getIssuerDN(); } } log.info(message); } } }