1 7 8 9 package org.enhydra.oyster.cms; 10 11 import org.enhydra.oyster.exception.SMIMEException; 12 import org.enhydra.oyster.exception.ErrorStorage; 13 import org.enhydra.oyster.der.DERSequencePr; 14 import org.enhydra.oyster.der.DERObjectIdentifier; 15 import org.enhydra.oyster.util.DERLengthSearcher; 16 import org.enhydra.oyster.util.ByteArrayComparator; 17 import java.security.cert.X509Certificate ; 18 19 20 26 public class IssuerName extends DERSequencePr { 27 28 31 private byte[] dNames; 32 33 36 private int enable = 0; 37 38 46 public IssuerName (X509Certificate cert0) throws SMIMEException 47 { 48 byte[] tbs = null; 49 try { 50 tbs = cert0.getTBSCertificate(); 51 } 52 catch(Exception e) { 53 throw SMIMEException.getInstance(this, e, "constructor" ); 54 } 55 dNames = findDNfromTBS(tbs); 56 } 57 58 64 private byte[] findDNfromTBS (byte[] tbs0) { 65 int start = 0; byte[] temp; 67 DERLengthSearcher len = new DERLengthSearcher(start, tbs0); 68 start = start + len.getLengthtDERLengthPart() + 1; len.newInitialization(start, tbs0); 70 start = start + len.getLengthtDERLengthPart() + len.getLengthtDERContentPart() + 1; len.newInitialization(start, tbs0); 72 start = start + len.getLengthtDERLengthPart() + len.getLengthtDERContentPart() + 1; len.newInitialization(start, tbs0); 74 start = start + len.getLengthtDERLengthPart() + len.getLengthtDERContentPart() + 1; len.newInitialization(start, tbs0); 76 start = start + len.getLengthtDERLengthPart() + 1; 77 int stop = start + len.getLengthtDERContentPart() - 1; 78 temp = new byte[stop - start + 1]; 79 for (int i = start; i <= stop; i++) 80 temp[i - start] = tbs0[i]; 81 return temp; 82 } 83 84 88 public void addAllRelativeDN () throws SMIMEException { 89 super.addContent(dNames); 90 enable = 1; 91 } 92 93 104 public int addParticularRelativeDN (String id_at_type0) throws SMIMEException { 105 if (enable == 1) 106 throw new SMIMEException(this, 1021); 107 byte[] temp = new DERObjectIdentifier(id_at_type0, "NAME_STRING").getDEREncoded(); 108 ByteArrayComparator bcomp = new ByteArrayComparator(temp, dNames); 109 int positionFirst = bcomp.getMatchingIndex(); 110 if (positionFirst != -1) { 112 positionFirst = positionFirst + temp.length; 113 DERLengthSearcher len = new DERLengthSearcher(positionFirst, dNames); 114 positionFirst = positionFirst + len.getLengthtDERLengthPart() + 1; 115 int positionLast = positionFirst + len.getLengthtDERContentPart() - 1; 116 byte[] name = new byte[positionLast - positionFirst + 1]; 117 for (int i = positionFirst; i <= positionLast; i++) name[i - positionFirst] = dNames[i]; 119 RelativeDistinguishedName rdn = null; 120 try { 121 rdn = new RelativeDistinguishedName(id_at_type0, "NAME_STRING", new String (name, "ISO-8859-1")); 122 } 123 catch(Exception e) { 124 throw SMIMEException.getInstance(this, e, "addParticularRelativeDN" ); 125 } 126 super.addContent(rdn.getDEREncoded()); 127 return 0; } 129 else 130 return -1; } 132 } 133 134 135 136 | Popular Tags |