2012-12-22 11:23:58 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Cryptography API (CryptoAPI)
|
|
|
|
*
|
2013-10-11 12:01:07 +04:00
|
|
|
* Copyright 2012-2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2012-12-22 11:23:58 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 12:08:00 +03:00
|
|
|
#include <winpr/config.h>
|
2012-12-22 11:23:58 +04:00
|
|
|
|
|
|
|
#include <winpr/crypto.h>
|
|
|
|
|
|
|
|
/**
|
2012-12-22 11:39:39 +04:00
|
|
|
* CertOpenStore
|
|
|
|
* CertCloseStore
|
|
|
|
* CertControlStore
|
|
|
|
* CertDuplicateStore
|
|
|
|
* CertSaveStore
|
|
|
|
* CertRegisterPhysicalStore
|
|
|
|
* CertRegisterSystemStore
|
|
|
|
* CertAddStoreToCollection
|
|
|
|
* CertRemoveStoreFromCollection
|
|
|
|
* CertOpenSystemStoreA
|
|
|
|
* CertOpenSystemStoreW
|
|
|
|
* CertEnumPhysicalStore
|
|
|
|
* CertEnumSystemStore
|
|
|
|
* CertEnumSystemStoreLocation
|
|
|
|
* CertSetStoreProperty
|
|
|
|
* CertUnregisterPhysicalStore
|
|
|
|
* CertUnregisterSystemStore
|
|
|
|
*
|
2012-12-22 11:23:58 +04:00
|
|
|
* CertAddCertificateContextToStore
|
|
|
|
* CertAddCertificateLinkToStore
|
|
|
|
* CertAddCRLContextToStore
|
|
|
|
* CertAddCRLLinkToStore
|
|
|
|
* CertAddCTLContextToStore
|
|
|
|
* CertAddCTLLinkToStore
|
|
|
|
* CertAddEncodedCertificateToStore
|
|
|
|
* CertAddEncodedCertificateToSystemStoreA
|
|
|
|
* CertAddEncodedCertificateToSystemStoreW
|
|
|
|
* CertAddEncodedCRLToStore
|
|
|
|
* CertAddEncodedCTLToStore
|
|
|
|
* CertAddSerializedElementToStore
|
|
|
|
* CertDeleteCertificateFromStore
|
|
|
|
* CertDeleteCRLFromStore
|
|
|
|
* CertDeleteCTLFromStore
|
|
|
|
* CertGetCRLFromStore
|
|
|
|
* CertEnumCertificatesInStore
|
|
|
|
* CertEnumCRLsInStore
|
|
|
|
* CertEnumCTLsInStore
|
|
|
|
* CertFindCertificateInStore
|
|
|
|
* CertFindChainInStore
|
|
|
|
* CertFindCRLInStore
|
|
|
|
* CertFindCTLInStore
|
|
|
|
* CertGetIssuerCertificateFromStore
|
|
|
|
* CertGetStoreProperty
|
|
|
|
* CertGetSubjectCertificateFromStore
|
|
|
|
* CertSerializeCertificateStoreElement
|
|
|
|
* CertSerializeCRLStoreElement
|
|
|
|
* CertSerializeCTLStoreElement
|
|
|
|
*
|
|
|
|
* CertAddEnhancedKeyUsageIdentifier
|
|
|
|
* CertAddRefServerOcspResponse
|
|
|
|
* CertAddRefServerOcspResponseContext
|
|
|
|
* CertAlgIdToOID
|
|
|
|
* CertCloseServerOcspResponse
|
|
|
|
* CertCompareCertificate
|
|
|
|
* CertCompareCertificateName
|
|
|
|
* CertCompareIntegerBlob
|
|
|
|
* CertComparePublicKeyInfo
|
|
|
|
* CertCreateCertificateChainEngine
|
|
|
|
* CertCreateCertificateContext
|
|
|
|
* CertCreateContext
|
|
|
|
* CertCreateCRLContext
|
|
|
|
* CertCreateCTLContext
|
|
|
|
* CertCreateCTLEntryFromCertificateContextProperties
|
|
|
|
* CertCreateSelfSignCertificate
|
|
|
|
* CertDuplicateCertificateChain
|
|
|
|
* CertDuplicateCertificateContext
|
|
|
|
* CertDuplicateCRLContext
|
|
|
|
* CertDuplicateCTLContext
|
|
|
|
* CertEnumCertificateContextProperties
|
|
|
|
* CertEnumCRLContextProperties
|
|
|
|
* CertEnumCTLContextProperties
|
|
|
|
* CertEnumSubjectInSortedCTL
|
|
|
|
* CertFindAttribute
|
|
|
|
* CertFindCertificateInCRL
|
|
|
|
* CertFindExtension
|
|
|
|
* CertFindRDNAttr
|
|
|
|
* CertFindSubjectInCTL
|
|
|
|
* CertFindSubjectInSortedCTL
|
|
|
|
* CertFreeCertificateChain
|
|
|
|
* CertFreeCertificateChainEngine
|
|
|
|
* CertFreeCertificateChainList
|
|
|
|
* CertFreeCertificateContext
|
|
|
|
* CertFreeCRLContext
|
|
|
|
* CertFreeCTLContext
|
|
|
|
* CertFreeServerOcspResponseContext
|
|
|
|
* CertGetCertificateChain
|
|
|
|
* CertGetCertificateContextProperty
|
|
|
|
* CertGetCRLContextProperty
|
|
|
|
* CertGetCTLContextProperty
|
|
|
|
* CertGetEnhancedKeyUsage
|
|
|
|
* CertGetIntendedKeyUsage
|
|
|
|
* CertGetNameStringA
|
|
|
|
* CertGetNameStringW
|
|
|
|
* CertGetPublicKeyLength
|
|
|
|
* CertGetServerOcspResponseContext
|
|
|
|
* CertGetValidUsages
|
|
|
|
* CertIsRDNAttrsInCertificateName
|
|
|
|
* CertIsStrongHashToSign
|
|
|
|
* CertIsValidCRLForCertificate
|
|
|
|
* CertNameToStrA
|
|
|
|
* CertNameToStrW
|
|
|
|
* CertOIDToAlgId
|
|
|
|
* CertOpenServerOcspResponse
|
|
|
|
* CertRDNValueToStrA
|
|
|
|
* CertRDNValueToStrW
|
|
|
|
* CertRemoveEnhancedKeyUsageIdentifier
|
|
|
|
* CertResyncCertificateChainEngine
|
|
|
|
* CertRetrieveLogoOrBiometricInfo
|
|
|
|
* CertSelectCertificateChains
|
|
|
|
* CertSetCertificateContextPropertiesFromCTLEntry
|
|
|
|
* CertSetCertificateContextProperty
|
|
|
|
* CertSetCRLContextProperty
|
|
|
|
* CertSetCTLContextProperty
|
|
|
|
* CertSetEnhancedKeyUsage
|
|
|
|
* CertStrToNameA
|
|
|
|
* CertStrToNameW
|
|
|
|
* CertVerifyCertificateChainPolicy
|
|
|
|
* CertVerifyCRLRevocation
|
|
|
|
* CertVerifyCRLTimeValidity
|
|
|
|
* CertVerifyCTLUsage
|
|
|
|
* CertVerifyRevocation
|
|
|
|
* CertVerifySubjectCertificateContext
|
|
|
|
* CertVerifyTimeValidity
|
|
|
|
* CertVerifyValidityNesting
|
|
|
|
*/
|
|
|
|
|
2013-10-11 12:01:07 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2012-12-22 11:23:58 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2013-10-11 12:01:07 +04:00
|
|
|
#include "crypto.h"
|
|
|
|
|
|
|
|
HCERTSTORE CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType,
|
2019-11-06 17:24:51 +03:00
|
|
|
HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void* pvPara)
|
2013-10-11 12:01:07 +04:00
|
|
|
{
|
|
|
|
WINPR_CERTSTORE* certstore;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
certstore = (WINPR_CERTSTORE*)calloc(1, sizeof(WINPR_CERTSTORE));
|
2013-10-11 12:01:07 +04:00
|
|
|
|
|
|
|
if (certstore)
|
|
|
|
{
|
|
|
|
certstore->lpszStoreProvider = lpszStoreProvider;
|
|
|
|
certstore->dwMsgAndCertEncodingType = dwMsgAndCertEncodingType;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return (HCERTSTORE)certstore;
|
2013-10-11 12:01:07 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 20:35:08 +04:00
|
|
|
HCERTSTORE CertOpenSystemStoreW(HCRYPTPROV_LEGACY hProv, LPCWSTR szSubsystemProtocol)
|
|
|
|
{
|
2013-10-11 12:01:07 +04:00
|
|
|
HCERTSTORE hCertStore;
|
|
|
|
|
|
|
|
hCertStore = CertOpenStore(CERT_STORE_PROV_FILE, X509_ASN_ENCODING, hProv, 0, NULL);
|
|
|
|
|
|
|
|
return hCertStore;
|
2013-01-03 20:35:08 +04:00
|
|
|
}
|
2012-12-22 11:23:58 +04:00
|
|
|
|
2013-01-03 20:35:08 +04:00
|
|
|
HCERTSTORE CertOpenSystemStoreA(HCRYPTPROV_LEGACY hProv, LPCSTR szSubsystemProtocol)
|
|
|
|
{
|
|
|
|
return CertOpenSystemStoreW(hProv, NULL);
|
|
|
|
}
|
|
|
|
|
2013-01-05 21:35:24 +04:00
|
|
|
BOOL CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
|
|
|
|
{
|
2013-10-11 12:01:07 +04:00
|
|
|
WINPR_CERTSTORE* certstore;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
certstore = (WINPR_CERTSTORE*)hCertStore;
|
2013-10-11 12:01:07 +04:00
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(certstore);
|
2013-10-11 12:01:07 +04:00
|
|
|
|
2013-01-05 21:35:24 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-01-03 20:35:08 +04:00
|
|
|
PCCERT_CONTEXT CertFindCertificateInStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType,
|
2019-11-06 17:24:51 +03:00
|
|
|
DWORD dwFindFlags, DWORD dwFindType,
|
|
|
|
const void* pvFindPara, PCCERT_CONTEXT pPrevCertContext)
|
2013-01-03 20:35:08 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return (PCCERT_CONTEXT)1;
|
2013-01-03 20:35:08 +04:00
|
|
|
}
|
2012-12-22 11:23:58 +04:00
|
|
|
|
2013-01-05 21:35:24 +04:00
|
|
|
PCCERT_CONTEXT CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrevCertContext)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return (PCCERT_CONTEXT)NULL;
|
2013-01-05 21:35:24 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
DWORD CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void* pvTypePara,
|
|
|
|
LPWSTR pszNameString, DWORD cchNameString)
|
2013-01-05 21:35:24 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
DWORD CertGetNameStringA(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void* pvTypePara,
|
|
|
|
LPSTR pszNameString, DWORD cchNameString)
|
2013-01-05 21:35:24 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 11:23:58 +04:00
|
|
|
#endif
|