Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ cmake_install.cmake
# Ignore autogenerated version.h.
/include/version.cmake
/version.h

# Ignore VSCore related stuff
build/
settings.json
*.code-workspace
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Feature added in 3.7.x
======================
- Enabled support of RFC 7118 The WebSocket Protocol as a Transport for the Session Initiation Protocol (SIP)
- Based on libwebsocket and only in client mode and WSS only.
- added a -w1 option to specify SIP transport
- added a USE_WSS definition in CMakeList.txt to enable it

Features added in 3.7.5
=======================

Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ function(apply_common_sipp_dependencies TARGET_NAME)
if(BUILD_STATIC AND MSYS)
target_link_libraries(${TARGET_NAME} crypt32)
endif()

if(USE_WSS)
target_link_libraries(${TARGET_NAME} ${LIBWEBSOCKETS_LIBRARIES})
endif()
endfunction()

optional_library(SCTP "Build with SCTP support")
Expand Down Expand Up @@ -293,6 +297,17 @@ if(USE_SCTP)
find_library(SCTP_LIBRARY sctp)
endif()

# Option principale
option(USE_WSS "Enable WebSocket Secure (WSS) support via libwebsockets" OFF)

if(USE_WSS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBWEBSOCKETS REQUIRED libwebsockets)
add_definitions("-DUSE_WSS")
set(LIBWEBSOCKETS_LIBRARIES ${LIBWEBSOCKETS_LIBRARIES})
message(STATUS "Found libwebsockets: ${LIBWEBSOCKETS_LIBRARIES}")

