commit 53681089491b6321780a2eccd7a6da0956f40cc2 Author: niansa Date: Thu Apr 13 09:09:03 2023 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc78368 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.so +*.o diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..30c92da --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +libnosni.so: nss.c common.c common.cpp common.h + g++ -c common.cpp -o cpp.o + gcc -g -fPIC -shared -I /usr/include/nspr/ nss.c common.c cpp.o -o libnosni.so + rm -f cpp.o + +clean: + rm -f *.so *.o diff --git a/common.c b/common.c new file mode 100644 index 0000000..7c7b9b3 --- /dev/null +++ b/common.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include + + + +const char *resolve_hostname_to_str(const char *hostname) { + struct addrinfo *addrInfo; + char str[INET_ADDRSTRLEN]; + + // Set up hints + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_INET; //TODO: Care about IPv6 + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_CANONNAME; + + // Get addrinfo + int error = getaddrinfo(hostname, "https", &hints, &addrInfo); + if (addrInfo == NULL) return NULL; + + // Return addr + struct sockaddr_in *addr = (struct sockaddr_in *)addrInfo->ai_addr; + return inet_ntoa((struct in_addr)addr->sin_addr); +} diff --git a/common.cpp b/common.cpp new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/common.cpp @@ -0,0 +1 @@ + diff --git a/common.h b/common.h new file mode 100644 index 0000000..f79026e --- /dev/null +++ b/common.h @@ -0,0 +1 @@ +const char *resolve_hostname_to_str(const char *hostname); diff --git a/nss.c b/nss.c new file mode 100644 index 0000000..4a8444e --- /dev/null +++ b/nss.c @@ -0,0 +1,47 @@ +#include "common.h" + +#include +#include +#include +#include + + + +SECStatus SSL_SNISocketConfigHook(PRFileDesc *fd, +SSLSNISocketConfig f, +void *arg) { + // Debug + printf("Interrupted socket config hook setter; dummy not implemented. Returning error.\n"); + fflush(stdout); + + // Report failure + return SECFailure; +} + +SECStatus SSL_SetURL(PRFileDesc *fd, const char *url) { + // Debug + printf("Interrupted URL setter for %s; setting IP address on success.\n", url); + fflush(stdout); + + // Get original function + static typeof(SSL_SetURL) *orig = NULL; + if (!orig) orig = dlsym(RTLD_NEXT, "SSL_SetURL"); + + // Get IP addr as string + url = resolve_hostname_to_str(url); + if (!url) return SECFailure; + + // Call origin function + orig(fd, url); + + // Report success + return SECSuccess; +} + +extern char * +NSS_CMSSignerInfo_GetSignerCommonName(NSSCMSSignerInfo *sinfo) { + printf("Interrupted common signer name getter; returning debug domain.\n"); + fflush(stdout); + + return strdup("hello.com"); +}