Example usage for org.bouncycastle.asn1.x509 KeyUsage toASN1Primitive

List of usage examples for org.bouncycastle.asn1.x509 KeyUsage toASN1Primitive

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 KeyUsage toASN1Primitive.

Prototype

public ASN1Primitive toASN1Primitive() 

Source Link

Usage

From source file:org.glite.voms.contact.VOMSProxyBuilder.java

License:Open Source License

/**
 *
 * This method is used to create a VOMS proxy starting from the
 * {@link UserCredentials} passed as arguments and including a list of
 * {@link AttributeCertificate} objects that will be included in the proxy.
 *
 * @param cred, the {@link UserCredentials} from which the proxy must be
 * created./*  w ww.  j a  v  a 2  s. c om*/
 * @param ACs, the list of {@link AttributeCertificate} objects.
 * @param lifetime, the lifetime in seconds of the generated proxy.
 * @param version, the version of globus to which the proxy conforms
 * @return a {@link GlobusCredential} object that represents the proxy.
 * @throws {@link VOMSException}, if something goes wrong.
 *
 * @author Vincenzo Ciaschini
 * @author Andrea Ceccanti
 *
 *
 */
public static X509Credential buildProxy(UserCredentials cred, List ACs, int bits, int lifetime,
        CertificateType gtVersion, DelegationType delegType, String policyType) {

    if (ACs.isEmpty()) {
        throw new VOMSException(
                "Please specify a non-empty list of attribute certificate to build a voms-proxy.");
    }

    Iterator i = ACs.iterator();

    DEREncodableVector acVector = new DEREncodableVector();

    while (i.hasNext()) {
        acVector.add((AttributeCertificate) i.next());
    }

    HashMap extensions = new HashMap();

    if (ACs.size() != 0) {
        DERSequence seqac = new DERSequence(acVector);
        DERSequence seqacwrap = new DERSequence(seqac);
        extensions.put("1.3.6.1.4.1.8005.100.100.5",
                ExtensionData.creator("1.3.6.1.4.1.8005.100.100.5", seqacwrap));
    }

    KeyUsage keyUsage = new KeyUsage(
            KeyUsage.digitalSignature | KeyUsage.keyEncipherment | KeyUsage.dataEncipherment);
    extensions.put("2.5.29.15", ExtensionData.creator("2.5.29.15", keyUsage.toASN1Primitive()));

    //        try {
    X509Credential proxy = myCreateCredential(cred.getUserChain(), cred.getUserKey(), bits, lifetime, delegType,
            gtVersion, extensions, policyType);

    return proxy;

    //         } catch ( GeneralSecurityException e ) {

    //             log.error( "Error generating voms proxy: " + e.getMessage() );

    //             if ( log.isDebugEnabled() )
    //                 log.error( e.getMessage(), e );

    //             throw new VOMSException( e );

    //         }

}