KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > crmf > POPOPrivKey


1 // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
2
//
3
// Author: Maik Stohn
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
// software and associated documentation files (the "Software"), to deal in the Software
7
// without restriction, including without limitation the rights to use, copy, modify, merge,
8
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
// to whom the Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in all copies or
12
// substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19

20 package com.novosec.pkix.asn1.crmf;
21
22 import org.bouncycastle.asn1.ASN1TaggedObject;
23 import org.bouncycastle.asn1.DERBitString;
24 import org.bouncycastle.asn1.DEREncodable;
25 import org.bouncycastle.asn1.DERInteger;
26 import org.bouncycastle.asn1.DERObject;
27 import org.bouncycastle.asn1.DERTaggedObject;
28
29 /**
30  * ASN.1 structure DER En/DeCoder.
31  *
32  * <pre>
33  *
34  * POPOPrivKey ::= CHOICE {
35  * thisMessage [0] BIT STRING, -- posession is proven in this message (which contains the private key itself (encrypted for the CA))
36  * subsequentMessage [1] SubsequentMessage, -- possession will be proven in a subsequent message (INTEGER)
37  * dhMAC [2] BIT STRING } -- for keyAgreement (only), possession is proven in this message (which contains a MAC (over the DER-encoded value of the
38  * -- certReq parameter in CertReqMsg, which MUST include both subject and publicKey) based on a key derived from the end entity's
39  * -- private DH key and the CA's public DH key); the dhMAC value MUST be calculated as per the directions given in Appendix A.
40  *
41  * SubsequentMessage ::= INTEGER {
42  * encrCert (0), -- requests that resulting certificate be encrypted for the end entity (following which, POP will be proven in a confirmation message)
43  * challengeResp (1) } -- requests that CA engage in challenge-response exchange with end entity in order to prove private key possession
44  *
45  * </pre>
46  */

47 public class POPOPrivKey implements DEREncodable
48 {
49     DEREncodable obj;
50     int tag;
51
52     public POPOPrivKey( DERObject obj, int tag )
53     {
54         this.obj = obj;
55         this.tag = tag;
56     }
57     
58     public DERBitString getThisMessage()
59     {
60       if( this.tag != 0 )
61         return null;
62       return (DERBitString)this.obj;
63     }
64
65     public DERInteger getSubsequentMessage()
66     {
67       if( this.tag != 1 )
68         return null;
69       return (DERInteger)this.obj;
70     }
71
72     public DERBitString getDhMAC()
73     {
74       if( this.tag != 2 )
75         return null;
76       return (DERBitString)this.obj;
77     }
78
79     public static POPOPrivKey getInstance( DERObject obj )
80     {
81       return getInstance( (ASN1TaggedObject)obj, true );
82     }
83
84     public static POPOPrivKey getInstance( ASN1TaggedObject tagObj, boolean explicit )
85     {
86         int tag = tagObj.getTagNo();
87
88         switch (tag)
89         {
90           case 0: return new POPOPrivKey(DERBitString.getInstance(tagObj.getObject()), 0);
91           case 1: return new POPOPrivKey(DERInteger.getInstance(tagObj.getObject()), 1);
92           case 2: return new POPOPrivKey(DERBitString.getInstance(tagObj.getObject()), 2);
93         }
94
95         throw new IllegalArgumentException JavaDoc("unknown tag: " + tag);
96     }
97
98     public DERObject getDERObject()
99     {
100       return new DERTaggedObject(true, tag, obj);
101     }
102
103     public String JavaDoc toString()
104     {
105       return "POPOPrivKey: (" + obj + ")";
106     }
107 }
108
Popular Tags