Commit graph

63 commits

Author SHA1 Message Date
Lioncash
767fcd8a81 crypto/key_manager: Remove dependency on the global system accessor
We can supply the content provider as an argument instead of hardcoding
a global accessor in the implementation.
2020-09-14 16:49:59 -04:00
Lioncash
ebe30ea145 key_manager: Make data arrays constexpr
We can convert these maps into constexpr arrays to eliminate some
runtime static constructors.
2020-08-22 22:47:24 -04:00
Lioncash
a87209e09d common/fileutil: Convert namespace to Common::FS
Migrates a remaining common file over to the Common namespace, making it
consistent with the rest of common files.

This also allows for high-traffic FS related code to alias the
filesystem function namespace as

namespace FS = Common::FS;

for more concise typing.
2020-08-16 06:52:40 -04:00
Lioncash
b0c3f66dc7 partition_data_manager: Make data arrays constexpr
Previously the constructor for all of these would run at program
startup, consuming time before the application can enter main().

This is also particularly dangerous, given the logging system wouldn't
have been initialized properly yet, yet the program would use the logs
to signify an error.

To rectify this, we can replace the literals with constexpr functions
that perform the conversion at compile-time, completely eliminating the
runtime cost of initializing these arrays.
2020-08-06 02:41:58 -04:00
Morph
c0dc6904e7 KeyManager: Prevent writing of invalid keys
If the keys are zero, don't write them to the autogenerated file.
2020-07-10 00:39:00 -04:00
Lioncash
3c70e27d64 key_manager: Resolve missing field initializer warning 2020-04-16 22:45:44 -04:00
bunnei
5897348571 Merge pull request #3091 from lioncash/core-conversion
core: Make most implicit type conversion warnings errors on MSVC
2019-11-15 12:08:50 -05:00
bunnei
9364f4d30c Merge pull request #3093 from lioncash/mbedtls
core: Migrate off deprecated mbedtls functions
2019-11-14 13:47:23 -05:00
Lioncash
c6b2fd7415 key_manager: Make use of IOFile in WriteKeyToFile()
This properly handles unicode-based paths on Windows, while opening a
raw stream doesn't out-of-the-box.

