Skip to content

Commit

Permalink
Abstract away the TLS stream implementation
Browse files Browse the repository at this point in the history
Instead, provide git_tls_stream_new() to ask for the most appropriate
encrypted stream and use it in our HTTP transport.
  • Loading branch information
carlosmn committed Mar 18, 2015
1 parent 43be1ad commit 5d46db3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/tls_stream.c
@@ -0,0 +1,21 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/

#include "openssl_stream.h"
#include "stransport_stream.h"

int git_tls_stream_new(git_stream **out, const char *host, const char *port)
{
#ifdef GIT_SECURE_TRANSPORT
return git_stransport_stream_new(out, host, port);
#elif defined(GIT_SSL)
return git_openssl_stream_new(out, host, port);
#else
giterr_set(GITERR_SSL, "there is no TLS stream available");
return -1;
#endif
}
21 changes: 21 additions & 0 deletions src/tls_stream.h
@@ -0,0 +1,21 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_tls_stream_h__
#define INCLUDE_tls_stream_h__

#include "git2/sys/stream.h"

/**
* Create a TLS stream with the most appropriate backend available for
* the current platform.
*
* This allows us to ask for a SecureTransport or OpenSSL stream
* according to being on general Unix vs OS X.
*/
extern int git_tls_stream_new(git_stream **out, const char *host, const char *port);

#endif
4 changes: 2 additions & 2 deletions src/transports/http.c
Expand Up @@ -13,7 +13,7 @@
#include "smart.h"
#include "auth.h"
#include "auth_negotiate.h"
#include "openssl_stream.h"
#include "tls_stream.h"
#include "socket_stream.h"

git_http_auth_scheme auth_schemes[] = {
Expand Down Expand Up @@ -545,7 +545,7 @@ static int http_connect(http_subtransport *t)
}

if (t->connection_data.use_ssl) {
error = git_openssl_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
error = git_tls_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
} else {
error = git_socket_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
}
Expand Down

0 comments on commit 5d46db3

Please sign in to comment.