Initial attempt to reimplement ecdsa certificates

This commit is contained in:
Phillip Stephens 2016-06-29 22:20:27 -07:00
parent 99dcef42f1
commit aff3349c33
8 changed files with 30 additions and 15 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "easy-ecc"]
path = extern/easy-ecc
url = https://github.com/libAthena/easy-ecc.git

View File

@ -19,7 +19,8 @@ set(ATHENA_VERSION
add_subdirectory(extern) add_subdirectory(extern)
include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}) include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${EASYECC_INCLUDE_DIR})
if (NOT MSVC) if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif() endif()
@ -122,6 +123,7 @@ if(NOT MSVC AND NOT GEKKO)
set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes) set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes)
endif() endif()
add_library(athena-zelda EXCLUDE_FROM_ALL add_library(athena-zelda EXCLUDE_FROM_ALL
src/athena/ALTTPFile.cpp src/athena/ALTTPFile.cpp
src/athena/ALTTPFileReader.cpp src/athena/ALTTPFileReader.cpp

View File

@ -1,3 +1,4 @@
add_subdirectory(lzo) add_subdirectory(lzo)
add_subdirectory(zlib) add_subdirectory(zlib)
add_subdirectory(yaml) add_subdirectory(yaml)
add_subdirectory(easy-ecc)

1
extern/easy-ecc vendored Submodule

@ -0,0 +1 @@
Subproject commit da2748507cbe429d3e1be918c54cfba3be06d4b2

View File

@ -42,7 +42,7 @@ public:
* \brief readSave * \brief readSave
* \return * \return
*/ */
WiiSave* readSave(); std::unique_ptr<WiiSave> readSave();
private: private:
WiiBanner* readBanner(); WiiBanner* readBanner();
WiiFile* readFile(); WiiFile* readFile();

View File

@ -4,10 +4,6 @@
#include "athena/MemoryReader.hpp" #include "athena/MemoryReader.hpp"
#include "athena/MemoryWriter.hpp" #include "athena/MemoryWriter.hpp"
#include "athena/Utility.hpp" #include "athena/Utility.hpp"
#include "aes.hpp"
#include "ec.h"
#include "md5.h"
#include "sha1.h"
#include <stdio.h> #include <stdio.h>
#include <vector> #include <vector>

View File

@ -7,7 +7,7 @@
#include "athena/FileWriter.hpp" #include "athena/FileWriter.hpp"
#include "md5.h" #include "md5.h"
#include "aes.hpp" #include "aes.hpp"
#include "ec.h" #include "ecc.h"
#include "sha1.h" #include "sha1.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
@ -31,7 +31,7 @@ WiiSaveReader::WiiSaveReader(const std::string& filename)
setEndian(Endian::BigEndian); setEndian(Endian::BigEndian);
} }
WiiSave* WiiSaveReader::readSave() std::unique_ptr<WiiSave> WiiSaveReader::readSave()
{ {
WiiSave* ret = new WiiSave; WiiSave* ret = new WiiSave;
@ -92,7 +92,7 @@ WiiSave* WiiSaveReader::readSave()
ret->setRoot(buildTree(files)); ret->setRoot(buildTree(files));
readCerts(totalSize); readCerts(totalSize);
return ret; return std::unique_ptr<WiiSave>(ret);
} }
WiiBanner* WiiSaveReader::readBanner() WiiBanner* WiiSaveReader::readBanner()
@ -292,9 +292,9 @@ WiiFile* WiiSaveReader::readFile()
return ret; return ret;
} }
void WiiSaveReader::readCerts(atUint32 totalSize) void WiiSaveReader::readCerts(atUint32 totalSize)
{ {
#if 0
std::cout << "Reading certs..." << std::endl; std::cout << "Reading certs..." << std::endl;
atUint32 dataSize = totalSize - 0x340; atUint32 dataSize = totalSize - 0x340;
std::unique_ptr<atUint8[]> sig = base::readUBytes(0x40); std::unique_ptr<atUint8[]> sig = base::readUBytes(0x40);
@ -304,12 +304,24 @@ void WiiSaveReader::readCerts(atUint32 totalSize)
std::unique_ptr<atUint8[]> data = base::readUBytes(dataSize); std::unique_ptr<atUint8[]> data = base::readUBytes(dataSize);
atUint8* hash; atUint8* hash;
std::cout << "validating..." << std::endl;
hash = getSha1(data.get(), dataSize); hash = getSha1(data.get(), dataSize);
atUint8* hash2 = getSha1(hash, 20); atUint8* hash2 = getSha1(hash, 20);
#if 0 bool failed = false;
std::cout << "validating..." << std::endl;
std::cout << (check_ec(ngCert.get(), apCert.get(), sig.get(), hash2) ? "ok" : "invalid") << "..."; if (!ecdsa_verify(ngCert.get(), hash, sig.get()))
std::cout << "done" << std::endl; {
std::cout << "NGCert failure" << std::endl;
failed = true;
}
if (!ecdsa_verify(apCert.get(), hash2, sig.get()))
{
std::cout << "APCert failure" << std::endl;
failed = true;
}
if (!failed)
std::cout << "certificates ok" << std::endl;
#endif #endif
} }

View File

@ -10,7 +10,7 @@
#include "athena/Utility.hpp" #include "athena/Utility.hpp"
#include "aes.hpp" #include "aes.hpp"
#include "ec.h" #include "ecc.h"
#include "md5.h" #include "md5.h"
#include "sha1.h" #include "sha1.h"