Source Code Cross Referenced for ExtendedKeyUsageExtension.java in  » 6.0-JDK-Modules » j2me » sun » security » x509 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » sun.security.x509 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)ExtendedKeyUsageExtension.java	1.8 06/10/10
003:         *
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation. 
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt). 
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA 
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions. 
025:         */
026:
027:        package sun.security.x509;
028:
029:        import java.io.IOException;
030:        import java.io.InputStream;
031:        import java.io.OutputStream;
032:        import java.lang.reflect.Array;
033:        import java.util.Enumeration;
034:        import java.util.Vector;
035:        import java.util.List;
036:        import java.util.ArrayList;
037:
038:        import sun.security.util.DerValue;
039:        import sun.security.util.DerOutputStream;
040:        import sun.security.util.ObjectIdentifier;
041:
042:        /**
043:         * This class defines the Extended Key Usage Extension, which
044:         * indicates one or more purposes for which the certified public key
045:         * may be used, in addition to or in place of the basic purposes
046:         * indicated in the key usage extension field.  This field is defined
047:         * as follows:<p>
048:         *
049:         * id-ce-extKeyUsage OBJECT IDENTIFIER ::= {id-ce 37}<p>
050:         *
051:         * ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId<p>
052:         *
053:         * KeyPurposeId ::= OBJECT IDENTIFIER<p>
054:         *
055:         * Key purposes may be defined by any organization with a need. Object
056:         * identifiers used to identify key purposes shall be assigned in
057:         * accordance with IANA or ITU-T Rec. X.660 | ISO/IEC/ITU 9834-1.<p>
058:         *
059:         * This extension may, at the option of the certificate issuer, be
060:         * either critical or non-critical.<p>
061:         *
062:         * If the extension is flagged critical, then the certificate MUST be
063:         * used only for one of the purposes indicated.<p>
064:         *
065:         * If the extension is flagged non-critical, then it indicates the
066:         * intended purpose or purposes of the key, and may be used in finding
067:         * the correct key/certificate of an entity that has multiple
068:         * keys/certificates. It is an advisory field and does not imply that
069:         * usage of the key is restricted by the certification authority to
070:         * the purpose indicated. Certificate using applications may
071:         * nevertheless require that a particular purpose be indicated in
072:         * order for the certificate to be acceptable to that application.<p>
073:
074:         * If a certificate contains both a critical key usage field and a
075:         * critical extended key usage field, then both fields MUST be
076:         * processed independently and the certificate MUST only be used for a
077:         * purpose consistent with both fields.  If there is no purpose
078:         * consistent with both fields, then the certificate MUST NOT be used
079:         * for any purpose.<p>
080:         *
081:         * @version 1.8, 10/10/06
082:         * @since	1.4
083:         */
084:        public class ExtendedKeyUsageExtension extends Extension implements 
085:                CertAttrSet {
086:
087:            /**
088:             * Identifier for this attribute, to be used with the
089:             * get, set, delete methods of Certificate, x509 type.
090:             */
091:            public static final String IDENT = "x509.info.extensions.ExtendedKeyUsage";
092:
093:            /**
094:             * Attribute names.
095:             */
096:            public static final String NAME = "ExtendedKeyUsage";
097:            public static final String USAGES = "usages";
098:
099:            /**
100:             * Vector of KeyUsages for this object.
101:             */
102:            private Vector keyUsages;
103:
104:            // Encode this extension value.
105:            private void encodeThis() throws IOException {
106:                if (keyUsages == null || keyUsages.isEmpty()) {
107:                    this .extensionValue = null;
108:                    return;
109:                }
110:                DerOutputStream os = new DerOutputStream();
111:                DerOutputStream tmp = new DerOutputStream();
112:
113:                for (int i = 0; i < keyUsages.size(); i++) {
114:                    tmp.putOID((ObjectIdentifier) keyUsages.elementAt(i));
115:                }
116:
117:                os.write(DerValue.tag_Sequence, tmp);
118:                this .extensionValue = os.toByteArray();
119:            }
120:
121:            /**
122:             * Create a ExtendedKeyUsageExtension object from
123:             * a Vector of Key Usages; the criticality is set to false.
124:             *
125:             * @param keyUsages the Vector of KeyUsages (ObjectIdentifiers)
126:             */
127:            public ExtendedKeyUsageExtension(Vector keyUsages)
128:                    throws IOException {
129:                this (Boolean.FALSE, keyUsages);
130:            }
131:
132:            /**
133:             * Create a ExtendedKeyUsageExtension object from
134:             * a Vector of KeyUsages with specified criticality.
135:             *
136:             * @param critical true if the extension is to be treated as critical.
137:             * @param keyUsages the Vector of KeyUsages (ObjectIdentifiers)
138:             */
139:            public ExtendedKeyUsageExtension(Boolean critical, Vector keyUsages)
140:                    throws IOException {
141:                this .keyUsages = keyUsages;
142:                this .extensionId = PKIXExtensions.ExtendedKeyUsage_Id;
143:                this .critical = critical.booleanValue();
144:                encodeThis();
145:            }
146:
147:            /**
148:             * Create the extension from its DER encoded value and criticality.
149:             *
150:             * @param critical true if the extension is to be treated as critical.
151:             * @param value Array of DER encoded bytes of the actual value.
152:             * @exception IOException on error.
153:             */
154:            public ExtendedKeyUsageExtension(Boolean critical, Object value)
155:                    throws IOException {
156:                this .extensionId = PKIXExtensions.ExtendedKeyUsage_Id;
157:                this .critical = critical.booleanValue();
158:                //Array.getLength will throw an IllegalArgumentException if
159:                //value is not an array, and Array.getByte will do so if the
160:                //values are not bytes, so a type check is not needed.
161:                int len = 0;
162:                byte[] extValue = null;
163:                try {
164:                    len = Array.getLength(value);
165:                    extValue = new byte[len];
166:                    for (int i = 0; i < len; i++)
167:                        extValue[i] = Array.getByte(value, i);
168:                } catch (IllegalArgumentException iae) {
169:                    throw new IOException(iae.toString());
170:                }
171:                this .extensionValue = extValue;
172:                DerValue val = new DerValue(extValue);
173:                if (val.tag != DerValue.tag_Sequence) {
174:                    throw new IOException("Invalid encoding for "
175:                            + "ExtendedKeyUsageExtension.");
176:                }
177:                keyUsages = new Vector(1, 1);
178:                while (val.data.available() != 0) {
179:                    DerValue seq = val.data.getDerValue();
180:                    ObjectIdentifier usage = seq.getOID();
181:                    keyUsages.addElement(usage);
182:                }
183:            }
184:
185:            /**
186:             * Return the extension as user readable string.
187:             */
188:            public String toString() {
189:                if (keyUsages == null)
190:                    return "";
191:                return super .toString() + "ExtendedKeyUsages [\n"
192:                        + keyUsages.toString() + "]\n";
193:            }
194:
195:            /**
196:             * Decode the extension from the InputStream.
197:             *
198:             * @param in the InputStream to unmarshal the contents from.
199:             * @exception IOException on decoding or validity errors.
200:             */
201:            public void decode(InputStream in) throws IOException {
202:                throw new IOException("Method not to be called directly.");
203:            }
204:
205:            /**
206:             * Write the extension to the DerOutputStream.
207:             *
208:             * @param out the DerOutputStream to write the extension to.
209:             * @exception IOException on encoding errors.
210:             */
211:            public void encode(OutputStream out) throws IOException {
212:                DerOutputStream tmp = new DerOutputStream();
213:                if (extensionValue == null) {
214:                    extensionId = PKIXExtensions.ExtendedKeyUsage_Id;
215:                    critical = false;
216:                    encodeThis();
217:                }
218:                super .encode(tmp);
219:                out.write(tmp.toByteArray());
220:            }
221:
222:            /**
223:             * Set the attribute value.
224:             */
225:            public void set(String name, Object obj) throws IOException {
226:                if (name.equalsIgnoreCase(USAGES)) {
227:                    if (!(obj instanceof  Vector)) {
228:                        throw new IOException(
229:                                "Attribute value should be of type Vector.");
230:                    }
231:                    this .keyUsages = (Vector) obj;
232:                } else {
233:                    throw new IOException("Attribute name [" + name
234:                            + "] not recognized by "
235:                            + "CertAttrSet:ExtendedKeyUsageExtension.");
236:                }
237:                encodeThis();
238:            }
239:
240:            /**
241:             * Get the attribute value.
242:             */
243:            public Object get(String name) throws IOException {
244:                if (name.equalsIgnoreCase(USAGES)) {
245:                    //NOTE: May want to consider cloning this
246:                    return keyUsages;
247:                } else {
248:                    throw new IOException("Attribute name [" + name
249:                            + "] not recognized by "
250:                            + "CertAttrSet:ExtendedKeyUsageExtension.");
251:                }
252:            }
253:
254:            /**
255:             * Delete the attribute value.
256:             */
257:            public void delete(String name) throws IOException {
258:                if (name.equalsIgnoreCase(USAGES)) {
259:                    keyUsages = null;
260:                } else {
261:                    throw new IOException("Attribute name [" + name
262:                            + "] not recognized by "
263:                            + "CertAttrSet:ExtendedKeyUsageExtension.");
264:                }
265:                encodeThis();
266:            }
267:
268:            /**
269:             * Return an enumeration of names of attributes existing within this
270:             * attribute.
271:             */
272:            public Enumeration getElements() {
273:                AttributeNameEnumeration elements = new AttributeNameEnumeration();
274:                elements.addElement(USAGES);
275:
276:                return (elements.elements());
277:            }
278:
279:            /**
280:             * Return the name of this attribute.
281:             */
282:            public String getName() {
283:                return (NAME);
284:            }
285:
286:            public List getExtendedKeyUsage() {
287:                ArrayList al = new ArrayList(keyUsages.size());
288:                for (int i = 0; i < keyUsages.size(); i++) {
289:                    al.add(keyUsages.elementAt(i).toString());
290:                }
291:                return al;
292:            }
293:
294:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.