Pre-shared credentials moved to heap

This commit is contained in:
Simon Rozman 2016-08-05 11:38:43 +02:00
parent 460adb9858
commit f4be571499
3 changed files with 18 additions and 15 deletions

View File

@ -257,6 +257,9 @@ namespace eap
}; };
class credentials;
template <class _Tcred> template <class _Tcred>
class config_method_with_cred : public config_method class config_method_with_cred : public config_method
{ {
@ -269,7 +272,7 @@ namespace eap
config_method_with_cred(_In_ module *mod) : config_method_with_cred(_In_ module *mod) :
m_allow_save(true), m_allow_save(true),
m_use_preshared(false), m_use_preshared(false),
m_preshared(mod), m_preshared(new _Tcred(mod)),
config_method(mod) config_method(mod)
{ {
} }
@ -283,7 +286,7 @@ namespace eap
config_method_with_cred(_In_ const config_method_with_cred<_Tcred> &other) : config_method_with_cred(_In_ const config_method_with_cred<_Tcred> &other) :
m_allow_save(other.m_allow_save), m_allow_save(other.m_allow_save),
m_use_preshared(other.m_use_preshared), m_use_preshared(other.m_use_preshared),
m_preshared(other.m_preshared), m_preshared((_Tcred*)other.m_preshared->clone()),
config_method(other) config_method(other)
{ {
} }
@ -316,7 +319,7 @@ namespace eap
(config_method&)*this = other; (config_method&)*this = other;
m_allow_save = other.m_allow_save; m_allow_save = other.m_allow_save;
m_use_preshared = other.m_use_preshared; m_use_preshared = other.m_use_preshared;
m_preshared = other.m_preshared; m_preshared.reset((_Tcred*)other.m_preshared->clone());
} }
return *this; return *this;
@ -379,7 +382,7 @@ namespace eap
return false; return false;
} }
if (m_use_preshared && !m_preshared.save(pDoc, pXmlElClientSideCredential, ppEapError)) if (m_use_preshared && !m_preshared->save(pDoc, pXmlElClientSideCredential, ppEapError))
return false; return false;
return true; return true;
@ -402,7 +405,7 @@ namespace eap
m_allow_save = true; m_allow_save = true;
m_use_preshared = false; m_use_preshared = false;
m_preshared.clear(); m_preshared->clear();
// <ClientSideCredential> // <ClientSideCredential>
winstd::com_obj<IXMLDOMElement> pXmlElClientSideCredential; winstd::com_obj<IXMLDOMElement> pXmlElClientSideCredential;
@ -416,7 +419,7 @@ namespace eap
_Tcred preshared(m_module); _Tcred preshared(m_module);
if (preshared.load(pXmlElClientSideCredential, ppEapError)) { if (preshared.load(pXmlElClientSideCredential, ppEapError)) {
m_use_preshared = true; m_use_preshared = true;
m_preshared = std::move(preshared); *m_preshared = std::move(preshared);
} else { } else {
// This is not really an error - merely an indication pre-shared credentials are unavailable. // This is not really an error - merely an indication pre-shared credentials are unavailable.
if (*ppEapError) { if (*ppEapError) {
@ -444,7 +447,7 @@ namespace eap
config_method::operator<<(cursor); config_method::operator<<(cursor);
cursor << m_allow_save; cursor << m_allow_save;
cursor << m_use_preshared; cursor << m_use_preshared;
cursor << m_preshared; cursor << *m_preshared;
} }
@ -459,7 +462,7 @@ namespace eap
config_method::get_pk_size() + config_method::get_pk_size() +
pksizeof(m_allow_save ) + pksizeof(m_allow_save ) +
pksizeof(m_use_preshared) + pksizeof(m_use_preshared) +
pksizeof(m_preshared ); pksizeof(*m_preshared );
} }
@ -473,15 +476,15 @@ namespace eap
config_method::operator>>(cursor); config_method::operator>>(cursor);
cursor >> m_allow_save; cursor >> m_allow_save;
cursor >> m_use_preshared; cursor >> m_use_preshared;
cursor >> m_preshared; cursor >> *m_preshared;
} }
/// @} /// @}
public: public:
bool m_allow_save; ///< Are credentials allowed to be saved to Windows Credential Manager? bool m_allow_save; ///< Are credentials allowed to be saved to Windows Credential Manager?
bool m_use_preshared; ///< Use pre-shared credentials bool m_use_preshared; ///< Use pre-shared credentials
_Tcred m_preshared; ///< Pre-shared credentials std::unique_ptr<_Tcred> m_preshared; ///< Pre-shared credentials
}; };

View File

@ -253,7 +253,7 @@ protected:
else else
m_preshared->SetValue(true); m_preshared->SetValue(true);
m_cred = m_cfg.m_preshared; m_cred = *m_cfg.m_preshared;
return wxEAPCredentialsConfigPanelBase::TransferDataToWindow(); return wxEAPCredentialsConfigPanelBase::TransferDataToWindow();
} }
@ -266,7 +266,7 @@ protected:
if (!m_prov.m_read_only) { if (!m_prov.m_read_only) {
// This is not a provider-locked configuration. Save the data. // This is not a provider-locked configuration. Save the data.
m_cfg.m_use_preshared = !m_own->GetValue(); m_cfg.m_use_preshared = !m_own->GetValue();
m_cfg.m_preshared = m_cred; *m_cfg.m_preshared = m_cred;
} }
return true; return true;

View File

@ -121,7 +121,7 @@ bool eap::peer_ttls::get_identity(
target_inner = L"PAP"; target_inner = L"PAP";
if (cfg_inner_pap->m_use_preshared) { if (cfg_inner_pap->m_use_preshared) {
// Inner PAP: Using preshared credentials. // Inner PAP: Using preshared credentials.
cred_out.m_inner.reset((credentials*)cfg_inner_pap->m_preshared.clone()); cred_out.m_inner.reset((credentials*)cfg_inner_pap->m_preshared->clone());
log_event(&EAPMETHOD_TRACE_EVT_CRED_PRESHARED, event_data(target_inner), event_data(cred_out.m_inner->get_name()), event_data::blank); log_event(&EAPMETHOD_TRACE_EVT_CRED_PRESHARED, event_data(target_inner), event_data(cred_out.m_inner->get_name()), event_data::blank);
is_inner_set = true; is_inner_set = true;
} }