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 package org.apache.harmony.security.x509; 19 20 import java.io.IOException; 21 import javax.security.auth.x500.X500Principal; 22 import org.apache.harmony.security.asn1.ASN1Sequence; 23 import org.apache.harmony.security.asn1.ASN1Type; 24 import org.apache.harmony.security.asn1.BerInputStream; 25 import org.apache.harmony.security.x501.Name; 26 27 /** 28 * CRL Entry's Certificate Issuer Extension (OID = 2.5.29.29). 29 * It is a CRL entry extension and contains the GeneralNames describing 30 * the issuer of revoked certificate. Its ASN.1 notation is as follows: 31 * <pre> 32 * id-ce-certificateIssuer OBJECT IDENTIFIER ::= { id-ce 29 } 33 * 34 * certificateIssuer ::= GeneralNames 35 * </pre> 36 * (as specified in RFC 3280) 37 * In java implementation it is presumed that GeneralNames consist of 38 * one element and its type is directoryName. 39 */ 40 public class CertificateIssuer extends ExtensionValue { 41 42 // certificate issuer value 43 private X500Principal issuer; 44 45 /** 46 * Creates an object on the base of GeneralName structure. 47 */ 48 public CertificateIssuer(GeneralName issuer) { 49 super(ASN1.encode(issuer)); 50 } 51 52 /** 53 * Creates an object on the base of its encoded form. 54 */ 55 public CertificateIssuer(byte[] encoding) { 56 super(encoding); 57 } 58 59 /** 60 * Returns the issuer. 61 */ 62 public X500Principal getIssuer() throws IOException { 63 if (issuer == null) { 64 issuer = (X500Principal) ASN1.decode(getEncoded()); 65 } 66 return issuer; 67 } 68 69 /** 70 * Places the string representation of extension value 71 * into the StringBuffer object. 72 */ 73 public void dumpValue(StringBuffer buffer, String prefix) { 74 buffer.append(prefix).append("Certificate Issuer: "); 75 if (issuer == null) { 76 try { 77 issuer = getIssuer(); 78 } catch (IOException e) { 79 // incorrect extension value encoding 80 buffer.append("Unparseable (incorrect!) extension value:\n"); 81 super.dumpValue(buffer); 82 } 83 } 84 buffer.append(issuer).append('\n'); 85 } 86 87 /** 88 * ASN.1 Encoder/Decoder. 89 */ 90 public static final ASN1Type ASN1 = new ASN1Sequence(new ASN1Type[] { 91 GeneralName.ASN1 92 }) { 93 public Object getDecodedObject(BerInputStream in) { 94 return ((Name) ((GeneralName) ((Object[]) in.content)[0]) 95 .getName()).getX500Principal(); 96 } 97 98 protected void getValues(Object object, Object[] values) { 99 values[0] = object; 100 } 101 }; 102 } 103