Refactor base64 functions to common static library.

This commit is contained in:
Roger A. Light
2024-03-17 21:34:27 +00:00
parent 9fe8b95dcf
commit 16d465fa49
27 changed files with 41 additions and 70 deletions

View File

@@ -1,7 +1,6 @@
if(WITH_TLS AND CJSON_FOUND) if(WITH_TLS AND CJSON_FOUND)
add_executable(mosquitto_ctrl add_executable(mosquitto_ctrl
mosquitto_ctrl.c mosquitto_ctrl.h mosquitto_ctrl.c mosquitto_ctrl.h
../../common/base64_mosq.c ../../common/base64_mosq.h
broker.c broker.c
client.c client.c
dynsec.c dynsec.c
@@ -58,6 +57,7 @@ if(WITH_TLS AND CJSON_FOUND)
target_link_libraries(mosquitto_ctrl target_link_libraries(mosquitto_ctrl
PRIVATE PRIVATE
common-options common-options
libmosquitto_common
OpenSSL::SSL OpenSSL::SSL
cJSON cJSON
) )

View File

@@ -6,7 +6,7 @@ include ${R}/config.mk
LOCAL_CFLAGS+= LOCAL_CFLAGS+=
LOCAL_CPPFLAGS+=-I${R}/lib -I${R}/apps/mosquitto_passwd -I${R}/plugins/dynamic-security -I${R}/common LOCAL_CPPFLAGS+=-I${R}/lib -I${R}/apps/mosquitto_passwd -I${R}/plugins/dynamic-security -I${R}/common
LOCAL_LDFLAGS+= LOCAL_LDFLAGS+=
LOCAL_LDADD+=-lcjson -ldl ${LIBMOSQ} ${LIB_ARGON2} LOCAL_LDADD+=-lcjson -ldl ${LIBMOSQ} ${LIBMOSQ_COMMON} ${LIB_ARGON2}
# ------------------------------------------ # ------------------------------------------
# Compile time options # Compile time options
@@ -33,7 +33,6 @@ OBJS= \
options.o \ options.o \
OBJS_EXTERNAL= \ OBJS_EXTERNAL= \
base64_mosq.o \
get_password.o \ get_password.o \
json_help.o \ json_help.o \
password_mosq.o password_mosq.o
@@ -57,9 +56,6 @@ mosquitto_ctrl_example.so : ${EXAMPLE_OBJS}
${OBJS} : %.o: %.c mosquitto_ctrl.h ${OBJS} : %.o: %.c mosquitto_ctrl.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@
example.o : example.c mosquitto_ctrl.h example.o : example.c mosquitto_ctrl.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -fPIC -c $< -o $@ ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -fPIC -c $< -o $@

View File

@@ -32,7 +32,6 @@ Contributors:
#include "mosquitto_ctrl.h" #include "mosquitto_ctrl.h"
#include "mosquitto.h" #include "mosquitto.h"
#include "base64_mosq.h"
#include "json_help.h" #include "json_help.h"
#include "password_mosq.h" #include "password_mosq.h"
#include "get_password.h" #include "get_password.h"
@@ -587,8 +586,8 @@ static cJSON *init_add_client(const char *username, const char *password, const
if(pw.hashtype == pw_sha512_pbkdf2){ if(pw.hashtype == pw_sha512_pbkdf2){
char *salt_b64 = NULL, *password_b64 = NULL; char *salt_b64 = NULL, *password_b64 = NULL;
if(base64__encode(pw.params.sha512_pbkdf2.salt, pw.params.sha512_pbkdf2.salt_len, &salt_b64) if(mosquitto_base64_encode(pw.params.sha512_pbkdf2.salt, pw.params.sha512_pbkdf2.salt_len, &salt_b64)
|| base64__encode(pw.params.sha512_pbkdf2.password_hash, sizeof(pw.params.sha512_pbkdf2.password_hash), &password_b64) || mosquitto_base64_encode(pw.params.sha512_pbkdf2.password_hash, sizeof(pw.params.sha512_pbkdf2.password_hash), &password_b64)
|| cJSON_AddStringToObject(j_client, "salt", salt_b64) == NULL || cJSON_AddStringToObject(j_client, "salt", salt_b64) == NULL
|| cJSON_AddStringToObject(j_client, "password", password_b64) == NULL || cJSON_AddStringToObject(j_client, "password", password_b64) == NULL
|| cJSON_AddNumberToObject(j_client, "iterations", pw.params.sha512_pbkdf2.iterations) == NULL){ || cJSON_AddNumberToObject(j_client, "iterations", pw.params.sha512_pbkdf2.iterations) == NULL){

View File

@@ -240,11 +240,11 @@ int dynsec_client__file_set_password(int argc, char *argv[], const char *file)
char *password_b64, *salt_b64; char *password_b64, *salt_b64;
cJSON *j_password = NULL, *j_salt = NULL, *j_iterations = NULL; cJSON *j_password = NULL, *j_salt = NULL, *j_iterations = NULL;
if(base64__encode(client.pw.params.sha512_pbkdf2.password_hash, sizeof(client.pw.params.sha512_pbkdf2.password_hash), &password_b64) != MOSQ_ERR_SUCCESS){ if(mosquitto_base64_encode(client.pw.params.sha512_pbkdf2.password_hash, sizeof(client.pw.params.sha512_pbkdf2.password_hash), &password_b64) != MOSQ_ERR_SUCCESS){
fprintf(stderr, "Error: Problem generating password hash.\n"); fprintf(stderr, "Error: Problem generating password hash.\n");
return MOSQ_ERR_NOMEM; return MOSQ_ERR_NOMEM;
} }
if(base64__encode(client.pw.params.sha512_pbkdf2.salt, client.pw.params.sha512_pbkdf2.salt_len, &salt_b64) != MOSQ_ERR_SUCCESS){ if(mosquitto_base64_encode(client.pw.params.sha512_pbkdf2.salt, client.pw.params.sha512_pbkdf2.salt_len, &salt_b64) != MOSQ_ERR_SUCCESS){
free(password_b64); free(password_b64);
fprintf(stderr, "Error: Problem generating password hash.\n"); fprintf(stderr, "Error: Problem generating password hash.\n");
return MOSQ_ERR_NOMEM; return MOSQ_ERR_NOMEM;

View File

@@ -2,7 +2,6 @@ if(WITH_TLS)
add_executable(mosquitto_passwd add_executable(mosquitto_passwd
mosquitto_passwd.c mosquitto_passwd.c
get_password.c get_password.h get_password.c get_password.h
../../common/base64_mosq.c ../../common/base64_mosq.h
../../common/misc_mosq.c ../../common/misc_mosq.h ../../common/misc_mosq.c ../../common/misc_mosq.h
../../common/password_mosq.c ../../common/password_mosq.h ../../common/password_mosq.c ../../common/password_mosq.h
) )

View File

@@ -13,7 +13,6 @@ OBJS= \
get_password.o \ get_password.o \
OBJS_EXTERNAL= \ OBJS_EXTERNAL= \
base64_mosq.o \
misc_mosq.o \ misc_mosq.o \
password_mosq.o password_mosq.o
@@ -37,9 +36,6 @@ mosquitto_passwd.a : ${OBJS} ${OBJS_EXTERNAL}
${OBJS} : %.o: %.c ${OBJS} : %.o: %.c
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
${CROSS_COMPILE}${CC} ${LOCAL_CPPFLAGS} $(LOCAL_CFLAGS) -c $< -o $@
misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h
${CROSS_COMPILE}${CC} ${LOCAL_CPPFLAGS} $(LOCAL_CFLAGS) -c $< -o $@ ${CROSS_COMPILE}${CC} ${LOCAL_CPPFLAGS} $(LOCAL_CFLAGS) -c $< -o $@

View File

@@ -29,7 +29,6 @@ Contributors:
#include "mosquitto.h" #include "mosquitto.h"
#include "get_password.h" #include "get_password.h"
#include "base64_mosq.h"
#include "password_mosq.h" #include "password_mosq.h"
#ifdef WIN32 #ifdef WIN32

View File

@@ -26,7 +26,6 @@ Contributors:
#include <string.h> #include <string.h>
#include "mosquitto.h" #include "mosquitto.h"
#include "base64_mosq.h"
#include "password_mosq.h" #include "password_mosq.h"
#ifdef WIN32 #ifdef WIN32
@@ -221,12 +220,12 @@ static int pw__encode_sha512_pbkdf2(struct mosquitto_pw *pw)
int rc; int rc;
char *salt64 = NULL, *hash64 = NULL; char *salt64 = NULL, *hash64 = NULL;
rc = base64__encode(pw->params.sha512_pbkdf2.salt, pw->params.sha512_pbkdf2.salt_len, &salt64); rc = mosquitto_base64_encode(pw->params.sha512_pbkdf2.salt, pw->params.sha512_pbkdf2.salt_len, &salt64);
if(rc){ if(rc){
return MOSQ_ERR_UNKNOWN; return MOSQ_ERR_UNKNOWN;
} }
rc = base64__encode(pw->params.sha512_pbkdf2.password_hash, sizeof(pw->params.sha512_pbkdf2.password_hash), &hash64); rc = mosquitto_base64_encode(pw->params.sha512_pbkdf2.password_hash, sizeof(pw->params.sha512_pbkdf2.password_hash), &hash64);
if(rc){ if(rc){
free(salt64); free(salt64);
return MOSQ_ERR_UNKNOWN; return MOSQ_ERR_UNKNOWN;
@@ -278,7 +277,7 @@ static int pw__decode_sha512_pbkdf2(struct mosquitto_pw *pw, const char *salt_pa
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
rc = base64__decode(salt_b64, &salt, &salt_len); rc = mosquitto_base64_decode(salt_b64, &salt, &salt_len);
if(rc != MOSQ_ERR_SUCCESS || (salt_len != 12 && salt_len != HASH_LEN)){ if(rc != MOSQ_ERR_SUCCESS || (salt_len != 12 && salt_len != HASH_LEN)){
free(sp_heap); free(sp_heap);
free(salt); free(salt);
@@ -294,7 +293,7 @@ static int pw__decode_sha512_pbkdf2(struct mosquitto_pw *pw, const char *salt_pa
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
rc = base64__decode(password_b64, &password, &password_len); rc = mosquitto_base64_decode(password_b64, &password, &password_len);
free(sp_heap); free(sp_heap);
if(rc != MOSQ_ERR_SUCCESS || password_len != HASH_LEN){ if(rc != MOSQ_ERR_SUCCESS || password_len != HASH_LEN){
@@ -391,12 +390,12 @@ static int pw__encode_sha512(struct mosquitto_pw *pw)
int rc; int rc;
char *salt64 = NULL, *hash64 = NULL; char *salt64 = NULL, *hash64 = NULL;
rc = base64__encode(pw->params.sha512.salt, pw->params.sha512.salt_len, &salt64); rc = mosquitto_base64_encode(pw->params.sha512.salt, pw->params.sha512.salt_len, &salt64);
if(rc){ if(rc){
return MOSQ_ERR_UNKNOWN; return MOSQ_ERR_UNKNOWN;
} }
rc = base64__encode(pw->params.sha512.password_hash, sizeof(pw->params.sha512.password_hash), &hash64); rc = mosquitto_base64_encode(pw->params.sha512.password_hash, sizeof(pw->params.sha512.password_hash), &hash64);
if(rc){ if(rc){
return MOSQ_ERR_UNKNOWN; return MOSQ_ERR_UNKNOWN;
} }
@@ -435,7 +434,7 @@ static int pw__decode_sha512(struct mosquitto_pw *pw, const char *salt_password)
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
rc = base64__decode(salt_b64, &salt, &salt_len); rc = mosquitto_base64_decode(salt_b64, &salt, &salt_len);
if(rc != MOSQ_ERR_SUCCESS || (salt_len != 12 && salt_len != HASH_LEN)){ if(rc != MOSQ_ERR_SUCCESS || (salt_len != 12 && salt_len != HASH_LEN)){
free(sp_heap); free(sp_heap);
free(salt); free(salt);
@@ -451,7 +450,7 @@ static int pw__decode_sha512(struct mosquitto_pw *pw, const char *salt_password)
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
rc = base64__decode(password_b64, &password, &password_len); rc = mosquitto_base64_decode(password_b64, &password, &password_len);
free(sp_heap); free(sp_heap);
if(rc != MOSQ_ERR_SUCCESS || password_len != HASH_LEN){ if(rc != MOSQ_ERR_SUCCESS || password_len != HASH_LEN){

View File

@@ -26,6 +26,7 @@ Contributors:
extern "C" { extern "C" {
#endif #endif
#include <mosquitto/libcommon_base64.h>
#include <mosquitto/libcommon_memory.h> #include <mosquitto/libcommon_memory.h>
#include <mosquitto/libcommon_properties.h> #include <mosquitto/libcommon_properties.h>
#include <mosquitto/libcommon_string.h> #include <mosquitto/libcommon_string.h>

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2012-2020 Roger Light <roger@atchoo.org> Copyright (c) 2010-2021 Roger Light <roger@atchoo.org>
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0 are made available under the terms of the Eclipse Public License 2.0
@@ -15,18 +15,23 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
Contributors: Contributors:
Roger Light - initial implementation and documentation. Roger Light - initial implementation and documentation.
*/ */
#ifndef BASE64_MOSQ_H
#define BASE64_MOSQ_H
#ifndef MOSQUITTO_LIBCOMMON_BASE64_H
#define MOSQUITTO_LIBCOMMON_BASE64_H
/*
* File: mosquitto/libcommon_base64.h
*
* This header contains functions for handling base64
*/
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
int base64__encode(const unsigned char *in, size_t in_len, char **encoded); int mosquitto_base64_encode(const unsigned char *in, size_t in_len, char **encoded);
int base64__decode(const char *in, unsigned char **decoded, unsigned int *decoded_len); int mosquitto_base64_decode(const char *in, unsigned char **decoded, unsigned int *decoded_len);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View File

@@ -86,7 +86,6 @@ if(WITH_WEBSOCKETS AND WITH_WEBSOCKETS_BUILTIN)
add_definitions("-DWITH_WEBSOCKETS=WS_IS_BUILTIN") add_definitions("-DWITH_WEBSOCKETS=WS_IS_BUILTIN")
set(C_SRC ${C_SRC} set(C_SRC ${C_SRC}
../deps/picohttpparser/picohttpparser.c ../deps/picohttpparser/picohttpparser.c
../common/base64_mosq.c ../common/base64_mosq.h
http_client.c http_client.h http_client.c http_client.h
net_ws.c net_ws.c
) )

View File

@@ -83,7 +83,6 @@ OBJS= \
will_mosq.o will_mosq.o
OBJS_EXTERNAL= \ OBJS_EXTERNAL= \
base64_mosq.o \
misc_mosq.o \ misc_mosq.o \
password_mosq.o password_mosq.o
@@ -143,9 +142,6 @@ libmosquitto.a : ${OBJS} ${OBJS_EXTERNAL}
${OBJS} : %.o: %.c ${R}/include/mosquitto.h mosquitto_internal.h ${OBJS} : %.o: %.c ${R}/include/mosquitto.h mosquitto_internal.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
${CROSS_COMPILE}$(CC) $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@
misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h misc_mosq.o : ${R}/common/misc_mosq.c ${R}/common/misc_mosq.h
${CROSS_COMPILE}$(CC) $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ ${CROSS_COMPILE}$(CC) $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@

View File

@@ -25,7 +25,6 @@ Contributors:
#include <string.h> #include <string.h>
#include "mosquitto_internal.h" #include "mosquitto_internal.h"
#include "base64_mosq.h"
#include "http_client.h" #include "http_client.h"
#include "mosquitto/mqtt_protocol.h" #include "mosquitto/mqtt_protocol.h"
#include "net_mosq.h" #include "net_mosq.h"
@@ -40,7 +39,7 @@ static int create_request_key(char **encoded)
{ {
uint8_t bytes[16]; uint8_t bytes[16];
util__random_bytes(bytes, sizeof(bytes)); util__random_bytes(bytes, sizeof(bytes));
return base64__encode(bytes, sizeof(bytes), encoded); return mosquitto_base64_encode(bytes, sizeof(bytes), encoded);
} }

View File

@@ -27,7 +27,6 @@ Contributors:
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include "base64_mosq.h"
#include "mosquitto_internal.h" #include "mosquitto_internal.h"
#include "mosquitto/mqtt_protocol.h" #include "mosquitto/mqtt_protocol.h"
#include "net_mosq.h" #include "net_mosq.h"
@@ -350,7 +349,7 @@ int ws__create_accept_key(const char *client_key, size_t client_key_len, char **
if(EVP_DigestFinal_ex(evp, accept_key_hash, &accept_key_hash_len) != 0){ if(EVP_DigestFinal_ex(evp, accept_key_hash, &accept_key_hash_len) != 0){
EVP_MD_CTX_free(evp); EVP_MD_CTX_free(evp);
return base64__encode(accept_key_hash, accept_key_hash_len, encoded); return mosquitto_base64_encode(accept_key_hash, accept_key_hash_len, encoded);
} }
} }
} }

View File

@@ -1,4 +1,5 @@
set(C_SRC set(C_SRC
base64_common.c
memory_common.c memory_common.c
mqtt_common.c mqtt_common.c
property_common.c property_common.c

View File

@@ -12,6 +12,7 @@ LOCAL_LIBADD+=
.PHONY : really clean install .PHONY : really clean install
OBJS= \ OBJS= \
base64_common.o \
memory_common.o \ memory_common.o \
mqtt_common.o \ mqtt_common.o \
property_common.o \ property_common.o \

View File

@@ -18,23 +18,18 @@ Contributors:
#include "config.h" #include "config.h"
#include <errno.h>
#ifdef WITH_TLS #ifdef WITH_TLS
# include <openssl/opensslv.h> # include <openssl/opensslv.h>
# include <openssl/evp.h> # include <openssl/evp.h>
# include <openssl/rand.h> # include <openssl/rand.h>
# include <openssl/buffer.h> # include <openssl/buffer.h>
#endif #endif
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "mosquitto.h" #include "mosquitto.h"
#include "base64_mosq.h"
#ifdef WITH_TLS #ifdef WITH_TLS
int base64__encode(const unsigned char *in, size_t in_len, char **encoded) int mosquitto_base64_encode(const unsigned char *in, size_t in_len, char **encoded)
{ {
BIO *bmem, *b64; BIO *bmem, *b64;
BUF_MEM *bptr = NULL; BUF_MEM *bptr = NULL;
@@ -65,7 +60,7 @@ int base64__encode(const unsigned char *in, size_t in_len, char **encoded)
} }
int base64__decode(const char *in, unsigned char **decoded, unsigned int *decoded_len) int mosquitto_base64_decode(const char *in, unsigned char **decoded, unsigned int *decoded_len)
{ {
BIO *bmem, *b64; BIO *bmem, *b64;
size_t slen; size_t slen;

View File

@@ -4,7 +4,6 @@ if(WITH_TLS)
set(SRCLIST set(SRCLIST
acl.c acl.c
auth.c auth.c
../../common/base64_mosq.c ../../common/base64_mosq.h
clients.c clients.c
clientlist.c clientlist.c
config.c config.c

View File

@@ -31,7 +31,6 @@ OBJS = \
tick.o tick.o
OBJS_EXTERNAL = \ OBJS_EXTERNAL = \
base64_mosq.o \
json_help.o \ json_help.o \
misc_mosq.o \ misc_mosq.o \
password_mosq.o \ password_mosq.o \
@@ -46,9 +45,6 @@ endif
all : ${ALL_DEPS} all : ${ALL_DEPS}
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@
json_help.o : ${R}/common/json_help.c ${R}/common/json_help.h json_help.o : ${R}/common/json_help.c ${R}/common/json_help.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@

View File

@@ -164,7 +164,7 @@ int dynsec_clients__config_load(struct dynsec__data *data, cJSON *tree)
client->pw.hashtype = pw_sha512_pbkdf2; client->pw.hashtype = pw_sha512_pbkdf2;
client->pw.params.sha512_pbkdf2.iterations = iterations; client->pw.params.sha512_pbkdf2.iterations = iterations;
if(base64__decode(salt, &buf, &buf_len) != MOSQ_ERR_SUCCESS if(mosquitto_base64_decode(salt, &buf, &buf_len) != MOSQ_ERR_SUCCESS
|| buf_len > sizeof(client->pw.params.sha512_pbkdf2.salt)){ || buf_len > sizeof(client->pw.params.sha512_pbkdf2.salt)){
mosquitto_free(buf); mosquitto_free(buf);
@@ -175,7 +175,7 @@ int dynsec_clients__config_load(struct dynsec__data *data, cJSON *tree)
client->pw.params.sha512_pbkdf2.salt_len = (size_t)buf_len; client->pw.params.sha512_pbkdf2.salt_len = (size_t)buf_len;
mosquitto_free(buf); mosquitto_free(buf);
if(base64__decode(password, &buf, &buf_len) != MOSQ_ERR_SUCCESS if(mosquitto_base64_decode(password, &buf, &buf_len) != MOSQ_ERR_SUCCESS
|| buf_len != sizeof(client->pw.params.sha512_pbkdf2.password_hash)){ || buf_len != sizeof(client->pw.params.sha512_pbkdf2.password_hash)){
mosquitto_free(buf); mosquitto_free(buf);
@@ -279,7 +279,7 @@ static int dynsec__config_add_clients(struct dynsec__data *data, cJSON *j_client
if(client->pw.hashtype == pw_sha512_pbkdf2){ if(client->pw.hashtype == pw_sha512_pbkdf2){
char *buf; char *buf;
if(base64__encode(client->pw.params.sha512_pbkdf2.password_hash, sizeof(client->pw.params.sha512_pbkdf2.password_hash), &buf) != MOSQ_ERR_SUCCESS){ if(mosquitto_base64_encode(client->pw.params.sha512_pbkdf2.password_hash, sizeof(client->pw.params.sha512_pbkdf2.password_hash), &buf) != MOSQ_ERR_SUCCESS){
return 1; return 1;
} }
cJSON *jtmp = cJSON_CreateString(buf); cJSON *jtmp = cJSON_CreateString(buf);
@@ -287,7 +287,7 @@ static int dynsec__config_add_clients(struct dynsec__data *data, cJSON *j_client
if(jtmp == NULL) return 1; if(jtmp == NULL) return 1;
cJSON_AddItemToObject(j_client, "password", jtmp); cJSON_AddItemToObject(j_client, "password", jtmp);
if(base64__encode(client->pw.params.sha512_pbkdf2.salt, client->pw.params.sha512_pbkdf2.salt_len, &buf) != MOSQ_ERR_SUCCESS){ if(mosquitto_base64_encode(client->pw.params.sha512_pbkdf2.salt, client->pw.params.sha512_pbkdf2.salt_len, &buf) != MOSQ_ERR_SUCCESS){
return 1; return 1;
} }

View File

@@ -161,8 +161,8 @@ static int generate_password(struct dynsec__data *data, cJSON *j_client, char **
if(pw.hashtype == pw_sha512_pbkdf2){ if(pw.hashtype == pw_sha512_pbkdf2){
char *salt_b64 = NULL, *password_b64 = NULL; char *salt_b64 = NULL, *password_b64 = NULL;
if(base64__encode(pw.params.sha512_pbkdf2.salt, pw.params.sha512_pbkdf2.salt_len, &salt_b64) if(mosquitto_base64_encode(pw.params.sha512_pbkdf2.salt, pw.params.sha512_pbkdf2.salt_len, &salt_b64)
|| base64__encode(pw.params.sha512_pbkdf2.password_hash, sizeof(pw.params.sha512_pbkdf2.password_hash), &password_b64) || mosquitto_base64_encode(pw.params.sha512_pbkdf2.password_hash, sizeof(pw.params.sha512_pbkdf2.password_hash), &password_b64)
|| cJSON_AddStringToObject(j_client, "salt", salt_b64) == NULL || cJSON_AddStringToObject(j_client, "salt", salt_b64) == NULL
|| cJSON_AddStringToObject(j_client, "password", password_b64) == NULL || cJSON_AddStringToObject(j_client, "password", password_b64) == NULL
|| cJSON_AddNumberToObject(j_client, "iterations", pw.params.sha512_pbkdf2.iterations) == NULL){ || cJSON_AddNumberToObject(j_client, "iterations", pw.params.sha512_pbkdf2.iterations) == NULL){

View File

@@ -22,7 +22,6 @@ Contributors:
#include <uthash.h> #include <uthash.h>
#include "mosquitto.h" #include "mosquitto.h"
#include "password_mosq.h" #include "password_mosq.h"
#include "base64_mosq.h"
#define PRIORITY_MAX 100000 #define PRIORITY_MAX 100000

View File

@@ -1,6 +1,5 @@
set (MOSQ_SRCS set (MOSQ_SRCS
../lib/alias_mosq.c ../lib/alias_mosq.h ../lib/alias_mosq.c ../lib/alias_mosq.h
../common/base64_mosq.c ../common/base64_mosq.h
bridge.c bridge_topic.c bridge.c bridge_topic.c
broker_control.c broker_control.c
conf.c conf.c

View File

@@ -112,7 +112,6 @@ OBJS= mosquitto.o \
OBJS_EXTERNAL= \ OBJS_EXTERNAL= \
alias_mosq.o \ alias_mosq.o \
base64_mosq.o \
handle_ping.o \ handle_ping.o \
handle_pubackcomp.o \ handle_pubackcomp.o \
handle_pubrec.o \ handle_pubrec.o \
@@ -154,9 +153,6 @@ ${OBJS} : %.o: %.c mosquitto_broker_internal.h
alias_mosq.o : ${R}/lib/alias_mosq.c ${R}/lib/alias_mosq.h alias_mosq.o : ${R}/lib/alias_mosq.c ${R}/lib/alias_mosq.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@
base64_mosq.o : ${R}/common/base64_mosq.c ${R}/common/base64_mosq.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@
handle_ping.o : ${R}/lib/handle_ping.c ${R}/lib/read_handle.h handle_ping.o : ${R}/lib/handle_ping.c ${R}/lib/read_handle.h
${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@ ${CROSS_COMPILE}${CC} $(LOCAL_CPPFLAGS) $(LOCAL_CFLAGS) -c $< -o $@

View File

@@ -25,7 +25,6 @@ Contributors:
#include <string.h> #include <string.h>
#include "mosquitto_broker_internal.h" #include "mosquitto_broker_internal.h"
#include "base64_mosq.h"
#include "mosquitto/mqtt_protocol.h" #include "mosquitto/mqtt_protocol.h"
#include "net_mosq.h" #include "net_mosq.h"
#include "packet_mosq.h" #include "packet_mosq.h"

View File

@@ -25,7 +25,6 @@ Contributors:
#include "mosquitto_broker_internal.h" #include "mosquitto_broker_internal.h"
#include "mosquitto/mqtt_protocol.h" #include "mosquitto/mqtt_protocol.h"
#include "send_mosq.h" #include "send_mosq.h"
#include "base64_mosq.h"
#include "misc_mosq.h" #include "misc_mosq.h"
#include "util_mosq.h" #include "util_mosq.h"

View File

@@ -12,7 +12,7 @@ add_executable(bridge-topic-test
stubs.c stubs.c
) )
target_compile_definitions(bridge-topic-test PRIVATE WITH_BRIDGE WITH_BROKER) target_compile_definitions(bridge-topic-test PRIVATE WITH_BRIDGE WITH_BROKER)
target_link_libraries(bridge-topic-test PRIVATE bridge-topic-obj common-unit-test-header libmosquitto_common) target_link_libraries(bridge-topic-test PRIVATE bridge-topic-obj common-unit-test-header libmosquitto_common OpenSSL::SSL)
add_test(NAME unit-bridge-topic-test COMMAND bridge-topic-test) add_test(NAME unit-bridge-topic-test COMMAND bridge-topic-test)
# keepalive-test # keepalive-test
@@ -21,7 +21,7 @@ add_executable(keepalive-test
keepalive_stubs.c keepalive_stubs.c
) )
target_compile_definitions(keepalive-test PRIVATE WITH_BROKER) target_compile_definitions(keepalive-test PRIVATE WITH_BROKER)
target_link_libraries(keepalive-test PRIVATE common-unit-test-header libmosquitto_common) target_link_libraries(keepalive-test PRIVATE common-unit-test-header libmosquitto_common OpenSSL::SSL)
add_test(NAME unit-keepalive-test COMMAND keepalive-test) add_test(NAME unit-keepalive-test COMMAND keepalive-test)
# persist-read-test # persist-read-test
@@ -99,5 +99,5 @@ add_executable(subs-test
) )
target_compile_definitions(subs-test PRIVATE WITH_PERSISTENCE WITH_BROKER WITH_SYS_TREE) target_compile_definitions(subs-test PRIVATE WITH_PERSISTENCE WITH_BROKER WITH_SYS_TREE)
target_link_libraries(subs-test PRIVATE common-unit-test-header subs-obj libmosquitto_common) target_link_libraries(subs-test PRIVATE common-unit-test-header subs-obj libmosquitto_common OpenSSL::SSL)
add_test(NAME unit-subs-test COMMAND subs-test) add_test(NAME unit-subs-test COMMAND subs-test)