eap::get_cert_title() moved from TLS_UI to TLS

This commit is contained in:
Simon Rozman 2016-07-19 12:03:02 +02:00
parent 0ee9bade32
commit faea2f3771
4 changed files with 51 additions and 49 deletions

View File

@ -20,12 +20,22 @@
#include <sal.h>
#include <WinStd/Common.h>
#include <Windows.h>
#include <WinCrypt.h> // Must include after <Windows.h>
namespace eap
{
///
/// TLS configuration
///
class config_tls;
///
/// Helper function to compile human-readable certificate name for UI display
///
winstd::tstring get_cert_title(PCCERT_CONTEXT cert);
}
namespace eapserial

View File

@ -20,10 +20,48 @@
#include "StdAfx.h"
#pragma comment(lib, "Cryptui.lib")
using namespace std;
using namespace winstd;
//////////////////////////////////////////////////////////////////////
// eap::get_cert_title
//////////////////////////////////////////////////////////////////////
tstring eap::get_cert_title(PCCERT_CONTEXT cert)
{
tstring name, str, issuer, title;
FILETIME ft;
SYSTEMTIME st;
// Prepare certificate information
CertGetNameString(cert, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, name);
title += name;
FileTimeToLocalFileTime(&(cert->pCertInfo->NotBefore), &ft);
FileTimeToSystemTime(&ft, &st);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, str);
title += _T(", ");
title += str;
FileTimeToLocalFileTime(&(cert->pCertInfo->NotAfter ), &ft);
FileTimeToSystemTime(&ft, &st);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, str);
title += _T('-');
title += str;
CertGetNameString(cert, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, issuer);
if (name != issuer) {
title += _T(", ");
title += issuer;
}
return title;
}
//////////////////////////////////////////////////////////////////////
// eap::config_tls
//////////////////////////////////////////////////////////////////////

View File

@ -27,8 +27,8 @@
#include <wx/filedlg.h>
#include <wx/msgdlg.h>
#include <cryptuiapi.h>
#include <Windows.h>
#include <cryptuiapi.h>
#include <WinCrypt.h> // Must include after <Windows.h>
#include <list>
@ -75,14 +75,6 @@ template <class _Tprov> class wxEAPTLSCredentialsConfigPanel;
///
template <class _Tprov> class wxEAPTLSConfigPanel;
namespace eap
{
///
/// Helper function to compile human-readable certificate name for UI display
///
void get_cert_title(PCCERT_CONTEXT cert, winstd::tstring &title);
}
#pragma once
#include "../res/wxTLS_UI.h"
@ -297,8 +289,7 @@ protected:
m_cred.m_cert &&
m_cred.m_cert->cbCertEncoded == data->m_cert->cbCertEncoded &&
memcmp(m_cred.m_cert->pbCertEncoded, data->m_cert->pbCertEncoded, m_cred.m_cert->cbCertEncoded) == 0;
winstd::tstring name;
eap::get_cert_title(cert, name);
winstd::tstring name(std::move(eap::get_cert_title(cert)));
int i = m_cert_select_val->Append(name, data.release());
if (is_selected) {
m_cert_select_val->SetSelection(i);

View File

@ -20,46 +20,9 @@
#include "StdAfx.h"
#pragma comment(lib, "Cryptui.lib")
#pragma comment(lib, "Crypt32.lib")
//////////////////////////////////////////////////////////////////////
// eap::get_cert_title
//////////////////////////////////////////////////////////////////////
void eap::get_cert_title(PCCERT_CONTEXT cert, winstd::tstring &title)
{
winstd::tstring name, str, issuer;
FILETIME ft;
SYSTEMTIME st;
title.clear();
// Prepare certificate information
CertGetNameString(cert, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, name);
title += name;
FileTimeToLocalFileTime(&(cert->pCertInfo->NotBefore), &ft);
FileTimeToSystemTime(&ft, &st);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, str);
title += _T(", ");
title += str;
FileTimeToLocalFileTime(&(cert->pCertInfo->NotAfter ), &ft);
FileTimeToSystemTime(&ft, &st);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, str);
title += _T('-');
title += str;
CertGetNameString(cert, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, issuer);
if (name != issuer) {
title += _T(", ");
title += issuer;
}
}
//////////////////////////////////////////////////////////////////////
// wxCertificateClientData
//////////////////////////////////////////////////////////////////////