|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.security.x509; |
|
|
|
import java.io.IOException; |
|
import java.io.OutputStream; |
|
import java.security.cert.CertificateException; |
|
import java.util.Enumeration; |
|
import java.util.Vector; |
|
|
|
import sun.security.util.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class PolicyConstraintsExtension extends Extension |
|
implements CertAttrSet<String> { |
|
|
|
|
|
|
|
*/ |
|
public static final String IDENT = "x509.info.extensions.PolicyConstraints"; |
|
|
|
|
|
*/ |
|
public static final String NAME = "PolicyConstraints"; |
|
public static final String REQUIRE = "require"; |
|
public static final String INHIBIT = "inhibit"; |
|
|
|
private static final byte TAG_REQUIRE = 0; |
|
private static final byte TAG_INHIBIT = 1; |
|
|
|
private int require = -1; |
|
private int inhibit = -1; |
|
|
|
|
|
private void encodeThis() throws IOException { |
|
if (require == -1 && inhibit == -1) { |
|
this.extensionValue = null; |
|
return; |
|
} |
|
DerOutputStream tagged = new DerOutputStream(); |
|
DerOutputStream seq = new DerOutputStream(); |
|
|
|
if (require != -1) { |
|
DerOutputStream tmp = new DerOutputStream(); |
|
tmp.putInteger(require); |
|
tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, |
|
false, TAG_REQUIRE), tmp); |
|
} |
|
if (inhibit != -1) { |
|
DerOutputStream tmp = new DerOutputStream(); |
|
tmp.putInteger(inhibit); |
|
tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, |
|
false, TAG_INHIBIT), tmp); |
|
} |
|
seq.write(DerValue.tag_Sequence, tagged); |
|
this.extensionValue = seq.toByteArray(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public PolicyConstraintsExtension(int require, int inhibit) |
|
throws IOException { |
|
this(Boolean.FALSE, require, inhibit); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public PolicyConstraintsExtension(Boolean critical, int require, int inhibit) |
|
throws IOException { |
|
this.require = require; |
|
this.inhibit = inhibit; |
|
this.extensionId = PKIXExtensions.PolicyConstraints_Id; |
|
this.critical = critical.booleanValue(); |
|
encodeThis(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public PolicyConstraintsExtension(Boolean critical, Object value) |
|
throws IOException { |
|
this.extensionId = PKIXExtensions.PolicyConstraints_Id; |
|
this.critical = critical.booleanValue(); |
|
|
|
this.extensionValue = (byte[]) value; |
|
DerValue val = new DerValue(this.extensionValue); |
|
if (val.tag != DerValue.tag_Sequence) { |
|
throw new IOException("Sequence tag missing for PolicyConstraint."); |
|
} |
|
DerInputStream in = val.data; |
|
while (in != null && in.available() != 0) { |
|
DerValue next = in.getDerValue(); |
|
|
|
if (next.isContextSpecific(TAG_REQUIRE) && !next.isConstructed()) { |
|
if (this.require != -1) |
|
throw new IOException("Duplicate requireExplicitPolicy" + |
|
"found in the PolicyConstraintsExtension"); |
|
next.resetTag(DerValue.tag_Integer); |
|
this.require = next.getInteger(); |
|
|
|
} else if (next.isContextSpecific(TAG_INHIBIT) && |
|
!next.isConstructed()) { |
|
if (this.inhibit != -1) |
|
throw new IOException("Duplicate inhibitPolicyMapping" + |
|
"found in the PolicyConstraintsExtension"); |
|
next.resetTag(DerValue.tag_Integer); |
|
this.inhibit = next.getInteger(); |
|
} else |
|
throw new IOException("Invalid encoding of PolicyConstraint"); |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public String toString() { |
|
String s; |
|
s = super.toString() + "PolicyConstraints: [" + " Require: "; |
|
if (require == -1) |
|
s += "unspecified;"; |
|
else |
|
s += require + ";"; |
|
s += "\tInhibit: "; |
|
if (inhibit == -1) |
|
s += "unspecified"; |
|
else |
|
s += inhibit; |
|
s += " ]\n"; |
|
return s; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void encode(OutputStream out) throws IOException { |
|
DerOutputStream tmp = new DerOutputStream(); |
|
if (extensionValue == null) { |
|
extensionId = PKIXExtensions.PolicyConstraints_Id; |
|
critical = false; |
|
encodeThis(); |
|
} |
|
super.encode(tmp); |
|
out.write(tmp.toByteArray()); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void set(String name, Object obj) throws IOException { |
|
if (!(obj instanceof Integer)) { |
|
throw new IOException("Attribute value should be of type Integer."); |
|
} |
|
if (name.equalsIgnoreCase(REQUIRE)) { |
|
require = ((Integer)obj).intValue(); |
|
} else if (name.equalsIgnoreCase(INHIBIT)) { |
|
inhibit = ((Integer)obj).intValue(); |
|
} else { |
|
throw new IOException("Attribute name " + "[" + name + "]" + |
|
" not recognized by " + |
|
"CertAttrSet:PolicyConstraints."); |
|
} |
|
encodeThis(); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public Integer get(String name) throws IOException { |
|
if (name.equalsIgnoreCase(REQUIRE)) { |
|
return new Integer(require); |
|
} else if (name.equalsIgnoreCase(INHIBIT)) { |
|
return new Integer(inhibit); |
|
} else { |
|
throw new IOException("Attribute name not recognized by " + |
|
"CertAttrSet:PolicyConstraints."); |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void delete(String name) throws IOException { |
|
if (name.equalsIgnoreCase(REQUIRE)) { |
|
require = -1; |
|
} else if (name.equalsIgnoreCase(INHIBIT)) { |
|
inhibit = -1; |
|
} else { |
|
throw new IOException("Attribute name not recognized by " + |
|
"CertAttrSet:PolicyConstraints."); |
|
} |
|
encodeThis(); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public Enumeration<String> getElements() { |
|
AttributeNameEnumeration elements = new AttributeNameEnumeration(); |
|
elements.addElement(REQUIRE); |
|
elements.addElement(INHIBIT); |
|
|
|
return (elements.elements()); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public String getName() { |
|
return (NAME); |
|
} |
|
} |