COM-74: Expose _PEP_enc_format to app for EncryptMessage COM-74
authorMarkus Schaber <markus@pep-security.net>
Sat, 13 Jan 2018 14:02:03 +0100
branchCOM-74
changeset 267ae02fcd56811
parent 264 aa6bd84bd6c3
child 270 c713a265866f
COM-74: Expose _PEP_enc_format to app for EncryptMessage
CpEpEngine.cpp
CpEpEngine.h
pEpCOMServerAdapter.idl
     1.1 --- a/CpEpEngine.cpp	Fri Dec 01 19:38:09 2017 +0100
     1.2 +++ b/CpEpEngine.cpp	Sat Jan 13 14:02:03 2018 +0100
     1.3 @@ -831,6 +831,11 @@
     1.4  
     1.5  STDMETHODIMP CpEpEngine::EncryptMessage(TextMessage * src, TextMessage * dst, SAFEARRAY * extra, pEpEncryptFlags flags)
     1.6  {
     1.7 +	return EncryptMessage2(src, dst, extra, flags, pEpEncPep);
     1.8 +}
     1.9 +
    1.10 +STDMETHODIMP CpEpEngine::EncryptMessage2(TextMessage * src, TextMessage * dst, SAFEARRAY * extra, pEpEncryptFlags flags, pEpEncFormat encFormat)
    1.11 +{
    1.12      assert(src);
    1.13      assert(dst);
    1.14  
    1.15 @@ -839,16 +844,19 @@
    1.16  
    1.17      ::message *_src = text_message_to_C(src);
    1.18  
    1.19 +	_PEP_enc_format _encFormat = (_PEP_enc_format)encFormat;
    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      ::stringlist_t *_extra = new_stringlist(extra); // can cope with NULL
    1.26  
    1.27 -    // _PEP_enc_format is intentionally hardcoded to PEP_enc_PEP:
    1.28 -    // 2016-10-02 14:10 < fdik> schabi: actually, all adapters now must use PEP_enc_PEP
    1.29 +    // _PEP_enc_format used to be intentionally hardcoded to PEP_enc_PEP:
    1.30 +    // Since COM-74, this has been changed to an explicit parameter, to allow the engine to attach
    1.31 +	// the keys and headers to outgoing, unencrypted messages.
    1.32      PEP_encrypt_flags_t engineFlags = (PEP_encrypt_flags_t)flags;
    1.33 -    PEP_STATUS status = ::encrypt_message(get_session(), _src, _extra, &msg_dst, PEP_enc_PEP, engineFlags);
    1.34 +    PEP_STATUS status = ::encrypt_message(get_session(), _src, _extra, &msg_dst, _encFormat, engineFlags);
    1.35      ::free_stringlist(_extra);
    1.36  
    1.37      if (status == PEP_STATUS_OK)
     2.1 --- a/CpEpEngine.h	Fri Dec 01 19:38:09 2017 +0100
     2.2 +++ b/CpEpEngine.h	Sat Jan 13 14:02:03 2018 +0100
     2.3 @@ -22,9 +22,9 @@
     2.4  
     2.5  class ATL_NO_VTABLE CpEpEngine :
     2.6      public CComObjectRootEx<CComObjectThreadModel>,
     2.7 -	public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
     2.8 -	public ISupportErrorInfo,
     2.9 -	public IpEpEngine2
    2.10 +    public CComCoClass<CpEpEngine, &CLSID_pEpEngine>,
    2.11 +    public ISupportErrorInfo,
    2.12 +    public IpEpEngine2
    2.13  {
    2.14  
    2.15  protected:
    2.16 @@ -32,10 +32,10 @@
    2.17  
    2.18  public:
    2.19      CpEpEngine() : keymanagement_thread(NULL), identity_queue(NULL), verbose_mode(false)
    2.20 -	{
    2.21 -		std::lock_guard<std::mutex> lock(init_mutex);
    2.22 -		PEP_STATUS status = ::init(&m_session);
    2.23 -		assert(status == PEP_STATUS_OK);
    2.24 +    {
    2.25 +        std::lock_guard<std::mutex> lock(init_mutex);
    2.26 +        PEP_STATUS status = ::init(&m_session);
    2.27 +        assert(status == PEP_STATUS_OK);
    2.28  
    2.29          ::register_examine_function(m_session, CpEpEngine::examine_identity, (void *)this);
    2.30          ::log_event(m_session, "Startup", "pEp COM Adapter", NULL, NULL);
    2.31 @@ -46,8 +46,8 @@
    2.32          stop_keysync();
    2.33          StopKeyserverLookup();
    2.34          ::log_event(m_session, "Shutdown", "pEp COM Adapter", NULL, NULL);
    2.35 -		std::lock_guard<std::mutex> lock(init_mutex);
    2.36 -		::release(m_session);
    2.37 +        std::lock_guard<std::mutex> lock(init_mutex);
    2.38 +        ::release(m_session);
    2.39      }
    2.40  
    2.41  DECLARE_REGISTRY_RESOURCEID(IDR_PEPENGINE)
    2.42 @@ -61,19 +61,19 @@
    2.43  END_COM_MAP()
    2.44  
    2.45  // ISupportsErrorInfo
    2.46 -	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    2.47 +    STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    2.48  
    2.49  
    2.50 -	DECLARE_PROTECT_FINAL_CONSTRUCT()
    2.51 +    DECLARE_PROTECT_FINAL_CONSTRUCT()
    2.52  
    2.53 -	HRESULT FinalConstruct()
    2.54 -	{
    2.55 -		return S_OK;
    2.56 -	}
    2.57 +    HRESULT FinalConstruct()
    2.58 +    {
    2.59 +        return S_OK;
    2.60 +    }
    2.61  
    2.62 -	void FinalRelease()
    2.63 -	{
    2.64 -	}
    2.65 +    void FinalRelease()
    2.66 +    {
    2.67 +    }
    2.68  
    2.69  
    2.70  protected:
    2.71 @@ -131,19 +131,19 @@
    2.72      bool verbose_mode;
    2.73  
    2.74  
    2.75 -	IpEpEngineCallbacks* client_callbacks = NULL;
    2.76 +    IpEpEngineCallbacks* client_callbacks = NULL;
    2.77      IpEpEngineCallbacks* client_callbacks_on_sync_thread = NULL;
    2.78      IpEpEngineCallbacks2* client_callbacks2_on_sync_thread = NULL;
    2.79      bool client_last_signalled_polling_state = true;
    2.80  
    2.81 -	// Keysync members
    2.82 +    // Keysync members
    2.83      static int inject_sync_msg(void *msg, void* management);
    2.84      static void* retrieve_next_sync_msg(void* management, time_t *timeout);
    2.85      void start_keysync();
    2.86      static void do_keysync_in_thread(CpEpEngine* self, LPSTREAM marshaled_callbacks);
    2.87      void stop_keysync();
    2.88  
    2.89 -	static std::mutex init_mutex;
    2.90 +    static std::mutex init_mutex;
    2.91  
    2.92      std::recursive_mutex keysync_mutex;
    2.93      std::condition_variable_any keysync_condition;
    2.94 @@ -191,8 +191,8 @@
    2.95      STDMETHOD(GetCrashdumpLog)(LONG maxlines, BSTR * log);
    2.96      STDMETHOD(GetEngineVersion)(BSTR * engineVersion);
    2.97      STDMETHOD(GetLanguageList)(BSTR * languages);
    2.98 -	STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
    2.99 -	STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.100 +    STDMETHOD(SetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.101 +    STDMETHOD(UnsetIdentityFlags)(struct pEpIdentity *identity, pEpIdentityFlags flags);
   2.102  
   2.103      // keymanagement API
   2.104  
   2.105 @@ -204,7 +204,7 @@
   2.106      STDMETHOD(KeyMistrusted)(struct pEpIdentity *ident);
   2.107      STDMETHOD(KeyResetTrust)(struct pEpIdentity *ident);
   2.108      STDMETHOD(TrustPersonalKey)(struct pEpIdentity *ident, struct pEpIdentity *result);
   2.109 -	STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   2.110 +    STDMETHOD(OwnIdentitiesRetrieve)(LPSAFEARRAY* ownIdentities);
   2.111  
   2.112      // Blacklist API
   2.113  
   2.114 @@ -220,7 +220,7 @@
   2.115      STDMETHOD(ReEvaluateMessageRating)(TextMessage * msg, SAFEARRAY * x_KeyList, pEpRating x_EncStatus, pEpRating *rating);
   2.116      STDMETHOD(OutgoingMessageRating)(TextMessage *msg, pEpRating * pVal);
   2.117      STDMETHOD(IdentityRating)(pEpIdentity * ident, pEpRating * pVal);
   2.118 -	STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
   2.119 +    STDMETHOD(ColorFromRating)(pEpRating rating, pEpColor * pVal);
   2.120  
   2.121      STDMETHOD(EncryptMessageForSelf)(
   2.122          pEpIdentity * targetId, 
   2.123 @@ -229,19 +229,26 @@
   2.124          pEpEncryptFlags flags
   2.125          );
   2.126  
   2.127 -	// Event callbacks
   2.128 +    STDMETHOD(EncryptMessage2)(
   2.129 +        /* [in] */ struct TextMessage *src,
   2.130 +        /* [out] */ struct TextMessage *dst,
   2.131 +        /* [in] */ SAFEARRAY * extra,
   2.132 +        /* [defaultvalue][in] */ pEpEncryptFlags flags = pEpEncryptFlagDefault,
   2.133 +        /* [defaultvalue][in] */ pEpEncFormat encFormat = pEpEncPep);
   2.134  
   2.135 -	STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
   2.136 -	STDMETHOD(UnregisterCallbacks)();
   2.137 +    // Event callbacks
   2.138 +
   2.139 +    STDMETHOD(RegisterCallbacks)(IpEpEngineCallbacks *new_callback);
   2.140 +    STDMETHOD(UnregisterCallbacks)();
   2.141  
   2.142      // PGP compatibility functions
   2.143      STDMETHOD(OpenPGPListKeyinfo)(BSTR search_pattern, LPSAFEARRAY* keyinfo_list);
   2.144  
   2.145 -	STDMETHOD(UndoLastMistrust)();
   2.146 +    STDMETHOD(UndoLastMistrust)();
   2.147  
   2.148  protected:
   2.149 -	HRESULT Fire_MessageToSend(
   2.150 -		/* [in] */ struct TextMessage *msg);
   2.151 +    HRESULT Fire_MessageToSend(
   2.152 +        /* [in] */ struct TextMessage *msg);
   2.153  };
   2.154  
   2.155  OBJECT_ENTRY_AUTO(__uuidof(pEpEngine), CpEpEngine)
     3.1 --- a/pEpCOMServerAdapter.idl	Fri Dec 01 19:38:09 2017 +0100
     3.2 +++ b/pEpCOMServerAdapter.idl	Sat Jan 13 14:02:03 2018 +0100
     3.3 @@ -304,6 +304,15 @@
     3.4  ]
     3.5  interface IpEpEngine2 : IpEpEngine
     3.6  {
     3.7 +    typedef [v1_enum] enum pEpEncFormat {
     3.8 +        pEpEncNone = 0,                       // message is not encrypted
     3.9 +        pEpEncPieces,                         // inline PGP + PGP extensions
    3.10 +        pEpEncSMime,                          // RFC5751
    3.11 +        pEpEncPgpMime,                        // RFC3156
    3.12 +        pEpEncPep,                            // pEp encryption format
    3.13 +        pEpEncPgpMimeOutlook1                 // Message B0rken by Outlook type 1
    3.14 +    } pEpEncFormat;
    3.15 +
    3.16      HRESULT GetMessageTrustwords(
    3.17          [in] struct TextMessage *msg,
    3.18          [in] struct pEpIdentity * receivedBy,
    3.19 @@ -327,7 +336,17 @@
    3.20          [out, retval] pEpRating *rating
    3.21      );
    3.22  
    3.23 -	HRESULT UndoLastMistrust();
    3.24 +    HRESULT UndoLastMistrust();
    3.25 +
    3.26 +    HRESULT EncryptMessage2(
    3.27 +        [in] struct TextMessage *src,
    3.28 +        [out] struct TextMessage * dst,
    3.29 +        [in] SAFEARRAY(BSTR) extra,
    3.30 +        [in, defaultvalue(pEpEncryptFlagDefault)] pEpEncryptFlags flags,
    3.31 +        // Use pEpEncFormat.pEpEncNone for unencrypted, outgoing messages.
    3.32 +        // Default is pEpEncFormat.pEpEncPep, all other formats are only 
    3.33 +        // for compatibility and not intended for normal use.
    3.34 +        [in, defaultvalue(pEpEncPep)] pEpEncFormat encFormat);
    3.35  };
    3.36  
    3.37  [