1 17 18 19 package org.apache.geronimo.util.jce.provider; 20 21 import java.io.ByteArrayOutputStream ; 22 import java.io.IOException ; 23 import java.math.BigInteger ; 24 import java.security.cert.CRLException ; 25 import java.security.cert.X509CRLEntry ; 26 import java.util.Date ; 27 import java.util.Enumeration ; 28 import java.util.HashSet ; 29 import java.util.Set ; 30 31 import org.apache.geronimo.util.asn1.DERObjectIdentifier; 32 import org.apache.geronimo.util.asn1.DEROutputStream; 33 import org.apache.geronimo.util.asn1.x509.TBSCertList; 34 import org.apache.geronimo.util.asn1.x509.X509Extension; 35 import org.apache.geronimo.util.asn1.x509.X509Extensions; 36 37 45 public class X509CRLEntryObject extends X509CRLEntry 46 { 47 private TBSCertList.CRLEntry c; 48 49 public X509CRLEntryObject( 50 TBSCertList.CRLEntry c) 51 { 52 this.c = c; 53 } 54 55 59 public boolean hasUnsupportedCriticalExtension() 60 { 61 Set extns = getCriticalExtensionOIDs(); 62 if ( extns != null && !extns.isEmpty() ) 63 { 64 return true; 65 } 66 67 return false; 68 } 69 70 private Set getExtensionOIDs(boolean critical) 71 { 72 X509Extensions extensions = c.getExtensions(); 73 74 if ( extensions != null ) 75 { 76 HashSet set = new HashSet (); 77 Enumeration e = extensions.oids(); 78 79 while (e.hasMoreElements()) 80 { 81 DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement(); 82 X509Extension ext = extensions.getExtension(oid); 83 84 if (critical == ext.isCritical()) 85 { 86 set.add(oid.getId()); 87 } 88 } 89 90 return set; 91 } 92 93 return null; 94 } 95 96 public Set getCriticalExtensionOIDs() 97 { 98 return getExtensionOIDs(true); 99 } 100 101 public Set getNonCriticalExtensionOIDs() 102 { 103 return getExtensionOIDs(false); 104 } 105 106 public byte[] getExtensionValue(String oid) 107 { 108 X509Extensions exts = c.getExtensions(); 109 110 if (exts != null) 111 { 112 X509Extension ext = exts.getExtension(new DERObjectIdentifier(oid)); 113 114 if (ext != null) 115 { 116 try 117 { 118 return ext.getValue().getEncoded(); 119 } 120 catch (Exception e) 121 { 122 throw new RuntimeException ("error encoding " + e.toString()); 123 } 124 } 125 } 126 127 return null; 128 } 129 130 public byte[] getEncoded() 131 throws CRLException 132 { 133 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 134 DEROutputStream dOut = new DEROutputStream(bOut); 135 136 try 137 { 138 dOut.writeObject(c); 139 140 return bOut.toByteArray(); 141 } 142 catch (IOException e) 143 { 144 throw new CRLException (e.toString()); 145 } 146 } 147 148 public BigInteger getSerialNumber() 149 { 150 return c.getUserCertificate().getValue(); 151 } 152 153 public Date getRevocationDate() 154 { 155 return c.getRevocationDate().getDate(); 156 } 157 158 public boolean hasExtensions() 159 { 160 return c.getExtensions() != null; 161 } 162 163 public String toString() 164 { 165 StringBuffer buf = new StringBuffer (); 166 String nl = System.getProperty("line.separator"); 167 168 buf.append(" userCertificate: " + this.getSerialNumber() + nl); 169 buf.append(" revocationDate: " + this.getRevocationDate() + nl); 170 171 172 X509Extensions extensions = c.getExtensions(); 173 174 if ( extensions != null ) 175 { 176 Enumeration e = extensions.oids(); 177 if ( e.hasMoreElements() ) 178 { 179 buf.append(" crlEntryExtensions:" + nl); 180 181 while ( e.hasMoreElements() ) 182 { 183 DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement(); 184 X509Extension ext = extensions.getExtension(oid); 185 buf.append(ext); 186 } 187 } 188 } 189 190 return buf.toString(); 191 } 192 } 193 | Popular Tags |