Skip to content

Commit

Permalink
Replace PKCS11 headers with a version from p11-kit
Browse files Browse the repository at this point in the history
Since headers provided by OASIS PKCS11 TC have not-exactly free license
(they do not allow modification), use an alternative header from p11-kit
which is licensed under a more liberal license.

Vendor-specific constants were also updated to PKCS11 standard v3.0
where possible.
  • Loading branch information
abbra committed Aug 17, 2018
1 parent 56b4d03 commit ecba266
Show file tree
Hide file tree
Showing 10 changed files with 1,758 additions and 3,218 deletions.
2 changes: 1 addition & 1 deletion src/bin/dump/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void fill_CKA_table(std::map<unsigned long, std::string> &t)
t[CKA_SUBPRIME] = "CKA_SUBPRIME";
t[CKA_BASE] = "CKA_BASE";
t[CKA_PRIME_BITS] = "CKA_PRIME_BITS";
t[CKA_SUBPRIME_BITS] = "CKA_SUBPRIME_BITS";
t[CKA_SUB_PRIME_BITS] = "CKA_SUB_PRIME_BITS";
t[CKA_VALUE_BITS] = "CKA_VALUE_BITS";
t[CKA_VALUE_LEN] = "CKA_VALUE_LEN";
t[CKA_EXTRACTABLE] = "CKA_EXTRACTABLE";
Expand Down
4 changes: 2 additions & 2 deletions src/lib/P11Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2350,7 +2350,7 @@ CK_RV P11AttrWrapTemplate::updateAttr(Token* /*token*/, bool /*isPrivate*/, CK_V
case CKA_KEY_GEN_MECHANISM:
case CKA_MODULUS_BITS:
case CKA_PRIME_BITS:
case CKA_SUBPRIME_BITS:
case CKA_SUB_PRIME_BITS:
case CKA_VALUE_BITS:
case CKA_VALUE_LEN:
case CKA_AUTH_PIN_FLAGS:
Expand Down Expand Up @@ -2449,7 +2449,7 @@ CK_RV P11AttrUnwrapTemplate::updateAttr(Token* /*token*/, bool /*isPrivate*/, CK
case CKA_KEY_GEN_MECHANISM:
case CKA_MODULUS_BITS:
case CKA_PRIME_BITS:
case CKA_SUBPRIME_BITS:
case CKA_SUB_PRIME_BITS:
case CKA_VALUE_BITS:
case CKA_VALUE_LEN:
case CKA_AUTH_PIN_FLAGS:
Expand Down
8 changes: 4 additions & 4 deletions src/lib/SoftHSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8301,10 +8301,10 @@ CK_RV SoftHSM::generateDSAParameters
}
bitLen = *(CK_ULONG*)pTemplate[i].pValue;
break;
case CKA_SUBPRIME_BITS:
case CKA_SUB_PRIME_BITS:
if (pTemplate[i].ulValueLen != sizeof(CK_ULONG))
{
INFO_MSG("CKA_SUBPRIME_BITS does not have the size of CK_ULONG");
INFO_MSG("CKA_SUB_PRIME_BITS does not have the size of CK_ULONG");
return CKR_ATTRIBUTE_VALUE_INVALID;
}
qLen = *(CK_ULONG*)pTemplate[i].pValue;
Expand All @@ -8321,11 +8321,11 @@ CK_RV SoftHSM::generateDSAParameters
return CKR_TEMPLATE_INCOMPLETE;
}

// No real choice for CKA_SUBPRIME_BITS
// No real choice for CKA_SUB_PRIME_BITS
if ((qLen != 0) &&
(((bitLen >= 2048) && (qLen != 256)) ||
((bitLen < 2048) && (qLen != 160))))
INFO_MSG("CKA_SUBPRIME_BITS is ignored");
INFO_MSG("CKA_SUB_PRIME_BITS is ignored");


// Generate domain parameters
Expand Down
2 changes: 1 addition & 1 deletion src/lib/object_store/DBObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static AttributeKind attributeKind(CK_ATTRIBUTE_TYPE type)
case CKA_SUBPRIME: return akBinary;
case CKA_BASE: return akBinary;
case CKA_PRIME_BITS: return akInteger;
case CKA_SUBPRIME_BITS: return akInteger;
case CKA_SUB_PRIME_BITS: return akInteger;
case CKA_VALUE_BITS: return akInteger;
case CKA_VALUE_LEN: return akInteger;
case CKA_EXTRACTABLE: return akBoolean;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/object_store/test/DBObjectTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void test_a_dbobject_with_an_object::should_store_unsigned_long_attributes()
CPPUNIT_ASSERT(testObject.setAttribute(CKA_MODULUS_BITS, attr1));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_AUTH_PIN_FLAGS, attr3));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUBPRIME_BITS, attr4));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUB_PRIME_BITS, attr4));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_KEY_TYPE, attr5));
}

