public void performTest() throws Exception { DistributionPointName name = new DistributionPointName( new GeneralNames(new GeneralName(new X500Name("cn=test")))); ReasonFlags reasonFlags = new ReasonFlags(ReasonFlags.cACompromise); checkPoint(6, name, true, true, reasonFlags, true, true); checkPoint(2, name, false, false, reasonFlags, false, false); checkPoint(0, null, false, false, null, false, false); try { IssuingDistributionPoint.getInstance(new Object()); fail("getInstance() failed to detect bad object."); } catch (IllegalArgumentException e) { // expected } }
private void checkPoint( int size, DistributionPointName distributionPoint, boolean onlyContainsUserCerts, boolean onlyContainsCACerts, ReasonFlags onlySomeReasons, boolean indirectCRL, boolean onlyContainsAttributeCerts) throws IOException { IssuingDistributionPoint point = new IssuingDistributionPoint(distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); checkValues(point, distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); ASN1Sequence seq = ASN1Sequence.getInstance(ASN1Primitive.fromByteArray(point.getEncoded())); if (seq.size() != size) { fail("size mismatch"); } point = IssuingDistributionPoint.getInstance(seq); checkValues(point, distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); }
public void performTest() throws Exception { DistributionPointName name = new DistributionPointName( new GeneralNames(new GeneralName(new X509Name("cn=test")))); ReasonFlags reasonFlags = new ReasonFlags(ReasonFlags.cACompromise); checkPoint(6, name, true, true, reasonFlags, true, true); checkPoint(2, name, false, false, reasonFlags, false, false); checkPoint(0, null, false, false, null, false, false); try { IssuingDistributionPoint.getInstance(new Object()); fail("getInstance() failed to detect bad object."); } catch (IllegalArgumentException e) { // expected } }
private void checkValues(IssuingDistributionPoint point, DistributionPointName distributionPoint, boolean onlyContainsUserCerts, boolean onlyContainsCACerts, ReasonFlags onlySomeReasons, boolean indirectCRL, boolean onlyContainsAttributeCerts) { if (point.onlyContainsUserCerts() != onlyContainsUserCerts) { fail("mismatch on onlyContainsUserCerts"); } if (point.onlyContainsCACerts() != onlyContainsCACerts) { fail("mismatch on onlyContainsCACerts"); } if (point.isIndirectCRL() != indirectCRL) { fail("mismatch on indirectCRL"); } if (point.onlyContainsAttributeCerts() != onlyContainsAttributeCerts) { fail("mismatch on onlyContainsAttributeCerts"); } if (!isEquiv(onlySomeReasons, point.getOnlySomeReasons())) { fail("mismatch on onlySomeReasons"); } if (!isEquiv(distributionPoint, point.getDistributionPoint())) { fail("mismatch on distributionPoint"); } }
public static CrlDistPointExtension create(final NameType distribPointNameType, final String distribPointName, final NameType crlIssuerNameType, final String crlIssuer, final ReasonFlags reasons) { final DistributionPointName dp = new DistributionPointName( distribPointNameType.generalNames(distribPointName)); final GeneralNames crl; if (crlIssuerNameType != null && crlIssuer != null) { crl = crlIssuerNameType.generalNames(crlIssuer); } else { crl = null; } return create(dp, reasons, crl); }
protected void checkCriticalExtensions(CRLValidity validity, Collection<String> criticalExtensionsOid, byte[] issuingDistributionPointBinary) { if (criticalExtensionsOid == null || criticalExtensionsOid.isEmpty()) { validity.setUnknownCriticalExtension(false); } else { IssuingDistributionPoint issuingDistributionPoint = IssuingDistributionPoint .getInstance(ASN1OctetString.getInstance(issuingDistributionPointBinary).getOctets()); final boolean onlyAttributeCerts = issuingDistributionPoint.onlyContainsAttributeCerts(); final boolean onlyCaCerts = issuingDistributionPoint.onlyContainsCACerts(); final boolean onlyUserCerts = issuingDistributionPoint.onlyContainsUserCerts(); final boolean indirectCrl = issuingDistributionPoint.isIndirectCRL(); ReasonFlags onlySomeReasons = issuingDistributionPoint.getOnlySomeReasons(); DistributionPointName distributionPoint = issuingDistributionPoint.getDistributionPoint(); boolean urlFound = false; if (DistributionPointName.FULL_NAME == distributionPoint.getType()) { final GeneralNames generalNames = (GeneralNames) distributionPoint.getName(); if ((generalNames != null) && (generalNames.getNames() != null && generalNames.getNames().length > 0)) { for (GeneralName generalName : generalNames.getNames()) { if (GeneralName.uniformResourceIdentifier == generalName.getTagNo()) { ASN1String str = (ASN1String) ((DERTaggedObject) generalName.toASN1Primitive()).getObject(); validity.setUrl(str.getString()); urlFound = true; } } } } if (!(onlyAttributeCerts && onlyCaCerts && onlyUserCerts && indirectCrl) && (onlySomeReasons == null) && urlFound) { validity.setUnknownCriticalExtension(false); } } }
public void performTest() throws IOException { BitStringConstantTester.testFlagValueCorrect(0, ReasonFlags.unused); BitStringConstantTester.testFlagValueCorrect(1, ReasonFlags.keyCompromise); BitStringConstantTester.testFlagValueCorrect(2, ReasonFlags.cACompromise); BitStringConstantTester.testFlagValueCorrect(3, ReasonFlags.affiliationChanged); BitStringConstantTester.testFlagValueCorrect(4, ReasonFlags.superseded); BitStringConstantTester.testFlagValueCorrect(5, ReasonFlags.cessationOfOperation); BitStringConstantTester.testFlagValueCorrect(6, ReasonFlags.certificateHold); BitStringConstantTester.testFlagValueCorrect(7, ReasonFlags.privilegeWithdrawn); BitStringConstantTester.testFlagValueCorrect(8, ReasonFlags.aACompromise); }
/** * Get extension value for CRL Distribution Points as a string. * * @param bValue The octet string value * @return Extension value as a string * @throws IOException If an I/O problem occurs */ private String getCrlDistributionPointsStringValue(byte[] bValue) throws IOException { CRLDistPoint dps = CRLDistPoint.getInstance(bValue); DistributionPoint[] points = dps.getDistributionPoints(); StringBuilder sb = new StringBuilder(); sb.append("<ul>"); for (DistributionPoint point : points) { DistributionPointName dpn; if ((dpn = point.getDistributionPoint()) != null) { sb.append("<li>"); switch (dpn.getType()) { case DistributionPointName.FULL_NAME: sb.append(RB.getString("CrlDistributionPoint.0.0")); sb.append(": "); sb.append(getGeneralNamesString((GeneralNames) dpn.getName(), LinkClass.CRL)); break; case DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER: sb.append(RB.getString("CrlDistributionPoint.0.1")); sb.append(": "); // TODO: need better decode? sb.append(stringify(dpn.getName())); break; default: sb.append(RB.getString("UnknownCrlDistributionPointName")); sb.append(": "); sb.append(stringify(dpn.getName())); break; } sb.append("</li>"); } ReasonFlags flags; if ((flags = point.getReasons()) != null) { sb.append("<li>"); sb.append(RB.getString("CrlDistributionPoint.1")); sb.append(": "); // TODO: decode sb.append(stringify(flags)); sb.append("</li>"); } GeneralNames issuer; if ((issuer = point.getCRLIssuer()) != null) { sb.append("<li>"); sb.append(RB.getString("CrlDistributionPoint.2")); sb.append(": "); sb.append(getGeneralNamesString(issuer, LinkClass.CRL)); sb.append("</li>"); } } sb.append("</ul>"); return sb.toString(); }
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(); }
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(); }
private String[] getReasonFlagsStrings(ReasonFlags reasonFlags) throws IOException { // @formatter:off /* * ReasonFlags ::= BIT STRING { unused(0), keyCompromise(1), * cACompromise(2), affiliationChanged(3), superseded(4), * cessationOfOperation(5), certificateHold(6), privilegeWithdrawn(7), * aACompromise(8)} */ // @formatter:on List<String> reasonFlagsList = new ArrayList<String>(); DERBitString reasonFlagsBitString = (DERBitString) reasonFlags.toASN1Primitive(); int reasonFlagsInt = reasonFlagsBitString.intValue(); // Go through bit string adding reason flags found to be true if (hasReasonFlag(reasonFlagsInt, ReasonFlags.unused)) { reasonFlagsList.add(res.getString("UnusedReasonFlag")); } if (hasReasonFlag(reasonFlagsInt, ReasonFlags.keyCompromise)) { reasonFlagsList.add(res.getString("KeyCompromiseReasonFlag")); } if (hasReasonFlag(reasonFlagsInt, ReasonFlags.cACompromise)) { reasonFlagsList.add(res.getString("CaCompromiseReasonFlag")); } if (hasReasonFlag(reasonFlagsInt, ReasonFlags.affiliationChanged)) { reasonFlagsList.add(res.getString("AffiliationChangedReasonFlag")); } if (hasReasonFlag(reasonFlagsInt, ReasonFlags.superseded)) { reasonFlagsList.add(res.getString("SupersededReasonFlag")); } if (hasReasonFlag(reasonFlagsInt, ReasonFlags.cessationOfOperation)) { reasonFlagsList.add(res.getString("CessationOfOperationReasonFlag")); } if (hasReasonFlag(reasonFlagsInt, ReasonFlags.certificateHold)) { reasonFlagsList.add(res.getString("CertificateHoldReasonFlag")); } if (hasReasonFlag(reasonFlagsInt, ReasonFlags.privilegeWithdrawn)) { reasonFlagsList.add(res.getString("PrivilegeWithdrawnReasonFlag")); } if (hasReasonFlag(reasonFlagsInt, ReasonFlags.aACompromise)) { reasonFlagsList.add(res.getString("AaCompromiseReasonFlag")); } return reasonFlagsList.toArray(new String[reasonFlagsList.size()]); }
public static CrlDistPointExtension create(final DistributionPointName distributionPoint, final ReasonFlags reasons, final GeneralNames cRLIssuer) { final DistributionPoint p = new DistributionPoint(distributionPoint, reasons, cRLIssuer); return create(p); }
/** * Constructs are reason mask with the reasons. * * @param reasons The reasons. */ ReasonsMask(ReasonFlags reasons) { _reasons = reasons.intValue(); }