winpr: fix some string constant in ncrypt and add reader property
Some WCHAR string constant were wrong (missing \x00 at the end). The commit also implements the NCRYPT_READER_PROPERTY property in the pkcs11 provider.
This commit is contained in:
parent
eb53b9913a
commit
130f191392
@ -66,7 +66,7 @@ typedef ULONG_PTR NCRYPT_KEY_HANDLE;
|
||||
"e\x00 " \
|
||||
"\x00P\x00r\x00o\x00v\x00i\x00" \
|
||||
"d\x00" \
|
||||
"e\x00r\x00"
|
||||
"e\x00r\x00\x00"
|
||||
|
||||
#define MS_SCARD_PROV_A "Microsoft Base Smart Card Crypto Provider"
|
||||
#define MS_SCARD_PROV \
|
||||
@ -114,6 +114,22 @@ typedef ULONG_PTR NCRYPT_KEY_HANDLE;
|
||||
"c\x00" \
|
||||
"a\x00t\x00" \
|
||||
"e\x00\x00"
|
||||
#define NCRYPT_UNIQUE_NAME_PROPERTY \
|
||||
(const WCHAR*)"U\x00n\x00i\x00q\x00u\x00" \
|
||||
"e\x00 \x00N\x00" \
|
||||
"a\x00m\x00" \
|
||||
"e\x00\x00"
|
||||
#define NCRYPT_READER_PROPERTY \
|
||||
(const WCHAR *)"S\x00m\x00" \
|
||||
"a\x00r\x00t\x00" \
|
||||
"C\x00" \
|
||||
"a\x00r\x00" \
|
||||
"d\x00R\x00" \
|
||||
"e\x00" \
|
||||
"a\x00" \
|
||||
"d\x00" \
|
||||
"e\x00r\x00\x00"
|
||||
|
||||
|
||||
#define NCRYPT_MACHINE_KEY_FLAG 0x20
|
||||
#define NCRYPT_SILENT_FLAG 0x40
|
||||
|
@ -126,7 +126,8 @@ SECURITY_STATUS NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE* phProvider, LPCWST
|
||||
{
|
||||
|
||||
#ifdef WITH_PKCS11
|
||||
if (_wcscmp(pszProviderName, MS_SMART_CARD_KEY_STORAGE_PROVIDER) == 0)
|
||||
if (_wcscmp(pszProviderName, MS_SMART_CARD_KEY_STORAGE_PROVIDER) == 0 ||
|
||||
_wcscmp(pszProviderName, MS_SCARD_PROV) == 0)
|
||||
{
|
||||
static LPCSTR openscPaths[] = { "/usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so", NULL };
|
||||
|
||||
@ -188,6 +189,10 @@ static NCryptKeyGetPropertyEnum propertyStringToEnum(LPCWSTR pszProperty)
|
||||
{
|
||||
return NCRYPT_PROPERTY_CERTIFICATE;
|
||||
}
|
||||
else if(_wcscmp(pszProperty, NCRYPT_READER_PROPERTY) == 0)
|
||||
{
|
||||
return NCRYPT_PROPERTY_READER;
|
||||
}
|
||||
|
||||
return NCRYPT_PROPERTY_UNKNOWN;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ typedef SECURITY_STATUS (*NCryptReleaseFn)(NCRYPT_HANDLE handle);
|
||||
typedef enum
|
||||
{
|
||||
NCRYPT_PROPERTY_CERTIFICATE,
|
||||
NCRYPT_PROPERTY_READER,
|
||||
NCRYPT_PROPERTY_UNKNOWN
|
||||
} NCryptKeyGetPropertyEnum;
|
||||
|
||||
|
@ -86,20 +86,17 @@ static CK_ATTRIBUTE private_key_filter[] = {
|
||||
{ CKA_KEY_TYPE, &object_ktype_rsa, sizeof(object_ktype_rsa) }
|
||||
};
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @return the real length of string padded with pad
|
||||
*
|
||||
*/
|
||||
static size_t padded_strlen(const char *str, size_t maxlen, char pad)
|
||||
{
|
||||
size_t ret = strnlen(str, maxlen);
|
||||
|
||||
while ((ret > 0) && str[ret-1] == pad)
|
||||
ret--;
|
||||
return ret;
|
||||
static void fix_padded_string(char *str, size_t maxlen)
|
||||
{
|
||||
char *ptr = str + maxlen-1;
|
||||
|
||||
while (ptr > str && *ptr == ' ')
|
||||
ptr--;
|
||||
ptr++;
|
||||
*ptr = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static BOOL attributes_have_unallocated_buffers(CK_ATTRIBUTE_PTR attributes, CK_ULONG count)
|
||||
{
|
||||
@ -617,15 +614,29 @@ static SECURITY_STATUS NCryptP11KeyGetProperties(NCryptP11KeyHandle* keyHandle,
|
||||
CK_ATTRIBUTE* objectFilter = certificateFilter;
|
||||
CK_ULONG objectFilterLen = ARRAY_LENGTH(certificateFilter);
|
||||
|
||||
if (property == NCRYPT_PROPERTY_UNKNOWN)
|
||||
return NTE_NOT_SUPPORTED;
|
||||
|
||||
/* TODO: shall adjust objectFilter and objectFilterLen depending on requested
|
||||
* the property when we add new ones */
|
||||
switch (property)
|
||||
{
|
||||
case NCRYPT_PROPERTY_CERTIFICATE:
|
||||
break;
|
||||
case NCRYPT_PROPERTY_READER: {
|
||||
CK_SLOT_INFO slotInfo;
|
||||
|
||||
rv = provider->p11->C_GetSlotInfo(keyHandle->slotId, &slotInfo);
|
||||
if (rv != CKR_OK)
|
||||
return NTE_BAD_KEY;
|
||||
|
||||
fix_padded_string((char*)slotInfo.slotDescription, sizeof(slotInfo.slotDescription));
|
||||
*pcbResult = 2 * (strlen((char*)slotInfo.slotDescription) + 1);
|
||||
if (pbOutput)
|
||||
{
|
||||
if(cbOutput < *pcbResult)
|
||||
return NTE_NO_MEMORY;
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)slotInfo.slotDescription, -1, (LPWSTR)pbOutput, cbOutput);
|
||||
}
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
case NCRYPT_PROPERTY_UNKNOWN:
|
||||
default:
|
||||
return NTE_NOT_SUPPORTED;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user