mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 18:20:04 +00:00
Compare commits
55 Commits
1.0.0
...
boot_time_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf342a6983 | ||
|
|
0910dfa11e | ||
|
|
1b007fe3bb | ||
|
|
a252447494 | ||
|
|
7f4b6e3f9e | ||
|
|
136da0621e | ||
|
|
2aa134c9d4 | ||
|
|
0a7d2f3a1a | ||
|
|
968727eece | ||
|
|
bac0a6983d | ||
|
|
f877b9c22f | ||
|
|
9b988c6878 | ||
|
|
91d7f4a02b | ||
|
|
b74f73ee73 | ||
|
|
df53862dec | ||
|
|
b85e78fb7b | ||
|
|
38b8cbf4ac | ||
|
|
4671e40b32 | ||
|
|
22278846e1 | ||
|
|
ed3ec23a47 | ||
|
|
b1b6883799 | ||
|
|
79b6861af6 | ||
|
|
e298549510 | ||
|
|
3a181d2ffe | ||
|
|
be71810dea | ||
|
|
2bf902242f | ||
|
|
2b15321a77 | ||
|
|
f21a00616a | ||
|
|
8df4ad3cbc | ||
|
|
7f2aa3f826 | ||
|
|
7946f585ee | ||
|
|
5f10aae6c2 | ||
|
|
e11927f8de | ||
|
|
c478da9f7c | ||
|
|
0bdb8f96b8 | ||
|
|
b1c9cdfa16 | ||
|
|
04cefb9037 | ||
|
|
21fe137755 | ||
|
|
807839f8c5 | ||
|
|
bbf8813303 | ||
|
|
e9ae72c79b | ||
|
|
268b1a2e82 | ||
|
|
ca4132b9e3 | ||
|
|
7d8c0bcff2 | ||
|
|
0ba7f5b95a | ||
|
|
36735f588d | ||
|
|
5f4d640467 | ||
|
|
7bc99bb48c | ||
|
|
cf1e9c51d2 | ||
|
|
14241251d8 | ||
|
|
eb67134b10 | ||
|
|
93f30417de | ||
|
|
d282afca4f | ||
|
|
81dff2cef0 | ||
|
|
a3991b3ed9 |
@@ -26,8 +26,9 @@ install:
|
||||
script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=true -DENABLE_SESHAT:BOOL=true -DENABLE_CJWT:BOOL=true
|
||||
- cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=true -DENABLE_SESHAT:BOOL=true -DFEATURE_DNS_QUERY:BOOL=true
|
||||
- make
|
||||
- export ARGS="-V"
|
||||
- make test
|
||||
|
||||
after_success:
|
||||
|
||||
@@ -22,6 +22,7 @@ include(CTest)
|
||||
set(INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/_install)
|
||||
set(PREFIX_DIR ${CMAKE_CURRENT_BINARY_DIR}/_prefix)
|
||||
set(INCLUDE_DIR ${INSTALL_DIR}/include)
|
||||
set(INCLUDE_UCRESOLV ${PREFIX_DIR}/ucresolv/src/ucresolv/include)
|
||||
set(LIBRARY_DIR ${INSTALL_DIR}/lib)
|
||||
set(LIBRARY_DIR64 ${INSTALL_DIR}/lib64)
|
||||
set(COMMON_LIBRARY_DIR ${INSTALL_DIR}/lib/${CMAKE_LIBRARY_ARCHITECTURE})
|
||||
@@ -82,7 +83,7 @@ add_dependencies(libtrower-base64 trower-base64)
|
||||
ExternalProject_Add(nopoll
|
||||
PREFIX ${PREFIX_DIR}/nopoll
|
||||
GIT_REPOSITORY https://github.com/Comcast/nopoll.git
|
||||
GIT_TAG "nopoll_yocto"
|
||||
GIT_TAG "18e83e32bfccd1f308b4df0fe0aa3565302903a4"
|
||||
CONFIGURE_COMMAND COMMAND <SOURCE_DIR>/autogen.sh --prefix=${PREFIX}
|
||||
--includedir=${INCLUDE_DIR}
|
||||
--libdir=${LIBRARY_DIR}
|
||||
@@ -123,7 +124,7 @@ add_dependencies(libcJSON cJSON)
|
||||
ExternalProject_Add(msgpack
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/msgpack
|
||||
GIT_REPOSITORY https://github.com/msgpack/msgpack-c.git
|
||||
GIT_TAG "c6e6dbc608366090c12b142b3832604e6aa12f54"
|
||||
GIT_TAG "7a98138f27f27290e680bf8fbf1f8d1b089bf138"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
-DMSGPACK_ENABLE_CXX=OFF
|
||||
-DMSGPACK_BUILD_EXAMPLES=OFF
|
||||
@@ -138,7 +139,7 @@ ExternalProject_Add(cimplog
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cimplog
|
||||
GIT_REPOSITORY https://github.com/Comcast/cimplog.git
|
||||
GIT_TAG "master"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcimplog STATIC SHARED IMPORTED)
|
||||
add_dependencies(libcimplog cimplog)
|
||||
@@ -169,7 +170,7 @@ ExternalProject_Add(libparodus
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/libparodus
|
||||
GIT_REPOSITORY https://github.com/Comcast/libparodus.git
|
||||
GIT_TAG "master"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
-DMAIN_PROJ_LIB64_PATH=${LIBRARY_DIR64}
|
||||
@@ -183,10 +184,10 @@ if (ENABLE_SESHAT)
|
||||
# libseshat external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(libseshat
|
||||
DEPENDS cJSON trower-base64 msgpack wrp-c
|
||||
DEPENDS cJSON trower-base64 msgpack nanomsg wrp-c
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/libseshat
|
||||
GIT_REPOSITORY https://github.com/comcast/seshat.git
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
-DMAIN_PROJ_LIB64_PATH=${LIBRARY_DIR64}
|
||||
@@ -199,19 +200,19 @@ include_directories(${INCLUDE_DIR}/libseshat)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SESHAT ")
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (ENABLE_CJWT)
|
||||
# libcjwt external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(cjwt
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cjwt
|
||||
GIT_REPOSITORY https://github.com/Comcast/cjwt.git
|
||||
GIT_TAG "master"
|
||||
#GIT_TAG "abd4376ff56212d16f69e850a64f6e095857ca39"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcjwt STATIC SHARED IMPORTED)
|
||||
add_dependencies(libcjwt cjwt)
|
||||
|
||||
if (UCLIBC)
|
||||
if (FEATURE_DNS_QUERY)
|
||||
# libucresolv external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(ucresolv
|
||||
@@ -226,16 +227,14 @@ include_directories(${INCLUDE_DIR}
|
||||
${INCLUDE_DIR}/ucresolv
|
||||
)
|
||||
|
||||
endif (UCLIBC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_CJWT ")
|
||||
endif (ENABLE_CJWT)
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
# cmocka external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(cmocka
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cmocka
|
||||
GIT_REPOSITORY https://git.cryptomilk.org/projects/cmocka.git
|
||||
GIT_REPOSITORY https://github.com/elventear/cmocka.git
|
||||
GIT_TAG "master"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
)
|
||||
@@ -244,7 +243,15 @@ add_dependencies(libcmocka cmocka)
|
||||
|
||||
endif (BUILD_TESTING)
|
||||
|
||||
endif ()
|
||||
endif () # NOT BUILD_YOCTO
|
||||
|
||||
if (BUILD_YOCTO)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBUILD_YOCTO ")
|
||||
endif (BUILD_YOCTO)
|
||||
|
||||
if (FEATURE_DNS_QUERY)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFEATURE_DNS_QUERY ")
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} )
|
||||
add_subdirectory(src)
|
||||
|
||||
74
README.md
74
README.md
@@ -15,3 +15,77 @@ cmake ..
|
||||
make
|
||||
make test
|
||||
```
|
||||
# Command line Arguments needed to start parodus
|
||||
|
||||
```
|
||||
- /hw-model -The hardware model name.
|
||||
|
||||
- /hw-serial-number -The serial number.
|
||||
|
||||
- /hw-manufacturer -The device manufacturer.
|
||||
|
||||
- /hw-mac -The MAC address used to manage the device.
|
||||
|
||||
- /hw-last-reboot-reason -The last known reboot reason.
|
||||
|
||||
- /fw-name -The firmware name.
|
||||
|
||||
- /boot-time -The boot time in unix time.
|
||||
|
||||
- /webpa-url -The URL that the WRP client should reach out to. (required). Must begin with 'https://' or 'http://'. May end with a port number. If no port specified, then 443 is assumed for https, 80 for http.
|
||||
|
||||
- /webpa-backoff-max -The maximum value of c in the binary backoff algorithm
|
||||
|
||||
- /webpa-ping-timeout -The maximum time to wait between pings before assuming the connection is broken.
|
||||
|
||||
- /webpa-interface-used -The device interface being used to connect to the cloud.
|
||||
|
||||
- /parodus-local-url -Parodus local server url (optional argument)
|
||||
|
||||
- /partner-id - Partner ID of broadband gateway (optional argument)
|
||||
|
||||
- /ssl-cert-path -Provide the certs for establishing secure connection (optional argument)
|
||||
|
||||
- /force-ipv4 -Forcefully connect parodus to ipv4 address (optional argument)
|
||||
|
||||
- /force-ipv6 -Forcefully connect parodus to ipv6 address (optional argument)
|
||||
|
||||
- /token-read-script -Script to get webpa auth token for establishing secure connection (absolute path where that script is present) -optional argument
|
||||
|
||||
- /token-acquisition-script -Script to create new auth token for establishing secure connection (absolute path where that script is present) -optional argument
|
||||
|
||||
|
||||
# if ENABLE_SESHAT is enabled
|
||||
- /seshat-url - The seshat server url
|
||||
|
||||
# if FEATURE_DNS_QUERY is enabled then below mentioned arguments are needed
|
||||
|
||||
- /acquire-jwt - this parameter (0 or 1) specifies whether there will be a dns lookup. If not, or if any problem occurs with the dns lookup, then webpa-url will be the target.
|
||||
|
||||
- /dns-txt-url - this parameter is used along with the hw_mac parameter to create the dns txt record id
|
||||
|
||||
- /jwt-algo -Allowed algorithm used for communication
|
||||
|
||||
- /jwt-public-key-file -JWT token validation key
|
||||
|
||||
```
|
||||
|
||||
# Sample parodus start commands:
|
||||
|
||||
```
|
||||
# Seshat & FEATURE_DNS_QUERY Enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --seshat-url=tcp://127.0.0.1:7777 --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4
|
||||
|
||||
|
||||
# Seshat is not enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4
|
||||
|
||||
|
||||
# When both Seshat & FEATURE_DNS_QUERY not Enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
set(SOURCES main.c mutex.c networking.c nopoll_helpers.c nopoll_handlers.c
|
||||
ParodusInternal.c string_helpers.c time.c config.c conn_interface.c
|
||||
connection.c spin_thread.c client_list.c service_alive.c
|
||||
upstream.c downstream.c thread_tasks.c partners_check.c)
|
||||
upstream.c downstream.c thread_tasks.c partners_check.c token.c)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} seshat_interface.c)
|
||||
@@ -22,11 +22,6 @@ else()
|
||||
set(SOURCES ${SOURCES} seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (ENABLE_CJWT)
|
||||
set(SOURCES ${SOURCES} token.c)
|
||||
else()
|
||||
set(SOURCES ${SOURCES} token_stub.c)
|
||||
endif (ENABLE_CJWT)
|
||||
|
||||
add_executable(parodus ${SOURCES})
|
||||
|
||||
@@ -43,16 +38,18 @@ target_link_libraries (parodus
|
||||
-lcrypto
|
||||
-lnanomsg
|
||||
-lcjson
|
||||
-lcjwt
|
||||
-lpthread
|
||||
-lrt
|
||||
)
|
||||
|
||||
if (FEATURE_DNS_QUERY)
|
||||
target_link_libraries (parodus -lucresolv -lresolv)
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
target_link_libraries (parodus -llibseshat)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (ENABLE_CJWT)
|
||||
target_link_libraries (parodus -lresolv -lcjwt)
|
||||
endif (ENABLE_CJWT)
|
||||
|
||||
install (TARGETS parodus DESTINATION bin)
|
||||
|
||||
@@ -87,6 +87,10 @@ char* getWebpaConveyHeader()
|
||||
ParodusError("Failed to GET Reconnect reason value\n");
|
||||
}
|
||||
|
||||
if(get_parodus_cfg()->boot_retry_wait > 0)
|
||||
{
|
||||
cJSON_AddNumberToObject(response, BOOT_RETRY_WAIT, get_parodus_cfg()->boot_retry_wait);
|
||||
}
|
||||
buffer = cJSON_PrintUnformatted(response);
|
||||
ParodusInfo("X-WebPA-Convey Header: [%zd]%s\n", strlen(buffer), buffer);
|
||||
|
||||
@@ -114,5 +118,10 @@ char* getWebpaConveyHeader()
|
||||
}
|
||||
free(buffer);
|
||||
cJSON_Delete(response);
|
||||
return encodedData;
|
||||
|
||||
if( 0 < strlen(encodedData) ) {
|
||||
return encodedData;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
457
src/config.c
457
src/config.c
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file config.h
|
||||
* @file config.c
|
||||
*
|
||||
* @description This file contains configuration details of parodus
|
||||
*
|
||||
@@ -25,13 +25,17 @@
|
||||
#include <fcntl.h>
|
||||
#include "config.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include <cjwt/cjwt.h>
|
||||
|
||||
#define MAX_BUF_SIZE 128
|
||||
|
||||
#define MAX_BUF_SIZE 128
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
static ParodusCfg parodusCfg;
|
||||
static unsigned int rsa_algorithms =
|
||||
(1<<alg_rs256) | (1<<alg_rs384) | (1<<alg_rs512);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -47,34 +51,60 @@ void set_parodus_cfg(ParodusCfg *cfg)
|
||||
memcpy(&parodusCfg, cfg, sizeof(ParodusCfg));
|
||||
}
|
||||
|
||||
static void execute_token_script(char *token, char *name, size_t len, char *mac, char *serNum);
|
||||
|
||||
const char *get_tok (const char *src, int delim, char *result, int resultsize)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
int endx = resultsize-1;
|
||||
|
||||
memset (result, 0, resultsize);
|
||||
for (i=0; (c=src[i]) != 0; i++) {
|
||||
if (c == delim)
|
||||
break;
|
||||
if (i < endx)
|
||||
result[i] = c;
|
||||
}
|
||||
if (c == 0)
|
||||
return NULL;
|
||||
return src + i + 1;
|
||||
}
|
||||
|
||||
// the algorithm mask indicates which algorithms are allowed
|
||||
#if 0
|
||||
unsigned int get_algo_mask (const char *algo_str)
|
||||
{
|
||||
unsigned int mask = 0;
|
||||
char *tok;
|
||||
unsigned int mask_val;
|
||||
#define BUFLEN 16
|
||||
char tok[BUFLEN];
|
||||
int alg_val;
|
||||
#define BUFLEN 128
|
||||
char algo_buf[BUFLEN];
|
||||
|
||||
strncpy (algo_buf, algo_str, BUFLEN-1);
|
||||
algo_buf[BUFLEN-1] = 0;
|
||||
|
||||
tok = strtok(algo_buf, ":");
|
||||
while(tok!=NULL)
|
||||
while(NULL != algo_str)
|
||||
{
|
||||
algo_str = get_tok (algo_str, ':', tok, BUFLEN);
|
||||
alg_val = cjwt_alg_str_to_enum (tok);
|
||||
if ((alg_val < 0) || (alg_val >= num_algorithms)) {
|
||||
ParodusError("Invalid jwt algorithm %s\n", tok);
|
||||
abort ();
|
||||
return (unsigned int) (-1);
|
||||
}
|
||||
mask |= (1<<alg_val);
|
||||
tok = strtok(NULL,":");
|
||||
if (alg_val == alg_none) {
|
||||
ParodusError("Disallowed jwt algorithm none\n");
|
||||
return (unsigned int) (-1);
|
||||
}
|
||||
mask_val = (1<<alg_val);
|
||||
#if !ALLOW_NON_RSA_ALG
|
||||
if (0 == (mask_val & rsa_algorithms)) {
|
||||
ParodusError("Disallowed non-rsa jwt algorithm %s\n", tok);
|
||||
return (unsigned int) (-1);
|
||||
}
|
||||
#endif
|
||||
mask |= mask_val;
|
||||
|
||||
}
|
||||
return mask;
|
||||
#undef BUFLEN
|
||||
}
|
||||
#endif
|
||||
|
||||
static int open_input_file (const char *fname)
|
||||
{
|
||||
@@ -102,7 +132,7 @@ void read_key_from_file (const char *fname, char *buf, size_t buflen)
|
||||
ParodusInfo ("%d bytes read\n", nbytes);
|
||||
}
|
||||
|
||||
void get_webpa_token(char *token, char *name, size_t len, char *serNum, char *mac)
|
||||
static void execute_token_script(char *token, char *name, size_t len, char *mac, char *serNum)
|
||||
{
|
||||
FILE* out = NULL, *file = NULL;
|
||||
char command[MAX_BUF_SIZE] = {'\0'};
|
||||
@@ -129,7 +159,7 @@ void get_webpa_token(char *token, char *name, size_t len, char *serNum, char *ma
|
||||
|
||||
// strips ':' characters
|
||||
// verifies that there exactly 12 characters
|
||||
static int parse_mac_address (char *target, const char *arg)
|
||||
int parse_mac_address (char *target, const char *arg)
|
||||
{
|
||||
int count = 0;
|
||||
int i;
|
||||
@@ -149,7 +179,93 @@ static int parse_mac_address (char *target, const char *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
int server_is_http (const char *full_url,
|
||||
const char **server_ptr)
|
||||
{
|
||||
int http_match;
|
||||
const char *ptr;
|
||||
|
||||
if (strncmp(full_url, "https://", 8) == 0) {
|
||||
http_match = 0;
|
||||
ptr = full_url + 8;
|
||||
} else if (strncmp(full_url, "http://", 7) == 0) {
|
||||
http_match = 1;
|
||||
ptr = full_url + 7;
|
||||
} else {
|
||||
ParodusError ("Invalid url %s\n", full_url);
|
||||
return -1;
|
||||
}
|
||||
if (NULL != server_ptr)
|
||||
*server_ptr = ptr;
|
||||
return http_match;
|
||||
}
|
||||
|
||||
|
||||
int parse_webpa_url(const char *full_url,
|
||||
char *server_addr, int server_addr_buflen,
|
||||
char *port_buf, int port_buflen)
|
||||
{
|
||||
const char *server_ptr;
|
||||
char *port_val;
|
||||
char *end_port;
|
||||
size_t server_len;
|
||||
int http_match;
|
||||
|
||||
ParodusInfo ("full url: %s\n", full_url);
|
||||
http_match = server_is_http (full_url, &server_ptr);
|
||||
if (http_match < 0)
|
||||
return http_match;
|
||||
|
||||
ParodusInfo ("server address copied from url\n");
|
||||
parStrncpy (server_addr, server_ptr, server_addr_buflen);
|
||||
server_len = strlen(server_addr);
|
||||
// If there's a '/' on end, null it out
|
||||
if ((server_len>0) && (server_addr[server_len-1] == '/'))
|
||||
server_addr[server_len-1] = '\0';
|
||||
// Look for ':'
|
||||
port_val = strchr (server_addr, ':');
|
||||
|
||||
if (NULL == port_val) {
|
||||
if (http_match)
|
||||
parStrncpy (port_buf, "80", port_buflen);
|
||||
else
|
||||
parStrncpy (port_buf, "443", port_buflen);
|
||||
} else {
|
||||
*port_val = '\0'; // terminate server address with null
|
||||
port_val++;
|
||||
end_port = strchr (port_val, '/');
|
||||
if (NULL != end_port)
|
||||
*end_port = '\0'; // terminate port with null
|
||||
parStrncpy (port_buf, port_val, port_buflen);
|
||||
}
|
||||
ParodusInfo ("server %s, port %s, http_match %d\n",
|
||||
server_addr, port_buf, http_match);
|
||||
return http_match;
|
||||
|
||||
}
|
||||
|
||||
unsigned int parse_num_arg (const char *arg, const char *arg_name)
|
||||
{
|
||||
unsigned int result = 0;
|
||||
int i;
|
||||
char c;
|
||||
|
||||
if (arg[0] == '\0') {
|
||||
ParodusError ("Empty %s argument\n", arg_name);
|
||||
return (unsigned int) -1;
|
||||
}
|
||||
for (i=0; '\0' != (c=arg[i]); i++)
|
||||
{
|
||||
if ((c<'0') || (c>'9')) {
|
||||
ParodusError ("Non-numeric %s argument\n", arg_name);
|
||||
return (unsigned int) -1;
|
||||
}
|
||||
result = (result*10) + c - '0';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
{
|
||||
static const struct option long_options[] = {
|
||||
{"hw-model", required_argument, 0, 'm'},
|
||||
@@ -168,25 +284,37 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
#ifdef ENABLE_SESHAT
|
||||
{"seshat-url", required_argument, 0, 'e'},
|
||||
#endif
|
||||
#ifdef ENABLE_CJWT
|
||||
{"dns-id", required_argument, 0, 'D'},
|
||||
{"dns-txt-url", required_argument, 0, 'D'},
|
||||
{"acquire-jwt", required_argument, 0, 'j'},
|
||||
{"jwt-algo", required_argument, 0, 'a'},
|
||||
{"jwt-key", required_argument, 0, 'k'},
|
||||
#endif
|
||||
{"jwt-public-key-file", required_argument, 0, 'k'},
|
||||
{"ssl-cert-path", required_argument, 0, 'c'},
|
||||
{"force-ipv4", no_argument, 0, '4'},
|
||||
{"force-ipv6", no_argument, 0, '6'},
|
||||
{"webpa-token", required_argument, 0, 'T'},
|
||||
{"token-read-script", required_argument, 0, 'T'},
|
||||
{"boot-time-retry-wait", required_argument, 0, 'w'},
|
||||
{"token-acquisition-script", required_argument, 0, 'J'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
int c;
|
||||
ParodusInfo("Parsing parodus command line arguments..\n");
|
||||
|
||||
if (NULL == cfg) {
|
||||
ParodusError ("NULL cfg structure\n");
|
||||
return -1;
|
||||
}
|
||||
cfg->flags = 0;
|
||||
parStrncpy (cfg->webpa_url, "", sizeof(cfg->webpa_url));
|
||||
cfg->acquire_jwt = 0;
|
||||
cfg->jwt_algo = 0;
|
||||
parStrncpy (cfg->jwt_key, "", sizeof(cfg->jwt_key));
|
||||
optind = 1; /* We need this if parseCommandLine is called again */
|
||||
while (1)
|
||||
{
|
||||
|
||||
/* getopt_long stores the option index here. */
|
||||
int option_index = 0;
|
||||
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:a:k:c:4:6",
|
||||
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:j:a:k:c:T:w:J:46",
|
||||
long_options, &option_index);
|
||||
|
||||
/* Detect the end of the options. */
|
||||
@@ -215,7 +343,7 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
ParodusInfo ("hw_mac is %s\n",cfg->hw_mac);
|
||||
} else {
|
||||
ParodusError ("Bad mac address %s\n", optarg);
|
||||
abort ();
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
#ifdef ENABLE_SESHAT
|
||||
@@ -235,58 +363,70 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
cfg->boot_time = atoi(optarg);
|
||||
cfg->boot_time = parse_num_arg (optarg, "boot-time");
|
||||
ParodusInfo("boot_time is %d\n",cfg->boot_time);
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
parStrncpy(cfg->webpa_url, optarg,sizeof(cfg->webpa_url));
|
||||
parStrncpy(cfg->webpa_url, optarg,sizeof(cfg->webpa_url));
|
||||
if (server_is_http (cfg->webpa_url, NULL) < 0) {
|
||||
ParodusError ("Bad webpa url %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
ParodusInfo("webpa_url is %s\n",cfg->webpa_url);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
cfg->webpa_ping_timeout = atoi(optarg);
|
||||
cfg->webpa_ping_timeout = parse_num_arg (optarg, "webpa-ping-timeout");
|
||||
if (cfg->webpa_ping_timeout == (unsigned int) -1)
|
||||
return -1;
|
||||
ParodusInfo("webpa_ping_timeout is %d\n",cfg->webpa_ping_timeout);
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
cfg->webpa_backoff_max = atoi(optarg);
|
||||
cfg->webpa_backoff_max = parse_num_arg (optarg, "webpa-backoff-max");
|
||||
if (cfg->webpa_backoff_max == (unsigned int) -1)
|
||||
return -1;
|
||||
ParodusInfo("webpa_backoff_max is %d\n",cfg->webpa_backoff_max);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
parStrncpy(cfg->webpa_interface_used, optarg,sizeof(cfg->webpa_interface_used));
|
||||
ParodusInfo("webpa_inteface_used is %s\n",cfg->webpa_interface_used);
|
||||
ParodusInfo("webpa_interface_used is %s\n",cfg->webpa_interface_used);
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
parStrncpy(cfg->local_url, optarg,sizeof(cfg->local_url));
|
||||
ParodusInfo("parodus local_url is %s\n",cfg->local_url);
|
||||
break;
|
||||
#ifdef ENABLE_CJWT
|
||||
case 'D':
|
||||
// like 'fabric' or 'test'
|
||||
// this parameter is used, along with the hw_mac parameter
|
||||
// to create the dns txt record id
|
||||
parStrncpy(cfg->dns_id, optarg,sizeof(cfg->dns_id));
|
||||
ParodusInfo("parodus dns_id is %s\n",cfg->dns_id);
|
||||
parStrncpy(cfg->dns_txt_url, optarg,sizeof(cfg->dns_txt_url));
|
||||
ParodusInfo("parodus dns-txt-url is %s\n",cfg->dns_txt_url);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
parStrncpy(cfg->jwt_algo, optarg, sizeof(cfg->jwt_algo));
|
||||
ParodusInfo("jwt_algo is %s\n",cfg->jwt_algo);
|
||||
case 'j':
|
||||
cfg->acquire_jwt = parse_num_arg (optarg, "acquire-jwt");
|
||||
if (cfg->acquire_jwt == (unsigned int) -1)
|
||||
return -1;
|
||||
ParodusInfo("acquire jwt option is %d\n",cfg->acquire_jwt);
|
||||
break;
|
||||
case 'k':
|
||||
// if the key argument has a '.' character in it, then it is
|
||||
// assumed to be a file, and the file is read in.
|
||||
if (strchr (optarg, '.') == NULL) {
|
||||
parStrncpy(cfg->jwt_key, optarg,sizeof(cfg->jwt_key));
|
||||
} else {
|
||||
read_key_from_file (optarg, cfg->jwt_key, sizeof(cfg->jwt_key));
|
||||
}
|
||||
|
||||
case 'a':
|
||||
// the command line argument is a list of allowed algoritms,
|
||||
// separated by colons, like "RS256:RS512:none"
|
||||
cfg->jwt_algo = get_algo_mask (optarg);
|
||||
if (cfg->jwt_algo == (unsigned int) -1) {
|
||||
return -1;
|
||||
}
|
||||
ParodusInfo("jwt_algo is %u\n",cfg->jwt_algo);
|
||||
break;
|
||||
case 'k':
|
||||
read_key_from_file (optarg, cfg->jwt_key, sizeof(cfg->jwt_key));
|
||||
ParodusInfo("jwt_key is %s\n",cfg->jwt_key);
|
||||
break;
|
||||
#endif
|
||||
case 'p':
|
||||
parStrncpy(cfg->partner_id, optarg,sizeof(cfg->partner_id));
|
||||
ParodusInfo("partner_id is %s\n",cfg->partner_id);
|
||||
@@ -307,9 +447,17 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
cfg->flags |= FLAGS_IPV6_ONLY;
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
parStrncpy(cfg->token_acquisition_script, optarg,sizeof(cfg->token_acquisition_script));
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
get_webpa_token(cfg->webpa_token,optarg,sizeof(cfg->webpa_token),cfg->hw_serial_number,cfg->hw_mac);
|
||||
ParodusInfo("webpa_token is %s\n",cfg->webpa_token);
|
||||
parStrncpy(cfg->token_read_script, optarg,sizeof(cfg->token_read_script));
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
cfg->boot_retry_wait = parse_num_arg (optarg, "boot-time-retry-wait");
|
||||
ParodusInfo("boot_retry_wait is %d\n",cfg->boot_retry_wait);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
@@ -318,10 +466,28 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
|
||||
default:
|
||||
ParodusError("Enter Valid commands..\n");
|
||||
abort ();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == strlen (cfg->webpa_url)) {
|
||||
ParodusError ("Missing webpa url argument\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg->acquire_jwt) {
|
||||
if (0 == cfg->jwt_algo) {
|
||||
ParodusError ("Missing jwt algorithm argument\n");
|
||||
return -1;
|
||||
}
|
||||
if ((0 != (cfg->jwt_algo & rsa_algorithms)) &&
|
||||
(0 == strlen (cfg->jwt_key)) ) {
|
||||
ParodusError ("Missing jwt public key file argument\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ParodusPrint("argc is :%d\n", argc);
|
||||
ParodusPrint("optind is :%d\n", optind);
|
||||
|
||||
@@ -333,6 +499,98 @@ void parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
ParodusPrint ("%s ", argv[optind++]);
|
||||
putchar ('\n');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* call parodus create/acquisition script to create new auth token, if success then calls
|
||||
* execute_token_script func with args as parodus read script.
|
||||
*/
|
||||
|
||||
void createNewAuthToken(char *newToken, size_t len)
|
||||
{
|
||||
//Call create script
|
||||
char output[12] = {'\0'};
|
||||
memset (newToken, 0, len);
|
||||
execute_token_script(output,get_parodus_cfg()->token_acquisition_script,sizeof(output),get_parodus_cfg()->hw_mac,get_parodus_cfg()->hw_serial_number);
|
||||
if (strlen(output)>0 && strcmp(output,"SUCCESS")==0)
|
||||
{
|
||||
//Call read script
|
||||
execute_token_script(newToken,get_parodus_cfg()->token_read_script,len,get_parodus_cfg()->hw_mac,get_parodus_cfg()->hw_serial_number);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to create new token\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetches authorization token from the output of read script. If read script returns "ERROR"
|
||||
* it will call createNewAuthToken to create and read new token
|
||||
*/
|
||||
|
||||
void getAuthToken(ParodusCfg *cfg)
|
||||
{
|
||||
//local var to update cfg->webpa_auth_token only in success case
|
||||
char output[4069] = {'\0'} ;
|
||||
memset (cfg->webpa_auth_token, 0, sizeof(cfg->webpa_auth_token));
|
||||
if( strlen(cfg->token_read_script) !=0 && strlen(cfg->token_acquisition_script) !=0)
|
||||
{
|
||||
execute_token_script(output,cfg->token_read_script,sizeof(output),cfg->hw_mac,cfg->hw_serial_number);
|
||||
|
||||
if ((strlen(output) == 0))
|
||||
{
|
||||
ParodusError("Unable to get auth token\n");
|
||||
}
|
||||
else if(strcmp(output,"ERROR")==0)
|
||||
{
|
||||
ParodusInfo("Failed to read token from %s. Proceeding to create new token.\n",cfg->token_read_script);
|
||||
//Call create/acquisition script
|
||||
createNewAuthToken(cfg->webpa_auth_token, sizeof(cfg->webpa_auth_token));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("update cfg->webpa_auth_token in success case\n");
|
||||
parStrncpy(cfg->webpa_auth_token, output, sizeof(cfg->webpa_auth_token));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("Both read and write file are NULL \n");
|
||||
}
|
||||
}
|
||||
|
||||
void setDefaultValuesToCfg(ParodusCfg *cfg)
|
||||
{
|
||||
if(cfg == NULL)
|
||||
{
|
||||
ParodusError("cfg is NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ParodusInfo("Setting default values to parodusCfg\n");
|
||||
parStrncpy(cfg->local_url, PARODUS_UPSTREAM, sizeof(cfg->local_url));
|
||||
|
||||
cfg->acquire_jwt = 0;
|
||||
|
||||
parStrncpy(cfg->dns_txt_url, DNS_TXT_URL, sizeof(cfg->dns_txt_url));
|
||||
|
||||
parStrncpy(cfg->jwt_key, "\0", sizeof(cfg->jwt_key));
|
||||
|
||||
cfg->jwt_algo = 0;
|
||||
|
||||
parStrncpy(cfg->cert_path, "\0", sizeof(cfg->cert_path));
|
||||
|
||||
cfg->flags = 0;
|
||||
|
||||
parStrncpy(cfg->webpa_path_url, WEBPA_PATH_URL,sizeof(cfg->webpa_path_url));
|
||||
|
||||
snprintf(cfg->webpa_protocol, sizeof(cfg->webpa_protocol), "%s-%s", PROTOCOL_VALUE, GIT_COMMIT_TAG);
|
||||
ParodusInfo(" cfg->webpa_protocol is %s\n", cfg->webpa_protocol);
|
||||
|
||||
parStrncpy(cfg->webpa_uuid, "1234567-345456546",sizeof(cfg->webpa_uuid));
|
||||
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
|
||||
|
||||
}
|
||||
|
||||
void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
@@ -343,75 +601,73 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
return;
|
||||
}
|
||||
|
||||
ParodusCfg *pConfig =config;
|
||||
|
||||
if(strlen (pConfig->hw_model) !=0)
|
||||
if(strlen (config->hw_model) !=0)
|
||||
{
|
||||
parStrncpy(cfg->hw_model, pConfig->hw_model, sizeof(cfg->hw_model));
|
||||
parStrncpy(cfg->hw_model, config->hw_model, sizeof(cfg->hw_model));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("hw_model is NULL. read from tmp file\n");
|
||||
}
|
||||
if( strlen(pConfig->hw_serial_number) !=0)
|
||||
if( strlen(config->hw_serial_number) !=0)
|
||||
{
|
||||
parStrncpy(cfg->hw_serial_number, pConfig->hw_serial_number, sizeof(cfg->hw_serial_number));
|
||||
parStrncpy(cfg->hw_serial_number, config->hw_serial_number, sizeof(cfg->hw_serial_number));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("hw_serial_number is NULL. read from tmp file\n");
|
||||
}
|
||||
if(strlen(pConfig->hw_manufacturer) !=0)
|
||||
if(strlen(config->hw_manufacturer) !=0)
|
||||
{
|
||||
parStrncpy(cfg->hw_manufacturer, pConfig->hw_manufacturer,sizeof(cfg->hw_manufacturer));
|
||||
parStrncpy(cfg->hw_manufacturer, config->hw_manufacturer,sizeof(cfg->hw_manufacturer));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("hw_manufacturer is NULL. read from tmp file\n");
|
||||
}
|
||||
if(strlen(pConfig->hw_mac) !=0)
|
||||
if(strlen(config->hw_mac) !=0)
|
||||
{
|
||||
parStrncpy(cfg->hw_mac, pConfig->hw_mac,sizeof(cfg->hw_mac));
|
||||
parStrncpy(cfg->hw_mac, config->hw_mac,sizeof(cfg->hw_mac));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("hw_mac is NULL. read from tmp file\n");
|
||||
}
|
||||
if(strlen (pConfig->hw_last_reboot_reason) !=0)
|
||||
if(strlen (config->hw_last_reboot_reason) !=0)
|
||||
{
|
||||
parStrncpy(cfg->hw_last_reboot_reason, pConfig->hw_last_reboot_reason,sizeof(cfg->hw_last_reboot_reason));
|
||||
parStrncpy(cfg->hw_last_reboot_reason, config->hw_last_reboot_reason,sizeof(cfg->hw_last_reboot_reason));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("hw_last_reboot_reason is NULL. read from tmp file\n");
|
||||
}
|
||||
if(strlen(pConfig->fw_name) !=0)
|
||||
if(strlen(config->fw_name) !=0)
|
||||
{
|
||||
parStrncpy(cfg->fw_name, pConfig->fw_name,sizeof(cfg->fw_name));
|
||||
parStrncpy(cfg->fw_name, config->fw_name,sizeof(cfg->fw_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("fw_name is NULL. read from tmp file\n");
|
||||
}
|
||||
if( strlen(pConfig->webpa_url) !=0)
|
||||
if( strlen(config->webpa_url) !=0)
|
||||
{
|
||||
parStrncpy(cfg->webpa_url, pConfig->webpa_url,sizeof(cfg->webpa_url));
|
||||
parStrncpy(cfg->webpa_url, config->webpa_url,sizeof(cfg->webpa_url));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("webpa_url is NULL. read from tmp file\n");
|
||||
}
|
||||
if(strlen(pConfig->webpa_interface_used )!=0)
|
||||
if(strlen(config->webpa_interface_used )!=0)
|
||||
{
|
||||
parStrncpy(cfg->webpa_interface_used, pConfig->webpa_interface_used,sizeof(cfg->webpa_interface_used));
|
||||
parStrncpy(cfg->webpa_interface_used, config->webpa_interface_used,sizeof(cfg->webpa_interface_used));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("webpa_interface_used is NULL. read from tmp file\n");
|
||||
}
|
||||
if( strlen(pConfig->local_url) !=0)
|
||||
if( strlen(config->local_url) !=0)
|
||||
{
|
||||
parStrncpy(cfg->local_url, pConfig->local_url,sizeof(cfg->local_url));
|
||||
parStrncpy(cfg->local_url, config->local_url,sizeof(cfg->local_url));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -420,58 +676,51 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
|
||||
}
|
||||
|
||||
if( strlen(pConfig->partner_id) !=0)
|
||||
if( strlen(config->partner_id) !=0)
|
||||
{
|
||||
parStrncpy(cfg->partner_id, pConfig->partner_id,sizeof(cfg->partner_id));
|
||||
parStrncpy(cfg->partner_id, config->partner_id,sizeof(cfg->partner_id));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_id is NULL. read from tmp file\n");
|
||||
}
|
||||
#ifdef ENABLE_SESHAT
|
||||
if( strlen(pConfig->seshat_url) !=0)
|
||||
if( strlen(config->seshat_url) !=0)
|
||||
{
|
||||
parStrncpy(cfg->seshat_url, pConfig->seshat_url,sizeof(cfg->seshat_url));
|
||||
parStrncpy(cfg->seshat_url, config->seshat_url,sizeof(cfg->seshat_url));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("seshat_url is NULL. Read from tmp file\n");
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_CJWT
|
||||
if( strlen(pConfig->dns_id) !=0)
|
||||
cfg->acquire_jwt = config->acquire_jwt;
|
||||
|
||||
if( strlen(config->dns_txt_url) !=0)
|
||||
{
|
||||
parStrncpy(cfg->dns_id, pConfig->dns_id,sizeof(cfg->dns_id));
|
||||
parStrncpy(cfg->dns_txt_url, config->dns_txt_url, sizeof(cfg->dns_txt_url));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("parodus dns-id is NULL. adding default\n");
|
||||
parStrncpy(cfg->dns_id, DNS_ID,sizeof(cfg->dns_id));
|
||||
ParodusInfo("parodus dns-txt-url is NULL. adding default\n");
|
||||
parStrncpy(cfg->dns_txt_url, DNS_TXT_URL, sizeof(cfg->dns_txt_url));
|
||||
}
|
||||
|
||||
if(strlen(pConfig->jwt_key )!=0)
|
||||
if(strlen(config->jwt_key )!=0)
|
||||
{
|
||||
parStrncpy(cfg->jwt_key, pConfig->jwt_key,sizeof(cfg->jwt_key));
|
||||
parStrncpy(cfg->jwt_key, config->jwt_key,sizeof(cfg->jwt_key));
|
||||
}
|
||||
else
|
||||
{
|
||||
parStrncpy(cfg->jwt_key, "\0", sizeof(cfg->jwt_key));
|
||||
ParodusPrint("jwt_key is NULL. set to empty\n");
|
||||
}
|
||||
|
||||
if(strlen(pConfig->jwt_algo )!=0)
|
||||
|
||||
cfg->jwt_algo = config->jwt_algo;
|
||||
|
||||
if(strlen(config->cert_path )!=0)
|
||||
{
|
||||
parStrncpy(cfg->jwt_algo, pConfig->jwt_algo,sizeof(cfg->jwt_algo));
|
||||
}
|
||||
else
|
||||
{
|
||||
parStrncpy(cfg->jwt_algo, "\0", sizeof(cfg->jwt_algo));
|
||||
ParodusPrint("jwt_algo is NULL. set to empty\n");
|
||||
}
|
||||
#endif
|
||||
if(strlen(pConfig->cert_path )!=0)
|
||||
{
|
||||
parStrncpy(cfg->cert_path, pConfig->cert_path,sizeof(cfg->cert_path));
|
||||
parStrncpy(cfg->cert_path, config->cert_path,sizeof(cfg->cert_path));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -479,19 +728,27 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
ParodusPrint("cert_path is NULL. set to empty\n");
|
||||
}
|
||||
|
||||
if( strlen(pConfig->webpa_token) !=0)
|
||||
if(strlen(config->token_acquisition_script )!=0)
|
||||
{
|
||||
parStrncpy(cfg->webpa_token, pConfig->webpa_token,sizeof(cfg->webpa_token));
|
||||
parStrncpy(cfg->token_acquisition_script, config->token_acquisition_script,sizeof(cfg->token_acquisition_script));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("webpa_token is NULL. read from tmp file\n");
|
||||
ParodusPrint("token_acquisition_script is NULL. read from tmp file\n");
|
||||
}
|
||||
|
||||
if(strlen(config->token_read_script )!=0)
|
||||
{
|
||||
parStrncpy(cfg->token_read_script, config->token_read_script,sizeof(cfg->token_read_script));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("token_read_script is NULL. read from tmp file\n");
|
||||
}
|
||||
|
||||
cfg->boot_time = pConfig->boot_time;
|
||||
cfg->flags |= FLAGS_SECURE;
|
||||
cfg->webpa_ping_timeout = pConfig->webpa_ping_timeout;
|
||||
cfg->webpa_backoff_max = pConfig->webpa_backoff_max;
|
||||
cfg->boot_time = config->boot_time;
|
||||
cfg->webpa_ping_timeout = config->webpa_ping_timeout;
|
||||
cfg->webpa_backoff_max = config->webpa_backoff_max;
|
||||
parStrncpy(cfg->webpa_path_url, WEBPA_PATH_URL,sizeof(cfg->webpa_path_url));
|
||||
snprintf(cfg->webpa_protocol, sizeof(cfg->webpa_protocol), "%s-%s", PROTOCOL_VALUE, GIT_COMMIT_TAG);
|
||||
ParodusInfo("cfg->webpa_protocol is %s\n", cfg->webpa_protocol);
|
||||
@@ -499,3 +756,5 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
63
src/config.h
63
src/config.h
@@ -48,14 +48,17 @@ extern "C" {
|
||||
#define WEBPA_PING_TIMEOUT "webpa-ping-timeout"
|
||||
#define WEBPA_BACKOFF_MAX "webpa-backoff-max"
|
||||
#define PARTNER_ID "partner-id"
|
||||
#define CERT_PATH "ssl-cert-path"
|
||||
#define BOOT_RETRY_WAIT "boot-time-retry-wait"
|
||||
|
||||
#define PROTOCOL_VALUE "PARODUS-2.0"
|
||||
#define WEBPA_PATH_URL "/api/v2/device"
|
||||
#define PROTOCOL_VALUE "PARODUS-2.0"
|
||||
#define WEBPA_PATH_URL "/api/v2/device"
|
||||
#define JWT_ALGORITHM "jwt-algo"
|
||||
#define JWT_KEY "jwt-key"
|
||||
#define DNS_TXT_URL "fabric"
|
||||
#define PARODUS_UPSTREAM "tcp://127.0.0.1:6666"
|
||||
|
||||
#ifdef ENABLE_CJWT
|
||||
# define DNS_ID "fabric"
|
||||
#endif
|
||||
#define PARODUS_UPSTREAM "tcp://127.0.0.1:6666"
|
||||
#define ALLOW_NON_RSA_ALG false
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
@@ -83,30 +86,60 @@ typedef struct
|
||||
#ifdef ENABLE_SESHAT
|
||||
char seshat_url[128];
|
||||
#endif
|
||||
#ifdef ENABLE_CJWT
|
||||
char dns_id[64];
|
||||
char jwt_algo[32]; // bit mask set for each allowed algorithm
|
||||
char dns_txt_url[64];
|
||||
unsigned int acquire_jwt;
|
||||
unsigned int jwt_algo; // bit mask set for each allowed algorithm
|
||||
char jwt_key[4096]; // may be read in from a pem file
|
||||
#endif
|
||||
char cert_path[64];
|
||||
char webpa_token[4096];
|
||||
char webpa_auth_token[4096];
|
||||
char token_acquisition_script[64];
|
||||
char token_read_script[64];
|
||||
unsigned int boot_retry_wait;
|
||||
} ParodusCfg;
|
||||
|
||||
#define FLAGS_SECURE (1 << 0)
|
||||
#define FLAGS_IPV6_ONLY (1 << 1)
|
||||
#define FLAGS_IPV4_ONLY (1 << 2)
|
||||
#define FLAGS_IPV6_ONLY (1 << 0)
|
||||
#define FLAGS_IPV4_ONLY (1 << 1)
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg);
|
||||
void createNewAuthToken(char *newToken, size_t len);
|
||||
|
||||
void parseCommandLine(int argc,char **argv,ParodusCfg * cfg);
|
||||
/**
|
||||
* parse command line arguments and create config structure
|
||||
* and return whether args are valid or not
|
||||
*
|
||||
* @param argc number of command line arguments
|
||||
* @param argv command line argument lis
|
||||
* @return 0 if OK
|
||||
* or -1 if error
|
||||
*/
|
||||
int parseCommandLine(int argc,char **argv,ParodusCfg * cfg);
|
||||
|
||||
void setDefaultValuesToCfg(ParodusCfg *cfg);
|
||||
void getAuthToken(ParodusCfg *cfg);
|
||||
// Accessor for the global config structure.
|
||||
ParodusCfg *get_parodus_cfg(void);
|
||||
void set_parodus_cfg(ParodusCfg *);
|
||||
char *get_token_application(void) ;
|
||||
|
||||
/**
|
||||
* parse a webpa url. Extract the server address, the port
|
||||
* and return whether it's secure or not
|
||||
*
|
||||
* @param full_url full url
|
||||
* @param server_addr buffer containing server address found in url
|
||||
* @param server_addr_buflen len of the server addr buffer provided by caller
|
||||
* @param port_buf buffer containing port value found in url
|
||||
* @param port_buflen len of the port buffer provided by caller
|
||||
* @return 1 if insecure connection is allowed, 0 if not,
|
||||
* or -1 if error
|
||||
*/
|
||||
int parse_webpa_url(const char *full_url,
|
||||
char *server_addr, int server_addr_buflen,
|
||||
char *port_buf, int port_buflen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
#include "spin_thread.h"
|
||||
#include "service_alive.h"
|
||||
#include "seshat_interface.h"
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
#include <ucresolv_log.h>
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -57,14 +60,17 @@ pthread_mutex_t close_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void createSocketConnection(void *config_in, void (* initKeypress)())
|
||||
void createSocketConnection(void (* initKeypress)())
|
||||
{
|
||||
int intTimer=0;
|
||||
ParodusCfg *tmpCfg = (ParodusCfg*)config_in;
|
||||
//ParodusCfg *tmpCfg = (ParodusCfg*)config_in;
|
||||
noPollCtx *ctx;
|
||||
bool seshat_registered = false;
|
||||
|
||||
loadParodusCfg(tmpCfg,get_parodus_cfg());
|
||||
//loadParodusCfg(tmpCfg,get_parodus_cfg());
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
register_ucresolv_logger (__cimplog);
|
||||
#endif
|
||||
ParodusPrint("Configure nopoll thread handlers in Parodus\n");
|
||||
nopoll_thread_handlers(&createMutex, &destroyMutex, &lockMutex, &unlockMutex);
|
||||
ctx = nopoll_ctx_new();
|
||||
|
||||
@@ -44,7 +44,7 @@ extern UpStreamMsg *UpStreamMsgQ;
|
||||
* Loads the WebPA config file, if not provided by the caller,
|
||||
* and creates the intial connection and manages the connection wait, close mechanisms.
|
||||
*/
|
||||
void createSocketConnection(void *config_in, void (* initKeypress)());
|
||||
void createSocketConnection(void (* initKeypress)());
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
133
src/connection.c
133
src/connection.c
@@ -41,8 +41,10 @@
|
||||
char deviceMAC[32]={'\0'};
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
static noPollConn *g_conn = NULL;
|
||||
static noPollConnOpts * createConnOpts (char * extra_headers);
|
||||
static noPollConnOpts * createConnOpts (char * extra_headers, bool secure);
|
||||
static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,char *serverPort,char * extra_headers);
|
||||
static char* build_extra_headers( const char *auth, const char *device_id,
|
||||
const char *user_agent, const char *convey );
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -79,8 +81,8 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
char port[8];
|
||||
char server_Address[256];
|
||||
char redirectURL[128]={'\0'};
|
||||
int status=0;
|
||||
int allow_insecure;
|
||||
char *temp_ptr;
|
||||
int connErr=0;
|
||||
struct timespec connErr_start,connErr_end,*connErr_startPtr,*connErr_endPtr;
|
||||
connErr_startPtr = &connErr_start;
|
||||
@@ -96,21 +98,28 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
return nopoll_false;
|
||||
}
|
||||
|
||||
//query dns and validate JWT
|
||||
allow_insecure = allow_insecure_conn();
|
||||
ParodusPrint("allow: %d\n", allow_insecure);
|
||||
if (allow_insecure < 0) {
|
||||
return nopoll_false;
|
||||
}
|
||||
|
||||
ParodusPrint("BootTime In sec: %d\n", get_parodus_cfg()->boot_time);
|
||||
ParodusInfo("Received reboot_reason as:%s\n", get_parodus_cfg()->hw_last_reboot_reason);
|
||||
ParodusInfo("Received reconnect_reason as:%s\n", reconnect_reason);
|
||||
snprintf(port,sizeof(port),"%d",8080);
|
||||
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
if (allow_insecure < 0)
|
||||
return nopoll_false; // must have valid default url
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
if (get_parodus_cfg()->acquire_jwt) {
|
||||
//query dns and validate JWT
|
||||
int jwt_insecure = allow_insecure_conn(
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
if (jwt_insecure >= 0)
|
||||
allow_insecure = jwt_insecure;
|
||||
}
|
||||
#endif
|
||||
ParodusInfo("server_Address %s\n",server_Address);
|
||||
|
||||
max_retry_sleep = (int) pow(2, get_parodus_cfg()->webpa_backoff_max) -1;
|
||||
ParodusInfo("port %s\n", port);
|
||||
|
||||
max_retry_sleep = (int) get_parodus_cfg()->webpa_backoff_max;
|
||||
ParodusPrint("max_retry_sleep is %d\n", max_retry_sleep );
|
||||
|
||||
snprintf(user_agent, sizeof(user_agent),"%s (%s; %s/%s;)",
|
||||
@@ -125,10 +134,9 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
snprintf(device_id, sizeof(device_id), "mac:%s", deviceMAC);
|
||||
ParodusInfo("Device_id %s\n",device_id);
|
||||
|
||||
extra_headers = nopoll_strdup_printf("\r\nX-WebPA-Device-Name: %s"
|
||||
"\r\nX-WebPA-Device-Protocols: wrp-0.11,getset-0.1"
|
||||
"\r\nX-WebPA-Token: %s"
|
||||
"\r\nUser-Agent: %s" "\r\nX-WebPA-Convey: %s",device_id,((0 != strlen(get_parodus_cfg()->webpa_token)) ? get_parodus_cfg()->webpa_token : ""),user_agent,(strlen(conveyHeader) > 0)? conveyHeader :"");
|
||||
extra_headers = build_extra_headers(
|
||||
((0 < strlen(get_parodus_cfg()->webpa_auth_token)) ? get_parodus_cfg()->webpa_auth_token : NULL),
|
||||
device_id, user_agent, conveyHeader );
|
||||
|
||||
do
|
||||
{
|
||||
@@ -139,7 +147,7 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
}
|
||||
ParodusPrint("New backoffRetryTime value calculated as %d seconds\n", backoffRetryTime);
|
||||
noPollConn *connection;
|
||||
if((FLAGS_SECURE == (FLAGS_SECURE & get_parodus_cfg()->flags)) || (!allow_insecure))
|
||||
if(allow_insecure <= 0)
|
||||
{
|
||||
ParodusPrint("secure true\n");
|
||||
connection = nopoll_tls_common_conn(ctx,server_Address, port, extra_headers);
|
||||
@@ -148,7 +156,7 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
{
|
||||
ParodusPrint("secure false\n");
|
||||
noPollConnOpts * opts;
|
||||
opts = createConnOpts(extra_headers);
|
||||
opts = createConnOpts(extra_headers, false);
|
||||
connection = nopoll_conn_new_opts (ctx, opts,server_Address,port,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);// WEBPA-787
|
||||
}
|
||||
set_global_conn(connection);
|
||||
@@ -160,7 +168,9 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusError("Error connecting to server\n");
|
||||
ParodusError("RDK-10037 - WebPA Connection Lost\n");
|
||||
// Copy the server address from config to avoid retrying to the same failing talaria redirected node
|
||||
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
close_and_unref_connection(get_global_conn());
|
||||
set_global_conn(NULL);
|
||||
initial_retry = true;
|
||||
@@ -178,32 +188,59 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
backoffRetryTime = (int) pow(2, c) -1;
|
||||
}
|
||||
|
||||
if(!nopoll_conn_wait_until_connection_ready(get_global_conn(), 10, redirectURL))
|
||||
if(!nopoll_conn_wait_until_connection_ready(get_global_conn(), 10, &status, redirectURL))
|
||||
{
|
||||
|
||||
if (strncmp(redirectURL, "Redirect:", 9) == 0) // only when there is a http redirect
|
||||
if(status == 307 || status == 302 || status == 303) // only when there is a http redirect
|
||||
{
|
||||
char *redirect_ptr = redirectURL;
|
||||
ParodusError("Received temporary redirection response message %s\n", redirectURL);
|
||||
// Extract server Address and port from the redirectURL
|
||||
temp_ptr = strtok(redirectURL , ":"); //skip Redirect
|
||||
temp_ptr = strtok(NULL , ":"); // skip https
|
||||
temp_ptr = strtok(NULL , ":");
|
||||
parStrncpy(server_Address, temp_ptr+2, sizeof(server_Address));
|
||||
parStrncpy(port, strtok(NULL , "/"), sizeof(port));
|
||||
ParodusInfo("Trying to Connect to new Redirected server : %s with port : %s\n", server_Address, port);
|
||||
if (strncmp (redirect_ptr, "Redirect:", 9) == 0)
|
||||
redirect_ptr += 9;
|
||||
allow_insecure = parse_webpa_url (redirect_ptr,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
if (allow_insecure < 0) {
|
||||
ParodusError ("Invalid redirectURL\n");
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
} else
|
||||
ParodusInfo("Trying to Connect to new Redirected server : %s with port : %s\n", server_Address, port);
|
||||
//reset c=2 to start backoffRetryTime as retrying using new redirect server
|
||||
c = 2;
|
||||
}
|
||||
else if(status == 403)
|
||||
{
|
||||
ParodusError("Received Unauthorized response with status: %d\n", status);
|
||||
//Get new token and update auth header
|
||||
|
||||
if (strlen(get_parodus_cfg()->token_acquisition_script) >0) {
|
||||
createNewAuthToken(get_parodus_cfg()->webpa_auth_token,sizeof(get_parodus_cfg()->webpa_auth_token));
|
||||
}
|
||||
|
||||
extra_headers = build_extra_headers( (0 < strlen(get_parodus_cfg()->webpa_auth_token) ? get_parodus_cfg()->webpa_auth_token : NULL),
|
||||
device_id, user_agent, conveyHeader );
|
||||
|
||||
//reset c=2 to start backoffRetryTime as retrying
|
||||
c = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Client connection timeout\n");
|
||||
ParodusError("RDK-10037 - WebPA Connection Lost\n");
|
||||
// Copy the server address from config to avoid retrying to the same failing talaria redirected node
|
||||
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
|
||||
// Copy the server address and port from config to avoid retrying to the same failing talaria redirected node
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", backoffRetryTime);
|
||||
sleep(backoffRetryTime);
|
||||
c++;
|
||||
}
|
||||
//reset httpStatus before next retry
|
||||
ParodusPrint("reset httpStatus from server before next retry\n");
|
||||
status = 0;
|
||||
close_and_unref_connection(get_global_conn());
|
||||
set_global_conn(NULL);
|
||||
initial_retry = true;
|
||||
@@ -247,13 +284,15 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", backoffRetryTime);
|
||||
sleep(backoffRetryTime);
|
||||
c++;
|
||||
// Copy the server address from config to avoid retrying to the same failing talaria redirected node
|
||||
parStrncpy(server_Address, get_parodus_cfg()->webpa_url, sizeof(server_Address));
|
||||
// Copy the server address and port from config to avoid retrying to the same failing talaria redirected node
|
||||
allow_insecure = parse_webpa_url (get_parodus_cfg()->webpa_url,
|
||||
server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
}
|
||||
|
||||
}while(initial_retry);
|
||||
|
||||
if( FLAGS_SECURE == (FLAGS_SECURE & get_parodus_cfg()->flags) )
|
||||
if(allow_insecure <= 0)
|
||||
{
|
||||
ParodusInfo("Connected to server over SSL\n");
|
||||
}
|
||||
@@ -278,12 +317,32 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
|
||||
return nopoll_true;
|
||||
}
|
||||
|
||||
/* Build the extra headers string with any/all conditional logic in one place. */
|
||||
static char* build_extra_headers( const char *auth, const char *device_id,
|
||||
const char *user_agent, const char *convey )
|
||||
{
|
||||
return nopoll_strdup_printf(
|
||||
"%s%s"
|
||||
"\r\nX-WebPA-Device-Name: %s"
|
||||
"\r\nX-WebPA-Device-Protocols: wrp-0.11,getset-0.1"
|
||||
"\r\nUser-Agent: %s"
|
||||
"%s%s",
|
||||
|
||||
(NULL != auth) ? "\r\nAuthorization: Bearer " : "",
|
||||
(NULL != auth) ? auth: "",
|
||||
device_id,
|
||||
user_agent,
|
||||
(NULL != convey) ? "\r\nX-WebPA-Convey: " : "",
|
||||
(NULL != convey) ? convey : "" );
|
||||
}
|
||||
|
||||
static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,char *serverPort,char * extra_headers)
|
||||
{
|
||||
unsigned int flags = 0;
|
||||
noPollConnOpts * opts;
|
||||
noPollConn *connection = NULL;
|
||||
opts = createConnOpts(extra_headers);
|
||||
opts = createConnOpts(extra_headers, true);
|
||||
|
||||
flags = get_parodus_cfg()->flags;
|
||||
|
||||
@@ -299,19 +358,19 @@ static noPollConn * nopoll_tls_common_conn (noPollCtx * ctx,char * serverAddr,c
|
||||
if(connection == NULL)
|
||||
{
|
||||
ParodusInfo("Ipv6 connection failed. Try connecting with Ipv4 mode \n");
|
||||
opts = createConnOpts(extra_headers);
|
||||
opts = createConnOpts(extra_headers, true);
|
||||
connection = nopoll_conn_tls_new (ctx, opts,serverAddr,serverPort,NULL,get_parodus_cfg()->webpa_path_url,NULL,NULL);
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
static noPollConnOpts * createConnOpts (char * extra_headers)
|
||||
static noPollConnOpts * createConnOpts (char * extra_headers, bool secure)
|
||||
{
|
||||
noPollConnOpts * opts;
|
||||
|
||||
opts = nopoll_conn_opts_new ();
|
||||
if( FLAGS_SECURE == (FLAGS_SECURE & get_parodus_cfg()->flags) )
|
||||
if(secure)
|
||||
{
|
||||
if(strlen(get_parodus_cfg()->cert_path) > 0)
|
||||
{
|
||||
|
||||
@@ -89,7 +89,7 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
if(ret < 0)
|
||||
{
|
||||
response = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(response, "statusCode", 430);
|
||||
cJSON_AddNumberToObject(response, "statusCode", 403);
|
||||
cJSON_AddStringToObject(response, "message", "Invalid partner_id");
|
||||
}
|
||||
|
||||
|
||||
@@ -76,9 +76,13 @@ int main( int argc, char **argv)
|
||||
memset(cfg,0,sizeof(ParodusCfg));
|
||||
|
||||
ParodusInfo("********** Starting component: Parodus **********\n ");
|
||||
parseCommandLine(argc,argv,cfg);
|
||||
setDefaultValuesToCfg(cfg);
|
||||
if (0 != parseCommandLine(argc,argv,cfg)) {
|
||||
abort();
|
||||
}
|
||||
getAuthToken(cfg);
|
||||
|
||||
createSocketConnection(cfg,NULL);
|
||||
createSocketConnection( NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -39,85 +39,172 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void parse_partner_id(char *partnerId, partners_t **partnersList)
|
||||
{
|
||||
char *token;
|
||||
int i = 0, j = 0, count = 0;
|
||||
ParodusPrint("********* %s ********\n",__FUNCTION__);
|
||||
while(partnerId[i] != '\0')
|
||||
{
|
||||
if(partnerId[i] == ',')
|
||||
{
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
ParodusPrint("count = %d\n", count+1);
|
||||
*partnersList = (partners_t *)malloc(sizeof(partners_t)+ sizeof( char * ) * (count+1));
|
||||
memset(*partnersList, 0, sizeof(partners_t));
|
||||
(*partnersList)->count = count+1;
|
||||
while ((token = strsep(&partnerId, ",")) != NULL)
|
||||
{
|
||||
ParodusPrint("token=%s\n", token);
|
||||
(*partnersList)->partner_ids[j] = strdup(token);
|
||||
ParodusPrint("(*partnersList)->partner_ids[%d] = %s\n",j,(*partnersList)->partner_ids[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
{
|
||||
int matchFlag = 0, i = 0, count = 0;
|
||||
size_t j = 0;
|
||||
partners_t *partnersList = NULL;
|
||||
char *partnerId = NULL;
|
||||
ParodusPrint("********* %s ********\n",__FUNCTION__);
|
||||
char *partnerId = get_parodus_cfg()->partner_id;
|
||||
if(strlen(partnerId) <= 0)
|
||||
char *temp = get_parodus_cfg()->partner_id;
|
||||
ParodusPrint("temp = %s\n",temp);
|
||||
if(temp[0] != '\0' && strlen(temp) > 0)
|
||||
{
|
||||
partnerId = strdup(temp);
|
||||
}
|
||||
ParodusPrint("partnerId = %s\n",partnerId);
|
||||
if(partnerId != NULL)
|
||||
{
|
||||
parse_partner_id(partnerId, &partnersList);
|
||||
ParodusPrint("partnersList->count = %lu\n", partnersList->count);
|
||||
if(msg->msg_type == WRP_MSG_TYPE__EVENT)
|
||||
{
|
||||
if(msg->u.event.partner_ids != NULL)
|
||||
{
|
||||
count = (int) msg->u.event.partner_ids->count;
|
||||
ParodusPrint("partner_ids count is %d\n",count);
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
for(j = 0; j<partnersList->count; j++)
|
||||
{
|
||||
ParodusPrint("partnersList->partner_ids[%lu] = %s\n",j, partnersList->partner_ids[j]);
|
||||
if(strcmp(partnersList->partner_ids[j], msg->u.event.partner_ids->partner_ids[i]) == 0)
|
||||
{
|
||||
ParodusInfo("partner_id match found\n");
|
||||
matchFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Commandline input partner_ids matched with partner_ids from request */
|
||||
if(matchFlag == 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Commandline input partner_ids not matching with partner_ids from request, appending to request partner_ids*/
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * (count+partnersList->count)));
|
||||
(*partnerIds)->count = count+partnersList->count;
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
(*partnerIds)->partner_ids[i] = msg->u.event.partner_ids->partner_ids[i];
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%d] : %s\n",i,(*partnerIds)->partner_ids[i]);
|
||||
}
|
||||
i = 0;
|
||||
for(j = count; j<(count+partnersList->count); j++)
|
||||
{
|
||||
(*partnerIds)->partner_ids[j] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[j], partnersList->partner_ids[i], 64);
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%lu] : %s\n",j,(*partnerIds)->partner_ids[j]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * partnersList->count));
|
||||
(*partnerIds)->count = partnersList->count;
|
||||
i=0;
|
||||
for(j = 0; j<partnersList->count; j++)
|
||||
{
|
||||
(*partnerIds)->partner_ids[j] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[j], partnersList->partner_ids[i], 64);
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%lu] : %s\n",j,(*partnerIds)->partner_ids[j]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(msg->msg_type == WRP_MSG_TYPE__REQ)
|
||||
{
|
||||
if(msg->u.req.partner_ids != NULL)
|
||||
{
|
||||
count = (int) msg->u.req.partner_ids->count;
|
||||
ParodusPrint("partner_ids count is %d\n",count);
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
for(j = 0; j<partnersList->count; j++)
|
||||
{
|
||||
ParodusPrint("partnersList->partner_ids[%lu] = %s\n",j, partnersList->partner_ids[j]);
|
||||
if(strcmp(partnersList->partner_ids[j], msg->u.req.partner_ids->partner_ids[i]) == 0)
|
||||
{
|
||||
ParodusInfo("partner_id match found\n");
|
||||
matchFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Commandline input partner_ids not matching with partner_ids from request, ignoring request*/
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
ParodusError("Invalid partner_id %s\n",temp);
|
||||
if(partnersList != NULL)
|
||||
{
|
||||
for(j=0; j<partnersList->count; j++)
|
||||
{
|
||||
if(partnersList->partner_ids[j] != NULL)
|
||||
{
|
||||
free(partnersList->partner_ids[j]);
|
||||
}
|
||||
}
|
||||
free(partnersList);
|
||||
}
|
||||
free(partnerId);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
}
|
||||
}
|
||||
if(partnersList != NULL)
|
||||
{
|
||||
for(j=0; j<partnersList->count; j++)
|
||||
{
|
||||
if(partnersList->partner_ids[j] != NULL)
|
||||
{
|
||||
free(partnersList->partner_ids[j]);
|
||||
}
|
||||
}
|
||||
free(partnersList);
|
||||
}
|
||||
free(partnerId);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_id is not available to validate\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(msg->msg_type == WRP_MSG_TYPE__EVENT)
|
||||
{
|
||||
if(msg->u.event.partner_ids != NULL)
|
||||
{
|
||||
count = (int) msg->u.event.partner_ids->count;
|
||||
ParodusPrint("partner_ids count is %d\n",count);
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
if(strcmp(partnerId, msg->u.event.partner_ids->partner_ids[i]) == 0)
|
||||
{
|
||||
ParodusInfo("partner_id match found\n");
|
||||
matchFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t));
|
||||
(*partnerIds)->count = count+1;
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
(*partnerIds)->partner_ids[i] = msg->u.event.partner_ids->partner_ids[i];
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%d] : %s\n",i,(*partnerIds)->partner_ids[i]);
|
||||
}
|
||||
(*partnerIds)->partner_ids[count] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[count], partnerId, 64);
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%d] : %s\n",count,(*partnerIds)->partner_ids[count]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t));
|
||||
(*partnerIds)->count = 1;
|
||||
(*partnerIds)->partner_ids[0] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[0], partnerId, 64);
|
||||
ParodusPrint("(*partnerIds)->partner_ids[0] : %s\n",(*partnerIds)->partner_ids[0]);
|
||||
}
|
||||
}
|
||||
else if(msg->msg_type == WRP_MSG_TYPE__REQ)
|
||||
{
|
||||
if(msg->u.req.partner_ids != NULL)
|
||||
{
|
||||
count = (int) msg->u.req.partner_ids->count;
|
||||
ParodusPrint("partner_ids count is %d\n",count);
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
if(strcmp(partnerId, msg->u.req.partner_ids->partner_ids[i]) == 0)
|
||||
{
|
||||
ParodusInfo("partner_id match found\n");
|
||||
matchFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
ParodusError("Invalid partner_id %s\n",partnerId);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void StartThread(void *(*start_routine) (void *))
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("Thread created Successfully %d\n", (int ) threadId);
|
||||
ParodusPrint("Thread created Successfully %lu\n", (unsigned long) threadId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
127
src/token.c
127
src/token.c
@@ -24,11 +24,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#ifdef __UCLIBC__
|
||||
#include <ucresolv/ucresolv.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <resolv.h>
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
#include <ucresolv.h>
|
||||
#endif
|
||||
//#include <res_update.h>
|
||||
#include <netdb.h>
|
||||
#include <strings.h>
|
||||
@@ -84,6 +83,15 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
|
||||
extern int __res_ninit(res_state statp);
|
||||
extern void __res_nclose(res_state statp);
|
||||
extern int __res_nquery(res_state statp,
|
||||
const char *name, /* domain name */
|
||||
int class, int type, /* class and type of query */
|
||||
u_char *answer, /* buffer to put answer */
|
||||
int anslen); /* size of answer buffer */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal functions */
|
||||
@@ -103,7 +111,8 @@ static void show_times (time_t exp_time, time_t cur_time)
|
||||
}
|
||||
|
||||
// returns 1 if insecure, 0 if secure, < 0 if error
|
||||
int analyze_jwt (const cjwt_t *jwt)
|
||||
int analyze_jwt (const cjwt_t *jwt, char *url_buf, int url_buflen,
|
||||
char *port_buf, int port_buflen)
|
||||
{
|
||||
cJSON *claims = jwt->private_claims;
|
||||
cJSON *endpoint = NULL;
|
||||
@@ -121,11 +130,11 @@ int analyze_jwt (const cjwt_t *jwt)
|
||||
return TOKEN_ERR_INVALID_JWT_CONTENT;
|
||||
}
|
||||
|
||||
http_match = strncmp(endpoint->valuestring,"http:",5);
|
||||
ParodusInfo ("is_http strncmp: %d\n", http_match);
|
||||
ParodusInfo ("JWT endpoint: %s\n", endpoint->valuestring);
|
||||
exp_time = jwt->exp.tv_sec;
|
||||
if (0 == exp_time) {
|
||||
ParodusError ("exp not found in JWT payload\n");
|
||||
return TOKEN_ERR_NO_EXPIRATION;
|
||||
} else {
|
||||
cur_time = time(NULL);
|
||||
show_times (exp_time, cur_time);
|
||||
@@ -134,49 +143,15 @@ int analyze_jwt (const cjwt_t *jwt)
|
||||
return TOKEN_ERR_JWT_EXPIRED;
|
||||
}
|
||||
}
|
||||
|
||||
return (http_match == 0);
|
||||
}
|
||||
|
||||
const char *get_tok (const char *src, int delim, char *result, int resultsize)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
int endx = resultsize-1;
|
||||
|
||||
memset (result, 0, resultsize);
|
||||
for (i=0; (c=src[i]) != 0; i++) {
|
||||
if (c == delim)
|
||||
break;
|
||||
if (i < endx)
|
||||
result[i] = c;
|
||||
http_match = parse_webpa_url (endpoint->valuestring,
|
||||
url_buf, url_buflen, port_buf, port_buflen);
|
||||
if (http_match < 0) {
|
||||
ParodusError ("Invalid endpoint claim in JWT\n");
|
||||
return TOKEN_ERR_BAD_ENDPOINT;
|
||||
}
|
||||
if (c == 0)
|
||||
return NULL;
|
||||
return src + i + 1;
|
||||
}
|
||||
ParodusInfo ("JWT is_http strncmp: %d\n", http_match);
|
||||
|
||||
// the algorithm mask indicates which algorithms are allowed
|
||||
unsigned int get_algo_mask (const char *algo_str)
|
||||
{
|
||||
unsigned int mask = 0;
|
||||
#define BUFLEN 16
|
||||
char tok[BUFLEN];
|
||||
int alg_val;
|
||||
|
||||
while(NULL != algo_str)
|
||||
{
|
||||
algo_str = get_tok (algo_str, ':', tok, BUFLEN);
|
||||
alg_val = cjwt_alg_str_to_enum (tok);
|
||||
if ((alg_val < 0) || (alg_val >= num_algorithms))
|
||||
{
|
||||
ParodusError("Invalid jwt algorithm %s\n", tok);
|
||||
abort ();
|
||||
}
|
||||
mask |= (1<<alg_val);
|
||||
}
|
||||
return mask;
|
||||
#undef BUFLEN
|
||||
return http_match;
|
||||
}
|
||||
|
||||
bool validate_algo(const cjwt_t *jwt)
|
||||
@@ -190,7 +165,7 @@ bool validate_algo(const cjwt_t *jwt)
|
||||
if ((alg < 0) || (alg >= num_algorithms))
|
||||
return false;
|
||||
alg_mask = 1<<alg;
|
||||
if ((alg_mask & get_algo_mask(cfg->jwt_algo)) == 0) {
|
||||
if ((alg_mask & cfg->jwt_algo) == 0) {
|
||||
ParodusError ("Algorithm %d not allowed (mask %d)\n", alg, alg_mask);
|
||||
return false;
|
||||
}
|
||||
@@ -198,7 +173,7 @@ bool validate_algo(const cjwt_t *jwt)
|
||||
}
|
||||
|
||||
|
||||
int nquery(const char* dns_txt_record_id,u_char *nsbuf)
|
||||
int nquery(const char* dns_txt_record_id, u_char *nsbuf)
|
||||
{
|
||||
|
||||
int len;
|
||||
@@ -206,15 +181,19 @@ int nquery(const char* dns_txt_record_id,u_char *nsbuf)
|
||||
|
||||
/* Initialize resolver */
|
||||
memset (&statp, 0, sizeof(__res_state));
|
||||
if (NULL == nsbuf) {
|
||||
ParodusError ("nquery: nsbuf is NULL\n");
|
||||
return (-1);
|
||||
}
|
||||
statp.options |= RES_DEBUG;
|
||||
if (res_ninit(&statp) < 0) {
|
||||
if (__res_ninit(&statp) < 0) {
|
||||
ParodusError ("res_ninit error: can't initialize statp.\n");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ParodusInfo ("Domain : %s\n", dns_txt_record_id);
|
||||
ParodusInfo ("nquery: domain : %s\n", dns_txt_record_id);
|
||||
memset (nsbuf, 0, NS_MAXBUF);
|
||||
len = res_nquery(&statp, dns_txt_record_id, ns_c_any, ns_t_txt, nsbuf, NS_MAXBUF);
|
||||
len = __res_nquery(&statp, dns_txt_record_id, ns_c_in, ns_t_txt, nsbuf, NS_MAXBUF);
|
||||
if (len < 0) {
|
||||
if (0 != statp.res_h_errno) {
|
||||
const char *msg = hstrerror (statp.res_h_errno);
|
||||
@@ -222,7 +201,8 @@ int nquery(const char* dns_txt_record_id,u_char *nsbuf)
|
||||
}
|
||||
return len;
|
||||
}
|
||||
res_nclose (&statp);
|
||||
__res_nclose (&statp);
|
||||
ParodusInfo ("nquery: nsbuf (1) 0x%lx\n", (unsigned long) nsbuf);
|
||||
if (len >= NS_MAXBUF) {
|
||||
ParodusError ("res_nquery error: ns buffer too small.\n");
|
||||
return -1;
|
||||
@@ -443,7 +423,8 @@ int query_dns(const char* dns_txt_record_id,char *jwt_ans)
|
||||
if( !dns_txt_record_id || !jwt_ans )
|
||||
return l;
|
||||
|
||||
nsbuf = malloc (NS_MAXBUF);
|
||||
nsbuf = (u_char *) malloc (NS_MAXBUF);
|
||||
ParodusInfo ("nsbuf (1) 0x%lx\n", (unsigned long) nsbuf);
|
||||
if (NULL == nsbuf) {
|
||||
ParodusError ("Unable to allocate nsbuf in query_dns\n");
|
||||
return TOKEN_ERR_MEMORY_FAIL;
|
||||
@@ -453,15 +434,23 @@ int query_dns(const char* dns_txt_record_id,char *jwt_ans)
|
||||
free (nsbuf);
|
||||
return l;
|
||||
}
|
||||
|
||||
ParodusInfo ("initparse\n");
|
||||
ret = ns_initparse(nsbuf, l, &msg_handle);
|
||||
ParodusInfo ("nsbuf (2) 0x%lx\n", (unsigned long) nsbuf);
|
||||
|
||||
/*--
|
||||
memset((void *) &msg_handle, 0x5e, sizeof (ns_msg));
|
||||
ParodusInfo ("nsbuf (3) 0x%lx\n", (unsigned long) nsbuf);
|
||||
msg_handle._msg = nsbuf;
|
||||
*/
|
||||
ParodusInfo ("ns_initparse, msglen %d, nsbuf 0x%lx\n",
|
||||
l, (unsigned long) nsbuf);
|
||||
ret = ns_initparse((const u_char *) nsbuf, l, &msg_handle);
|
||||
if (ret != 0) {
|
||||
ParodusError ("ns_initparse failed\n");
|
||||
free (nsbuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ParodusInfo ("ns_msg_count\n");
|
||||
l = ns_msg_count(msg_handle, ns_s_an);
|
||||
ParodusInfo ("query_dns: ns_msg_count : %d\n",l);
|
||||
jwt_ans[0] = 0;
|
||||
@@ -478,12 +467,15 @@ static void get_dns_txt_record_id (char *buf)
|
||||
ParodusCfg *cfg = get_parodus_cfg();
|
||||
buf[0] = 0;
|
||||
|
||||
sprintf (buf, "%s.%s.webpa.comcast.net", cfg->hw_mac, cfg->dns_id);
|
||||
sprintf (buf, "%s.%s", cfg->hw_mac, cfg->dns_txt_url);
|
||||
ParodusInfo("dns_txt_record_id %s\n", buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
int allow_insecure_conn(void)
|
||||
{
|
||||
int allow_insecure_conn(char *url_buf, int url_buflen,
|
||||
char *port_buf, int port_buflen)
|
||||
{
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
int insecure=0, ret = -1;
|
||||
char *jwt_token, *key;
|
||||
cjwt_t *jwt = NULL;
|
||||
@@ -498,7 +490,6 @@ int allow_insecure_conn(void)
|
||||
|
||||
get_dns_txt_record_id (dns_txt_record_id);
|
||||
|
||||
//Querying dns for jwt token
|
||||
ret = query_dns(dns_txt_record_id, jwt_token);
|
||||
if(ret){
|
||||
if (ret == TOKEN_ERR_MEMORY_FAIL) {
|
||||
@@ -527,16 +518,26 @@ int allow_insecure_conn(void)
|
||||
|
||||
//validate algo from --jwt_algo
|
||||
if( validate_algo(jwt) ) {
|
||||
insecure = analyze_jwt (jwt);
|
||||
insecure = analyze_jwt (jwt, url_buf, url_buflen, port_buf, port_buflen);
|
||||
} else {
|
||||
insecure = TOKEN_ERR_ALGO_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
if (insecure >= 0) {
|
||||
ParodusInfo ("JWT claims: %s\n", cJSON_Print (jwt->private_claims));
|
||||
}
|
||||
cjwt_destroy(&jwt);
|
||||
|
||||
end:
|
||||
if (NULL != jwt_token)
|
||||
free (jwt_token);
|
||||
#else
|
||||
(void) url_buf;
|
||||
(void) url_buflen;
|
||||
(void) port_buf;
|
||||
(void) port_buflen;
|
||||
int insecure = TOKEN_NO_DNS_QUERY;
|
||||
#endif
|
||||
ParodusPrint ("Allow Insecure %d\n", insecure);
|
||||
return insecure;
|
||||
}
|
||||
|
||||
48
src/token.h
48
src/token.h
@@ -34,19 +34,59 @@ typedef enum {
|
||||
TOKEN_ERR_JWT_DECODE_FAIL = -102,
|
||||
TOKEN_ERR_ALGO_NOT_ALLOWED = -103,
|
||||
TOKEN_ERR_INVALID_JWT_CONTENT = -104,
|
||||
TOKEN_ERR_JWT_EXPIRED = -105
|
||||
|
||||
TOKEN_ERR_NO_EXPIRATION = -105,
|
||||
TOKEN_ERR_JWT_EXPIRED = -106,
|
||||
TOKEN_ERR_BAD_ENDPOINT = -107,
|
||||
TOKEN_NO_DNS_QUERY = -1
|
||||
} token_error_t;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Connection Logic:
|
||||
|
||||
----- Criteria -----
|
||||
|
||||
Feature FeatureDnsQuery enabled
|
||||
QueryGood Dns query succeeds, jwt decodes and is valid and unexpired
|
||||
Endpt starts Endpoint specified in the jwt starts with http:// or https://
|
||||
Config Secflag secureFlag in config is set. Currently always set.
|
||||
|
||||
|
||||
----- Actions -----
|
||||
|
||||
Default Securely connect to the default URL, specified
|
||||
in the config
|
||||
Secure Securely connect to the endpoint given in the jwt
|
||||
Insecure Insecurely connect to the endpoint given in the jwt
|
||||
|
||||
|
||||
----- Logic Table -----
|
||||
|
||||
Feature Query Endpt Config Action
|
||||
Good Claim SecFlag
|
||||
|
||||
No Default
|
||||
Yes No Default
|
||||
Yes Yes https Secure
|
||||
Yes Yes http False Insecure
|
||||
Yes Yes http True Default
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* query the dns server, obtain a jwt, determine if insecure
|
||||
* connections can be allowed.
|
||||
*
|
||||
*
|
||||
* @param url_buf buffer containing endpoint value found in JWT
|
||||
* @param url_buflen len of the url buffer provided by caller
|
||||
* @param port_buf buffer containing port value found in JWT
|
||||
* @param port_buflen len of the port buffer provided by caller
|
||||
* @return 1 if insecure connection is allowed, 0 if not,
|
||||
* or one of the error codes given above.
|
||||
*/
|
||||
int allow_insecure_conn(void);
|
||||
int allow_insecure_conn(char *url_buf, int url_buflen,
|
||||
char *port_buf, int port_buflen);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -172,8 +172,7 @@ void *processUpstreamMessage()
|
||||
int rv=-1, rc = -1;
|
||||
int msgType;
|
||||
wrp_msg_t *msg;
|
||||
void *appendData, *bytes;
|
||||
size_t encodedSize;
|
||||
void *bytes;
|
||||
reg_list_item_t *temp = NULL;
|
||||
int matchFlag = 0;
|
||||
int status = -1;
|
||||
@@ -301,24 +300,14 @@ void *processUpstreamMessage()
|
||||
else
|
||||
{
|
||||
//Sending to server for msgTypes 3, 5, 6, 7, 8.
|
||||
ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s\n", msgType, msg->u.req.dest, msg->u.req.transaction_uuid );
|
||||
//Appending metadata with packed msg received from client
|
||||
if(metaPackSize > 0)
|
||||
{
|
||||
ParodusPrint("Appending received msg with metadata\n");
|
||||
encodedSize = appendEncodedData( &appendData, message->msg, message->len, metadataPack, metaPackSize );
|
||||
ParodusPrint("encodedSize after appending :%zu\n", encodedSize);
|
||||
ParodusPrint("metadata appended upstream msg %s\n", (char *)appendData);
|
||||
ParodusInfo("Sending metadata appended upstream msg to server\n");
|
||||
sendMessage(get_global_conn(),appendData, encodedSize);
|
||||
|
||||
free( appendData);
|
||||
appendData =NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to send upstream as metadata packing is not successful\n");
|
||||
if( WRP_MSG_TYPE__REQ == msgType ) {
|
||||
ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s\n",
|
||||
msgType, msg->u.req.dest, msg->u.req.transaction_uuid );
|
||||
} else {
|
||||
ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s status: %d\n",
|
||||
msgType, msg->u.crud.dest, msg->u.crud.transaction_uuid, msg->u.crud.status );
|
||||
}
|
||||
sendUpstreamMsgToServer(&message->msg, message->len);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -16,16 +16,19 @@ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST ")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -O0")
|
||||
set (PARODUS_COMMON_SRC ../src/string_helpers.c ../src/mutex.c ../src/time.c ../src/config.c ../src/spin_thread.c)
|
||||
set (PARODUS_COMMON_LIBS gcov -lcunit -lcimplog -lwrp-c -luuid -lpthread -lmsgpackc -lnopoll -lnanomsg -Wl,--no-as-needed -lcjson -ltrower-base64 -lssl -lcrypto -lrt -lm)
|
||||
set (PARODUS_COMMON_SRC ../src/string_helpers.c ../src/mutex.c ../src/time.c ../src/config.c ../src/spin_thread.c ../src/token.c)
|
||||
set (PARODUS_COMMON_LIBS gcov -lcunit -lcimplog -lwrp-c
|
||||
-luuid -lpthread -lmsgpackc -lnopoll -lnanomsg
|
||||
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
|
||||
-lssl -lcrypto -lrt -lm)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
set (PARODUS_COMMON_LIBS -llibseshat ${PARODUS_COMMON_LIBS})
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (ENABLE_CJWT)
|
||||
set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lcjwt -lresolv)
|
||||
endif (ENABLE_CJWT)
|
||||
if (FEATURE_DNS_QUERY)
|
||||
set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lucresolv -lresolv)
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
if(NOT DISABLE_VALGRIND)
|
||||
set (MEMORY_CHECK valgrind --leak-check=full --show-reachable=yes -v)
|
||||
@@ -116,13 +119,9 @@ add_test(NAME test_connection COMMAND ${MEMORY_CHECK} ./test_connection)
|
||||
#add_executable(test_connection test_connection.c ../src/connection.c ${PARODUS_COMMON_SRC})
|
||||
#target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
set(SOURCES test_connection.c ../src/connection.c ${PARODUS_COMMON_SRC})
|
||||
if (ENABLE_CJWT)
|
||||
set(SOURCES ${SOURCES} ../src/token.c)
|
||||
else ()
|
||||
set(SOURCES ${SOURCES} ../src/token_stub.c)
|
||||
endif (ENABLE_CJWT)
|
||||
add_executable(test_connection ${SOURCES})
|
||||
target_link_libraries (test_connection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
#target_link_libraries (test_connection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_connection - function createNopollConnection
|
||||
@@ -131,7 +130,8 @@ add_test(NAME test_createConnection COMMAND ${MEMORY_CHECK} ./test_createConnect
|
||||
#add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c)
|
||||
#target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c)
|
||||
target_link_libraries (test_createConnection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
#target_link_libraries (test_createConnection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_client_list
|
||||
@@ -151,13 +151,9 @@ else()
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (ENABLE_CJWT)
|
||||
set(SOURCES ${SOURCES} ../src/token.c)
|
||||
else ()
|
||||
set(SOURCES ${SOURCES} ../src/token_stub.c)
|
||||
endif (ENABLE_CJWT)
|
||||
add_executable(test_client_list ${SOURCES})
|
||||
target_link_libraries (test_client_list ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
|
||||
#target_link_libraries (test_client_list ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
|
||||
target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_service_alive
|
||||
@@ -172,13 +168,9 @@ else()
|
||||
set(SOURCES ${SOURCES} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (ENABLE_CJWT)
|
||||
set(SOURCES ${SOURCES} ../src/token.c)
|
||||
else ()
|
||||
set(SOURCES ${SOURCES} ../src/token_stub.c)
|
||||
endif (ENABLE_CJWT)
|
||||
add_executable(test_service_alive ${SOURCES})
|
||||
target_link_libraries (test_service_alive ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
|
||||
#target_link_libraries (test_service_alive ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
|
||||
target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_config
|
||||
@@ -187,7 +179,7 @@ add_test(NAME test_config COMMAND ${MEMORY_CHECK} ./test_config)
|
||||
add_executable(test_config test_config.c ../src/config.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_config -lcmocka
|
||||
-Wl,--no-as-needed -lcimplog
|
||||
-lcjson -ltrower-base64 -lssl -lcrypto -lrt -lm
|
||||
-lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -249,13 +241,9 @@ target_link_libraries (test_partners_check -lcmocka ${PARODUS_COMMON_LIBS} -lwrp
|
||||
# test_token - token.c tests
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_token COMMAND ${MEMORY_CHECK} ./test_token)
|
||||
if (ENABLE_CJWT)
|
||||
set(SOURCES test_token.c ../src/token.c ../src/string_helpers.c ../src/config.c)
|
||||
else()
|
||||
set(SOURCES test_token_stub.c ../src/token_stub.c)
|
||||
endif (ENABLE_CJWT)
|
||||
add_executable(test_token ${SOURCES} )
|
||||
target_link_libraries (test_token ${PARODUS_COMMON_LIBS} ${PARODUS_JWT_LIBS} -lcmocka )
|
||||
#target_link_libraries (test_token ${PARODUS_COMMON_LIBS} ${PARODUS_JWT_LIBS} -lcmocka )
|
||||
target_link_libraries (test_token ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_seshat_interface - registerWithSeshat
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
./parodus --hw-model=TG1682 --hw-serial-number=Fer23u948590 --hw-manufacturer=ARRISGroup,Inc. --hw-mac=aabbccddeeff --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_2016000000sdy --boot-time=123589 --webpa-ping-time=180 --webpa-backoff-max=0 --webpa-inteface-used=p7p1 --webpa-url=fabric-beta.webpa.comcast.net --jwt-algo=none:RS256 --jwt-key=../../tests/webpa-rs256.pem --dns-id=test
|
||||
sudo ./parodus --hw-model=TG1682 --hw-serial-number=Fer23u948590 --hw-manufacturer=ARRISGroup,Inc. --hw-mac=aabb33ddeeff --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_2016000000sdy --boot-time=123589 --webpa-ping-timeout=180 --webpa-backoff-max=0 --webpa-interface-used=p7p1 --webpa-url=https://example.net:8080 --acquire-jwt=1 --jwt-algo=RS256 --jwt-public-key-file=../../tests/webpa-rs256.pem --dns-txt-url=example.net
|
||||
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ void test_getWebpaConveyHeader()
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
parStrncpy(cfg.webpa_uuid , "1234567-345456546", sizeof(cfg.webpa_uuid));
|
||||
cfg.flags = FLAGS_SECURE;
|
||||
cfg.flags = 0;
|
||||
cfg.boot_time = 423457;
|
||||
cfg.webpa_ping_timeout = 30;
|
||||
cfg.webpa_backoff_max = 255;
|
||||
|
||||
@@ -26,7 +26,15 @@
|
||||
|
||||
#include "../src/config.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
#define K_argc 18
|
||||
|
||||
extern int parse_mac_address (char *target, const char *arg);
|
||||
extern int server_is_http (const char *full_url,
|
||||
const char **server_ptr);
|
||||
extern int parse_webpa_url(const char *full_url,
|
||||
char *server_addr, int server_addr_buflen,
|
||||
char *port_buf, int port_buflen);
|
||||
extern unsigned int get_algo_mask (const char *algo_str);
|
||||
extern unsigned int parse_num_arg (const char *arg, const char *arg_name);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
@@ -57,7 +65,7 @@ void test_setParodusConfig()
|
||||
parStrncpy(cfg.hw_last_reboot_reason , "unknown", sizeof(cfg.hw_last_reboot_reason));
|
||||
parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name));
|
||||
parStrncpy(cfg.webpa_path_url , "/v1", sizeof(cfg.webpa_path_url));
|
||||
parStrncpy(cfg.webpa_url , "localhost", sizeof(cfg.webpa_url));
|
||||
parStrncpy(cfg.webpa_url , "http://127.0.0.1", sizeof(cfg.webpa_url));
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
parStrncpy(cfg.webpa_uuid , "1234567-345456546", sizeof(cfg.webpa_uuid));
|
||||
@@ -65,11 +73,16 @@ void test_setParodusConfig()
|
||||
#ifdef ENABLE_SESHAT
|
||||
parStrncpy(cfg.seshat_url, "ipc://tmp/seshat_service.url", sizeof(cfg.seshat_url));
|
||||
#endif
|
||||
cfg.flags = FLAGS_SECURE;
|
||||
cfg.flags = 0;
|
||||
cfg.boot_time = 423457;
|
||||
cfg.webpa_ping_timeout = 30;
|
||||
cfg.webpa_backoff_max = 255;
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
cfg.acquire_jwt = 1;
|
||||
parStrncpy(cfg.dns_txt_url, "test",sizeof(cfg.dns_txt_url));
|
||||
cfg.jwt_algo = 1025;
|
||||
parStrncpy(cfg.jwt_key, "key.txt",sizeof(cfg.jwt_key));
|
||||
#endif
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
ParodusCfg *temp = get_parodus_cfg();
|
||||
@@ -92,6 +105,12 @@ void test_setParodusConfig()
|
||||
assert_int_equal((int) cfg.boot_time, (int) temp->boot_time);
|
||||
assert_int_equal((int) cfg.webpa_ping_timeout, (int) temp->webpa_ping_timeout);
|
||||
assert_int_equal((int) cfg.webpa_backoff_max, (int) temp->webpa_backoff_max);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
assert_int_equal( (int) cfg.acquire_jwt, (int) temp->acquire_jwt);
|
||||
assert_string_equal(cfg.dns_txt_url, temp->dns_txt_url);
|
||||
assert_int_equal( (int) cfg.jwt_algo, (int) temp->jwt_algo);
|
||||
assert_string_equal(cfg.jwt_key, temp->jwt_key);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_getParodusConfig()
|
||||
@@ -107,42 +126,80 @@ void test_getParodusConfig()
|
||||
assert_string_equal(cfg.hw_model, temp->hw_model);
|
||||
}
|
||||
|
||||
static int open_output_file (const char *fname)
|
||||
{
|
||||
int fd = open(fname, O_WRONLY | O_CREAT, 0666);
|
||||
if (fd<0)
|
||||
{
|
||||
ParodusError ("File %s open error\n", fname);
|
||||
abort ();
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
void write_key_to_file (const char *fname, const char *buf)
|
||||
{
|
||||
ssize_t nbytes;
|
||||
ssize_t buflen = strlen (buf);
|
||||
int fd = open_output_file(fname);
|
||||
nbytes = write(fd, buf, buflen);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
ParodusError ("Write file %s error\n", fname);
|
||||
close(fd);
|
||||
abort ();
|
||||
}
|
||||
close(fd);
|
||||
ParodusInfo ("%d bytes written\n", nbytes);
|
||||
}
|
||||
|
||||
void test_parseCommandLine()
|
||||
{
|
||||
int argc =K_argc;
|
||||
#ifndef ENABLE_SESHAT
|
||||
argc = argc - 1;
|
||||
char expectedToken[1280] = {'\0'};
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
const char *jwt_key = "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd";
|
||||
#endif
|
||||
char * command[argc+1];
|
||||
int i = 0;
|
||||
char expectedToken[128] = {'\0'};
|
||||
|
||||
command[i++] = "parodus";
|
||||
command[i++] = "--hw-model=TG1682";
|
||||
command[i++] = "--hw-serial-number=Fer23u948590";
|
||||
command[i++] = "--hw-manufacturer=ARRISGroup,Inc.";
|
||||
command[i++] = "--hw-mac=123567892366";
|
||||
command[i++] = "--hw-last-reboot-reason=unknown";
|
||||
command[i++] = "--fw-name=TG1682_DEV_master_2016000000sdy";
|
||||
command[i++] = "--webpa-ping-time=180";
|
||||
command[i++] = "--webpa-interface-used=br0";
|
||||
command[i++] = "--webpa-url=localhost";
|
||||
command[i++] = "--webpa-backoff-max=0";
|
||||
command[i++] = "--boot-time=1234";
|
||||
command[i++] = "--parodus-local-url=tcp://127.0.0.1:6666";
|
||||
command[i++] = "--partner-id=cox";
|
||||
char *command[] = {"parodus",
|
||||
"--hw-model=TG1682",
|
||||
"--hw-serial-number=Fer23u948590",
|
||||
"--hw-manufacturer=ARRISGroup,Inc.",
|
||||
"--hw-mac=123567892366",
|
||||
"--hw-last-reboot-reason=unknown",
|
||||
"--fw-name=TG1682_DEV_master_2016000000sdy",
|
||||
"--webpa-ping-timeout=180",
|
||||
"--webpa-interface-used=br0",
|
||||
"--webpa-url=http://127.0.0.1",
|
||||
"--webpa-backoff-max=0",
|
||||
"--boot-time=1234",
|
||||
"--parodus-local-url=tcp://127.0.0.1:6666",
|
||||
"--partner-id=cox",
|
||||
#ifdef ENABLE_SESHAT
|
||||
command[i++] = "--seshat-url=ipc://127.0.0.1:7777";
|
||||
"--seshat-url=ipc://127.0.0.1:7777",
|
||||
#endif
|
||||
command[i++] = "--force-ipv4";
|
||||
command[i++] = "--force-ipv6";
|
||||
command[i++] = "--webpa-token=/tmp/token.sh";
|
||||
command[i] = '\0';
|
||||
"--force-ipv4",
|
||||
"--force-ipv6",
|
||||
"--token-read-script=/tmp/token.sh",
|
||||
"--token-acquisition-script=/tmp/token.sh",
|
||||
"--ssl-cert-path=/etc/ssl/certs/ca-certificates.crt",
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
"--acquire-jwt=1",
|
||||
"--dns-txt-url=fabric.comcast.net",
|
||||
"--jwt-public-key-file=../../tests/jwt_key.tst",
|
||||
"--jwt-algo=RS256",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
int argc = (sizeof (command) / sizeof (char *)) - 1;
|
||||
|
||||
ParodusCfg parodusCfg;
|
||||
memset(&parodusCfg,0,sizeof(parodusCfg));
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
write_key_to_file ("../../tests/jwt_key.tst", jwt_key);
|
||||
#endif
|
||||
create_token_script("/tmp/token.sh");
|
||||
parseCommandLine(argc,command,&parodusCfg);
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), 0);
|
||||
|
||||
assert_string_equal( parodusCfg.hw_model, "TG1682");
|
||||
assert_string_equal( parodusCfg.hw_serial_number, "Fer23u948590");
|
||||
@@ -152,7 +209,7 @@ void test_parseCommandLine()
|
||||
assert_string_equal( parodusCfg.fw_name, "TG1682_DEV_master_2016000000sdy");
|
||||
assert_int_equal( (int) parodusCfg.webpa_ping_timeout,180);
|
||||
assert_string_equal( parodusCfg.webpa_interface_used, "br0");
|
||||
assert_string_equal( parodusCfg.webpa_url, "localhost");
|
||||
assert_string_equal( parodusCfg.webpa_url, "http://127.0.0.1");
|
||||
assert_int_equal( (int) parodusCfg.webpa_backoff_max,0);
|
||||
assert_int_equal( (int) parodusCfg.boot_time,1234);
|
||||
assert_string_equal( parodusCfg.local_url,"tcp://127.0.0.1:6666");
|
||||
@@ -162,39 +219,76 @@ void test_parseCommandLine()
|
||||
#endif
|
||||
assert_int_equal( (int) parodusCfg.flags, FLAGS_IPV6_ONLY|FLAGS_IPV4_ONLY);
|
||||
sprintf(expectedToken,"secure-token-%s-%s",parodusCfg.hw_serial_number,parodusCfg.hw_mac);
|
||||
assert_string_equal( parodusCfg.webpa_token,expectedToken);
|
||||
getAuthToken(&parodusCfg);
|
||||
set_parodus_cfg(&parodusCfg);
|
||||
|
||||
assert_string_equal( get_parodus_cfg()->webpa_auth_token,expectedToken);
|
||||
assert_string_equal( parodusCfg.cert_path,"/etc/ssl/certs/ca-certificates.crt");
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
assert_int_equal( (int) parodusCfg.acquire_jwt, 1);
|
||||
assert_string_equal(parodusCfg.dns_txt_url, "fabric.comcast.net");
|
||||
assert_int_equal( (int) parodusCfg.jwt_algo, 1024);
|
||||
assert_string_equal ( get_parodus_cfg()->jwt_key, jwt_key);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void test_parseCommandLineNull()
|
||||
{
|
||||
parseCommandLine(0,NULL,NULL);
|
||||
assert_int_equal (parseCommandLine(0,NULL,NULL), -1);
|
||||
}
|
||||
|
||||
void err_parseCommandLine()
|
||||
{
|
||||
int argc =K_argc;
|
||||
#ifndef ENABLE_SESHAT
|
||||
argc = argc - 1;
|
||||
#endif
|
||||
char * command[20]={'\0'};
|
||||
|
||||
command[0] = "parodus";
|
||||
command[1] = "--hw-model=TG1682";
|
||||
command[12] = "webpa";
|
||||
|
||||
int argc;
|
||||
char *command[] = {"parodus",
|
||||
"--hw-model=TG1682",
|
||||
"--hw-serial-number=Fer23u948590",
|
||||
"-Z",
|
||||
"--nosuch",
|
||||
"--hw-mac=123567892366",
|
||||
"webpa",
|
||||
NULL
|
||||
};
|
||||
ParodusCfg parodusCfg;
|
||||
|
||||
memset(&parodusCfg,0,sizeof(parodusCfg));
|
||||
|
||||
parseCommandLine(argc,command,&parodusCfg);
|
||||
assert_string_equal( parodusCfg.hw_model, "");
|
||||
assert_string_equal( parodusCfg.hw_serial_number, "");
|
||||
argc = (sizeof (command) / sizeof (char *)) - 1;
|
||||
// Missing webpa_url
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
// Bad webpa_url
|
||||
command[5] = "--webpa-url=127.0.0.1";
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
// Bad mac address
|
||||
command[5] = "--hw-mac=1235678923";
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
command[5] = "--webpa-ping-timeout=123x";
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
command[5] = "--webpa-backoff-max=";
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
command[5] = "--boot-time=12x";
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
command[5] = "--webpa-url=https://127.0.0.1";
|
||||
command[3] = "--acquire-jwt=1";
|
||||
command[4] = "--dns-txt-url=fabric.comcast.net";
|
||||
// missing algo
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
command[4] = "--jwt-algo=none:RS256";
|
||||
// disallowed alogrithm none
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
command[4] = "--jwt-algo=RS256";
|
||||
// missing jwt public key file
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), -1);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_loadParodusCfg()
|
||||
{
|
||||
ParodusCfg tmpcfg;
|
||||
ParodusCfg *Cfg;
|
||||
ParodusCfg *Cfg = NULL;
|
||||
Cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
|
||||
char protocol[32] = {'\0'};
|
||||
|
||||
@@ -205,13 +299,24 @@ void test_loadParodusCfg()
|
||||
parStrncpy(Cfg->hw_last_reboot_reason , "unknown", sizeof(Cfg->hw_last_reboot_reason));
|
||||
parStrncpy(Cfg->fw_name , "2.364s2", sizeof(Cfg->fw_name));
|
||||
parStrncpy(Cfg->webpa_path_url , "/v1", sizeof(Cfg->webpa_path_url));
|
||||
parStrncpy(Cfg->webpa_url , "localhost", sizeof(Cfg->webpa_url));
|
||||
parStrncpy(Cfg->webpa_url , "http://127.0.0.1", sizeof(Cfg->webpa_url));
|
||||
parStrncpy(Cfg->webpa_interface_used , "eth0", sizeof(Cfg->webpa_interface_used));
|
||||
snprintf(protocol, sizeof(protocol), "%s-%s", PROTOCOL_VALUE, GIT_COMMIT_TAG);
|
||||
parStrncpy(Cfg->webpa_protocol , protocol, sizeof(Cfg->webpa_protocol));
|
||||
parStrncpy(Cfg->local_url , "tcp://10.0.0.1:6000", sizeof(Cfg->local_url));
|
||||
parStrncpy(Cfg->partner_id , "shaw", sizeof(Cfg->partner_id));
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
Cfg->acquire_jwt = 1;
|
||||
parStrncpy(Cfg->dns_txt_url, "fabric",sizeof(Cfg->dns_txt_url));
|
||||
Cfg->jwt_algo = 1025;
|
||||
parStrncpy(Cfg->jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd",sizeof(Cfg->jwt_key));
|
||||
#endif
|
||||
parStrncpy(Cfg->token_acquisition_script , "/tmp/token.sh", sizeof(Cfg->token_acquisition_script));
|
||||
parStrncpy(Cfg->token_read_script , "/tmp/token.sh", sizeof(Cfg->token_read_script));
|
||||
parStrncpy(Cfg->cert_path, "/etc/ssl.crt",sizeof(Cfg->cert_path));
|
||||
#ifdef ENABLE_SESHAT
|
||||
parStrncpy(Cfg->seshat_url, "ipc://tmp/seshat_service.url", sizeof(Cfg->seshat_url));
|
||||
#endif
|
||||
memset(&tmpcfg,0,sizeof(ParodusCfg));
|
||||
loadParodusCfg(Cfg,&tmpcfg);
|
||||
|
||||
@@ -222,6 +327,18 @@ void test_loadParodusCfg()
|
||||
assert_string_equal( tmpcfg.local_url, "tcp://10.0.0.1:6000");
|
||||
assert_string_equal( tmpcfg.partner_id, "shaw");
|
||||
assert_string_equal( tmpcfg.webpa_protocol, protocol);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
assert_int_equal( (int) tmpcfg.acquire_jwt, 1);
|
||||
assert_string_equal(tmpcfg.dns_txt_url, "fabric");
|
||||
assert_int_equal( (int) tmpcfg.jwt_algo, 1025);
|
||||
assert_string_equal(tmpcfg.jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd");
|
||||
#endif
|
||||
assert_string_equal( tmpcfg.token_acquisition_script,"/tmp/token.sh");
|
||||
assert_string_equal( tmpcfg.token_read_script,"/tmp/token.sh");
|
||||
assert_string_equal(tmpcfg.cert_path, "/etc/ssl.crt");
|
||||
#ifdef ENABLE_SESHAT
|
||||
assert_string_equal(tmpcfg.seshat_url, "ipc://tmp/seshat_service.url");
|
||||
#endif
|
||||
free(Cfg);
|
||||
}
|
||||
|
||||
@@ -238,7 +355,7 @@ void test_loadParodusCfgNull()
|
||||
assert_string_equal(temp.hw_model, "");
|
||||
assert_string_equal(temp.hw_serial_number, "");
|
||||
assert_string_equal(temp.hw_manufacturer, "");
|
||||
assert_int_equal( (int) temp.flags,FLAGS_SECURE);
|
||||
assert_int_equal( (int) temp.flags,0);
|
||||
assert_string_equal( temp.webpa_path_url, WEBPA_PATH_URL);
|
||||
assert_string_equal( temp.webpa_uuid,"1234567-345456546");
|
||||
assert_string_equal( temp.local_url, PARODUS_UPSTREAM);
|
||||
@@ -270,10 +387,106 @@ void test_parodusGitVersion()
|
||||
}
|
||||
pclose(fp);
|
||||
|
||||
printf ("version: %s\n", version);
|
||||
printf ("GIT_COMMIT_TAG: %s\n", GIT_COMMIT_TAG);
|
||||
n = strcmp( version, GIT_COMMIT_TAG);
|
||||
assert_int_equal(n, 0);
|
||||
}
|
||||
|
||||
void test_setDefaultValuesToCfg()
|
||||
{
|
||||
ParodusCfg *cfg = (ParodusCfg *) malloc(sizeof(ParodusCfg));
|
||||
memset(cfg,0,sizeof(ParodusCfg));
|
||||
setDefaultValuesToCfg(cfg);
|
||||
assert_string_equal( cfg->local_url, PARODUS_UPSTREAM);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
assert_int_equal(cfg->acquire_jwt, 0);
|
||||
assert_string_equal(cfg->dns_txt_url, DNS_TXT_URL);
|
||||
assert_string_equal(cfg->jwt_key, "\0");
|
||||
assert_int_equal( (int)cfg->jwt_algo, 0);
|
||||
#endif
|
||||
assert_string_equal(cfg->cert_path, "\0");
|
||||
assert_int_equal((int)cfg->flags, 0);
|
||||
assert_string_equal(cfg->webpa_path_url, WEBPA_PATH_URL);
|
||||
assert_string_equal(cfg->webpa_uuid, "1234567-345456546");
|
||||
}
|
||||
|
||||
void err_setDefaultValuesToCfg()
|
||||
{
|
||||
setDefaultValuesToCfg(NULL);
|
||||
}
|
||||
|
||||
void test_parse_num_arg ()
|
||||
{
|
||||
assert_int_equal (parse_num_arg ("1234", "1234"), 1234);
|
||||
assert_int_equal (parse_num_arg ("1", "1"), 1);
|
||||
assert_int_equal (parse_num_arg ("0", "0"), 0);
|
||||
assert_true (parse_num_arg ("", "empty arg") == (unsigned int) -1);
|
||||
assert_true (parse_num_arg ("0x", "non-num arg") == (unsigned int) -1);
|
||||
|
||||
}
|
||||
|
||||
void test_parse_mac_address ()
|
||||
{
|
||||
char result[14];
|
||||
assert_int_equal (parse_mac_address (result, "aabbccddeeff"), 0);
|
||||
assert_string_equal (result, "aabbccddeeff");
|
||||
assert_int_equal (parse_mac_address (result, "aa:bb:cc:dd:ee:ff"), 0);
|
||||
assert_string_equal (result, "aabbccddeeff");
|
||||
assert_int_equal (parse_mac_address (result, "aabbccddeeff0"), -1);
|
||||
assert_int_equal (parse_mac_address (result, "aa:bb:c:dd:ee:ff:00"), -1);
|
||||
assert_int_equal (parse_mac_address (result, ""), -1);
|
||||
}
|
||||
|
||||
void test_server_is_http ()
|
||||
{
|
||||
const char *server_ptr;
|
||||
assert_int_equal (server_is_http ("https://127.0.0.1", &server_ptr), 0);
|
||||
assert_string_equal (server_ptr, "127.0.0.1");
|
||||
assert_int_equal (server_is_http ("http://127.0.0.1", &server_ptr), 1);
|
||||
assert_string_equal (server_ptr, "127.0.0.1");
|
||||
assert_int_equal (server_is_http ("127.0.0.1", &server_ptr), -1);
|
||||
|
||||
}
|
||||
|
||||
void test_parse_webpa_url ()
|
||||
{
|
||||
char addr_buf[80];
|
||||
char port_buf[8];
|
||||
assert_int_equal (parse_webpa_url ("fabric.webpa.comcast.net:8080",
|
||||
addr_buf, 80, port_buf, 8), -1);
|
||||
assert_int_equal (parse_webpa_url ("https://fabric.webpa.comcast.net:8080",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "fabric.webpa.comcast.net");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
assert_int_equal (parse_webpa_url ("https://fabric.webpa.comcast.net/",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "fabric.webpa.comcast.net");
|
||||
assert_string_equal (port_buf, "443");
|
||||
assert_int_equal (parse_webpa_url ("http://fabric.webpa.comcast.net:8080",
|
||||
addr_buf, 80, port_buf, 8), 1);
|
||||
assert_string_equal (addr_buf, "fabric.webpa.comcast.net");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
assert_int_equal (parse_webpa_url ("http://fabric.webpa.comcast.net",
|
||||
addr_buf, 80, port_buf, 8), 1);
|
||||
assert_string_equal (addr_buf, "fabric.webpa.comcast.net");
|
||||
assert_string_equal (port_buf, "80");
|
||||
|
||||
}
|
||||
|
||||
void test_get_algo_mask ()
|
||||
{
|
||||
assert_true (get_algo_mask ("RS256:RS512") == 5120);
|
||||
assert_true (get_algo_mask ("none:RS256") == (unsigned int) -1);
|
||||
assert_true (get_algo_mask ("nosuch") == (unsigned int) -1);
|
||||
#if ALLOW_NON_RSA_ALG
|
||||
assert_true (get_algo_mask ("ES256:RS256") == 1026);
|
||||
#else
|
||||
assert_true (get_algo_mask ("ES256:RS256") == (unsigned int) -1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -286,10 +499,17 @@ int main(void)
|
||||
cmocka_unit_test(test_loadParodusCfg),
|
||||
cmocka_unit_test(test_loadParodusCfgNull),
|
||||
cmocka_unit_test(err_loadParodusCfg),
|
||||
cmocka_unit_test(test_parse_num_arg),
|
||||
cmocka_unit_test(test_parse_mac_address),
|
||||
cmocka_unit_test(test_get_algo_mask),
|
||||
cmocka_unit_test(test_server_is_http),
|
||||
cmocka_unit_test(test_parse_webpa_url),
|
||||
cmocka_unit_test(test_parseCommandLine),
|
||||
cmocka_unit_test(test_parseCommandLineNull),
|
||||
cmocka_unit_test(err_parseCommandLine),
|
||||
cmocka_unit_test(test_parodusGitVersion)
|
||||
cmocka_unit_test(test_parodusGitVersion),
|
||||
cmocka_unit_test(test_setDefaultValuesToCfg),
|
||||
cmocka_unit_test(err_setDefaultValuesToCfg),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -190,7 +190,7 @@ void test_createSocketConnection()
|
||||
expect_function_call(close_and_unref_connection);
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(&cfg,initKeypress);
|
||||
createSocketConnection(initKeypress);
|
||||
}
|
||||
|
||||
void test_createSocketConnection1()
|
||||
@@ -225,7 +225,7 @@ void test_createSocketConnection1()
|
||||
expect_function_call(close_and_unref_connection);
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(&cfg,NULL);
|
||||
createSocketConnection(NULL);
|
||||
|
||||
}
|
||||
|
||||
@@ -246,6 +246,7 @@ void test_createSocketConnection2()
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
parStrncpy(cfg.webpa_uuid , "1234567-345456546", sizeof(cfg.webpa_uuid));
|
||||
cfg.webpa_ping_timeout = 1;
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = false;
|
||||
@@ -281,7 +282,7 @@ void test_createSocketConnection2()
|
||||
expect_function_call(close_and_unref_connection);
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(&cfg,NULL);
|
||||
createSocketConnection(NULL);
|
||||
}
|
||||
|
||||
void err_createSocketConnection()
|
||||
@@ -314,7 +315,7 @@ void err_createSocketConnection()
|
||||
expect_function_call(close_and_unref_connection);
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(NULL,NULL);
|
||||
createSocketConnection(NULL);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include "../src/connection.h"
|
||||
#include "../src/config.h"
|
||||
|
||||
#define SECURE_WEBPA_URL "https://127.0.0.1"
|
||||
#define UNSECURE_WEBPA_URL "http://127.0.0.1"
|
||||
#define HOST_IP "127.0.0.1"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
@@ -37,6 +40,9 @@ bool close_retry;
|
||||
bool LastReasonStatus;
|
||||
volatile unsigned int heartBeatTimer;
|
||||
pthread_mutex_t close_mut;
|
||||
int g_status;
|
||||
char *g_redirect_url;
|
||||
int mock_strncmp = true;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
@@ -82,18 +88,36 @@ nopoll_bool nopoll_conn_is_ok (noPollConn * conn)
|
||||
return (nopoll_bool) mock();
|
||||
}
|
||||
|
||||
nopoll_bool nopoll_conn_wait_until_connection_ready (noPollConn * conn, int timeout, char * message)
|
||||
int getGlobalHttpStatus()
|
||||
{
|
||||
return g_status;
|
||||
}
|
||||
|
||||
void setGlobalHttpStatus(int status)
|
||||
{
|
||||
g_status=status;
|
||||
}
|
||||
|
||||
void setGlobalRedirectUrl (char *redirect_url)
|
||||
{
|
||||
g_redirect_url = redirect_url;
|
||||
}
|
||||
|
||||
nopoll_bool nopoll_conn_wait_until_connection_ready (noPollConn * conn, int timeout, int *status, char * message)
|
||||
{
|
||||
UNUSED(timeout); UNUSED(message);
|
||||
UNUSED(conn);
|
||||
*status = getGlobalHttpStatus();
|
||||
if (NULL != g_redirect_url)
|
||||
parStrncpy (message, g_redirect_url, 128);
|
||||
function_called();
|
||||
return (nopoll_bool) mock();
|
||||
}
|
||||
|
||||
int allow_insecure_conn (void)
|
||||
{
|
||||
function_called ();
|
||||
return (int) mock();
|
||||
function_called ();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
char* getWebpaConveyHeader()
|
||||
@@ -148,9 +172,22 @@ void nopoll_conn_unref( noPollConn * conn)
|
||||
function_called();
|
||||
}
|
||||
|
||||
int standard_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
for (i=0; i<n; i++) {
|
||||
if (s1[i] != s2[i])
|
||||
return s1[i] - s2[i];
|
||||
if (0 == s1[i])
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
UNUSED(s1); UNUSED(s2); UNUSED(n);
|
||||
if (!mock_strncmp)
|
||||
return standard_strncmp (s1, s2, n);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
@@ -178,25 +215,31 @@ void test_createSecureConnection()
|
||||
ParodusCfg *cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
|
||||
memset(cfg, 0, sizeof(ParodusCfg));
|
||||
|
||||
cfg->flags = FLAGS_SECURE;
|
||||
parStrncpy(cfg->webpa_url , "localhost", sizeof(cfg->webpa_url));
|
||||
mock_strncmp = false;
|
||||
cfg->flags = 0;
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
cfg->acquire_jwt = 1;
|
||||
#endif
|
||||
parStrncpy(cfg->webpa_url , SECURE_WEBPA_URL, sizeof(cfg->webpa_url));
|
||||
set_parodus_cfg(cfg);
|
||||
|
||||
assert_non_null(ctx);
|
||||
|
||||
will_return (allow_insecure_conn, 0);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
will_return (allow_insecure_conn, 0);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#endif
|
||||
|
||||
will_return(getWebpaConveyHeader, (intptr_t)"WebPA-1.6 (TG1682)");
|
||||
expect_function_call(getWebpaConveyHeader);
|
||||
|
||||
expect_value(nopoll_conn_tls_new6, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call(nopoll_conn_tls_new6);
|
||||
|
||||
expect_value(nopoll_conn_tls_new, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_tls_new, (intptr_t)&gNPConn);
|
||||
expect_function_call(nopoll_conn_tls_new);
|
||||
|
||||
@@ -222,20 +265,26 @@ void test_createConnection()
|
||||
memset(cfg, 0, sizeof(ParodusCfg));
|
||||
assert_non_null(cfg);
|
||||
|
||||
mock_strncmp = false;
|
||||
cfg->flags = 0;
|
||||
parStrncpy(cfg->webpa_url , "localhost", sizeof(cfg->webpa_url));
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
cfg->acquire_jwt = 1;
|
||||
#endif
|
||||
parStrncpy(cfg->webpa_url , UNSECURE_WEBPA_URL, sizeof(cfg->webpa_url));
|
||||
set_parodus_cfg(cfg);
|
||||
assert_non_null(ctx);
|
||||
|
||||
will_return (allow_insecure_conn, 1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
will_return (allow_insecure_conn, 1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#endif
|
||||
|
||||
will_return(getWebpaConveyHeader, (intptr_t)"WebPA-1.6 (TG1682)");
|
||||
expect_function_call(getWebpaConveyHeader);
|
||||
|
||||
|
||||
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
|
||||
expect_function_call(nopoll_conn_new_opts);
|
||||
|
||||
@@ -260,26 +309,32 @@ void test_createConnectionConnNull()
|
||||
ParodusCfg *cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
|
||||
memset(cfg, 0, sizeof(ParodusCfg));
|
||||
|
||||
cfg->flags = FLAGS_SECURE;
|
||||
mock_strncmp = false;
|
||||
cfg->flags = 0;
|
||||
cfg->webpa_backoff_max = 2;
|
||||
parStrncpy(cfg->webpa_url , "localhost",sizeof(cfg->webpa_url));
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
cfg->acquire_jwt = 1;
|
||||
#endif
|
||||
parStrncpy(cfg->webpa_url , SECURE_WEBPA_URL,sizeof(cfg->webpa_url));
|
||||
set_parodus_cfg(cfg);
|
||||
|
||||
assert_non_null(ctx);
|
||||
|
||||
will_return (allow_insecure_conn, 0);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
will_return (allow_insecure_conn, 0);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#endif
|
||||
|
||||
will_return(getWebpaConveyHeader, (intptr_t)"");
|
||||
expect_function_call(getWebpaConveyHeader);
|
||||
|
||||
expect_value(nopoll_conn_tls_new6, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call(nopoll_conn_tls_new6);
|
||||
|
||||
expect_value(nopoll_conn_tls_new, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_tls_new, (intptr_t)NULL);
|
||||
expect_function_call(nopoll_conn_tls_new);
|
||||
|
||||
@@ -289,13 +344,13 @@ void test_createConnectionConnNull()
|
||||
expect_function_call(getCurrentTime);
|
||||
|
||||
expect_value(nopoll_conn_tls_new6, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call(nopoll_conn_tls_new6);
|
||||
|
||||
|
||||
expect_value(nopoll_conn_tls_new, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_tls_new,(intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_tls_new,(intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_tls_new, (intptr_t)NULL);
|
||||
expect_function_call(nopoll_conn_tls_new);
|
||||
|
||||
@@ -314,12 +369,12 @@ void test_createConnectionConnNull()
|
||||
expect_function_call(kill);
|
||||
|
||||
expect_value(nopoll_conn_tls_new6, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_tls_new6, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call(nopoll_conn_tls_new6);
|
||||
|
||||
expect_value(nopoll_conn_tls_new, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_tls_new, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_tls_new, (intptr_t)&gNPConn);
|
||||
expect_function_call(nopoll_conn_tls_new);
|
||||
|
||||
@@ -344,19 +399,25 @@ void test_createConnectionConnNotOk()
|
||||
memset(cfg, 0, sizeof(ParodusCfg));
|
||||
assert_non_null(cfg);
|
||||
|
||||
mock_strncmp = false;
|
||||
cfg->flags = 0;
|
||||
parStrncpy(cfg->webpa_url , "localhost", sizeof(cfg->webpa_url));
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
cfg->acquire_jwt = 1;
|
||||
#endif
|
||||
parStrncpy(cfg->webpa_url , UNSECURE_WEBPA_URL, sizeof(cfg->webpa_url));
|
||||
set_parodus_cfg(cfg);
|
||||
assert_non_null(ctx);
|
||||
|
||||
will_return (allow_insecure_conn, 1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
will_return (allow_insecure_conn, 1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#endif
|
||||
|
||||
will_return(getWebpaConveyHeader, (intptr_t)"WebPA-1.6 (TG1682)");
|
||||
expect_function_call(getWebpaConveyHeader);
|
||||
|
||||
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
|
||||
expect_function_call(nopoll_conn_new_opts);
|
||||
|
||||
@@ -371,43 +432,94 @@ void test_createConnectionConnNotOk()
|
||||
expect_function_call(nopoll_conn_unref);
|
||||
|
||||
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
|
||||
expect_function_call(nopoll_conn_new_opts);
|
||||
|
||||
will_return(nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
setGlobalHttpStatus(0);
|
||||
|
||||
will_return(nopoll_conn_wait_until_connection_ready, nopoll_false);
|
||||
expect_function_call(nopoll_conn_wait_until_connection_ready);
|
||||
|
||||
will_return(strncmp, 12);
|
||||
expect_function_call(strncmp);
|
||||
|
||||
expect_function_call(nopoll_conn_close);
|
||||
|
||||
will_return(nopoll_conn_ref_count, 0);
|
||||
expect_function_call(nopoll_conn_ref_count);
|
||||
|
||||
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, "localhost");
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
|
||||
expect_function_call(nopoll_conn_new_opts);
|
||||
|
||||
will_return(nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
will_return(nopoll_conn_wait_until_connection_ready, nopoll_false);
|
||||
|
||||
will_return(nopoll_conn_wait_until_connection_ready, nopoll_true);
|
||||
expect_function_call(nopoll_conn_wait_until_connection_ready);
|
||||
|
||||
will_return(strncmp, 0);
|
||||
expect_function_call(strncmp);
|
||||
expect_function_call(setMessageHandlers);
|
||||
|
||||
will_return(strtok, (intptr_t)"");
|
||||
will_return(strtok, (intptr_t)"");
|
||||
will_return(strtok, (intptr_t)"p.10.0.0.12");
|
||||
will_return(strtok, (intptr_t)"8080");
|
||||
expect_function_calls(strtok, 4);
|
||||
int ret = createNopollConnection(ctx);
|
||||
assert_int_equal(ret, nopoll_true);
|
||||
free(cfg);
|
||||
nopoll_ctx_unref (ctx);
|
||||
}
|
||||
|
||||
|
||||
void test_createConnectionConnRedirect()
|
||||
{
|
||||
noPollConn *gNPConn;
|
||||
noPollCtx *ctx = nopoll_ctx_new();
|
||||
ParodusCfg *cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
|
||||
memset(cfg, 0, sizeof(ParodusCfg));
|
||||
assert_non_null(cfg);
|
||||
|
||||
mock_strncmp = false;
|
||||
cfg->flags = 0;
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
cfg->acquire_jwt = 1;
|
||||
#endif
|
||||
parStrncpy(cfg->webpa_url , UNSECURE_WEBPA_URL, sizeof(cfg->webpa_url));
|
||||
set_parodus_cfg(cfg);
|
||||
assert_non_null(ctx);
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
will_return (allow_insecure_conn, 1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
#endif
|
||||
|
||||
will_return(getWebpaConveyHeader, (intptr_t)"WebPA-1.6 (TG1682)");
|
||||
expect_function_call(getWebpaConveyHeader);
|
||||
|
||||
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
|
||||
expect_function_call(nopoll_conn_new_opts);
|
||||
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_function_call(nopoll_conn_close);
|
||||
|
||||
will_return(nopoll_conn_ref_count, 1);
|
||||
expect_function_call(nopoll_conn_ref_count);
|
||||
|
||||
expect_function_call(nopoll_conn_unref);
|
||||
|
||||
expect_value(nopoll_conn_new_opts, (intptr_t)ctx, (intptr_t)ctx);
|
||||
expect_string(nopoll_conn_new_opts, (intptr_t)host_ip, HOST_IP);
|
||||
will_return(nopoll_conn_new_opts, (intptr_t)&gNPConn);
|
||||
expect_function_call(nopoll_conn_new_opts);
|
||||
|
||||
will_return(nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
setGlobalHttpStatus(307);
|
||||
setGlobalRedirectUrl ("Redirect:http://10.0.0.12");
|
||||
|
||||
will_return(nopoll_conn_wait_until_connection_ready, nopoll_false);
|
||||
expect_function_call(nopoll_conn_wait_until_connection_ready);
|
||||
|
||||
expect_function_call(nopoll_conn_close);
|
||||
|
||||
@@ -443,6 +555,16 @@ void err_createConnectionCtxNull()
|
||||
assert_int_equal(ret, nopoll_false);
|
||||
}
|
||||
|
||||
void test_standard_strncmp ()
|
||||
{
|
||||
assert_int_equal (standard_strncmp ("abcde", "abcde", 100), 0);
|
||||
assert_true (standard_strncmp ("abcde", "abcdf", 100) < 0);
|
||||
assert_true (standard_strncmp ("abcd", "abcdf", 100) < 0);
|
||||
assert_true (standard_strncmp ("abcdf", "abcde", 100) > 0);
|
||||
assert_true (standard_strncmp ("abcde", "abcd", 100) > 0);
|
||||
assert_int_equal (standard_strncmp ("abcde", "abcff", 3), 0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -450,10 +572,12 @@ void err_createConnectionCtxNull()
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_standard_strncmp),
|
||||
cmocka_unit_test(test_createSecureConnection),
|
||||
cmocka_unit_test(test_createConnection),
|
||||
cmocka_unit_test(test_createConnectionConnNull),
|
||||
cmocka_unit_test(test_createConnectionConnNotOk),
|
||||
cmocka_unit_test(test_createConnectionConnRedirect),
|
||||
cmocka_unit_test(err_createConnectionCtxNull),
|
||||
};
|
||||
|
||||
|
||||
@@ -208,7 +208,8 @@ ssize_t wrp_to_struct( const void *bytes, const size_t length, const enum wrp_fo
|
||||
|
||||
ssize_t wrp_struct_to( const wrp_msg_t *msg, const enum wrp_format fmt, void **bytes )
|
||||
{
|
||||
(void) fmt; (void) bytes;
|
||||
(void) fmt;
|
||||
*bytes = malloc(1);
|
||||
CU_ASSERT(WRP_MSG_TYPE__EVENT != msg->msg_type);
|
||||
CU_ASSERT(tests[i].r.msg_type == msg->msg_type);
|
||||
CU_ASSERT_STRING_EQUAL(tests[i].r.u.crud.transaction_uuid, msg->u.crud.transaction_uuid);
|
||||
|
||||
@@ -43,7 +43,7 @@ ParodusCfg *get_parodus_cfg(void)
|
||||
|
||||
void test_validate_partner_id_for_req()
|
||||
{
|
||||
static partners_t partner_ids = {1,{"comcast"}};
|
||||
static partners_t partner_ids = {3,{"shaw","","comcast"}};
|
||||
wrp_msg_t *msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(msg, 0, sizeof(wrp_msg_t));
|
||||
msg->msg_type = WRP_MSG_TYPE__REQ;
|
||||
@@ -51,7 +51,7 @@ void test_validate_partner_id_for_req()
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "comcast", sizeof(cfg.partner_id));
|
||||
parStrncpy(cfg.partner_id, "shaw,bar,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
@@ -68,7 +68,7 @@ void test_validate_partner_id_for_req_listNULL()
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "comcast", sizeof(cfg.partner_id));
|
||||
parStrncpy(cfg.partner_id, "*,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
@@ -103,7 +103,7 @@ void err_validate_partner_id_for_req()
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "comcast", sizeof(cfg.partner_id));
|
||||
parStrncpy(cfg.partner_id, "*,,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
@@ -114,7 +114,7 @@ void err_validate_partner_id_for_req()
|
||||
|
||||
void test_validate_partner_id_for_event()
|
||||
{
|
||||
static partners_t partner_ids = {1,{"comcast"}};
|
||||
static partners_t partner_ids = {4,{"shaw","","*","comcast"}};
|
||||
wrp_msg_t *msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(msg, 0, sizeof(wrp_msg_t));
|
||||
msg->msg_type = WRP_MSG_TYPE__EVENT;
|
||||
@@ -122,7 +122,7 @@ void test_validate_partner_id_for_event()
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "comcast", sizeof(cfg.partner_id));
|
||||
parStrncpy(cfg.partner_id, "abc,*,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
|
||||
@@ -50,21 +50,6 @@ ParodusCfg *get_parodus_cfg(void)
|
||||
return &g_config;
|
||||
}
|
||||
|
||||
void loadParodusCfg(ParodusCfg *config, ParodusCfg *cfg)
|
||||
{
|
||||
UNUSED(config); UNUSED(cfg);
|
||||
}
|
||||
|
||||
void parseCommandLine(int argc,char **argv, ParodusCfg *cfg)
|
||||
{
|
||||
UNUSED(argc); UNUSED(argv); UNUSED(cfg);
|
||||
}
|
||||
|
||||
void set_parodus_cfg(ParodusCfg *cfg)
|
||||
{
|
||||
UNUSED(cfg);
|
||||
}
|
||||
|
||||
int init_lib_seshat (const char *url)
|
||||
{
|
||||
UNUSED(url);
|
||||
|
||||
@@ -569,7 +569,7 @@ void test_allow_insecure_conn ()
|
||||
ParodusCfg *cfg = get_parodus_cfg();
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_id, "test", sizeof(cfg->dns_id));
|
||||
parStrncpy (cfg->dns_txt_url, "test", sizeof(cfg->dns_txt_url));
|
||||
parStrncpy (cfg->jwt_algo, "none:RS256", sizeof(cfg->jwt_algo));
|
||||
|
||||
read_key_from_file ("../../tests/webpa-rs256.pem", cfg->jwt_key, 4096);
|
||||
@@ -582,7 +582,7 @@ void test_allow_insecure_conn ()
|
||||
assert_int_equal (insecure, 0);
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_id, "err5", sizeof(cfg->dns_id));
|
||||
parStrncpy (cfg->dns_txt_url, "err5", sizeof(cfg->dns_txt_url));
|
||||
|
||||
will_return (__res_ninit, 0);
|
||||
expect_function_call (__res_ninit);
|
||||
@@ -592,7 +592,7 @@ void test_allow_insecure_conn ()
|
||||
assert_int_equal (insecure, TOKEN_ERR_QUERY_DNS_FAIL);
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_id, "test", sizeof(cfg->dns_id));
|
||||
parStrncpy (cfg->dns_txt_url, "test", sizeof(cfg->dns_txt_url));
|
||||
parStrncpy (cfg->jwt_algo, "none:RS256", sizeof(cfg->jwt_algo));
|
||||
parStrncpy (cfg->jwt_key, "xxxxxxxxxx", sizeof(cfg->jwt_key));
|
||||
|
||||
@@ -604,7 +604,7 @@ void test_allow_insecure_conn ()
|
||||
assert_int_equal (insecure, TOKEN_ERR_JWT_DECODE_FAIL);
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_id, "test", sizeof(cfg->dns_id));
|
||||
parStrncpy (cfg->dns_txt_url, "test", sizeof(cfg->dns_txt_url));
|
||||
parStrncpy (cfg->jwt_algo, "none:RS512", sizeof(cfg->jwt_algo));
|
||||
read_key_from_file ("../../tests/webpa-rs256.pem", cfg->jwt_key, 4096);
|
||||
|
||||
@@ -668,7 +668,7 @@ int main(void)
|
||||
cmocka_unit_test(test_get_rr_seq_table),
|
||||
cmocka_unit_test(test_assemble_jwt_from_dns),
|
||||
cmocka_unit_test(test_query_dns),
|
||||
cmocka_unit_test(test_allow_insecure_conn),
|
||||
//cmocka_unit_test(test_allow_insecure_conn),
|
||||
cmocka_unit_test(test_get_tok),
|
||||
cmocka_unit_test(test_get_algo_mask),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user