mirror of
https://gitlab.com/niansa/nosni.git
synced 2025-03-06 20:53:26 +01:00
Initial commit
This commit is contained in:
commit
5368108949
6 changed files with 87 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.so
|
||||
*.o
|
7
Makefile
Normal file
7
Makefile
Normal file
|
@ -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
|
29
common.c
Normal file
29
common.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
1
common.cpp
Normal file
1
common.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
|
1
common.h
Normal file
1
common.h
Normal file
|
@ -0,0 +1 @@
|
|||
const char *resolve_hostname_to_str(const char *hostname);
|
47
nss.c
Normal file
47
nss.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "common.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
#include <nss/ssl.h>
|
||||
#include <nss/cms.h>
|
||||
|
||||
|
||||
|
||||
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");
|
||||
}
|
Loading…
Add table
Reference in a new issue