Search in sources :

Example 86 with ASN1EncodableVector

use of org.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class SignerUtil method dsaSigPlainToX962.

// CHECKSTYLE:SKIP
public static byte[] dsaSigPlainToX962(byte[] signature) throws XiSecurityException {
    ParamUtil.requireNonNull("signature", signature);
    if (signature.length % 2 != 0) {
        throw new XiSecurityException("signature.lenth must be even, but is odd");
    }
    byte[] ba = new byte[signature.length / 2];
    ASN1EncodableVector sigder = new ASN1EncodableVector();
    System.arraycopy(signature, 0, ba, 0, ba.length);
    sigder.add(new ASN1Integer(new BigInteger(1, ba)));
    System.arraycopy(signature, ba.length, ba, 0, ba.length);
    sigder.add(new ASN1Integer(new BigInteger(1, ba)));
    DERSequence seq = new DERSequence(sigder);
    try {
        return seq.getEncoded();
    } catch (IOException ex) {
        throw new XiSecurityException("IOException, message: " + ex.getMessage(), ex);
    }
}
Also used : XiSecurityException(org.xipki.security.exception.XiSecurityException) DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) BigInteger(java.math.BigInteger) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) IOException(java.io.IOException)

Example 87 with ASN1EncodableVector

use of org.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class OcspBenchRequestor method init.

public void init(OcspBenchmark responseHandler, String responderUrl, Certificate issuerCert, RequestOptions requestOptions, int queueSize) throws Exception {
    ParamUtil.requireNonNull("issuerCert", issuerCert);
    ParamUtil.requireNonNull("responseHandler", responseHandler);
    this.requestOptions = ParamUtil.requireNonNull("requestOptions", requestOptions);
    HashAlgo hashAlgo = HashAlgo.getInstance(requestOptions.getHashAlgorithmId());
    if (hashAlgo == null) {
        throw new OcspRequestorException("unknown HashAlgo " + requestOptions.getHashAlgorithmId().getId());
    }
    this.issuerhashAlg = hashAlgo.getAlgorithmIdentifier();
    this.issuerNameHash = new DEROctetString(hashAlgo.hash(issuerCert.getSubject().getEncoded()));
    this.issuerKeyHash = new DEROctetString(hashAlgo.hash(issuerCert.getSubjectPublicKeyInfo().getPublicKeyData().getOctets()));
    List<AlgorithmIdentifier> prefSigAlgs = requestOptions.getPreferredSignatureAlgorithms();
    if (prefSigAlgs == null || prefSigAlgs.size() == 0) {
        this.extensions = null;
    } else {
        ASN1EncodableVector vec = new ASN1EncodableVector();
        for (AlgorithmIdentifier algId : prefSigAlgs) {
            ASN1Sequence prefSigAlgObj = new DERSequence(algId);
            vec.add(prefSigAlgObj);
        }
        ASN1Sequence extnValue = new DERSequence(vec);
        Extension extn;
        try {
            extn = new Extension(ObjectIdentifiers.id_pkix_ocsp_prefSigAlgs, false, new DEROctetString(extnValue));
        } catch (IOException ex) {
            throw new OcspRequestorException(ex.getMessage(), ex);
        }
        this.extensions = new Extension[] { extn };
    }
    URI uri = new URI(responderUrl);
    this.responderRawPathPost = uri.getRawPath();
    if (this.responderRawPathPost.endsWith("/")) {
        this.responderRawPathGet = this.responderRawPathPost;
    } else {
        this.responderRawPathGet = this.responderRawPathPost + "/";
    }
    this.httpClient = new HttpClient(responderUrl, responseHandler, queueSize);
    this.httpClient.start();
}
Also used : OcspRequestorException(org.xipki.ocsp.client.api.OcspRequestorException) Extension(org.bouncycastle.asn1.x509.Extension) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERSequence(org.bouncycastle.asn1.DERSequence) HashAlgo(org.xipki.security.HashAlgo) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) IOException(java.io.IOException) URI(java.net.URI) DEROctetString(org.bouncycastle.asn1.DEROctetString) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 88 with ASN1EncodableVector

use of org.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class Asn1NewKeyControl method toASN1Primitive.

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vector = new ASN1EncodableVector();
    vector.add(new DERTaggedObject(0, ASN1Boolean.getInstance(control.isExtractable())));
    return new DERSequence(vector);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 89 with ASN1EncodableVector

use of org.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class Asn1RSAPkcsPssParams method toASN1Primitive.

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vector = new ASN1EncodableVector();
    vector.add(new ASN1Integer(pkcsPssParams.getHashAlgorithm()));
    vector.add(new ASN1Integer(pkcsPssParams.getMaskGenerationFunction()));
    vector.add(new ASN1Integer(pkcsPssParams.getSaltLength()));
    return new DERSequence(vector);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Example 90 with ASN1EncodableVector

use of org.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class Asn1ServerCaps method toASN1Primitive.

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vecVersions = new ASN1EncodableVector();
    for (Short version : versions) {
        vecVersions.add(new ASN1Integer(BigInteger.valueOf(version)));
    }
    ASN1EncodableVector vec = new ASN1EncodableVector();
    vec.add(ASN1Boolean.getInstance(readOnly));
    vec.add(new DERSequence(vecVersions));
    return new DERSequence(vec);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Aggregations

ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)250 DERSequence (org.bouncycastle.asn1.DERSequence)199 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)56 IOException (java.io.IOException)47 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)44 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)42 DEROctetString (org.bouncycastle.asn1.DEROctetString)32 BigInteger (java.math.BigInteger)24 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)24 X509Certificate (java.security.cert.X509Certificate)22 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)21 DLSequence (org.bouncycastle.asn1.DLSequence)21 ArrayList (java.util.ArrayList)20 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)18 DERSet (org.bouncycastle.asn1.DERSet)18 DERBitString (org.bouncycastle.asn1.DERBitString)17 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)16 GeneralName (org.bouncycastle.asn1.x509.GeneralName)16 List (java.util.List)15 BERSequence (org.bouncycastle.asn1.BERSequence)14