Skip to content

Commit dd230cb

Browse files
typo fix, trim down struct, connect fd variable update
1 parent a24437d commit dd230cb

5 files changed

Lines changed: 20 additions & 23 deletions

File tree

examples/posix/wh_posix_client/wh_posix_client_cfg.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,9 @@ static int wh_PosixClient_ExampleTlsCommonConfig(void* conf)
249249

250250
memset(&tccTls, 0, sizeof(posixTransportTlsClientContext));
251251

252-
/* Initialize TCP context fields that need specific values */
252+
/* Initialize TLS context fields that need specific values */
253253
tccTls.state = 0;
254254
tccTls.connect_fd_p1 = 0; /* Invalid fd */
255-
tccTls.request_sent = 0;
256-
tccTls.buffer_offset = 0;
257255

258256
tlsConfig.server_ip_string = WH_POSIX_SERVER_TCP_IPSTRING;
259257
tlsConfig.server_port = WH_POSIX_SERVER_TCP_PORT;

examples/posix/wh_posix_server/wh_posix_server_cfg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ wh_PosixServer_ExampleTlsContextSetup(posixTransportTlsServerContext* ctx)
304304
return WH_ERROR_ABORTED;
305305
}
306306

307-
/* Setup server for mutual authentication. It will try to verify the clients
308-
* certificate so both the client and server authenticate the peer
309-
* connecting with. */
307+
/* Setup server for mutual authentication. It will try to verify the
308+
* client's certificate so both the client and server authenticate the peer
309+
* they are connecting to. */
310310
wolfSSL_CTX_set_verify(ctx->ssl_ctx, WOLFSSL_VERIFY_PEER, NULL);
311311

312312
return WH_ERROR_OK;

port/posix/posix_transport_tls.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ int posixTransportTls_SendRequest(void* context, uint16_t size,
127127
(void*)&ctx->tcpCtx, &ctx->connect_fd_p1) != WH_ERROR_OK) {
128128
return WH_ERROR_NOTREADY;
129129
}
130+
ctx->connect_fd_p1++;
130131

131132
ctx->ssl = wolfSSL_new(ctx->ssl_ctx);
132133
if (!ctx->ssl) {
@@ -135,7 +136,7 @@ int posixTransportTls_SendRequest(void* context, uint16_t size,
135136
}
136137

137138
/* Set the current socket file descriptor */
138-
rc = wolfSSL_set_fd(ctx->ssl, ctx->connect_fd_p1);
139+
rc = wolfSSL_set_fd(ctx->ssl, ctx->connect_fd_p1 - 1);
139140
if (rc != WOLFSSL_SUCCESS) {
140141
wolfSSL_free(ctx->ssl);
141142
ctx->ssl = NULL;
@@ -157,16 +158,16 @@ int posixTransportTls_SendRequest(void* context, uint16_t size,
157158
* send was in the TCP backlog waiting on the server. But
158159
* if the server closes down the listen port then RST gets
159160
* returned. Retry the TCP connect() */
160-
wolfSSL_free(ctx->ssl);
161-
ctx->ssl = NULL;
161+
wolfSSL_free(ctx->ssl);
162+
ctx->ssl = NULL;
162163

163-
/* Close the failed socket fd and set state for retry */
164-
if (ctx->tcpCtx.connect_fd_p1 != 0) {
165-
close(ctx->tcpCtx.connect_fd_p1 - 1);
164+
/* Close the failed socket fd and set state for retry */
165+
if (ctx->tcpCtx.connect_fd_p1 != 0) {
166166
ctx->tcpCtx.connect_fd_p1 = 0;
167167
}
168-
ctx->tcpCtx.state = PTT_STATE_UNCONNECTED;
169-
return WH_ERROR_NOTREADY;
168+
ctx->connect_fd_p1 = 0;
169+
ctx->tcpCtx.state = PTT_STATE_UNCONNECTED;
170+
return WH_ERROR_NOTREADY;
170171

171172
}
172173

@@ -347,7 +348,9 @@ int posixTransportTls_RecvRequest(void* context, uint16_t* out_size, void* data)
347348
ctx->client_addr = client_addr;
348349

349350
/* Make accepted socket non-blocking */
350-
fcntl(ctx->accept_fd_p1 - 1, F_SETFL, O_NONBLOCK);
351+
if (fcntl(ctx->accept_fd_p1 - 1, F_SETFL, O_NONBLOCK) != 0) {
352+
return WH_ERROR_ABORTED;
353+
}
351354

352355
/* Create SSL object for this connection */
353356
ctx->ssl = wolfSSL_new(ctx->ssl_ctx);
@@ -378,7 +381,8 @@ int posixTransportTls_RecvRequest(void* context, uint16_t* out_size, void* data)
378381
}
379382
}
380383

381-
/* Read data from SSL connection */
384+
/* Read data from SSL connection (also handles continuing on with
385+
* handshake if not complete yet) */
382386
rc = wolfSSL_read(ctx->ssl, data, PTTLS_PACKET_MAX_SIZE);
383387
err = wolfSSL_get_error(ctx->ssl, rc);
384388
if (rc > 0) {
@@ -423,7 +427,7 @@ int posixTransportTls_SendResponse(void* context, uint16_t size,
423427
}
424428
else {
425429
int err = wolfSSL_get_error(ctx->ssl, rc);
426-
if (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE) {
430+
if ((NonBlockingError(err))) {
427431
return WH_ERROR_NOTREADY;
428432
}
429433
return WH_ERROR_ABORTED;

port/posix/posix_transport_tls.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ typedef struct {
7272
struct sockaddr_in server_addr;
7373
pttlsClientState state;
7474
int connect_fd_p1; /* fd plus 1 so 0 is invalid */
75-
int request_sent;
76-
uint16_t buffer_offset;
77-
uint8_t buffer[PTTLS_BUFFER_SIZE];
7875
#ifndef WOLFHSM_CFG_NO_CRYPTO
7976
WOLFSSL_CTX* ssl_ctx;
8077
WOLFSSL* ssl;

test/wh_test.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,9 @@ static int whPosixClient_ExampleTlsCommonConfig(void* conf)
243243

244244
memset(&tccTls, 0, sizeof(posixTransportTlsClientContext));
245245

246-
/* Initialize TCP context fields that need specific values */
246+
/* Initialize TLS context fields that need specific values */
247247
tccTls.state = 0;
248248
tccTls.connect_fd_p1 = 0; /* Invalid fd */
249-
tccTls.request_sent = 0;
250-
tccTls.buffer_offset = 0;
251249

252250
tlsConfig.server_ip_string = WH_POSIX_SERVER_TCP_IPSTRING;
253251
tlsConfig.server_port = WH_POSIX_SERVER_TCP_PORT;

0 commit comments

Comments
 (0)