@@ -62,6 +62,7 @@ static int cert_verify_cb(int preverify, WOLFSSL_X509_STORE_CTX* store)
6262 WOLFSSL_CERT_MANAGER * cm = NULL ;
6363 DecodedCert cert ;
6464 byte certInit = 0 ;
65+ WOLFSSL * ssl = (WOLFSSL * )store -> userCtx ;
6566
6667 cm = wolfSSL_CertManagerNew ();
6768 if (cm == NULL )
@@ -82,6 +83,27 @@ static int cert_verify_cb(int preverify, WOLFSSL_X509_STORE_CTX* store)
8283 if (ret == 1 && wc_ParseCert (& cert , CERT_TYPE , VERIFY , cm ) != 0 )
8384 ret = 0 ;
8485
86+ if (ret == 1 && (wolfSSL_version (ssl ) == TLS1_3_VERSION ||
87+ wolfSSL_version (ssl ) == DTLS1_3_VERSION )) {
88+ WOLFSSL_BUFFER_INFO * ocspStaple = wolfSSL_GetTls13OcspStatusResp (ssl , (word32 )depth );
89+ WOLFSSL_OCSP * ocsp = NULL ;
90+
91+ if (ocspStaple == NULL || ocspStaple -> buffer == NULL || ocspStaple -> length == 0 )
92+ ret = 0 ;
93+ if (ret == 1 && (ocsp = wc_NewOCSP (cm )) == NULL )
94+ ret = 0 ;
95+ if (ret == 1 &&
96+ wc_CheckCertOcspResponse (ocsp , & cert , ocspStaple -> buffer ,
97+ ocspStaple -> length , NULL ) != 0 )
98+ ret = 0 ;
99+ wc_FreeOCSP (ocsp );
100+
101+ if (ret == 1 )
102+ printf ("Client: Manual OCSP staple verification succeeded at depth %d\n" , depth );
103+ else
104+ printf ("Client: Manual OCSP staple verification failed at depth %d\n" , depth );
105+ }
106+
85107 if (certInit )
86108 wc_FreeDecodedCert (& cert );
87109 wolfSSL_CertManagerFree (cm );
@@ -152,24 +174,34 @@ static int ocsp_verify_cb(WOLFSSL* ssl, int err, unsigned char* staple, unsigned
152174 return err ;
153175}
154176
155- int main ()
177+ int main (int argc , char * * argv )
156178{
157179 int sockfd = -1 ;
158180 struct sockaddr_in serv_addr ;
159181 WOLFSSL_CTX * ctx = NULL ;
160182 WOLFSSL * ssl = NULL ;
161183 char buf [32 ];
184+ int use_tls13 = 0 ;
185+
186+ if (argc != 2 ) {
187+ printf ("Usage: %s [--tls12|--tls13]\n" , argv [0 ]);
188+ return 0 ;
189+ }
190+ if (strcmp (argv [1 ], "--tls13" ) == 0 ) {
191+ use_tls13 = 1 ;
192+ } else if (strcmp (argv [1 ], "--tls12" ) == 0 ) {
193+ use_tls13 = 0 ;
194+ } else {
195+ printf ("Usage: %s [--tls12|--tls13]\n" , argv [0 ]);
196+ return 0 ;
197+ }
162198
163199 wolfSSL_Init ();
164- ctx = wolfSSL_CTX_new (wolfTLSv1_2_client_method ());
200+ ctx = wolfSSL_CTX_new (use_tls13 ? wolfTLSv1_3_client_method () : wolfTLSv1_2_client_method ());
165201 if (!ctx ) {
166202 fprintf (stderr , "wolfSSL_CTX_new (client) failed\n" );
167203 goto cleanup ;
168204 }
169- // if (wolfSSL_CTX_load_verify_locations(ctx, CA_CERT, NULL) != WOLFSSL_SUCCESS) {
170- // fprintf(stderr, "wolfSSL_CTX_load_verify_locations failed\n");
171- // goto cleanup;
172- // }
173205 wolfSSL_CTX_set_verify (ctx , SSL_VERIFY_PEER , cert_verify_cb );
174206 if (wolfSSL_CTX_EnableOCSPStapling (ctx ) != WOLFSSL_SUCCESS ) {
175207 fprintf (stderr , "wolfSSL_CTX_EnableOCSPStapling failed\n" );
@@ -179,9 +211,17 @@ int main()
179211 fprintf (stderr , "wolfSSL_CTX_EnableOCSPMustStaple failed\n" );
180212 goto cleanup ;
181213 }
182- if (wolfSSL_CTX_UseOCSPStaplingV2 (ctx , WOLFSSL_CSR2_OCSP_MULTI , WOLFSSL_CSR2_OCSP_USE_NONCE ) != WOLFSSL_SUCCESS ) {
183- fprintf (stderr , "wolfSSL_CTX_UseOCSPStaplingV2 failed\n" );
184- goto cleanup ;
214+ if (use_tls13 ) {
215+ if (wolfSSL_CTX_UseOCSPStapling (ctx , WOLFSSL_CSR_OCSP , 0 ) != WOLFSSL_SUCCESS ) {
216+ fprintf (stderr , "wolfSSL_CTX_UseOCSPStaplingV2 failed\n" );
217+ goto cleanup ;
218+ }
219+ }
220+ else {
221+ if (wolfSSL_CTX_UseOCSPStaplingV2 (ctx , WOLFSSL_CSR2_OCSP_MULTI , 0 ) != WOLFSSL_SUCCESS ) {
222+ fprintf (stderr , "wolfSSL_CTX_UseOCSPStaplingV2 failed\n" );
223+ goto cleanup ;
224+ }
185225 }
186226 wolfSSL_CTX_set_tls12_ocsp_status_verify_cb (ctx , ocsp_verify_cb , NULL );
187227
@@ -208,9 +248,12 @@ int main()
208248 goto cleanup ;
209249 }
210250 wolfSSL_set_fd (ssl , sockfd );
251+ /* No way to get ssl from the store without OPENSSL_EXTRA */
252+ wolfSSL_SetCertCbCtx (ssl , ssl );
211253
212254 if (wolfSSL_connect (ssl ) == WOLFSSL_SUCCESS ) {
213255 printf ("Client: TLS handshake success\n" );
256+ printf ("Negotiated TLS version: %s\n" , wolfSSL_get_version (ssl ));
214257 int n = wolfSSL_read (ssl , buf , sizeof (buf )- 1 );
215258 if (n > 0 ) {
216259 buf [n ] = 0 ;
0 commit comments