use of java.security.cert.CertPath in project keystore-explorer by kaikramer.
the class X509CertUtil method getCertsEncodedPkiPath.
/**
* PKI Path encode a number of certificates.
*
* @return The encoding
* @param certs
* The certificates
* @throws CryptoException
* If there was a problem encoding the certificates
*/
public static byte[] getCertsEncodedPkiPath(X509Certificate[] certs) throws CryptoException {
try {
ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>();
Collections.addAll(encodedCerts, certs);
CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
CertPath cp = cf.generateCertPath(encodedCerts);
return cp.getEncoded(PKI_PATH_ENCODING);
} catch (CertificateException | NoSuchProviderException e) {
throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
}
}
use of java.security.cert.CertPath in project j2objc by google.
the class CertificateFactory3Test method testGenerateCertPath02.
/**
* Test for
* <code>generateCertPath(InputStream inStream, String encoding)</code>
* method Assertion: returns CertPath with 1 Certificate
*/
public void testGenerateCertPath02() throws Exception {
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
for (int i = 0; i < certFs.length; i++) {
CertPath certPath = null;
InputStream fis = Support_Resources.getResourceStream(fileCertPathPki);
certPath = certFs[i].generateCertPath(fis, "PkiPath");
fis.close();
assertEquals(defaultType, certPath.getType());
List<? extends Certificate> list1 = certPath.getCertificates();
assertFalse("Result list is empty", list1.isEmpty());
}
}
use of java.security.cert.CertPath in project j2objc by google.
the class CertificateFactory3Test method testGenerateCertPath01.
/**
* Test for <code>generateCertPath(List certificates)</code> method
* Assertion: returns CertPath with 1 Certificate
*/
public void testGenerateCertPath01() throws Exception {
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
// create list of certificates with one certificate
Certificate cert = certFs[0].generateCertificate(new ByteArrayInputStream(TestUtils.getEncodedX509Certificate()));
List<Certificate> list = new Vector<Certificate>();
list.add(cert);
for (int i = 0; i < certFs.length; i++) {
CertPath certPath = null;
certPath = certFs[i].generateCertPath(list);
assertEquals(cert.getType(), certPath.getType());
List<? extends Certificate> list1 = certPath.getCertificates();
assertFalse("Result list is empty", list1.isEmpty());
Iterator<? extends Certificate> it = list1.iterator();
assertEquals("Incorrect Certificate in CertPath", cert, it.next());
}
}
use of java.security.cert.CertPath in project j2objc by google.
the class CertificateFactory3Test method testGenerateCertPath03.
/**
* Test for <code>generateCertPath(InputStream inStream)</code> method
* Assertion: returns CertPath with 1 Certificate
*/
public void testGenerateCertPath03() throws Exception {
String certPathEncoding = "PkiPath";
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
for (int i = 0; i < certFs.length; i++) {
Iterator<String> it = certFs[0].getCertPathEncodings();
assertTrue("no CertPath encodings", it.hasNext());
assertEquals("Incorrect default encoding", certPathEncoding, it.next());
CertPath certPath = null;
InputStream fis = Support_Resources.getResourceStream(fileCertPathPki);
certPath = certFs[i].generateCertPath(fis);
fis.close();
assertEquals(defaultType, certPath.getType());
List<? extends Certificate> list1 = certPath.getCertificates();
assertFalse("Result list is empty", list1.isEmpty());
}
}
use of java.security.cert.CertPath in project j2objc by google.
the class SignatureFileVerifier method getTimestamp.
/*
* Examines a signature timestamp token to generate a timestamp object.
*
* Examines the signer's unsigned attributes for a
* <tt>signatureTimestampToken</tt> attribute. If present,
* then it is parsed to extract the date and time at which the
* timestamp was generated.
*
* @param info A signer information element of a PKCS 7 block.
*
* @return A timestamp token or null if none is present.
* @throws IOException if an error is encountered while parsing the
* PKCS7 data.
* @throws NoSuchAlgorithmException if an error is encountered while
* verifying the PKCS7 object.
* @throws SignatureException if an error is encountered while
* verifying the PKCS7 object.
* @throws CertificateException if an error is encountered while generating
* the TSA's certpath.
*/
private Timestamp getTimestamp(SignerInfo info) throws IOException, NoSuchAlgorithmException, SignatureException, CertificateException {
Timestamp timestamp = null;
// Extract the signer's unsigned attributes
PKCS9Attributes unsignedAttrs = info.getUnauthenticatedAttributes();
if (unsignedAttrs != null) {
PKCS9Attribute timestampTokenAttr = unsignedAttrs.getAttribute("signatureTimestampToken");
if (timestampTokenAttr != null) {
PKCS7 timestampToken = new PKCS7((byte[]) timestampTokenAttr.getValue());
// Extract the content (an encoded timestamp token info)
byte[] encodedTimestampTokenInfo = timestampToken.getContentInfo().getData();
// Extract the signer (the Timestamping Authority)
// while verifying the content
SignerInfo[] tsa = timestampToken.verify(encodedTimestampTokenInfo);
// Expect only one signer
ArrayList<X509Certificate> chain = tsa[0].getCertificateChain(timestampToken);
CertPath tsaChain = certificateFactory.generateCertPath(chain);
// Create a timestamp token info object
TimestampToken timestampTokenInfo = new TimestampToken(encodedTimestampTokenInfo);
// Check that the signature timestamp applies to this signature
verifyTimestamp(timestampTokenInfo, info.getEncryptedDigest());
// Create a timestamp object
timestamp = new Timestamp(timestampTokenInfo.getDate(), tsaChain);
}
}
return timestamp;
}
Aggregations