summaryrefslogtreecommitdiffstats
path: root/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java')
-rw-r--r--pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java266
1 files changed, 129 insertions, 137 deletions
diff --git a/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java b/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java
index 4c3c4fa08..83c031ead 100644
--- a/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java
+++ b/pki/base/util/src/netscape/security/x509/CertificatePoliciesExtension.java
@@ -16,7 +16,7 @@
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package netscape.security.x509;
-
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -27,31 +27,24 @@ import java.util.Vector;
import netscape.security.util.DerOutputStream;
import netscape.security.util.DerValue;
import netscape.security.util.ObjectIdentifier;
-
+
/**
* This class defines the Certificate Policies Extension.
*
- * <p>The certificate policies extension conatins a sequence of policy
- * information terms, each of which consists of an object identifier
- * (OID) and optional qualifiers. These policy information terms
- * indicate the policy under which the certificate has been issued and
- * the purposes for which the certificate may be used. Aplications with
- * specific policy requirements are expected to have a list of those
- * policies which they will accept and to compare the policy OIDs in the
- * certificate to that list. If this extension is critical, the path
- * validation software must be able to interpret this extension, or must
- * reject the certificate.
- *
+ * <p>
+ * The certificate policies extension conatins a sequence of policy information terms, each of which consists of an object identifier (OID) and optional qualifiers. These policy information terms indicate the policy under which the certificate has been issued and the purposes for which the certificate may be used. Aplications with specific policy requirements are expected to have a list of those policies which they will accept and to compare the policy OIDs in the certificate to that list. If
+ * this extension is critical, the path validation software must be able to interpret this extension, or must reject the certificate.
+ *
* <pre>
* CertificatePolicies ::= SEQUENECE OF PolicyInformation
* </pre>
- *
- *@author Christine Ho
- *@see Extension
- *@see CertAttrSet
+ *
+ * @author Christine Ho
+ * @see Extension
+ * @see CertAttrSet
*/
public class CertificatePoliciesExtension extends Extension
-implements CertAttrSet {
+ implements CertAttrSet {
/**
*
@@ -66,21 +59,20 @@ implements CertAttrSet {
* Attribute names.
*/
public static final String NAME = "CertificatePolicies";
- public static final String INFOS = "infos";
-
+ public static final String INFOS = "infos";
// Private data members
private Vector<CertificatePolicyInfo> mInfos;
-
+
// Encode this extension value
private void encodeThis() throws IOException {
DerOutputStream os = new DerOutputStream();
DerOutputStream tmp = new DerOutputStream();
-
+
for (int i = 0; i < mInfos.size(); i++) {
- ((CertificatePolicyInfo)mInfos.elementAt(i)).encode(tmp);
+ ((CertificatePolicyInfo) mInfos.elementAt(i)).encode(tmp);
}
- os.write(DerValue.tag_Sequence,tmp);
+ os.write(DerValue.tag_Sequence, tmp);
extensionValue = os.toByteArray();
}
@@ -92,8 +84,8 @@ implements CertAttrSet {
}
/**
- * Create a CertificatePolicies with the Vector of CertificatePolicyInfo.
- *
+ * Create a CertificatePolicies with the Vector of CertificatePolicyInfo.
+ *
* @param infos the Vector of CertificatePolicyInfo.
*/
public CertificatePoliciesExtension(Vector<CertificatePolicyInfo> infos) throws IOException {
@@ -102,32 +94,32 @@ implements CertAttrSet {
this.critical = false;
encodeThis();
}
-
+
/**
* Create a default CertificatePoliciesExtension.
*/
- public CertificatePoliciesExtension() {
- this.extensionId = PKIXExtensions.CertificatePolicies_Id;
+ public CertificatePoliciesExtension() {
+ this.extensionId = PKIXExtensions.CertificatePolicies_Id;
critical = false;
- mInfos = new Vector<CertificatePolicyInfo>(1,1);
+ mInfos = new Vector<CertificatePolicyInfo>(1, 1);
}
/**
* Create the extension from the passed DER encoded value.
- *
+ *
* @param critical true if the extension is to be treated as critical.
* @param value Array of DER encoded bytes of the actual value.
* @exception IOException on error.
*/
public CertificatePoliciesExtension(Boolean critical, Object value)
- throws IOException {
- this.extensionId = PKIXExtensions.CertificatePolicies_Id;
+ throws IOException {
+ this.extensionId = PKIXExtensions.CertificatePolicies_Id;
this.critical = critical.booleanValue();
-
+
int len = Array.getLength(value);
- byte [] extValue = new byte[len];
+ byte[] extValue = new byte[len];
for (int i = 0; i < len; i++) {
- extValue[i] = Array.getByte(value, i);
+ extValue[i] = Array.getByte(value, i);
}
this.extensionValue = extValue;
DerValue val = new DerValue(extValue);
@@ -147,16 +139,17 @@ implements CertAttrSet {
* Returns a printable representation of the policy extension.
*/
public String toString() {
- if (mInfos == null) return "";
+ if (mInfos == null)
+ return "";
String s = super.toString() + "Certificate Policies [\n"
+ mInfos.toString() + "]\n";
-
+
return (s);
}
-
+
/**
* Write the extension to the OutputStream.
- *
+ *
* @param out the OutputStream to write the extension to.
* @exception IOException on encoding errors.
*/
@@ -173,32 +166,32 @@ implements CertAttrSet {
/**
* Decode the extension from the InputStream.
- *
+ *
* @param in the InputStream to unmarshal the contents from.
* @exception IOException on decoding or validity errors.
*/
public void decode(InputStream in) throws IOException {
throw new IOException("Method not to be called directly.");
}
-
+
/**
* Set the attribute value.
*/
@SuppressWarnings("unchecked")
- public void set(String name, Object obj) throws IOException {
+ public void set(String name, Object obj) throws IOException {
clearValue();
if (name.equalsIgnoreCase(INFOS)) {
if (!(obj instanceof Vector)) {
- throw new IOException("Attribute value should be of" +
+ throw new IOException("Attribute value should be of" +
" type Vector.");
}
- mInfos = (Vector<CertificatePolicyInfo>)obj;
+ mInfos = (Vector<CertificatePolicyInfo>) obj;
} else {
- throw new IOException("Attribute name not recognized by " +
+ throw new IOException("Attribute name not recognized by " +
"CertAttrSet:CertificatePoliciesExtension.");
}
}
-
+
/**
* Get the attribute value.
*/
@@ -206,11 +199,11 @@ implements CertAttrSet {
if (name.equalsIgnoreCase(INFOS)) {
return (mInfos);
} else {
- throw new IOException("Attribute name not recognized by " +
+ throw new IOException("Attribute name not recognized by " +
"CertAttrSet:CertificatePoliciesExtension.");
}
}
-
+
/**
* Delete the attribute value.
*/
@@ -218,112 +211,111 @@ implements CertAttrSet {
if (name.equalsIgnoreCase(INFOS)) {
mInfos = null;
} else {
- throw new IOException("Attribute name not recognized by " +
+ throw new IOException("Attribute name not recognized by " +
"CertAttrSet:CertificatePoliciesExtension.");
}
}
-
+
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
- public Enumeration<Vector<CertificatePolicyInfo>> getElements () {
+ public Enumeration<Vector<CertificatePolicyInfo>> getElements() {
Vector<Vector<CertificatePolicyInfo>> elements = new Vector<Vector<CertificatePolicyInfo>>();
elements.addElement(mInfos);
return (elements.elements());
}
-
+
/**
* Return the name of this attribute.
*/
- public String getName () {
+ public String getName() {
return (NAME);
}
- public static void main(String args[])
- {
-
-/** From ASN.1 dump
+ public static void main(String args[]) {
- 0 30 133: SEQUENCE {
- 3 30 45: . SEQUENCE {
- 5 06 3: . . OBJECT IDENTIFIER '1 2 3 5'
- 10 30 38: . . SEQUENCE {
- 12 30 36: . . . SEQUENCE {
- 14 06 8: . . . . OBJECT IDENTIFIER cps (1 3 6 1 5 5 7 2 1)
- : . . . . . (PKIX policy qualifier)
- 24 16 24: . . . . IA5String 'http://home.netscape.com'
- : . . . . }
- : . . . }
- : . . }
- 50 30 84: . SEQUENCE {
- 52 06 2: . . OBJECT IDENTIFIER '2 3 5'
- 56 30 78: . . SEQUENCE {
- 58 30 36: . . . SEQUENCE {
- 60 06 8: . . . . OBJECT IDENTIFIER cps (1 3 6 1 5 5 7 2 1)
- : . . . . . (PKIX policy qualifier)
- 70 16 24: . . . . IA5String 'http://home.netscape.com'
- : . . . . }
- 96 30 38: . . . SEQUENCE {
- 98 06 8: . . . . OBJECT IDENTIFIER unotice (1 3 6 1 5 5 7 2 2)
- : . . . . . (PKIX policy qualifier)
- 108 30 26: . . . . SEQUENCE {
- 110 30 16: . . . . . SEQUENCE {
- 112 1E 8: . . . . . . BMPString (1993) '_..o.r.g'
- 122 02 1: . . . . . . INTEGER 1
- 125 02 1: . . . . . . INTEGER 2
- : . . . . . . }
- 128 1E 6: . . . . . BMPString (1993) '_..d.t'
- : . . . . . }
- : . . . . }
- : . . . }
- : . . }
- : . }
+ /**
+ * From ASN.1 dump
+ *
+ * 0 30 133: SEQUENCE {
+ * 3 30 45: . SEQUENCE {
+ * 5 06 3: . . OBJECT IDENTIFIER '1 2 3 5'
+ * 10 30 38: . . SEQUENCE {
+ * 12 30 36: . . . SEQUENCE {
+ * 14 06 8: . . . . OBJECT IDENTIFIER cps (1 3 6 1 5 5 7 2 1)
+ * : . . . . . (PKIX policy qualifier)
+ * 24 16 24: . . . . IA5String 'http://home.netscape.com'
+ * : . . . . }
+ * : . . . }
+ * : . . }
+ * 50 30 84: . SEQUENCE {
+ * 52 06 2: . . OBJECT IDENTIFIER '2 3 5'
+ * 56 30 78: . . SEQUENCE {
+ * 58 30 36: . . . SEQUENCE {
+ * 60 06 8: . . . . OBJECT IDENTIFIER cps (1 3 6 1 5 5 7 2 1)
+ * : . . . . . (PKIX policy qualifier)
+ * 70 16 24: . . . . IA5String 'http://home.netscape.com'
+ * : . . . . }
+ * 96 30 38: . . . SEQUENCE {
+ * 98 06 8: . . . . OBJECT IDENTIFIER unotice (1 3 6 1 5 5 7 2 2)
+ * : . . . . . (PKIX policy qualifier)
+ * 108 30 26: . . . . SEQUENCE {
+ * 110 30 16: . . . . . SEQUENCE {
+ * 112 1E 8: . . . . . . BMPString (1993) '_..o.r.g'
+ * 122 02 1: . . . . . . INTEGER 1
+ * 125 02 1: . . . . . . INTEGER 2
+ * : . . . . . . }
+ * 128 1E 6: . . . . . BMPString (1993) '_..d.t'
+ * : . . . . . }
+ * : . . . . }
+ * : . . . }
+ * : . . }
+ * : . }
+ **/
- **/
+ CertificatePolicyId plcyId0 = new CertificatePolicyId(
+ new ObjectIdentifier("1.2.3.5")
+ );
+ PolicyQualifiers qualifiers0 = new PolicyQualifiers();
+ CPSuri cpsQualifier0 = new CPSuri("http://home.netscape.com");
+ PolicyQualifierInfo qualifierInfo0 = new PolicyQualifierInfo(
+ PolicyQualifierInfo.QT_CPS,
+ cpsQualifier0
+ );
+ qualifiers0.add(qualifierInfo0);
+ CertificatePolicyInfo info0 = new CertificatePolicyInfo(
+ plcyId0, qualifiers0);
+ CertificatePolicyId plcyId1 = new CertificatePolicyId(
+ new ObjectIdentifier("2.3.5")
+ );
+ PolicyQualifiers qualifiers1 = new PolicyQualifiers();
+ DisplayText org1 = new DisplayText(DisplayText.tag_BMPString,
+ "org");
+ int nums[] = { 1, 2 };
+ NoticeReference nr1 = new NoticeReference(org1, nums);
+ DisplayText dt1 = new DisplayText(DisplayText.tag_BMPString,
+ "dt");
+ UserNotice userNotice1 = new UserNotice(nr1, dt1);
+ PolicyQualifierInfo qualifierInfo1 = new PolicyQualifierInfo(
+ PolicyQualifierInfo.QT_UNOTICE,
+ userNotice1
+ );
+ qualifiers1.add(qualifierInfo0);
+ qualifiers1.add(qualifierInfo1);
+ CertificatePolicyInfo info1 = new CertificatePolicyInfo(
+ plcyId1, qualifiers1);
+ Vector<CertificatePolicyInfo> infos = new Vector<CertificatePolicyInfo>();
+ infos.addElement(info0);
+ infos.addElement(info1);
+ try {
+ CertificatePoliciesExtension ext =
+ new CertificatePoliciesExtension(infos);
- CertificatePolicyId plcyId0 = new CertificatePolicyId(
- new ObjectIdentifier("1.2.3.5")
- );
- PolicyQualifiers qualifiers0 = new PolicyQualifiers();
- CPSuri cpsQualifier0 = new CPSuri("http://home.netscape.com");
- PolicyQualifierInfo qualifierInfo0 = new PolicyQualifierInfo(
- PolicyQualifierInfo.QT_CPS,
- cpsQualifier0
- );
- qualifiers0.add(qualifierInfo0);
- CertificatePolicyInfo info0 = new CertificatePolicyInfo(
- plcyId0, qualifiers0);
- CertificatePolicyId plcyId1 = new CertificatePolicyId(
- new ObjectIdentifier("2.3.5")
- );
- PolicyQualifiers qualifiers1 = new PolicyQualifiers();
- DisplayText org1 = new DisplayText(DisplayText.tag_BMPString,
- "org");
- int nums[] = {1, 2};
- NoticeReference nr1 = new NoticeReference(org1, nums);
- DisplayText dt1 = new DisplayText(DisplayText.tag_BMPString,
- "dt");
- UserNotice userNotice1 = new UserNotice(nr1, dt1);
- PolicyQualifierInfo qualifierInfo1 = new PolicyQualifierInfo(
- PolicyQualifierInfo.QT_UNOTICE,
- userNotice1
- );
- qualifiers1.add(qualifierInfo0);
- qualifiers1.add(qualifierInfo1);
- CertificatePolicyInfo info1 = new CertificatePolicyInfo(
- plcyId1, qualifiers1);
- Vector<CertificatePolicyInfo> infos = new Vector<CertificatePolicyInfo>();
- infos.addElement(info0);
- infos.addElement(info1);
- try {
- CertificatePoliciesExtension ext =
- new CertificatePoliciesExtension(infos);
-
- // BASE64 encode the whole thing and write it to stdout
- System.out.println( com.netscape.osutil.OSUtil.BtoA(ext.getExtensionValue()) );
- } catch (IOException e) {
- System.out.println(e.toString());
- }
- }
+ // BASE64 encode the whole thing and write it to stdout
+ System.out.println(com.netscape.osutil.OSUtil.BtoA(ext.getExtensionValue()));
+ } catch (IOException e) {
+ System.out.println(e.toString());
+ }
+ }
}