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 P11Objects.cpp
29
30 This class respresent a PKCS#11 object
31 *****************************************************************************/
32
33 #include "config.h"
34 #include "P11Objects.h"
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 // Constructor
P11Object()39 P11Object::P11Object()
40 {
41 initialized = false;
42 osobject = NULL;
43 }
44
45 // Destructor
~P11Object()46 P11Object::~P11Object()
47 {
48 std::map<CK_ATTRIBUTE_TYPE, P11Attribute*> cleanUp = attributes;
49 attributes.clear();
50
51 for (std::map<CK_ATTRIBUTE_TYPE, P11Attribute*>::iterator i = cleanUp.begin(); i != cleanUp.end(); i++)
52 {
53 if (i->second == NULL)
54 {
55 continue;
56 }
57
58 delete i->second;
59 i->second = NULL;
60 }
61 }
62
63 // Add attributes
init(OSObject * inobject)64 bool P11Object::init(OSObject *inobject)
65 {
66 if (initialized) return true;
67 if (inobject == NULL) return false;
68
69 osobject = inobject;
70
71 // Create attributes
72 P11Attribute* attrClass = new P11AttrClass(osobject);
73 P11Attribute* attrToken = new P11AttrToken(osobject);
74 P11Attribute* attrPrivate = new P11AttrPrivate(osobject);
75 P11Attribute* attrModifiable = new P11AttrModifiable(osobject);
76 P11Attribute* attrLabel = new P11AttrLabel(osobject);
77 P11Attribute* attrCopyable = new P11AttrCopyable(osobject);
78 P11Attribute* attrDestroyable = new P11AttrDestroyable(osobject);
79
80 // Initialize the attributes
81 if
82 (
83 !attrClass->init() ||
84 !attrToken->init() ||
85 !attrPrivate->init() ||
86 !attrModifiable->init() ||
87 !attrLabel->init() ||
88 !attrCopyable->init() ||
89 !attrDestroyable->init()
90 )
91 {
92 ERROR_MSG("Could not initialize the attribute");
93 delete attrClass;
94 delete attrToken;
95 delete attrPrivate;
96 delete attrModifiable;
97 delete attrLabel;
98 delete attrCopyable;
99 delete attrDestroyable;
100 return false;
101 }
102
103 // Add them to the map
104 attributes[attrClass->getType()] = attrClass;
105 attributes[attrToken->getType()] = attrToken;
106 attributes[attrPrivate->getType()] = attrPrivate;
107 attributes[attrModifiable->getType()] = attrModifiable;
108 attributes[attrLabel->getType()] = attrLabel;
109 attributes[attrCopyable->getType()] = attrCopyable;
110 attributes[attrDestroyable->getType()] = attrDestroyable;
111
112 initialized = true;
113 return true;
114 }
115
loadTemplate(Token * token,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulAttributeCount)116 CK_RV P11Object::loadTemplate(Token *token, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount)
117 {
118 bool isPrivate = this->isPrivate();
119
120 // [PKCS#11 v2.40, C_GetAttributeValue]
121 // 1. If the specified attribute (i.e., the attribute specified by the
122 // type field) for the object cannot be revealed because the object
123 // is sensitive or unextractable, then the ulValueLen field in that
124 // triple is modified to hold the value CK_UNAVAILABLE_INFORMATION.
125 //
126 // 2. Otherwise, if the specified value for the object is invalid (the
127 // object does not possess such an attribute), then the ulValueLen
128 // field in that triple is modified to hold the value
129 // CK_UNAVAILABLE_INFORMATION.
130 //
131 // 3. Otherwise, if the pValue field has the value NULL_PTR, then the
132 // ulValueLen field is modified to hold the exact length of the
133 // specified attribute for the object.
134 //
135 // 4. Otherwise, if the length specified in ulValueLen is large enough
136 // to hold the value of the specified attribute for the object,
137 // then that attribute is copied into the buffer located at pValue,
138 // and the ulValueLen field is modified to hold the exact length of
139 // the attribute.
140 //
141 // 5. Otherwise, the ulValueLen field is modified to hold the value
142 // CK_UNAVAILABLE_INFORMATION.
143
144 bool invalid = false, sensitive = false, buffer_too_small = false;
145
146 // If case 3 or 4 applies to all the requested attributes, then the call will return CKR_OK.
147 for (CK_ULONG i = 0; i < ulAttributeCount; ++i)
148 {
149 P11Attribute* attr = attributes[pTemplate[i].type];
150
151 // case 2 of the attribute checks
152 if (attr == NULL) {
153 pTemplate[i].ulValueLen = CK_UNAVAILABLE_INFORMATION;
154 // If case 2 applies to any of the requested attributes, then the call should
155 // return the value CKR_ATTRIBUTE_TYPE_INVALID.
156 invalid = true;
157 continue;
158 }
159
160 // case 1,3,4 and 5 of the attribute checks are done while retrieving the attribute itself.
161 CK_RV retrieve_rv = attr->retrieve(token, isPrivate, pTemplate[i].pValue, &pTemplate[i].ulValueLen);
162 if (retrieve_rv == CKR_ATTRIBUTE_SENSITIVE) {
163 // If case 1 applies to any of the requested attributes, then the call should
164 // return the value CKR_ATTRIBUTE_SENSITIVE.
165 sensitive = true;
166 } else if (retrieve_rv == CKR_BUFFER_TOO_SMALL) {
167 // If case 5 applies to any of the requested attributes, then the call should
168 // return the value CKR_BUFFER_TOO_SMALL.
169 buffer_too_small = true;
170 } else if (retrieve_rv != CKR_OK) {
171 return CKR_GENERAL_ERROR;
172 }
173
174 }
175
176 // As usual if more than one of these error codes is applicable, Cryptoki may
177 // return any of them. Only if none of them applies to any of the requested
178 // attributes will CKR_OK be returned. We choose to return the errors in
179 // the following priority, which is probably the most useful order.
180 if (sensitive)
181 return CKR_ATTRIBUTE_SENSITIVE;
182 if (invalid)
183 return CKR_ATTRIBUTE_TYPE_INVALID;
184 if (buffer_too_small)
185 return CKR_BUFFER_TOO_SMALL;
186 return CKR_OK;
187 }
188
189 // Save template
saveTemplate(Token * token,bool isPrivate,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulAttributeCount,int op)190 CK_RV P11Object::saveTemplate(Token *token, bool isPrivate, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, int op)
191 {
192 if (osobject == NULL)
193 return CKR_GENERAL_ERROR;
194 if (osobject->startTransaction() == false)
195 return CKR_GENERAL_ERROR;
196
197 if (op == OBJECT_OP_SET)
198 {
199 if (!isModifiable())
200 {
201 osobject->abortTransaction();
202 return CKR_ACTION_PROHIBITED;
203 }
204 }
205
206 // [PKCS#11 v2.40, 4.1.3 Copying objects] OBJECT_OP_COPY
207 // If the CKA_COPYABLE attribute of the object to be copied is set
208 // to CK_FALSE, C_CopyObject returns CKR_ACTION_PROHIBITED.
209 if (op == OBJECT_OP_COPY)
210 {
211 if (!isCopyable())
212 {
213 osobject->abortTransaction();
214 return CKR_ACTION_PROHIBITED;
215 }
216 }
217
218 for (CK_ULONG i = 0; i < ulAttributeCount; i++)
219 {
220 // [PKCS#11 v2.40, 4.1.1 Creating objects] OBJECT_OP_CREATE | OBJECT_OP_SET | OBJECT_OP_COPY
221 // 1. If the supplied template specifies a value for an invalid attribute, then the attempt
222 // should fail with the error code CKR_ATTRIBUTE_TYPE_INVALID. An attribute
223 // is valid if it is either one of the attributes described in the Cryptoki specification or an
224 // additional vendor-specific attribute supported by the library and token.
225 P11Attribute* attr = attributes[pTemplate[i].type];
226
227 if (attr == NULL)
228 {
229 osobject->abortTransaction();
230 return CKR_ATTRIBUTE_TYPE_INVALID;
231 }
232
233 // Additonal checks are done while updating the attributes themselves.
234 CK_RV rv = attr->update(token,isPrivate, pTemplate[i].pValue, pTemplate[i].ulValueLen, op);
235 if (rv != CKR_OK)
236 {
237 osobject->abortTransaction();
238 return rv;
239 }
240 }
241
242 // [PKCS#11 v2.40, 4.1.1 Creating objects]
243 // 4. If the attribute values in the supplied template, together with any default attribute
244 // values and any attribute values contributed to the object by the object-creation
245 // function itself, are insufficient to fully specify the object to create, then the attempt
246 // should fail with the error code CKR_TEMPLATE_INCOMPLETE.
247
248 // All attributes that have to be specified are marked as such in the specification.
249 // The following checks are relevant here:
250 for (std::map<CK_ATTRIBUTE_TYPE, P11Attribute*>::iterator i = attributes.begin(); i != attributes.end(); i++)
251 {
252 CK_ULONG checks = i->second->getChecks();
253
254 // ck1 MUST be specified when object is created with C_CreateObject.
255 // ck3 MUST be specified when object is generated with C_GenerateKey or C_GenerateKeyPair.
256 // ck5 MUST be specified when object is unwrapped with C_UnwrapKey.
257 if (((checks & P11Attribute::ck1) == P11Attribute::ck1 && op == OBJECT_OP_CREATE) ||
258 ((checks & P11Attribute::ck3) == P11Attribute::ck3 && op == OBJECT_OP_GENERATE) ||
259 ((checks & P11Attribute::ck5) == P11Attribute::ck5 && op == OBJECT_OP_UNWRAP))
260 {
261 bool isSpecified = false;
262
263 for (CK_ULONG n = 0; n < ulAttributeCount; n++)
264 {
265 if (i->first == pTemplate[n].type)
266 {
267 isSpecified = true;
268 break;
269 }
270 }
271
272 if (!isSpecified)
273 {
274 ERROR_MSG("Mandatory attribute (0x%08X) was not specified in template", (unsigned int)i->first);
275
276 return CKR_TEMPLATE_INCOMPLETE;
277 }
278 }
279 }
280
281 // [PKCS#11 v2.40, 4.1.1 Creating objects]
282 // 5. If the attribute values in the supplied template, together with any default attribute
283 // values and any attribute values contributed to the object by the object-creation
284 // function itself, are inconsistent, then the attempt should fail with the error code
285 // CKR_TEMPLATE_INCONSISTENT. A set of attribute values is inconsistent if not
286 // all of its members can be satisfied simultaneously by the token, although each value
287 // individually is valid in Cryptoki. One example of an inconsistent template would be
288 // using a template which specifies two different values for the same attribute. Another
289 // example would be trying to create a secret key object with an attribute which is
290 // appropriate for various types of public keys or private keys, but not for secret keys.
291 // A final example would be a template with an attribute that violates some token
292 // specific requirement. Note that this final example of an inconsistent template is
293 // token-dependent—on a different token, such a template might not be inconsistent.
294
295 if (osobject->commitTransaction() == false)
296 {
297 return CKR_GENERAL_ERROR;
298 }
299
300 return CKR_OK;
301 }
302
isPrivate()303 bool P11Object::isPrivate()
304 {
305 // Get the CKA_PRIVATE attribute, when the attribute is
306 // not present return the default value which we have
307 // chosen to be CK_FALSE.
308 if (!osobject->attributeExists(CKA_PRIVATE)) return false;
309
310 return osobject->getBooleanValue(CKA_PRIVATE, false);
311 }
312
isCopyable()313 bool P11Object::isCopyable()
314 {
315 // Get the CKA_COPYABLE attribute, when the attribute is not
316 // present return the default value which is CK_TRUE.
317 if (!osobject->attributeExists(CKA_COPYABLE)) return true;
318
319 return osobject->getBooleanValue(CKA_COPYABLE, true);
320 }
321
isModifiable()322 bool P11Object::isModifiable()
323 {
324 // Get the CKA_MODIFIABLE attribute, when the attribute is
325 // not present return the default value which is CK_TRUE.
326 if (!osobject->attributeExists(CKA_MODIFIABLE)) return true;
327
328 return osobject->getBooleanValue(CKA_MODIFIABLE, true);
329 }
330
331 // Constructor
P11DataObj()332 P11DataObj::P11DataObj()
333 {
334 initialized = false;
335 }
336
337 // Add attributes
init(OSObject * inobject)338 bool P11DataObj::init(OSObject *inobject)
339 {
340 if (initialized) return true;
341 if (inobject == NULL) return false;
342
343 // Set default values for attributes that will be introduced in the parent
344 if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_DATA) {
345 OSAttribute setClass((unsigned long)CKO_DATA);
346 inobject->setAttribute(CKA_CLASS, setClass);
347 }
348
349 // Create parent
350 if (!P11Object::init(inobject)) return false;
351
352 // Create attributes
353 P11Attribute* attrApplication = new P11AttrApplication(osobject);
354 P11Attribute* attrObjectID = new P11AttrObjectID(osobject);
355 // NOTE: There is no mention in the PKCS#11 v2.40 spec that for a Data
356 // Object the CKA_VALUE attribute may be modified after creation!
357 // Therefore we assume it is not allowed to change the CKA_VALUE
358 // attribute of a Data Object.
359 P11Attribute* attrValue = new P11AttrValue(osobject,0);
360
361 // Initialize the attributes
362 if
363 (
364 !attrApplication->init() ||
365 !attrObjectID->init() ||
366 !attrValue->init()
367 )
368 {
369 ERROR_MSG("Could not initialize the attribute");
370 delete attrApplication;
371 delete attrObjectID;
372 delete attrValue;
373 return false;
374 }
375
376 // Add them to the map
377 attributes[attrApplication->getType()] = attrApplication;
378 attributes[attrObjectID->getType()] = attrObjectID;
379 attributes[attrValue->getType()] = attrValue;
380
381 initialized = true;
382 return true;
383 }
384
385 // Constructor
P11CertificateObj()386 P11CertificateObj::P11CertificateObj()
387 {
388 initialized = false;
389 }
390
391 // Add attributes
init(OSObject * inobject)392 bool P11CertificateObj::init(OSObject *inobject)
393 {
394 if (initialized) return true;
395 if (inobject == NULL) return false;
396
397 // Set default values for attributes that will be introduced in the parent
398 if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_CERTIFICATE) {
399 OSAttribute setClass((unsigned long)CKO_CERTIFICATE);
400 inobject->setAttribute(CKA_CLASS, setClass);
401 }
402 // Make certificates public
403 if (!inobject->attributeExists(CKA_PRIVATE)) {
404 OSAttribute setPrivate(false);
405 inobject->setAttribute(CKA_PRIVATE, setPrivate);
406 }
407
408 // Create parent
409 if (!P11Object::init(inobject)) return false;
410
411 // Create attributes
412 P11Attribute* attrCertificateType = new P11AttrCertificateType(osobject);
413 P11Attribute* attrTrusted = new P11AttrTrusted(osobject);
414 P11Attribute* attrCertificateCategory = new P11AttrCertificateCategory(osobject);
415 // NOTE: Because these attributes are used in a certificate object
416 // where the CKA_VALUE containing the certificate data is not
417 // modifiable, we assume that this attribute is also not modifiable.
418 // There is also no explicit mention of these attributes being modifiable.
419 P11Attribute* attrCheckValue = new P11AttrCheckValue(osobject, 0);
420 P11Attribute* attrStartDate = new P11AttrStartDate(osobject,0);
421 P11Attribute* attrEndDate = new P11AttrEndDate(osobject,0);
422 // TODO: CKA_PUBLIC_KEY_INFO is accepted, but we do not calculate it.
423 P11Attribute* attrPublicKeyInfo = new P11AttrPublicKeyInfo(osobject,0);
424
425 // Initialize the attributes
426 if
427 (
428 !attrCertificateType->init() ||
429 !attrTrusted->init() ||
430 !attrCertificateCategory->init() ||
431 !attrCheckValue->init() ||
432 !attrStartDate->init() ||
433 !attrEndDate->init() ||
434 !attrPublicKeyInfo->init()
435 )
436 {
437 ERROR_MSG("Could not initialize the attribute");
438 delete attrCertificateType;
439 delete attrTrusted;
440 delete attrCertificateCategory;
441 delete attrCheckValue;
442 delete attrStartDate;
443 delete attrEndDate;
444 delete attrPublicKeyInfo;
445 return false;
446 }
447
448 // Add them to the map
449 attributes[attrCertificateType->getType()] = attrCertificateType;
450 attributes[attrTrusted->getType()] = attrTrusted;
451 attributes[attrCertificateCategory->getType()] = attrCertificateCategory;
452 attributes[attrCheckValue->getType()] = attrCheckValue;
453 attributes[attrStartDate->getType()] = attrStartDate;
454 attributes[attrEndDate->getType()] = attrEndDate;
455 attributes[attrPublicKeyInfo->getType()] = attrPublicKeyInfo;
456
457 initialized = true;
458 return true;
459 }
460
461 // Constructor
P11X509CertificateObj()462 P11X509CertificateObj::P11X509CertificateObj()
463 {
464 initialized = false;
465 }
466
467 // Add attributes
init(OSObject * inobject)468 bool P11X509CertificateObj::init(OSObject *inobject)
469 {
470 if (initialized) return true;
471 if (inobject == NULL) return false;
472
473 // Set default values for attributes that will be introduced in the parent
474 if (!inobject->attributeExists(CKA_CERTIFICATE_TYPE) || inobject->getUnsignedLongValue(CKA_CERTIFICATE_TYPE, CKC_VENDOR_DEFINED) != CKC_X_509) {
475 OSAttribute setCertType((unsigned long)CKC_X_509);
476 inobject->setAttribute(CKA_CERTIFICATE_TYPE, setCertType);
477 }
478
479 // Create parent
480 if (!P11CertificateObj::init(inobject)) return false;
481
482 // Create attributes
483 P11Attribute* attrSubject = new P11AttrSubject(osobject,P11Attribute::ck1);
484 P11Attribute* attrID = new P11AttrID(osobject);
485 P11Attribute* attrIssuer = new P11AttrIssuer(osobject);
486 P11Attribute* attrSerialNumber = new P11AttrSerialNumber(osobject);
487 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck14);
488 P11Attribute* attrURL = new P11AttrURL(osobject);
489 P11Attribute* attrHashOfSubjectPublicKey = new P11AttrHashOfSubjectPublicKey(osobject);
490 P11Attribute* attrHashOfIssuerPublicKey = new P11AttrHashOfIssuerPublicKey(osobject);
491 P11Attribute* attrJavaMidpSecurityDomain = new P11AttrJavaMidpSecurityDomain(osobject);
492 P11Attribute* attrNameHashAlgorithm = new P11AttrNameHashAlgorithm(osobject);
493
494 // Initialize the attributes
495 if
496 (
497 !attrSubject->init() ||
498 !attrID->init() ||
499 !attrIssuer->init() ||
500 !attrSerialNumber->init() ||
501 !attrValue->init() ||
502 !attrURL->init() ||
503 !attrHashOfSubjectPublicKey->init() ||
504 !attrHashOfIssuerPublicKey->init() ||
505 !attrJavaMidpSecurityDomain->init() ||
506 !attrNameHashAlgorithm->init()
507 )
508 {
509 ERROR_MSG("Could not initialize the attribute");
510 delete attrSubject;
511 delete attrID;
512 delete attrIssuer;
513 delete attrSerialNumber;
514 delete attrValue;
515 delete attrURL;
516 delete attrHashOfSubjectPublicKey;
517 delete attrHashOfIssuerPublicKey;
518 delete attrJavaMidpSecurityDomain;
519 delete attrNameHashAlgorithm;
520 return false;
521 }
522
523 // Add them to the map
524 attributes[attrSubject->getType()] = attrSubject;
525 attributes[attrID->getType()] = attrID;
526 attributes[attrIssuer->getType()] = attrIssuer;
527 attributes[attrSerialNumber->getType()] = attrSerialNumber;
528 attributes[attrValue->getType()] = attrValue;
529 attributes[attrURL->getType()] = attrURL;
530 attributes[attrHashOfSubjectPublicKey->getType()] = attrHashOfSubjectPublicKey;
531 attributes[attrHashOfIssuerPublicKey->getType()] = attrHashOfIssuerPublicKey;
532 attributes[attrJavaMidpSecurityDomain->getType()] = attrJavaMidpSecurityDomain;
533 attributes[attrNameHashAlgorithm->getType()] = attrNameHashAlgorithm;
534
535 return true;
536 }
537
538 // Constructor
P11OpenPGPPublicKeyObj()539 P11OpenPGPPublicKeyObj::P11OpenPGPPublicKeyObj()
540 {
541 initialized = false;
542 }
543
544 // Add attributes
init(OSObject * inobject)545 bool P11OpenPGPPublicKeyObj::init(OSObject *inobject)
546 {
547 if (initialized) return true;
548 if (inobject == NULL) return false;
549
550 // Set default values for attributes that will be introduced in the parent
551 if (!inobject->attributeExists(CKA_CERTIFICATE_TYPE) || inobject->getUnsignedLongValue(CKA_CERTIFICATE_TYPE, CKC_VENDOR_DEFINED) != CKC_OPENPGP) {
552 OSAttribute setCertType((unsigned long)CKC_OPENPGP);
553 inobject->setAttribute(CKA_CERTIFICATE_TYPE, setCertType);
554 }
555
556 // Create parent
557 if (!P11CertificateObj::init(inobject)) return false;
558
559 // Create attributes
560 P11Attribute* attrSubject = new P11AttrSubject(osobject,P11Attribute::ck1);
561 P11Attribute* attrID = new P11AttrID(osobject);
562 P11Attribute* attrIssuer = new P11AttrIssuer(osobject);
563 P11Attribute* attrSerialNumber = new P11AttrSerialNumber(osobject);
564 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck14);
565 P11Attribute* attrURL = new P11AttrURL(osobject);
566
567 // Initialize the attributes
568 if
569 (
570 !attrSubject->init() ||
571 !attrID->init() ||
572 !attrIssuer->init() ||
573 !attrSerialNumber->init() ||
574 !attrValue->init() ||
575 !attrURL->init()
576 )
577 {
578 ERROR_MSG("Could not initialize the attribute");
579 delete attrSubject;
580 delete attrID;
581 delete attrIssuer;
582 delete attrSerialNumber;
583 delete attrValue;
584 delete attrURL;
585 return false;
586 }
587
588 // Add them to the map
589 attributes[attrSubject->getType()] = attrSubject;
590 attributes[attrID->getType()] = attrID;
591 attributes[attrIssuer->getType()] = attrIssuer;
592 attributes[attrSerialNumber->getType()] = attrSerialNumber;
593 attributes[attrValue->getType()] = attrValue;
594 attributes[attrURL->getType()] = attrURL;
595
596 return true;
597 }
598
599 // Constructor
P11KeyObj()600 P11KeyObj::P11KeyObj()
601 {
602 initialized = false;
603 }
604
605 // Add attributes
init(OSObject * inobject)606 bool P11KeyObj::init(OSObject *inobject)
607 {
608 if (initialized) return true;
609 if (inobject == NULL) return false;
610
611 // Create parent
612 if (!P11Object::init(inobject)) return false;
613
614 // Create attributes
615 P11Attribute* attrKeyType = new P11AttrKeyType(osobject,P11Attribute::ck5);
616 P11Attribute* attrID = new P11AttrID(osobject);
617 P11Attribute* attrStartDate = new P11AttrStartDate(osobject,P11Attribute::ck8);
618 P11Attribute* attrEndDate = new P11AttrEndDate(osobject,P11Attribute::ck8);
619 P11Attribute* attrDerive = new P11AttrDerive(osobject);
620 P11Attribute* attrLocal = new P11AttrLocal(osobject,P11Attribute::ck6);
621 P11Attribute* attrKeyGenMechanism = new P11AttrKeyGenMechanism(osobject);
622 P11Attribute* attrAllowedMechanisms = new P11AttrAllowedMechanisms(osobject);
623
624 // Initialize the attributes
625 if
626 (
627 !attrKeyType->init() ||
628 !attrID->init() ||
629 !attrStartDate->init() ||
630 !attrEndDate->init() ||
631 !attrDerive->init() ||
632 !attrLocal->init() ||
633 !attrKeyGenMechanism->init() ||
634 !attrAllowedMechanisms->init()
635 )
636 {
637 ERROR_MSG("Could not initialize the attribute");
638 delete attrKeyType;
639 delete attrID;
640 delete attrStartDate;
641 delete attrEndDate;
642 delete attrDerive;
643 delete attrLocal;
644 delete attrKeyGenMechanism;
645 delete attrAllowedMechanisms;
646 return false;
647 }
648
649 // Add them to the map
650 attributes[attrKeyType->getType()] = attrKeyType;
651 attributes[attrID->getType()] = attrID;
652 attributes[attrStartDate->getType()] = attrStartDate;
653 attributes[attrEndDate->getType()] = attrEndDate;
654 attributes[attrDerive->getType()] = attrDerive;
655 attributes[attrLocal->getType()] = attrLocal;
656 attributes[attrKeyGenMechanism->getType()] = attrKeyGenMechanism;
657 attributes[attrAllowedMechanisms->getType()] = attrAllowedMechanisms;
658
659 initialized = true;
660 return true;
661 }
662
663 // Constructor
P11PublicKeyObj()664 P11PublicKeyObj::P11PublicKeyObj()
665 {
666 initialized = false;
667 }
668
669 // Add attributes
init(OSObject * inobject)670 bool P11PublicKeyObj::init(OSObject *inobject)
671 {
672 if (initialized) return true;
673 if (inobject == NULL) return false;
674
675 // Set default values for attributes that will be introduced in the parent
676 if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_PUBLIC_KEY) {
677 OSAttribute setClass((unsigned long)CKO_PUBLIC_KEY);
678 inobject->setAttribute(CKA_CLASS, setClass);
679 }
680 // Make public keys public
681 if (!inobject->attributeExists(CKA_PRIVATE)) {
682 OSAttribute setPrivate(false);
683 inobject->setAttribute(CKA_PRIVATE, setPrivate);
684 }
685
686 // Create parent
687 if (!P11KeyObj::init(inobject)) return false;
688
689 if (initialized) return true;
690
691 // Create attributes
692 P11Attribute* attrSubject = new P11AttrSubject(osobject,P11Attribute::ck8);
693 P11Attribute* attrEncrypt = new P11AttrEncrypt(osobject);
694 P11Attribute* attrVerify = new P11AttrVerify(osobject);
695 P11Attribute* attrVerifyRecover = new P11AttrVerifyRecover(osobject);
696 P11Attribute* attrWrap = new P11AttrWrap(osobject);
697 P11Attribute* attrTrusted = new P11AttrTrusted(osobject);
698 P11Attribute* attrWrapTemplate = new P11AttrWrapTemplate(osobject);
699 // TODO: CKA_PUBLIC_KEY_INFO is accepted, but we do not calculate it
700 P11Attribute* attrPublicKeyInfo = new P11AttrPublicKeyInfo(osobject,0);
701
702 // Initialize the attributes
703 if
704 (
705 !attrSubject->init() ||
706 !attrEncrypt->init() ||
707 !attrVerify->init() ||
708 !attrVerifyRecover->init() ||
709 !attrWrap->init() ||
710 !attrTrusted->init() ||
711 !attrWrapTemplate->init() ||
712 !attrPublicKeyInfo->init()
713 )
714 {
715 ERROR_MSG("Could not initialize the attribute");
716 delete attrSubject;
717 delete attrEncrypt;
718 delete attrVerify;
719 delete attrVerifyRecover;
720 delete attrWrap;
721 delete attrTrusted;
722 delete attrWrapTemplate;
723 delete attrPublicKeyInfo;
724 return false;
725 }
726
727 // Add them to the map
728 attributes[attrSubject->getType()] = attrSubject;
729 attributes[attrEncrypt->getType()] = attrEncrypt;
730 attributes[attrVerify->getType()] = attrVerify;
731 attributes[attrVerifyRecover->getType()] = attrVerifyRecover;
732 attributes[attrWrap->getType()] = attrWrap;
733 attributes[attrTrusted->getType()] = attrTrusted;
734 attributes[attrWrapTemplate->getType()] = attrWrapTemplate;
735 attributes[attrPublicKeyInfo->getType()] = attrPublicKeyInfo;
736
737 initialized = true;
738 return true;
739 }
740
741 // Constructor
P11RSAPublicKeyObj()742 P11RSAPublicKeyObj::P11RSAPublicKeyObj()
743 {
744 initialized = false;
745 }
746
747 // Add attributes
init(OSObject * inobject)748 bool P11RSAPublicKeyObj::init(OSObject *inobject)
749 {
750 if (initialized) return true;
751 if (inobject == NULL) return false;
752
753 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_RSA) {
754 OSAttribute setKeyType((unsigned long)CKK_RSA);
755 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
756 }
757
758 // Create parent
759 if (!P11PublicKeyObj::init(inobject)) return false;
760
761 // Create attributes
762 P11Attribute* attrModulus = new P11AttrModulus(osobject);
763 P11Attribute* attrModulusBits = new P11AttrModulusBits(osobject);
764 P11Attribute* attrPublicExponent = new P11AttrPublicExponent(osobject,P11Attribute::ck1);
765
766 // Initialize the attributes
767 if
768 (
769 !attrModulus->init() ||
770 !attrModulusBits->init() ||
771 !attrPublicExponent->init()
772 )
773 {
774 ERROR_MSG("Could not initialize the attribute");
775 delete attrModulus;
776 delete attrModulusBits;
777 delete attrPublicExponent;
778 return false;
779 }
780
781 // Add them to the map
782 attributes[attrModulus->getType()] = attrModulus;
783 attributes[attrModulusBits->getType()] = attrModulusBits;
784 attributes[attrPublicExponent->getType()] = attrPublicExponent;
785
786 initialized = true;
787 return true;
788 }
789
790 // Constructor
P11DSAPublicKeyObj()791 P11DSAPublicKeyObj::P11DSAPublicKeyObj()
792 {
793 initialized = false;
794 }
795
796 // Add attributes
init(OSObject * inobject)797 bool P11DSAPublicKeyObj::init(OSObject *inobject)
798 {
799 if (initialized) return true;
800 if (inobject == NULL) return false;
801
802 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DSA) {
803 OSAttribute setKeyType((unsigned long)CKK_DSA);
804 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
805 }
806
807 // Create parent
808 if (!P11PublicKeyObj::init(inobject)) return false;
809
810 // Create attributes
811 P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck3);
812 P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject,P11Attribute::ck3);
813 P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck3);
814 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4);
815
816 // Initialize the attributes
817 if
818 (
819 !attrPrime->init() ||
820 !attrSubPrime->init() ||
821 !attrBase->init() ||
822 !attrValue->init()
823 )
824 {
825 ERROR_MSG("Could not initialize the attribute");
826 delete attrPrime;
827 delete attrSubPrime;
828 delete attrBase;
829 delete attrValue;
830 return false;
831 }
832
833 // Add them to the map
834 attributes[attrPrime->getType()] = attrPrime;
835 attributes[attrSubPrime->getType()] = attrSubPrime;
836 attributes[attrBase->getType()] = attrBase;
837 attributes[attrValue->getType()] = attrValue;
838
839 initialized = true;
840 return true;
841 }
842
843 // Constructor
P11ECPublicKeyObj()844 P11ECPublicKeyObj::P11ECPublicKeyObj()
845 {
846 initialized = false;
847 }
848
849 // Add attributes
init(OSObject * inobject)850 bool P11ECPublicKeyObj::init(OSObject *inobject)
851 {
852 if (initialized) return true;
853 if (inobject == NULL) return false;
854
855 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_EC) {
856 OSAttribute setKeyType((unsigned long)CKK_EC);
857 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
858 }
859
860 // Create parent
861 if (!P11PublicKeyObj::init(inobject)) return false;
862
863 // Create attributes
864 P11Attribute* attrEcParams = new P11AttrEcParams(osobject,P11Attribute::ck3);
865 P11Attribute* attrEcPoint = new P11AttrEcPoint(osobject);
866
867 // Initialize the attributes
868 if
869 (
870 !attrEcParams->init() ||
871 !attrEcPoint->init()
872 )
873 {
874 ERROR_MSG("Could not initialize the attribute");
875 delete attrEcParams;
876 delete attrEcPoint;
877 return false;
878 }
879
880 // Add them to the map
881 attributes[attrEcParams->getType()] = attrEcParams;
882 attributes[attrEcPoint->getType()] = attrEcPoint;
883
884 initialized = true;
885 return true;
886 }
887
888 // Constructor
P11EDPublicKeyObj()889 P11EDPublicKeyObj::P11EDPublicKeyObj()
890 {
891 initialized = false;
892 }
893
894 // Add attributes
init(OSObject * inobject)895 bool P11EDPublicKeyObj::init(OSObject *inobject)
896 {
897 if (initialized) return true;
898 if (inobject == NULL) return false;
899
900 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_EC_EDWARDS) {
901 OSAttribute setKeyType((unsigned long)CKK_EC_EDWARDS);
902 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
903 }
904
905 // Create parent
906 if (!P11PublicKeyObj::init(inobject)) return false;
907
908 // Create attributes
909 P11Attribute* attrEcParams = new P11AttrEcParams(osobject,P11Attribute::ck3);
910 P11Attribute* attrEcPoint = new P11AttrEcPoint(osobject);
911
912 // Initialize the attributes
913 if
914 (
915 !attrEcParams->init() ||
916 !attrEcPoint->init()
917 )
918 {
919 ERROR_MSG("Could not initialize the attribute");
920 delete attrEcParams;
921 delete attrEcPoint;
922 return false;
923 }
924
925 // Add them to the map
926 attributes[attrEcParams->getType()] = attrEcParams;
927 attributes[attrEcPoint->getType()] = attrEcPoint;
928
929 initialized = true;
930 return true;
931 }
932
933 // Constructor
P11DHPublicKeyObj()934 P11DHPublicKeyObj::P11DHPublicKeyObj()
935 {
936 initialized = false;
937 }
938
939 // Add attributes
init(OSObject * inobject)940 bool P11DHPublicKeyObj::init(OSObject *inobject)
941 {
942 if (initialized) return true;
943 if (inobject == NULL) return false;
944
945 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DH) {
946 OSAttribute setKeyType((unsigned long)CKK_DH);
947 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
948 }
949
950 // Create parent
951 if (!P11PublicKeyObj::init(inobject)) return false;
952
953 // Create attributes
954 P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck3);
955 P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck3);
956 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4);
957
958 // Initialize the attributes
959 if
960 (
961 !attrPrime->init() ||
962 !attrBase->init() ||
963 !attrValue->init()
964 )
965 {
966 ERROR_MSG("Could not initialize the attribute");
967 delete attrPrime;
968 delete attrBase;
969 delete attrValue;
970 return false;
971 }
972
973 // Add them to the map
974 attributes[attrPrime->getType()] = attrPrime;
975 attributes[attrBase->getType()] = attrBase;
976 attributes[attrValue->getType()] = attrValue;
977
978 initialized = true;
979 return true;
980 }
981
982 // Constructor
P11GOSTPublicKeyObj()983 P11GOSTPublicKeyObj::P11GOSTPublicKeyObj()
984 {
985 initialized = false;
986 }
987
988 // Add attributes
init(OSObject * inobject)989 bool P11GOSTPublicKeyObj::init(OSObject *inobject)
990 {
991 if (initialized) return true;
992 if (inobject == NULL) return false;
993
994 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_GOSTR3410) {
995 OSAttribute setKeyType((unsigned long)CKK_GOSTR3410);
996 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
997 }
998
999 // Create parent
1000 if (!P11PublicKeyObj::init(inobject)) return false;
1001
1002 // Create attributes
1003 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4);
1004 P11Attribute* attrGostR3410Params = new P11AttrGostR3410Params(osobject,P11Attribute::ck3);
1005 P11Attribute* attrGostR3411Params = new P11AttrGostR3411Params(osobject,P11Attribute::ck3);
1006 P11Attribute* attrGost28147Params = new P11AttrGost28147Params(osobject,P11Attribute::ck8);
1007
1008 // Initialize the attributes
1009 if
1010 (
1011 !attrValue->init() ||
1012 !attrGostR3410Params->init() ||
1013 !attrGostR3411Params->init() ||
1014 !attrGost28147Params->init()
1015 )
1016 {
1017 ERROR_MSG("Could not initialize the attribute");
1018 delete attrValue;
1019 delete attrGostR3410Params;
1020 delete attrGostR3411Params;
1021 delete attrGost28147Params;
1022 return false;
1023 }
1024
1025 // Add them to the map
1026 attributes[attrValue->getType()] = attrValue;
1027 attributes[attrGostR3410Params->getType()] = attrGostR3410Params;
1028 attributes[attrGostR3411Params->getType()] = attrGostR3411Params;
1029 attributes[attrGost28147Params->getType()] = attrGost28147Params;
1030
1031 initialized = true;
1032 return true;
1033 }
1034
1035 //constructor
P11PrivateKeyObj()1036 P11PrivateKeyObj::P11PrivateKeyObj()
1037 {
1038 initialized = false;
1039 }
1040
1041 // Add attributes
init(OSObject * inobject)1042 bool P11PrivateKeyObj::init(OSObject *inobject)
1043 {
1044 if (initialized) return true;
1045 if (inobject == NULL) return false;
1046
1047 if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_PRIVATE_KEY) {
1048 OSAttribute setClass((unsigned long)CKO_PRIVATE_KEY);
1049 inobject->setAttribute(CKA_CLASS, setClass);
1050 }
1051
1052 // Create parent
1053 if (!P11KeyObj::init(inobject)) return false;
1054
1055 // Create attributes
1056 P11Attribute* attrSubject = new P11AttrSubject(osobject,P11Attribute::ck8);
1057 P11Attribute* attrSensitive = new P11AttrSensitive(osobject);
1058 P11Attribute* attrDecrypt = new P11AttrDecrypt(osobject);
1059 P11Attribute* attrSign = new P11AttrSign(osobject);
1060 P11Attribute* attrSignRecover = new P11AttrSignRecover(osobject);
1061 P11Attribute* attrUnwrap = new P11AttrUnwrap(osobject);
1062 P11Attribute* attrExtractable = new P11AttrExtractable(osobject);
1063 P11Attribute* attrAlwaysSensitive = new P11AttrAlwaysSensitive(osobject);
1064 P11Attribute* attrNeverExtractable = new P11AttrNeverExtractable(osobject);
1065 P11Attribute* attrWrapWithTrusted = new P11AttrWrapWithTrusted(osobject);
1066 P11Attribute* attrUnwrapTemplate = new P11AttrUnwrapTemplate(osobject);
1067 // TODO: CKA_ALWAYS_AUTHENTICATE is accepted, but we do not use it
1068 P11Attribute* attrAlwaysAuthenticate = new P11AttrAlwaysAuthenticate(osobject);
1069 // TODO: CKA_PUBLIC_KEY_INFO is accepted, but we do not calculate it
1070 P11Attribute* attrPublicKeyInfo = new P11AttrPublicKeyInfo(osobject,P11Attribute::ck8);
1071
1072 // Initialize the attributes
1073 if
1074 (
1075 !attrSubject->init() ||
1076 !attrSensitive->init() ||
1077 !attrDecrypt->init() ||
1078 !attrSign->init() ||
1079 !attrSignRecover->init() ||
1080 !attrUnwrap->init() ||
1081 !attrExtractable->init() ||
1082 !attrAlwaysSensitive->init() ||
1083 !attrNeverExtractable->init() ||
1084 !attrWrapWithTrusted->init() ||
1085 !attrUnwrapTemplate->init() ||
1086 !attrAlwaysAuthenticate->init() ||
1087 !attrPublicKeyInfo->init()
1088 )
1089 {
1090 ERROR_MSG("Could not initialize the attribute");
1091 delete attrSubject;
1092 delete attrSensitive;
1093 delete attrDecrypt;
1094 delete attrSign;
1095 delete attrSignRecover;
1096 delete attrUnwrap;
1097 delete attrExtractable;
1098 delete attrAlwaysSensitive;
1099 delete attrNeverExtractable;
1100 delete attrWrapWithTrusted;
1101 delete attrUnwrapTemplate;
1102 delete attrAlwaysAuthenticate;
1103 delete attrPublicKeyInfo;
1104 return false;
1105 }
1106
1107 // Add them to the map
1108 attributes[attrSubject->getType()] = attrSubject;
1109 attributes[attrSensitive->getType()] = attrSensitive;
1110 attributes[attrDecrypt->getType()] = attrDecrypt;
1111 attributes[attrSign->getType()] = attrSign;
1112 attributes[attrSignRecover->getType()] = attrSignRecover;
1113 attributes[attrUnwrap->getType()] = attrUnwrap;
1114 attributes[attrExtractable->getType()] = attrExtractable;
1115 attributes[attrAlwaysSensitive->getType()] = attrAlwaysSensitive;
1116 attributes[attrNeverExtractable->getType()] = attrNeverExtractable;
1117 attributes[attrWrapWithTrusted->getType()] = attrWrapWithTrusted;
1118 attributes[attrUnwrapTemplate->getType()] = attrUnwrapTemplate;
1119 attributes[attrAlwaysAuthenticate->getType()] = attrAlwaysAuthenticate;
1120 attributes[attrPublicKeyInfo->getType()] = attrPublicKeyInfo;
1121
1122 initialized = true;
1123 return true;
1124 }
1125
1126 // Constructor
P11RSAPrivateKeyObj()1127 P11RSAPrivateKeyObj::P11RSAPrivateKeyObj()
1128 {
1129 initialized = false;
1130 }
1131
1132 // Add attributes
init(OSObject * inobject)1133 bool P11RSAPrivateKeyObj::init(OSObject *inobject)
1134 {
1135 if (initialized) return true;
1136 if (inobject == NULL) return false;
1137
1138 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_RSA) {
1139 OSAttribute setKeyType((unsigned long)CKK_RSA);
1140 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1141 }
1142
1143 // Create parent
1144 if (!P11PrivateKeyObj::init(inobject)) return false;
1145
1146 // Create attributes
1147 P11Attribute* attrModulus = new P11AttrModulus(osobject,P11Attribute::ck6);
1148 P11Attribute* attrPublicExponent = new P11AttrPublicExponent(osobject,P11Attribute::ck4|P11Attribute::ck6);
1149 P11Attribute* attrPrivateExponent = new P11AttrPrivateExponent(osobject);
1150 P11Attribute* attrPrime1 = new P11AttrPrime1(osobject);
1151 P11Attribute* attrPrime2 = new P11AttrPrime2(osobject);
1152 P11Attribute* attrExponent1 = new P11AttrExponent1(osobject);
1153 P11Attribute* attrExponent2 = new P11AttrExponent2(osobject);
1154 P11Attribute* attrCoefficient = new P11AttrCoefficient(osobject);
1155
1156 // Initialize the attributes
1157 if
1158 (
1159 !attrModulus->init() ||
1160 !attrPublicExponent->init() ||
1161 !attrPrivateExponent->init() ||
1162 !attrPrime1->init() ||
1163 !attrPrime2->init() ||
1164 !attrExponent1->init() ||
1165 !attrExponent2->init() ||
1166 !attrCoefficient->init()
1167 )
1168 {
1169 ERROR_MSG("Could not initialize the attribute");
1170 delete attrModulus;
1171 delete attrPublicExponent;
1172 delete attrPrivateExponent;
1173 delete attrPrime1;
1174 delete attrPrime2;
1175 delete attrExponent1;
1176 delete attrExponent2;
1177 delete attrCoefficient;
1178 return false;
1179 }
1180
1181 // Add them to the map
1182 attributes[attrModulus->getType()] = attrModulus;
1183 attributes[attrPublicExponent->getType()] = attrPublicExponent;
1184 attributes[attrPrivateExponent->getType()] = attrPrivateExponent;
1185 attributes[attrPrime1->getType()] = attrPrime1;
1186 attributes[attrPrime2->getType()] = attrPrime2;
1187 attributes[attrExponent1->getType()] = attrExponent1;
1188 attributes[attrExponent2->getType()] = attrExponent2;
1189 attributes[attrCoefficient->getType()] = attrCoefficient;
1190
1191 initialized = true;
1192 return true;
1193 }
1194
1195 // Constructor
P11DSAPrivateKeyObj()1196 P11DSAPrivateKeyObj::P11DSAPrivateKeyObj()
1197 {
1198 initialized = false;
1199 }
1200
1201 // Add attributes
init(OSObject * inobject)1202 bool P11DSAPrivateKeyObj::init(OSObject *inobject)
1203 {
1204 if (initialized) return true;
1205 if (inobject == NULL) return false;
1206
1207 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DSA) {
1208 OSAttribute setKeyType((unsigned long)CKK_DSA);
1209 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1210 }
1211
1212 // Create parent
1213 if (!P11PrivateKeyObj::init(inobject)) return false;
1214
1215 // Create attributes
1216 P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4|P11Attribute::ck6);
1217 P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject,P11Attribute::ck4|P11Attribute::ck6);
1218 P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4|P11Attribute::ck6);
1219 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1220
1221 // Initialize the attributes
1222 if
1223 (
1224 !attrPrime->init() ||
1225 !attrSubPrime->init() ||
1226 !attrBase->init() ||
1227 !attrValue->init()
1228 )
1229 {
1230 ERROR_MSG("Could not initialize the attribute");
1231 delete attrPrime;
1232 delete attrSubPrime;
1233 delete attrBase;
1234 delete attrValue;
1235 return false;
1236 }
1237
1238 // Add them to the map
1239 attributes[attrPrime->getType()] = attrPrime;
1240 attributes[attrSubPrime->getType()] = attrSubPrime;
1241 attributes[attrBase->getType()] = attrBase;
1242 attributes[attrValue->getType()] = attrValue;
1243
1244 initialized = true;
1245 return true;
1246 }
1247
1248 // Constructor
P11ECPrivateKeyObj()1249 P11ECPrivateKeyObj::P11ECPrivateKeyObj()
1250 {
1251 initialized = false;
1252 }
1253
1254 // Add attributes
init(OSObject * inobject)1255 bool P11ECPrivateKeyObj::init(OSObject *inobject)
1256 {
1257 if (initialized) return true;
1258 if (inobject == NULL) return false;
1259
1260 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_EC) {
1261 OSAttribute setKeyType((unsigned long)CKK_EC);
1262 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1263 }
1264
1265 // Create parent
1266 if (!P11PrivateKeyObj::init(inobject)) return false;
1267
1268 // Create attributes
1269 P11Attribute* attrEcParams = new P11AttrEcParams(osobject,P11Attribute::ck4|P11Attribute::ck6);
1270 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1271
1272 // Initialize the attributes
1273 if
1274 (
1275 !attrEcParams->init() ||
1276 !attrValue->init()
1277 )
1278 {
1279 ERROR_MSG("Could not initialize the attribute");
1280 delete attrEcParams;
1281 delete attrValue;
1282 return false;
1283 }
1284
1285 // Add them to the map
1286 attributes[attrEcParams->getType()] = attrEcParams;
1287 attributes[attrValue->getType()] = attrValue;
1288
1289 initialized = true;
1290 return true;
1291 }
1292
1293 // Constructor
P11EDPrivateKeyObj()1294 P11EDPrivateKeyObj::P11EDPrivateKeyObj()
1295 {
1296 initialized = false;
1297 }
1298
1299 // Add attributes
init(OSObject * inobject)1300 bool P11EDPrivateKeyObj::init(OSObject *inobject)
1301 {
1302 if (initialized) return true;
1303 if (inobject == NULL) return false;
1304
1305 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_EC_EDWARDS) {
1306 OSAttribute setKeyType((unsigned long)CKK_EC_EDWARDS);
1307 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1308 }
1309
1310 // Create parent
1311 if (!P11PrivateKeyObj::init(inobject)) return false;
1312
1313 // Create attributes
1314 P11Attribute* attrEcParams = new P11AttrEcParams(osobject,P11Attribute::ck4|P11Attribute::ck6);
1315 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1316
1317 // Initialize the attributes
1318 if
1319 (
1320 !attrEcParams->init() ||
1321 !attrValue->init()
1322 )
1323 {
1324 ERROR_MSG("Could not initialize the attribute");
1325 delete attrEcParams;
1326 delete attrValue;
1327 return false;
1328 }
1329
1330 // Add them to the map
1331 attributes[attrEcParams->getType()] = attrEcParams;
1332 attributes[attrValue->getType()] = attrValue;
1333
1334 initialized = true;
1335 return true;
1336 }
1337
1338 // Constructor
P11DHPrivateKeyObj()1339 P11DHPrivateKeyObj::P11DHPrivateKeyObj()
1340 {
1341 initialized = false;
1342 }
1343
1344 // Add attributes
init(OSObject * inobject)1345 bool P11DHPrivateKeyObj::init(OSObject *inobject)
1346 {
1347 if (initialized) return true;
1348 if (inobject == NULL) return false;
1349
1350 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DH) {
1351 OSAttribute setKeyType((unsigned long)CKK_DH);
1352 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1353 }
1354
1355 // Create parent
1356 if (!P11PrivateKeyObj::init(inobject)) return false;
1357
1358 // Create attributes
1359 P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4|P11Attribute::ck6);
1360 P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4|P11Attribute::ck6);
1361 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1362 P11Attribute* attrValueBits = new P11AttrValueBits(osobject);
1363
1364 // Initialize the attributes
1365 if
1366 (
1367 !attrPrime->init() ||
1368 !attrBase->init() ||
1369 !attrValue->init() ||
1370 !attrValueBits->init()
1371 )
1372 {
1373 ERROR_MSG("Could not initialize the attribute");
1374 delete attrPrime;
1375 delete attrBase;
1376 delete attrValue;
1377 delete attrValueBits;
1378 return false;
1379 }
1380
1381 // Add them to the map
1382 attributes[attrPrime->getType()] = attrPrime;
1383 attributes[attrBase->getType()] = attrBase;
1384 attributes[attrValue->getType()] = attrValue;
1385 attributes[attrValueBits->getType()] = attrValueBits;
1386
1387 initialized = true;
1388 return true;
1389 }
1390
1391 // Constructor
P11GOSTPrivateKeyObj()1392 P11GOSTPrivateKeyObj::P11GOSTPrivateKeyObj()
1393 {
1394 initialized = false;
1395 }
1396
1397 // Add attributes
init(OSObject * inobject)1398 bool P11GOSTPrivateKeyObj::init(OSObject *inobject)
1399 {
1400 if (initialized) return true;
1401 if (inobject == NULL) return false;
1402
1403 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_GOSTR3410) {
1404 OSAttribute setKeyType((unsigned long)CKK_GOSTR3410);
1405 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1406 }
1407
1408 // Create parent
1409 if (!P11PrivateKeyObj::init(inobject)) return false;
1410
1411 // Create attributes
1412 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1413 P11Attribute* attrGostR3410Params = new P11AttrGostR3410Params(osobject,P11Attribute::ck4|P11Attribute::ck6);
1414 P11Attribute* attrGostR3411Params = new P11AttrGostR3411Params(osobject,P11Attribute::ck4|P11Attribute::ck6);
1415 P11Attribute* attrGost28147Params = new P11AttrGost28147Params(osobject,P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck8);
1416
1417 // Initialize the attributes
1418 if
1419 (
1420 !attrValue->init() ||
1421 !attrGostR3410Params->init() ||
1422 !attrGostR3411Params->init() ||
1423 !attrGost28147Params->init()
1424 )
1425 {
1426 ERROR_MSG("Could not initialize the attribute");
1427 delete attrValue;
1428 delete attrGostR3410Params;
1429 delete attrGostR3411Params;
1430 delete attrGost28147Params;
1431 return false;
1432 }
1433
1434 // Add them to the map
1435 attributes[attrValue->getType()] = attrValue;
1436 attributes[attrGostR3410Params->getType()] = attrGostR3410Params;
1437 attributes[attrGostR3411Params->getType()] = attrGostR3411Params;
1438 attributes[attrGost28147Params->getType()] = attrGost28147Params;
1439
1440 initialized = true;
1441 return true;
1442 }
1443
1444 // Constructor
P11SecretKeyObj()1445 P11SecretKeyObj::P11SecretKeyObj()
1446 {
1447 initialized = false;
1448 }
1449
1450 // Add attributes
init(OSObject * inobject)1451 bool P11SecretKeyObj::init(OSObject *inobject)
1452 {
1453 if (initialized) return true;
1454 if (inobject == NULL) return false;
1455
1456 if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_SECRET_KEY) {
1457 OSAttribute setClass((unsigned long)CKO_SECRET_KEY);
1458 inobject->setAttribute(CKA_CLASS, setClass);
1459 }
1460
1461 // Create parent
1462 if (!P11KeyObj::init(inobject)) return false;
1463
1464 // Create attributes
1465 P11Attribute* attrSensitive = new P11AttrSensitive(osobject);
1466 P11Attribute* attrEncrypt = new P11AttrEncrypt(osobject);
1467 P11Attribute* attrDecrypt = new P11AttrDecrypt(osobject);
1468 P11Attribute* attrSign = new P11AttrSign(osobject);
1469 P11Attribute* attrVerify = new P11AttrVerify(osobject);
1470 P11Attribute* attrWrap = new P11AttrWrap(osobject);
1471 P11Attribute* attrUnwrap = new P11AttrUnwrap(osobject);
1472 P11Attribute* attrExtractable = new P11AttrExtractable(osobject);
1473 P11Attribute* attrAlwaysSensitive = new P11AttrAlwaysSensitive(osobject);
1474 P11Attribute* attrNeverExtractable = new P11AttrNeverExtractable(osobject);
1475 P11Attribute* attrCheckValue = new P11AttrCheckValue(osobject, P11Attribute::ck8);
1476 P11Attribute* attrWrapWithTrusted = new P11AttrWrapWithTrusted(osobject);
1477 P11Attribute* attrTrusted = new P11AttrTrusted(osobject);
1478 P11Attribute* attrWrapTemplate = new P11AttrWrapTemplate(osobject);
1479 P11Attribute* attrUnwrapTemplate = new P11AttrUnwrapTemplate(osobject);
1480
1481 // Initialize the attributes
1482 if
1483 (
1484 !attrSensitive->init() ||
1485 !attrEncrypt->init() ||
1486 !attrDecrypt->init() ||
1487 !attrSign->init() ||
1488 !attrVerify->init() ||
1489 !attrWrap->init() ||
1490 !attrUnwrap->init() ||
1491 !attrExtractable->init() ||
1492 !attrAlwaysSensitive->init() ||
1493 !attrNeverExtractable->init() ||
1494 !attrCheckValue->init() ||
1495 !attrWrapWithTrusted->init() ||
1496 !attrTrusted->init() ||
1497 !attrWrapTemplate->init() ||
1498 !attrUnwrapTemplate->init()
1499 )
1500 {
1501 ERROR_MSG("Could not initialize the attribute");
1502 delete attrSensitive;
1503 delete attrEncrypt;
1504 delete attrDecrypt;
1505 delete attrSign;
1506 delete attrVerify;
1507 delete attrWrap;
1508 delete attrUnwrap;
1509 delete attrExtractable;
1510 delete attrAlwaysSensitive;
1511 delete attrNeverExtractable;
1512 delete attrCheckValue;
1513 delete attrWrapWithTrusted;
1514 delete attrTrusted;
1515 delete attrWrapTemplate;
1516 delete attrUnwrapTemplate;
1517 return false;
1518 }
1519
1520 // Add them to the map
1521 attributes[attrSensitive->getType()] = attrSensitive;
1522 attributes[attrEncrypt->getType()] = attrEncrypt;
1523 attributes[attrDecrypt->getType()] = attrDecrypt;
1524 attributes[attrSign->getType()] = attrSign;
1525 attributes[attrVerify->getType()] = attrVerify;
1526 attributes[attrWrap->getType()] = attrWrap;
1527 attributes[attrUnwrap->getType()] = attrUnwrap;
1528 attributes[attrExtractable->getType()] = attrExtractable;
1529 attributes[attrAlwaysSensitive->getType()] = attrAlwaysSensitive;
1530 attributes[attrNeverExtractable->getType()] = attrNeverExtractable;
1531 attributes[attrCheckValue->getType()] = attrCheckValue;
1532 attributes[attrWrapWithTrusted->getType()] = attrWrapWithTrusted;
1533 attributes[attrTrusted->getType()] = attrTrusted;
1534 attributes[attrWrapTemplate->getType()] = attrWrapTemplate;
1535 attributes[attrUnwrapTemplate->getType()] = attrUnwrapTemplate;
1536
1537 initialized = true;
1538 return true;
1539 }
1540
1541 // Constructor
P11GenericSecretKeyObj()1542 P11GenericSecretKeyObj::P11GenericSecretKeyObj()
1543 {
1544 initialized = false;
1545 keytype = CKK_VENDOR_DEFINED;
1546 }
1547
1548 // Add attributes
init(OSObject * inobject)1549 bool P11GenericSecretKeyObj::init(OSObject *inobject)
1550 {
1551 if (initialized) return true;
1552 if (inobject == NULL) return false;
1553
1554 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != keytype) {
1555 OSAttribute setKeyType(keytype);
1556 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1557 }
1558
1559 // Create parent
1560 if (!P11SecretKeyObj::init(inobject)) return false;
1561
1562 // Create attributes
1563 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1564 P11Attribute* attrValueLen = new P11AttrValueLen(osobject);
1565
1566 // Initialize the attributes
1567 if
1568 (
1569 !attrValue->init() ||
1570 !attrValueLen->init()
1571 )
1572 {
1573 ERROR_MSG("Could not initialize the attribute");
1574 delete attrValue;
1575 delete attrValueLen;
1576 return false;
1577 }
1578
1579 // Add them to the map
1580 attributes[attrValue->getType()] = attrValue;
1581 attributes[attrValueLen->getType()] = attrValueLen;
1582
1583 initialized = true;
1584 return true;
1585 }
1586
1587 // Set Key Type
setKeyType(CK_KEY_TYPE inKeytype)1588 bool P11GenericSecretKeyObj::setKeyType(CK_KEY_TYPE inKeytype)
1589 {
1590 if (!initialized)
1591 {
1592 keytype = inKeytype;
1593 return true;
1594 }
1595 else
1596 return false;
1597 }
1598
1599 // Get Key Type
getKeyType()1600 CK_KEY_TYPE P11GenericSecretKeyObj::getKeyType()
1601 {
1602 return keytype;
1603 }
1604
1605 // Constructor
P11AESSecretKeyObj()1606 P11AESSecretKeyObj::P11AESSecretKeyObj()
1607 {
1608 initialized = false;
1609 }
1610
1611 // Add attributes
init(OSObject * inobject)1612 bool P11AESSecretKeyObj::init(OSObject *inobject)
1613 {
1614 if (initialized) return true;
1615 if (inobject == NULL) return false;
1616
1617 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_AES) {
1618 OSAttribute setKeyType((unsigned long)CKK_AES);
1619 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1620 }
1621
1622 // Create parent
1623 if (!P11SecretKeyObj::init(inobject)) return false;
1624
1625 // Create attributes
1626 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1627 P11Attribute* attrValueLen = new P11AttrValueLen(osobject,P11Attribute::ck6);
1628
1629 // Initialize the attributes
1630 if
1631 (
1632 !attrValue->init() ||
1633 !attrValueLen->init()
1634 )
1635 {
1636 ERROR_MSG("Could not initialize the attribute");
1637 delete attrValue;
1638 delete attrValueLen;
1639 return false;
1640 }
1641
1642 // Add them to the map
1643 attributes[attrValue->getType()] = attrValue;
1644 attributes[attrValueLen->getType()] = attrValueLen;
1645
1646 initialized = true;
1647 return true;
1648 }
1649
1650 // Constructor
P11DESSecretKeyObj()1651 P11DESSecretKeyObj::P11DESSecretKeyObj()
1652 {
1653 initialized = false;
1654 keytype = CKK_VENDOR_DEFINED;
1655 }
1656
1657 // Add attributes
init(OSObject * inobject)1658 bool P11DESSecretKeyObj::init(OSObject *inobject)
1659 {
1660 if (initialized) return true;
1661 if (inobject == NULL) return false;
1662
1663 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != keytype) {
1664 OSAttribute setKeyType(keytype);
1665 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1666 }
1667
1668 // Create parent
1669 if (!P11SecretKeyObj::init(inobject)) return false;
1670
1671 // Create attributes
1672 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1673
1674 // Initialize the attributes
1675 if (!attrValue->init())
1676 {
1677 ERROR_MSG("Could not initialize the attribute");
1678 delete attrValue;
1679 return false;
1680 }
1681
1682 // Add them to the map
1683 attributes[attrValue->getType()] = attrValue;
1684
1685 initialized = true;
1686 return true;
1687 }
1688
1689 // Set Key Type
setKeyType(CK_KEY_TYPE inKeytype)1690 bool P11DESSecretKeyObj::setKeyType(CK_KEY_TYPE inKeytype)
1691 {
1692 if (!initialized)
1693 {
1694 keytype = inKeytype;
1695 return true;
1696 }
1697 else
1698 return false;
1699 }
1700
1701 // Get Key Type
getKeyType()1702 CK_KEY_TYPE P11DESSecretKeyObj::getKeyType()
1703 {
1704 return keytype;
1705 }
1706
1707 // Constructor
P11GOSTSecretKeyObj()1708 P11GOSTSecretKeyObj::P11GOSTSecretKeyObj()
1709 {
1710 initialized = false;
1711 }
1712
1713 // Add attributes
init(OSObject * inobject)1714 bool P11GOSTSecretKeyObj::init(OSObject *inobject)
1715 {
1716 if (initialized) return true;
1717 if (inobject == NULL) return false;
1718
1719 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_GOST28147) {
1720 OSAttribute setKeyType((unsigned long)CKK_GOST28147);
1721 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1722 }
1723
1724 // Create parent
1725 if (!P11SecretKeyObj::init(inobject)) return false;
1726
1727 // Create attributes
1728 P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
1729 P11Attribute* attrGost28147Params = new P11AttrGost28147Params(osobject,P11Attribute::ck1|P11Attribute::ck3|P11Attribute::ck5);
1730
1731 // Initialize the attributes
1732 if
1733 (
1734 !attrValue->init() ||
1735 !attrGost28147Params->init()
1736 )
1737 {
1738 ERROR_MSG("Could not initialize the attribute");
1739 delete attrValue;
1740 delete attrGost28147Params;
1741 return false;
1742 }
1743
1744 // Add them to the map
1745 attributes[attrValue->getType()] = attrValue;
1746 attributes[attrGost28147Params->getType()] = attrGost28147Params;
1747
1748 initialized = true;
1749 return true;
1750 }
1751
1752 // Constructor
P11DomainObj()1753 P11DomainObj::P11DomainObj()
1754 {
1755 initialized = false;
1756 }
1757
1758 // Add attributes
init(OSObject * inobject)1759 bool P11DomainObj::init(OSObject *inobject)
1760 {
1761 if (initialized) return true;
1762 if (inobject == NULL) return false;
1763
1764 if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_DOMAIN_PARAMETERS) {
1765 OSAttribute setClass((unsigned long)CKO_DOMAIN_PARAMETERS);
1766 inobject->setAttribute(CKA_CLASS, setClass);
1767 }
1768
1769 // Create parent
1770 if (!P11Object::init(inobject)) return false;
1771
1772 // Create attributes
1773 P11Attribute* attrKeyType = new P11AttrKeyType(osobject);
1774 P11Attribute* attrLocal = new P11AttrLocal(osobject);
1775
1776 // Initialize the attributes
1777 if
1778 (
1779 !attrKeyType->init() ||
1780 !attrLocal->init()
1781 )
1782 {
1783 ERROR_MSG("Could not initialize the attribute");
1784 delete attrKeyType;
1785 delete attrLocal;
1786 return false;
1787 }
1788
1789 // Add them to the map
1790 attributes[attrKeyType->getType()] = attrKeyType;
1791 attributes[attrLocal->getType()] = attrLocal;
1792
1793 initialized = true;
1794 return true;
1795 }
1796
1797 // Constructor
P11DSADomainObj()1798 P11DSADomainObj::P11DSADomainObj()
1799 {
1800 initialized = false;
1801 }
1802
1803 // Add attributes
init(OSObject * inobject)1804 bool P11DSADomainObj::init(OSObject *inobject)
1805 {
1806 if (initialized) return true;
1807 if (inobject == NULL) return false;
1808
1809 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DSA) {
1810 OSAttribute setKeyType((unsigned long)CKK_DSA);
1811 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1812 }
1813
1814 // Create parent
1815 if (!P11DomainObj::init(inobject)) return false;
1816
1817 // Create attributes
1818 P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4);
1819 P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject,P11Attribute::ck4);
1820 P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4);
1821 P11Attribute* attrPrimeBits = new P11AttrPrimeBits(osobject);
1822
1823 // Initialize the attributes
1824 if
1825 (
1826 !attrPrime->init() ||
1827 !attrSubPrime->init() ||
1828 !attrBase->init() ||
1829 !attrPrimeBits->init()
1830 )
1831 {
1832 ERROR_MSG("Could not initialize the attribute");
1833 delete attrPrime;
1834 delete attrSubPrime;
1835 delete attrBase;
1836 delete attrPrimeBits;
1837 return false;
1838 }
1839
1840 // Add them to the map
1841 attributes[attrPrime->getType()] = attrPrime;
1842 attributes[attrSubPrime->getType()] = attrSubPrime;
1843 attributes[attrBase->getType()] = attrBase;
1844 attributes[attrPrimeBits->getType()] = attrPrimeBits;
1845
1846 initialized = true;
1847 return true;
1848 }
1849
1850 // Constructor
P11DHDomainObj()1851 P11DHDomainObj::P11DHDomainObj()
1852 {
1853 initialized = false;
1854 }
1855
1856 // Add attributes
init(OSObject * inobject)1857 bool P11DHDomainObj::init(OSObject *inobject)
1858 {
1859 if (initialized) return true;
1860 if (inobject == NULL) return false;
1861
1862 if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DH) {
1863 OSAttribute setKeyType((unsigned long)CKK_DH);
1864 inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
1865 }
1866
1867 // Create parent
1868 if (!P11DomainObj::init(inobject)) return false;
1869
1870 // Create attributes
1871 P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4);
1872 P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4);
1873 P11Attribute* attrPrimeBits = new P11AttrPrimeBits(osobject);
1874
1875 // Initialize the attributes
1876 if
1877 (
1878 !attrPrime->init() ||
1879 !attrBase->init() ||
1880 !attrPrimeBits->init()
1881 )
1882 {
1883 ERROR_MSG("Could not initialize the attribute");
1884 delete attrPrime;
1885 delete attrBase;
1886 delete attrPrimeBits;
1887 return false;
1888 }
1889
1890 // Add them to the map
1891 attributes[attrPrime->getType()] = attrPrime;
1892 attributes[attrBase->getType()] = attrBase;
1893 attributes[attrPrimeBits->getType()] = attrPrimeBits;
1894
1895 initialized = true;
1896 return true;
1897 }
1898