QUIC APL: Implement SSL_want
authorHugo Landau <hlandau@openssl.org>
Thu, 31 Aug 2023 10:53:32 +0000 (11:53 +0100)
committerHugo Landau <hlandau@openssl.org>
Fri, 1 Sep 2023 13:44:47 +0000 (14:44 +0100)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21915)

include/internal/quic_ssl.h
ssl/quic/quic_impl.c
ssl/ssl_lib.c

index f815ba5435951fec46b9c504c6fbd31fdc14653f..77ff85a022cd4e333a298fb2b41bf70fde76b482 100644 (file)
@@ -57,6 +57,7 @@ __owur int ossl_quic_get_wpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *d);
 __owur int ossl_quic_get_net_read_desired(SSL *s);
 __owur int ossl_quic_get_net_write_desired(SSL *s);
 __owur int ossl_quic_get_error(const SSL *s, int i);
+__owur int ossl_quic_want(const SSL *s);
 __owur int ossl_quic_conn_get_blocking_mode(const SSL *s);
 __owur int ossl_quic_conn_set_blocking_mode(SSL *s, int blocking);
 __owur int ossl_quic_conn_shutdown(SSL *s, uint64_t flags,
index 2f60594efa7ac404c481d661c9c38dcd79a3e5bb..71c15361027d1a313fd49d78beac0b099fc261b5 100644 (file)
@@ -2025,6 +2025,7 @@ SSL *ossl_quic_conn_stream_new(SSL *s, uint64_t flags)
  * above, all QUIC I/O is implemented using non-blocking mode internally.
  *
  *         SSL_get_error        => partially implemented by ossl_quic_get_error
+ *         SSL_want             => ossl_quic_want
  *   (BIO/)SSL_read             => ossl_quic_read
  *   (BIO/)SSL_write            => ossl_quic_write
  *         SSL_pending          => ossl_quic_pending
@@ -2052,6 +2053,47 @@ int ossl_quic_get_error(const SSL *s, int i)
     return last_error;
 }
 
+/* Converts a code returned by SSL_get_error to a code returned by SSL_want. */
+static int error_to_want(int error)
+{
+    switch (error) {
+    case SSL_ERROR_WANT_CONNECT: /* never used - UDP is connectionless */
+    case SSL_ERROR_WANT_ACCEPT:  /* never used - UDP is connectionless */
+    case SSL_ERROR_ZERO_RETURN:
+    default:
+        return SSL_NOTHING;
+
+    case SSL_ERROR_WANT_READ:
+        return SSL_READING;
+
+    case SSL_ERROR_WANT_WRITE:
+        return SSL_WRITING;
+
+    case SSL_ERROR_WANT_CLIENT_HELLO_CB:
+        return SSL_CLIENT_HELLO_CB;
+
+    case SSL_ERROR_WANT_X509_LOOKUP:
+        return SSL_X509_LOOKUP;
+    }
+}
+
+/* SSL_want */
+int ossl_quic_want(const SSL *s)
+{
+    QCTX ctx;
+    int w;
+
+    if (!expect_quic(s, &ctx))
+        return SSL_NOTHING;
+
+    quic_lock(ctx.qc);
+
+    w = error_to_want(ctx.is_stream ? ctx.xso->last_error : ctx.qc->last_error);
+
+    quic_unlock(ctx.qc);
+    return w;
+}
+
 /*
  * SSL_write
  * ---------
index b83f11fa5b4a070e4b2dc1e3c74ab01d23fbd027..5bfd8cc4cef0fa23947126793c7939f76ca9732a 100644 (file)
@@ -5501,6 +5501,11 @@ int SSL_want(const SSL *s)
 {
     const SSL_CONNECTION *sc = SSL_CONNECTION_FROM_CONST_SSL(s);
 
+#ifndef OPENSSL_NO_QUIC
+    if (IS_QUIC(s))
+        return ossl_quic_want(s);
+#endif
+
     if (sc == NULL)
         return SSL_NOTHING;