#include "prx/libSceLibreSsl/libSceLibreSsl.hpp" #include #include #include #include #include #include static void Require(bool value, const char* what) { if (value) return; std::fprintf(stderr, "failed: %s\n", what); std::abort(); } int main() { static_assert(sizeof(void*) == 8); Require(X509_EXTENSION_get_critical_nid_postfix(nullptr) == 0, "null extension is not critical"); Require(X509_EXTENSION_get_data_nid_postfix(nullptr) == nullptr, "null extension has no data"); Require(X509_EXTENSION_get_object_nid_postfix(nullptr) == nullptr, "null extension has no object"); struct CriticalCase { std::int32_t stored; int expected; }; constexpr CriticalCase criticalCases[] { {std::numeric_limits::min(), 0}, {-256, 0}, {-1, 0}, {0, 0}, {1, 1}, {127, 1}, {128, 1}, {255, 1}, {256, 1}, {65536, 1}, {std::numeric_limits::max(), 1} }; unsigned char object[16] {}; unsigned char octetString[24] {}; alignas(8) std::array storage; void* extension = storage.data() + 8; void* pointers[] {nullptr, object, octetString, extension, reinterpret_cast(std::uintptr_t{0x00007abc12345678})}; for (void* objectPointer : pointers) { for (void* dataPointer : pointers) { for (const auto& item : criticalCases) { for (unsigned char padding : {0x00, 0x7f, 0x80, 0xff}) { storage.fill(padding); std::memcpy(storage.data() + 8, &objectPointer, 8); std::memcpy(storage.data() + 16, &item.stored, 4); std::memcpy(storage.data() + 24, &dataPointer, 8); const auto before = storage; Require(X509_EXTENSION_get_critical_nid_postfix(extension) == item.expected, "signed critical field ignores padding"); Require(X509_EXTENSION_get_object_nid_postfix(extension) == objectPointer, "borrowed object pointer is preserved"); Require(X509_EXTENSION_get_data_nid_postfix(extension) == dataPointer, "borrowed ASN1 string pointer is preserved"); Require(storage == before, "getters preserve the extension and adjacent bytes"); } } } } void* dataPointer = octetString; std::memcpy(storage.data() + 24, &dataPointer, 8); auto* borrowed = static_cast(X509_EXTENSION_get_data_nid_postfix(extension)); borrowed[3] = 0x5a; Require(octetString[3] == 0x5a, "data is borrowed, not copied or decoded"); std::puts("libSceLibreSsl X509 extension tests passed"); }