summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/CAPICertificateSelector.cpp')
-rw-r--r--Swift/QtUI/CAPICertificateSelector.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/Swift/QtUI/CAPICertificateSelector.cpp b/Swift/QtUI/CAPICertificateSelector.cpp
index 44f5793..aa41d70 100644
--- a/Swift/QtUI/CAPICertificateSelector.cpp
+++ b/Swift/QtUI/CAPICertificateSelector.cpp
@@ -1,49 +1,51 @@
/*
* Copyright (c) 2012 Isode Limited, London, England.
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <string>
+#include "CAPICertificateSelector.h"
+
#define SECURITY_WIN32
#include <Windows.h>
#include <WinCrypt.h>
#include <cryptuiapi.h>
-#include "CAPICertificateSelector.h"
+#include <boost/algorithm/string.hpp>
namespace Swift {
#define cert_dlg_title L"TLS Client Certificate Selection"
#define cert_dlg_prompt L"Select a certificate to use for authentication"
/////Hmm, maybe we should not exlude the "location" column
#define exclude_columns CRYPTUI_SELECT_LOCATION_COLUMN \
|CRYPTUI_SELECT_INTENDEDUSE_COLUMN
static std::string getCertUri(PCCERT_CONTEXT cert, const char * cert_store_name) {
DWORD required_size;
char * comma;
char * p_in;
char * p_out;
char * subject_name;
std::string ret = std::string("certstore:") + cert_store_name + ":";
required_size = CertNameToStrA(cert->dwCertEncodingType,
&cert->pCertInfo->Subject,
/* Discard attribute names: */
CERT_SIMPLE_NAME_STR | CERT_NAME_STR_REVERSE_FLAG,
NULL,
0);
subject_name = static_cast<char *>(malloc(required_size+1));
if (!CertNameToStrA(cert->dwCertEncodingType,
&cert->pCertInfo->Subject,
/* Discard attribute names: */
CERT_SIMPLE_NAME_STR | CERT_NAME_STR_REVERSE_FLAG,
subject_name,
required_size)) {
return "";
@@ -102,37 +104,40 @@ std::string selectCAPICertificate() {
if (!hstore) {
return "";
}
////Does this handle need to be freed as well?
hwnd = GetForegroundWindow();
if (!hwnd) {
hwnd = GetActiveWindow();
}
/* Call Windows dialog to select a suitable certificate */
cert = CryptUIDlgSelectCertificateFromStore(hstore,
hwnd,
cert_dlg_title,
cert_dlg_prompt,
exclude_columns,
0,
NULL);
if (hstore) {
CertCloseStore(hstore, 0);
}
if (cert) {
std::string ret = getCertUri(cert, cert_store_name);
CertFreeCertificateContext(cert);
return ret;
} else {
return "";
}
}
+bool isCAPIURI(std::string uri) {
+ return (boost::iequals(uri.substr(0, 10), "certstore:"));
+}
}