Example usage for org.bouncycastle.asn1 ASN1Integer getValue

List of usage examples for org.bouncycastle.asn1 ASN1Integer getValue

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 ASN1Integer getValue.

Prototype

public BigInteger getValue() 

Source Link

Usage

From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java

License:Open Source License

private String getCertificatePoliciesStringValue(byte[] value) throws IOException {
    // @formatter:off

    /*//www.  j a v  a  2s  .c o  m
     * CertificatePolicies ::= ASN1Sequence SIZE (1..MAX) OF PolicyInformation
     *
     * PolicyInformation ::= ASN1Sequence
     * {
     *      policyIdentifier CertPolicyId,
     *      policyQualifiers ASN1Sequence SIZE (1..MAX) OF PolicyQualifierInfo OPTIONAL
     * }
     *
     * CertPolicyId ::= OBJECT IDENTIFIER
     *
     * PolicyQualifierInfo ::= ASN1Sequence
     * {
     *      policyQualifierId PolicyQualifierId,
     *      qualifier ANY DEFINED BY policyQualifierId
     * }
     *
     * PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
     *
     * Qualifier ::= CHOICE
     * {
     *      cPSuri CPSuri,
     *      userNotice UserNotice
     * }
     *
     * CPSuri ::= DERIA5String
     *
     * UserNotice ::= ASN1Sequence
     * {
     *      noticeRef NoticeReference OPTIONAL,
     *      explicitText DisplayText OPTIONAL
     * }
     *
     * NoticeReference ::= ASN1Sequence
     * {
     *      organization DisplayText,
     *      noticeNumbers ASN1Sequence OF ASN1Integer
     * }
     *
     * DisplayText ::= CHOICE
     * {
     *      ia5String DERIA5String (SIZE (1..200)),
     *      visibleString VisibleString (SIZE (1..200)),
     *      bmpString BMPString (SIZE (1..200)),
     *      utf8String UTF8String (SIZE (1..200))
     * }
     */

    // @formatter:on

    StringBuilder sb = new StringBuilder();

    CertificatePolicies certificatePolicies = CertificatePolicies.getInstance(value);

    int certPolicy = 0;

    for (PolicyInformation policyInformation : certificatePolicies.getPolicyInformation()) {
        certPolicy++;

        sb.append(MessageFormat.format(res.getString("CertificatePolicy"), certPolicy));
        sb.append(NEWLINE);

        ASN1ObjectIdentifier policyIdentifier = policyInformation.getPolicyIdentifier();
        String policyIdentifierStr = ObjectIdUtil.toString(policyIdentifier);

        sb.append(INDENT);
        sb.append(MessageFormat.format(res.getString("PolicyIdentifier"), policyIdentifierStr));
        sb.append(NEWLINE);

        ASN1Sequence policyQualifiers = policyInformation.getPolicyQualifiers();

        if (policyQualifiers != null) { // Optional
            int policyQual = 0;

            for (ASN1Encodable policyQualifier : policyQualifiers.toArray()) {

                ASN1Sequence policyQualifierInfo = (ASN1Sequence) policyQualifier;

                sb.append(INDENT.toString(1));
                sb.append(MessageFormat.format(res.getString("PolicyQualifierInformation"), certPolicy,
                        ++policyQual));
                sb.append(NEWLINE);

                ASN1ObjectIdentifier policyQualifierId = (ASN1ObjectIdentifier) policyQualifierInfo
                        .getObjectAt(0);

                CertificatePolicyQualifierType certificatePolicyQualifierType = CertificatePolicyQualifierType
                        .resolveOid(policyQualifierId.getId());

                if (certificatePolicyQualifierType != null) {
                    sb.append(INDENT.toString(2));
                    sb.append(certificatePolicyQualifierType.friendly());
                    sb.append(NEWLINE);

                    if (certificatePolicyQualifierType == PKIX_CPS_POINTER_QUALIFIER) {
                        DERIA5String cpsPointer = (DERIA5String) policyQualifierInfo.getObjectAt(1);

                        sb.append(INDENT.toString(2));
                        sb.append(MessageFormat.format(res.getString("CpsPointer"),
                                "<a href=\"" + cpsPointer + "\">" + cpsPointer + "</a>"));
                        sb.append(NEWLINE);
                    } else if (certificatePolicyQualifierType == PKIX_USER_NOTICE_QUALIFIER) {
                        ASN1Encodable userNoticeObj = policyQualifierInfo.getObjectAt(1);

                        UserNotice userNotice = UserNotice.getInstance(userNoticeObj);

                        sb.append(INDENT.toString(2));
                        sb.append(res.getString("UserNotice"));
                        sb.append(NEWLINE);

                        NoticeReference noticeReference = userNotice.getNoticeRef();

                        DisplayText explicitText = userNotice.getExplicitText();

                        if (noticeReference != null) { // Optional
                            sb.append(INDENT.toString(3));
                            sb.append(res.getString("NoticeReference"));
                            sb.append(NEWLINE);

                            DisplayText organization = noticeReference.getOrganization();
                            String organizationString = organization.getString();

                            sb.append(INDENT.toString(4));
                            sb.append(MessageFormat.format(res.getString("Organization"), organizationString));
                            sb.append(NEWLINE);

                            ASN1Integer[] noticeNumbers = noticeReference.getNoticeNumbers();

                            StringBuilder sbNoticeNumbers = new StringBuilder();
                            for (ASN1Integer noticeNumber : noticeNumbers) {
                                sbNoticeNumbers.append(noticeNumber.getValue().intValue());
                                sbNoticeNumbers.append(", ");
                            }
                            sbNoticeNumbers.setLength(sbNoticeNumbers.length() - 2);

                            sb.append(INDENT.toString(4));
                            sb.append(MessageFormat.format(res.getString("NoticeNumbers"),
                                    sbNoticeNumbers.toString()));
                            sb.append(NEWLINE);
                        }

                        if (explicitText != null) { // Optional
                            String explicitTextString = explicitText.getString();

                            sb.append(INDENT.toString(3));
                            sb.append(MessageFormat.format(res.getString("ExplicitText"), explicitTextString));
                            sb.append(NEWLINE);
                        }
                    }
                }
            }
        }
    }

    return sb.toString();
}

