Search in sources :

Example 1 with ReasonFlags

use of de.carne.certmgr.certs.x509.ReasonFlags in project jdk8u_jdk by JetBrains.

the class NamedBitList method main.

public static void main(String[] args) throws Exception {
    boolean[] bb = (new boolean[] { true, false, true, false, false, false });
    GeneralNames gns = new GeneralNames();
    gns.add(new GeneralName(new DNSName("dns")));
    DerOutputStream out;
    // length should be 5 since only {T,F,T} should be encoded
    KeyUsageExtension x1 = new KeyUsageExtension(bb);
    check(new DerValue(x1.getExtensionValue()).getUnalignedBitString().length(), 3);
    NetscapeCertTypeExtension x2 = new NetscapeCertTypeExtension(bb);
    check(new DerValue(x2.getExtensionValue()).getUnalignedBitString().length(), 3);
    ReasonFlags r = new ReasonFlags(bb);
    out = new DerOutputStream();
    r.encode(out);
    check(new DerValue(out.toByteArray()).getUnalignedBitString().length(), 3);
    // Read sun.security.x509.DistributionPoint for ASN.1 definition
    DistributionPoint dp = new DistributionPoint(gns, bb, gns);
    out = new DerOutputStream();
    dp.encode(out);
    DerValue v = new DerValue(out.toByteArray());
    // skip distributionPoint
    v.data.getDerValue();
    // read reasons
    DerValue v2 = v.data.getDerValue();
    // reset to BitString since it's context-specfic[1] encoded
    v2.resetTag(DerValue.tag_BitString);
    // length should be 5 since only {T,F,T} should be encoded
    check(v2.getUnalignedBitString().length(), 3);
    BitArray ba;
    ba = new BitArray(new boolean[] { false, false, false });
    check(ba.length(), 3);
    ba = ba.truncate();
    check(ba.length(), 1);
    ba = new BitArray(new boolean[] { true, true, true, true, true, true, true, true, false, false });
    check(ba.length(), 10);
    check(ba.toByteArray().length, 2);
    ba = ba.truncate();
    check(ba.length(), 8);
    check(ba.toByteArray().length, 1);
    ba = new BitArray(new boolean[] { true, true, true, true, true, true, true, true, true, false });
    check(ba.length(), 10);
    check(ba.toByteArray().length, 2);
    ba = ba.truncate();
    check(ba.length(), 9);
    check(ba.toByteArray().length, 2);
}
Also used : GeneralNames(sun.security.x509.GeneralNames) DerOutputStream(sun.security.util.DerOutputStream) ReasonFlags(sun.security.x509.ReasonFlags) DerValue(sun.security.util.DerValue) GeneralName(sun.security.x509.GeneralName) DistributionPoint(sun.security.x509.DistributionPoint) BitArray(sun.security.util.BitArray) DNSName(sun.security.x509.DNSName) NetscapeCertTypeExtension(sun.security.x509.NetscapeCertTypeExtension) KeyUsageExtension(sun.security.x509.KeyUsageExtension)

Example 2 with ReasonFlags

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

the class ASN1DataTest method testReasonFlags.

/**
 * Test encoding & decoding of {@link ReasonFlags} object.
 */
@Test
public void testReasonFlags() {
    try {
        ReasonFlags in = new ReasonFlags(ReasonFlag.instances());
        byte[] inEncoded = in.getEncoded();
        ReasonFlags out = ReasonFlags.decode(decodeBytes(inEncoded));
        byte[] outEncoded = out.getEncoded();
        Assert.assertArrayEquals(inEncoded, outEncoded);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail(e.getLocalizedMessage());
    }
}
Also used : ReasonFlags(de.carne.certmgr.certs.x509.ReasonFlags) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with ReasonFlags

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

the class X509Ext method getIssuingDistributionPointStringValue.

