add support for OpenSSL 1.1.0 for BIO filter Closes: https://github.com/libgit2/libgit2/issues/3959 Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
diff --git a/src/openssl_stream.c b/src/openssl_stream.c
index b8ab21f..9c5e0b1 100644
--- a/src/openssl_stream.c
+++ b/src/openssl_stream.c
@@ -156,10 +156,14 @@ int git_openssl_set_locking(void)
static int bio_create(BIO *b)
{
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
b->init = 1;
b->num = 0;
b->ptr = NULL;
b->flags = 0;
+#else
+ BIO_set_init(b, 1);
+#endif
return 1;
}
@@ -169,23 +173,36 @@ static int bio_destroy(BIO *b)
if (!b)
return 0;
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
b->init = 0;
b->num = 0;
b->ptr = NULL;
b->flags = 0;
+#else
+ BIO_set_init(b, 0);
+ BIO_set_data(b, NULL);
+#endif
return 1;
}
static int bio_read(BIO *b, char *buf, int len)
{
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
git_stream *io = (git_stream *) b->ptr;
+#else
+ git_stream *io = (git_stream *) BIO_get_data(b);
+#endif
return (int) git_stream_read(io, buf, len);
}
static int bio_write(BIO *b, const char *buf, int len)
{
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
git_stream *io = (git_stream *) b->ptr;
+#else
+ git_stream *io = (git_stream *) BIO_get_data(b);
+#endif
return (int) git_stream_write(io, buf, len, 0);
}
@@ -214,6 +231,7 @@ static int bio_puts(BIO *b, const char *str)
return bio_write(b, str, strlen(str));
}
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
static BIO_METHOD git_stream_bio_method = {
BIO_TYPE_SOURCE_SINK,
"git_stream",
@@ -225,6 +243,9 @@ static BIO_METHOD git_stream_bio_method = {
bio_create,
bio_destroy
};
+#else
+static BIO_METHOD *git_stream_bio_method = NULL;
+#endif
static int ssl_set_error(SSL *ssl, int error)
{
@@ -445,9 +466,25 @@ int openssl_connect(git_stream *stream)
st->connected = true;
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
bio = BIO_new(&git_stream_bio_method);
+#else
+ git_stream_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK | BIO_get_new_index(), "git_stream");
+ BIO_meth_set_write(git_stream_bio_method, bio_write);
+ BIO_meth_set_read(git_stream_bio_method, bio_read);
+ BIO_meth_set_puts(git_stream_bio_method, bio_puts);
+ BIO_meth_set_gets(git_stream_bio_method, bio_gets);
+ BIO_meth_set_ctrl(git_stream_bio_method, bio_ctrl);
+ BIO_meth_set_create(git_stream_bio_method, bio_create);
+ BIO_meth_set_destroy(git_stream_bio_method, bio_destroy);
+ bio = BIO_new(git_stream_bio_method);
+#endif
GITERR_CHECK_ALLOC(bio);
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
bio->ptr = st->io;
+#else
+ BIO_set_data(bio, st->io);
+#endif
SSL_set_bio(st->ssl, bio, bio);
/* specify the host in case SNI is needed */