Example usage for org.bouncycastle.asn1 DERApplicationSpecific getObject

List of usage examples for org.bouncycastle.asn1 DERApplicationSpecific getObject

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DERApplicationSpecific getObject.

Prototype

public ASN1Primitive getObject() throws IOException 

Source Link

Document

Return the enclosed object assuming explicit tagging.

Usage

From source file:com.github.horrorho.inflatabledonkey.data.der.DER.java

License:Open Source License

static ASN1Primitive asApplicationSpecific(int tag, ASN1Encodable encodable) {
    try {//w  w  w.  jav  a  2s. co m
        DERApplicationSpecific specific = as(DERApplicationSpecific.class, encodable);

        if (specific.getApplicationTag() == tag) {
            return specific.getObject();

        } else {
            throw new IllegalArgumentException(
                    "tag mismatch, expected " + tag + " got " + specific.getApplicationTag());
        }

    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
}

From source file:uk.ac.ox.webauth.asn1.Authenticator.java

License:Open Source License

/**
 * Parse an Authenticator message into an object structure.
 * @param   data    The ASN.1 structure to parse.
 *///from  w w  w  .j  av a 2s.  c o m
public Authenticator(DERApplicationSpecific data)
        throws IllegalArgumentException, IOException, GeneralSecurityException {
    if (data.getApplicationTag() != AUTHENTICATOR_APP_TAG) {
        throw new IllegalArgumentException(
                "Expected Authenticator ASN.1 APPLICATION tag of 2, got " + data.getApplicationTag() + ".");
    }
    ASN1Sequence seq = (ASN1Sequence) data.getObject();
    for (int i = 0; i < seq.size(); i++) {
        ASN1TaggedObject asn1 = (ASN1TaggedObject) seq.getObjectAt(i);
        switch (asn1.getTagNo()) {
        case 0: // authenticator-vno
            authenticator_vno = (DERInteger) asn1.getObject();
            if (authenticator_vno.getValue().longValue() != 5) {
                throw new IllegalArgumentException("The Authenticator authenticator-vno has value "
                        + authenticator_vno.getValue().longValue() + ", should be 5.");
            }
            break;
        case 1: // crealm
            crealm = (DERGeneralString) asn1.getObject();
            break;
        case 2: // cname
            cname = new PrincipalName((ASN1Sequence) asn1.getObject());
            break;
        // TODO: finish the other types (not needed at the moment)
        case 3: // cksum
            System.out.println("Authenticator: got a cksum, not using it.");
            break;
        case 4: // cusec
            cusec = (DERInteger) asn1.getObject();
            break;
        case 5: // ctime
            ctime = (DERGeneralizedTime) asn1.getObject();
            break;
        // TODO: finish the other types (not needed at the moment)
        case 6: // subkey
            System.out.println("Authenticator: got a subkey, not using it.");
            break;
        case 7: // seq-number
            seq_number = (DERInteger) asn1.getObject();
            break;
        // TODO: finish the other types (not needed at the moment)
        case 8: // authorization-data
            System.out.println("Authenticator: got authorization-data, not using it.");
            break;
        default:
            throw new IllegalArgumentException("Got an ASN.1 object with tag " + asn1.getTagNo() + ".");
        }
    }
}

From source file:uk.ac.ox.webauth.asn1.KrbApReq.java

License:Open Source License

/**
 * Parse a KRB_AP_REQ message into an object structure.
 * @param   data        The ASN.1 structure to parse.
 * @param   keyType     Which type of Kerberos encryption this key is used for.
 * @param   sessionKey  The session key to decrypt with.
 *///from w w w.  java2s  . c  om
public KrbApReq(DERApplicationSpecific data, int keyType, SecretKey sessionKey)
        throws IllegalArgumentException, IOException, GeneralSecurityException {
    if (data.getApplicationTag() != KRB_AP_REQ_APP_TAG) {
        throw new IllegalArgumentException(
                "Expected AP-REQ ASN.1 APPLICATION tag of 14, got " + data.getApplicationTag() + ".");
    }
    ASN1Sequence seq = (ASN1Sequence) data.getObject();
    for (int i = 0; i < seq.size(); i++) {
        ASN1TaggedObject asn1 = (ASN1TaggedObject) seq.getObjectAt(i);
        switch (asn1.getTagNo()) {
        case 0: // pvno
            pvno = (DERInteger) asn1.getObject();
            if (pvno.getValue().longValue() != 5) {
                throw new IllegalArgumentException(
                        "The KRB_AP_REQ pvno has value " + pvno.getValue().longValue() + ", should be 5.");
            }
            break;
        case 1: // msg-type
            msg_type = (DERInteger) asn1.getObject();
            if (msg_type.getValue().longValue() != KRB_AP_REQ_APP_TAG) {
                throw new IllegalArgumentException("The KRB_AP_REQ msg-type has value "
                        + msg_type.getValue().longValue() + ", should be " + KRB_AP_REQ_APP_TAG + ".");
            }
            break;
        case 2: // ap-options
            ap_options = new APOptions((DERBitString) asn1.getObject());
            break;
        case 3: // ticket
            // depends on ap-options having been parsed first
            if (ap_options.use_session_key()) {
                // use a key usage number of 11, for KRB_AP_REQ messages
                ticket = new Ticket((DERApplicationSpecific) asn1.getObject(), keyType, sessionKey,
                        KRB_AP_REQ_USAGE);
            } else {
                ticket = new Ticket((DERApplicationSpecific) asn1.getObject(), 0, null, 0);
            }
            break;
        case 4: // authenticator
            // use a key usage number of 11, for KRB_AP_REQ messages
            authenticator = new EncryptedData((ASN1Sequence) asn1.getObject(), keyType, sessionKey,
                    KRB_AP_REQ_USAGE);
            if (authenticator.decrypted() != null) {
                ASN1Encodable a = authenticator.decrypted();
                authenticator.decrypted(new Authenticator((DERApplicationSpecific) a));
            }
            break;
        default:
            throw new IllegalArgumentException("Got an ASN.1 object with tag " + asn1.getTagNo() + ".");
        }
    }
}

From source file:uk.ac.ox.webauth.asn1.Ticket.java

License:Open Source License

public Ticket(DERApplicationSpecific data, int keyType, SecretKey key, int keyUsage)
        throws IllegalArgumentException, IOException, GeneralSecurityException {
    if (data.getApplicationTag() != TICKET_APP_TAG) {
        throw new IllegalArgumentException(
                "Expected Ticket ASN.1 APPLICATION tag of 1, got " + data.getApplicationTag() + ".");
    }/* w  ww . j a  v a2 s.  com*/
    ASN1Sequence seq = (ASN1Sequence) data.getObject();
    for (int i = 0; i < seq.size(); i++) {
        ASN1TaggedObject asn1 = (ASN1TaggedObject) seq.getObjectAt(i);
        switch (asn1.getTagNo()) {
        case 0: // tkt-vno
            tkt_vno = (DERInteger) asn1.getObject();
            break;
        case 1: // realm
            realm = (DERGeneralString) asn1.getObject();
            break;
        case 2: // sname
            sname = new PrincipalName((ASN1Sequence) asn1.getObject());
            break;
        case 3: // enc-part
            enc_part = new EncryptedData((ASN1Sequence) asn1.getObject(), keyType, key, keyUsage);
            break;
        default:
            throw new IllegalArgumentException("Got an ASN.1 object with tag " + asn1.getTagNo() + ".");
        }
    }
}