Skip to content

Commit de33246

Browse files
authored
Merge pull request #331 from Faless/fix/https_ca_certs
Load Godot CA certs in libgit2
2 parents a79f3d3 + ff12736 commit de33246

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

build_profile.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"enabled_classes": [
33
"OS",
44
"EditorVCSInterface",
5+
"ProjectSettings",
6+
"FileAccess",
7+
"DirAccess",
58
"Window"
69
]
710
}

godot-git-plugin/src/git_plugin.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include <git2/tree.h>
66
#include "godot_cpp/core/class_db.hpp"
77
#include "godot_cpp/classes/file_access.hpp"
8+
#include "godot_cpp/classes/dir_access.hpp"
9+
#include "godot_cpp/classes/os.hpp"
10+
#include "godot_cpp/classes/project_settings.hpp"
811
#include "godot_cpp/variant/utility_functions.hpp"
912

1013
#define GIT2_CALL(error, msg) \
@@ -701,6 +704,22 @@ bool GitPlugin::_initialize(const godot::String &project_path) {
701704
create_gitignore_and_gitattributes();
702705
}
703706

707+
// We need to create a temporary file to load the CA from (libgit2 does not support loading certificates from string or raw pem).
708+
const String cafile = ProjectSettings::get_singleton()->globalize_path("res://.godot/git-cas" + OS::get_singleton()->get_entropy(8).hex_encode() + ".crt");
709+
godot::Ref<godot::FileAccess> file = godot::FileAccess::open(cafile, godot::FileAccess::WRITE_READ);
710+
if (file.is_null()) {
711+
return false;
712+
}
713+
file->store_buffer(OS::get_singleton()->get_system_ca_certificates().to_utf8_buffer());
714+
file->close();
715+
int error = git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, cafile.utf8().get_data(), NULL);
716+
DirAccess::remove_absolute(cafile); // Always remove the file
717+
if (unlikely(error)) {
718+
ERR_PRINT("GitPlugin: Failed to load CA bundle: " + cafile + ", error: " + itos(error));
719+
} else {
720+
godot::UtilityFunctions::print("GitPlugin: Loaded system CA certificates");
721+
}
722+
704723
return true;
705724
}
706725

0 commit comments

Comments
 (0)