From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java

License:Open Source License

private String getQcStatementsStringValue(byte[] octets) throws IOException {

    // @formatter:off

    /*//from ww  w  . j a v a  2 s  . com
       QCStatements ::= SEQUENCE OF QSStatement
        QSStatement ::= SEQUENCE
        {
      statementId OBJECT IDENTIFIER,
      statementInfo ANY DEFINED BY statementId OPTIONAL
        }
        QcEuLimitValue ::= MonetaryValue
       QcRetentionPeriod ::= INTEGER
     */

    // @formatter:on

    StringBuilder sb = new StringBuilder();

    int qcStatementNr = 0;

    ASN1Sequence qcStatements = ASN1Sequence.getInstance(octets);
    for (ASN1Encodable asn1Encodable : qcStatements.toArray()) {
        QCStatement qcStatement = QCStatement.getInstance(asn1Encodable);
        ASN1ObjectIdentifier statementId = qcStatement.getStatementId();
        ASN1Encodable statementInfo = qcStatement.getStatementInfo();

        int indentLevel = 1;

        sb.append(MessageFormat.format(res.getString("QCStatement.QCStatement"), ++qcStatementNr));
        sb.append(NEWLINE);

        QcStatementType qcStatementType = QcStatementType.resolveOid(statementId.getId());
        switch (qcStatementType) {
        case QC_SYNTAX_V1:
        case QC_SYNTAX_V2:
            SemanticsInformation semanticsInfo = SemanticsInformation.getInstance(statementInfo);
            sb.append(getSemanticInformationValueString(qcStatementType, semanticsInfo, indentLevel));
            break;
        case QC_COMPLIANCE:
            // no statementInfo
            sb.append(INDENT.toString(indentLevel));
            sb.append(res.getString(QcStatementType.QC_COMPLIANCE.getResKey()));
            sb.append(NEWLINE);
            break;
        case QC_EU_LIMIT_VALUE:
            sb.append(INDENT.toString(indentLevel));
            sb.append(res.getString(QcStatementType.QC_EU_LIMIT_VALUE.getResKey()));
            sb.append(NEWLINE);
            sb.append(getMonetaryValueStringValue(statementInfo, indentLevel + 1));
            break;
        case QC_RETENTION_PERIOD:
            ASN1Integer asn1Integer = ASN1Integer.getInstance(statementInfo);
            sb.append(INDENT.toString(indentLevel));
            sb.append(MessageFormat.format(res.getString(QcStatementType.QC_RETENTION_PERIOD.getResKey()),
                    asn1Integer.getValue().toString()));
            sb.append(NEWLINE);
            break;
        case QC_SSCD:
            // no statementInfo
            sb.append(INDENT.toString(indentLevel));
            sb.append(res.getString(QcStatementType.QC_SSCD.getResKey()));
            sb.append(NEWLINE);
            break;
        }
    }

    return sb.toString();
}

