136
146
CKA_ALLOWED_MECHANISMS, sizeof (value), &value,
137
147
CKA_DECRYPT, GP11_BOOLEAN, TRUE,
138
148
CKA_PRIVATE, GP11_BOOLEAN, TRUE,
149
CKA_WRAP, GP11_BOOLEAN, TRUE,
150
CKA_UNWRAP, GP11_BOOLEAN, TRUE,
151
CKA_DERIVE, GP11_BOOLEAN, TRUE,
152
CKA_VALUE, GP11_STRING, "value",
140
154
g_hash_table_insert (the_objects, GUINT_TO_POINTER (PRIVATE_KEY_CAPITALIZE), attrs);
482
499
test_C_InitPIN (CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pPin,
483
500
CK_ULONG ulPinLen)
485
g_assert_not_reached (); /* Not yet used by library */
486
return CKR_FUNCTION_NOT_SUPPORTED;
504
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
505
g_assert (session != NULL && "No such session found");
507
return CKR_SESSION_HANDLE_INVALID;
510
the_pin = g_strndup ((gchar*)pPin, ulPinLen);
490
515
test_C_SetPIN (CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pOldPin,
491
CK_ULONG ulOldLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewLen)
516
CK_ULONG ulOldLen, CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewLen)
493
g_assert_not_reached (); /* Not yet used by library */
494
return CKR_FUNCTION_NOT_SUPPORTED;
521
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
522
g_assert (session != NULL && "No such session found");
524
return CKR_SESSION_HANDLE_INVALID;
526
old = g_strndup ((gchar*)pOldPin, ulOldLen);
527
if (!g_str_equal (old, the_pin))
528
return CKR_PIN_INCORRECT;
531
the_pin = g_strndup ((gchar*)pNewPin, ulNewLen);
1342
1374
test_C_GenerateKeyPair (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
1343
CK_ATTRIBUTE_PTR pPublicKeyTemplate, CK_ULONG ulPublicKeyAttributeCount,
1344
CK_ATTRIBUTE_PTR pPrivateKeyTemplate, CK_ULONG ulPrivateKeyAttributeCount,
1345
CK_OBJECT_HANDLE_PTR phPublicKey, CK_OBJECT_HANDLE_PTR phPrivateKey)
1375
CK_ATTRIBUTE_PTR pPublicKeyTemplate, CK_ULONG ulPublicKeyAttributeCount,
1376
CK_ATTRIBUTE_PTR pPrivateKeyTemplate, CK_ULONG ulPrivateKeyAttributeCount,
1377
CK_OBJECT_HANDLE_PTR phPublicKey, CK_OBJECT_HANDLE_PTR phPrivateKey)
1347
g_assert_not_reached (); /* Not yet used by library */
1348
return CKR_FUNCTION_NOT_SUPPORTED;
1379
GP11Attributes *attrs;
1384
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
1385
g_assert (session != NULL && "No such session found");
1387
return CKR_SESSION_HANDLE_INVALID;
1389
g_assert (pMechanism);
1390
g_assert (pPublicKeyTemplate);
1391
g_assert (ulPublicKeyAttributeCount);
1392
g_assert (pPrivateKeyTemplate);
1393
g_assert (phPublicKey);
1394
g_assert (phPrivateKey);
1396
if (pMechanism->mechanism != CKM_GENERATE)
1397
return CKR_MECHANISM_INVALID;
1399
if (!pMechanism->pParameter || pMechanism->ulParameterLen != 9 ||
1400
memcmp (pMechanism->pParameter, "generate", 9) != 0) {
1401
g_assert_not_reached ();
1402
return CKR_MECHANISM_PARAM_INVALID;
1405
attrs = gp11_attributes_new ();
1406
gp11_attributes_add_string (attrs, CKA_VALUE, "generated");
1407
for (i = 0; i < ulPublicKeyAttributeCount; ++i)
1408
gp11_attributes_add_data (attrs, pPublicKeyTemplate[i].type,
1409
pPublicKeyTemplate[i].pValue,
1410
pPublicKeyTemplate[i].ulValueLen);
1411
*phPublicKey = ++unique_identifier;
1412
if (gp11_attributes_find_boolean (attrs, CKA_TOKEN, &token) && token)
1413
g_hash_table_insert (the_objects, GUINT_TO_POINTER (*phPublicKey), attrs);
1415
g_hash_table_insert (session->objects, GUINT_TO_POINTER (*phPublicKey), attrs);
1417
attrs = gp11_attributes_new ();
1418
gp11_attributes_add_string (attrs, CKA_VALUE, "generated");
1419
for (i = 0; i < ulPrivateKeyAttributeCount; ++i)
1420
gp11_attributes_add_data (attrs, pPrivateKeyTemplate[i].type,
1421
pPrivateKeyTemplate[i].pValue,
1422
pPrivateKeyTemplate[i].ulValueLen);
1423
*phPrivateKey = ++unique_identifier;
1424
if (gp11_attributes_find_boolean (attrs, CKA_TOKEN, &token) && token)
1425
g_hash_table_insert (the_objects, GUINT_TO_POINTER (*phPrivateKey), attrs);
1427
g_hash_table_insert (session->objects, GUINT_TO_POINTER (*phPrivateKey), attrs);
1352
1432
test_C_WrapKey (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
1353
CK_OBJECT_HANDLE hWrappingKey, CK_OBJECT_HANDLE hKey,
1354
CK_BYTE_PTR pWrappedKey, CK_ULONG_PTR pulWrappedKeyLen)
1433
CK_OBJECT_HANDLE hWrappingKey, CK_OBJECT_HANDLE hKey,
1434
CK_BYTE_PTR pWrappedKey, CK_ULONG_PTR pulWrappedKeyLen)
1356
g_assert_not_reached (); /* Not yet used by library */
1357
return CKR_FUNCTION_NOT_SUPPORTED;
1436
GP11Attributes *attrs;
1437
GP11Attribute *attr;
1440
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
1442
g_assert_not_reached ();
1443
return CKR_SESSION_HANDLE_INVALID;
1446
g_assert (pMechanism);
1447
g_assert (hWrappingKey);
1449
g_assert (pulWrappedKeyLen);
1451
attrs = lookup_object (session, hWrappingKey);
1453
g_assert_not_reached ();
1454
return CKR_WRAPPING_KEY_HANDLE_INVALID;
1457
attrs = lookup_object (session, hKey);
1459
g_assert_not_reached ();
1460
return CKR_WRAPPED_KEY_INVALID;
1463
if (pMechanism->mechanism != CKM_WRAP)
1464
return CKR_MECHANISM_INVALID;
1466
if (pMechanism->pParameter) {
1467
if (pMechanism->ulParameterLen != 4 ||
1468
memcmp (pMechanism->pParameter, "wrap", 4) != 0) {
1469
g_assert_not_reached ();
1470
return CKR_MECHANISM_PARAM_INVALID;
1474
attr = gp11_attributes_find (attrs, CKA_VALUE);
1476
return CKR_WRAPPED_KEY_INVALID;
1479
*pulWrappedKeyLen = attr->length;
1483
if (*pulWrappedKeyLen < attr->length) {
1484
*pulWrappedKeyLen = attr->length;
1485
return CKR_BUFFER_TOO_SMALL;
1488
memcpy (pWrappedKey, attr->value, attr->length);
1489
*pulWrappedKeyLen = attr->length;
1363
1497
CK_ULONG pulWrappedKeyLen, CK_ATTRIBUTE_PTR pTemplate,
1364
1498
CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phKey)
1366
g_assert_not_reached (); /* Not yet used by library */
1367
return CKR_FUNCTION_NOT_SUPPORTED;
1500
GP11Attributes *attrs;
1505
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
1507
g_assert_not_reached ();
1508
return CKR_SESSION_HANDLE_INVALID;
1511
g_assert (pMechanism);
1512
g_assert (pUnwrappingKey);
1513
g_assert (pWrappedKey);
1514
g_assert (pulWrappedKeyLen);
1517
g_assert (pTemplate);
1520
attrs = lookup_object (session, pUnwrappingKey);
1522
g_assert_not_reached ();
1523
return CKR_WRAPPING_KEY_HANDLE_INVALID;
1526
if (pMechanism->mechanism != CKM_WRAP)
1527
return CKR_MECHANISM_INVALID;
1529
if (pMechanism->pParameter) {
1530
if (pMechanism->ulParameterLen != 4 ||
1531
memcmp (pMechanism->pParameter, "wrap", 4) != 0) {
1532
g_assert_not_reached ();
1533
return CKR_MECHANISM_PARAM_INVALID;
1537
attrs = gp11_attributes_new ();
1538
gp11_attributes_add_data (attrs, CKA_VALUE, pWrappedKey, pulWrappedKeyLen);
1539
for (i = 0; i < ulCount; ++i)
1540
gp11_attributes_add_data (attrs, pTemplate[i].type,
1541
pTemplate[i].pValue,
1542
pTemplate[i].ulValueLen);
1543
*phKey = ++unique_identifier;
1544
if (gp11_attributes_find_boolean (attrs, CKA_TOKEN, &token) && token)
1545
g_hash_table_insert (the_objects, GUINT_TO_POINTER (*phKey), attrs);
1547
g_hash_table_insert (session->objects, GUINT_TO_POINTER (*phKey), attrs);
1372
1554
CK_OBJECT_HANDLE hBaseKey, CK_ATTRIBUTE_PTR pTemplate,
1373
1555
CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phKey)
1375
g_assert_not_reached (); /* Not yet used by library */
1376
return CKR_FUNCTION_NOT_SUPPORTED;
1557
GP11Attributes *attrs, *copy;
1562
session = g_hash_table_lookup (the_sessions, GUINT_TO_POINTER (hSession));
1564
g_assert_not_reached ();
1565
return CKR_SESSION_HANDLE_INVALID;
1568
g_assert (pMechanism);
1570
g_assert (pTemplate);
1573
attrs = lookup_object (session, hBaseKey);
1575
g_assert_not_reached ();
1576
return CKR_WRAPPING_KEY_HANDLE_INVALID;
1579
if (pMechanism->mechanism != CKM_DERIVE)
1580
return CKR_MECHANISM_INVALID;
1582
if (pMechanism->pParameter) {
1583
if (pMechanism->ulParameterLen != 6 ||
1584
memcmp (pMechanism->pParameter, "derive", 6) != 0) {
1585
g_assert_not_reached ();
1586
return CKR_MECHANISM_PARAM_INVALID;
1590
copy = gp11_attributes_new ();
1591
gp11_attributes_add_string (copy, CKA_VALUE, "derived");
1592
for (i = 0; i < ulCount; ++i)
1593
gp11_attributes_add_data (copy, pTemplate[i].type,
1594
pTemplate[i].pValue,
1595
pTemplate[i].ulValueLen);
1596
for (i = 0; i < gp11_attributes_count (attrs); ++i)
1597
gp11_attributes_add (copy, gp11_attributes_at (attrs, i));
1598
*phKey = ++unique_identifier;
1599
if (gp11_attributes_find_boolean (copy, CKA_TOKEN, &token) && token)
1600
g_hash_table_insert (the_objects, GUINT_TO_POINTER (*phKey), copy);
1602
g_hash_table_insert (session->objects, GUINT_TO_POINTER (*phKey), copy);