diff --git a/include/linphone/FlexiAPIClient.hh b/include/linphone/FlexiAPIClient.hh index 085524d3704e91d2790c70202ecd00fc3daa8bc7..73b302e7de79095c624acafb761eb40c374c4344 100644 --- a/include/linphone/FlexiAPIClient.hh +++ b/include/linphone/FlexiAPIClient.hh @@ -75,12 +75,14 @@ public: // Public endpoinds FlexiAPIClient *ping(); + FlexiAPIClient *sendAccountCreationToken(); FlexiAPIClient *sendAccountCreationTokenByPush(string pnProvider, string pnParam, string pnPrid); FlexiAPIClient *accountCreationRequestToken(); FlexiAPIClient *accountCreationTokenUsingRequestToken(string token); - FlexiAPIClient *accountCreateWithAccountCreationToken(string username, string password, string algorithm, string token); - FlexiAPIClient *accountCreateWithAccountCreationToken(string username, string domain, string password, - string algorithm, string token); + FlexiAPIClient * + accountCreateWithAccountCreationToken(string username, string password, string algorithm, string token); + FlexiAPIClient *accountCreateWithAccountCreationToken( + string username, string domain, string password, string algorithm, string token); FlexiAPIClient *accountInfo(string sip); FlexiAPIClient *accountActivateEmail(string sip, string code); FlexiAPIClient *accountActivatePhone(string sip, string code); diff --git a/src/FlexiAPIClient.cc b/src/FlexiAPIClient.cc index bf78076943cd18c026abc0fd57ced5f6376800bb..f8cc3b449d07045a1699646a9381ba9b120c77b0 100644 --- a/src/FlexiAPIClient.cc +++ b/src/FlexiAPIClient.cc @@ -81,6 +81,12 @@ FlexiAPIClient *FlexiAPIClient::sendAccountCreationTokenByPush(string pnProvider return this; } +FlexiAPIClient *FlexiAPIClient::sendAccountCreationToken() { + JsonParams params; + prepareAndSendRequest("account_creation_tokens", "POST", params); + return this; +} + FlexiAPIClient *FlexiAPIClient::accountCreationRequestToken() { prepareAndSendRequest("account_creation_request_tokens", "POST"); return this; diff --git a/src/c-wrapper/internal/c-tools.h b/src/c-wrapper/internal/c-tools.h index 46347fb28208a11d0156e4e7cce79a35107e85f0..40675027b896e862cad8cb9ba2e0249e7e5cb769 100644 --- a/src/c-wrapper/internal/c-tools.h +++ b/src/c-wrapper/internal/c-tools.h @@ -231,14 +231,13 @@ public: wrappedObject->weakCppPtr.~weak_ptr(); } - template<typename CppType> - static bool isOwnedByC(void *cObject){ - WrappedBaseObject<CppType> *base = static_cast<WrappedBaseObject<CppType>*>(cObject); + template <typename CppType> + static bool isOwnedByC(void *cObject) { + WrappedBaseObject<CppType> *base = static_cast<WrappedBaseObject<CppType> *>(cObject); return base->owner == WrappedObjectOwner::External; } - template< - typename CType, + template <typename CType, typename CppType = typename CTypeMetaInfo<CType>::cppType, typename = typename std::enable_if<IsDefinedClonableCppObject<CppType>::value, CppType>::type> static void uninitClonableCppObject(CType *cObject) { diff --git a/src/chat/chat-room/server-group-chat-room-p.h b/src/chat/chat-room/server-group-chat-room-p.h index f8767c56ceadc842822d40a59132e4e16e44e693..0074088c2ebc843f7a9d88257f9348d6ab3b169e 100644 --- a/src/chat/chat-room/server-group-chat-room-p.h +++ b/src/chat/chat-room/server-group-chat-room-p.h @@ -193,7 +193,8 @@ private: std::map<std::string, RegistrationSubscriptionContext> registrationSubscriptions; /*map of registrationSubscriptions for each participant*/ int unnotifiedRegistrationSubscriptions = 0; /*count of not-yet notified registration subscriptions*/ - std::shared_ptr<ParticipantDevice> mInitiatorDevice; /*pointer to the ParticipantDevice that is creating the chat room*/ + std::shared_ptr<ParticipantDevice> + mInitiatorDevice; /*pointer to the ParticipantDevice that is creating the chat room*/ std::unordered_map<std::string, std::queue<std::shared_ptr<Message>>> queuedMessages; Utils::Version protocolVersion; bool joiningPendingAfterCreation = false; diff --git a/src/chat/chat-room/server-group-chat-room.cpp b/src/chat/chat-room/server-group-chat-room.cpp index 0f9546a883e3464d7732a452678039024503181f..998477c0ec0cf43ec5ff95251c72d5afe407986f 100644 --- a/src/chat/chat-room/server-group-chat-room.cpp +++ b/src/chat/chat-room/server-group-chat-room.cpp @@ -226,10 +226,8 @@ void ServerGroupChatRoomPrivate::requestDeletion() { LinphoneChatRoom *cChatRoom = L_GET_C_BACK_PTR(chatRoom); /* If the chatroom was created as "external" mode, explicitely unref the C object to destroy it.*/ - if (cChatRoom && Wrapper::isOwnedByC<ServerGroupChatRoom>(cChatRoom)){ - q->getCore()->doLater([cChatRoom](){ - linphone_chat_room_unref(cChatRoom); - }); + if (cChatRoom && Wrapper::isOwnedByC<ServerGroupChatRoom>(cChatRoom)) { + q->getCore()->doLater([cChatRoom]() { linphone_chat_room_unref(cChatRoom); }); } } @@ -1429,7 +1427,6 @@ ServerGroupChatRoom::ServerGroupChatRoom(const shared_ptr<Core> &core, SalCallOp const auto to = Address::create(op->getTo()); session->configure(LinphoneCallIncoming, nullptr, op, from, to); d->protocolVersion = CorePrivate::groupChatProtocolVersion; - } ServerGroupChatRoom::ServerGroupChatRoom(const shared_ptr<Core> &core, diff --git a/src/conference/session/ms2-stream.cpp b/src/conference/session/ms2-stream.cpp index bae3e70d60d61ba8e0fc102e2663a51ce3c3e5bf..b2b9b2a1432108c5d5ccb9a65cb11d0e81ef6529 100644 --- a/src/conference/session/ms2-stream.cpp +++ b/src/conference/session/ms2-stream.cpp @@ -1328,6 +1328,13 @@ void MS2Stream::confirmGoClear() { } } +void MS2Stream::zrtpStarted(BCTBX_UNUSED(Stream *mainZrtpStream)) { + if (getState() == Running && !mRtpBundle) { // No need to start zrtp on secondary streams if bundle is used. + lInfo() << "Trying to start ZRTP encryption on stream" << *this; + startZrtp(); + } +} + void MS2Stream::encryptionChanged() { getGroup().propagateEncryptionChanged(); } diff --git a/src/conference/session/ms2-streams.h b/src/conference/session/ms2-streams.h index 7eb761e178f0a8374608d1a9c1819983f09e37bf..ca4bfa5025933afed0b1a72433431182ebcdb0e0 100644 --- a/src/conference/session/ms2-streams.h +++ b/src/conference/session/ms2-streams.h @@ -85,6 +85,7 @@ public: protected: virtual void handleEvent(const OrtpEvent *ev) = 0; + virtual void zrtpStarted(Stream *mainZrtpStream) override; MS2Stream(StreamsGroup &sm, const OfferAnswerContext ¶ms); void startEventHandling(); void stopEventHandling(); @@ -341,10 +342,10 @@ public: protected: AudioStream *getPeerAudioStream(); virtual void onSnapshotTaken(const std::string &filepath) override; + virtual void zrtpStarted(Stream *mainZrtpStream) override; private: virtual void handleEvent(const OrtpEvent *ev) override; - virtual void zrtpStarted(Stream *mainZrtpStream) override; static void sSnapshotTakenCb(void *userdata, struct _MSFilter *f, unsigned int id, void *arg); void snapshotTakenCb(void *userdata, struct _MSFilter *f, unsigned int id, void *arg); void videoStreamEventCb(const MSFilter *f, const unsigned int eventId, const void *args); diff --git a/src/conference/session/video-stream.cpp b/src/conference/session/video-stream.cpp index 2dda125486c576fb4800c22ca814dea74e041739..bd2d62c425998e27e71d0d05127c02bdbf8b5d12 100644 --- a/src/conference/session/video-stream.cpp +++ b/src/conference/session/video-stream.cpp @@ -145,10 +145,7 @@ void MS2VideoStream::videoStreamEventCb(BCTBX_UNUSED(const MSFilter *f), const u } } - -void MS2VideoStream::sVideoStreamDisplayCb(void *userData, - const unsigned int eventId, - const void *args) { +void MS2VideoStream::sVideoStreamDisplayCb(void *userData, const unsigned int eventId, const void *args) { MS2VideoStream *zis = static_cast<MS2VideoStream *>(userData); zis->videoStreamDisplayCb(eventId, args); } @@ -157,14 +154,14 @@ void MS2VideoStream::videoStreamDisplayCb(const unsigned int eventId, const void CallSessionListener *callListener = getMediaSessionPrivate().getCallSessionListener(); auto participantDevice = getMediaSession().getParticipantDevice(getLabel()); - switch(eventId){ - case MS_VIDEO_DISPLAY_ERROR_OCCURRED : - if (callListener) - callListener->onVideoDisplayErrorOccurred(getMediaSession().getSharedFromThis(), *((int*)args)); - if(participantDevice) - participantDevice->videoDisplayErrorOccurred(*((int*)args)); - break; - default:{} + switch (eventId) { + case MS_VIDEO_DISPLAY_ERROR_OCCURRED: + if (callListener) + callListener->onVideoDisplayErrorOccurred(getMediaSession().getSharedFromThis(), *((int *)args)); + if (participantDevice) participantDevice->videoDisplayErrorOccurred(*((int *)args)); + break; + default: { + } } } @@ -637,10 +634,9 @@ void MS2VideoStream::handleEvent(const OrtpEvent *ev) { mNetworkMonitor.checkNackQuality(mStream->ms.sessions.rtp_session); } -void MS2VideoStream::zrtpStarted(BCTBX_UNUSED(Stream *mainZrtpStream)) { +void MS2VideoStream::zrtpStarted(Stream *mainZrtpStream) { + MS2Stream::zrtpStarted(mainZrtpStream); if (getState() == Running) { - lInfo() << "Trying to start ZRTP encryption on video stream"; - startZrtp(); if (getMediaSessionPrivate().isEncryptionMandatory()) { /* Nothing could have been sent yet so generating key frame */ video_stream_send_vfu(mStream); diff --git a/tester/account_creator_flexiapi_tester.cpp b/tester/account_creator_flexiapi_tester.cpp index 131a55ecb0107dc66629c04b66b11292fddbd098..5a2b44710f83dae521859bb3727d7a8a761aee15 100644 --- a/tester/account_creator_flexiapi_tester.cpp +++ b/tester/account_creator_flexiapi_tester.cpp @@ -239,16 +239,10 @@ static void server_account_send_token(void) { linphone_account_creator_set_pn_prid(creator, "123456789"); linphone_account_creator_cbs_set_send_token(cbs, account_creator_cb); - BC_ASSERT_EQUAL( - linphone_account_creator_send_token_flexiapi(creator), - LinphoneAccountCreatorStatusRequestOk, - LinphoneAccountCreatorStatus, - "%i"); - BC_ASSERT_EQUAL( - linphone_account_creator_account_creation_request_token_flexiapi(creator), - LinphoneAccountCreatorStatusRequestOk, - LinphoneAccountCreatorStatus, - "%i"); + BC_ASSERT_EQUAL(linphone_account_creator_send_token_flexiapi(creator), LinphoneAccountCreatorStatusRequestOk, + LinphoneAccountCreatorStatus, "%i"); + BC_ASSERT_EQUAL(linphone_account_creator_account_creation_request_token_flexiapi(creator), + LinphoneAccountCreatorStatusRequestOk, LinphoneAccountCreatorStatus, "%i"); wait_for_until(marie->lc, NULL, &stats->cb_done, 2, TIMEOUT_REQUEST); ms_free(stats); @@ -322,6 +316,26 @@ static void server_account_created_with_email(void) { linphone_account_creator_cbs_unref(cbs); } +static string obtain_auth_token(LinphoneCoreManager *mgr) { + auto flexiAPIClient = make_shared<FlexiAPIClient>(mgr->lc); + flexiAPIClient->useTestAdminAccount(true); + + int code = 0; + int fetched = 0; + string token; + + // Create the account + flexiAPIClient->sendAccountCreationToken()->then([&code, &fetched, &token](FlexiAPIClient::Response response) { + code = response.code; + fetched = 1; + token = response.json()["token"].asString(); + }); + + wait_for_until(mgr->lc, NULL, &fetched, 1, 10000); + BC_ASSERT_EQUAL(code, 201, int, "%d"); + return token; +} + static void server_account_created_with_phone(void) { LinphoneCoreManager *marie = linphone_core_manager_new_with_proxies_check("account_creator_flexiapi_rc", FALSE); LinphoneAccountCreator *creator = init(marie->lc); @@ -334,6 +348,10 @@ static void server_account_created_with_phone(void) { linphone_account_creator_service_set_user_data(linphone_account_creator_get_service(creator), (void *)LinphoneAccountCreatorStatusAccountCreated); + // Obtain auth token (normally it is sent via push notification. + + string authToken = obtain_auth_token(marie); + // Create string phone = string("000").append(to_string(rand()).substr(0, 6)); string password = "password"; @@ -341,6 +359,7 @@ static void server_account_created_with_phone(void) { linphone_account_creator_set_phone_number(creator, phone.c_str(), "1"); linphone_account_creator_set_email(creator, "username@linphone.org"); linphone_account_creator_set_password(creator, password.c_str()); + linphone_account_creator_set_token(creator, authToken.c_str()); linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb); BC_ASSERT_EQUAL(linphone_account_creator_create_account_flexiapi(creator), LinphoneAccountCreatorStatusRequestOk, diff --git a/tester/call_single_tester.c b/tester/call_single_tester.c index 23518bd1fbccbb234d092c352bcc916e0d83f50d..44d73626a47cd97b4588aa6609683e0d67f81bd8 100644 --- a/tester/call_single_tester.c +++ b/tester/call_single_tester.c @@ -7163,6 +7163,64 @@ static void call_with_unknown_stream_accepted(void) { _call_with_unknown_stream(TRUE); } +static void call_with_maformed_from(void) { + const char *crashing_invite = + "INVITE sip:631453@212.55.48.36:51230;transport=udp SIP/2.0\r\n" + "Via: SIP/2.0/UDP 212.55.48.2:5060;branch=z9hG4bKac1473882254\r\n" + "Max-Forwards: 19\r\n" + "From: \"\r\n\" <sip:mickey@example.com;user=phone>;tag=1c849167855\r\n" + "To: \"Bugs Bunny\" <sip:bunny@example.com>\r\n" + "Call-ID: 9771187781832022142418@212.55.48.2\r\n" + "CSeq: 1 INVITE\r\n" + "Contact: <sip:212.55.48.2:5060>\r\n" + "Supported: 100rel,sdp-anat\r\n" + "Allow: ACK,BYE,CANCEL,INFO,INVITE,OPTIONS,PRACK,REFER,NOTIFY,UPDATE\r\n" + "User-Agent: vSBC PROD/v.7.20A.258.459\r\n" + "Accept:application/media_control+xml,application/sdp,multipart/mixed\r\n" + "Recv-Info:x-broadworks-client-session-info\r\n" + "Content-Type: application/sdp\r\n" + "Content-Length: 860\r\n" + "\r\n" + "v=0\r\n" + "o=BroadWorks 1693848685 415741525 IN IP4 212.55.48.2\r\n" + "s=-\r\n" + "c=IN IP4 212.55.48.2\r\n" + "t=0 0\r\n" + "m=audio 15536 RTP/AVP 8 0 18 116\r\n" + "a=rtpmap:8 PCMA/8000\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:116 telephone-event/8000\r\n" + "a=ptime:20\r\n" + "a=3gOoBTC\r\n" + "a=rtpmap:18 G729/8000\r\n" + "a=fmtp:18 annexb=yes\r\n" + "m=audio 15536 RTP/SAVP 8 0 18 116\r\n" + "a=rtpmap:8 PCMA/8000\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:116 telephone-event/8000\r\n" + "a=ptime:20\r\n" + "a=3gOoBTC\r\n" + "a=rtpmap:18 G729/8000\r\n" + "a=fmtp:18 annexb=yes\r\n" + "a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:zc409/eT1JuwUPQAswLkF878WJvn5Rpo+aLUt+SI|2^31\r\n" + "a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:ebHN/WPPcu2E+Jm4kdx9YK58jVFDKD4uRgwFu18k|2^31\r\n" + "a=crypto:3 AES_256_CM_HMAC_SHA1_80 " + "inline:M9UR+6n8F8DZ5mh/V5vh2VKdYZ+5Hb4K3mwepx8oM9aIQYb7RzdfJE42ezOTcQ==|2^31\r\n" + "a=crypto:4 AES_256_CM_HMAC_SHA1_32 " + "inline:AIsXIk2O8tsCefUYXpqP96hNZKJR+nJZcXlCOiXZW6TDEtg/g5HQD7lcj0KJPA==|2^31\r\n"; + + LinphoneCoreManager *laure = linphone_core_manager_new("laure_rc_udp"); + + LinphoneTransports *tp = linphone_core_get_transports_used(laure->lc); + BC_ASSERT_TRUE(liblinphone_tester_send_data(crashing_invite, strlen(crashing_invite), "127.0.0.1", + linphone_transports_get_udp_port(tp), SOCK_DGRAM) > 0); + linphone_transports_unref(tp); + + wait_for_until(laure->lc, NULL, NULL, 0, 1000); + + linphone_core_manager_destroy(laure); +} + static void enable_specific_payloads(LinphoneCore *lc) { bctbx_list_t *payloads = linphone_core_get_audio_payload_types(lc); LinphonePayloadType *type; @@ -7503,6 +7561,7 @@ test_t call_not_established_tests[] = { TEST_NO_TAG("Call cancelled with reason", cancel_call_with_error), TEST_NO_TAG("Call declined, other ringing device receive CANCEL with reason", cancel_other_device_after_decline), TEST_NO_TAG("Call with unknown stream", call_with_unknown_stream), + TEST_NO_TAG("Call with malformed from", call_with_maformed_from), TEST_NO_TAG("Call rejected with 403", call_rejected_with_403), }; diff --git a/tester/ics-tester.cpp b/tester/ics-tester.cpp index 0e40ef9889738b8f3d5a3e56a742f4b458be20f4..348db8f8e275c46121ddff362b759ddd9673082b 100644 --- a/tester/ics-tester.cpp +++ b/tester/ics-tester.cpp @@ -381,8 +381,6 @@ static void send_conference_invitations(bool_t enable_encryption, linphone_conference_info_unref(conf_info_from_original_content); } linphone_chat_message_unref(msg); - - linphone_chat_room_unref(marieCr); } BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageReceived, 1)); @@ -450,6 +448,8 @@ static void send_conference_invitations(bool_t enable_encryption, linphone_core_manager_delete_chat_room(laure, laureCr, coresList); } + linphone_core_manager_delete_chat_room(marie, marieCr, coresList); + linphone_address_unref(conf_uri); bctbx_list_free(coresManagerList);