KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > cert > PolicyQualifierInfo


1 /*
2  * @(#)PolicyQualifierInfo.java 1.11 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.security.cert;
9
10 import java.io.IOException JavaDoc;
11
12 import sun.misc.HexDumpEncoder;
13 import sun.security.util.DerValue;
14
15 /**
16  * An immutable policy qualifier represented by the ASN.1 PolicyQualifierInfo
17  * structure.
18  *
19  * <p>The ASN.1 definition is as follows:
20  * <p><pre>
21  * PolicyQualifierInfo ::= SEQUENCE {
22  * policyQualifierId PolicyQualifierId,
23  * qualifier ANY DEFINED BY policyQualifierId }
24  * </pre>
25  * <p>
26  * A certificate policies extension, if present in an X.509 version 3
27  * certificate, contains a sequence of one or more policy information terms,
28  * each of which consists of an object identifier (OID) and optional
29  * qualifiers. In an end-entity certificate, these policy information terms
30  * indicate the policy under which the certificate has been issued and the
31  * purposes for which the certificate may be used. In a CA certificate, these
32  * policy information terms limit the set of policies for certification paths
33  * which include this certificate.
34  * <p>
35  * A <code>Set</code> of <code>PolicyQualifierInfo</code> objects are returned
36  * by the {@link PolicyNode#getPolicyQualifiers PolicyNode.getPolicyQualifiers}
37  * method. This allows applications with specific policy requirements to
38  * process and validate each policy qualifier. Applications that need to
39  * process policy qualifiers should explicitly set the
40  * <code>policyQualifiersRejected</code> flag to false (by calling the
41  * {@link PKIXParameters#setPolicyQualifiersRejected
42  * PKIXParameters.setPolicyQualifiersRejected} method) before validating
43  * a certification path.
44  *
45  * <p>Note that the PKIX certification path validation algorithm specifies
46  * that any policy qualifier in a certificate policies extension that is
47  * marked critical must be processed and validated. Otherwise the
48  * certification path must be rejected. If the
49  * <code>policyQualifiersRejected</code> flag is set to false, it is up to
50  * the application to validate all policy qualifiers in this manner in order
51  * to be PKIX compliant.
52  *
53  * <p><b>Concurrent Access</b>
54  *
55  * <p>All <code>PolicyQualifierInfo</code> objects must be immutable and
56  * thread-safe. That is, multiple threads may concurrently invoke the
57  * methods defined in this class on a single <code>PolicyQualifierInfo</code>
58  * object (or more than one) with no ill effects. Requiring
59  * <code>PolicyQualifierInfo</code> objects to be immutable and thread-safe
60  * allows them to be passed around to various pieces of code without
61  * worrying about coordinating access.
62  *
63  * @author seth proctor
64  * @author Sean Mullan
65  * @version 1.11 12/19/03
66  * @since 1.4
67  */

68 public class PolicyQualifierInfo {
69
70     private byte [] mEncoded;
71     private String JavaDoc mId;
72     private byte [] mData;
73     private String JavaDoc pqiString;
74
75     /**
76      * Creates an instance of <code>PolicyQualifierInfo</code> from the
77      * encoded bytes. The encoded byte array is copied on construction.
78      *
79      * @param encoded a byte array containing the qualifier in DER encoding
80      * @exception IOException thrown if the byte array does not represent a
81      * valid and parsable policy qualifier
82      */

83     public PolicyQualifierInfo(byte[] encoded) throws IOException JavaDoc {
84     mEncoded = (byte[]) encoded.clone();
85         
86     DerValue val = new DerValue(mEncoded);
87     if (val.tag != DerValue.tag_Sequence)
88         throw new IOException JavaDoc("Invalid encoding for PolicyQualifierInfo");
89
90     mId = (val.data.getDerValue()).getOID().toString();
91     byte [] tmp = val.data.toByteArray();
92     if (tmp == null) {
93         mData = null;
94     } else {
95         mData = new byte[tmp.length];
96         System.arraycopy(tmp, 0, mData, 0, tmp.length);
97     }
98     }
99
100     /**
101      * Returns the <code>policyQualifierId</code> field of this
102      * <code>PolicyQualifierInfo</code>. The <code>policyQualifierId</code>
103      * is an Object Identifier (OID) represented by a set of nonnegative
104      * integers separated by periods.
105      *
106      * @return the OID (never <code>null</code>)
107      */

108     public final String JavaDoc getPolicyQualifierId() {
109     return mId;
110     }
111     
112     /**
113      * Returns the ASN.1 DER encoded form of this
114      * <code>PolicyQualifierInfo</code>.
115      *
116      * @return the ASN.1 DER encoded bytes (never <code>null</code>).
117      * Note that a copy is returned, so the data is cloned each time
118      * this method is called.
119      */

120     public final byte[] getEncoded() {
121     return (byte[]) mEncoded.clone();
122     }
123     
124     /**
125      * Returns the ASN.1 DER encoded form of the <code>qualifier</code>
126      * field of this <code>PolicyQualifierInfo</code>.
127      *
128      * @return the ASN.1 DER encoded bytes of the <code>qualifier</code>
129      * field. Note that a copy is returned, so the data is cloned each
130      * time this method is called.
131      */

132     public final byte[] getPolicyQualifier() {
133     return (mData == null ? null : (byte[]) mData.clone());
134     }
135
136     /**
137      * Return a printable representation of this
138      * <code>PolicyQualifierInfo</code>.
139      *
140      * @return a <code>String</code> describing the contents of this
141      * <code>PolicyQualifierInfo</code>
142      */

143     public String JavaDoc toString() {
144     if (pqiString != null)
145         return pqiString;
146         HexDumpEncoder enc = new HexDumpEncoder();
147         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
148         sb.append("PolicyQualifierInfo: [\n");
149         sb.append(" qualifierID: " + mId + "\n");
150         sb.append(" qualifier: " +
151         (mData == null ? "null" : enc.encodeBuffer(mData)) + "\n");
152         sb.append("]");
153     pqiString = sb.toString();
154     return pqiString;
155     }
156 }
157
Popular Tags