Skip to content

Commit

Permalink
quic: documentation and demo nits
Browse files Browse the repository at this point in the history
The code for the quic demos (from the openssl guide) is presented as
modifications of tls-client-block.c.  Make it so that the quic code
better matches the tls code (drop unneeded assignments to "ret", use
the same comment on SSL_connect(), add the same printf() statement).

Also fix some minor typos.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #22483)
  • Loading branch information
James Muir authored and mattcaswell committed Oct 25, 2023
1 parent 687326c commit 59d8a33
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions demos/guide/quic-client-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ int main(void)
goto end;
}

/* Connect to the server and perform the TLS handshake */
if ((ret = SSL_connect(ssl)) < 1) {
/* Do the handshake with the server */
if (SSL_connect(ssl) < 1) {
printf("Failed to connect to the server\n");
/*
* If the failure is due to a verification error we can get more
* information about it from SSL_get_verify_result().
Expand Down
9 changes: 5 additions & 4 deletions demos/guide/quic-multi-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
*/
for (ai = res; ai != NULL; ai = BIO_ADDRINFO_next(ai)) {
/*
* Create a TCP socket. We could equally use non-OpenSSL calls such
* Create a UDP socket. We could equally use non-OpenSSL calls such
* as "socket" here for this and the subsequent connect and close
* functions. But for portability reasons and also so that we get
* errors on the OpenSSL stack in the event of a failure we use
Expand Down Expand Up @@ -82,7 +82,6 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
}
}


/* Free the address information resources we allocated earlier */
BIO_ADDRINFO_free(res);

Expand All @@ -96,6 +95,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port,
BIO_closesocket(sock);
return NULL;
}

/*
* Associate the newly created BIO with the underlying socket. By
* passing BIO_CLOSE here the socket will be automatically closed when
Expand Down Expand Up @@ -222,8 +222,9 @@ int main(void)
goto end;
}

/* Connect to the server and perform the TLS handshake */
if ((ret = SSL_connect(ssl)) < 1) {
/* Do the handshake with the server */
if (SSL_connect(ssl) < 1) {
printf("Failed to connect to the server\n");
/*
* If the failure is due to a verification error we can get more
* information about it from SSL_get_verify_result().
Expand Down
2 changes: 1 addition & 1 deletion demos/guide/tls-client-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static BIO *create_socket_bio(const char *hostname, const char *port)
if (sock == -1)
return NULL;

/* Create a BIO to wrap the socket*/
/* Create a BIO to wrap the socket */
bio = BIO_new(BIO_s_socket());
if (bio == NULL) {
BIO_closesocket(sock);
Expand Down
6 changes: 3 additions & 3 deletions doc/man7/ossl-guide-quic-multi-stream.pod
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ passes the connection B<SSL> object as a parameter.

If a client application calls L<SSL_write_ex(3)> or L<SSL_write(3)> first then
(by default) the default stream will be a client-initiated bi-directional
stream. If the client applications call L<SSL_read_ex(3)> or L<SSL_read(3)>
stream. If a client application calls L<SSL_read_ex(3)> or L<SSL_read(3)>
first then the first stream initiated by the server will be used as the default
stream (whether it is bi-directional or uni-directional).

Expand Down Expand Up @@ -285,7 +285,7 @@ these different cases.
* QUIC terms this means that the peer has sent FIN on the stream to
* indicate that no further data will be sent.
*/
switch (SSL_get_error(ssl, 0)) {
switch (SSL_get_error(stream1, 0)) {
case SSL_ERROR_ZERO_RETURN:
/* Normal completion of the stream */
break;
Expand All @@ -295,7 +295,7 @@ these different cases.
* Some stream fatal error occurred. This could be because of a stream
* reset - or some failure occurred on the underlying connection.
*/
switch (SSL_get_stream_read_state(ssl)) {
switch (SSL_get_stream_read_state(stream1)) {
case SSL_STREAM_STATE_RESET_REMOTE:
printf("Stream reset occurred\n");
/* The stream has been reset but the connection is still healthy. */
Expand Down

0 comments on commit 59d8a33

Please sign in to comment.