2021-12-07 02:07:57 +03:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* NCrypt library
|
|
|
|
*
|
|
|
|
* Copyright 2021 David Fort <contact@hardening-consulting.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WINPR_LIBWINPR_NCRYPT_NCRYPT_H_
|
|
|
|
#define WINPR_LIBWINPR_NCRYPT_NCRYPT_H_
|
|
|
|
|
2022-02-16 12:08:00 +03:00
|
|
|
#include <winpr/config.h>
|
2022-02-14 14:23:14 +03:00
|
|
|
|
2021-12-07 02:07:57 +03:00
|
|
|
#include <winpr/bcrypt.h>
|
|
|
|
#include <winpr/crypto.h>
|
|
|
|
#include <winpr/ncrypt.h>
|
|
|
|
#include <winpr/error.h>
|
|
|
|
#include <winpr/string.h>
|
|
|
|
|
|
|
|
/** @brief type of ncrypt object */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
WINPR_NCRYPT_INVALID,
|
|
|
|
WINPR_NCRYPT_PROVIDER,
|
|
|
|
WINPR_NCRYPT_KEY
|
|
|
|
} NCryptHandleType;
|
|
|
|
|
|
|
|
/** @brief dtor function for ncrypt object */
|
|
|
|
typedef SECURITY_STATUS (*NCryptReleaseFn)(NCRYPT_HANDLE handle);
|
|
|
|
|
|
|
|
/** @brief an enum for the kind of property to retrieve */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
NCRYPT_PROPERTY_CERTIFICATE,
|
2022-01-10 17:27:10 +03:00
|
|
|
NCRYPT_PROPERTY_READER,
|
2022-01-27 14:04:52 +03:00
|
|
|
NCRYPT_PROPERTY_SLOTID,
|
2022-10-16 18:36:20 +03:00
|
|
|
NCRYPT_PROPERTY_NAME,
|
2021-12-07 02:07:57 +03:00
|
|
|
NCRYPT_PROPERTY_UNKNOWN
|
|
|
|
} NCryptKeyGetPropertyEnum;
|
|
|
|
|
|
|
|
typedef SECURITY_STATUS (*NCryptGetPropertyFn)(NCRYPT_HANDLE hObject,
|
|
|
|
NCryptKeyGetPropertyEnum property, PBYTE pbOutput,
|
|
|
|
DWORD cbOutput, DWORD* pcbResult, DWORD dwFlags);
|
|
|
|
|
|
|
|
/** @brief common ncrypt handle items */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char magic[6];
|
|
|
|
NCryptHandleType type;
|
|
|
|
NCryptGetPropertyFn getPropertyFn;
|
|
|
|
NCryptReleaseFn releaseFn;
|
|
|
|
} NCryptBaseHandle;
|
|
|
|
|
|
|
|
typedef SECURITY_STATUS (*NCryptEnumKeysFn)(NCRYPT_PROV_HANDLE hProvider, LPCWSTR pszScope,
|
|
|
|
NCryptKeyName** ppKeyName, PVOID* ppEnumState,
|
|
|
|
DWORD dwFlags);
|
|
|
|
typedef SECURITY_STATUS (*NCryptOpenKeyFn)(NCRYPT_PROV_HANDLE hProvider, NCRYPT_KEY_HANDLE* phKey,
|
|
|
|
LPCWSTR pszKeyName, DWORD dwLegacyKeySpec,
|
|
|
|
DWORD dwFlags);
|
|
|
|
|
|
|
|
/** @brief common ncrypt provider items */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
NCryptBaseHandle baseHandle;
|
|
|
|
|
|
|
|
NCryptEnumKeysFn enumKeysFn;
|
|
|
|
NCryptOpenKeyFn openKeyFn;
|
|
|
|
} NCryptBaseProvider;
|
|
|
|
|
|
|
|
SECURITY_STATUS checkNCryptHandle(NCRYPT_HANDLE handle, NCryptHandleType matchType);
|
2024-01-26 15:09:00 +03:00
|
|
|
|
|
|
|
SECURITY_STATUS winpr_NCryptDefault_dtor(NCRYPT_HANDLE handle);
|
|
|
|
|
2021-12-07 02:07:57 +03:00
|
|
|
void* ncrypt_new_handle(NCryptHandleType kind, size_t len, NCryptGetPropertyFn getProp,
|
|
|
|
NCryptReleaseFn dtor);
|
|
|
|
|
2022-02-14 14:23:14 +03:00
|
|
|
#if defined(WITH_PKCS11)
|
|
|
|
SECURITY_STATUS NCryptOpenP11StorageProviderEx(NCRYPT_PROV_HANDLE* phProvider,
|
|
|
|
LPCWSTR pszProviderName, DWORD dwFlags,
|
|
|
|
LPCSTR* modulePaths);
|
2024-04-19 15:56:05 +03:00
|
|
|
|
|
|
|
const char* NCryptGetModulePath(NCRYPT_PROV_HANDLE phProvider);
|
2022-02-14 14:23:14 +03:00
|
|
|
#endif
|
|
|
|
|
2021-12-07 02:07:57 +03:00
|
|
|
#endif /* WINPR_LIBWINPR_NCRYPT_NCRYPT_H_ */
|