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 ; 8 9 23 public class AuthorityKeyIdentifier implements V3Extension 24 { 25 String value = null; 26 BigInteger serialNumber; 27 byte [] keyId; 28 29 public BigInteger getSerialNumber() { return serialNumber; } 30 31 public byte [] getKeyId() { return keyId; } 32 33 public void init(ASN1Object asn1object) throws Exception 34 { 35 if (!asn1object.isASN1Type(ASN1Type.SEQUENCE)) 36 throw new Exception ("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 ((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 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 toString() 77 { 78 return value; 79 } 80 } 81 82 | Popular Tags |