001: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
002: //
003: // Author: Maik Stohn
004: //
005: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
006: // software and associated documentation files (the "Software"), to deal in the Software
007: // without restriction, including without limitation the rights to use, copy, modify, merge,
008: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
009: // to whom the Software is furnished to do so, subject to the following conditions:
010: //
011: // The above copyright notice and this permission notice shall be included in all copies or
012: // substantial portions of the Software.
013: //
014: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
015: // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
016: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
017: // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
018: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
019:
020: package com.novosec.pkix.asn1.crmf;
021:
022: import org.bouncycastle.asn1.ASN1TaggedObject;
023: import org.bouncycastle.asn1.DEREncodable;
024: import org.bouncycastle.asn1.DERNull;
025: import org.bouncycastle.asn1.DERObject;
026: import org.bouncycastle.asn1.DERTaggedObject;
027:
028: /**
029: * ASN.1 structure DER En/DeCoder.
030: *
031: * <pre>
032: * ProofOfPossession ::= CHOICE {
033: * raVerified [0] NULL, -- used if the RA has already verified that the requester is in possession of the private key
034: * signature [1] POPOSigningKey,
035: * keyEncipherment [2] POPOPrivKey,
036: * keyAgreement [3] POPOPrivKey }
037: *
038: * </pre>
039: */
040: public class ProofOfPossession implements DEREncodable {
041: DEREncodable obj;
042: int tag;
043:
044: public ProofOfPossession(DEREncodable obj, int tag) {
045: this .obj = obj;
046: this .tag = tag;
047: }
048:
049: public DERNull getRaVerified() {
050: if (this .tag != 0)
051: return null;
052: return (DERNull) this .obj;
053: }
054:
055: public POPOSigningKey getSignature() {
056: if (this .tag != 1)
057: return null;
058: return (POPOSigningKey) this .obj;
059: }
060:
061: public POPOPrivKey getKeyEncipherment() {
062: if (this .tag != 2)
063: return null;
064: return (POPOPrivKey) this .obj;
065: }
066:
067: public POPOPrivKey getKeyAgreement() {
068: if (this .tag != 3)
069: return null;
070: return (POPOPrivKey) this .obj;
071: }
072:
073: public static ProofOfPossession getInstance(DERObject obj) {
074: return getInstance((ASN1TaggedObject) obj, true);
075: }
076:
077: public static ProofOfPossession getInstance(
078: ASN1TaggedObject tagObj, boolean explicit) {
079: int tag = tagObj.getTagNo();
080:
081: switch (tag) {
082: case 0:
083: return new ProofOfPossession(tagObj.getObject(), 0);
084: case 1:
085: return new ProofOfPossession(POPOSigningKey
086: .getInstance(tagObj.getObject()), 1);
087: case 2:
088: return new ProofOfPossession(POPOPrivKey.getInstance(tagObj
089: .getObject()), 2);
090: case 3:
091: return new ProofOfPossession(POPOPrivKey.getInstance(tagObj
092: .getObject()), 3);
093: }
094:
095: throw new IllegalArgumentException("unknown tag: " + tag);
096: }
097:
098: public DERObject getDERObject() {
099: return new DERTaggedObject(true, tag, obj); //tag explicit since we are in a choice
100: }
101:
102: public String toString() {
103: return "ProofOfPossession: (" + obj + ")";
104: }
105: }
|