2 * Copyright (c) 2010 .SE (The Internet Infrastructure Foundation)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /*****************************************************************************
30 This class represents a single session
31 *****************************************************************************/
33 #ifndef _SOFTHSM_V2_SESSION_H
34 #define _SOFTHSM_V2_SESSION_H
37 #include "FindOperation.h"
38 #include "HashAlgorithm.h"
39 #include "MacAlgorithm.h"
40 #include "AsymmetricAlgorithm.h"
41 #include "SymmetricAlgorithm.h"
45 #define SESSION_OP_NONE 0x0
46 #define SESSION_OP_FIND 0x1
47 #define SESSION_OP_ENCRYPT 0x2
48 #define SESSION_OP_DECRYPT 0x3
49 #define SESSION_OP_DIGEST 0x4
50 #define SESSION_OP_SIGN 0x5
51 #define SESSION_OP_VERIFY 0x6
52 #define SESSION_OP_DIGEST_ENCRYPT 0x7
53 #define SESSION_OP_DECRYPT_DIGEST 0x8
54 #define SESSION_OP_SIGN_ENCRYPT 0x9
55 #define SESSION_OP_DECRYPT_VERIFY 0x10
60 Session(Slot* inSlot, bool inIsReadWrite, CK_VOID_PTR inPApplication, CK_NOTIFY inNotify);
70 CK_RV getInfo(CK_SESSION_INFO_PTR pInfo);
73 void setHandle(CK_SESSION_HANDLE inHSession);
74 CK_SESSION_HANDLE getHandle();
78 void setOpType(int inOperation);
82 void setFindOp(FindOperation *inFindOp);
83 FindOperation *getFindOp();
86 void setDigestOp(HashAlgorithm* inDigestOp);
87 HashAlgorithm* getDigestOp();
88 void setHashAlgo(HashAlgo::Type inHashAlgo);
89 HashAlgo::Type getHashAlgo();
92 void setMacOp(MacAlgorithm* inMacOp);
93 MacAlgorithm* getMacOp();
96 void setAsymmetricCryptoOp(AsymmetricAlgorithm* inAsymmetricCryptoOp);
97 AsymmetricAlgorithm* getAsymmetricCryptoOp();
100 void setSymmetricCryptoOp(SymmetricAlgorithm* inSymmetricCryptoOp);
101 SymmetricAlgorithm* getSymmetricCryptoOp();
103 void setMechanism(AsymMech::Type inMechanism);
104 AsymMech::Type getMechanism();
106 void setParameters(void* inParam, size_t inParamLen);
107 void* getParameters(size_t& inParamLen);
109 void setReAuthentication(bool inReAuthentication);
110 bool getReAuthentication();
112 void setAllowMultiPartOp(bool inAllowMultiPartOp);
113 bool getAllowMultiPartOp();
115 void setAllowSinglePartOp(bool inAllowSinglePartOp);
116 bool getAllowSinglePartOp();
118 void setPublicKey(PublicKey* inPublicKey);
119 PublicKey* getPublicKey();
121 void setPrivateKey(PrivateKey* inPrivateKey);
122 PrivateKey* getPrivateKey();
124 void setSymmetricKey(SymmetricKey* inSymmetricKey);
125 SymmetricKey* getSymmetricKey();
127 void setKeyHandle(CK_OBJECT_HANDLE inHKey);
128 CK_OBJECT_HANDLE getKeyHandle();
130 void setHwCryptoOpaque(void* inHwCryptoOpaque);
131 void *getHwCryptoOpaque();
141 // Application data (not in use)
142 CK_VOID_PTR pApplication;
145 // Session properties
147 CK_SESSION_HANDLE hSession;
153 FindOperation *findOp;
156 HashAlgorithm* digestOp;
157 HashAlgo::Type hashAlgo;
163 AsymmetricAlgorithm* asymmetricCryptoOp;
166 SymmetricAlgorithm* symmetricCryptoOp;
168 AsymMech::Type mechanism;
171 bool reAuthentication;
172 bool allowMultiPartOp;
173 bool allowSinglePartOp;
174 PublicKey* publicKey;
175 PrivateKey* privateKey;
178 SymmetricKey* symmetricKey;
180 // hw plugin specific data
181 void *hwCryptoOpaque;
183 // Storing Key handle in session
184 CK_OBJECT_HANDLE hKey;
187 #endif // !_SOFTHSM_V2_SESSION_H