001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.util.asn1.x509; 019 020 import org.apache.geronimo.util.asn1.ASN1Encodable; 021 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 022 import org.apache.geronimo.util.asn1.ASN1Sequence; 023 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 024 import org.apache.geronimo.util.asn1.DERBitString; 025 import org.apache.geronimo.util.asn1.DERInteger; 026 import org.apache.geronimo.util.asn1.DERObject; 027 import org.apache.geronimo.util.asn1.DERSequence; 028 029 public class AttributeCertificateInfo 030 extends ASN1Encodable 031 { 032 private DERInteger version; 033 private Holder holder; 034 private AttCertIssuer issuer; 035 private AlgorithmIdentifier signature; 036 private DERInteger serialNumber; 037 private AttCertValidityPeriod attrCertValidityPeriod; 038 private ASN1Sequence attributes; 039 private DERBitString issuerUniqueID; 040 private X509Extensions extensions; 041 042 public static AttributeCertificateInfo getInstance( 043 ASN1TaggedObject obj, 044 boolean explicit) 045 { 046 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 047 } 048 049 public static AttributeCertificateInfo getInstance( 050 Object obj) 051 { 052 if (obj instanceof AttributeCertificateInfo) 053 { 054 return (AttributeCertificateInfo)obj; 055 } 056 else if (obj instanceof ASN1Sequence) 057 { 058 return new AttributeCertificateInfo((ASN1Sequence)obj); 059 } 060 061 throw new IllegalArgumentException("unknown object in factory"); 062 } 063 064 public AttributeCertificateInfo( 065 ASN1Sequence seq) 066 { 067 this.version = DERInteger.getInstance(seq.getObjectAt(0)); 068 this.holder = Holder.getInstance(seq.getObjectAt(1)); 069 this.issuer = AttCertIssuer.getInstance(seq.getObjectAt(2)); 070 this.signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(3)); 071 this.serialNumber = DERInteger.getInstance(seq.getObjectAt(4)); 072 this.attrCertValidityPeriod = AttCertValidityPeriod.getInstance(seq.getObjectAt(5)); 073 this.attributes = ASN1Sequence.getInstance(seq.getObjectAt(6)); 074 075 for (int i = 7; i < seq.size(); i++) 076 { 077 ASN1Encodable obj = (ASN1Encodable)seq.getObjectAt(i); 078 079 if (obj instanceof DERBitString) 080 { 081 this.issuerUniqueID = DERBitString.getInstance(seq.getObjectAt(i)); 082 } 083 else if (obj instanceof ASN1Sequence || obj instanceof X509Extensions) 084 { 085 this.extensions = X509Extensions.getInstance(seq.getObjectAt(i)); 086 } 087 } 088 } 089 090 public DERInteger getVersion() 091 { 092 return version; 093 } 094 095 public Holder getHolder() 096 { 097 return holder; 098 } 099 100 public AttCertIssuer getIssuer() 101 { 102 return issuer; 103 } 104 105 public AlgorithmIdentifier getSignature() 106 { 107 return signature; 108 } 109 110 public DERInteger getSerialNumber() 111 { 112 return serialNumber; 113 } 114 115 public AttCertValidityPeriod getAttrCertValidityPeriod() 116 { 117 return attrCertValidityPeriod; 118 } 119 120 public ASN1Sequence getAttributes() 121 { 122 return attributes; 123 } 124 125 public DERBitString getIssuerUniqueID() 126 { 127 return issuerUniqueID; 128 } 129 130 public X509Extensions getExtensions() 131 { 132 return extensions; 133 } 134 135 /** 136 * Produce an object suitable for an ASN1OutputStream. 137 * <pre> 138 * AttributeCertificateInfo ::= SEQUENCE { 139 * version AttCertVersion -- version is v2, 140 * holder Holder, 141 * issuer AttCertIssuer, 142 * signature AlgorithmIdentifier, 143 * serialNumber CertificateSerialNumber, 144 * attrCertValidityPeriod AttCertValidityPeriod, 145 * attributes SEQUENCE OF Attribute, 146 * issuerUniqueID UniqueIdentifier OPTIONAL, 147 * extensions Extensions OPTIONAL 148 * } 149 * 150 * AttCertVersion ::= INTEGER { v2(1) } 151 * </pre> 152 */ 153 public DERObject toASN1Object() 154 { 155 ASN1EncodableVector v = new ASN1EncodableVector(); 156 157 v.add(version); 158 v.add(holder); 159 v.add(issuer); 160 v.add(signature); 161 v.add(serialNumber); 162 v.add(attrCertValidityPeriod); 163 v.add(attributes); 164 165 if (issuerUniqueID != null) 166 { 167 v.add(issuerUniqueID); 168 } 169 170 if (extensions != null) 171 { 172 v.add(extensions); 173 } 174 175 return new DERSequence(v); 176 } 177 }