From aff3349c3343226ad4923edc47ebade7eacac8f3 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 29 Jun 2016 22:20:27 -0700 Subject: [PATCH] Initial attempt to reimplement ecdsa certificates --- .gitmodules | 3 +++ CMakeLists.txt | 4 +++- extern/CMakeLists.txt | 1 + extern/easy-ecc | 1 + include/athena/WiiSaveReader.hpp | 2 +- src/athena/WiiSave.cpp | 4 ---- src/athena/WiiSaveReader.cpp | 28 ++++++++++++++++++++-------- src/athena/WiiSaveWriter.cpp | 2 +- 8 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 .gitmodules create mode 160000 extern/easy-ecc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4226383 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "easy-ecc"] + path = extern/easy-ecc + url = https://github.com/libAthena/easy-ecc.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f442c6..4bc3de4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,8 @@ set(ATHENA_VERSION 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) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") endif() @@ -122,6 +123,7 @@ if(NOT MSVC AND NOT GEKKO) set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes) endif() + add_library(athena-zelda EXCLUDE_FROM_ALL src/athena/ALTTPFile.cpp src/athena/ALTTPFileReader.cpp diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 211f1c0..4600c53 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(lzo) add_subdirectory(zlib) add_subdirectory(yaml) +add_subdirectory(easy-ecc) diff --git a/extern/easy-ecc b/extern/easy-ecc new file mode 160000 index 0000000..da27485 --- /dev/null +++ b/extern/easy-ecc @@ -0,0 +1 @@ +Subproject commit da2748507cbe429d3e1be918c54cfba3be06d4b2 diff --git a/include/athena/WiiSaveReader.hpp b/include/athena/WiiSaveReader.hpp index f68685d..1c15242 100644 --- a/include/athena/WiiSaveReader.hpp +++ b/include/athena/WiiSaveReader.hpp @@ -42,7 +42,7 @@ public: * \brief readSave * \return */ - WiiSave* readSave(); + std::unique_ptr readSave(); private: WiiBanner* readBanner(); WiiFile* readFile(); diff --git a/src/athena/WiiSave.cpp b/src/athena/WiiSave.cpp index 8f45da0..5584f48 100644 --- a/src/athena/WiiSave.cpp +++ b/src/athena/WiiSave.cpp @@ -4,10 +4,6 @@ #include "athena/MemoryReader.hpp" #include "athena/MemoryWriter.hpp" #include "athena/Utility.hpp" -#include "aes.hpp" -#include "ec.h" -#include "md5.h" -#include "sha1.h" #include #include diff --git a/src/athena/WiiSaveReader.cpp b/src/athena/WiiSaveReader.cpp index 74ef4ff..1bbf069 100644 --- a/src/athena/WiiSaveReader.cpp +++ b/src/athena/WiiSaveReader.cpp @@ -7,7 +7,7 @@ #include "athena/FileWriter.hpp" #include "md5.h" #include "aes.hpp" -#include "ec.h" +#include "ecc.h" #include "sha1.h" #include #include @@ -31,7 +31,7 @@ WiiSaveReader::WiiSaveReader(const std::string& filename) setEndian(Endian::BigEndian); } -WiiSave* WiiSaveReader::readSave() +std::unique_ptr WiiSaveReader::readSave() { WiiSave* ret = new WiiSave; @@ -92,7 +92,7 @@ WiiSave* WiiSaveReader::readSave() ret->setRoot(buildTree(files)); readCerts(totalSize); - return ret; + return std::unique_ptr(ret); } WiiBanner* WiiSaveReader::readBanner() @@ -292,9 +292,9 @@ WiiFile* WiiSaveReader::readFile() return ret; } - void WiiSaveReader::readCerts(atUint32 totalSize) { +#if 0 std::cout << "Reading certs..." << std::endl; atUint32 dataSize = totalSize - 0x340; std::unique_ptr sig = base::readUBytes(0x40); @@ -304,12 +304,24 @@ void WiiSaveReader::readCerts(atUint32 totalSize) std::unique_ptr data = base::readUBytes(dataSize); atUint8* hash; + std::cout << "validating..." << std::endl; hash = getSha1(data.get(), dataSize); atUint8* hash2 = getSha1(hash, 20); -#if 0 - std::cout << "validating..." << std::endl; - std::cout << (check_ec(ngCert.get(), apCert.get(), sig.get(), hash2) ? "ok" : "invalid") << "..."; - std::cout << "done" << std::endl; + bool failed = false; + + if (!ecdsa_verify(ngCert.get(), hash, sig.get())) + { + 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 } diff --git a/src/athena/WiiSaveWriter.cpp b/src/athena/WiiSaveWriter.cpp index 8fce1e2..5c48906 100644 --- a/src/athena/WiiSaveWriter.cpp +++ b/src/athena/WiiSaveWriter.cpp @@ -10,7 +10,7 @@ #include "athena/Utility.hpp" #include "aes.hpp" -#include "ec.h" +#include "ecc.h" #include "md5.h" #include "sha1.h"