Search in sources :

Example 31 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project pdfbox by apache.

the class TSAClient method getTimeStampToken.

/**
 * @param messageImprint imprint of message contents
 * @return the encoded time stamp token
 * @throws IOException if there was an error with the connection or data from the TSA server,
 *                     or if the time stamp response could not be validated
 */
public byte[] getTimeStampToken(byte[] messageImprint) throws IOException {
    digest.reset();
    byte[] hash = digest.digest(messageImprint);
    // 32-bit cryptographic nonce
    SecureRandom random = new SecureRandom();
    int nonce = random.nextInt();
    // generate TSA request
    TimeStampRequestGenerator tsaGenerator = new TimeStampRequestGenerator();
    tsaGenerator.setCertReq(true);
    ASN1ObjectIdentifier oid = getHashObjectIdentifier(digest.getAlgorithm());
    TimeStampRequest request = tsaGenerator.generate(oid, hash, BigInteger.valueOf(nonce));
    // get TSA response
    byte[] tsaResponse = getTSAResponse(request.getEncoded());
    TimeStampResponse response;
    try {
        response = new TimeStampResponse(tsaResponse);
        response.validate(request);
    } catch (TSPException e) {
        throw new IOException(e);
    }
    TimeStampToken token = response.getTimeStampToken();
    if (token == null) {
        throw new IOException("Response does not have a time stamp token");
    }
    return token.getEncoded();
}
Also used : TimeStampResponse(org.bouncycastle.tsp.TimeStampResponse) SecureRandom(java.security.SecureRandom) TimeStampRequestGenerator(org.bouncycastle.tsp.TimeStampRequestGenerator) TSPException(org.bouncycastle.tsp.TSPException) IOException(java.io.IOException) TimeStampToken(org.bouncycastle.tsp.TimeStampToken) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) TimeStampRequest(org.bouncycastle.tsp.TimeStampRequest)

Example 32 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project pdfbox by apache.

the class CertInformationHelper method getAuthorityInfoExtensionValue.

/**
 * Extracts authority information access extension values from the given data. The Data
 * structure has to be implemented as described in RFC 2459, 4.2.2.1.
 *
 * @param extensionValue byte[] of the extension value.
 * @param certInfo where to put the found values
 * @throws IOException when there is a problem with the extensionValue
 */