From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java

License:Open Source License

private String getMsCaVersionStringValue(byte[] octets) {

    /*//w  ww .  j  a  v  a2  s  .  c om
    "The extension data is a DWORD value (encoded as X509_INTEGER in the extension);
    the low 16 bits are the certificate index, and the high 16 bits are the key index."
     */

    ASN1Integer asn1Integer = ASN1Integer.getInstance(octets);
    int version = asn1Integer.getValue().intValue();
    String certIndex = String.valueOf(version & 0xffff);
    String keyIndex = String.valueOf(version >> 16);

    StringBuilder sb = new StringBuilder();

    sb.append(MessageFormat.format(res.getString("MSCaVersion.CertIndex"), certIndex));
    sb.append(NEWLINE);
    sb.append(MessageFormat.format(res.getString("MSCaVersion.KeyIndex"), keyIndex));
    sb.append(NEWLINE);

    return sb.toString();
}

From source file:net.sf.keystore_explorer.gui.crypto.policyinformation.DUserNoticeChooser.java

License:Open Source License

private void populateNoticeNumbers(NoticeReference noticeReference) {
    ASN1Integer[] noticeNumbers = noticeReference.getNoticeNumbers();

    if (noticeNumbers != null) {
        StringBuffer sb = new StringBuffer();

        for (int i = 0; i < noticeNumbers.length; i++) {
            ASN1Integer noticeNumber = noticeNumbers[i];

            sb.append(noticeNumber.getValue().intValue());

            if ((i + 1) < noticeNumbers.length) {
                sb.append(" ");
            }//from  w  w w. java  2 s  .  c  o  m
        }

        jtfNoticeNumbers.setText(sb.toString());
        jtfNoticeNumbers.setCaretPosition(0);
    }
}

From source file:net.sf.keystore_explorer.utilities.asn1.Asn1Dump.java

License:Open Source License

private String dumpInteger(ASN1Integer asn1Integer) throws IOException {
    StringBuilder sb = new StringBuilder();
    BigInteger value = asn1Integer.getValue();

    sb.append(indentSequence.toString(indentLevel));
    sb.append("INTEGER=");
    // is big int value small enough to be displayed as a number?
    if (value.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) == -1) {
        sb.append(value.toString(10));//from w ww.j  ava 2 s  .  c  o m
        if (value.longValue() >= 10) {
            sb.append(" (0x").append(value.toString(16)).append(")");
        }
    } else {
        // else print as byte array
        sb.append(NEWLINE);
        sb.append(dumpHexClear(value.toByteArray()));
    }
    sb.append(NEWLINE);

    return sb.toString();
}

From source file:net.sf.portecle.crypto.X509Ext.java

License:Open Source License

