Search in sources :

Example 26 with DistributionPoint

use of de.carne.certmgr.certs.x509.DistributionPoint in project certmgr by hdecarne.

the class ASN1DataTest method testDistributionPoint.

/**
 * Test encoding & decoding of {@link DistributionPoint} object.
 */
@Test
public void testDistributionPoint() {
    try {
        // DistributionPointName based
        GeneralNames in1FullName = new GeneralNames();
        StringName in1NameA = new StringName(GeneralNameType.UNIFORM_RESOURCE_IDENTIFIER, "https://localhost/test.crl");
        DirectoryName in1NameB = new DirectoryName(new X500Principal("CN=localhost"));
        in1FullName.addName(in1NameA);
        in1FullName.addName(in1NameB);
        DistributionPointName in1Name = new DistributionPointName(in1FullName);
        DistributionPoint in1 = new DistributionPoint(in1Name);
        byte[] in1Encoded = in1.getEncoded();
        DistributionPoint out1 = DistributionPoint.decode(decodeBytes(in1Encoded));
        byte[] out1Encoded = out1.getEncoded();
        Assert.assertArrayEquals(in1Encoded, out1Encoded);
        // GeneralName based
        GeneralNames in2CrlIssuers = new GeneralNames();
        StringName in2NameA = new StringName(GeneralNameType.UNIFORM_RESOURCE_IDENTIFIER, "https://localhost/test.crl");
        DirectoryName in2NameB = new DirectoryName(new X500Principal("CN=localhost"));
        in1FullName.addName(in2NameA);
        in1FullName.addName(in2NameB);
        DistributionPoint in2 = new DistributionPoint(in2CrlIssuers);
        byte[] in2Encoded = in2.encode().toASN1Primitive().getEncoded();
        DistributionPoint out2 = DistributionPoint.decode(decodeBytes(in2Encoded));
        byte[] out2Encoded = out2.encode().toASN1Primitive().getEncoded();
        Assert.assertArrayEquals(in2Encoded, out2Encoded);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail(e.getLocalizedMessage());
    }
}
Also used : GeneralNames(de.carne.certmgr.certs.x509.GeneralNames) StringName(de.carne.certmgr.certs.x509.StringName) DistributionPointName(de.carne.certmgr.certs.x509.DistributionPointName) X500Principal(javax.security.auth.x500.X500Principal) DistributionPoint(de.carne.certmgr.certs.x509.DistributionPoint) IOException(java.io.IOException) DirectoryName(de.carne.certmgr.certs.x509.DirectoryName) Test(org.junit.Test)

Example 27 with DistributionPoint

use of de.carne.certmgr.certs.x509.DistributionPoint in project certmgr by hdecarne.

the class CRLDistributionPointsController method onApply.

private void onApply(ActionEvent evt) {
    try {
        boolean critical = this.ctlCritical.isSelected();
        DistributionPoint distributionPoint = validateAndGetDistributionPoint();
        this.extensionDataResult = new CRLDistributionPointsExtensionData(critical);
        this.extensionDataResult.addDistributionPoint(distributionPoint);
    } catch (ValidationException e) {
        ValidationAlerts.error(e).showAndWait();
        evt.consume();
    }
}
Also used : ValidationException(de.carne.jfx.util.validation.ValidationException) CRLDistributionPointsExtensionData(de.carne.certmgr.certs.x509.CRLDistributionPointsExtensionData) DistributionPoint(de.carne.certmgr.certs.x509.DistributionPoint)

Example 28 with DistributionPoint

use of de.carne.certmgr.certs.x509.DistributionPoint in project signer by demoiselle.

the class BasicCertificate method getCRLDistributionPoint.

/**
 * @return A list of ulrs that inform the location of the certificate revocation lists
 * @throws IOException exception
 */
public List<String> getCRLDistributionPoint() throws IOException {
    List<String> crlUrls = new ArrayList<>();
    ASN1Primitive primitive = getExtensionValue(Extension.cRLDistributionPoints.getId());
    if (primitive == null) {
        return null;
    }
    CRLDistPoint crlDistPoint = CRLDistPoint.getInstance(primitive);
    DistributionPoint[] distributionPoints = crlDistPoint.getDistributionPoints();
    for (DistributionPoint distributionPoint : distributionPoints) {
        DistributionPointName dpn = distributionPoint.getDistributionPoint();
        // Look for URIs in fullName
        if (dpn != null) {
            if (dpn.getType() == DistributionPointName.FULL_NAME) {
                GeneralName[] genNames = GeneralNames.getInstance(dpn.getName()).getNames();
                for (GeneralName genName : genNames) {
                    if (genName.getTagNo() == GeneralName.uniformResourceIdentifier) {
                        String url = DERIA5String.getInstance(genName.getName()).getString();
                        crlUrls.add(url);
                        logger.info("Adicionando a url {}", url);
                    }
                }
            }
        }
    }
    return crlUrls;
}
Also used : ArrayList(java.util.ArrayList) DistributionPointName(org.bouncycastle.asn1.x509.DistributionPointName) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) GeneralName(org.bouncycastle.asn1.x509.GeneralName) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint)

Example 29 with DistributionPoint

use of de.carne.certmgr.certs.x509.DistributionPoint in project keystore-explorer by kaikramer.

the class X509Ext method getCrlDistributionPointsStringValue.

private String getCrlDistributionPointsStringValue(byte[] value) throws IOException {
    // @formatter:off
    /*
		 * CRLDistPointSyntax ::= ASN1Sequence SIZE (1..MAX) OF
		 * DistributionPoint
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    CRLDistPoint crlDistributionPoints = CRLDistPoint.getInstance(value);
    int distPoint = 0;
    for (DistributionPoint distributionPoint : crlDistributionPoints.getDistributionPoints()) {
        distPoint++;
        sb.append(MessageFormat.format(res.getString("CrlDistributionPoint"), distPoint));
        sb.append(NEWLINE);
        sb.append(getDistributionPointString(distributionPoint, INDENT.toString(1)));
    }
    return sb.toString();
}
Also used : IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint)

Example 30 with DistributionPoint

use of de.carne.certmgr.certs.x509.DistributionPoint in project keystore-explorer by kaikramer.

the class CRLDistributionPoints method toASN1Primitive.

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    Iterator<DistributionPoint> it = distributionPointList.iterator();
    while (it.hasNext()) {
        v.add(it.next().toASN1Primitive());
    }
    return new DERSequence(v);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint)

Aggregations

DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)24 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)21 GeneralName (org.bouncycastle.asn1.x509.GeneralName)20 IOException (java.io.IOException)14 DistributionPointName (org.bouncycastle.asn1.x509.DistributionPointName)12 DERIA5String (org.bouncycastle.asn1.DERIA5String)9 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)9 IssuingDistributionPoint (org.bouncycastle.asn1.x509.IssuingDistributionPoint)8 GeneralSecurityException (java.security.GeneralSecurityException)7 ArrayList (java.util.ArrayList)7 CertPathValidatorException (java.security.cert.CertPathValidatorException)6 List (java.util.List)6 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)5 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)5 DEROctetString (org.bouncycastle.asn1.DEROctetString)5 ExtCertPathValidatorException (org.bouncycastle.jce.exception.ExtCertPathValidatorException)5 DistributionPoint (de.carne.certmgr.certs.x509.DistributionPoint)4 CertPathBuilderException (java.security.cert.CertPathBuilderException)4 CertificateExpiredException (java.security.cert.CertificateExpiredException)4 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)4