-
Notifications
You must be signed in to change notification settings - Fork 2.5k
mbedTLS support #4173
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
Merged
Merged
mbedTLS support #4173
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ca3b223
mbedtls: initial support
tiennou 1a1875f
mbedtls: proper certificate verification
tiennou 6c6be3c
mbedtls: use libmbedcrypto for hashing
tiennou 60e1ad9
mbedtls: add global initialization
tiennou 2419ccc
mbedtls: default cipher list support
tiennou ec79b0f
mbedtls: fix libgit2 hanging due to incomplete writes
tiennou 262dfcf
mbedtls: enable Travis CI tests
tiennou 4165bb7
mbedtls: use our own certificate validation
tiennou 1edde0b
mbedtls: use mbedTLS certificate verification
tiennou 382ed1e
mbedtls: load default CA certificates
tiennou b3e0280
mbedtls: display error codes as hex for consistency with mbedTLS docs
tiennou e3d764a
tests: clarify comment
tiennou 5455475
cmake: make our preferred backend ordering consistent
tiennou 10aff3d
travis: just grab what we need from mbedtls
tiennou cb2da47
travis: pass -fPIC when configuring mbedtls
tiennou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# - Try to find mbedTLS | ||
# Once done this will define | ||
# | ||
# 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 | ||
# | ||
# Hint | ||
# MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation. | ||
|
||
SET(_MBEDTLS_ROOT_HINTS | ||
${MBEDTLS_ROOT_DIR} | ||
ENV MBEDTLS_ROOT_DIR | ||
) | ||
|
||
SET(_MBEDTLS_ROOT_HINTS_AND_PATHS | ||
HINTS ${_MBEDTLS_ROOT_HINTS} | ||
PATHS ${_MBEDTLS_ROOT_PATHS} | ||
) | ||
|
||
FIND_PATH(MBEDTLS_INCLUDE_DIR | ||
NAMES mbedtls/version.h | ||
${_MBEDTLS_ROOT_HINTS_AND_PATHS} | ||
PATH_SUFFIXES include | ||
) | ||
|
||
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 | ||
${_MBEDTLS_ROOT_HINTS_AND_PATHS} | ||
PATH_SUFFIXES library | ||
) | ||
FIND_LIBRARY(MBEDX509_LIBRARY | ||
NAMES mbedx509 libmbedx509 | ||
${_MBEDTLS_ROOT_HINTS_AND_PATHS} | ||
PATH_SUFFIXES library | ||
) | ||
FIND_LIBRARY(MBEDCRYPTO_LIBRARY | ||
NAMES mbedcrypto libmbedcrypto | ||
${_MBEDTLS_ROOT_HINTS_AND_PATHS} | ||
PATH_SUFFIXES library | ||
) | ||
|
||
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 | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
set -x | ||
|
||
if [ "$MBEDTLS" ]; then | ||
git clone --depth 10 --single-branch --branch mbedtls-2.6.1 https://github.com/ARMmbed/mbedtls.git ./deps/mbedtls | ||
cd ./deps/mbedtls | ||
# We pass -fPIC explicitely because we'll include it in libgit2.so | ||
CFLAGS=-fPIC cmake -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . | ||
cmake --build . | ||
|
||
echo "mbedTLS built in `pwd`" | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The comment for
USE_HTTPS
says that you can set it to the name of the backend that you want to use. I don't think that's true, but it would be nice if it was.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.
It does though. If you pass
ON
, this will use "autodetection" (a.k.a. use whatever backend we've found and is first in the following tests), Otherwise, this will be passed verbatim asHTTPS_BACKEND
, which is handled just below (and will error if you passed nonsense).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.
Yep, rereading, I see it now. Thanks!