private String getIssuingDistributionPointStringValue(byte[] value) throws IOException {
    // @formatter:off
    /*
		 * IssuingDistributionPoint ::= ASN1Sequence {
		 *     distributionPoint [0] DistributionPointName OPTIONAL,
		 *     onlyContainsUserCerts [1] ASN1Boolean DEFAULT FALSE,
		 *     onlyContainsCACerts [2] ASN1Boolean DEFAULT FALSE,
		 *     onlySomeReasons [3] ReasonFlags OPTIONAL,
		 *     indirectCRL [4] ASN1Boolean DEFAULT FALSE,
		 *     onlyContainsAttributeCerts [5] ASN1Boolean DEFAULT FALSE }
		 */
    // @formatter:on
    /*
		 * Getting any DEFAULTS returns a false ASN1Boolean when no value
		 * present which saves the bother of a null check
		 */
    StringBuilder sb = new StringBuilder();
    IssuingDistributionPoint issuingDistributionPoint = IssuingDistributionPoint.getInstance(value);
    DistributionPointName distributionPointName = issuingDistributionPoint.getDistributionPoint();
    if (distributionPointName != null) {
        // Optional
        sb.append(getDistributionPointNameString(distributionPointName, ""));
    }
    boolean onlyContainsUserCerts = issuingDistributionPoint.onlyContainsUserCerts();
    sb.append(MessageFormat.format(res.getString("OnlyContainsUserCerts"), onlyContainsUserCerts));
    sb.append(NEWLINE);
    boolean onlyContainsCaCerts = issuingDistributionPoint.onlyContainsCACerts();
    sb.append(MessageFormat.format(res.getString("OnlyContainsCaCerts"), onlyContainsCaCerts));
    sb.append(NEWLINE);
    ReasonFlags onlySomeReasons = issuingDistributionPoint.getOnlySomeReasons();
    if (onlySomeReasons != null) {
        // Optional
        sb.append(res.getString("OnlySomeReasons"));
        sb.append(NEWLINE);
        String[] reasonFlags = getReasonFlagsStrings(onlySomeReasons);
        for (String reasonFlag : reasonFlags) {
            sb.append(INDENT);
            sb.append(reasonFlag);
            sb.append(NEWLINE);
        }
    }
    boolean indirectCrl = issuingDistributionPoint.isIndirectCRL();
    sb.append(MessageFormat.format(res.getString("IndirectCrl"), indirectCrl));
    sb.append(NEWLINE);
    boolean onlyContainsAttributeCerts = issuingDistributionPoint.onlyContainsAttributeCerts();
    sb.append(MessageFormat.format(res.getString("OnlyContainsAttributeCerts"), onlyContainsAttributeCerts));
    sb.append(NEWLINE);
    return sb.toString();
}
Also used : IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) ReasonFlags(org.bouncycastle.asn1.x509.ReasonFlags) DistributionPointName(org.bouncycastle.asn1.x509.DistributionPointName) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERIA5String(org.bouncycastle.asn1.DERIA5String)

Example 4 with ReasonFlags

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

the class X509Ext method getDistributionPointString.

private String getDistributionPointString(DistributionPoint distributionPoint, String baseIndent) throws IOException {
    // @formatter:off
    /*
		 * DistributionPoint ::= ASN1Sequence {
		 * 		distributionPoint [0] DistributionPointName OPTIONAL,
		 * 		reasons [1] ReasonFlags OPTIONAL,
		 * 		cRLIssuer [2] GeneralNames OPTIONAL
		 * }
		 *
		 * GeneralNames ::= ASN1Sequence SIZE (1..MAX) OF GeneralName
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    DistributionPointName distributionPointName = distributionPoint.getDistributionPoint();
    ReasonFlags reasons = distributionPoint.getReasons();
    GeneralNames crlIssuer = distributionPoint.getCRLIssuer();
    if (distributionPointName != null) {
        // Optional
        sb.append(getDistributionPointNameString(distributionPointName, baseIndent));
    }
    if (reasons != null) {
        // Optional
        sb.append(baseIndent);
        sb.append(res.getString("DistributionPointReasons"));
        sb.append(NEWLINE);
        String[] reasonFlags = getReasonFlagsStrings(reasons);
        for (String reasonFlag : reasonFlags) {
            sb.append(baseIndent);
            sb.append(INDENT);
            sb.append(reasonFlag);
            sb.append(NEWLINE);
        }
    }
    if (crlIssuer != null) {
        // Optional
        sb.append(baseIndent);
        sb.append(res.getString("DistributionPointCrlIssuer"));
        sb.append(NEWLINE);
        for (GeneralName generalName : crlIssuer.getNames()) {
            sb.append(baseIndent);
            sb.append(INDENT);
            sb.append(GeneralNameUtil.toString(generalName));
            sb.append(NEWLINE);
        }
    }
    return sb.toString();
}
Also used : GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) ReasonFlags(org.bouncycastle.asn1.x509.ReasonFlags) DistributionPointName(org.bouncycastle.asn1.x509.DistributionPointName) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERIA5String(org.bouncycastle.asn1.DERIA5String) GeneralName(org.bouncycastle.asn1.x509.GeneralName)

Aggregations

ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 DERBMPString (org.bouncycastle.asn1.DERBMPString)2 DERBitString (org.bouncycastle.asn1.DERBitString)2 DERGeneralString (org.bouncycastle.asn1.DERGeneralString)2 DERIA5String (org.bouncycastle.asn1.DERIA5String)2 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)2 DirectoryString (org.bouncycastle.asn1.x500.DirectoryString)2 DistributionPointName (org.bouncycastle.asn1.x509.DistributionPointName)2 ReasonFlags (org.bouncycastle.asn1.x509.ReasonFlags)2 ReasonFlags (de.carne.certmgr.certs.x509.ReasonFlags)1 IOException (java.io.IOException)1 GeneralName (org.bouncycastle.asn1.x509.GeneralName)1 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)1 IssuingDistributionPoint (org.bouncycastle.asn1.x509.IssuingDistributionPoint)1 Test (org.junit.Test)1 BitArray (sun.security.util.BitArray)1 DerOutputStream (sun.security.util.DerOutputStream)1 DerValue (sun.security.util.DerValue)1 DNSName (sun.security.x509.DNSName)1 DistributionPoint (sun.security.x509.DistributionPoint)1