Lines Matching +full:- +full:r
4 * SPDX-License-Identifier: Apache-2.0
25 #define SECRET "forty-two"
30 #define SECRET_SIZE (sizeof(SECRET) - 1)
44 * @brief Application-dependent TLS credential identifiers
51 * - SERVER_CERTIFICATE_TAG (for both public and private keys)
52 * - CA_CERTIFICATE_TAG (only when client authentication is required)
55 * - CA_CERTIFICATE_TAG (always required, to verify the server)
56 * - CLIENT_CERTIFICATE_TAG (for both public and private keys, only when
151 int r; in server_thread_fn() local
167 r = accept(server_fd, (struct sockaddr *)&sa, &addrlen); in server_thread_fn()
168 zassert_not_equal(r, -1, "accept() failed (%d)", r); in server_thread_fn()
169 client_fd = r; in server_thread_fn()
180 r = recv(client_fd, addrstr, sizeof(addrstr), 0); in server_thread_fn()
181 zassert_not_equal(r, -1, "recv() failed (%d)", errno); in server_thread_fn()
182 zassert_equal(r, SECRET_SIZE, "expected: %zu actual: %d", SECRET_SIZE, r); in server_thread_fn()
185 r = send(client_fd, SECRET, SECRET_SIZE, 0); in server_thread_fn()
186 zassert_not_equal(r, -1, "send() failed (%d)", errno); in server_thread_fn()
187 zassert_equal(r, SECRET_SIZE, "expected: %zu actual: %d", SECRET_SIZE, r); in server_thread_fn()
190 r = close(client_fd); in server_thread_fn()
191 zassert_not_equal(r, -1, "close() failed on the server fd (%d)", errno); in server_thread_fn()
198 int r; in test_common() local
218 r = socket(AF_INET, SOCK_STREAM, proto); in test_common()
219 zassert_not_equal(r, -1, "failed to create server socket (%d)", errno); in test_common()
220 server_fd = r; in test_common()
222 r = setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); in test_common()
223 zassert_not_equal(r, -1, "failed to set SO_REUSEADDR (%d)", errno); in test_common()
250 r = setsockopt(server_fd, SOL_TLS, TLS_PEER_VERIFY, in test_common()
252 zassert_not_equal(r, -1, in test_common()
262 r = setsockopt(server_fd, SOL_TLS, TLS_SEC_TAG_LIST, in test_common()
264 zassert_not_equal(r, -1, "failed to set TLS_SEC_TAG_LIST (%d)", in test_common()
267 r = setsockopt(server_fd, SOL_TLS, TLS_HOSTNAME, "localhost", in test_common()
269 zassert_not_equal(r, -1, "failed to set TLS_HOSTNAME (%d)", in test_common()
279 r = bind(server_fd, (struct sockaddr *)&sa, sizeof(sa)); in test_common()
280 zassert_not_equal(r, -1, "failed to bind (%d)", errno); in test_common()
282 r = listen(server_fd, 1); in test_common()
283 zassert_not_equal(r, -1, "failed to listen (%d)", errno); in test_common()
299 r = k_sem_take(&server_sem, K_MSEC(TIMEOUT)); in test_common()
300 zassert_equal(0, r, "failed to synchronize with server thread (%d)", r); in test_common()
309 r = socket(AF_INET, SOCK_STREAM, proto); in test_common()
310 zassert_not_equal(r, -1, "failed to create client socket (%d)", errno); in test_common()
311 client_fd = r; in test_common()
344 r = setsockopt(client_fd, SOL_TLS, TLS_SEC_TAG_LIST, in test_common()
346 zassert_not_equal(r, -1, "failed to set TLS_SEC_TAG_LIST (%d)", in test_common()
349 r = setsockopt(client_fd, SOL_TLS, TLS_HOSTNAME, "localhost", in test_common()
351 zassert_not_equal(r, -1, "failed to set TLS_HOSTNAME (%d)", errno); in test_common()
354 r = inet_pton(AF_INET, MY_IPV4_ADDR, &sa.sin_addr.s_addr); in test_common()
355 zassert_not_equal(-1, r, "inet_pton() failed (%d)", errno); in test_common()
356 zassert_not_equal(0, r, "%s is not a valid IPv4 address", MY_IPV4_ADDR); in test_common()
357 zassert_equal(1, r, "inet_pton() failed to convert %s", MY_IPV4_ADDR); in test_common()
367 r = connect(client_fd, (struct sockaddr *)&sa, sizeof(sa)); in test_common()
368 zassert_not_equal(r, -1, "failed to connect (%d)", errno); in test_common()
375 r = send(client_fd, SECRET, SECRET_SIZE, 0); in test_common()
376 zassert_not_equal(r, -1, "send() failed (%d)", errno); in test_common()
377 zassert_equal(SECRET_SIZE, r, "expected: %zu actual: %d", SECRET_SIZE, r); in test_common()
381 r = recv(client_fd, addrstr, sizeof(addrstr), 0); in test_common()
382 zassert_not_equal(r, -1, "recv() failed (%d)", errno); in test_common()
383 zassert_equal(SECRET_SIZE, r, "expected: %zu actual: %d", SECRET_SIZE, r); in test_common()
393 r = close(client_fd); in test_common()
394 zassert_not_equal(-1, r, "close() failed on the client fd (%d)", errno); in test_common()
397 r = close(server_fd); in test_common()
398 zassert_not_equal(-1, r, "close() failed on the server fd (%d)", errno); in test_common()
400 r = k_thread_join(&server_thread, K_FOREVER); in test_common()
401 zassert_equal(0, r, "k_thread_join() failed (%d)", r); in test_common()
421 int r; in setup() local
433 * - server public key in setup()
434 * - server private key in setup()
435 * - ca cert (only when client authentication is required) in setup()
438 * - ca cert (to verify the server) in setup()
439 * - client public key (only when client authentication is required) in setup()
440 * - client private key (only when client authentication is required) in setup()
444 r = tls_credential_add(CA_CERTIFICATE_TAG, in setup()
447 zassert_equal(r, 0, "failed to add CA Certificate (%d)", r); in setup()
449 r = tls_credential_add(SERVER_CERTIFICATE_TAG, in setup()
452 zassert_equal(r, 0, "failed to add Server Certificate (%d)", r); in setup()
454 r = tls_credential_add(SERVER_CERTIFICATE_TAG, in setup()
457 zassert_equal(r, 0, "failed to add Server Private Key (%d)", r); in setup()
459 r = tls_credential_add(CLIENT_CERTIFICATE_TAG, in setup()
462 zassert_equal(r, 0, "failed to add Client Certificate (%d)", r); in setup()
464 r = tls_credential_add(CLIENT_CERTIFICATE_TAG, in setup()
467 zassert_equal(r, 0, "failed to add Client Private Key (%d)", r); in setup()