Skip to content

Commit 9eb4a8d

Browse files
committed
Add preload hack for trying out upki with openssl
1 parent 3c3897a commit 9eb4a8d

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

upki-openssl/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CC = gcc
2+
CFLAGS = -Wall -Wextra -fPIC
3+
LDFLAGS = -shared
4+
LIBS = -lssl -lcrypto -ldl -lupkiopenssl -L../target/release/
5+
6+
TARGET = libupkiopenssl-preload.so
7+
SOURCE = preload.c
8+
9+
.PHONY: all clean
10+
11+
all: $(TARGET)
12+
13+
$(TARGET): $(SOURCE) upki-openssl.h
14+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SOURCE) $(LIBS)
15+
16+
clean:
17+
rm -f $(TARGET)
18+
19+
install: $(TARGET)
20+
install -m 755 $(TARGET) /usr/local/lib/
21+
22+
uninstall:
23+
rm -f /usr/local/lib/$(TARGET)

upki-openssl/preload.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "upki-openssl.h"
2+
#include <dlfcn.h>
3+
#include <openssl/ssl.h>
4+
5+
typedef SSL *(*ssl_new_fn)(SSL_CTX *);
6+
7+
SSL *SSL_new(SSL_CTX *ctx) {
8+
void *parent = dlsym(RTLD_NEXT, "SSL_new");
9+
if (!parent) {
10+
return NULL;
11+
}
12+
13+
SSL *new = ((ssl_new_fn)(parent))(ctx);
14+
if (!new) {
15+
return new;
16+
}
17+
18+
// TODO: save and call current too.
19+
// SSL_verify_cb current = SSL_get_verify_callback(new);
20+
int mode = SSL_get_verify_mode(new);
21+
SSL_set_verify(new, mode, upki_openssl_verify_callback);
22+
return new;
23+
}
24+
25+
// TODO: also hook later calls of SSL_set_verify, SSL_get_verify_callback

0 commit comments

Comments
 (0)