01: package org.bouncycastle.asn1.cmp;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1OctetString;
06: import org.bouncycastle.asn1.ASN1Sequence;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERSequence;
09: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
10:
11: public class Challenge extends ASN1Encodable {
12: private AlgorithmIdentifier owf;
13: private ASN1OctetString witness;
14: private ASN1OctetString challenge;
15:
16: private Challenge(ASN1Sequence seq) {
17: int index = 0;
18:
19: if (seq.size() == 3) {
20: owf = AlgorithmIdentifier.getInstance(seq
21: .getObjectAt(index++));
22: }
23:
24: witness = ASN1OctetString.getInstance(seq.getObjectAt(index++));
25: challenge = ASN1OctetString.getInstance(seq.getObjectAt(index));
26: }
27:
28: public static Challenge getInstance(Object o) {
29: if (o instanceof Challenge) {
30: return (Challenge) o;
31: }
32:
33: if (o instanceof ASN1Sequence) {
34: return new Challenge((ASN1Sequence) o);
35: }
36:
37: throw new IllegalArgumentException("Invalid object: "
38: + o.getClass().getName());
39: }
40:
41: public AlgorithmIdentifier getOwf() {
42: return owf;
43: }
44:
45: /**
46: * <pre>
47: * Challenge ::= SEQUENCE {
48: * owf AlgorithmIdentifier OPTIONAL,
49: *
50: * -- MUST be present in the first Challenge; MAY be omitted in
51: * -- any subsequent Challenge in POPODecKeyChallContent (if
52: * -- omitted, then the owf used in the immediately preceding
53: * -- Challenge is to be used).
54: *
55: * witness OCTET STRING,
56: * -- the result of applying the one-way function (owf) to a
57: * -- randomly-generated INTEGER, A. [Note that a different
58: * -- INTEGER MUST be used for each Challenge.]
59: * challenge OCTET STRING
60: * -- the encryption (under the public key for which the cert.
61: * -- request is being made) of Rand, where Rand is specified as
62: * -- Rand ::= SEQUENCE {
63: * -- int INTEGER,
64: * -- - the randomly-generated INTEGER A (above)
65: * -- sender GeneralName
66: * -- - the sender's name (as included in PKIHeader)
67: * -- }
68: * }
69: * </pre>
70: * @return a basic ASN.1 object representation.
71: */
72: public DERObject toASN1Object() {
73: ASN1EncodableVector v = new ASN1EncodableVector();
74:
75: addOptional(v, owf);
76: v.add(witness);
77: v.add(challenge);
78:
79: return new DERSequence(v);
80: }
81:
82: private void addOptional(ASN1EncodableVector v, ASN1Encodable obj) {
83: if (obj != null) {
84: v.add(obj);
85: }
86: }
87: }
|