001package org.apache.commons.ssl.org.bouncycastle.asn1.x509;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1ObjectIdentifier;
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
006
007/**
008 * The KeyPurposeId object.
009 * <pre>
010 *     KeyPurposeId ::= OBJECT IDENTIFIER
011 *
012 *     id-kp ::= OBJECT IDENTIFIER { iso(1) identified-organization(3) 
013 *          dod(6) internet(1) security(5) mechanisms(5) pkix(7) 3}
014 *
015 * </pre>
016 * To create a new KeyPurposeId where none of the below suit, use
017 * <pre>
018 *     ASN1ObjectIdentifier newKeyPurposeIdOID = new ASN1ObjectIdentifier("1.3.6.1...");
019 *
020 *     KeyPurposeId newKeyPurposeId = KeyPurposeId.getInstance(newKeyPurposeIdOID);
021 * </pre>
022 */
023public class KeyPurposeId
024    extends ASN1Object
025{
026    private static final ASN1ObjectIdentifier id_kp = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.3");
027
028    /**
029     * { 2 5 29 37 0 }
030     */
031    public static final KeyPurposeId anyExtendedKeyUsage = new KeyPurposeId(Extension.extendedKeyUsage.branch("0"));
032
033    /**
034     * { id-kp 1 }
035     */
036    public static final KeyPurposeId id_kp_serverAuth = new KeyPurposeId(id_kp.branch("1"));
037    /**
038     * { id-kp 2 }
039     */
040    public static final KeyPurposeId id_kp_clientAuth = new KeyPurposeId(id_kp.branch("2"));
041    /**
042     * { id-kp 3 }
043     */
044    public static final KeyPurposeId id_kp_codeSigning = new KeyPurposeId(id_kp.branch("3"));
045    /**
046     * { id-kp 4 }
047     */
048    public static final KeyPurposeId id_kp_emailProtection = new KeyPurposeId(id_kp.branch("4"));
049    /**
050     * Usage deprecated by RFC4945 - was { id-kp 5 }
051     */
052    public static final KeyPurposeId id_kp_ipsecEndSystem = new KeyPurposeId(id_kp.branch("5"));
053    /**
054     * Usage deprecated by RFC4945 - was { id-kp 6 }
055     */
056    public static final KeyPurposeId id_kp_ipsecTunnel = new KeyPurposeId(id_kp.branch("6"));
057    /**
058     * Usage deprecated by RFC4945 - was { idkp 7 }
059     */
060    public static final KeyPurposeId id_kp_ipsecUser = new KeyPurposeId(id_kp.branch("7"));
061    /**
062     * { id-kp 8 }
063     */
064    public static final KeyPurposeId id_kp_timeStamping = new KeyPurposeId(id_kp.branch("8"));
065    /**
066     * { id-kp 9 }
067     */
068    public static final KeyPurposeId id_kp_OCSPSigning = new KeyPurposeId(id_kp.branch("9"));
069    /**
070     * { id-kp 10 }
071     */
072    public static final KeyPurposeId id_kp_dvcs = new KeyPurposeId(id_kp.branch("10"));
073    /**
074     * { id-kp 11 }
075     */
076    public static final KeyPurposeId id_kp_sbgpCertAAServerAuth = new KeyPurposeId(id_kp.branch("11"));
077    /**
078     * { id-kp 12 }
079     */
080    public static final KeyPurposeId id_kp_scvp_responder = new KeyPurposeId(id_kp.branch("12"));
081    /**
082     * { id-kp 13 }
083     */
084    public static final KeyPurposeId id_kp_eapOverPPP = new KeyPurposeId(id_kp.branch("13"));
085    /**
086     * { id-kp 14 }
087     */
088    public static final KeyPurposeId id_kp_eapOverLAN = new KeyPurposeId(id_kp.branch("14"));
089    /**
090     * { id-kp 15 }
091     */
092    public static final KeyPurposeId id_kp_scvpServer = new KeyPurposeId(id_kp.branch("15"));
093    /**
094     * { id-kp 16 }
095     */
096    public static final KeyPurposeId id_kp_scvpClient = new KeyPurposeId(id_kp.branch("16"));
097    /**
098     * { id-kp 17 }
099     */
100    public static final KeyPurposeId id_kp_ipsecIKE = new KeyPurposeId(id_kp.branch("17"));
101    /**
102     * { id-kp 18 }
103     */
104    public static final KeyPurposeId id_kp_capwapAC = new KeyPurposeId(id_kp.branch("18"));
105    /**
106     * { id-kp 19 }
107     */
108    public static final KeyPurposeId id_kp_capwapWTP = new KeyPurposeId(id_kp.branch("19"));
109
110    //
111    // microsoft key purpose ids
112    //
113    /**
114     * { 1 3 6 1 4 1 311 20 2 2 }
115     */
116    public static final KeyPurposeId id_kp_smartcardlogon = new KeyPurposeId(new ASN1ObjectIdentifier("1.3.6.1.4.1.311.20.2.2"));
117
118    private ASN1ObjectIdentifier id;
119
120    private KeyPurposeId(ASN1ObjectIdentifier id)
121    {
122        this.id = id;
123    }
124
125    /**
126     * @deprecated use getInstance and an OID or one of the constants above.
127     * @param id string representation of an OID.
128     */
129    public KeyPurposeId(String id)
130    {
131        this(new ASN1ObjectIdentifier(id));
132    }
133
134    public static KeyPurposeId getInstance(Object o)
135    {
136        if (o instanceof KeyPurposeId)
137        {
138            return (KeyPurposeId)o;
139        }
140        else if (o != null)
141        {
142            return new KeyPurposeId(ASN1ObjectIdentifier.getInstance(o));
143        }
144
145        return null;
146    }
147
148    public ASN1Primitive toASN1Primitive()
149    {
150        return id;
151    }
152
153    public String getId()
154    {
155        return id.getId();
156    }
157}