Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/libs/prx/libSceLibreSsl3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_library(libSceLibreSsl3 SHARED EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/
target_include_directories(libSceLibreSsl3 PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(libSceLibreSsl3 PRIVATE libSceLibreSsl libc)
configure_windows_unwind(libSceLibreSsl3)
target_sources(libSceLibreSsl3 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/Ssl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/X509.cpp)

target_sources(libSceLibreSsl3 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/AdditionalExports.cpp)
target_sources(libSceLibreSsl3 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/Stack.cpp)
Expand Down Expand Up @@ -140,6 +141,16 @@ if(BUILD_TESTING)
configure_windows_unwind(guest_libressl3_key_reference_tests)
add_test(NAME guest_libressl3_key_reference COMMAND guest_libressl3_key_reference_tests)
set_tests_properties(guest_libressl3_key_reference PROPERTIES TIMEOUT 20)
add_test_executable(guest_libressl3_ssl_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibreSsl3Ssl.cpp)
target_include_directories(guest_libressl3_ssl_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libressl3_ssl_tests PRIVATE libSceLibreSsl3 libSceLibreSsl)
configure_windows_unwind(guest_libressl3_ssl_tests)
add_test(NAME guest_libressl3_ssl COMMAND guest_libressl3_ssl_tests)
set_tests_properties(guest_libressl3_ssl PROPERTIES TIMEOUT 20)
if(WIN32)
set_tests_properties(guest_libressl3_ssl PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibreSsl3>")
endif()
add_test_executable(guest_libressl3_evp_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibreSsl3Evp.cpp)
target_include_directories(guest_libressl3_evp_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libressl3_evp_tests PRIVATE libSceLibreSsl3 libc)
Expand Down
40 changes: 0 additions & 40 deletions core/libs/prx/libSceLibreSsl3/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,36 +206,6 @@ int APS5_VABI SSL_CTX_clear_chain_certs_nid_postfix(void) {
return 0;
}

int APS5_VABI SSL_CTX_set_max_proto_version_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI SSL_CTX_set_min_proto_version_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI SSL_CTX_up_ref_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI SSL_SESSION_up_ref_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI SSL_get_client_random_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI SSL_up_ref_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI X509_STORE_CTX_free_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
Expand All @@ -256,16 +226,6 @@ int APS5_VABI X509_STORE_up_ref_nid_postfix(void) {
return 0;
}

int APS5_VABI X509_get_version_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI X509_up_ref_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI d2i_ECParameters_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
Expand Down
18 changes: 10 additions & 8 deletions core/libs/prx/libSceLibreSsl3/include/Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "SceTypes.hpp"
#include "EvpDigest.hpp"
#include "prx/libSceLibreSsl3/include/Key.hpp"
#include "prx/libSceLibreSsl3/include/Ssl.hpp"
#include "prx/libSceLibreSsl3/include/X509.hpp"
#include "prx/libSceLibreSsl/include/Api.hpp"
#include "prx/libSceLibreSsl3/include/Cipher.hpp"

Expand Down Expand Up @@ -172,12 +174,12 @@ int APS5_VABI RSA_padding_add_PKCS1_PSS_mgf1_nid_postfix(void);
int APS5_VABI RSA_up_ref_nid_postfix(LibreSsl3Rsa* rsa);
int APS5_VABI SSL_CTX_add0_chain_cert_nid_postfix(void);
int APS5_VABI SSL_CTX_clear_chain_certs_nid_postfix(void);
int APS5_VABI SSL_CTX_set_max_proto_version_nid_postfix(void);
int APS5_VABI SSL_CTX_set_min_proto_version_nid_postfix(void);
int APS5_VABI SSL_CTX_up_ref_nid_postfix(void);
int APS5_VABI SSL_SESSION_up_ref_nid_postfix(void);
int APS5_VABI SSL_get_client_random_nid_postfix(void);
int APS5_VABI SSL_up_ref_nid_postfix(void);
int APS5_VABI SSL_CTX_set_max_proto_version_nid_postfix(LibreSsl3SslCtx* context, std::uint16_t version);
int APS5_VABI SSL_CTX_set_min_proto_version_nid_postfix(LibreSsl3SslCtx* context, std::uint16_t version);
int APS5_VABI SSL_CTX_up_ref_nid_postfix(LibreSsl3SslCtx* ctx);
int APS5_VABI SSL_SESSION_up_ref_nid_postfix(LibreSsl3SslSession* session);
std::size_t APS5_VABI SSL_get_client_random_nid_postfix(const LibreSsl3Ssl* ssl, unsigned char* out, std::size_t maxOut);
int APS5_VABI SSL_up_ref_nid_postfix(LibreSsl3Ssl* ssl);
int APS5_VABI X509_PUBKEY_get0_param_nid_postfix(void** publicKeyAlgorithm, const unsigned char** publicKey, int* publicKeyLength, void** algorithm, const void* pub);
int APS5_VABI X509_STORE_CTX_free_nid_postfix(void);
int APS5_VABI X509_STORE_CTX_init_nid_postfix(void);
Expand All @@ -189,10 +191,10 @@ const void* APS5_VABI X509_get0_notBefore_nid_postfix(const LibreSsl3ValidityX50
void APS5_VABI X509_get0_signature_nid_postfix(const void** signature, const void** algorithm, const LibreSsl3ValidityX509* certificate);
void* APS5_VABI X509_get_ext_nid_postfix(const LibreSsl3ExtensionsX509* certificate, int loc);
int APS5_VABI X509_get_ext_count_nid_postfix(const LibreSsl3ExtensionsX509* certificate);
int APS5_VABI X509_get_version_nid_postfix(void);
std::int64_t APS5_VABI X509_get_version_nid_postfix(const LibreSsl3X509* certificate);
void* APS5_VABI X509_getm_notAfter_nid_postfix(const LibreSsl3ValidityX509* certificate);
void* APS5_VABI X509_getm_notBefore_nid_postfix(const LibreSsl3ValidityX509* certificate);
int APS5_VABI X509_up_ref_nid_postfix(void);
int APS5_VABI X509_up_ref_nid_postfix(LibreSsl3X509* certificate);
void* APS5_VABI d2i_ASN1_INTEGER_nid_postfix(void** output, const unsigned char** input, std::int64_t length);
int APS5_VABI d2i_ECParameters_nid_postfix(void);
int APS5_VABI d2i_PKCS7_nid_postfix(void);
Expand Down
26 changes: 26 additions & 0 deletions core/libs/prx/libSceLibreSsl3/include/Key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,38 @@ struct LibreSsl3Rsa {
void* mtBlinding;
};

struct LibreSsl3SslCtx {
const void* method;
const void* quicMethod;
void* cipherList;
void* certStore;
std::int64_t sessionTimeout;
std::int32_t references;
void* extraCerts;
std::int32_t verifyMode;
std::uint64_t sidCtxLength;
unsigned char sidCtx[32];
void* param;
void* defaultPasswdCallback;
void* defaultPasswdCallbackUserdata;
std::uint16_t minTlsVersion;
std::uint16_t maxTlsVersion;
std::uint16_t minProtoVersion;
std::uint16_t maxProtoVersion;
};

static_assert(sizeof(LibreSsl3EvpPkey) == 32);
static_assert(offsetof(LibreSsl3EvpPkey, references) == 4);
static_assert(sizeof(LibreSsl3EcKey) == 64);
static_assert(offsetof(LibreSsl3EcKey, references) == 48);
static_assert(sizeof(LibreSsl3Rsa) == 152);
static_assert(offsetof(LibreSsl3Rsa, references) == 104);
static_assert(sizeof(LibreSsl3SslCtx) == 136);
static_assert(offsetof(LibreSsl3SslCtx, references) == 40);
static_assert(offsetof(LibreSsl3SslCtx, minTlsVersion) == 128);
static_assert(offsetof(LibreSsl3SslCtx, maxTlsVersion) == 130);
static_assert(offsetof(LibreSsl3SslCtx, minProtoVersion) == 132);
static_assert(offsetof(LibreSsl3SslCtx, maxProtoVersion) == 134);
static_assert(offsetof(LibreSsl3Rsa, p) == 48);
static_assert(offsetof(LibreSsl3Rsa, q) == 56);
static_assert(offsetof(LibreSsl3Rsa, dmp1) == 64);
Expand Down
19 changes: 19 additions & 0 deletions core/libs/prx/libSceLibreSsl3/include/Reference.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <atomic>
#include <cstdint>
#include <limits>
#include <stdexcept>

static_assert(std::atomic_ref<std::int32_t>::required_alignment <= alignof(std::int32_t));

inline int Retain_nid_no_patch(std::int32_t& references) {
std::atomic_ref<std::int32_t> count(references);
auto previous = count.load();
for (;;) {
if (previous == std::numeric_limits<std::int32_t>::max())
throw std::overflow_error("LibreSSL3 reference count overflow");
if (count.compare_exchange_weak(previous, previous + 1))
return previous > 0;
}
}
70 changes: 70 additions & 0 deletions core/libs/prx/libSceLibreSsl3/include/Ssl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include "prx/libSceLibreSsl3/include/Key.hpp"

struct LibreSsl3SslMethod {
std::int32_t dtls;
std::int32_t server;
std::int32_t version;
std::uint16_t minTlsVersion;
std::uint16_t maxTlsVersion;
};

struct LibreSsl3Ssl3State {
std::int64_t flags;
unsigned char serverRandom[32];
unsigned char clientRandom[32];
};

struct LibreSsl3Ssl {
std::int32_t version;
const LibreSsl3SslMethod* method;
const void* quicMethod;
void* rbio;
void* wbio;
void* bbio;
std::int32_t server;
LibreSsl3Ssl3State* s3;
void* d1;
void* param;
void* cipherList;
void* cert;
std::uint64_t sidCtxLength;
unsigned char sidCtx[32];
void* session;
std::int32_t verifyMode;
std::int32_t error;
std::int32_t errorCode;
LibreSsl3SslCtx* ctx;
std::int64_t verifyResult;
std::int32_t references;
};

struct LibreSsl3SslSession {
std::int32_t sslVersion;
std::uint64_t masterKeyLength;
unsigned char masterKey[48];
std::uint64_t sessionIdLength;
unsigned char sessionId[32];
std::uint64_t sidCtxLength;
unsigned char sidCtx[32];
void* peerCert;
std::int32_t peerCertType;
std::int64_t verifyResult;
std::int64_t timeout;
std::int64_t time;
std::int32_t references;
};

static_assert(sizeof(LibreSsl3SslMethod) == 16);
static_assert(offsetof(LibreSsl3SslMethod, minTlsVersion) == 12);
static_assert(offsetof(LibreSsl3SslMethod, maxTlsVersion) == 14);
static_assert(sizeof(LibreSsl3Ssl3State) == 72);
static_assert(offsetof(LibreSsl3Ssl3State, clientRandom) == 40);
static_assert(sizeof(LibreSsl3Ssl) == 184);
static_assert(offsetof(LibreSsl3Ssl, s3) == 56);
static_assert(offsetof(LibreSsl3Ssl, references) == 176);
static_assert(sizeof(LibreSsl3SslSession) == 192);
static_assert(offsetof(LibreSsl3SslSession, references) == 184);
21 changes: 21 additions & 0 deletions core/libs/prx/libSceLibreSsl3/include/X509.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include "prx/libSceLibreSsl/include/Api.hpp"

struct LibreSsl3X509CertInfo {
Asn1String* version;
};

struct LibreSsl3X509 {
LibreSsl3X509CertInfo* certInfo;
void* sigAlg;
void* signature;
std::int32_t valid;
std::int32_t references;
};

static_assert(sizeof(LibreSsl3X509CertInfo) == 8);
static_assert(sizeof(LibreSsl3X509) == 32);
static_assert(offsetof(LibreSsl3X509, references) == 28);
26 changes: 7 additions & 19 deletions core/libs/prx/libSceLibreSsl3/src/Key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,10 @@
*/

#include "prx/libSceLibreSsl3/libSceLibreSsl3.hpp"
#include "prx/libSceLibreSsl3/include/Reference.hpp"

#include <atomic>
#include <limits>
#include <stdexcept>

namespace {

static_assert(std::atomic_ref<std::int32_t>::required_alignment <= alignof(std::int32_t));

int Retain_nid_no_patch(std::int32_t& references) {
std::atomic_ref<std::int32_t> count(references);
auto previous = count.load();
for (;;) {
if (previous == std::numeric_limits<std::int32_t>::max())
throw std::overflow_error("LibreSSL3 key reference count overflow");
if (count.compare_exchange_weak(previous, previous + 1))
return previous > 0;
}
}

} // namespace

extern "C" {

int APS5_VABI EVP_PKEY_up_ref_nid_postfix(LibreSsl3EvpPkey* key) {
Expand All @@ -99,6 +81,12 @@ int APS5_VABI RSA_up_ref_nid_postfix(LibreSsl3Rsa* rsa) {
return Retain_nid_no_patch(rsa->references);
}

int APS5_VABI SSL_CTX_up_ref_nid_postfix(LibreSsl3SslCtx* ctx) {
if (!ctx)
throw std::invalid_argument("SSL_CTX_up_ref requires a context");
return Retain_nid_no_patch(ctx->references);
}

void APS5_VABI RSA_get0_factors_nid_postfix(const LibreSsl3Rsa* rsa, const void** p, const void** q) {
if (!rsa && (p || q))
throw std::invalid_argument("RSA_get0_factors requires a key when outputs are requested");
Expand Down
Loading
Loading