|
|
f6aa30 |
diff -up ./src/coolkey/coolkey.cpp.fail-on-bad-mechanisms ./src/coolkey/coolkey.cpp
|
|
|
f6aa30 |
--- ./src/coolkey/coolkey.cpp.fail-on-bad-mechanisms 2016-06-16 14:36:05.934755563 -0700
|
|
|
f6aa30 |
+++ ./src/coolkey/coolkey.cpp 2016-06-16 14:36:05.945755372 -0700
|
|
|
f6aa30 |
@@ -77,7 +77,8 @@ rsaMechanismList[] = {
|
|
|
f6aa30 |
|
|
|
f6aa30 |
static const MechInfo
|
|
|
f6aa30 |
ecMechanismList[] = {
|
|
|
f6aa30 |
- {CKM_ECDSA,{256,521,CKF_HW | CKF_SIGN | CKF_EC_F_P}},{ CKM_ECDSA_SHA1, {256, 521, CKF_HW | CKF_SIGN | CKF_EC_F_P}},{ CKM_ECDH1_DERIVE,{256, 521, CKF_HW | CKF_DERIVE | CKF_EC_F_P} }
|
|
|
f6aa30 |
+ {CKM_ECDSA,{256,521,CKF_HW | CKF_SIGN | CKF_EC_F_P}},
|
|
|
f6aa30 |
+ {CKM_ECDH1_DERIVE,{256, 521, CKF_HW | CKF_DERIVE | CKF_EC_F_P} }
|
|
|
f6aa30 |
};
|
|
|
f6aa30 |
|
|
|
f6aa30 |
unsigned int numRSAMechanisms = sizeof(rsaMechanismList)/sizeof(MechInfo);
|
|
|
f6aa30 |
diff -up ./src/coolkey/slot.cpp.fail-on-bad-mechanisms ./src/coolkey/slot.cpp
|
|
|
f6aa30 |
--- ./src/coolkey/slot.cpp.fail-on-bad-mechanisms 2016-06-16 14:36:05.943755407 -0700
|
|
|
f6aa30 |
+++ ./src/coolkey/slot.cpp 2016-06-16 15:07:40.255882660 -0700
|
|
|
f6aa30 |
@@ -4185,11 +4185,30 @@ Slot::signInit(SessionHandleSuffix suffi
|
|
|
f6aa30 |
{
|
|
|
f6aa30 |
refreshTokenState();
|
|
|
f6aa30 |
SessionIter session = findSession(suffix);
|
|
|
f6aa30 |
+ PKCS11Object *key = getKeyFromHandle(hKey);
|
|
|
f6aa30 |
if( session == sessions.end() ) {
|
|
|
f6aa30 |
throw PKCS11Exception(CKR_SESSION_HANDLE_INVALID);
|
|
|
f6aa30 |
}
|
|
|
f6aa30 |
+ if (pMechanism == NULL) {
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_ARGUMENTS_BAD);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
+
|
|
|
f6aa30 |
+ switch (pMechanism->mechanism) {
|
|
|
f6aa30 |
+ case CKM_RSA_PKCS:
|
|
|
f6aa30 |
+ if (key->getKeyType() != Key::rsa) {
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_KEY_TYPE_INCONSISTENT);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
+ break;
|
|
|
f6aa30 |
+ case CKM_ECDSA:
|
|
|
f6aa30 |
+ if (key->getKeyType() != Key::ecc) {
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_KEY_TYPE_INCONSISTENT);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
+ break;
|
|
|
f6aa30 |
+ default:
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_MECHANISM_INVALID);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
|
|
|
f6aa30 |
- session->signatureState.initialize(getKeyFromHandle(hKey));
|
|
|
f6aa30 |
+ session->signatureState.initialize(key);
|
|
|
f6aa30 |
}
|
|
|
f6aa30 |
|
|
|
f6aa30 |
void
|
|
|
f6aa30 |
@@ -4198,11 +4217,24 @@ Slot::decryptInit(SessionHandleSuffix su
|
|
|
f6aa30 |
{
|
|
|
f6aa30 |
refreshTokenState();
|
|
|
f6aa30 |
SessionIter session = findSession(suffix);
|
|
|
f6aa30 |
+ PKCS11Object *key = getKeyFromHandle(hKey);
|
|
|
f6aa30 |
if( session == sessions.end() ) {
|
|
|
f6aa30 |
throw PKCS11Exception(CKR_SESSION_HANDLE_INVALID);
|
|
|
f6aa30 |
}
|
|
|
f6aa30 |
+ if (pMechanism == NULL) {
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_ARGUMENTS_BAD);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
+ switch (pMechanism->mechanism) {
|
|
|
f6aa30 |
+ case CKM_RSA_PKCS:
|
|
|
f6aa30 |
+ if (key->getKeyType() != Key::rsa) {
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_KEY_TYPE_INCONSISTENT);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
+ break;
|
|
|
f6aa30 |
+ default:
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_MECHANISM_INVALID);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
|
|
|
f6aa30 |
- session->decryptionState.initialize(getKeyFromHandle(hKey));
|
|
|
f6aa30 |
+ session->decryptionState.initialize(key);
|
|
|
f6aa30 |
}
|
|
|
f6aa30 |
|
|
|
f6aa30 |
/**
|
|
|
f6aa30 |
@@ -5008,8 +5040,23 @@ Slot::derive(SessionHandleSuffix suffix,
|
|
|
f6aa30 |
|
|
|
f6aa30 |
ECCKeyAgreementParams params(CryptParams::ECC_DEFAULT_KEY_SIZE);
|
|
|
f6aa30 |
SessionIter session = findSession(suffix);
|
|
|
f6aa30 |
+ PKCS11Object *key=getKeyFromHandle(hBaseKey);
|
|
|
f6aa30 |
|
|
|
f6aa30 |
- session->keyAgreementState.initialize(getKeyFromHandle(hBaseKey));
|
|
|
f6aa30 |
+ if (pMechanism == NULL ) {
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_ARGUMENTS_BAD);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
+
|
|
|
f6aa30 |
+ switch (pMechanism->mechanism) {
|
|
|
f6aa30 |
+ case CKM_ECDH1_DERIVE:
|
|
|
f6aa30 |
+ if (key->getKeyType() != Key::ecc) {
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_KEY_TYPE_INCONSISTENT);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
+ break;
|
|
|
f6aa30 |
+ default:
|
|
|
f6aa30 |
+ throw PKCS11Exception(CKR_MECHANISM_INVALID);
|
|
|
f6aa30 |
+ }
|
|
|
f6aa30 |
+
|
|
|
f6aa30 |
+ session->keyAgreementState.initialize(key);
|
|
|
f6aa30 |
deriveECC(suffix, pMechanism, hBaseKey, pTemplate, ulAttributeCount,
|
|
|
f6aa30 |
phKey, params);
|
|
|
f6aa30 |
|
|
|
f6aa30 |
@@ -5018,9 +5065,6 @@ Slot::derive(SessionHandleSuffix suffix,
|
|
|
f6aa30 |
void Slot::deriveECC(SessionHandleSuffix suffix, CK_MECHANISM_PTR pMechanism,
|
|
|
f6aa30 |
CK_OBJECT_HANDLE hBaseKey, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, CK_OBJECT_HANDLE_PTR phKey, CryptParams& params)
|
|
|
f6aa30 |
{
|
|
|
f6aa30 |
- if (pMechanism == NULL ) {
|
|
|
f6aa30 |
- throw PKCS11Exception(CKR_ARGUMENTS_BAD);
|
|
|
f6aa30 |
- }
|
|
|
f6aa30 |
|
|
|
f6aa30 |
CK_ECDH1_DERIVE_PARAMS *mechParams = NULL;
|
|
|
f6aa30 |
|