1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19* @author Alexander Y. Kleymenov 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.security.provider.cert; 24 25import java.math.BigInteger; 26import java.security.cert.CRLException; 27import java.security.cert.X509CRLEntry; 28import java.util.Date; 29import java.util.Set; 30 31import javax.security.auth.x500.X500Principal; 32 33import org.apache.harmony.security.x509.Extension; 34import org.apache.harmony.security.x509.Extensions; 35import org.apache.harmony.security.x509.TBSCertList; 36 37/** 38 * Implementation of X509CRLEntry. It wraps the instance 39 * of org.apache.harmony.security.x509.TBSCertList.RevokedCertificate 40 * obtained during the decoding of TBSCertList substructure 41 * of the CertificateList structure which is an X.509 form of CRL. 42 * (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt) 43 * Normally the instances of this class are constructed by involving 44 * X509CRLImpl object. 45 * @see org.apache.harmony.security.x509.TBSCertList 46 * @see org.apache.harmony.security.provider.cert.X509CRLImpl 47 * @see java.security.cert.X509CRLEntry 48 */ 49public class X509CRLEntryImpl extends X509CRLEntry { 50 51 // the crl entry object to be wrapped in X509CRLEntry 52 private final TBSCertList.RevokedCertificate rcert; 53 // the extensions of the entry 54 private final Extensions extensions; 55 // issuer of the revoked certificate described by this crl entry 56 private final X500Principal issuer; 57 58 // encoded form of this revoked certificate entry 59 private byte[] encoding; 60 61 /** 62 * Creates an instance on the base of existing 63 * <code>TBSCertList.RevokedCertificate</code> object and 64 * information about the issuer of revoked certificate. 65 * If specified issuer is null, it is supposed that issuer 66 * of the revoked certificate is the same as for involving CRL. 67 */ 68 public X509CRLEntryImpl(TBSCertList.RevokedCertificate rcert, 69 X500Principal issuer) { 70 this.rcert = rcert; 71 this.extensions = rcert.getCrlEntryExtensions(); 72 this.issuer = issuer; 73 } 74 75 // --------------------------------------------------------------------- 76 // ------ java.security.cert.X509CRLEntry method implementations ------- 77 // --------------------------------------------------------------------- 78 79 /** 80 * @see java.security.cert.X509CRLEntry#getEncoded() 81 * method documentation for more info 82 */ 83 public byte[] getEncoded() throws CRLException { 84 if (encoding == null) { 85 encoding = rcert.getEncoded(); 86 } 87 byte[] result = new byte[encoding.length]; 88 System.arraycopy(encoding, 0, result, 0, encoding.length); 89 return result; 90 } 91 92 /** 93 * @see java.security.cert.X509CRLEntry#getSerialNumber() 94 * method documentation for more info 95 */ 96 public BigInteger getSerialNumber() { 97 return rcert.getUserCertificate(); 98 } 99 100 /** 101 * @see java.security.cert.X509CRLEntry#getCertificateIssuer() 102 * method documentation for more info 103 */ 104 public X500Principal getCertificateIssuer() { 105 return issuer; 106 } 107 108 /** 109 * @see java.security.cert.X509CRLEntry#getRevocationDate() 110 * method documentation for more info 111 */ 112 public Date getRevocationDate() { 113 return rcert.getRevocationDate(); 114 } 115 116 /** 117 * @see java.security.cert.X509CRLEntry#hasExtensions() 118 * method documentation for more info 119 */ 120 public boolean hasExtensions() { 121 return (extensions != null) && (extensions.size() != 0); 122 } 123 124 /** 125 * @see java.security.cert.X509CRLEntry#toString() 126 * method documentation for more info 127 */ 128 public String toString() { 129 return "X509CRLEntryImpl: "+rcert.toString(); //$NON-NLS-1$ 130 } 131 132 // --------------------------------------------------------------------- 133 // ------ java.security.cert.X509Extension method implementations ------ 134 // --------------------------------------------------------------------- 135 136 /** 137 * @see java.security.cert.X509Extension#getNonCriticalExtensionOIDs() 138 * method documentation for more info 139 */ 140 public Set getNonCriticalExtensionOIDs() { 141 if (extensions == null) { 142 return null; 143 } 144 return extensions.getNonCriticalExtensions(); 145 } 146 147 /** 148 * @see java.security.cert.X509Extension#getCriticalExtensionOIDs() 149 * method documentation for more info 150 */ 151 public Set getCriticalExtensionOIDs() { 152 if (extensions == null) { 153 return null; 154 } 155 return extensions.getCriticalExtensions(); 156 } 157 158 /** 159 * @see java.security.cert.X509Extension#getExtensionValue(String) 160 * method documentation for more info 161 */ 162 public byte[] getExtensionValue(String oid) { 163 if (extensions == null) { 164 return null; 165 } 166 Extension ext = extensions.getExtensionByOID(oid); 167 return (ext == null) ? null : ext.getRawExtnValue(); 168 } 169 170 /** 171 * @see java.security.cert.X509Extension#hasUnsupportedCriticalExtension() 172 * method documentation for more info 173 */ 174 public boolean hasUnsupportedCriticalExtension() { 175 if (extensions == null) { 176 return false; 177 } 178 return extensions.hasUnsupportedCritical(); 179 } 180} 181 182