Skip to content

Commit 6a21884

Browse files
committed
Use mbedTLS instead of OpenSSL
1 parent de33246 commit 6a21884

15 files changed

Lines changed: 328 additions & 344 deletions

File tree

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
[submodule "thirdparty/ssh2/libssh2"]
1010
path = thirdparty/ssh2/libssh2
1111
url = https://github.com/libssh2/libssh2
12-
[submodule "thirdparty/openssl"]
13-
path = thirdparty/openssl
14-
url = https://github.com/openssl/openssl
12+
[submodule "thirdparty/mbedtls"]
13+
path = thirdparty/mbedtls
14+
url = https://github.com/Mbed-TLS/mbedtls.git

SConstruct

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ env.__class__.msvc = env.get("is_msvc", False)
2929
if env["platform"] == "windows" and env.get("is_msvc", False):
3030
env.AppendUnique(LINKFLAGS=["/LTCG"])
3131

32-
# OpenSSL Builder
33-
env.Tool("openssl", toolpath=["tools"])
34-
35-
# SSH2 Builder
3632
env.Tool("cmake", toolpath=["tools"])
33+
env.Tool("mbedtls", toolpath=["tools"])
3734
env.Tool("ssh2", toolpath=["tools"])
3835
env.Tool("git2", toolpath=["tools"])
3936

4037
opts.Update(env)
4138

42-
ssl = env.OpenSSL()
39+
env["MBEDTLS_CONFIG"] = env.File("godot-git-plugin/include/std_mbedtls_config.h").abspath
40+
env["MBEDTLS_THREADING_ALT"] = env.File("godot-git-plugin/include/threading_alt.h").abspath
41+
42+
ssl = env.BuildMbedTLS()
4343
ssh2 = env.BuildSSH2(ssl)
4444
ssl += ssh2
4545
git2 = env.BuildGIT2(ssl)

THIRDPARTY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ The Godot Git Plugin source code uses the following third-party source code:
44

55
1. godotengine/godot-cpp - MIT License - https://github.com/godotengine/godot-cpp/tree/58d1de720b8ffe9f8ffcdfe3a85148582cfd2e74
66
2. libgit2/libgit2 - GPLv2 with a special Linking Exception - https://github.com/libgit2/libgit2/tree/26055f5af74ab1cf636d272e8a34315496d3f06f
7-
3. libssh2/libssh2 - BSD-3-Clause License - https://github.com/libssh2/libssh2/tree/635caa90787220ac3773c1d5ba11f1236c22eae8
8-
4. openssl - OpenSSL License - https://github.com/openssl/openssl/tree/aae016bfd52fcad2bc9657c2c782cfdf73b1ed5f
7+
3. libssh2/libssh2 - BSD-3-Clause License - https://github.com/libssh2/libssh2/tree/a312b43325e3383c865a87bb1d26cb52e3292641
8+
4. mbedTLS - OpenSSL License - https://github.com/Mbed-TLS/mbedtls/tree/068ff080b369adfac81509f9b57b2afabaf82dc5
99

1010
## License Texts
1111

godot-git-plugin/SCsub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ if env["platform"] == "macos":
2222
env["macos_deployment_target"]])
2323
elif env["platform"] == "windows":
2424
env.Append(LIBS=["advapi32", "winhttp", "rpcrt4", "crypt32",
25-
"ole32", "user32", "wsock32", "ws2_32", "bcrypt"])
25+
"ole32", "user32", "wsock32", "ws2_32", "bcrypt", "secur32"])
2626

27-
env.Append(CPPPATH=[".", "src/"])
27+
env.Append(CPPPATH=[".", "include/", "src/"])
2828

