Code example for CertPath

Methods: getCertificates

0
		      CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
		      cp = cf.generateCertPath(stream, "PEM");
		    } finally { 
		      stream.close();
		    } 
		    List<? extends Certificate> certs = cp.getCertificates();
		    if (certs.size() < 1) {
		      throw new CertificateException("Certificate list is empty");
		    } else if (certs.size() > 1) {
		      throw new CertificateException("Intermediate certificate is not allowed");
		    } 
		    if (certs.get(0) instanceof X509Certificate) {
		      X509Certificate cert = (X509Certificate)certs.get(0);
		      cert.checkValidity();
		      return cert;
		    } else { 
		      throw new CertificateException("Certificate is not X509Certificate");
		    } 
		  }