From a69f84a046b9a402d09c858f9bb52dbbe5e054a1 Mon Sep 17 00:00:00 2001 From: jakcron Date: Mon, 6 Aug 2018 17:11:15 +0800 Subject: [PATCH] [nstool] Rename EsCertProcess to PkiCertProcess --- .../{EsCertProcess.cpp => PkiCertProcess.cpp} | 45 ++++++++++--------- .../{EsCertProcess.h => PkiCertProcess.h} | 11 ++--- programs/nstool/source/UserSettings.cpp | 4 +- programs/nstool/source/main.cpp | 6 +-- programs/nstool/source/nstool.h | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) rename programs/nstool/source/{EsCertProcess.cpp => PkiCertProcess.cpp} (78%) rename programs/nstool/source/{EsCertProcess.h => PkiCertProcess.h} (81%) diff --git a/programs/nstool/source/EsCertProcess.cpp b/programs/nstool/source/PkiCertProcess.cpp similarity index 78% rename from programs/nstool/source/EsCertProcess.cpp rename to programs/nstool/source/PkiCertProcess.cpp index bd15514..80f3b20 100644 --- a/programs/nstool/source/EsCertProcess.cpp +++ b/programs/nstool/source/PkiCertProcess.cpp @@ -4,10 +4,10 @@ #include #include #include "OffsetAdjustedIFile.h" -#include "EsCertProcess.h" +#include "PkiCertProcess.h" #include "PkiValidator.h" -EsCertProcess::EsCertProcess() : +PkiCertProcess::PkiCertProcess() : mFile(nullptr), mOwnIFile(false), mCliOutputMode(_BIT(OUTPUT_BASIC)), @@ -15,7 +15,7 @@ EsCertProcess::EsCertProcess() : { } -EsCertProcess::~EsCertProcess() +PkiCertProcess::~PkiCertProcess() { if (mOwnIFile) { @@ -23,7 +23,7 @@ EsCertProcess::~EsCertProcess() } } -void EsCertProcess::process() +void PkiCertProcess::process() { if (mFile == nullptr) { @@ -38,28 +38,28 @@ void EsCertProcess::process() displayCerts(); } -void EsCertProcess::setInputFile(fnd::IFile* file, bool ownIFile) +void PkiCertProcess::setInputFile(fnd::IFile* file, bool ownIFile) { mFile = file; mOwnIFile = ownIFile; } -void EsCertProcess::setKeyset(const sKeyset* keyset) +void PkiCertProcess::setKeyset(const sKeyset* keyset) { mKeyset = keyset; } -void EsCertProcess::setCliOutputMode(CliOutputMode mode) +void PkiCertProcess::setCliOutputMode(CliOutputMode mode) { mCliOutputMode = mode; } -void EsCertProcess::setVerifyMode(bool verify) +void PkiCertProcess::setVerifyMode(bool verify) { mVerify = verify; } -void EsCertProcess::importCerts() +void PkiCertProcess::importCerts() { fnd::Vec scratch; @@ -74,7 +74,7 @@ void EsCertProcess::importCerts() } } -void EsCertProcess::validateCerts() +void PkiCertProcess::validateCerts() { PkiValidator pki; @@ -90,7 +90,7 @@ void EsCertProcess::validateCerts() } } -void EsCertProcess::displayCerts() +void PkiCertProcess::displayCerts() { for (size_t i = 0; i < mCert.size(); i++) { @@ -98,13 +98,13 @@ void EsCertProcess::displayCerts() } } -void EsCertProcess::displayCert(const pki::SignedData& cert) +void PkiCertProcess::displayCert(const pki::SignedData& cert) { #define _SPLIT_VER(ver) ( (ver>>26) & 0x3f), ( (ver>>20) & 0x3f), ( (ver>>16) & 0xf), (ver & 0xffff) #define _HEXDUMP_U(var, len) do { for (size_t a__a__A = 0; a__a__A < len; a__a__A++) printf("%02X", var[a__a__A]); } while(0) #define _HEXDUMP_L(var, len) do { for (size_t a__a__A = 0; a__a__A < len; a__a__A++) printf("%02x", var[a__a__A]); } while(0) - std::cout << "[ES Certificate]" << std::endl; + std::cout << "[NNPKI Certificate]" << std::endl; std::cout << " SignType " << getSignTypeStr(cert.getSignature().getSignType()); if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) @@ -123,7 +123,7 @@ void EsCertProcess::displayCert(const pki::SignedData& cer { std::cout << " PublicKey:" << std::endl; std::cout << " Modulus:" << std::endl; - fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().modulus, _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED) ? crypto::rsa::kRsa4096Size : 0x10, 0x10, 6); + fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().modulus, getHexDumpLen(crypto::rsa::kRsa4096Size), 0x10, 6); std::cout << " Public Exponent:" << std::endl; fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().public_exponent, crypto::rsa::kRsaPublicExponentSize, 0x10, 6); } @@ -131,7 +131,7 @@ void EsCertProcess::displayCert(const pki::SignedData& cer { std::cout << " PublicKey:" << std::endl; std::cout << " Public Exponent:" << std::endl; - fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().modulus, _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED) ? crypto::rsa::kRsa2048Size : 0x10, 0x10, 6); + fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().modulus, getHexDumpLen(crypto::rsa::kRsa2048Size), 0x10, 6); std::cout << " Modulus:" << std::endl; fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().public_exponent, crypto::rsa::kRsaPublicExponentSize, 0x10, 6); } @@ -139,9 +139,9 @@ void EsCertProcess::displayCert(const pki::SignedData& cer { std::cout << " PublicKey:" << std::endl; std::cout << " R:" << std::endl; - fnd::SimpleTextOutput::hexDump(cert.getBody().getEcdsa240PublicKey().r, _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED) ? crypto::ecdsa::kEcdsa240Size : 0x10, 0x10, 6); + fnd::SimpleTextOutput::hexDump(cert.getBody().getEcdsa240PublicKey().r, getHexDumpLen(crypto::ecdsa::kEcdsa240Size), 0x10, 6); std::cout << " S:" << std::endl; - fnd::SimpleTextOutput::hexDump(cert.getBody().getEcdsa240PublicKey().s, _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED) ? crypto::ecdsa::kEcdsa240Size : 0x10, 0x10, 6); + fnd::SimpleTextOutput::hexDump(cert.getBody().getEcdsa240PublicKey().s, getHexDumpLen(crypto::ecdsa::kEcdsa240Size), 0x10, 6); } @@ -151,7 +151,12 @@ void EsCertProcess::displayCert(const pki::SignedData& cer #undef _SPLIT_VER } -const char* EsCertProcess::getSignTypeStr(pki::sign::SignatureId type) const +size_t PkiCertProcess::getHexDumpLen(size_t max_size) const +{ + return _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED) ? max_size : kSmallHexDumpLen; +} + +const char* PkiCertProcess::getSignTypeStr(pki::sign::SignatureId type) const { const char* str; switch (type) @@ -181,12 +186,12 @@ const char* EsCertProcess::getSignTypeStr(pki::sign::SignatureId type) const return str; } -const char* EsCertProcess::getEndiannessStr(bool isLittleEndian) const +const char* PkiCertProcess::getEndiannessStr(bool isLittleEndian) const { return isLittleEndian ? "LittleEndian" : "BigEndian"; } -const char* EsCertProcess::getPublicKeyTypeStr(pki::cert::PublicKeyType type) const +const char* PkiCertProcess::getPublicKeyTypeStr(pki::cert::PublicKeyType type) const { const char* str; switch (type) diff --git a/programs/nstool/source/EsCertProcess.h b/programs/nstool/source/PkiCertProcess.h similarity index 81% rename from programs/nstool/source/EsCertProcess.h rename to programs/nstool/source/PkiCertProcess.h index 5ef7551..31c63b2 100644 --- a/programs/nstool/source/EsCertProcess.h +++ b/programs/nstool/source/PkiCertProcess.h @@ -8,11 +8,11 @@ #include #include "nstool.h" -class EsCertProcess +class PkiCertProcess { public: - EsCertProcess(); - ~EsCertProcess(); + PkiCertProcess(); + ~PkiCertProcess(); void process(); @@ -22,7 +22,8 @@ public: void setVerifyMode(bool verify); private: - const std::string kModuleName = "EsCertProcess"; + const std::string kModuleName = "PkiCertProcess"; + static const size_t kSmallHexDumpLen = 0x10; fnd::IFile* mFile; bool mOwnIFile; @@ -37,7 +38,7 @@ private: void displayCerts(); void displayCert(const pki::SignedData& cert); - + size_t getHexDumpLen(size_t max_size) const; const char* getSignTypeStr(pki::sign::SignatureId type) const; const char* getEndiannessStr(bool isLittleEndian) const; const char* getPublicKeyTypeStr(pki::cert::PublicKeyType type) const; diff --git a/programs/nstool/source/UserSettings.cpp b/programs/nstool/source/UserSettings.cpp index 412fa70..65d09a2 100644 --- a/programs/nstool/source/UserSettings.cpp +++ b/programs/nstool/source/UserSettings.cpp @@ -695,7 +695,7 @@ FileType UserSettings::getFileTypeFromString(const std::string& type_str) else if (str == "nacp") type = FILE_NACP; else if (str == "cert") - type = FILE_ES_CERT; + type = FILE_PKI_CERT; else if (str == "tik") type = FILE_ES_TIK; else if (str == "aset" || str == "asset") @@ -758,7 +758,7 @@ FileType UserSettings::determineFileTypeFromFile(const std::string& path) file_type = FILE_NRO; // test pki certificate else if (determineValidEsCertFromSample(scratch)) - file_type = FILE_ES_CERT; + file_type = FILE_PKI_CERT; // test ticket else if (determineValidEsTikFromSample(scratch)) file_type = FILE_ES_TIK; diff --git a/programs/nstool/source/main.cpp b/programs/nstool/source/main.cpp index 7186282..0c8ef07 100644 --- a/programs/nstool/source/main.cpp +++ b/programs/nstool/source/main.cpp @@ -11,7 +11,7 @@ #include "NsoProcess.h" #include "NroProcess.h" #include "NacpProcess.h" -#include "EsCertProcess.h" +#include "PkiCertProcess.h" #include "EsTikProcess.h" #include "AssetProcess.h" @@ -175,9 +175,9 @@ int main(int argc, char** argv) nacp.process(); } - else if (user_set.getFileType() == FILE_ES_CERT) + else if (user_set.getFileType() == FILE_PKI_CERT) { - EsCertProcess cert; + PkiCertProcess cert; cert.setInputFile(new fnd::SimpleFile(user_set.getInputPath(), fnd::SimpleFile::Read), OWN_IFILE); cert.setKeyset(&user_set.getKeyset()); diff --git a/programs/nstool/source/nstool.h b/programs/nstool/source/nstool.h index b94521d..a52c571 100644 --- a/programs/nstool/source/nstool.h +++ b/programs/nstool/source/nstool.h @@ -27,7 +27,7 @@ enum FileType FILE_NSO, FILE_NRO, FILE_NACP, - FILE_ES_CERT, + FILE_PKI_CERT, FILE_ES_TIK, FILE_HB_ASSET, FILE_INVALID = -1,