001: /*
002: *
003: *
004: * Copyright 1990-2007 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: package com.sun.satsa.util.pkcs15;
027:
028: import java.util.Vector;
029: import java.io.IOException;
030: import com.sun.satsa.util.*;
031:
032: /**
033: * This class represents the PKCS15 DODF file.
034: * <pre>
035: * It is assumed that the DODF file has the following content:
036: * opaqueDO: <value>
037: * externalIDO: 0x80 <len> <value>
038: * oidDO: 0xA1 <len+2>
039: * TLV.CONSTRUCTED+TLV.SEQUENCE_TYPE <len>
040: * TLV.OID_TYPE
041: * TLV.OCTETSTR_TYPE or something else
042: * </pre>
043: */
044: public class DODF extends PKCS15File {
045: /**
046: * <pre>
047: * DODF entries tags.
048: * These tags means the context-specific constructed type and tag of
049: * DataType ::= CHOICE {
050: * opaqueDO DataObject {Opaque},
051: * externalIDO [0] DataObject {ExternalIDO},
052: * oidDO [1] DataObject {OidDO},
053: * }
054: * </pre>
055: */
056: /** opaqueDO DODF entry tag. */
057: public static final int DODFTAG_OPAQUEDO = TLV.SEQUENCE_TYPE;
058: /** externalIDO DODF entry tag. */
059: /* It is assumed that this type is primitive (not constructed) */
060: public static final int DODFTAG_EXTIDO = 0x80;
061: /** oidDO DODF entry tag. */
062: public static final int DODFTAG_OIDDO = 0xA1;
063:
064: /** This vector contains parsed objects from DODF. */
065: private Vector DODF;
066: /** Staff variable used in the readDODF function */
067: private TLV typeTLV;
068: /** Staff variable used for the OidDo object store */
069: private TLV oidTLV;
070: /** Staff variable used for the ExtIDo object store */
071: private TLV valueTLV;
072:
073: /** This vector contains parsed OidDo objects from DODF. */
074: private Vector OidDo = new Vector();
075: /** This vector contains parsed ExtIDo objects from DODF. */
076: private Vector ExtIDo = new Vector();
077: /** This vector contains parsed OpaqueDo objects from DODF. */
078: private Vector OpaqueDo = new Vector();
079:
080: /**
081: * Creates DODF object for the pointed location and file system
082: * @param location Location required location
083: * @param files FileSystemAbstract requred file system
084: */
085: public DODF(Location location, FileSystemAbstract files) {
086: super (location, files);
087: }
088:
089: /**
090: * Loads DODF object from the file system
091: * @throws IOException if I/O error occurs
092: * @throws TLVException if TLV error occurs
093: */
094: public void load() throws IOException, TLVException {
095: DODF = new Vector();
096: resetLoader(DODF, null, null);
097: parseDF(location.path);
098: readDODF();
099: }
100:
101: /**
102: * <pre>
103: * Reads DODF data from the DODF vector.
104: * The DODF file contains information about DO files in the following
105: * format:
106: * CONTEXT_CONSTRUCTED_0 { the ExternalIDO
107: * <Object value>
108: * }
109: * CONTEXT_CONSTRUCTED_1 { the oidDO
110: * OID_TYPE Object ID
111: * <Object value>
112: * }
113: * }
114: * }
115: * </pre>
116: */
117: private void readDODF() {
118: TLV typeTLV = (TLV) DODF.firstElement();
119:
120: while (typeTLV != null) {
121: switch (typeTLV.type) {
122: case DODFTAG_EXTIDO: {
123: valueTLV = typeTLV;
124: ExtIDo.addElement(valueTLV);
125: break;
126: }
127: case DODFTAG_OIDDO: {
128: oidTLV = typeTLV.child.next.next.child.child;
129: OidDo.addElement(oidTLV);
130: break;
131: }
132: default: {
133: OpaqueDo.addElement(typeTLV);
134: break;
135: }
136: }
137: typeTLV = typeTLV.next;
138: }
139: }
140:
141: /**
142: * Returns the number of the OidDo objects in the DODF file
143: * @return int number
144: */
145: public int getOidDoNumber() {
146: return OidDo.size();
147: }
148:
149: /**
150: * Returns OID of the pointed OidDo object
151: * @param index int index of the OidDo object
152: * @return byte[] OID
153: */
154: public byte[] getOid(int index) {
155: return ((TLV) OidDo.elementAt(index)).getValue();
156: }
157:
158: /**
159: * Returns value of the pointed OidDo object
160: * @param index int index of the OidDo object
161: * @return TLV contained the required object
162: */
163: public TLV getOidDoValueTLV(int index) {
164: return ((TLV) OidDo.elementAt(index)).next.child;
165: }
166:
167: }
|