mirror of
https://github.com/godotengine/godot
synced 2024-09-05 05:38:35 +00:00
Generalize SSL cert reading from file
This commit is contained in:
parent
d97c45ad2e
commit
490dd9f946
|
@ -29,6 +29,8 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#include "stream_peer_ssl.h"
|
#include "stream_peer_ssl.h"
|
||||||
|
#include "os/file_access.h"
|
||||||
|
#include "project_settings.h"
|
||||||
|
|
||||||
StreamPeerSSL *(*StreamPeerSSL::_create)() = NULL;
|
StreamPeerSSL *(*StreamPeerSSL::_create)() = NULL;
|
||||||
|
|
||||||
|
@ -50,6 +52,35 @@ bool StreamPeerSSL::is_available() {
|
||||||
return available;
|
return available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolByteArray StreamPeerSSL::get_project_cert_array() {
|
||||||
|
|
||||||
|
PoolByteArray out;
|
||||||
|
String certs_path = GLOBAL_DEF("network/ssl/certificates", "");
|
||||||
|
ProjectSettings::get_singleton()->set_custom_property_info("network/ssl/certificates", PropertyInfo(Variant::STRING, "network/ssl/certificates", PROPERTY_HINT_FILE, "*.crt"));
|
||||||
|
|
||||||
|
if (certs_path != "") {
|
||||||
|
|
||||||
|
FileAccess *f = FileAccess::open(certs_path, FileAccess::READ);
|
||||||
|
if (f) {
|
||||||
|
int flen = f->get_len();
|
||||||
|
out.resize(flen + 1);
|
||||||
|
{
|
||||||
|
PoolByteArray::Write w = out.write();
|
||||||
|
f->get_buffer(w.ptr(), flen);
|
||||||
|
w[flen] = 0; //end f string
|
||||||
|
}
|
||||||
|
|
||||||
|
memdelete(f);
|
||||||
|
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
print_line("Loaded certs from '" + certs_path);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
void StreamPeerSSL::_bind_methods() {
|
void StreamPeerSSL::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll);
|
ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll);
|
||||||
|
|
|
@ -66,6 +66,7 @@ public:
|
||||||
|
|
||||||
static StreamPeerSSL *create();
|
static StreamPeerSSL *create();
|
||||||
|
|
||||||
|
static PoolByteArray get_project_cert_array();
|
||||||
static void load_certs_from_memory(const PoolByteArray &p_memory);
|
static void load_certs_from_memory(const PoolByteArray &p_memory);
|
||||||
static bool is_available();
|
static bool is_available();
|
||||||
|
|
||||||
|
|
|
@ -293,28 +293,10 @@ void StreamPeerMbedTLS::initialize_ssl() {
|
||||||
mbedtls_debug_set_threshold(1);
|
mbedtls_debug_set_threshold(1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String certs_path = GLOBAL_DEF("network/ssl/certificates", "");
|
PoolByteArray cert_array = StreamPeerSSL::get_project_cert_array();
|
||||||
ProjectSettings::get_singleton()->set_custom_property_info("network/ssl/certificates", PropertyInfo(Variant::STRING, "network/ssl/certificates", PROPERTY_HINT_FILE, "*.crt"));
|
|
||||||
|
|
||||||
if (certs_path != "") {
|
if (cert_array.size() > 0)
|
||||||
|
_load_certs(cert_array);
|
||||||
FileAccess *f = FileAccess::open(certs_path, FileAccess::READ);
|
|
||||||
if (f) {
|
|
||||||
PoolByteArray arr;
|
|
||||||
int flen = f->get_len();
|
|
||||||
arr.resize(flen + 1);
|
|
||||||
{
|
|
||||||
PoolByteArray::Write w = arr.write();
|
|
||||||
f->get_buffer(w.ptr(), flen);
|
|
||||||
w[flen] = 0; //end f string
|
|
||||||
}
|
|
||||||
|
|
||||||
memdelete(f);
|
|
||||||
|
|
||||||
_load_certs(arr);
|
|
||||||
print_line("Loaded certs from '" + certs_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
available = true;
|
available = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,6 @@
|
||||||
#define STREAM_PEER_OPEN_SSL_H
|
#define STREAM_PEER_OPEN_SSL_H
|
||||||
|
|
||||||
#include "io/stream_peer_ssl.h"
|
#include "io/stream_peer_ssl.h"
|
||||||
#include "os/file_access.h"
|
|
||||||
#include "project_settings.h"
|
|
||||||
|
|
||||||
#include "mbedtls/config.h"
|
#include "mbedtls/config.h"
|
||||||
#include "mbedtls/ctr_drbg.h"
|
#include "mbedtls/ctr_drbg.h"
|
||||||
|
|
Loading…
Reference in a new issue