endif()
# add the main executable
add_sipp_target(sipp
SOURCES "${PROJECT_SOURCE_DIR}/src/sipp.cpp"
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ This is the SIPp package. Please refer to the
Normally, you should be able to build SIPp by using CMake:

```
cmake .
mkdir build
cd build
cmake ..
make
```

Expand All @@ -59,6 +61,26 @@ The TLS key log file format is described here: https://datatracker.ietf.org/doc/

_Please note the security considerations ("3. Security Considerations")!_

To enable SIP over WebSocket feature pass `-DUSE_WSS=ON` to cmake. You need to have compiled [libwebsocket](https://libwebsockets.org/) before.
And on order to avoid dynamic dependency, use only the static version. Here are simple instructions to build the lib on for linux:

```
cd libwebsocket
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr -DLWS_WITHOUT_TESTAPPS=ON -DLWS_WITH_SSL=ON -DLWS_WITH_SHARED=OFF -DLWS_WITH_STATIC=OFF ..
make
sudo make install
```
Then compile sipp with -DUSE_WSS=1
```
cd sipp
mkdir build
cd build
cmake .. -DUSE_WSS=1
make
```

## Static builds

SIPp can be built into a single static binary, removing the need for
Expand Down
1 change: 1 addition & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Installing SIPp
+ For TLS support: OpenSSL >= 1.1.0 or WolfSSL >= 3.15.0
+ For pcap play support: libpcap and libnet
+ For SCTP support: lksctp-tools
+ For WSS support: libwebsocket
+ For distributed pauses: `Gnu Scientific Libraries`_

+ You have four options to compile SIPp:
Expand Down
6 changes: 6 additions & 0 deletions docs/transport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ This mode is generally used for emulating user agents calling a SIP
server.


WSS mode
````````
sipp supports SIP over secure WebSocket in mono socket mode (-t w1).
Only client mode is supported for now. It is generally used to emulate
WebRTC clients.

IPv6 support
````````````

Expand Down
14 changes: 13 additions & 1 deletion include/sipp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
#define T_TCP 1
#define T_TLS 2
#define T_SCTP 3
#define T_WSS 4

#ifdef USE_TLS
#define DEFAULT_TLS_CERT "cacert.pem"
Expand All @@ -113,7 +114,18 @@
#define DEFAULT_TLS_CRL ""
#endif

#define TRANSPORT_TO_STRING(p) ((p==T_TCP) ? "TCP" : ((p==T_TLS)? "TLS" : ((p==T_UDP)? "UDP" : "SCTP")))
inline const char * TRANSPORT_TO_STRING(int p) {
switch(p)
{
case T_TCP: return "TCP";
case T_UDP: return "UDP";
case T_TLS: return "TLS";
case T_SCTP: return "SCTP";
case T_WSS: return "WSS";
default: break;
}
return "Unknown";
}

#define SIPP_MAXFDS 65536

Expand Down
19 changes: 19 additions & 0 deletions include/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#define SCTP_UP 2
#endif

#ifdef USE_WSS
#include "libwebsockets.h"
#endif

/**
* On some systems you must pass the exact sockaddr struct size to
* connect/bind/sendto calls. Passing a length that is too large
Expand Down Expand Up @@ -99,6 +103,10 @@ class SIPpSocket {
int bind_to_device(const char* device_name);
#endif

#ifdef USE_WSS
void lws_callback_wss(enum lws_callback_reasons reason, void *in, size_t len);
#endif

static void pollset_process(int wait);

int ss_count = 1; /* How many users are there of this socket? */
Expand Down Expand Up @@ -150,6 +158,17 @@ class SIPpSocket {
#ifdef USE_SCTP
int sctpstate = SCTP_DOWN;
#endif

#ifdef USE_WSS
void init_lws_context();
void close_wss();
void wss_event_loop(int revents);
int wss_send(const void * buf, int len);

struct lws *wsi; // Connexion WebSocket
bool wss_connected;
struct socketbuf * wss_out;
#endif
};


Expand Down
23 changes: 18 additions & 5 deletions src/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,11 +1361,11 @@ bool call::connect_socket_if_needed()
if (sipp_bind_socket(call_socket, &saddr, &call_port)) {
ERROR_NO("Unable to bind UDP socket");
}
} else { /* TCP, SCTP or TLS. */
} else { /* TCP, SCTP, WSS or TLS. */
struct sockaddr_storage *L_dest = &remote_sockaddr;

if ((associate_socket(SIPpSocket::new_sipp_call_socket(use_ipv6, transport, &existing))) == nullptr) {
ERROR_NO("Unable to get a TCP/SCTP/TLS socket");
ERROR_NO("Unable to get a TCP/SCTP/TLS/WSS socket");
}
call_socket->ss_count++;

Expand Down Expand Up @@ -5775,18 +5775,29 @@ call::T_ActionResult call::executeAction(const char* msg, message* curmsg)
protocol = T_TLS;
} else if (!strcmp(str_protocol, "sctp") || !strcmp(str_protocol, "SCTP")) {
protocol = T_SCTP;
} else {
} else if (!strcmp(str_protocol, "wss") || !strcmp(str_protocol, "WSS")) {
protocol = T_WSS;
}
else {
ERROR("Unknown transport for setdest: '%s'", str_protocol);
}

if (!call_socket && ((protocol == T_TCP && transport == T_TCP) ||
(protocol == T_SCTP && transport == T_SCTP))) {
(protocol == T_SCTP && transport == T_SCTP) ||
(protocol == T_WSS && transport == T_WSS))) {
bool existing;
LOG_MSG("Creating new call socket");
if ((associate_socket(SIPpSocket::new_sipp_call_socket(use_ipv6, transport, &existing))) == nullptr) {
switch (protocol) {
switch (protocol)
{
case T_WSS:
ERROR_NO("Unable to get a WSS socket");
break;

case T_SCTP:
ERROR_NO("Unable to get a SCTP socket");
break;

default:
ERROR_NO("Unable to get a TCP socket");
}
Expand Down Expand Up @@ -5816,6 +5827,8 @@ call::T_ActionResult call::executeAction(const char* msg, message* curmsg)
if (call_socket->ss_count > 1) {
ERROR("Can not change destinations for a TCP/SCTP socket that has more than one user.");
}
} else if (protocol == T_WSS) {
ERROR("Changing destinations is not supported for WSS.");
}

if (gai_getsockaddr(&call_peer, str_host, port,
Expand Down
1 change: 1 addition & 0 deletions src/call_generation_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ bool CallGenerationTask::run()
case T_TCP:
case T_SCTP:
case T_TLS:
case T_WSS:
call_ptr->associate_socket(tcp_multiplex);
tcp_multiplex->ss_count++;
break;
Expand Down
8 changes: 8 additions & 0 deletions src/sipp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ struct sipp_option options_table[] = {
#endif
"- c1: u1 + compression (only if compression plugin loaded),\n"
"- cn: un + compression (only if compression plugin loaded). This plugin is not provided with SIPp.\n"
#ifdef USE_WSS
"- w1: Secure Web Socket with one socket,\n"
#endif
, SIPP_OPTION_TRANSPORT, nullptr, 1
},
{"i", "Set the local IP address for 'Contact:','Via:', and 'From:' headers. Default is primary host IP address.\n", SIPP_OPTION_IP, local_ip, 1},
Expand Down Expand Up @@ -1643,6 +1646,11 @@ int main(int argc, char *argv[])
ERROR("To use TLS transport you must compile SIPp with OpenSSL or WolfSSL");
#endif
break;

case 'w':
transport = T_WSS;
break;

case 'c':
if (strlen(comp_error)) {
ERROR("No " COMP_PLUGIN " plugin available: %s", comp_error);
Expand Down
Loading