]> gitweb.factorcode.org Git - factor.git/commitdiff
openssl: move some things around for bootstrap.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 4 May 2021 23:53:41 +0000 (16:53 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 4 May 2021 23:53:41 +0000 (16:53 -0700)
basis/io/sockets/secure/openssl/openssl.factor
basis/openssl/libssl/libssl.factor

index 0e870ddc62b0fe1658fd3bbe4ed1a130f458057a..3fb382e4bda86d9ce9f4e9a5e500c7aeacf1d5e2 100644 (file)
@@ -3,11 +3,13 @@
 USING: accessors alien alien.c-types alien.data alien.enums
 alien.strings assocs byte-arrays classes.struct combinators
 combinators.short-circuit destructors fry io io.backend
-io.binary io.buffers io.encodings.latin1 io.encodings.utf8
-io.files io.pathnames io.ports io.sockets io.sockets.secure
-io.timeouts kernel libc locals math math.functions math.order
-math.parser memoize namespaces openssl openssl.libcrypto
-openssl.libssl random sequences sets splitting unicode ;
+io.binary io.buffers io.encodings.latin1 io.encodings.string
+io.encodings.utf8 io.files io.pathnames io.ports io.sockets
+io.sockets.secure io.timeouts kernel libc locals math
+math.functions math.order math.parser memoize namespaces openssl
+openssl.libcrypto openssl.libssl random sequences sets splitting
+unicode ;
+SLOT: alpn-supported-protocols
 IN: io.sockets.secure.openssl
 
 GENERIC: ssl-method ( symbol -- method )
@@ -215,6 +217,50 @@ SYMBOL: default-secure-context
         set-secure-cipher-list-only
     ] with-destructors ;
 
+<PRIVATE
+
+: alpn_select_cb_func ( -- alien )
+    [|  ssl out outlen in inlen arg |
+        ! if alpn-protocols is empty return err noack
+
+        ! current-secure-context relies on secure-context
+        ! variable being set. if this is not set in a callback,
+        ! we need some other way of accessing it (probably
+        ! passing it as arg to SSL_CTX_set_alpn_select_cb, but
+        ! need to make sure that stays defined as long as the
+        ! callback can be called)
+        current-secure-context config>> alpn-supported-protocols>>
+        [ SSL_TLSEXT_ERR_NOACK ]
+        [ [ out outlen ] dip
+          ! convert alpn-protocols from list of strings to
+          ! c-string in wire format and length.
+          ! see https://www.openssl.org/docs/manmaster/man3/SSL_set_alpn_protos.html
+          [ utf8 encode dup length prefix ] map
+          concat dup length
+          in inlen SSL_select_next_proto
+          ! the function returns OPENSSL_NPN_NO_OVERLAP when no
+          ! match is found, otherwise OPENSSL_NPN_NEGOTIATED
+          OPENSSL_NPN_NEGOTIATED =
+          [ ! DOUBLECHECK: The value in out is already copied
+            ! from the original, so we can just leave it and
+            ! return... otherwise this detail needs to be ironed
+            ! out, probably by finding the entry in in that out
+            ! is identical to. (out needs to point directly into
+            ! in, or a buffer that will outlive the tls
+            ! handshake.)
+            SSL_TLSEXT_ERR_OK ]
+          [ SSL_TLSEXT_ERR_ALERT_FATAL ] if
+        ] if-empty
+    ] SSL_CTX_alpn_select_cb_func ;
+
+: get_alpn_selected_wrapper ( ssl* -- alpn_string/f )
+    { c-string int } [ SSL_get0_alpn_selected ] with-out-parameters
+    drop ! how do we unbox the c-string?
+    ! also, the string is not null-terminated, is that problematic?
+    ;
+
+PRIVATE>
+
 :: <ssl-socket> ( winsock hostname -- ssl )
     winsock socket-handle BIO_NOCLOSE BIO_new_socket dup ssl-error :> bio
     winsock <ssl-handle> :> handle
index f9d5001acd3aabb99bdac1c93771702e0d080fdc..84f8d38e5505034686b28674f0868b98e96525ec 100644 (file)
@@ -6,6 +6,7 @@ alien.destructors alien.libraries alien.parser alien.syntax
 classes.struct combinators io.encodings.string io.encodings.utf8
 io.sockets.secure.openssl kernel literals namespaces
 openssl.libcrypto sequences system ;
+SLOT: alpn-supported-protocols
 
 IN: openssl.libssl
 
@@ -548,46 +549,6 @@ client_len )
 FUNCTION: void SSL_get0_alpn_selected ( SSL* s,
 c-string* data, uint* len )
 
-: alpn_select_cb_func ( -- alien )
-    [|  ssl out outlen in inlen arg |
-        ! if alpn-protocols is empty return err noack
-
-        ! current-secure-context relies on secure-context
-        ! variable being set. if this is not set in a callback,
-        ! we need some other way of accessing it (probably
-        ! passing it as arg to SSL_CTX_set_alpn_select_cb, but
-        ! need to make sure that stays defined as long as the
-        ! callback can be called)
-        current-secure-context config>> alpn-supported-protocols>>
-        [ SSL_TLSEXT_ERR_NOACK ]
-        [ [ out outlen ] dip
-          ! convert alpn-protocols from list of strings to
-          ! c-string in wire format and length.
-          ! see https://www.openssl.org/docs/manmaster/man3/SSL_set_alpn_protos.html
-          [ utf8 encode dup length prefix ] map
-          concat dup length
-          in inlen SSL_select_next_proto
-          ! the function returns OPENSSL_NPN_NO_OVERLAP when no
-          ! match is found, otherwise OPENSSL_NPN_NEGOTIATED
-          OPENSSL_NPN_NEGOTIATED =
-          [ ! DOUBLECHECK: The value in out is already copied
-            ! from the original, so we can just leave it and
-            ! return... otherwise this detail needs to be ironed
-            ! out, probably by finding the entry in in that out
-            ! is identical to. (out needs to point directly into
-            ! in, or a buffer that will outlive the tls
-            ! handshake.)
-            SSL_TLSEXT_ERR_OK ]
-          [ SSL_TLSEXT_ERR_ALERT_FATAL ] if
-        ] if-empty
-    ] SSL_CTX_alpn_select_cb_func ;
-
-: get_alpn_selected_wrapper ( ssl* -- alpn_string/f )
-    { c-string int } [ SSL_get0_alpn_selected ] with-out-parameters
-    drop ! how do we unbox the c-string?
-    ! also, the string is not null-terminated, is that problematic?
-    ;
-
 ! ------------------------------------------------------------------------------
 ! Misc
 ! ------------------------------------------------------------------------------