Prevents file creation from potentially failing on Windows PCs that make
use of unicode characters in their save paths (e.g. writing to a user's
AppData folder, where the user has a name with non-ASCII characters).
2019-11-12 08:52:18 -05:00
Lioncash
4c6cd8b9e8 core: Migrate off deprecated mbedtls functions
These functions are marked for deprecation and it's recommended that the
*_ret variants be used instead.
2019-11-12 08:45:56 -05:00
Lioncash
0092723959 externals: Update httplib
Since the introduction of this library, numerous improvements have been
made. Notably, many of the warnings we would get by simply including the
library header have now been fixed. This makes it much easier to make
conversion warning an error.
2019-11-12 08:31:27 -05:00
Lioncash
5a0d4d4234 crypto: Resolve sign-conversion warnings 2019-11-12 07:55:22 -05:00
vperus
1625fd5a18 [crypto] Use IsAllZeroArray helper function 2019-10-02 19:20:45 +03:00
Zach Hilman
fe150ae0a4 key_manager: Convert Ticket union to std::variant 2019-07-07 21:38:33 -04:00
Zach Hilman
51374d2489 es: Populate/synthesize tickets on construction 2019-07-07 21:38:33 -04:00
Zach Hilman
7b86f1b7f8 key_manager: Add structure for Ticket parsing 2019-07-07 21:38:33 -04:00
Zach Hilman
2092bde879 key_manager: Add accessors/helpers for ticket management 2019-07-07 21:38:33 -04:00
Lioncash
59d55c8137 common/hex_util: Combine HexVectorToString() and HexArrayToString()
These can be generified together by using a concept type to designate
them. This also has the benefit of not making copies of potentially very
large arrays.
2019-06-12 17:54:05 -04:00
Zach Hilman
3f62d06b38 core: Port current uses of RegisteredCache to ContentProvider 2019-03-26 22:05:37 -04:00
Jungy
1bb4f7e58b Fixes Unicode Key File Directories (#2120)
* Fixes Unicode Key File Directories

Adds code so that when loading a file it converts to UTF16 first, to
ensure the files can be opened. Code borrowed from FileUtil::Exists.

* Update src/core/crypto/key_manager.cpp

Co-Authored-By: Jungorend <Jungorend@users.noreply.github.com>

* Update src/core/crypto/key_manager.cpp

Co-Authored-By: Jungorend <Jungorend@users.noreply.github.com>

* Using FileUtil instead to be cleaner.

* Update src/core/crypto/key_manager.cpp

Co-Authored-By: Jungorend <Jungorend@users.noreply.github.com>
2019-02-20 21:24:25 -05:00
bunnei
924661eda8 Merge pull request #1836 from lioncash/unused
crypto/key_manager: Remove unused variable in GetTicketblob()
2018-12-04 18:28:15 -05:00
Lioncash
de9051633c filesystem: De-globalize registered_cache_union
We can just return a new instance of this when it's requested. This only
ever holds pointers to the existing registed caches, so it's not a large
object. Plus, this also gets rid of the need to keep around a separate
member function just to properly clear out the union.

Gets rid of one of five globals in the filesystem code.
2018-12-01 23:43:23 -05:00
Lioncash
0a55663c74 crypto/key_manager: Remove unused variable in GetTicketblob() 2018-12-01 22:37:51 -05:00
Frederic L
c76f4b6aec global: Use std::optional instead of boost::optional (#1578)
* get rid of boost::optional

* Remove optional references

* Use std::reference_wrapper for optional references

* Fix clang format

* Fix clang format part 2

* Adressed feedback

* Fix clang format and MacOS build
2018-10-30 00:03:25 -04:00
Zach Hilman
74802ed32a key_manager: Use isxdigit instead of isdigit when reading key file
Crypto revisions are hex numbers and this function only checks if the string is valid for stoul in base 16, so it should be isxdigit.
2018-10-27 21:56:10 -04:00
Lioncash
c2b6cc4692 key_manager: Remove unused variable in DeriveBase() 2018-10-24 00:00:12 -04:00
Lioncash
e21cda8767 key_manager/partition_data_manager: Silence truncation compiler warnings 2018-10-13 09:13:19 -04:00
Lioncash
f50401aa7f key_manager: Use std::vector's insert() instead of std::copy with a back_inserter
If the data is unconditionally being appended to the back of a
std::vector, we can just directly insert it there without the need to
insert all of the elements one-by-one with a std::back_inserter.
2018-10-13 08:29:35 -04:00
Lioncash
5323ae4af4 key_manager: Brace long conditional body
If a conditional (or it's body) travels more than one line, it should be
braced.
2018-10-13 08:24:21 -04:00
Lioncash
214d206020 key_manager: Don't assume file seeks and reads will always succeed
Given the filesystem should always be assumed to be volatile, we should
check and bail out if a seek operation isn't successful. This'll prevent
potentially writing/returning garbage data from the function in rare
cases.

This also allows removing a check to see if an offset is within the
bounds of a file before perfoming a seek operation. If a seek is
attempted beyond the end of a file, it will fail, so this essentially
combines two checks into one in one place.
2018-10-13 08:24:18 -04:00
Lioncash
b7c947fed3 key_manager: Remove unnecessary seek in DeriveSDSeed()
Given the file is opened a few lines above and no operations are done,
other than check if the file is in a valid state, the read/write pointer
will always be at the beginning of the file.
2018-10-13 08:08:44 -04:00
Zach Hilman
cb3ebb0b8f partition_data_manager: Rename system files for hekate
x
2018-10-07 13:16:23 -04:00
Zach Hilman
877dd19cae key_manager: Add support for loading keys from partition data 2018-10-07 13:15:11 -04:00
Zach Hilman
facd1d42a6 key_manager: Add ETicket key derivation
Derives titlekeys
2018-10-07 13:15:11 -04:00
Zach Hilman
30b8dd7c50 key_manager: Add base key derivation
Derives master keys, game encryption keys, and package1/2 keys
2018-10-07 13:15:11 -04:00
Zach Hilman
3048dad94a key_manager: Add BIS key getter 2018-10-07 13:15:11 -04:00
Zach Hilman
509b916817 key_manager: Add support for more keys
TSEC, SBK, BIS, and other Sources for proper derivation
2018-10-07 13:15:11 -04:00
Zach Hilman
306f4c3c7b key_manager: Add keyblob support 2018-10-07 13:15:11 -04:00
Zach Hilman
7a3faf4ced key_manager: Add support for crypto revisions past 04 2018-10-07 13:15:11 -04:00
Zach Hilman
659b8150aa key_manager: Add support for comments in keyfiles 2018-10-07 13:15:11 -04:00
Zach Hilman
01843d244e key_manager: Add support for console-specific keyfile 2018-10-07 13:15:11 -04:00
Zach Hilman
0b4eb661a9 key_manager: Rename KEK to Kek 2018-10-07 13:15:11 -04:00
fearlessTobi
1190ea6ddb Port #4182 from Citra: "Prefix all size_t with std::" 2018-09-15 15:21:06 +02:00
Zach Hilman
887ffb2512 nsp: Comply with style and performance guidelines 2018-09-04 14:29:19 -04:00
Zach Hilman
8e787e5ec2 key_manager: Avoid autogeneration if key exists 2018-09-04 14:25:54 -04:00
Lioncash
a9f4e31cc0 file_sys: Replace includes with forward declarations where applicable
Cuts down on include dependencies, resulting in less files that need to
be rebuilt when certain things are changed.
2018-09-03 22:52:24 -04:00
Zach Hilman
89422004c3 file_sys/crypto: Fix missing/unnecessary includes 2018-08-24 22:15:32 -04:00
Zach Hilman
8f6ef9d395 key_manager: Eliminate indexed for loop 2018-08-23 11:53:30 -04:00
Zach Hilman
8b989b2e11 key_manager: Create keys dir if it dosen't exist
On call to WriteKeyToFile, so that the autogenerated file can be written.
2018-08-23 11:53:30 -04:00
Zach Hilman
d867928e90 file_sys: Cut down on includes and copies 2018-08-23 11:53:30 -04:00