1 /* This tests nx_secure_tls_send_certificate. */
2 
3 #include "nx_api.h"
4 #include "nx_secure_tls_api.h"
5 #include "tls_test_utility.h"
6 
7 extern VOID    test_control_return(UINT status);
8 
9 #ifndef NX_SECURE_DISABLE_X509
10 
11 UCHAR packet_buffer[100];
12 
13 #ifdef CTEST
14 void test_application_define(void *first_unused_memory);
test_application_define(void * first_unused_memory)15 void test_application_define(void *first_unused_memory)
16 #else
17 void nx_secure_tls_send_certificate_test_application_define(void *first_unused_memory)
18 #endif
19 {
20 UINT   status;
21 NX_SECURE_TLS_SESSION tls_session;
22 NX_SECURE_X509_CERT certificate;
23 NX_PACKET send_packet;
24 
25     /* Print out test information banner.  */
26     printf("NetX Secure Test:   TLS Send Certificate Test....................");
27 
28 	memset(&tls_session, 0, sizeof(tls_session));
29 	tls_session.nx_secure_tls_credentials.nx_secure_tls_active_certificate = &certificate;
30 
31 	memset(&send_packet, 0, sizeof(send_packet));
32 	send_packet.nx_packet_data_end = send_packet.nx_packet_append_ptr + 1;
33 
34     status = _nx_secure_tls_send_certificate(&tls_session, &send_packet, TX_WAIT_FOREVER);
35 	EXPECT_EQ(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL, status);
36 
37     status = _nx_secure_tls_send_certificate_request(&tls_session, &send_packet);
38 	EXPECT_EQ(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL, status);
39 
40 	send_packet.nx_packet_append_ptr = packet_buffer;
41 	send_packet.nx_packet_data_end = send_packet.nx_packet_append_ptr + 100;
42 	tls_session.nx_secure_tls_protocol_version = NX_SECURE_TLS_VERSION_TLS_1_2;
43     status = _nx_secure_tls_send_certificate_request(&tls_session, &send_packet);
44 	EXPECT_EQ(NX_SUCCESS, status);
45 
46 	tls_session.nx_secure_tls_protocol_version = NX_SECURE_TLS_VERSION_TLS_1_3;
47     status = _nx_secure_tls_send_certificate_request(&tls_session, &send_packet);
48 	EXPECT_EQ(NX_SUCCESS, status);
49 	tls_session.nx_secure_tls_protocol_version = NX_SECURE_TLS_VERSION_TLS_1_2;
50 
51 	/* Coverage test for _nx_secure_tls_send_finished */
52 	send_packet.nx_packet_data_end = send_packet.nx_packet_append_ptr + 10;
53 	tls_session.nx_secure_tls_socket_type = NX_SECURE_TLS_SESSION_TYPE_SERVER;
54 	status = _nx_secure_tls_send_finished(&tls_session, &send_packet);
55 	EXPECT_EQ(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL, status);
56 
57 	send_packet.nx_packet_data_end = send_packet.nx_packet_append_ptr + 50;
58 	tls_session.nx_secure_tls_socket_type = NX_SECURE_TLS_SESSION_TYPE_SERVER;
59 	status = _nx_secure_tls_send_finished(&tls_session, &send_packet);
60 	EXPECT_EQ(NX_SECURE_TLS_UNKNOWN_CIPHERSUITE, status);
61 
62 	printf("SUCCESS!\n");
63 	test_control_return(0);
64 }
65 #else
66 #ifdef CTEST
67 void test_application_define(void *first_unused_memory);
test_application_define(void * first_unused_memory)68 void test_application_define(void *first_unused_memory)
69 #else
70 void nx_secure_tls_send_certificate_test_application_define(void *first_unused_memory)
71 #endif
72 {
73 
74     /* Print out test information banner.  */
75     printf("NetX Secure Test:   TLS Send Certificate Test....................N/A\n");
76     test_control_return(3);
77 }
78 #endif
79