Expand All @@ -215,20 +215,20 @@ void test_a_dbobject_with_an_object::should_store_unsigned_long_attributes()
CPPUNIT_ASSERT(testObject.attributeExists(CKA_MODULUS_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_AUTH_PIN_FLAGS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUBPRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUB_PRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_KEY_TYPE));
CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_AUTH_PIN_FLAGS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBPRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUB_PRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_KEY_TYPE).isUnsignedLongAttribute());

CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_MODULUS_BITS).getUnsignedLongValue(), (unsigned long)0x12345678);
CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue(), (unsigned long)0x87654321);
CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_AUTH_PIN_FLAGS).getUnsignedLongValue(), (unsigned long)0x01010101);
CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_SUBPRIME_BITS).getUnsignedLongValue(), (unsigned long)0x10101010);
CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_SUB_PRIME_BITS).getUnsignedLongValue(), (unsigned long)0x10101010);
CPPUNIT_ASSERT_EQUAL(testObject.getAttribute(CKA_KEY_TYPE).getUnsignedLongValue(), (unsigned long)0xABCDEF);

unsigned long value6 = 0x90909090;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/object_store/test/ObjectFileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void ObjectFileTests::testULongAttr()
CPPUNIT_ASSERT(testObject.setAttribute(CKA_MODULUS_BITS, attr1));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_AUTH_PIN_FLAGS, attr3));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUBPRIME_BITS, attr4));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUB_PRIME_BITS, attr4));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_KEY_TYPE, attr5));
}

Expand All @@ -175,20 +175,20 @@ void ObjectFileTests::testULongAttr()
CPPUNIT_ASSERT(testObject.attributeExists(CKA_MODULUS_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_AUTH_PIN_FLAGS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUBPRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUB_PRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_KEY_TYPE));
CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_AUTH_PIN_FLAGS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBPRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUB_PRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_KEY_TYPE).isUnsignedLongAttribute());

CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS_BITS).getUnsignedLongValue() == 0x12345678);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == 0x87654321);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_AUTH_PIN_FLAGS).getUnsignedLongValue() == 0x01010101);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBPRIME_BITS).getUnsignedLongValue() == 0x10101010);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUB_PRIME_BITS).getUnsignedLongValue() == 0x10101010);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_KEY_TYPE).getUnsignedLongValue() == 0xABCDEF);

unsigned long value6 = 0x90909090;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/object_store/test/SessionObjectTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,28 @@ void SessionObjectTests::testULongAttr()
CPPUNIT_ASSERT(testObject.setAttribute(CKA_MODULUS_BITS, attr1));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_AUTH_PIN_FLAGS, attr3));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUBPRIME_BITS, attr4));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_SUB_PRIME_BITS, attr4));
CPPUNIT_ASSERT(testObject.setAttribute(CKA_KEY_TYPE, attr5));

CPPUNIT_ASSERT(testObject.isValid());

CPPUNIT_ASSERT(testObject.attributeExists(CKA_MODULUS_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_PRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_AUTH_PIN_FLAGS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUBPRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_SUB_PRIME_BITS));
CPPUNIT_ASSERT(testObject.attributeExists(CKA_KEY_TYPE));
CPPUNIT_ASSERT(!testObject.attributeExists(CKA_ID));

CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_AUTH_PIN_FLAGS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBPRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUB_PRIME_BITS).isUnsignedLongAttribute());
CPPUNIT_ASSERT(testObject.getAttribute(CKA_KEY_TYPE).isUnsignedLongAttribute());

CPPUNIT_ASSERT(testObject.getAttribute(CKA_MODULUS_BITS).getUnsignedLongValue() == 0x12345678);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == 0x87654321);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_AUTH_PIN_FLAGS).getUnsignedLongValue() == 0x01010101);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUBPRIME_BITS).getUnsignedLongValue() == 0x10101010);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_SUB_PRIME_BITS).getUnsignedLongValue() == 0x10101010);
CPPUNIT_ASSERT(testObject.getAttribute(CKA_KEY_TYPE).getUnsignedLongValue() == 0xABCDEF);

unsigned long value6 = 0x90909090;
Expand Down
Loading

0 comments on commit ecba266

Please sign in to comment.