-
Notifications
You must be signed in to change notification settings - Fork 5
/
PKCS11Object.h
184 lines (133 loc) · 4.51 KB
/
PKCS11Object.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
The MIT License (MIT)
Copyright (c) 2014 - Commonwealth of Australia (Represented by the Department of Defence)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include "stdafx.h"
#include <string>
#include "Utility.h"
#include "PKCS11Slot.h"
#include "include\cryptoki.h"
using namespace std;
class PKCS11Object
{
public:
PKCS11Object(void);
~PKCS11Object(void);
// Static factory method to interrogate a token for a particular object handle and return an appropriate instance.
static PKCS11Object* Create(PKCS11Slot * slot, CK_OBJECT_HANDLE handle);
public:
// Returns the CKA_CLASS object value
CK_OBJECT_CLASS getClass();
// Returns the CKA_CLASS object value as a string
string getClassString();
// Returns the object handle
CK_OBJECT_HANDLE getHandle();
// Diagnostic method to dump all related attributes to this object
virtual void DumpAttributes();
protected:
// Causes the instance to read its related attributes from the token.
virtual void QueryAttributes(PKCS11Slot * slot);
protected:
CK_OBJECT_CLASS m_Class;
CK_OBJECT_HANDLE m_Handle;
};
class PKCS11StorageObject : public PKCS11Object
{
public:
PKCS11StorageObject(void);
~PKCS11StorageObject(void);
// Returns the CKA_TOKEN object value
bool getIsToken();
// Returns the CKA_PRIVATE object value
bool getIsPrivate();
// Returns the CKA_MODIFIABLE object value
bool getIsModifiable();
// Returns the CKA_LABEL object value
string getLabel();
protected:
virtual void QueryAttributes(PKCS11Slot * slot);
virtual void DumpAttributes();
protected:
CK_BBOOL m_Token;
CK_BBOOL m_Private;
CK_BBOOL m_Modifiable;
string m_Label;
};
class PKCS11DataObject : public PKCS11StorageObject
{
public:
PKCS11DataObject(void);
~PKCS11DataObject(void);
// Returns the CKA_APPLICATION object value
string getApplication();
// Returns the CKA_OBJECT_ID object value
char* getObjectId();
// Returns the CKA_VALUE object value
char* getValue();
string getObjectIdString();
string getValueString();
protected:
void QueryAttributes(PKCS11Slot * slot);
void DumpAttributes();
protected:
string m_Application;
char* m_ObjectId;
int m_ObjectIdLength;
char* m_Value;
int m_ValueLength;
};
class PKCS11KeyObject : public PKCS11StorageObject
{
public:
PKCS11KeyObject(void);
~PKCS11KeyObject(void);
// Returns the CKA_KEY_TYPE object value
CK_KEY_TYPE getKeyType();
// Returns the CKA_KEY_TYPE object value as a string
string getKeyTypeString();
// Returns the CKA_ID object value
char * getId();
// Returns the CKA_ID object value as a string
string getIdString();
protected:
void QueryAttributes(PKCS11Slot * slot);
void DumpAttributes();
protected:
CK_KEY_TYPE m_KeyType;
char * m_Id;
int m_IdLength;
// Start Date
// End Date
};
class PKCS11X509CertificateObject : public PKCS11StorageObject
{
public:
PKCS11X509CertificateObject(void);
~PKCS11X509CertificateObject(void);
// Returns the CKA_SERIAL_NUMBER object value
char* getSerial();
// Returns the CKA_SERIAL_NUMBER object value as a string
string getSerialString();
protected:
void QueryAttributes(PKCS11Slot * slot);
void DumpAttributes();
protected:
char * m_Serial;
int m_SerialLength;
};