private void checkConstruction( OtherCertID certID, AlgorithmIdentifier algId, byte[] digest, IssuerSerial issuerSerial) throws IOException { checkValues(certID, algId, digest, issuerSerial); certID = OtherCertID.getInstance(certID); checkValues(certID, algId, digest, issuerSerial); ASN1InputStream aIn = new ASN1InputStream(certID.toASN1Primitive().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); certID = OtherCertID.getInstance(seq); checkValues(certID, algId, digest, issuerSerial); }
private void checkConstruction( OtherCertID certID, AlgorithmIdentifier algId, byte[] digest, IssuerSerial issuerSerial) throws IOException { checkValues(certID, algId, digest, issuerSerial); certID = OtherCertID.getInstance(certID); checkValues(certID, algId, digest, issuerSerial); ASN1InputStream aIn = new ASN1InputStream(certID.toASN1Object().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); certID = OtherCertID.getInstance(seq); checkValues(certID, algId, digest, issuerSerial); }
private void checkValues( OtherCertID certID, AlgorithmIdentifier algId, byte[] digest, IssuerSerial issuerSerial) { checkMandatoryField("algorithmHash", algId, certID.getAlgorithmHash()); checkMandatoryField("certHash", digest, certID.getCertHash()); checkOptionalField("issuerSerial", issuerSerial, certID.getIssuerSerial()); }
public void performTest() throws Exception { AlgorithmIdentifier algId = new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.2.2.3")); byte[] digest = new byte[20]; OtherCertID otherCertID = new OtherCertID(algId, digest); OtherSigningCertificate otherCert = new OtherSigningCertificate(otherCertID); checkConstruction(otherCert, otherCertID); otherCert = OtherSigningCertificate.getInstance(null); if (otherCert != null) { fail("null getInstance() failed."); } try { OtherCertID.getInstance(new Object()); fail("getInstance() failed to detect bad object."); } catch (IllegalArgumentException e) { // expected } }
private void checkValues( OtherSigningCertificate otherCert, OtherCertID otherCertID) { if (otherCert.getCerts().length != 1) { fail("getCerts() length wrong"); } checkMandatoryField("getCerts()[0]", otherCertID, otherCert.getCerts()[0]); }
@Override public Attribute getValue() throws SignerException { try { int chainSize = certificates.length -1; OtherCertID[] arrayOtherCertID = new OtherCertID[chainSize]; for (int i = 1; i <= chainSize; i++ ){ X509Certificate issuerCert = null; X509Certificate cert = (X509Certificate) certificates[i]; if (i < chainSize){ issuerCert = (X509Certificate) certificates[i+1]; }else{ // raiz issuerCert = (X509Certificate) certificates[i]; } Digest digest = DigestFactory.getInstance().factoryDefault(); digest.setAlgorithm(DigestAlgorithmEnum.SHA_256); byte[] certHash = digest.digest(cert.getEncoded()); X500Name dirName = new X500Name(issuerCert.getSubjectX500Principal().getName()); GeneralName name = new GeneralName(dirName); GeneralNames issuer = new GeneralNames(name); ASN1Integer serialNumber = new ASN1Integer(cert.getSerialNumber()); IssuerSerial issuerSerial = new IssuerSerial(issuer, serialNumber); AlgorithmIdentifier algId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256); OtherCertID otherCertID = new OtherCertID(algId, certHash, issuerSerial); arrayOtherCertID[i -1] = otherCertID; } return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(new ASN1Encodable[] { new DERSequence(arrayOtherCertID) })); } catch (CertificateEncodingException e) { throw new SignerException(e.getMessage()); } }
@Override public List<CertificateRef> getCertificateRefs() { final List<CertificateRef> list = new ArrayList<CertificateRef>(); final Attribute attribute = getUnsignedAttribute(id_aa_ets_certificateRefs); if (attribute == null) { return list; } final ASN1Set attrValues = attribute.getAttrValues(); if (attrValues.size() <= 0) { return list; } final ASN1Encodable attrValue = attrValues.getObjectAt(0); final ASN1Sequence completeCertificateRefs = (ASN1Sequence) attrValue; for (int i = 0; i < completeCertificateRefs.size(); i++) { final OtherCertID otherCertId = OtherCertID.getInstance(completeCertificateRefs.getObjectAt(i)); final CertificateRef certId = new CertificateRef(); certId.setDigestAlgorithm(DigestAlgorithm.forOID(otherCertId.getAlgorithmHash().getAlgorithm().getId())); certId.setDigestValue(otherCertId.getCertHash()); final IssuerSerial issuer = otherCertId.getIssuerSerial(); if (issuer != null) { final GeneralNames issuerName = issuer.getIssuer(); if (issuerName != null) { certId.setIssuerName(issuerName.toString()); } final ASN1Integer issuerSerial = issuer.getSerial(); if (issuerSerial != null) { certId.setIssuerSerial(issuerSerial.toString()); } } list.add(certId); } return list; }
public void performTest() throws Exception { AlgorithmIdentifier algId = new AlgorithmIdentifier(new DERObjectIdentifier("1.2.2.3")); byte[] digest = new byte[20]; OtherCertID otherCertID = new OtherCertID(algId, digest); OtherSigningCertificate otherCert = new OtherSigningCertificate(otherCertID); checkConstruction(otherCert, otherCertID); otherCert = OtherSigningCertificate.getInstance(null); if (otherCert != null) { fail("null getInstance() failed."); } try { OtherCertID.getInstance(new Object()); fail("getInstance() failed to detect bad object."); } catch (IllegalArgumentException e) { // expected } }
private void checkConstruction( OtherSigningCertificate otherCert, OtherCertID otherCertID) throws IOException { checkValues(otherCert, otherCertID); otherCert = OtherSigningCertificate.getInstance(otherCert); checkValues(otherCert, otherCertID); ASN1InputStream aIn = new ASN1InputStream(otherCert.toASN1Primitive().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); otherCert = OtherSigningCertificate.getInstance(seq); checkValues(otherCert, otherCertID); }
private void checkConstruction( OtherSigningCertificate otherCert, OtherCertID otherCertID) throws IOException { checkValues(otherCert, otherCertID); otherCert = OtherSigningCertificate.getInstance(otherCert); checkValues(otherCert, otherCertID); ASN1InputStream aIn = new ASN1InputStream(otherCert.toASN1Object().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); otherCert = OtherSigningCertificate.getInstance(seq); checkValues(otherCert, otherCertID); }