/**
 * Get Policy Constraints (2.5.29.36) extension value as a string.
 * //  www.  j a v a  2s. c o  m
 * <pre>
 * PolicyConstraints ::= SEQUENCE {
 *     requireExplicitPolicy           [0] SkipCerts OPTIONAL,
 *     inhibitPolicyMapping            [1] SkipCerts OPTIONAL }
 * SkipCerts ::= INTEGER (0..MAX)
 * </pre>
 * 
 * @param bValue The octet string value
 * @return Extension value as a string
 * @throws IOException If an I/O problem occurs
 */
private String getPolicyConstraintsStringValue(byte[] bValue) throws IOException {
    // Get sequence of policy constraint
    ASN1Sequence policyConstraints = (ASN1Sequence) ASN1Primitive.fromByteArray(bValue);

    StringBuilder strBuff = new StringBuilder();

    for (int i = 0, len = policyConstraints.size(); i < len; i++) {
        DERTaggedObject policyConstraint = (DERTaggedObject) policyConstraints.getObjectAt(i);
        ASN1Integer skipCerts = new ASN1Integer(((DEROctetString) policyConstraint.getObject()).getOctets());
        int iSkipCerts = skipCerts.getValue().intValue();

        switch (policyConstraint.getTagNo()) {
        case 0: // Require Explicit Policy Skip Certs
            if (strBuff.length() != 0) {
                strBuff.append("<br><br>");
            }
            strBuff.append(MessageFormat.format(RB.getString("RequireExplicitPolicy"), iSkipCerts));
            break;
        case 1: // Inhibit Policy Mapping Skip Certs
            if (strBuff.length() != 0) {
                strBuff.append("<br><br>");
            }
            strBuff.append(MessageFormat.format(RB.getString("InhibitPolicyMapping"), iSkipCerts));
            break;
        }
    }

    return strBuff.toString();

}

From source file:net.sf.portecle.crypto.X509Ext.java

License:Open Source License

/**
 * Get Inhibit Any Policy (2.5.29.54) extension value as a string.
 * // w w w .  j a v a2  s. c  om
 * <pre>
 * InhibitAnyPolicy ::= SkipCerts
 * SkipCerts ::= INTEGER (0..MAX)
 * </pre>
 * 
 * @param bValue The octet string value
 * @return Extension value as a string
 * @throws IOException If an I/O problem occurs
 */
private String getInhibitAnyPolicyStringValue(byte[] bValue) throws IOException {
    // Get skip certs integer
    ASN1Integer skipCerts = (ASN1Integer) ASN1Primitive.fromByteArray(bValue);

    int iSkipCerts = skipCerts.getValue().intValue();

    // Return inhibit any policy extension
    return MessageFormat.format(RB.getString("InhibitAnyPolicy"), iSkipCerts);
}

From source file:net.sf.portecle.crypto.X509Ext.java

License:Open Source License

/**
 * Get Microsoft certificate template name V2 (1.3.6.1.4.1.311.20.7) extension value as a string.
 * /*from  ww  w.j a  va  2  s  .c  o  m*/
 * <pre>
 * CertificateTemplate ::= SEQUENCE {
 *   templateID OBJECT IDENTIFIER,
 *   templateMajorVersion TemplateVersion,
 *   templateMinorVersion TemplateVersion OPTIONAL
 * }
 * TemplateVersion ::= INTEGER (0..4294967295)
 * </pre>
 * 
 * @see <a
 *      href="http://groups.google.com/groups?selm=OXFILYELDHA.1908%40TK2MSFTNGP11.phx.gbl">http://groups
        
 *      .google.com/groups?selm=OXFILYELDHA.1908%40TK2MSFTNGP11.phx.gbl</a>
 * @param bValue The octet string value
 * @return Extension value as a string
 * @throws IOException If an I/O problem occurs
 */
