This is the C++ code:
#include "stdafx.h"
#include <Windows.h>
#include <wincrypt.h>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
HCERTSTORE mystore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, NULL, CERT_SYSTEM_STORE_CURRENT_USER, L"My");
if (!mystore) {
std::cout << "Failed to open store" << std::endl;
return -1;
}
TCHAR pszNameString[256] = { 0 };
PCCERT_CONTEXT pcert = nullptr;
while (pcert = CertEnumCertificatesInStore(mystore, pcert)) {
auto res = CertGetNameString(pcert, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, nullptr, pszNameString, 128);
if (res) {
std::wcout << "Found certificate: " << pszNameString << std::endl;
DWORD usage_size = 0;
PCERT_ENHKEY_USAGE usage = nullptr;
(void)CertGetEnhancedKeyUsage(pcert, CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG, NULL, &usage_size);
usage = (PCERT_ENHKEY_USAGE)new char[usage_size];
BOOL got_usages = CertGetEnhancedKeyUsage(pcert, CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG, usage, &usage_size);
if (got_usages)
{
BOOL set_usages = CertSetEnhancedKeyUsage(pcert, usage);
if (!set_usages) {
std::cout << "Failed to set key usages: " << std::hex << GetLastError() << std::endl;
}
BOOL removed = CertRemoveEnhancedKeyUsageIdentifier(pcert, "1.3.6.1.4.1.[login to view URL]");
if (!removed) {
std::cout << "Error: " << std::hex << GetLastError() << std::endl;
}
}
}
};
CertCloseStore(mystore, 0);
return 0;
}
The code sets first set all purposes for a certificate
and then removes one of the purposes (= 1.3.6.1.4.1.[login to view URL])
I want to call this from a C# program with functions
To set all purposes for Certificate
bool SetAllPurposesForCertificate( X509Certificate2 cert) {...}
To remove one type of purpose from a Certificate
bool RemovePurposeFromCertificate(X509Certificate2 cert, string keyUsageIdentifier) { ... }
Hello
I have read your requirements and decide to work with you.
I am PHP developer since last 5 year .
I have already worked with 5 big projects in php if you interested then i will show you.
I'll give you the good design and functionality.
I`ll provide you daily status reports of your project.
My criteria is to give high quality work to my client.
Thank you.