Skip to content

Commit 6a34cb5

Browse files
authored
Merge pull request #413 from dgarske/cryptocb_hmac
Improve TLS crypto callback examples
2 parents 005d883 + ab0d633 commit 6a34cb5

17 files changed

Lines changed: 950 additions & 428 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ android/wolfssljni-ndk-sample/proguard-project.txt
7373
/psk/server-psk
7474
/psk/server-tcp
7575

76+
/tls/client-async
7677
/tls/client-tcp
7778
/tls/client-tls
7879
/tls/client-tls13
7980
/tls/client-tls13-resume
8081
/tls/client-tls-bio
8182
/tls/client-tls-cacb
8283
/tls/client-tls-callback
84+
/tls/client-tls-cryptocb
8385
/tls/client-tls-ecdhe
8486
/tls/client-tls-nonblocking
8587
/tls/client-tls-perf
@@ -89,10 +91,12 @@ android/wolfssljni-ndk-sample/proguard-project.txt
8991

9092
/tls/memory-tls
9193

94+
/tls/server-async
9295
/tls/server-tcp
9396
/tls/server-tls
9497
/tls/server-tls13
9598
/tls/server-tls-callback
99+
/tls/server-tls-cryptocb
96100
/tls/server-tls-ecdhe
97101
/tls/server-tls-epoll-perf
98102
/tls/server-tls-epoll-threaded

tls/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ STATIC_LIB = $(LIB_PATH)/lib/libwolfssl.a
1010
DEBUG_FLAGS = -g -DDEBUG
1111
DEBUG_INC_PATHS = -MD
1212
OPTIMIZE = -Os
13+
DEPS =
1314

1415
# Options
1516
#CFLAGS+=$(DEBUG_FLAGS)
@@ -19,9 +20,14 @@ CFLAGS+=$(OPTIMIZE)
1920
#LIBS+=$(STATIC_LIB)
2021
LIBS+=$(DYN_LIB)
2122

23+
# Openssl Option
24+
#CFLAGS+=-DUSE_OPENSSL
25+
#LIBS+=-lcrypto
26+
2227
# build targets
2328
SRC=$(wildcard *.c)
24-
TARGETS=$(patsubst %.c, %, $(SRC))
29+
IGNORE_FILES=cryptocb-common
30+
TARGETS=$(filter-out $(IGNORE_FILES), $(patsubst %.c, %, $(SRC)))
2531
LINUX_SPECIFIC=client-tls-perf \
2632
server-tls-poll-perf \
2733
server-tls-epoll-perf \
@@ -97,9 +103,11 @@ memory-tls: CFLAGS+=-pthread
97103
# compile tcp examples without the LIBS variable
98104
%-tcp: LIBS=
99105

106+
%-cryptocb: DEPS+=cryptocb-common.c
107+
100108
# build template
101109
%: %.c
102-
$(CC) -o $@ $< $(CFLAGS) $(LIBS)
110+
$(CC) -o $@ $(DEPS) $< $(CFLAGS) $(LIBS)
103111

104112
clean:
105113
rm -f $(TARGETS)

tls/client-tls-cacb.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void CaCb(unsigned char* der, int sz, int type)
9797
}
9898

9999
ret = wolfSSL_X509_get_serial_number(x509, serial, &sz);
100-
if (ret == SSL_SUCCESS) {
100+
if (ret == WOLFSSL_SUCCESS) {
101101
int i;
102102
int strLen;
103103
char serialMsg[80];
@@ -134,28 +134,28 @@ int Security(int sock)
134134
/* create and initialize WOLFSSL_CTX structure */
135135
if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) {
136136
printf("SSL_CTX_new error.\n");
137-
ret = EXIT_FAILURE;
137+
ret = EXIT_FAILURE;
138138
goto exit;
139139
}
140140

141141
/* set callback for action when CA's are added */
142142
wolfSSL_CTX_SetCACb(ctx, CaCb);
143143

144144
/* load CA certificates into wolfSSL_CTX. which will verify the server */
145-
if ((ret = wolfSSL_CTX_load_verify_locations(ctx, cert, 0))
145+
if ((ret = wolfSSL_CTX_load_verify_locations(ctx, cert, 0))
146146
!= WOLFSSL_SUCCESS) {
147147
printf("Error loading %s. Please check the file.\n", cert);
148148
goto exit;
149149
}
150150
if ((ssl = wolfSSL_new(ctx)) == NULL) {
151151
printf("wolfSSL_new error.\n");
152-
ret = EXIT_FAILURE;
152+
ret = EXIT_FAILURE;
153153
goto exit;
154154
}
155155
wolfSSL_set_fd(ssl, sock);
156156

157157
ret = wolfSSL_connect(ssl);
158-
if (ret == SSL_SUCCESS) {
158+
if (ret == WOLFSSL_SUCCESS) {
159159
ret = ClientGreet(sock, ssl);
160160
}
161161

@@ -190,7 +190,7 @@ int main(int argc, char** argv)
190190

191191
if (sockfd < 0) {
192192
printf("Failed to create socket. Error: %i\n", errno);
193-
ret = EXIT_FAILURE;
193+
ret = EXIT_FAILURE;
194194
goto exit;
195195
}
196196

0 commit comments

Comments
 (0)