diff --git a/.gitignore b/.gitignore index fa1fcac..a19ceb6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ fbconfig.config *.o *.so.* *.so +test-getrandom test-webserver test-json test-ssl diff --git a/Changelog b/Changelog index 79ca7f1..f31ac68 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +2026-04-15: +- getrandomtext did not init with a good seed value. using the sample from the + linux man pages. + 2026-04-04: - WebRequestBuffer::GerCookie did not return the correct cookie - test-webserver: added some basic data in and output. diff --git a/Makefile b/Makefile index ba15741..2b6b200 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ noconfig: help endif -all: dep $(TARGET) test-udp test-tcpserver test-tcpclient test-ssl test-json test-webserver +all: dep $(TARGET) test-udp test-tcpserver test-tcpclient test-ssl test-json test-webserver test-getrandom -include .depend @@ -37,6 +37,9 @@ configwindows: clean test-webserver: $(TARGET) test-webserver.o $(CXX) test-webserver.o -o $@ -lUDPTCPNetwork -L./ -I./ $(LDFLAGS) +test-getrandom: $(TARGET) test-getrandom.o + $(CXX) test-getrandom.o -o $@ -lUDPTCPNetwork -L./ -I./ $(LDFLAGS) + test-tcpserver: $(TARGET) test-tcpserver.o $(CXX) test-tcpserver.o -o $@ -lUDPTCPNetwork -L./ -I./ $(LDFLAGS) diff --git a/Makefile.rules.linux b/Makefile.rules.linux index c1c1a4f..bada259 100644 --- a/Makefile.rules.linux +++ b/Makefile.rules.linux @@ -5,7 +5,7 @@ ETCPREFIX = /etc LINUXVERSION = 1 CXX = g++ -CXXFLAGS = -ggdb -fPIC -pg -Wno-write-strings -I./ -std=c++11 -DBUILD_LINUX=1 +CXXFLAGS = -fPIC -pg -Wno-write-strings -I./ -std=c++11 -DBUILD_LINUX=1 LDFLAGS = -lm -pg -lssl -lcrypto TARGET = lib$(OBJLIB_NAME).so.$(VERSION) diff --git a/ssl.cc b/ssl.cc index 9823a1d..3082a65 100644 --- a/ssl.cc +++ b/ssl.cc @@ -375,6 +375,10 @@ std::string getsha256sum(std::string *in) { std::string getrandomtext(int numbytes) { std::string text = ""; + unsigned int seed; + + seed = arc4random(); + srand(seed); for (int i = 0; i < numbytes; i++) { char c = ((rand() % (90-48)) + 48); diff --git a/test-getrandom.cc b/test-getrandom.cc new file mode 100644 index 0000000..7b420a0 --- /dev/null +++ b/test-getrandom.cc @@ -0,0 +1,21 @@ + +#include +#include + +#include "UDPTCPNetwork.h" + +int main (int argc, char **argv) { + std::string user_salt; + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + + return 0; +}; diff --git a/test-ssl.cc b/test-ssl.cc index 6c233cf..cec7169 100644 --- a/test-ssl.cc +++ b/test-ssl.cc @@ -156,6 +156,15 @@ void client () { int main (int argc, char **argv) { pid_t pid; + + std::string user_salt; + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str()); + + #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #else pid = fork();