001: package org.bouncycastle.asn1.isismtt.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.ASN1TaggedObject;
007: import org.bouncycastle.asn1.DEREncodable;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERPrintableString;
010: import org.bouncycastle.asn1.DERSequence;
011: import org.bouncycastle.asn1.DERTaggedObject;
012: import org.bouncycastle.asn1.x500.DirectoryString;
013: import org.bouncycastle.asn1.x509.GeneralName;
014: import org.bouncycastle.asn1.x509.IssuerSerial;
015:
016: import java.util.Enumeration;
017:
018: /**
019: * Attribute to indicate that the certificate holder may sign in the name of a
020: * third person.
021: * <p>
022: * ISIS-MTT PROFILE: The corresponding ProcurationSyntax contains either the
023: * name of the person who is represented (subcomponent thirdPerson) or a
024: * reference to his/her base certificate (in the component signingFor,
025: * subcomponent certRef), furthermore the optional components country and
026: * typeSubstitution to indicate the country whose laws apply, and respectively
027: * the type of procuration (e.g. manager, procuration, custody).
028: * <p>
029: * ISIS-MTT PROFILE: The GeneralName MUST be of type directoryName and MAY only
030: * contain: - RFC3039 attributes, except pseudonym (countryName, commonName,
031: * surname, givenName, serialNumber, organizationName, organizationalUnitName,
032: * stateOrProvincename, localityName, postalAddress) and - SubjectDirectoryName
033: * attributes (title, dateOfBirth, placeOfBirth, gender, countryOfCitizenship,
034: * countryOfResidence and NameAtBirth).
035: *
036: * <pre>
037: * ProcurationSyntax ::= SEQUENCE {
038: * country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
039: * typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
040: * signingFor [3] EXPLICIT SigningFor
041: * }
042: *
043: * SigningFor ::= CHOICE
044: * {
045: * thirdPerson GeneralName,
046: * certRef IssuerSerial
047: * }
048: * </pre>
049: *
050: */
051: public class ProcurationSyntax extends ASN1Encodable {
052: private String country;
053: private DirectoryString typeOfSubstitution;
054:
055: private GeneralName thirdPerson;
056: private IssuerSerial certRef;
057:
058: public static ProcurationSyntax getInstance(Object obj) {
059: if (obj == null || obj instanceof ProcurationSyntax) {
060: return (ProcurationSyntax) obj;
061: }
062:
063: if (obj instanceof ASN1Sequence) {
064: return new ProcurationSyntax((ASN1Sequence) obj);
065: }
066:
067: throw new IllegalArgumentException(
068: "illegal object in getInstance: "
069: + obj.getClass().getName());
070: }
071:
072: /**
073: * Constructor from ASN1Sequence.
074: * <p/>
075: * The sequence is of type ProcurationSyntax:
076: * <p/>
077: * <pre>
078: * ProcurationSyntax ::= SEQUENCE {
079: * country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
080: * typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
081: * signingFor [3] EXPLICIT SigningFor
082: * }
083: * <p/>
084: * SigningFor ::= CHOICE
085: * {
086: * thirdPerson GeneralName,
087: * certRef IssuerSerial
088: * }
089: * </pre>
090: *
091: * @param seq The ASN.1 sequence.
092: */
093: private ProcurationSyntax(ASN1Sequence seq) {
094: if (seq.size() < 1 || seq.size() > 3) {
095: throw new IllegalArgumentException("Bad sequence size: "
096: + seq.size());
097: }
098: Enumeration e = seq.getObjects();
099:
100: while (e.hasMoreElements()) {
101: ASN1TaggedObject o = ASN1TaggedObject.getInstance(e
102: .nextElement());
103: switch (o.getTagNo()) {
104: case 1:
105: country = DERPrintableString.getInstance(o, true)
106: .getString();
107: break;
108: case 2:
109: typeOfSubstitution = DirectoryString.getInstance(o,
110: true);
111: break;
112: case 3:
113: DEREncodable signingFor = o.getObject();
114: if (signingFor instanceof ASN1TaggedObject) {
115: thirdPerson = GeneralName.getInstance(signingFor);
116: } else {
117: certRef = IssuerSerial.getInstance(signingFor);
118: }
119: break;
120: default:
121: throw new IllegalArgumentException("Bad tag number: "
122: + o.getTagNo());
123: }
124: }
125: }
126:
127: /**
128: * Constructor from a given details.
129: * <p/>
130: * <p/>
131: * Either <code>generalName</code> or <code>certRef</code> MUST be
132: * <code>null</code>.
133: *
134: * @param country The country code whose laws apply.
135: * @param typeOfSubstitution The type of procuration.
136: * @param certRef Reference to certificate of the person who is represented.
137: */
138: public ProcurationSyntax(String country,
139: DirectoryString typeOfSubstitution, IssuerSerial certRef) {
140: this .country = country;
141: this .typeOfSubstitution = typeOfSubstitution;
142: this .thirdPerson = null;
143: this .certRef = certRef;
144: }
145:
146: /**
147: * Constructor from a given details.
148: * <p/>
149: * <p/>
150: * Either <code>generalName</code> or <code>certRef</code> MUST be
151: * <code>null</code>.
152: *
153: * @param country The country code whose laws apply.
154: * @param typeOfSubstitution The type of procuration.
155: * @param thirdPerson The GeneralName of the person who is represented.
156: */
157: public ProcurationSyntax(String country,
158: DirectoryString typeOfSubstitution, GeneralName thirdPerson) {
159: this .country = country;
160: this .typeOfSubstitution = typeOfSubstitution;
161: this .thirdPerson = thirdPerson;
162: this .certRef = null;
163: }
164:
165: public String getCountry() {
166: return country;
167: }
168:
169: public DirectoryString getTypeOfSubstitution() {
170: return typeOfSubstitution;
171: }
172:
173: public GeneralName getThirdPerson() {
174: return thirdPerson;
175: }
176:
177: public IssuerSerial getCertRef() {
178: return certRef;
179: }
180:
181: /**
182: * Produce an object suitable for an ASN1OutputStream.
183: * <p/>
184: * Returns:
185: * <p/>
186: * <pre>
187: * ProcurationSyntax ::= SEQUENCE {
188: * country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
189: * typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
190: * signingFor [3] EXPLICIT SigningFor
191: * }
192: * <p/>
193: * SigningFor ::= CHOICE
194: * {
195: * thirdPerson GeneralName,
196: * certRef IssuerSerial
197: * }
198: * </pre>
199: *
200: * @return a DERObject
201: */
202: public DERObject toASN1Object() {
203: ASN1EncodableVector vec = new ASN1EncodableVector();
204: if (country != null) {
205: vec.add(new DERTaggedObject(true, 1,
206: new DERPrintableString(country, true)));
207: }
208: if (typeOfSubstitution != null) {
209: vec.add(new DERTaggedObject(true, 2, typeOfSubstitution));
210: }
211: if (thirdPerson != null) {
212: vec.add(new DERTaggedObject(true, 3, thirdPerson));
213: } else {
214: vec.add(new DERTaggedObject(true, 3, certRef));
215: }
216:
217: return new DERSequence(vec);
218: }
219: }
|