private String getMicrosoftCertificateTemplateV2StringValue(byte[] bValue) throws IOException {
    ASN1Sequence seq = (ASN1Sequence) ASN1Primitive.fromByteArray(bValue);
    StringBuilder sb = new StringBuilder();

    sb.append(RB.getString("MsftCertTemplateId"));
    sb.append(": ");
    sb.append(((ASN1ObjectIdentifier) seq.getObjectAt(0)).getId());
    sb.append("<br><br>");

    ASN1Integer derInt = (ASN1Integer) seq.getObjectAt(1);
    sb.append(MessageFormat.format(RB.getString("MsftCertTemplateMajorVer"), derInt.getValue()));

    if ((derInt = (ASN1Integer) seq.getObjectAt(2)) != null) {
        sb.append("<br><br>");
        sb.append(MessageFormat.format(RB.getString("MsftCertTemplateMinorVer"), derInt.getValue()));
    }

    return sb.toString();
}

From source file:net.sf.portecle.crypto.X509Ext.java

License:Open Source License

/**
 * Gets a Novell quality attribute in a decoded, human readable form.
 * /*from   w  w  w.jav a 2  s. c  om*/
 * @param seq the quality attribute
 * @return the decoded quality attribute
 */
private CharSequence getNovellQualityAttr(ASN1Sequence seq) {
    StringBuilder res = new StringBuilder();

    boolean enforceQuality = ((ASN1Boolean) seq.getObjectAt(0)).isTrue();
    res.append("<li>").append(RB.getString("NovellQualityEnforce"));
    res.append(' ').append(enforceQuality).append("</li>");

    ASN1Sequence compusecQ = (ASN1Sequence) seq.getObjectAt(1);
    int clen = compusecQ.size();
    if (clen > 0) {
        res.append("<li>");
        res.append(RB.getString("NovellCompusecQuality"));
        res.append("<ul>");

        for (int i = 0; i < clen; i++) {
            ASN1Sequence cqPair = (ASN1Sequence) compusecQ.getObjectAt(i);

            ASN1Integer tmp = (ASN1Integer) cqPair.getObjectAt(0);
            long type = tmp.getValue().longValue();
            String csecCriteria = getRes("NovellCompusecQuality." + type, "UnrecognisedNovellCompusecQuality");
            csecCriteria = MessageFormat.format(csecCriteria, tmp.getValue());
            res.append("<li>").append(csecCriteria);

            tmp = (ASN1Integer) cqPair.getObjectAt(1);
            String csecRating;
            if (type == 1L) { // TCSEC
                csecRating = getRes("TCSECRating." + tmp.getValue(), "UnrecognisedTCSECRating");
            } else {
                csecRating = RB.getString("UnrecognisedNovellQualityRating");
            }
            csecRating = MessageFormat.format(csecRating, tmp.getValue());
            res.append("<ul><li>").append(RB.getString("NovellQualityRating"));
            res.append(' ').append(csecRating).append("</li></ul>");

            res.append("</li>");
        }

        res.append("</ul></li>");
    }

    // ASN1Sequence cryptoQ = (ASN1Sequence) seq.getObjectAt(2);
    res.append("<li>").append(RB.getString("NovellCryptoQuality"));
    res.append(' ').append(RB.getString("DecodeNotImplemented")); // TODO
    res.append("</li>");
    /*
     * TODO for (int i = 0, len = cryptoQ.size(); i < len; i++) { ASN1Sequence cqPair = (ASN1Sequence)
     * cryptoQ.getObjectAt(i); ASN1Integer cryptoModuleCriteria = (ASN1Integer) cqPair.getObjectAt(0);
     * ASN1Integer cryptoModuleRating = (ASN1Integer) cqPair.getObjectAt(1); }
     */

    BigInteger ksqv = ((ASN1Integer) seq.getObjectAt(3)).getValue();
    String ksq = getRes("NovellKeyStorageQuality." + ksqv, "UnrecognisedNovellKeyStorageQuality");
    res.append("<li>").append(RB.getString("NovellKeyStorageQuality"));
    res.append(": ").append(MessageFormat.format(ksq, ksqv));
    res.append("</li>");

    return res;
}

From source file:org.cryptoworkshop.ximix.common.asn1.message.BigIntegerMessage.java

License:Apache License

private BigIntegerMessage(ASN1Integer integer) {
    this.value = integer.getValue();
}