COM-50: Handshake Requests need to be decoupled.
authorMarkus Schaber <markus@pep-security.net>
Mon, 13 Feb 2017 21:51:18 +0100
changeset 23670982ee747c5
parent 235 581e3f7a92f5
child 237 589b9cb32b07
COM-50: Handshake Requests need to be decoupled.

Allow reentrant call to deliver timeout of handshake, so the dialog is aborted.

Fix memory leak.
CpEpEngine.cpp
     1.1 --- a/CpEpEngine.cpp	Sun Feb 12 23:02:53 2017 +0100
     1.2 +++ b/CpEpEngine.cpp	Mon Feb 13 21:51:18 2017 +0100
     1.3 @@ -1371,8 +1371,57 @@
     1.4      CpEpEngine *me = (CpEpEngine *)obj;
     1.5  
     1.6      if (me->notify_handshake_active) {
     1.7 -        // We don't support concurrent handshakes currently...
     1.8 -        me->FAIL("Reentrant notify_handshake call!");
     1.9 +        // We don't support concurrent handshakes currently, 
    1.10 +        // with the exception of an abort of the handshake, 
    1.11 +        // which we deliver synchroneously (as it's non-blocking).
    1.12 +        if (signal == SYNC_NOTIFY_TIMEOUT) {
    1.13 +            pEpIdentity timeout_self;
    1.14 +            pEpIdentity timeout_partner;
    1.15 +            SyncHandshakeSignal timeout_signal = (SyncHandshakeSignal)signal;
    1.16 +            copy_identity(&timeout_self, self);
    1.17 +            copy_identity(&timeout_partner, partner);
    1.18 +            SyncHandshakeResult result;
    1.19 +            auto res = me->client_callbacks_on_sync_thread->NotifyHandshake(&timeout_self, &timeout_partner, timeout_signal, &result);
    1.20 +
    1.21 +            clear_identity_s(timeout_self);
    1.22 +            clear_identity_s(timeout_partner);
    1.23 +
    1.24 +            if (FAILED(res)) {
    1.25 +                IErrorInfo* errorInfo = NULL;
    1.26 +                if (FAILED(GetErrorInfo(0, &errorInfo)))
    1.27 +                    errorInfo = NULL;
    1.28 +
    1.29 +                // The _com_error takes ownership of the errorInfo
    1.30 +                // and will Release() it. It can also cope with
    1.31 +                // NULL errorInfos.
    1.32 +                _com_error error(res, errorInfo);
    1.33 +
    1.34 +                string _description = utf8_string(
    1.35 +                    error.ErrorMessage());
    1.36 +
    1.37 +                string _comment = utf8_string(error.Description());
    1.38 +
    1.39 +                auto source = error.Source();
    1.40 +                if (source.length() > 0) {
    1.41 +                    _comment += "\r\nSource: ";
    1.42 +                    _comment += utf8_string(source);
    1.43 +                }
    1.44 +
    1.45 +                ::log_event(me->keysync_session,
    1.46 +                    "Error on NotifyHandshakeTimeout",
    1.47 +                    "pEp COM Adapter",
    1.48 +                    _description.c_str(),
    1.49 +                    _comment.c_str());
    1.50 +
    1.51 +                return PEP_UNKNOWN_ERROR;
    1.52 +            }
    1.53 +
    1.54 +            if (res != S_OK)
    1.55 +
    1.56 +            return PEP_STATUS_OK;
    1.57 +        }
    1.58 +
    1.59 +        ::log_event(me->keysync_session, "Reentrant notify_handshake call!", "pEp COM Adapter", NULL, NULL);
    1.60          return PEP_UNKNOWN_ERROR;
    1.61      }
    1.62  
    1.63 @@ -1457,6 +1506,8 @@
    1.64      }
    1.65      notify_handshake_error_info = NULL;
    1.66  
    1.67 +    clear_identity_s(notify_handshake_self);
    1.68 +    clear_identity_s(notify_handshake_partner);
    1.69      notify_handshake_active = false;
    1.70      notify_handshake_finished = false;
    1.71  }