|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.security.x509; |
|
|
|
import java.io.IOException; |
|
import java.io.OutputStream; |
|
|
|
import java.util.*; |
|
|
|
import sun.security.util.DerOutputStream; |
|
import sun.security.util.DerValue; |
|
|
|
/** |
|
* The Authority Information Access Extension (OID = 1.3.6.1.5.5.7.1.1). |
|
* <p> |
|
* The AIA extension identifies how to access CA information and services |
|
* for the certificate in which it appears. It enables CAs to issue their |
|
* certificates pre-configured with the URLs appropriate for contacting |
|
* services relevant to those certificates. For example, a CA may issue a |
|
* certificate that identifies the specific OCSP Responder to use when |
|
* performing on-line validation of that certificate. |
|
* <p> |
|
* This extension is defined in <a href="http://tools.ietf.org/html/rfc5280"> |
|
* Internet X.509 PKI Certificate and Certificate Revocation List |
|
* (CRL) Profile</a>. The profile permits |
|
* the extension to be included in end-entity or CA certificates, |
|
* and it must be marked as non-critical. Its ASN.1 definition is as follows: |
|
* <pre> |
|
* id-pe-authorityInfoAccess OBJECT IDENTIFIER ::= { id-pe 1 } |
|
* |
|
* AuthorityInfoAccessSyntax ::= |
|
* SEQUENCE SIZE (1..MAX) OF AccessDescription |
|
* |
|
* AccessDescription ::= SEQUENCE { |
|
* accessMethod OBJECT IDENTIFIER, |
|
* accessLocation GeneralName } |
|
* </pre> |
|
* |
|
* @see Extension |
|
* @see CertAttrSet |
|
*/ |
|
|
|
public class AuthorityInfoAccessExtension extends Extension |
|
implements CertAttrSet<String> { |
|
|
|
|
|
|
|
|
|
*/ |
|
public static final String IDENT = |
|
"x509.info.extensions.AuthorityInfoAccess"; |
|
|
|
|
|
|
|
*/ |
|
public static final String NAME = "AuthorityInfoAccess"; |
|
public static final String DESCRIPTIONS = "descriptions"; |
|
|
|
|
|
|
|
*/ |
|
private List<AccessDescription> accessDescriptions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public AuthorityInfoAccessExtension( |
|
List<AccessDescription> accessDescriptions) throws IOException { |
|
this.extensionId = PKIXExtensions.AuthInfoAccess_Id; |
|
this.critical = false; |
|
this.accessDescriptions = accessDescriptions; |
|
encodeThis(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public AuthorityInfoAccessExtension(Boolean critical, Object value) |
|
throws IOException { |
|
this.extensionId = PKIXExtensions.AuthInfoAccess_Id; |
|
this.critical = critical.booleanValue(); |
|
|
|
if (!(value instanceof byte[])) { |
|
throw new IOException("Illegal argument type"); |
|
} |
|
|
|
extensionValue = (byte[])value; |
|
DerValue val = new DerValue(extensionValue); |
|
if (val.tag != DerValue.tag_Sequence) { |
|
throw new IOException("Invalid encoding for " + |
|
"AuthorityInfoAccessExtension."); |
|
} |
|
accessDescriptions = new ArrayList<AccessDescription>(); |
|
while (val.data.available() != 0) { |
|
DerValue seq = val.data.getDerValue(); |
|
AccessDescription accessDescription = new AccessDescription(seq); |
|
accessDescriptions.add(accessDescription); |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public List<AccessDescription> getAccessDescriptions() { |
|
return accessDescriptions; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public String getName() { |
|
return NAME; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void encode(OutputStream out) throws IOException { |
|
DerOutputStream tmp = new DerOutputStream(); |
|
if (this.extensionValue == null) { |
|
this.extensionId = PKIXExtensions.AuthInfoAccess_Id; |
|
this.critical = false; |
|
encodeThis(); |
|
} |
|
super.encode(tmp); |
|
out.write(tmp.toByteArray()); |
|
} |
|
|
|
|
|
|
|
*/ |
|
@SuppressWarnings("unchecked") |
|
public void set(String name, Object obj) throws IOException { |
|
if (name.equalsIgnoreCase(DESCRIPTIONS)) { |
|
if (!(obj instanceof List)) { |
|
throw new IOException("Attribute value should be of type List."); |
|
} |
|
accessDescriptions = (List<AccessDescription>)obj; |
|
} else { |
|
throw new IOException("Attribute name [" + name + |
|
"] not recognized by " + |
|
"CertAttrSet:AuthorityInfoAccessExtension."); |
|
} |
|
encodeThis(); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public List<AccessDescription> get(String name) throws IOException { |
|
if (name.equalsIgnoreCase(DESCRIPTIONS)) { |
|
return accessDescriptions; |
|
} else { |
|
throw new IOException("Attribute name [" + name + |
|
"] not recognized by " + |
|
"CertAttrSet:AuthorityInfoAccessExtension."); |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void delete(String name) throws IOException { |
|
if (name.equalsIgnoreCase(DESCRIPTIONS)) { |
|
accessDescriptions = new ArrayList<AccessDescription>(); |
|
} else { |
|
throw new IOException("Attribute name [" + name + |
|
"] not recognized by " + |
|
"CertAttrSet:AuthorityInfoAccessExtension."); |
|
} |
|
encodeThis(); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public Enumeration<String> getElements() { |
|
AttributeNameEnumeration elements = new AttributeNameEnumeration(); |
|
elements.addElement(DESCRIPTIONS); |
|
return elements.elements(); |
|
} |
|
|
|
|
|
private void encodeThis() throws IOException { |
|
if (accessDescriptions.isEmpty()) { |
|
this.extensionValue = null; |
|
} else { |
|
DerOutputStream ads = new DerOutputStream(); |
|
for (AccessDescription accessDescription : accessDescriptions) { |
|
accessDescription.encode(ads); |
|
} |
|
DerOutputStream seq = new DerOutputStream(); |
|
seq.write(DerValue.tag_Sequence, ads); |
|
this.extensionValue = seq.toByteArray(); |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public String toString() { |
|
return super.toString() + "AuthorityInfoAccess [\n " |
|
+ accessDescriptions + "\n]\n"; |
|
} |
|
|
|
} |