private CscaMasterList(ASN1Sequence seq) { if (seq == null || seq.size() == 0) { throw new IllegalArgumentException("null or empty sequence passed."); } if (seq.size() != 2) { throw new IllegalArgumentException("Incorrect sequence size: " + seq.size()); } version = DERInteger.getInstance(seq.getObjectAt(0)); ASN1Set certSet = ASN1Set.getInstance(seq.getObjectAt(1)); certList = new X509CertificateStructure[certSet.size()]; for (int i = 0; i < certList.length; i++) { certList[i] = X509CertificateStructure.getInstance(certSet.getObjectAt(i)); } }
/** * Parse the ServerCertificate message. * * @param is The stream where to parse from. * @return A Certificate object with the certs, the server has sended. * @throws IOException If something goes wrong during parsing. */ public static Certificate parse(InputStream is) throws IOException { X509CertificateStructure[] certs; int left = TlsUtils.readUint24(is); Vector tmp = new Vector(); while (left > 0) { int size = TlsUtils.readUint24(is); left -= 3 + size; byte[] buf = new byte[size]; TlsUtils.readFully(buf, is); ByteArrayInputStream bis = new ByteArrayInputStream(buf); ASN1InputStream ais = new ASN1InputStream(bis); DERObject o = ais.readObject(); tmp.addElement(X509CertificateStructure.getInstance(o)); if (bis.available() > 0) { throw new IllegalArgumentException( "Sorry, there is garbage data left after the certificate"); } } certs = new X509CertificateStructure[tmp.size()]; for (int i = 0; i < tmp.size(); i++) { certs[i] = (X509CertificateStructure) tmp.elementAt(i); } return new Certificate(certs); }