Added a new Attribute to store TPM key handle
[aaf/sshsm.git] / SoftHSMv2 / src / lib / P11Attributes.h
1 /*
2  * Copyright (c) 2011 .SE (The Internet Infrastructure Foundation)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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.
25  */
26
27 /*****************************************************************************
28  P11Attributes.h
29
30  This file contains classes for controlling attributes
31  *****************************************************************************/
32
33 #ifndef _SOFTHSM_V2_P11ATTRIBUTES_H
34 #define _SOFTHSM_V2_P11ATTRIBUTES_H
35
36 #include "cryptoki.h"
37 #include "OSObject.h"
38 #include "Token.h"
39 #include "OSAttributes.h"
40
41 // The operation types
42 #define OBJECT_OP_NONE          0x0
43 #define OBJECT_OP_COPY          0x1
44 #define OBJECT_OP_CREATE        0x2
45 #define OBJECT_OP_DERIVE        0x3
46 #define OBJECT_OP_GENERATE      0x4
47 #define OBJECT_OP_SET           0x5
48 #define OBJECT_OP_UNWRAP        0x6
49
50 class P11Attribute
51 {
52 public:
53         // Destructor
54         virtual ~P11Attribute();
55
56         // Initialize the attribute
57         bool init();
58
59         // Return the attribute type
60         CK_ATTRIBUTE_TYPE getType();
61
62         // Return the attribute checks
63         CK_ULONG getChecks();
64
65         // Retrieve the value if allowed
66         CK_RV retrieve(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG_PTR pulValueLen);
67
68         // Update the value if allowed
69         CK_RV update(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
70
71         // Checks are determined by footnotes from table 10 under section 4.2 in the PKCS#11 v2.40 spec.
72         // Table 10 contains common footnotes for object attribute tables that determine the checks to perform on attributes.
73         // There are also checks not in table 10 that have been added here to allow enforcing additional contraints.
74         enum {
75                 ck1=1,          //  1  MUST be specified when object is created with C_CreateObject.
76                 ck2=2,          //  2  MUST not be specified when object is created with C_CreateObject.
77                 ck3=4,          //  3  MUST be specified when object is generated with C_GenerateKey or C_GenerateKeyPair.
78                 ck4=8,          //  4  MUST not be specified when object is generated with C_GenerateKey or C_GenerateKeyPair.
79                 ck5=0x10,       //  5  MUST be specified when object is unwrapped with C_UnwrapKey.
80                 ck6=0x20,       //  6  MUST not be specified when object is unwrapped with C_UnwrapKey.
81                 ck7=0x40,       //  7  Cannot be revealed if object has its CKA_SENSITIVE attribute set to CK_TRUE or
82                                 //      its CKA_EXTRACTABLE attribute set to CK_FALSE.
83                 ck8=0x80,       //  8  May be modified after object is created with a C_SetAttributeValue call,
84                                 //      or in the process of copying object with a C_CopyObject call.
85                                 //      However, it is possible that a particular token may not permit modification of
86                                 //      the attribute during the course of a C_CopyObject call.
87                 ck9=0x100,      //  9  Default value is token-specific, and may depend on the values of other attributes.
88                 ck10=0x200,     // 10  Can only be set to CK_TRUE by the SO user.
89                 ck11=0x400,     // 11  Attribute cannot be changed once set to CK_TRUE. It becomes a read only attribute.
90                 ck12=0x800,     // 12  Attribute cannot be changed once set to CK_FALSE. It becomes a read only attribute.
91                 ck13=0x1000,    // Intentionally not defined
92                 ck14=0x2000,    // 14  MUST be non-empty if CKA_URL is empty. (CKA_VALUE)
93                 ck15=0x4000,    // 15  MUST be non-empty if CKA_VALUE is empty. (CKA_URL)
94                 ck16=0x8000,    // 16  Can only be empty if CKA_URL is empty.
95                 ck17=0x10000,   // 17  Can be changed in the process of copying the object using C_CopyObject.
96                 ck18=0x20000,
97                 ck19=0x40000,
98                 ck20=0x80000,
99                 ck21=0x100000,
100                 ck22=0x200000,
101                 ck23=0x400000,
102                 ck24=0x800000
103         };
104 protected:
105         // Constructor
106         P11Attribute(OSObject* inobject);
107
108         // The object
109         OSObject* osobject;
110
111         // The attribute type
112         CK_ATTRIBUTE_TYPE type;
113
114         // The checks to perform when the attribute is accessed.
115         CK_ULONG checks;
116
117         // The attribute fixed size contains (CK_ULONG)-1 when size is variable.
118         CK_ULONG size;
119
120         // Set the default value of the attribute
121         virtual bool setDefault() = 0;
122
123         // Update the value if allowed
124         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
125
126         // Helper functions
127         bool isModifiable();
128         bool isSensitive();
129         bool isExtractable();
130         bool isTrusted();
131 };
132
133 /*****************************************
134  * CKA_CLASS
135  *****************************************/
136
137 class P11AttrClass : public P11Attribute
138 {
139 public:
140         // Constructor
141         P11AttrClass(OSObject* inobject) : P11Attribute(inobject) { type = CKA_CLASS; size = sizeof(CK_OBJECT_CLASS); checks = ck1; }
142
143 protected:
144         // Set the default value of the attribute
145         virtual bool setDefault();
146
147         // Update the value if allowed
148         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
149 };
150
151 /*****************************************
152  * CKA_KEY_TYPE
153  *****************************************/
154
155 class P11AttrKeyType : public P11Attribute
156 {
157 public:
158         // Constructor
159         P11AttrKeyType(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_KEY_TYPE; size = sizeof(CK_KEY_TYPE); checks = ck1|inchecks; }
160
161 protected:
162         // Set the default value of the attribute
163         virtual bool setDefault();
164
165         // Update the value if allowed
166         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
167 };
168
169 /*****************************************
170  * CKA_CERTIFICATE_TYPE
171  *****************************************/
172
173 class P11AttrCertificateType : public P11Attribute
174 {
175 public:
176         // Constructor
177         P11AttrCertificateType(OSObject* inobject) : P11Attribute(inobject) { type = CKA_CERTIFICATE_TYPE; size = sizeof(CK_CERTIFICATE_TYPE); checks = ck1; }
178
179 protected:
180         // Set the default value of the attribute
181         virtual bool setDefault();
182
183         // Update the value if allowed
184         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
185 };
186
187 /*****************************************
188  * CKA_TOKEN
189  *****************************************/
190
191 class P11AttrToken : public P11Attribute
192 {
193 public:
194         // Constructor
195         P11AttrToken(OSObject* inobject) : P11Attribute(inobject) { type = CKA_TOKEN; size = sizeof(CK_BBOOL); checks = ck17; }
196
197 protected:
198         // Set the default value of the attribute
199         virtual bool setDefault();
200
201         // Update the value if allowed
202         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
203 };
204
205 /*****************************************
206  * CKA_PRIVATE
207  *****************************************/
208
209 class P11AttrPrivate : public P11Attribute
210 {
211 public:
212         // Constructor
213         P11AttrPrivate(OSObject* inobject) : P11Attribute(inobject) { type = CKA_PRIVATE; size = sizeof(CK_BBOOL); checks = ck17; }
214
215 protected:
216         // Set the default value of the attribute
217         virtual bool setDefault();
218
219         // Update the value if allowed
220         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
221 };
222
223 /*****************************************
224  * CKA_MODIFIABLE
225  *****************************************/
226
227 class P11AttrModifiable : public P11Attribute
228 {
229 public:
230         // Constructor
231         P11AttrModifiable(OSObject* inobject) : P11Attribute(inobject) { type = CKA_MODIFIABLE; size = sizeof(CK_BBOOL); checks = ck17; }
232
233 protected:
234         // Set the default value of the attribute
235         virtual bool setDefault();
236
237         // Update the value if allowed
238         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
239 };
240
241 /*****************************************
242  * CKA_LABEL
243  *****************************************/
244
245 class P11AttrLabel : public P11Attribute
246 {
247 public:
248         // Constructor
249         P11AttrLabel(OSObject* inobject) : P11Attribute(inobject) { type = CKA_LABEL;  checks = ck8; }
250
251 protected:
252         // Set the default value of the attribute
253         virtual bool setDefault();
254 };
255
256 /*****************************************
257  * CKA_COPYABLE
258  *****************************************/
259
260 class P11AttrCopyable : public P11Attribute
261 {
262 public:
263         // Constructor
264         P11AttrCopyable(OSObject* inobject) : P11Attribute(inobject) { type = CKA_COPYABLE; size = sizeof(CK_BBOOL); checks = ck12; }
265
266 protected:
267         // Set the default value of the attribute
268         virtual bool setDefault();
269
270         // Update the value if allowed
271         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
272 };
273
274 /*****************************************
275  * CKA_DESTROYABLE
276  *****************************************/
277
278 class P11AttrDestroyable : public P11Attribute
279 {
280 public:
281         // Constructor
282         P11AttrDestroyable(OSObject* inobject) : P11Attribute(inobject) { type = CKA_DESTROYABLE; size = sizeof(CK_BBOOL); checks = ck17; }
283
284 protected:
285         // Set the default value of the attribute
286         virtual bool setDefault();
287
288         // Update the value if allowed
289         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
290 };
291
292 /*****************************************
293  * CKA_APPLICATION
294  *****************************************/
295
296 class P11AttrApplication : public P11Attribute
297 {
298 public:
299         // Constructor
300         P11AttrApplication(OSObject* inobject) : P11Attribute(inobject) { type = CKA_APPLICATION; checks = 0; }
301
302 protected:
303         // Set the default value of the attribute
304         virtual bool setDefault();
305 };
306
307 /*****************************************
308  * CKA_OBJECT_ID
309  *****************************************/
310
311 class P11AttrObjectID : public P11Attribute
312 {
313 public:
314         // Constructor
315         P11AttrObjectID(OSObject* inobject) : P11Attribute(inobject) { type = CKA_OBJECT_ID; checks = 0; }
316
317 protected:
318         // Set the default value of the attribute
319         virtual bool setDefault();
320 };
321
322 /*****************************************
323  * CKA_CHECK_VALUE
324  *****************************************/
325
326 class P11AttrCheckValue : public P11Attribute
327 {
328 public:
329         // Constructor
330         P11AttrCheckValue(OSObject* inobject, CK_ULONG inchecks) : P11Attribute(inobject) { type = CKA_CHECK_VALUE; checks = inchecks; }
331
332 protected:
333         // Set the default value of the attribute
334         virtual bool setDefault();
335
336
337         // Update the value if allowed
338         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
339 };
340
341 /*****************************************
342  * CKA_PUBLIC_KEY_INFO
343  *****************************************/
344
345 class P11AttrPublicKeyInfo : public P11Attribute
346 {
347 public:
348         // Constructor
349         P11AttrPublicKeyInfo(OSObject* inobject, CK_ULONG inchecks) : P11Attribute(inobject) { type = CKA_OBJECT_ID; checks = inchecks; }
350
351 protected:
352         // Set the default value of the attribute
353         virtual bool setDefault();
354 };
355
356 /*****************************************
357  * CKA_ID
358  *****************************************/
359
360 class P11AttrID : public P11Attribute
361 {
362 public:
363         // Constructor
364         P11AttrID(OSObject* inobject) : P11Attribute(inobject) { type = CKA_ID; checks = ck8; }
365
366 protected:
367         // Set the default value of the attribute
368         virtual bool setDefault();
369 };
370
371 /*****************************************
372  * CKA_VALUE
373  *****************************************/
374
375 class P11AttrValue : public P11Attribute
376 {
377 public:
378         // Constructor
379         P11AttrValue(OSObject* inobject, CK_ULONG inchecks) : P11Attribute(inobject) { type = CKA_VALUE; checks = inchecks; }
380
381 protected:
382         // Set the default value of the attribute
383         virtual bool setDefault();
384
385         // Update the value if allowed
386         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
387 };
388
389 /*****************************************
390  * CKA_SUBJECT
391  *****************************************/
392
393 class P11AttrSubject : public P11Attribute
394 {
395 public:
396         // Constructor
397         P11AttrSubject(OSObject* inobject, CK_ULONG inchecks) : P11Attribute(inobject) { type = CKA_SUBJECT; checks = inchecks; }
398
399 protected:
400         // Set the default value of the attribute
401         virtual bool setDefault();
402 };
403
404 /*****************************************
405  * CKA_ISSUER
406  *****************************************/
407
408 class P11AttrIssuer : public P11Attribute
409 {
410 public:
411         // Constructor
412         P11AttrIssuer(OSObject* inobject) : P11Attribute(inobject) { type = CKA_ISSUER; checks = ck8; }
413
414 protected:
415         // Set the default value of the attribute
416         virtual bool setDefault();
417 };
418
419 /*****************************************
420  * CKA_TRUSTED
421  *****************************************/
422
423 class P11AttrTrusted : public P11Attribute
424 {
425 public:
426         // Constructor
427         P11AttrTrusted(OSObject* inobject) : P11Attribute(inobject) { type = CKA_TRUSTED; size = sizeof(CK_BBOOL); checks = ck10; }
428
429 protected:
430         // Set the default value of the attribute
431         virtual bool setDefault();
432
433         // Update the value if allowed
434         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
435 };
436
437 /*****************************************
438  * CKA_CERTIFICATE_CATEGORY
439  *****************************************/
440
441 class P11AttrCertificateCategory : public P11Attribute
442 {
443 public:
444         // Constructor
445         P11AttrCertificateCategory(OSObject* inobject) : P11Attribute(inobject) { type = CKA_CERTIFICATE_CATEGORY; size = sizeof(CK_ULONG); checks = 0; }
446
447 protected:
448         // Set the default value of the attribute
449         virtual bool setDefault();
450
451         // Update the value if allowed
452         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
453 };
454
455 /*****************************************
456  * CKA_START_DATE
457  *****************************************/
458
459 class P11AttrStartDate : public P11Attribute
460 {
461 public:
462         // Constructor
463         P11AttrStartDate(OSObject* inobject, CK_ULONG inchecks) : P11Attribute(inobject) { type = CKA_START_DATE; checks = inchecks; }
464
465 protected:
466         // Set the default value of the attribute
467         virtual bool setDefault();
468
469         // Update the value if allowed
470         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
471 };
472
473 /*****************************************
474  * CKA_END_DATE
475  *****************************************/
476
477 class P11AttrEndDate : public P11Attribute
478 {
479 public:
480         // Constructor
481         P11AttrEndDate(OSObject* inobject, CK_ULONG inchecks) : P11Attribute(inobject) { type = CKA_END_DATE; checks = inchecks; }
482
483 protected:
484         // Set the default value of the attribute
485         virtual bool setDefault();
486
487         // Update the value if allowed
488         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
489 };
490
491 /*****************************************
492  * CKA_SERIAL_NUMBER
493  *****************************************/
494
495 class P11AttrSerialNumber : public P11Attribute
496 {
497 public:
498         // Constructor
499         P11AttrSerialNumber(OSObject* inobject) : P11Attribute(inobject) { type = CKA_SERIAL_NUMBER; checks = ck8; }
500
501 protected:
502         // Set the default value of the attribute
503         virtual bool setDefault();
504 };
505
506 /*****************************************
507  * CKA_URL
508  *****************************************/
509
510 class P11AttrURL : public P11Attribute
511 {
512 public:
513         // Constructor
514         P11AttrURL(OSObject* inobject) : P11Attribute(inobject) { type = CKA_URL; checks = ck15; }
515
516 protected:
517         // Set the default value of the attribute
518         virtual bool setDefault();
519 };
520
521 /*****************************************
522  * CKA_HASH_OF_SUBJECT_PUBLIC_KEY
523  *****************************************/
524
525 class P11AttrHashOfSubjectPublicKey : public P11Attribute
526 {
527 public:
528         // Constructor
529         P11AttrHashOfSubjectPublicKey(OSObject* inobject) : P11Attribute(inobject) { type = CKA_HASH_OF_SUBJECT_PUBLIC_KEY; checks = ck16; }
530
531 protected:
532         // Set the default value of the attribute
533         virtual bool setDefault();
534 };
535
536 /*****************************************
537  * CKA_HASH_OF_ISSUER_PUBLIC_KEY
538  *****************************************/
539
540 class P11AttrHashOfIssuerPublicKey : public P11Attribute
541 {
542 public:
543         // Constructor
544         P11AttrHashOfIssuerPublicKey(OSObject* inobject) : P11Attribute(inobject) { type = CKA_HASH_OF_ISSUER_PUBLIC_KEY; checks = ck16; }
545
546 protected:
547         // Set the default value of the attribute
548         virtual bool setDefault();
549 };
550
551 /*****************************************
552  * CKA_JAVA_MIDP_SECURITY_DOMAIN
553  *****************************************/
554
555 class P11AttrJavaMidpSecurityDomain : public P11Attribute
556 {
557 public:
558         // Constructor
559         P11AttrJavaMidpSecurityDomain(OSObject* inobject) : P11Attribute(inobject) { type = CKA_JAVA_MIDP_SECURITY_DOMAIN; size = sizeof(CK_ULONG); checks = 0; }
560
561 protected:
562         // Set the default value of the attribute
563         virtual bool setDefault();
564
565         // Update the value if allowed
566         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
567 };
568
569 /*****************************************
570  * CKA_NAME_HASH_ALGORITHM
571  *****************************************/
572
573 class P11AttrNameHashAlgorithm : public P11Attribute
574 {
575 public:
576         // Constructor
577         P11AttrNameHashAlgorithm(OSObject* inobject) : P11Attribute(inobject) { type = CKA_NAME_HASH_ALGORITHM; size = sizeof(CK_MECHANISM_TYPE); checks = 0; }
578
579 protected:
580         // Set the default value of the attribute
581         virtual bool setDefault();
582
583         // Update the value if allowed
584         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
585 };
586
587 /*****************************************
588  * CKA_DERIVE
589  *****************************************/
590
591 class P11AttrDerive : public P11Attribute
592 {
593 public:
594         // Constructor
595         P11AttrDerive(OSObject* inobject) : P11Attribute(inobject) { type = CKA_DERIVE; size = sizeof(CK_BBOOL); checks = ck8;}
596
597 protected:
598         // Set the default value of the attribute
599         virtual bool setDefault();
600
601         // Update the value if allowed
602         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
603 };
604
605 /*****************************************
606  * CKA_ENCRYPT
607  *****************************************/
608
609 class P11AttrEncrypt : public P11Attribute
610 {
611 public:
612         // Constructor
613         P11AttrEncrypt(OSObject* inobject) : P11Attribute(inobject) { type = CKA_ENCRYPT; size = sizeof(CK_BBOOL); checks = ck8|ck9; }
614
615 protected:
616         // Set the default value of the attribute
617         virtual bool setDefault();
618
619         // Update the value if allowed
620         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
621 };
622
623 /*****************************************
624  * CKA_VERIFY
625  *****************************************/
626
627 class P11AttrVerify : public P11Attribute
628 {
629 public:
630         // Constructor
631         P11AttrVerify(OSObject* inobject) : P11Attribute(inobject) { type = CKA_VERIFY; size = sizeof(CK_BBOOL); checks = ck8|ck9; }
632
633 protected:
634         // Set the default value of the attribute
635         virtual bool setDefault();
636
637         // Update the value if allowed
638         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
639 };
640
641 /*****************************************
642  * CKA_VERIFY_RECOVER
643  *****************************************/
644
645 class P11AttrVerifyRecover : public P11Attribute
646 {
647 public:
648         // Constructor
649         P11AttrVerifyRecover(OSObject* inobject) : P11Attribute(inobject) { type = CKA_VERIFY_RECOVER; size = sizeof(CK_BBOOL); checks = ck8|ck9; }
650
651 protected:
652         // Set the default value of the attribute
653         virtual bool setDefault();
654
655         // Update the value if allowed
656         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
657 };
658
659 /*****************************************
660  * CKA_WRAP
661  *****************************************/
662
663 class P11AttrWrap : public P11Attribute
664 {
665 public:
666         // Constructor
667         P11AttrWrap(OSObject* inobject) : P11Attribute(inobject) { type = CKA_WRAP; size = sizeof(CK_BBOOL); checks = ck8|ck9; }
668
669 protected:
670         // Set the default value of the attribute
671         virtual bool setDefault();
672
673         // Update the value if allowed
674         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
675 };
676
677 /*****************************************
678  * CKA_DECRYPT
679  *****************************************/
680
681 class P11AttrDecrypt : public P11Attribute
682 {
683 public:
684         // Constructor
685         P11AttrDecrypt(OSObject* inobject) : P11Attribute(inobject) { type = CKA_DECRYPT; size = sizeof(CK_BBOOL); checks = ck8|ck9; }
686
687 protected:
688         // Set the default value of the attribute
689         virtual bool setDefault();
690
691         // Update the value if allowed
692         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
693 };
694
695 /*****************************************
696  * CKA_SIGN
697  *****************************************/
698
699 class P11AttrSign : public P11Attribute
700 {
701 public:
702         // Constructor
703         P11AttrSign(OSObject* inobject) : P11Attribute(inobject) { type = CKA_SIGN; size = sizeof(CK_BBOOL); checks = ck8|ck9; }
704
705 protected:
706         // Set the default value of the attribute
707         virtual bool setDefault();
708
709         // Update the value if allowed
710         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
711 };
712
713 /*****************************************
714  * CKA_SIGN_RECOVER
715  *****************************************/
716
717 class P11AttrSignRecover : public P11Attribute
718 {
719 public:
720         // Constructor
721         P11AttrSignRecover(OSObject* inobject) : P11Attribute(inobject) { type = CKA_SIGN_RECOVER; size = sizeof(CK_BBOOL); checks = ck8|ck9; }
722
723 protected:
724         // Set the default value of the attribute
725         virtual bool setDefault();
726
727         // Update the value if allowed
728         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
729 };
730
731 /*****************************************
732  * CKA_UNWRAP
733  *****************************************/
734
735 class P11AttrUnwrap : public P11Attribute
736 {
737 public:
738         // Constructor
739         P11AttrUnwrap(OSObject* inobject) : P11Attribute(inobject) { type = CKA_UNWRAP; size = sizeof(CK_BBOOL); checks = ck8|ck9; }
740
741 protected:
742         // Set the default value of the attribute
743         virtual bool setDefault();
744
745         // Update the value if allowed
746         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
747 };
748
749 /*****************************************
750  * CKA_LOCAL
751  *****************************************/
752
753 class P11AttrLocal : public P11Attribute
754 {
755 public:
756         // Constructor
757         P11AttrLocal(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_LOCAL; size = sizeof(CK_BBOOL); checks = ck2|ck4|inchecks; }
758
759 protected:
760         // Set the default value of the attribute
761         virtual bool setDefault();
762
763         // Update the value if allowed
764         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
765 };
766
767 /*****************************************
768  * CKA_KEY_GEN_MECHANISM
769  *****************************************/
770
771 class P11AttrKeyGenMechanism : public P11Attribute
772 {
773 public:
774         // Constructor
775         P11AttrKeyGenMechanism(OSObject* inobject) : P11Attribute(inobject) { type = CKA_KEY_GEN_MECHANISM; size = sizeof(CK_MECHANISM_TYPE); checks = ck2|ck4|ck6; }
776
777 protected:
778         // Set the default value of the attribute
779         virtual bool setDefault();
780
781         // Update the value if allowed
782         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
783 };
784
785 /*****************************************
786  * CKA_ALWAYS_SENSITIVE
787  *****************************************/
788
789 class P11AttrAlwaysSensitive : public P11Attribute
790 {
791 public:
792         // Constructor
793         P11AttrAlwaysSensitive(OSObject* inobject) : P11Attribute(inobject) { type = CKA_ALWAYS_SENSITIVE; size = sizeof(CK_BBOOL); checks = ck2|ck4|ck6; }
794
795 protected:
796         // Set the default value of the attribute
797         virtual bool setDefault();
798
799         // Update the value if allowed
800         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
801 };
802
803 /*****************************************
804  * CKA_NEVER_EXTRACTABLE
805  *****************************************/
806
807 class P11AttrNeverExtractable : public P11Attribute
808 {
809 public:
810         // Constructor
811         P11AttrNeverExtractable(OSObject* inobject) : P11Attribute(inobject) { type = CKA_NEVER_EXTRACTABLE; size = sizeof(CK_BBOOL); checks = ck2|ck4|ck6; }
812
813 protected:
814         // Set the default value of the attribute
815         virtual bool setDefault();
816
817         // Update the value if allowed
818         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
819 };
820
821 /*****************************************
822  * CKA_SENSITIVE
823  *****************************************/
824
825 class P11AttrSensitive : public P11Attribute
826 {
827 public:
828         // Constructor
829         P11AttrSensitive(OSObject* inobject) : P11Attribute(inobject) { type = CKA_SENSITIVE; size = sizeof(CK_BBOOL); checks = ck8|ck9|ck11; }
830
831 protected:
832         // Set the default value of the attribute
833         virtual bool setDefault();
834
835         // Update the value if allowed
836         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
837 };
838
839 /*****************************************
840  * CKA_EXTRACTABLE
841  *****************************************/
842
843 class P11AttrExtractable : public P11Attribute
844 {
845 public:
846         // Constructor
847         P11AttrExtractable(OSObject* inobject) : P11Attribute(inobject) { type = CKA_EXTRACTABLE; size = sizeof(CK_BBOOL); checks = ck8|ck9|ck12; }
848
849 protected:
850         // Set the default value of the attribute
851         virtual bool setDefault();
852
853         // Update the value if allowed
854         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
855 };
856
857 /*****************************************
858  * CKA_WRAP_WITH_TRUSTED
859  *****************************************/
860
861 class P11AttrWrapWithTrusted : public P11Attribute
862 {
863 public:
864         // Constructor
865         P11AttrWrapWithTrusted(OSObject* inobject) : P11Attribute(inobject) { type = CKA_WRAP_WITH_TRUSTED; size = sizeof(CK_BBOOL); checks = ck11; }
866
867 protected:
868         // Set the default value of the attribute
869         virtual bool setDefault();
870
871         // Update the value if allowed
872         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
873 };
874
875 /*****************************************
876  * CKA_ALWAYS_AUTHENTICATE
877  *****************************************/
878
879 class P11AttrAlwaysAuthenticate : public P11Attribute
880 {
881 public:
882         // Constructor
883         P11AttrAlwaysAuthenticate(OSObject* inobject) : P11Attribute(inobject) { type = CKA_ALWAYS_AUTHENTICATE; size = sizeof(CK_BBOOL); checks = 0; }
884
885 protected:
886         // Set the default value of the attribute
887         virtual bool setDefault();
888
889         // Update the value if allowed
890         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
891 };
892
893 /*****************************************
894  * CKA_MODULUS
895  *****************************************/
896
897 class P11AttrModulus : public P11Attribute
898 {
899 public:
900         // Constructor
901         P11AttrModulus(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_MODULUS; checks = ck1|ck4|inchecks; }
902
903 protected:
904         // Set the default value of the attribute
905         virtual bool setDefault();
906
907         // Update the value if allowed
908         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
909 };
910
911 /*****************************************
912  * CKA_PUBLIC_EXPONENT
913  *****************************************/
914
915 class P11AttrPublicExponent : public P11Attribute
916 {
917 public:
918         // Constructor
919         P11AttrPublicExponent(OSObject* inobject, CK_ULONG inchecks) : P11Attribute(inobject) { type = CKA_PUBLIC_EXPONENT; checks = inchecks; }
920
921 protected:
922         // Set the default value of the attribute
923         virtual bool setDefault();
924 };
925
926 /*****************************************
927  * CKA_PRIVATE_EXPONENT
928  *****************************************/
929
930 class P11AttrPrivateExponent : public P11Attribute
931 {
932 public:
933         // Constructor
934         P11AttrPrivateExponent(OSObject* inobject) : P11Attribute(inobject) { type = CKA_PRIVATE_EXPONENT; checks = ck1|ck4|ck6|ck7; }
935
936 protected:
937         // Set the default value of the attribute
938         virtual bool setDefault();
939 };
940
941 /*****************************************
942  * CKA_PRIME_1
943  *****************************************/
944
945 class P11AttrPrime1 : public P11Attribute
946 {
947 public:
948         // Constructor
949         P11AttrPrime1(OSObject* inobject) : P11Attribute(inobject) { type = CKA_PRIME_1; checks = ck4|ck6|ck7; }
950
951 protected:
952         // Set the default value of the attribute
953         virtual bool setDefault();
954 };
955
956 /*****************************************
957  * CKA_PRIME_2
958  *****************************************/
959
960 class P11AttrPrime2 : public P11Attribute
961 {
962 public:
963         // Constructor
964         P11AttrPrime2(OSObject* inobject) : P11Attribute(inobject) { type = CKA_PRIME_2; checks = ck4|ck6|ck7; }
965
966 protected:
967         // Set the default value of the attribute
968         virtual bool setDefault();
969 };
970
971 /*****************************************
972  * CKA_EXPONENT_1
973  *****************************************/
974
975 class P11AttrExponent1 : public P11Attribute
976 {
977 public:
978         // Constructor
979         P11AttrExponent1(OSObject* inobject) : P11Attribute(inobject) { type = CKA_EXPONENT_1; checks = ck4|ck6|ck7; }
980
981 protected:
982         // Set the default value of the attribute
983         virtual bool setDefault();
984 };
985
986 /*****************************************
987  * CKA_EXPONENT_2
988  *****************************************/
989
990 class P11AttrExponent2 : public P11Attribute
991 {
992 public:
993         // Constructor
994         P11AttrExponent2(OSObject* inobject) : P11Attribute(inobject) { type = CKA_EXPONENT_2; checks = ck4|ck6|ck7; }
995
996 protected:
997         // Set the default value of the attribute
998         virtual bool setDefault();
999 };
1000
1001 /*****************************************
1002  * CKA_COEFFICIENT
1003  *****************************************/
1004
1005 class P11AttrCoefficient : public P11Attribute
1006 {
1007 public:
1008         // Constructor
1009         P11AttrCoefficient(OSObject* inobject) : P11Attribute(inobject) { type = CKA_COEFFICIENT; checks = ck4|ck6|ck7; }
1010
1011 protected:
1012         // Set the default value of the attribute
1013         virtual bool setDefault();
1014 };
1015
1016 /*****************************************
1017  * CKA_MODULUS_BITS
1018  *****************************************/
1019
1020 class P11AttrModulusBits : public P11Attribute
1021 {
1022 public:
1023         // Constructor
1024         P11AttrModulusBits(OSObject* inobject) : P11Attribute(inobject) { type = CKA_MODULUS_BITS; size = sizeof(CK_ULONG); checks = ck2|ck3;}
1025
1026 protected:
1027         // Set the default value of the attribute
1028         virtual bool setDefault();
1029
1030         // Update the value if allowed
1031         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1032 };
1033
1034 /*****************************************
1035  * CKA_PRIME
1036  *****************************************/
1037
1038 class P11AttrPrime : public P11Attribute
1039 {
1040 public:
1041         // Constructor
1042         P11AttrPrime(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_PRIME; checks = ck1|inchecks; }
1043
1044 protected:
1045         // Set the default value of the attribute
1046         virtual bool setDefault();
1047
1048         // Update the value if allowed
1049         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1050 };
1051
1052 /*****************************************
1053  * CKA_SUBPRIME
1054  *****************************************/
1055
1056 class P11AttrSubPrime : public P11Attribute
1057 {
1058 public:
1059         // Constructor
1060         P11AttrSubPrime(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_SUBPRIME; checks = ck1|inchecks; }
1061
1062 protected:
1063         // Set the default value of the attribute
1064         virtual bool setDefault();
1065 };
1066
1067 /*****************************************
1068  * CKA_BASE
1069  *****************************************/
1070
1071 class P11AttrBase : public P11Attribute
1072 {
1073 public:
1074         // Constructor
1075         P11AttrBase(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_BASE; checks = ck1|inchecks; }
1076
1077 protected:
1078         // Set the default value of the attribute
1079         virtual bool setDefault();
1080 };
1081
1082 /*****************************************
1083  * CKA_PRIME_BITS
1084  *****************************************/
1085
1086 class P11AttrPrimeBits : public P11Attribute
1087 {
1088 public:
1089         // Constructor
1090         P11AttrPrimeBits(OSObject* inobject) : P11Attribute(inobject) { type = CKA_PRIME_BITS; size = sizeof(CK_ULONG); checks = ck2|ck3;}
1091
1092 protected:
1093         // Set the default value of the attribute
1094         virtual bool setDefault();
1095
1096         // Update the value if allowed
1097         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1098 };
1099
1100 /*****************************************
1101  * CKA_VALUE_BITS
1102  *****************************************/
1103
1104 class P11AttrValueBits : public P11Attribute
1105 {
1106 public:
1107         // Constructor
1108         P11AttrValueBits(OSObject* inobject) : P11Attribute(inobject) { type = CKA_VALUE_BITS; size = sizeof(CK_ULONG); checks = ck2|ck6;}
1109
1110 protected:
1111         // Set the default value of the attribute
1112         virtual bool setDefault();
1113
1114         // Update the value if allowed
1115         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1116 };
1117
1118 /*****************************************
1119  * CKA_EC_PARAMS
1120  *****************************************/
1121
1122 class P11AttrEcParams : public P11Attribute
1123 {
1124 public:
1125         // Constructor
1126         P11AttrEcParams(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_EC_PARAMS; checks = ck1|inchecks; }
1127
1128 protected:
1129         // Set the default value of the attribute
1130         virtual bool setDefault();
1131 };
1132
1133 /*****************************************
1134  * CKA_EC_POINT
1135  *****************************************/
1136
1137 class P11AttrEcPoint : public P11Attribute
1138 {
1139 public:
1140         // Constructor
1141         P11AttrEcPoint(OSObject* inobject) : P11Attribute(inobject) { type = CKA_EC_POINT; checks = ck1|ck4; }
1142
1143 protected:
1144         // Set the default value of the attribute
1145         virtual bool setDefault();
1146 };
1147
1148 /*****************************************
1149  * CKA_GOSTR3410_PARAMS
1150  *****************************************/
1151
1152 class P11AttrGostR3410Params : public P11Attribute
1153 {
1154 public:
1155         // Constructor
1156         P11AttrGostR3410Params(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_GOSTR3410_PARAMS; checks = ck1|inchecks; }
1157
1158 protected:
1159         // Set the default value of the attribute
1160         virtual bool setDefault();
1161 };
1162
1163 /*****************************************
1164  * CKA_GOSTR3411_PARAMS
1165  *****************************************/
1166
1167 class P11AttrGostR3411Params : public P11Attribute
1168 {
1169 public:
1170         // Constructor
1171         P11AttrGostR3411Params(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_GOSTR3411_PARAMS; checks = ck1|ck8|inchecks; }
1172
1173 protected:
1174         // Set the default value of the attribute
1175         virtual bool setDefault();
1176 };
1177
1178 /*****************************************
1179  * CKA_GOST28147_PARAMS
1180  *****************************************/
1181
1182 class P11AttrGost28147Params : public P11Attribute
1183 {
1184 public:
1185         // Constructor
1186         P11AttrGost28147Params(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_GOST28147_PARAMS; checks = inchecks; }
1187
1188 protected:
1189         // Set the default value of the attribute
1190         virtual bool setDefault();
1191 };
1192
1193 /*****************************************
1194  * CKA_VALUE_LEN
1195  *****************************************/
1196
1197 class P11AttrValueLen : public P11Attribute
1198 {
1199 public:
1200         // Constructor
1201         P11AttrValueLen(OSObject* inobject, CK_ULONG inchecks = 0) : P11Attribute(inobject) { type = CKA_VALUE_LEN; size = sizeof(CK_ULONG); checks = ck2|ck3|inchecks; }
1202
1203 protected:
1204         // Set the default value of the attribute
1205         virtual bool setDefault();
1206
1207         // Update the value if allowed
1208         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1209 };
1210
1211 /*****************************************
1212  * CKA_WRAP_TEMPLATE
1213  *****************************************/
1214
1215 class P11AttrWrapTemplate : public P11Attribute
1216 {
1217 public:
1218         // Constructor
1219         P11AttrWrapTemplate(OSObject* inobject) : P11Attribute(inobject) { type = CKA_WRAP_TEMPLATE; checks = 0; }
1220
1221 protected:
1222         // Set the default value of the attribute
1223         virtual bool setDefault();
1224
1225         // Update the value if allowed
1226         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1227 };
1228
1229 /*****************************************
1230  * CKA_UNWRAP_TEMPLATE
1231  *****************************************/
1232
1233 class P11AttrUnwrapTemplate : public P11Attribute
1234 {
1235 public:
1236         // Constructor
1237         P11AttrUnwrapTemplate(OSObject* inobject) : P11Attribute(inobject) { type = CKA_UNWRAP_TEMPLATE; checks = 0; }
1238
1239 protected:
1240         // Set the default value of the attribute
1241         virtual bool setDefault();
1242
1243         // Update the value if allowed
1244         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1245 };
1246
1247 /*****************************************
1248  * CKA_ALLOWED_MECHANISMS
1249  *****************************************/
1250
1251 class P11AttrAllowedMechanisms : public P11Attribute
1252 {
1253 public:
1254         // Constructor
1255         P11AttrAllowedMechanisms(OSObject* inobject) : P11Attribute(inobject) { type = CKA_ALLOWED_MECHANISMS; checks = 0; }
1256
1257 protected:
1258         // Set the default value of the attribute
1259         virtual bool setDefault();
1260
1261         // Update the value if allowed
1262         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1263 };
1264
1265 /*****************************************
1266  * CKA_COEFFICIENT
1267  *****************************************/
1268
1269 class P11AttrPrivateHandle : public P11Attribute
1270 {
1271 public:
1272         // Constructor
1273         P11AttrPrivateHandle(OSObject* inobject) : P11Attribute(inobject) { type = CKA_OS_PRIVATE_HANDLE; checks = ck1; }
1274
1275 protected:
1276         // Set the default value of the attribute
1277         virtual bool setDefault();
1278         // Update the value if allowed
1279         virtual CK_RV updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue, CK_ULONG ulValueLen, int op);
1280 };
1281
1282
1283 #endif // !_SOFTHSM_V2_P11ATTRIBUTES_H