protected static void getAuthorityInfoExtensionValue(byte[] extensionValue, CertSignatureInformation certInfo) throws IOException {
    ASN1Sequence asn1Seq = (ASN1Sequence) X509ExtensionUtil.fromExtensionValue(extensionValue);
    Enumeration<?> objects = asn1Seq.getObjects();
    while (objects.hasMoreElements()) {
        // AccessDescription
        ASN1Sequence obj = (ASN1Sequence) objects.nextElement();
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) obj.getObjectAt(0);
        // accessLocation
        DERTaggedObject location = (DERTaggedObject) obj.getObjectAt(1);
        if (oid.equals(X509ObjectIdentifiers.id_ad_ocsp) && location.getTagNo() == GeneralName.uniformResourceIdentifier) {
            DEROctetString url = (DEROctetString) location.getObject();
            certInfo.setOcspUrl(new String(url.getOctets()));
        } else if (oid.equals(X509ObjectIdentifiers.id_ad_caIssuers)) {
            DEROctetString uri = (DEROctetString) location.getObject();
            certInfo.setIssuerUrl(new String(uri.getOctets()));
        }
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 33 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project keystore-explorer by kaikramer.

the class X509Ext method getMsCertificateTemplateStringValue.

private String getMsCertificateTemplateStringValue(byte[] octets) {
    // @formatter:off
    /*
			CertificateTemplate ::= SEQUENCE
			{
				templateID              EncodedObjectID,
				templateMajorVersion    TemplateVersion,
				templateMinorVersion    TemplateVersion OPTIONAL
			}
			TemplateVersion ::= INTEGER (0..4294967295)
		 */
    // @formatter:on
    ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(octets);
    ASN1ObjectIdentifier templateID = (ASN1ObjectIdentifier) asn1Sequence.getObjectAt(0);
    ASN1Integer majorVersion = (ASN1Integer) asn1Sequence.getObjectAt(1);
    ASN1Integer minorVersion = (ASN1Integer) asn1Sequence.getObjectAt(2);
    StringBuilder sb = new StringBuilder();
    sb.append(MessageFormat.format(res.getString("MSCertificateTemplate.ID"), templateID.getId()));
    sb.append(NEWLINE);
    sb.append(MessageFormat.format(res.getString("MSCertificateTemplate.MajorVersion"), majorVersion));
    sb.append(NEWLINE);
    if (minorVersion != null) {
        sb.append(MessageFormat.format(res.getString("MSCertificateTemplate.MinorVersion"), minorVersion));
        sb.append(NEWLINE);
    }
    return sb.toString();
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 34 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project keystore-explorer by kaikramer.

the class X509Ext method getSMIMECapabilitiesStringValue.

private String getSMIMECapabilitiesStringValue(byte[] octets) throws IOException {
    // @formatter:off
    /*
			SMIMECapabilities ::= SEQUENCE OF SMIMECapability

			SMIMECapability ::= SEQUENCE
			{
				capabilityID OBJECT IDENTIFIER,
				parameters ANY DEFINED BY capabilityID OPTIONAL
			}
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    int capabilityNr = 0;
    ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(octets);
    for (ASN1Encodable asn1Encodable : asn1Sequence.toArray()) {
        SMIMECapability capability = SMIMECapability.getInstance(asn1Encodable);
        ASN1ObjectIdentifier oid = capability.getCapabilityID();
        ASN1Encodable parameters = capability.getParameters();
        sb.append(MessageFormat.format(res.getString("SMIMECapability"), ++capabilityNr));
        sb.append(NEWLINE);
        sb.append(INDENT);
        sb.append(MessageFormat.format(res.getString("SMIMECapability.ObjectID"), ObjectIdUtil.toString(oid)));
        sb.append(NEWLINE);
        if (parameters != null) {
            sb.append(INDENT);
            sb.append(MessageFormat.format(res.getString("SMIMECapability.Parameter"), HexUtil.getHexString(parameters.toASN1Primitive().getEncoded())));
            sb.append(NEWLINE);
        }
    }
    return sb.toString();
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) SMIMECapability(org.bouncycastle.asn1.smime.SMIMECapability) IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 35 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project keystore-explorer by kaikramer.

the class X509Ext method getQcStatementsStringValue.

private String getQcStatementsStringValue(byte[] octets) throws IOException {
    // @formatter:off
    /*
			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());
        if (qcStatementType != null) {
            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;
                case QC_PDS:
                    ASN1Sequence pdsLocations = ASN1Sequence.getInstance(statementInfo);
                    sb.append(INDENT.toString(indentLevel));
                    sb.append(res.getString(QcStatementType.QC_PDS.getResKey()));
                    for (ASN1Encodable pdsLoc : pdsLocations) {
                        sb.append(NEWLINE);
                        sb.append(INDENT.toString(indentLevel + 1));
                        DLSequence pds = (DLSequence) pdsLoc;
                        sb.append(MessageFormat.format(res.getString("QCPDS.locations"), pds.getObjectAt(1), pds.getObjectAt(0)));
                    }
                    sb.append(NEWLINE);
                    break;
                case QC_TYPE:
                    sb.append(INDENT.toString(indentLevel));
                    sb.append(res.getString(QcStatementType.QC_TYPE.getResKey()));
                    ASN1Sequence qcTypes = ASN1Sequence.getInstance(statementInfo);
                    for (ASN1Encodable type : qcTypes) {
                        sb.append(NEWLINE);
                        sb.append(INDENT.toString(indentLevel + 1));
                        sb.append(ObjectIdUtil.toString((ASN1ObjectIdentifier) type));
                    }
                    sb.append(NEWLINE);
            }
        } else {
            // unknown statement type
            sb.append(INDENT.toString(indentLevel));
            sb.append(ObjectIdUtil.toString(statementId));
            if (statementInfo != null) {
                sb.append(statementInfo.toString());
            }
            sb.append(NEWLINE);
        }
    }
    return sb.toString();
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) QCStatement(org.bouncycastle.asn1.x509.qualified.QCStatement) DLSequence(org.bouncycastle.asn1.DLSequence) SemanticsInformation(org.bouncycastle.asn1.x509.qualified.SemanticsInformation) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)330 IOException (java.io.IOException)76 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)70 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)53 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)49 DEROctetString (org.bouncycastle.asn1.DEROctetString)48 DERIA5String (org.bouncycastle.asn1.DERIA5String)47 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)45 DERSequence (org.bouncycastle.asn1.DERSequence)42 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)38 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)36 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)36 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)35 Extension (org.bouncycastle.asn1.x509.Extension)33 ASN1String (org.bouncycastle.asn1.ASN1String)31 HashSet (java.util.HashSet)30 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)29 X500Name (org.bouncycastle.asn1.x500.X500Name)29 ArrayList (java.util.ArrayList)28 DirectoryString (org.bouncycastle.asn1.x500.DirectoryString)27