[nstool] Rename EsCertProcess to PkiCertProcess

This commit is contained in:
jakcron 2018-08-06 17:11:15 +08:00
parent 900415f49d
commit a69f84a046
5 changed files with 37 additions and 31 deletions

View file

@ -4,10 +4,10 @@
#include <fnd/SimpleTextOutput.h> #include <fnd/SimpleTextOutput.h>
#include <pki/SignUtils.h> #include <pki/SignUtils.h>
#include "OffsetAdjustedIFile.h" #include "OffsetAdjustedIFile.h"
#include "EsCertProcess.h" #include "PkiCertProcess.h"
#include "PkiValidator.h" #include "PkiValidator.h"
EsCertProcess::EsCertProcess() : PkiCertProcess::PkiCertProcess() :
mFile(nullptr), mFile(nullptr),
mOwnIFile(false), mOwnIFile(false),
mCliOutputMode(_BIT(OUTPUT_BASIC)), mCliOutputMode(_BIT(OUTPUT_BASIC)),
@ -15,7 +15,7 @@ EsCertProcess::EsCertProcess() :
{ {
} }
EsCertProcess::~EsCertProcess() PkiCertProcess::~PkiCertProcess()
{ {
if (mOwnIFile) if (mOwnIFile)
{ {
@ -23,7 +23,7 @@ EsCertProcess::~EsCertProcess()
} }
} }
void EsCertProcess::process() void PkiCertProcess::process()
{ {
if (mFile == nullptr) if (mFile == nullptr)
{ {
@ -38,28 +38,28 @@ void EsCertProcess::process()
displayCerts(); displayCerts();
} }
void EsCertProcess::setInputFile(fnd::IFile* file, bool ownIFile) void PkiCertProcess::setInputFile(fnd::IFile* file, bool ownIFile)
{ {
mFile = file; mFile = file;
mOwnIFile = ownIFile; mOwnIFile = ownIFile;
} }
void EsCertProcess::setKeyset(const sKeyset* keyset) void PkiCertProcess::setKeyset(const sKeyset* keyset)
{ {
mKeyset = keyset; mKeyset = keyset;
} }
void EsCertProcess::setCliOutputMode(CliOutputMode mode) void PkiCertProcess::setCliOutputMode(CliOutputMode mode)
{ {
mCliOutputMode = mode; mCliOutputMode = mode;
} }
void EsCertProcess::setVerifyMode(bool verify) void PkiCertProcess::setVerifyMode(bool verify)
{ {
mVerify = verify; mVerify = verify;
} }
void EsCertProcess::importCerts() void PkiCertProcess::importCerts()
{ {
fnd::Vec<byte_t> scratch; fnd::Vec<byte_t> scratch;
@ -74,7 +74,7 @@ void EsCertProcess::importCerts()
} }
} }
void EsCertProcess::validateCerts() void PkiCertProcess::validateCerts()
{ {
PkiValidator pki; PkiValidator pki;
@ -90,7 +90,7 @@ void EsCertProcess::validateCerts()
} }
} }
void EsCertProcess::displayCerts() void PkiCertProcess::displayCerts()
{ {
for (size_t i = 0; i < mCert.size(); i++) for (size_t i = 0; i < mCert.size(); i++)
{ {
@ -98,13 +98,13 @@ void EsCertProcess::displayCerts()
} }
} }
void EsCertProcess::displayCert(const pki::SignedData<pki::CertificateBody>& cert) void PkiCertProcess::displayCert(const pki::SignedData<pki::CertificateBody>& cert)
{ {
#define _SPLIT_VER(ver) ( (ver>>26) & 0x3f), ( (ver>>20) & 0x3f), ( (ver>>16) & 0xf), (ver & 0xffff) #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_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) #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()); std::cout << " SignType " << getSignTypeStr(cert.getSignature().getSignType());
if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED))
@ -123,7 +123,7 @@ void EsCertProcess::displayCert(const pki::SignedData<pki::CertificateBody>& cer
{ {
std::cout << " PublicKey:" << std::endl; std::cout << " PublicKey:" << std::endl;
std::cout << " Modulus:" << 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; std::cout << " Public Exponent:" << std::endl;
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().public_exponent, crypto::rsa::kRsaPublicExponentSize, 0x10, 6); fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa4098PublicKey().public_exponent, crypto::rsa::kRsaPublicExponentSize, 0x10, 6);
} }
@ -131,7 +131,7 @@ void EsCertProcess::displayCert(const pki::SignedData<pki::CertificateBody>& cer
{ {
std::cout << " PublicKey:" << std::endl; std::cout << " PublicKey:" << std::endl;
std::cout << " Public Exponent:" << 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; std::cout << " Modulus:" << std::endl;
fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().public_exponent, crypto::rsa::kRsaPublicExponentSize, 0x10, 6); fnd::SimpleTextOutput::hexDump(cert.getBody().getRsa2048PublicKey().public_exponent, crypto::rsa::kRsaPublicExponentSize, 0x10, 6);
} }
@ -139,9 +139,9 @@ void EsCertProcess::displayCert(const pki::SignedData<pki::CertificateBody>& cer
{ {
std::cout << " PublicKey:" << std::endl; std::cout << " PublicKey:" << std::endl;
std::cout << " R:" << 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; 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<pki::CertificateBody>& cer
#undef _SPLIT_VER #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; const char* str;
switch (type) switch (type)
@ -181,12 +186,12 @@ const char* EsCertProcess::getSignTypeStr(pki::sign::SignatureId type) const
return str; return str;
} }
const char* EsCertProcess::getEndiannessStr(bool isLittleEndian) const const char* PkiCertProcess::getEndiannessStr(bool isLittleEndian) const
{ {
return isLittleEndian ? "LittleEndian" : "BigEndian"; 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; const char* str;
switch (type) switch (type)

View file

@ -8,11 +8,11 @@
#include <pki/CertificateBody.h> #include <pki/CertificateBody.h>
#include "nstool.h" #include "nstool.h"
class EsCertProcess class PkiCertProcess
{ {
public: public:
EsCertProcess(); PkiCertProcess();
~EsCertProcess(); ~PkiCertProcess();
void process(); void process();
@ -22,7 +22,8 @@ public:
void setVerifyMode(bool verify); void setVerifyMode(bool verify);
private: private:
const std::string kModuleName = "EsCertProcess"; const std::string kModuleName = "PkiCertProcess";
static const size_t kSmallHexDumpLen = 0x10;
fnd::IFile* mFile; fnd::IFile* mFile;
bool mOwnIFile; bool mOwnIFile;
@ -37,7 +38,7 @@ private:
void displayCerts(); void displayCerts();
void displayCert(const pki::SignedData<pki::CertificateBody>& cert); void displayCert(const pki::SignedData<pki::CertificateBody>& cert);
size_t getHexDumpLen(size_t max_size) const;
const char* getSignTypeStr(pki::sign::SignatureId type) const; const char* getSignTypeStr(pki::sign::SignatureId type) const;
const char* getEndiannessStr(bool isLittleEndian) const; const char* getEndiannessStr(bool isLittleEndian) const;
const char* getPublicKeyTypeStr(pki::cert::PublicKeyType type) const; const char* getPublicKeyTypeStr(pki::cert::PublicKeyType type) const;

View file

@ -695,7 +695,7 @@ FileType UserSettings::getFileTypeFromString(const std::string& type_str)
else if (str == "nacp") else if (str == "nacp")
type = FILE_NACP; type = FILE_NACP;
else if (str == "cert") else if (str == "cert")
type = FILE_ES_CERT; type = FILE_PKI_CERT;
else if (str == "tik") else if (str == "tik")
type = FILE_ES_TIK; type = FILE_ES_TIK;
else if (str == "aset" || str == "asset") else if (str == "aset" || str == "asset")
@ -758,7 +758,7 @@ FileType UserSettings::determineFileTypeFromFile(const std::string& path)
file_type = FILE_NRO; file_type = FILE_NRO;
// test pki certificate // test pki certificate
else if (determineValidEsCertFromSample(scratch)) else if (determineValidEsCertFromSample(scratch))
file_type = FILE_ES_CERT; file_type = FILE_PKI_CERT;
// test ticket // test ticket
else if (determineValidEsTikFromSample(scratch)) else if (determineValidEsTikFromSample(scratch))
file_type = FILE_ES_TIK; file_type = FILE_ES_TIK;

View file

@ -11,7 +11,7 @@
#include "NsoProcess.h" #include "NsoProcess.h"
#include "NroProcess.h" #include "NroProcess.h"
#include "NacpProcess.h" #include "NacpProcess.h"
#include "EsCertProcess.h" #include "PkiCertProcess.h"
#include "EsTikProcess.h" #include "EsTikProcess.h"
#include "AssetProcess.h" #include "AssetProcess.h"
@ -175,9 +175,9 @@ int main(int argc, char** argv)
nacp.process(); 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.setInputFile(new fnd::SimpleFile(user_set.getInputPath(), fnd::SimpleFile::Read), OWN_IFILE);
cert.setKeyset(&user_set.getKeyset()); cert.setKeyset(&user_set.getKeyset());

View file

@ -27,7 +27,7 @@ enum FileType
FILE_NSO, FILE_NSO,
FILE_NRO, FILE_NRO,
FILE_NACP, FILE_NACP,
FILE_ES_CERT, FILE_PKI_CERT,
FILE_ES_TIK, FILE_ES_TIK,
FILE_HB_ASSET, FILE_HB_ASSET,
FILE_INVALID = -1, FILE_INVALID = -1,