COM-52: Expose Encrypt for Identity (Myself) function in COM api
authorMarkus Schaber <markus@pep-security.net>
Mon, 06 Mar 2017 21:40:27 +0100
changeset 2380f19cbd5f1cd
parent 237 589b9cb32b07
child 239 1435b23368a6
COM-52: Expose Encrypt for Identity (Myself) function in COM api
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
     1.1 --- a/CpEpEngine.cpp	Tue Feb 21 12:43:43 2017 +0100
     1.2 +++ b/CpEpEngine.cpp	Mon Mar 06 21:40:27 2017 +0100
     1.3 @@ -862,6 +862,46 @@
     1.4      return S_OK;
     1.5  }
     1.6  
     1.7 +
     1.8 +STDMETHODIMP CpEpEngine::EncryptMessageForSelf(pEpIdentity * target_id, TextMessage * src, TextMessage * dst)
     1.9 +{
    1.10 +    assert(target_id);
    1.11 +    assert(src);
    1.12 +    assert(dst);
    1.13 +
    1.14 +    if (!(target_id && src && dst))
    1.15 +        return E_INVALIDARG;
    1.16 +
    1.17 +    ::pEp_identity *_target_id = new_identity(target_id);
    1.18 +
    1.19 +    ::message *_src = text_message_to_C(src);
    1.20 +
    1.21 +    // COM-19: Initialize msg_dst to NULL, or we end up calling
    1.22 +    // free_message() below with a pointer to random garbage in
    1.23 +    // case of an error in encrypt_message().
    1.24 +    ::message *msg_dst = NULL;
    1.25 +    PEP_STATUS status = ::encrypt_message_for_self(get_session(), _target_id, _src, &msg_dst, PEP_enc_PEP);
    1.26 +
    1.27 +    if (status == PEP_STATUS_OK)
    1.28 +        text_message_from_C(dst, msg_dst);
    1.29 +    else
    1.30 +        text_message_from_C(dst, _src);
    1.31 +
    1.32 +    ::free_message(msg_dst);
    1.33 +    ::free_message(_src);
    1.34 +    ::free_identity(_target_id);
    1.35 +
    1.36 +    if (status == PEP_OUT_OF_MEMORY)
    1.37 +        return E_OUTOFMEMORY;
    1.38 +
    1.39 +    // Different to encrypt_message, this should never fail (we ought to always
    1.40 +    // have a private key for ourself).#
    1.41 +    if (status != PEP_STATUS_OK)
    1.42 +        return FAIL("Failure to encrypt message", status);
    1.43 +
    1.44 +    return S_OK;
    1.45 +}
    1.46 +
    1.47  STDMETHODIMP CpEpEngine::DecryptMessage(TextMessage * src, TextMessage * dst, SAFEARRAY ** keylist, pEpDecryptFlags *flags, pEpRating *rating)
    1.48  {
    1.49      assert(src);
     2.1 --- a/CpEpEngine.h	Tue Feb 21 12:43:43 2017 +0100
     2.2 +++ b/CpEpEngine.h	Mon Mar 06 21:40:27 2017 +0100
     2.3 @@ -214,6 +214,8 @@
     2.4      STDMETHOD(IdentityRating)(pEpIdentity * ident, pEpRating * pVal);
     2.5  	STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
     2.6  
     2.7 +    STDMETHOD(EncryptMessageForSelf)(pEpIdentity * target_id, TextMessage* src, TextMessage *dst);
     2.8 +
     2.9  	// Event callbacks
    2.10  
    2.11  	STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
     3.1 --- a/pEpCOMServerAdapter.idl	Tue Feb 21 12:43:43 2017 +0100
     3.2 +++ b/pEpCOMServerAdapter.idl	Mon Mar 06 21:40:27 2017 +0100
     3.3 @@ -284,6 +284,12 @@
     3.4          [in, defaultvalue(0)] VARIANT_BOOL full,
     3.5          [out, retval] BSTR * words
     3.6      );
     3.7 +
     3.8 +    HRESULT EncryptMessageForSelf(
     3.9 +        [in] struct pEpIdentity* target_id,
    3.10 +        [in] struct TextMessage* src, 
    3.11 +        [out] struct TextMessage* dst
    3.12 +    );
    3.13  };
    3.14  
    3.15  [