summaryrefslogtreecommitdiff
path: root/include/git2/sys/stream.h
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-10-25 08:49:01 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2018-11-28 15:46:57 +0000
commit43b592ac84dbd3d649022ff9503f00ecc83d5278 (patch)
treeaeb52e3f745cf99eb5d7807073dab1d3d7a07709 /include/git2/sys/stream.h
parent6ba3e6affc73b84f6cd2cadf476c0e0c5e58e404 (diff)
downloadlibgit2-43b592ac84dbd3d649022ff9503f00ecc83d5278.tar.gz
tls: introduce a wrap function
Introduce `git_tls_stream_wrap` which will take an existing `stream` with an already connected socket and begin speaking TLS on top of it. This is useful if you've built a connection to a proxy server and you wish to begin CONNECT over it to tunnel a TLS connection. Also update the pluggable TLS stream layer so that it can accept a registration structure that provides an `init` and `wrap` function, instead of a single initialization function.
Diffstat (limited to 'include/git2/sys/stream.h')
-rw-r--r--include/git2/sys/stream.h42
1 files changed, 36 insertions, 6 deletions
diff --git a/include/git2/sys/stream.h b/include/git2/sys/stream.h
index eeeb68dae..104ec3b5c 100644
--- a/include/git2/sys/stream.h
+++ b/include/git2/sys/stream.h
@@ -40,18 +40,48 @@ typedef struct git_stream {
void (*free)(struct git_stream *);
} git_stream;
-typedef int (*git_stream_cb)(git_stream **out, const char *host, const char *port);
+typedef struct {
+ /** The `version` field should be set to `GIT_STREAM_VERSION`. */
+ int version;
+
+ /**
+ * Called to create a new TLS connection to a given host.
+ *
+ * @param out The created TLS stream
+ * @param host The hostname to connect to; may be a hostname or
+ * IP address
+ * @param port The port to connect to; may be a port number or
+ * service name
+ * @return 0 or an error code
+ */
+ int (*init)(git_stream **out, const char *host, const char *port);
+
+ /**
+ * Called to create a new TLS connection on top of the given
+ * stream. May be used to proxy a TLS stream over a CONNECT
+ * session.
+ *
+ * @param out The created TLS stream
+ * @param in An existing stream to add TLS to
+ * @param host The hostname that the stream is connected to,
+ * for certificate validation
+ * @return 0 or an error code
+ */
+ int (*wrap)(git_stream **out, git_stream *in, const char *host);
+} git_stream_registration;
/**
- * Register a TLS stream constructor for the library to use
+ * Register TLS stream constructors for the library to use
*
- * If a constructor is already set, it will be overwritten. Pass
- * `NULL` in order to deregister the current constructor.
+ * If a registration structure is already set, it will be overwritten.
+ * Pass `NULL` in order to deregister the current constructor and return
+ * to the system defaults.
*
- * @param ctor the constructor to use
+ * @param registration the registration data
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_stream_register_tls(git_stream_cb ctor);
+GIT_EXTERN(int) git_stream_register_tls(
+ git_stream_registration *registration);
GIT_END_DECL