KeyCollection.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2018 shchmue
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include "Key.hpp"
  18. #include "KeyLocation.hpp"
  19. #include <switch/types.h>
  20. class KeyCollection {
  21. public:
  22. KeyCollection();
  23. // get KeyLocations and find keys in them
  24. void get_keys();
  25. private:
  26. // utility functions called by get_keys
  27. void get_master_keys();
  28. void get_memory_keys();
  29. // derive calculated/encrypted keys
  30. void derive_keys();
  31. // save keys to key file
  32. void save_keys();
  33. // get titlekeys from es syssaves
  34. void get_titlekeys();
  35. // mask generation function used by get_titlekeys
  36. void mgf1(const u8 *data, size_t data_length, u8 *mask, size_t mask_length);
  37. // key pair tester for get_titlekeys
  38. bool test_key_pair(const void *E, const void *D, const void *N);
  39. Key // dumped by payload
  40. sbk,
  41. tsec,
  42. tsec_root_key,
  43. // from TZ
  44. aes_kek_generation_source,
  45. aes_kek_seed_01,
  46. aes_kek_seed_03,
  47. package2_key_source,
  48. titlekek_source,
  49. retail_specific_aes_key_source,
  50. // from Package1ldr
  51. keyblob_mac_key_source,
  52. master_key_source,
  53. per_console_key_source,
  54. // from FS
  55. bis_kek_source,
  56. bis_key_source_00,
  57. bis_key_source_01,
  58. bis_key_source_02,
  59. header_kek_source,
  60. header_key_source,
  61. key_area_key_application_source,
  62. key_area_key_ocean_source,
  63. key_area_key_system_source,
  64. save_mac_kek_source,
  65. save_mac_key_source,
  66. sd_card_kek_source,
  67. sd_card_nca_key_source,
  68. sd_card_save_key_source,
  69. // from SPL
  70. aes_key_generation_source,
  71. // from ES
  72. eticket_rsa_kek_source,
  73. eticket_rsa_kekek_source,
  74. // from SSL
  75. ssl_rsa_kek_source_x,
  76. ssl_rsa_kek_source_y,
  77. // derived keys
  78. device_key,
  79. eticket_rsa_kek,
  80. header_key,
  81. rsa_oaep_kek_generation_source,
  82. rsa_private_kek_generation_source,
  83. save_mac_key,
  84. ssl_rsa_kek,
  85. // other
  86. sd_seed;
  87. // key families
  88. std::vector<Key>
  89. bis_key,
  90. encrypted_keyblob,
  91. key_area_key_application,
  92. key_area_key_ocean,
  93. key_area_key_system,
  94. keyblob,
  95. keyblob_key,
  96. keyblob_key_source,
  97. keyblob_mac_key,
  98. master_kek,
  99. master_kek_source,
  100. master_key,
  101. mkey_vector,
  102. package1_key,
  103. package2_key,
  104. titlekek;
  105. std::vector<Key *>
  106. es_keys, fs_rodata_keys, ssl_keys;
  107. // hash of empty string used to verify titlekeys for personalized tickets
  108. static const u8 null_hash[0x20];
  109. size_t titlekeys_dumped = 0;
  110. };