From 8ad44dd00fc6f3ed0a961499eb72f5f1aa923cc9 Mon Sep 17 00:00:00 2001 From: Zion Nimchuk Date: Tue, 18 Jul 2017 11:42:52 -0700 Subject: [PATCH] Implement cellSslCertificateLoader --- rpcs3/Emu/Cell/Modules/cellSsl.cpp | 64 ++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellSsl.cpp b/rpcs3/Emu/Cell/Modules/cellSsl.cpp index 728d42fa22..e11ab15461 100644 --- a/rpcs3/Emu/Cell/Modules/cellSsl.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSsl.cpp @@ -1,11 +1,19 @@ #include "stdafx.h" + +#include +#include + #include "Emu/Cell/PPUModule.h" +#include "Utilities/File.h" +#include "Emu/VFS.h" logs::channel cellSsl("cellSsl"); -s32 cellSslInit() +namespace vm { using namespace ps3; } + +s32 cellSslInit(vm::ptr pool, u32 poolSize) { - UNIMPLEMENTED_FUNC(cellSsl); + cellSsl.todo("cellSslInit(pool=0x%x, poolSize=%d)", pool, poolSize); return CELL_OK; } @@ -15,9 +23,57 @@ s32 cellSslEnd() return CELL_OK; } -s32 cellSslCertificateLoader() +std::string getCert(const std::string certPath, const int certID) { - UNIMPLEMENTED_FUNC(cellSsl); + //Stupid cellssl + int newID = certID; + if (certID == 6) + newID = 23; + if (certID > 6 && certID < 23) + newID = certID - 1; + + std::string filePath = fmt::format("%sCA%02d.cer", certPath, newID); + + if (!fs::exists(filePath)) + { + cellSsl.error("Can't find certificate file %s, do you have the PS3 firmware installed?", filePath); + return ""; + } + return fs::file(filePath).to_string(); +} + +s32 cellSslCertificateLoader(u64 flag, vm::ptr buffer, u32 size, vm::ptr required) +{ + cellSsl.trace("cellSslCertificateLoader(flag=%llu, buffer=0x%x, size=%zu, required=0x%x)", flag, buffer, size, required); + + const std::bitset<58> flagBits(flag); + const std::string certPath = vfs::get("/dev_flash/") + "data/cert/"; + + if (required) + { + *required = (u32)flagBits.count(); + for (int i = 1; i < flagBits.size(); i++) + { + if (!flagBits[i-1]) + continue; + *required += (u32)(getCert(certPath, i).size() - 1); + } + } + else + { + std::string final; + for (int i = 1; i < flagBits.size(); i++) + { + if (!flagBits[i-1]) + continue; + final.append(getCert(certPath, i)); + } + + memset(buffer.get_ptr(), 0, size-1); + strncpy(buffer.get_ptr(), final.c_str(), size - 1); + buffer.get_ptr()[size - 1] = '\0'; + } + return CELL_OK; }