KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > security > cert > extensions > AuthorityKeyIdentifier


1
2 package com.ca.commons.security.cert.extensions;
3
4 import com.ca.commons.security.asn1.*;
5 import com.ca.commons.cbutil.CBParse;
6
7 import java.math.BigInteger JavaDoc;
8
9 /**
10  * <pre>
11  * AuthorityKeyIdentifier ::= SEQUENCE {
12  * keyIdentifier [0] KeyIdentifier OPTIONAL,
13  * authorityCertIssuer [1] GeneralNames OPTIONAL,
14  * authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL }
15  * -- authorityCertIssuer and authorityCertSerialNumber shall both
16  * -- be present or both be absent
17  *
18  * KeyIdentifier ::= OCTET STRING
19  * </pre>
20  *
21  * @author vbui
22  */

23 public class AuthorityKeyIdentifier implements V3Extension
24 {
25     String JavaDoc value = null;
26     BigInteger JavaDoc serialNumber;
27     byte [] keyId;
28
29     public BigInteger JavaDoc getSerialNumber() { return serialNumber; }
30
31     public byte [] getKeyId() { return keyId; }
32
33     public void init(ASN1Object asn1object) throws Exception JavaDoc
34     {
35         if (!asn1object.isASN1Type(ASN1Type.SEQUENCE))
36             throw new Exception JavaDoc("Wrong ASN.1 type for AuthorityKeyIdentifier");
37
38         for (int i = 0; i < asn1object.size(); i++)
39         {
40             ASN1Object compBig = asn1object.getComponent(i);
41             ASN1Object nextComp = (ASN1Object) compBig.getValue();
42
43             if (nextComp.isASN1Type(ASN1Type.OCTET_STRING) && i == 0)
44             {
45                 keyId = (byte[]) nextComp.getValue();
46                 value = "KeyID: " + CBParse.bytes2HexSplit(keyId, 4);
47             }
48             else if (nextComp.isASN1Type(ASN1Type.OCTET_STRING))
49             {
50                 if (value == null)
51                     value = "Authority Cert SerialNumber: " + CBParse.bytes2HexSplit((byte[]) nextComp.getValue(), 4);
52                 else
53                     value = value + "\nAuthority Cert SerialNumber: " + CBParse.bytes2HexSplit((byte[]) nextComp.getValue(), 4);
54                 serialNumber = new BigInteger JavaDoc((byte[]) nextComp.getValue());
55             }
56             else
57             {
58                 ASN1Object gnames = (ASN1Object) nextComp.getValue();
59
60                 IssuerAltName ian = new IssuerAltName();
61                 ian.init(gnames);
62
63                 String JavaDoc gnamesString = ian.toString();
64                 if (gnamesString.startsWith("Unrecognised"))
65                     gnamesString = "Directory Address: " + IssuerAltName.cleanName(new Name(gnames).toString());
66
67                 if (value == null)
68                     value = gnamesString;
69                 else
70                     value = value + "\n" + gnamesString;
71             }
72
73         }
74     }
75
76     public String JavaDoc toString()
77     {
78         return value;
79     }
80 }
81
82
Popular Tags