@@ -931,6 +931,8 @@ CK_RV SoftHSM::C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_
931
931
{
932
932
return CKR_SLOT_ID_INVALID;
933
933
}
934
+ if (!isMechanismPermitted (NULL , type))
935
+ return CKR_MECHANISM_INVALID;
934
936
935
937
AsymmetricAlgorithm* rsa = CryptoFactory::i ()->getAsymmetricAlgorithm (AsymAlgo::RSA);
936
938
if (rsa != NULL )
@@ -2183,7 +2185,7 @@ CK_RV SoftHSM::SymEncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech
2183
2185
return CKR_KEY_FUNCTION_NOT_PERMITTED;
2184
2186
2185
2187
// Check if the specified mechanism is allowed for the key
2186
- if (!isMechanismPermitted (key, pMechanism))
2188
+ if (!isMechanismPermitted (key, pMechanism-> mechanism ))
2187
2189
return CKR_MECHANISM_INVALID;
2188
2190
2189
2191
// Get key info
@@ -2903,7 +2905,7 @@ CK_RV SoftHSM::SymDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech
2903
2905
2904
2906
2905
2907
// Check if the specified mechanism is allowed for the key
2906
- if (!isMechanismPermitted (key, pMechanism))
2908
+ if (!isMechanismPermitted (key, pMechanism-> mechanism ))
2907
2909
return CKR_MECHANISM_INVALID;
2908
2910
2909
2911
// Get key info
@@ -3150,7 +3152,7 @@ CK_RV SoftHSM::AsymDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMec
3150
3152
return CKR_KEY_FUNCTION_NOT_PERMITTED;
3151
3153
3152
3154
// Check if the specified mechanism is allowed for the key
3153
- if (!isMechanismPermitted (key, pMechanism))
3155
+ if (!isMechanismPermitted (key, pMechanism-> mechanism ))
3154
3156
return CKR_MECHANISM_INVALID;
3155
3157
3156
3158
// Get key info
@@ -3944,7 +3946,7 @@ CK_RV SoftHSM::MacSignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechani
3944
3946
return CKR_KEY_FUNCTION_NOT_PERMITTED;
3945
3947
3946
3948
// Check if the specified mechanism is allowed for the key
3947
- if (!isMechanismPermitted (key, pMechanism))
3949
+ if (!isMechanismPermitted (key, pMechanism-> mechanism ))
3948
3950
return CKR_MECHANISM_INVALID;
3949
3951
3950
3952
// Get key info
@@ -4096,7 +4098,7 @@ CK_RV SoftHSM::AsymSignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechan
4096
4098
return CKR_KEY_FUNCTION_NOT_PERMITTED;
4097
4099
4098
4100
// Check if the specified mechanism is allowed for the key
4099
- if (!isMechanismPermitted (key, pMechanism))
4101
+ if (!isMechanismPermitted (key, pMechanism-> mechanism ))
4100
4102
return CKR_MECHANISM_INVALID;
4101
4103
4102
4104
// Get the asymmetric algorithm matching the mechanism
@@ -4922,7 +4924,7 @@ CK_RV SoftHSM::MacVerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMecha
4922
4924
return CKR_KEY_FUNCTION_NOT_PERMITTED;
4923
4925
4924
4926
// Check if the specified mechanism is allowed for the key
4925
- if (!isMechanismPermitted (key, pMechanism))
4927
+ if (!isMechanismPermitted (key, pMechanism-> mechanism ))
4926
4928
return CKR_MECHANISM_INVALID;
4927
4929
4928
4930
// Get key info
@@ -5074,7 +5076,7 @@ CK_RV SoftHSM::AsymVerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech
5074
5076
return CKR_KEY_FUNCTION_NOT_PERMITTED;
5075
5077
5076
5078
// Check if the specified mechanism is allowed for the key
5077
- if (!isMechanismPermitted (key, pMechanism))
5079
+ if (!isMechanismPermitted (key, pMechanism-> mechanism ))
5078
5080
return CKR_MECHANISM_INVALID;
5079
5081
5080
5082
// Get the asymmetric algorithm matching the mechanism
@@ -6527,7 +6529,7 @@ CK_RV SoftHSM::C_WrapKey
6527
6529
return CKR_KEY_FUNCTION_NOT_PERMITTED;
6528
6530
6529
6531
// Check if the specified mechanism is allowed for the wrapping key
6530
- if (!isMechanismPermitted (wrapKey, pMechanism))
6532
+ if (!isMechanismPermitted (wrapKey, pMechanism-> mechanism ))
6531
6533
return CKR_MECHANISM_INVALID;
6532
6534
6533
6535
// Check the to be wrapped key handle.
@@ -6993,7 +6995,7 @@ CK_RV SoftHSM::C_UnwrapKey
6993
6995
return CKR_KEY_FUNCTION_NOT_PERMITTED;
6994
6996
6995
6997
// Check if the specified mechanism is allowed for the unwrap key
6996
- if (!isMechanismPermitted (unwrapKey, pMechanism))
6998
+ if (!isMechanismPermitted (unwrapKey, pMechanism-> mechanism ))
6997
6999
return CKR_MECHANISM_INVALID;
6998
7000
6999
7001
// Extract information from the template that is needed to create the object.
@@ -7274,7 +7276,7 @@ CK_RV SoftHSM::C_DeriveKey
7274
7276
return CKR_KEY_FUNCTION_NOT_PERMITTED;
7275
7277
7276
7278
// Check if the specified mechanism is allowed for the key
7277
- if (!isMechanismPermitted (key, pMechanism))
7279
+ if (!isMechanismPermitted (key, pMechanism-> mechanism ))
7278
7280
return CKR_MECHANISM_INVALID;
7279
7281
7280
7282
// Extract information from the template that is needed to create the object.
@@ -12829,22 +12831,27 @@ CK_RV SoftHSM::MechParamCheckRSAPKCSOAEP(CK_MECHANISM_PTR pMechanism)
12829
12831
return CKR_OK;
12830
12832
}
12831
12833
12832
- bool SoftHSM::isMechanismPermitted (OSObject* key, CK_MECHANISM_PTR pMechanism )
12834
+ bool SoftHSM::isMechanismPermitted (OSObject* key, CK_MECHANISM_TYPE mechanism )
12833
12835
{
12834
12836
std::list<CK_MECHANISM_TYPE> mechs = supportedMechanisms;
12835
12837
/* First check if the algorithm is enabled in the global configuration */
12836
- auto it = std::find (mechs.begin (), mechs.end (), pMechanism-> mechanism );
12838
+ auto it = std::find (mechs.begin (), mechs.end (), mechanism);
12837
12839
if (it == mechs.end ())
12838
12840
return false ;
12839
12841
12840
- OSAttribute attribute = key->getAttribute (CKA_ALLOWED_MECHANISMS);
12841
- std::set<CK_MECHANISM_TYPE> allowed = attribute.getMechanismTypeSetValue ();
12842
+ /* If we have object, consult also its allowed mechanisms */
12843
+ if (key) {
12844
+ OSAttribute attribute = key->getAttribute (CKA_ALLOWED_MECHANISMS);
12845
+ std::set<CK_MECHANISM_TYPE> allowed = attribute.getMechanismTypeSetValue ();
12842
12846
12843
- if (allowed.empty ()) {
12847
+ /* empty allow list means we allowing everything that is built-in */
12848
+ if (allowed.empty ()) {
12849
+ return true ;
12850
+ }
12851
+ return allowed.find (mechanism) != allowed.end ();
12852
+ } else {
12844
12853
return true ;
12845
12854
}
12846
-
12847
- return allowed.find (pMechanism->mechanism ) != allowed.end ();
12848
12855
}
12849
12856
12850
12857
bool SoftHSM::detectFork (void ) {
0 commit comments