Browse Source

Wrap ImportKeyWithFprReturn

master
Thomas 4 months ago
parent
commit
eb4ff373b5
3 changed files with 59 additions and 40 deletions
  1. +54
    -39
      CpEpEngine.cpp
  2. +1
    -0
      CpEpEngine.h
  3. +4
    -1
      pEpCOMServerAdapter.idl

+ 54
- 39
CpEpEngine.cpp View File

@ -69,44 +69,7 @@ STDMETHODIMP CpEpEngine::ConfigCipherSuite(pEpCipherSuite cipherSuite)
STDMETHODIMP CpEpEngine::ImportKey(BSTR keyData, LPSAFEARRAY * privateKeys)
{
assert(keyData);
if (!keyData)
return E_INVALIDARG;
string key_data = utf8_string(keyData);
size_t size = SysStringLen(keyData);
::identity_list *private_keys = nullptr;
PEP_STATUS status = passphrase_cache.api(::import_key, session(), key_data.c_str(), size, &private_keys);
assert(status != ::PEP_OUT_OF_MEMORY);
if (status == ::PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
if ((status != PEP_STATUS_OK) && (status != PEP_KEY_IMPORTED))
return FAIL(L"import_key", status);
SAFEARRAY * _privateKeys = nullptr;
try {
_privateKeys = array_from_C<pEpIdentity, identity_list>(private_keys);
}
catch (exception& ex)
{
::free_identity_list(private_keys);
try {
dynamic_cast<bad_alloc&>(ex);
}
catch (bad_cast&)
{
return FAIL(ex.what());
}
return E_OUTOFMEMORY;
}
free_identity_list(private_keys);
*privateKeys = _privateKeys;
return status;
return ImportKeyWithFprReturn(keyData, privateKeys, NULL);
}
@ -2182,7 +2145,7 @@ STDMETHODIMP CpEpEngine::SetIdentity(struct pEpIdentity* identity) {
return FAIL(ex.what());
}
PEP_STATUS status = ::set_identity(session(), _ident);
PEP_STATUS status = passphrase_cache.api(::set_identity, session(), (const ::pEp_identity*)_ident);
::free_identity(_ident);
if (status != PEP_STATUS_OK)
return FAIL(_T("SetIdentity"), status);
@ -2221,3 +2184,55 @@ STDMETHODIMP CpEpEngine::SetCommPartnerKey(pEpIdentity* identity, BSTR fpr) {
return S_OK;
}
STDMETHODIMP CpEpEngine::ImportKeyWithFprReturn(BSTR keyData, LPSAFEARRAY* privateKeys, LPSAFEARRAY* importedKeys)
{
assert(keyData);
if (!keyData)
return E_INVALIDARG;
string key_data = utf8_string(keyData);
size_t size = SysStringLen(keyData);
::identity_list* private_keys = nullptr;
::stringlist_t* imported_keys = nullptr;
if (importedKeys) {
imported_keys = new_stringlist(*importedKeys);
}
PEP_STATUS status = passphrase_cache.api(::import_key_with_fpr_return, session(), key_data.c_str(), size, &private_keys, &imported_keys, (uint64_t*)nullptr);
assert(status != ::PEP_OUT_OF_MEMORY);
if (status == ::PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
if ((status != PEP_STATUS_OK) && (status != PEP_KEY_IMPORTED))
return FAIL(L"ImportKeyWithFprReturn", status);
SAFEARRAY* _privateKeys = nullptr;
try {
_privateKeys = array_from_C<pEpIdentity, identity_list>(private_keys);
}
catch (exception& ex)
{
::free_identity_list(private_keys);
try {
dynamic_cast<bad_alloc&>(ex);
}
catch (bad_cast&)
{
return FAIL(ex.what());
}
return E_OUTOFMEMORY;
}
free_identity_list(private_keys);
*privateKeys = _privateKeys;
if (imported_keys) {
if (importedKeys) {
*importedKeys = string_array(imported_keys);
}
free_stringlist(imported_keys);
}
return status;
}

+ 1
- 0
CpEpEngine.h View File

@ -194,6 +194,7 @@ public:
STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
STDMETHOD(ImportKey)(BSTR keyData, LPSAFEARRAY *privateKeys);
STDMETHOD(ImportKeyWithFprReturn)(BSTR keyData, LPSAFEARRAY* privateKeys, LPSAFEARRAY* importedKeys);
// keymanagement API


+ 4
- 1
pEpCOMServerAdapter.idl View File

@ -554,8 +554,11 @@ interface IpEpEngine : IUnknown {
// Sets the identity
[id(69)] HRESULT SetIdentity([in] struct pEpIdentity* identity);
// Sets the identity
// Sets the default key fingerprint for the identity
[id(70)] HRESULT SetCommPartnerKey([in] struct pEpIdentity* identity, [in] BSTR fpr);
// Imports keys from data, return optional list of fprs imported
[id(71)] HRESULT ImportKeyWithFprReturn([in] BSTR keyData, [out] SAFEARRAY(struct pEpIdentity)* privateKeys, [out] SAFEARRAY(BSTR)* importedKeys);
};
[


Loading…
Cancel
Save