2929
env.Append(CPPPATH=["#thirdparty/git2/libgit2/include/"])
3030

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**************************************************************************/
2+
/* std_mbedtls_config.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#pragma once
32+
33+
// Include default mbedTLS config.
34+
#include <mbedtls/mbedtls_config.h>
35+
36+
#define MBEDTLS_THREADING_C
37+
#define MBEDTLS_THREADING_ALT
38+
#define MBEDTLS_NO_PLATFORM_ENTROPY
39+
#define MBEDTLS_ENTROPY_HARDWARE_ALT
40+
41+
// Hack to fix libgit2 trying to load invalid certificates (hardcoded at built times).
42+
#ifdef GIT_DEFAULT_CERT_LOCATION
43+
#undef GIT_DEFAULT_CERT_LOCATION
44+
#endif
45+
#define GIT_DEFAULT_CERT_LOCATION NULL
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**************************************************************************/
2+
/* threading_alt.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#pragma once
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
typedef struct {
38+
void *mutex;
39+
} mbedtls_threading_mutex_t;
40+
41+
// MbedTLS 3.x compat
42+
typedef mbedtls_threading_mutex_t mbedtls_platform_mutex_t;
43+
#define MBEDTLS_ERR_THREADING_USAGE_ERROR MBEDTLS_ERR_THREADING_MUTEX_ERROR
44+
45+
#ifdef __cplusplus
46+
};
47+
#endif

godot-git-plugin/src/gdlibrary.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@
33
#include "godot_cpp/core/class_db.hpp"
44
#include "godot_cpp/godot.hpp"
55

6+
extern "C" {
7+
int std_mbedtls_platform_init();
8+
void std_mbedtls_platform_free();
9+
}
10+
611
void initialize_git_plugin_module(godot::ModuleInitializationLevel p_level) {
712
if (p_level != godot::MODULE_INITIALIZATION_LEVEL_EDITOR) {
813
return;
914
}
1015

16+
int ret = std_mbedtls_platform_init();
17+
if (ret) {
18+
ERR_PRINT("GitPlugin: Failed to initialize SSL library");
19+
return;
20+
}
1121
godot::ClassDB::register_class<GitPlugin>();
1222
}
1323

1424
void uninitialize_git_plugin_module(godot::ModuleInitializationLevel p_level) {
1525
if (p_level != godot::MODULE_INITIALIZATION_LEVEL_EDITOR) {
1626
return;
1727
}
28+
std_mbedtls_platform_free();
1829
}
1930

2031
extern "C" {
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**************************************************************************/
2+
/* std_mbedtls_platform.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include <godot_cpp/classes/os.hpp>
32+
33+
#include <mbedtls/build_info.h>
34+
#include <mbedtls/threading.h>
35+
#include <psa/crypto.h>
36+
37+
#include <mutex>
38+
39+
#if !defined(MBEDTLS_THREADING_C)
40+
#error "Godot Git Plugin require mbedTLS with threading support"
41+
#endif
42+
43+
using namespace godot;
44+
45+
extern "C" {
46+
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
47+
int mbedtls_hardware_poll(void *p_data, unsigned char *r_output, size_t p_output_size, size_t *r_output_len) {
48+
*r_output_len = 0;
49+
ERR_FAIL_NULL_V(OS::get_singleton(), -1);
50+
PackedByteArray rnd = OS::get_singleton()->get_entropy(p_output_size);
51+
ERR_FAIL_COND_V(rnd.size() != p_output_size, -1);
52+
memcpy(r_output, rnd.ptr(), p_output_size);
53+
*r_output_len = p_output_size;
54+
return 0;
55+
}
56+
57+
#endif
58+
#if defined(MBEDTLS_THREADING_ALT)
59+
void std_mbedtls_mutex_init(mbedtls_platform_mutex_t *p_mutex) {
60+
if (p_mutex == nullptr) {
61+
return;
62+
}
63+
p_mutex->mutex = new std::mutex();
64+
}
65+
66+
void std_mbedtls_mutex_free(mbedtls_platform_mutex_t *p_mutex) {
67+
if (p_mutex == nullptr || p_mutex->mutex == nullptr) {
68+
return;
69+
}
70+
delete ((std::mutex *)p_mutex->mutex);
71+
}
72+
73+
int std_mbedtls_mutex_lock(mbedtls_platform_mutex_t *p_mutex) {
74+
if (p_mutex == nullptr || p_mutex->mutex == nullptr) {
75+
return MBEDTLS_ERR_THREADING_USAGE_ERROR;
76+
}
77+
((std::mutex *)p_mutex->mutex)->lock();
78+
return 0;
79+
}
80+
81+
int std_mbedtls_mutex_unlock(mbedtls_platform_mutex_t *p_mutex) {
82+
if (p_mutex == nullptr || p_mutex->mutex == nullptr) {
83+
return MBEDTLS_ERR_THREADING_USAGE_ERROR;
84+
}
85+
((std::mutex *)p_mutex->mutex)->unlock();
86+
return 0;
87+
}
88+
#endif
89+
int std_mbedtls_platform_init() {
90+
#if defined(MBEDTLS_THREADING_ALT)
91+
mbedtls_threading_set_alt(
92+
std_mbedtls_mutex_init,
93+
std_mbedtls_mutex_free,
94+
std_mbedtls_mutex_lock,
95+
std_mbedtls_mutex_unlock);
96+
#endif
97+
return psa_crypto_init();
98+
}
99+
void std_mbedtls_platform_free() {
100+
#if defined(MBEDTLS_THREADING_ALT)
101+
mbedtls_threading_free_alt();
102+
#endif
103+
}
104+
};

thirdparty/mbedtls

Submodule mbedtls added at 068ff08

thirdparty/openssl

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)