-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Support mbedTLS #3935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support mbedTLS #3935
Changes from all commits
04a2b1d
cfc27a3
d44d020
a5958d0
ad2b2e2
101ab46
46db15f
369d23a
4f8968b
cc156e4
f814681
6b556a6
a47a6bc
05ca19a
77cdc58
dab8d43
81555f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# - Try to find mbedTLS | ||
# Once done this will define | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this file at all, do we? Our CMake script relies on pkg-config rather than trying to guess where it might be installed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mbed-TLS/mbedtls#228, so not yet 😉 |
||
# | ||
# Read-Only variables | ||
# MBEDTLS_FOUND - system has mbedTLS | ||
# MBEDTLS_INCLUDE_DIR - the mbedTLS include directory | ||
# MBEDTLS_LIBRARY_DIR - the mbedTLS library directory | ||
# MBEDTLS_LIBRARIES - Link these to use mbedTLS | ||
# MBEDTLS_LIBRARY - path to mbedTLS library | ||
# MBEDX509_LIBRARY - path to mbedTLS X.509 library | ||
# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library | ||
|
||
FIND_PATH(MBEDTLS_INCLUDE_DIR mbedtls/version.h) | ||
|
||
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) | ||
# Already in cache, be silent | ||
SET(MBEDTLS_FIND_QUIETLY TRUE) | ||
ENDIF() | ||
|
||
FIND_LIBRARY(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509) | ||
FIND_LIBRARY(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509) | ||
FIND_LIBRARY(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto) | ||
|
||
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) | ||
SET(MBEDTLS_FOUND TRUE) | ||
ENDIF() | ||
|
||
IF(MBEDTLS_FOUND) | ||
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config | ||
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH) | ||
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) | ||
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) | ||
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE) | ||
STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) | ||
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) | ||
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) | ||
SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") | ||
|
||
IF(NOT MBEDTLS_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found mbedTLS:") | ||
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) | ||
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) | ||
IF (MBEDTLSMATCH) | ||
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) | ||
MESSAGE(STATUS " version ${MBEDTLS_VERSION}") | ||
ENDIF(MBEDTLSMATCH) | ||
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}") | ||
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}") | ||
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") | ||
ENDIF(NOT MBEDTLS_FIND_QUIETLY) | ||
ELSE(MBEDTLS_FOUND) | ||
IF(MBEDTLS_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find mbedTLS") | ||
ENDIF(MBEDTLS_FIND_REQUIRED) | ||
ENDIF(MBEDTLS_FOUND) | ||
|
||
MARK_AS_ADVANCED( | ||
MBEDTLS_INCLUDE_DIR | ||
MBEDTLS_LIBRARY_DIR | ||
MBEDTLS_LIBRARIES | ||
MBEDTLS_LIBRARY | ||
MBEDX509_LIBRARY | ||
MBEDCRYPTO_LIBRARY | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,14 @@ curl -L https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy | |
# Run this early so we know it's ready by the time we need it | ||
java -jar poxyproxy.jar -d --port 8080 --credentials foo:bar & | ||
|
||
if [ -n "$MBEDTLS" ]; | ||
then | ||
./script/mbedtls.sh; | ||
CMAKE_INCLUDE_PATH=../mbedtls/include | ||
CMAKE_LIBRARY_PATH=../mbedtls/library | ||
export CMAKE_INCLUDE_PATH CMAKE_LIBRARY_PATH | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be part of the script that installs the dependencies. The Travis rules currently only do it for osx, but we should remove the |
||
|
||
mkdir _build | ||
cd _build | ||
# shellcheck disable=SC2086 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
git clone https://github.com/ARMmbed/mbedtls.git mbedtls | ||
cd mbedtls | ||
git checkout mbedtls-2.1.2 | ||
make CFLAGS='-fPIC -fpic' -j2 lib |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,11 @@ | |
#include "sysdir.h" | ||
#include "filter.h" | ||
#include "merge_driver.h" | ||
#ifdef GIT_OPENSSL | ||
#include "openssl_stream.h" | ||
#elif GIT_MBEDTLS | ||
#include "mbedtls_stream.h" | ||
#endif | ||
#include "thread-utils.h" | ||
#include "git2/global.h" | ||
#include "transports/ssh.h" | ||
|
@@ -61,8 +65,13 @@ static int init_common(void) | |
(ret = git_sysdir_global_init()) == 0 && | ||
(ret = git_filter_global_init()) == 0 && | ||
(ret = git_merge_driver_global_init()) == 0 && | ||
(ret = git_transport_ssh_global_init()) == 0 && | ||
(ret = git_openssl_stream_global_init()) == 0) | ||
(ret = git_transport_ssh_global_init()) == 0 | ||
#ifdef GIT_OPENSSL | ||
&& (ret = git_openssl_stream_global_init()) == 0 | ||
#elif GIT_MBEDTLS | ||
&& (ret = git_mbedtls_stream_global_init()) == 0 | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We didn't need to ifdef-away the OpenSSL stream init, and we definitely shouldn't need it now. If there is no mbedtls, its init function should no-op. We define an interface and program against it. |
||
) | ||
ret = git_mwindow_global_init(); | ||
|
||
GIT_MEMORY_BARRIER; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,12 @@ typedef struct { | |
extern SSL_CTX *git__ssl_ctx; | ||
#endif | ||
|
||
#ifdef GIT_MBEDTLS | ||
# include "mbedtls/platform.h" | ||
# include "mbedtls/ssl.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these specified as relative imports? Why woldn't |
||
extern mbedtls_ssl_config *git__ssl_conf; | ||
#endif | ||
|
||
git_global_st *git__global_state(void); | ||
|
||
extern git_mutex git__mwindow_mutex; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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 "common.h" | ||
#include "hash.h" | ||
#include "hash/hash_mbedtls.h" | ||
|
||
void git_hash_ctx_cleanup(git_hash_ctx *ctx) | ||
{ | ||
assert(ctx); | ||
mbedtls_sha1_free(&ctx->c); | ||
} | ||
|
||
int git_hash_init(git_hash_ctx *ctx) | ||
{ | ||
assert(ctx); | ||
mbedtls_sha1_init(&ctx->c); | ||
mbedtls_sha1_starts(&ctx->c); | ||
return 0; | ||
} | ||
|
||
int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) | ||
{ | ||
assert(ctx); | ||
mbedtls_sha1_update(&ctx->c, data, len); | ||
return 0; | ||
} | ||
|
||
int git_hash_final(git_oid *out, git_hash_ctx *ctx) | ||
{ | ||
assert(ctx); | ||
mbedtls_sha1_finish(&ctx->c, out->id); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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_hash_mbedtld_h__ | ||
#define INCLUDE_hash_mbedtld_h__ | ||
|
||
#include <mbedtls/sha1.h> | ||
|
||
struct git_hash_ctx { | ||
mbedtls_sha1_context c; | ||
}; | ||
|
||
#define git_hash_global_init() 0 | ||
#define git_hash_ctx_init(ctx) git_hash_init(ctx) | ||
|
||
#endif /* INCLUDE_hash_mbedtld_h__ */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The line ending is missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is amiga relevant? wonder why openssl is gated on
NOT AMIGA
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. @sba1 made that change in commit c57c4af.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that it is relevant for the Amiga port right now.
However, the identification of OpenSSL is disabled on Amiga, because FIND_PACKAGE produced wrong results when cross compiling (it added wrong (i.e., native) include paths), at least, if I remember it correctly. Instead, it is assumed that OpenSSL is available on this platform in the (cross) compiler's standard include path and libgit2 is only statically linked.
In essence, special care for Amiga doesn't need to be done in new stuff. From time to time, I'll take care of it and submit pull requests.