{
DERInputStream derInStream = new DERInputStream(inStream);
DERObject derObject = derInStream.readObject();
if ( derObject == null || ! ( derObject instanceof ASN1Sequence ) )
{
throw new CertificateException("input stream does not contain a ASN1 SEQUENCE while reading PkiPath encoded data to load CertPath" );
}
Enumeration enumx = ((ASN1Sequence)derObject).getObjects();
InputStream certInStream;
ByteArrayOutputStream outStream;
DEROutputStream derOutStream;
certificates = new ArrayList();
CertificateFactory certFactory= CertificateFactory.getInstance( "X.509", "BC" );
while ( enumx.hasMoreElements() ) {
outStream = new ByteArrayOutputStream();
derOutStream = new DEROutputStream(outStream);
derOutStream.writeObject(enumx.nextElement());
derOutStream.close();
certInStream = new ByteArrayInputStream(outStream.toByteArray());
certificates.add(0,certFactory.generateCertificate(certInStream));
}
}
else
{
throw new CertificateException( "unsupported encoding" );
}
} catch ( IOException ex ) {
throw new CertificateException( "IOException throw while decoding CertPath:\n" + ex.toString() );
} catch ( NoSuchProviderException ex ) {
throw new CertificateException( "BouncyCastle provider not found while trying to get a CertificateFactory:\n" + ex.toString() );
}
}