diff options
Diffstat (limited to 'drivers/openssl/stream_peer_openssl.cpp')
-rw-r--r-- | drivers/openssl/stream_peer_openssl.cpp | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/drivers/openssl/stream_peer_openssl.cpp b/drivers/openssl/stream_peer_openssl.cpp index 81795fdc60..aad3a11b7e 100644 --- a/drivers/openssl/stream_peer_openssl.cpp +++ b/drivers/openssl/stream_peer_openssl.cpp @@ -532,8 +532,26 @@ StreamPeerSSL* StreamPeerOpenSSL::_create_func() { Vector<X509*> StreamPeerOpenSSL::certs; +void StreamPeerOpenSSL::_load_certs(const ByteArray& p_array) { + + ByteArray::Read r = p_array.read(); + BIO* mem = BIO_new(BIO_s_mem()); + BIO_puts(mem,(const char*)r.ptr()); + while(true) { + X509*cert = PEM_read_bio_X509(mem, NULL, 0, NULL); + if (!cert) + break; + certs.push_back(cert); + } + BIO_free(mem); +} + void StreamPeerOpenSSL::initialize_ssl() { + available=true; + + load_certs_func=_load_certs; + _create=_create_func; CRYPTO_malloc_init(); // Initialize malloc, free, etc for OpenSSL's use SSL_library_init(); // Initialize OpenSSL's SSL libraries @@ -544,20 +562,24 @@ void StreamPeerOpenSSL::initialize_ssl() { Globals::get_singleton()->set_custom_property_info("ssl/certificates",PropertyInfo(Variant::STRING,"ssl/certificates",PROPERTY_HINT_FILE,"*.crt")); if (certs_path!="") { - Vector<uint8_t> data = FileAccess::get_file_as_array(certs_path);; - if (data.size()) { - data.push_back(0); - BIO* mem = BIO_new(BIO_s_mem()); - BIO_puts(mem,(const char*) data.ptr()); - while(true) { - X509*cert = PEM_read_bio_X509(mem, NULL, 0, NULL); - if (!cert) - break; - certs.push_back(cert); + + + FileAccess *f=FileAccess::open(certs_path,FileAccess::READ); + if (f) { + ByteArray arr; + int flen = f->get_len(); + arr.resize(flen+1); + { + ByteArray::Write w = arr.write(); + f->get_buffer(w.ptr(),flen); + w[flen]=0; //end f string } - BIO_free(mem); + + memdelete(f); + + _load_certs(arr); + print_line("Loaded certs from '"+certs_path+"': "+itos(certs.size())); } - print_line("Loaded certs from '"+certs_path+"': "+itos(certs.size())); } String config_path =GLOBAL_DEF("ssl/config",""); Globals::get_singleton()->set_custom_property_info("ssl/config",PropertyInfo(Variant::STRING,"ssl/config",PROPERTY_HINT_FILE,"*.cnf")); |