Jayanth Othayoth | 9d7cd83 | 2018-02-21 05:12:39 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <experimental/filesystem> |
Jayanth Othayoth | 2ab9b10 | 2018-02-21 05:27:47 -0600 | [diff] [blame^] | 3 | #include <set> |
Jayanth Othayoth | 9d7cd83 | 2018-02-21 05:12:39 -0600 | [diff] [blame] | 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace software |
| 8 | { |
| 9 | namespace image |
| 10 | { |
| 11 | |
| 12 | namespace fs = std::experimental::filesystem; |
Jayanth Othayoth | 2ab9b10 | 2018-02-21 05:27:47 -0600 | [diff] [blame^] | 13 | using Key_t = std::string; |
| 14 | using Hash_t = std::string; |
| 15 | using PublicKeyPath = fs::path; |
| 16 | using HashFilePath = fs::path; |
| 17 | using KeyHashPathPair = std::pair<HashFilePath, PublicKeyPath>; |
| 18 | using AvailableKeyTypes = std::set<Key_t>; |
Jayanth Othayoth | 9d7cd83 | 2018-02-21 05:12:39 -0600 | [diff] [blame] | 19 | |
Jayanth Othayoth | 2ab9b10 | 2018-02-21 05:27:47 -0600 | [diff] [blame^] | 20 | // BMC flash image file name list. |
| 21 | const std::vector<std::string> bmcImages = {"image-kernel", "image-rofs", |
| 22 | "image-rwfs", "image-u-boot"}; |
Jayanth Othayoth | 9d7cd83 | 2018-02-21 05:12:39 -0600 | [diff] [blame] | 23 | /** @class Signature |
| 24 | * @brief Contains signature verification functions. |
| 25 | * @details The software image class that contains the signature |
| 26 | * verification functions for signed image. |
| 27 | */ |
| 28 | class Signature |
| 29 | { |
| 30 | public: |
| 31 | Signature() = delete; |
| 32 | Signature(const Signature&) = delete; |
| 33 | Signature& operator=(const Signature&) = delete; |
| 34 | Signature(Signature&&) = default; |
| 35 | Signature& operator=(Signature&&) = default; |
| 36 | ~Signature() = default; |
| 37 | |
Jayanth Othayoth | 2ab9b10 | 2018-02-21 05:27:47 -0600 | [diff] [blame^] | 38 | /** |
| 39 | * @brief Constructs Signature. |
| 40 | * @param[in] imageDirPath - image path |
| 41 | * @param[in] signedConfPath - Path of public key |
| 42 | * hash function files |
Jayanth Othayoth | 9d7cd83 | 2018-02-21 05:12:39 -0600 | [diff] [blame] | 43 | */ |
Jayanth Othayoth | 2ab9b10 | 2018-02-21 05:27:47 -0600 | [diff] [blame^] | 44 | Signature(const fs::path& imageDirPath, const fs::path& signedConfPath); |
Jayanth Othayoth | 9d7cd83 | 2018-02-21 05:12:39 -0600 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * @brief Image signature verification function. |
| 48 | * Verify the Manifest and public key file signature using the |
| 49 | * public keys available in the system first. After successful |
| 50 | * validation, continue the whole image files signature |
| 51 | * validation using the image specific public key and the |
| 52 | * hash function. |
| 53 | * |
| 54 | * @return true if signature verification was successful, |
| 55 | * false if not |
| 56 | */ |
| 57 | bool verify(); |
| 58 | |
| 59 | private: |
Jayanth Othayoth | 2ab9b10 | 2018-02-21 05:27:47 -0600 | [diff] [blame^] | 60 | /** |
| 61 | * @brief Function used for system level file signature validation |
| 62 | * of image specfic publickey file and manifest file |
| 63 | * using the available public keys and hash functions |
| 64 | * in the system. |
| 65 | * Refer code-update documenation for more details. |
| 66 | */ |
| 67 | bool systemLevelVerify(); |
| 68 | |
| 69 | /** |
| 70 | * @brief Return all key types stored in the BMC based on the |
| 71 | * public key and hashfunc files stored in the BMC. |
| 72 | * |
| 73 | * @return list |
| 74 | */ |
| 75 | AvailableKeyTypes getAvailableKeyTypesFromSystem() const; |
| 76 | |
| 77 | /** |
| 78 | * @brief Return public key and hash function file names for the |
| 79 | * corresponding key type |
| 80 | * |
| 81 | * @param[in] key - key type |
| 82 | * @return Pair of hash and public key file names |
| 83 | */ |
| 84 | inline KeyHashPathPair getKeyHashFileNames(const Key_t& key) const; |
| 85 | |
| 86 | /** |
| 87 | * @brief Verify the file signature using public key and hash function |
| 88 | * |
| 89 | * @param[in] - Image file path |
| 90 | * @param[in] - Signature file path |
| 91 | * @param[in] - Public key |
| 92 | * @param[in] - Hash function name |
| 93 | * @return true if signature verification was successful, false if not |
| 94 | */ |
| 95 | bool verifyFile(const fs::path& file, const fs::path& signature, |
| 96 | const fs::path& publicKey, const std::string& hashFunc); |
| 97 | |
| 98 | /** @brief Directory where software images are placed */ |
Jayanth Othayoth | 9d7cd83 | 2018-02-21 05:12:39 -0600 | [diff] [blame] | 99 | fs::path imageDirPath; |
Jayanth Othayoth | 2ab9b10 | 2018-02-21 05:27:47 -0600 | [diff] [blame^] | 100 | |
| 101 | /** @brief Path of public key and hash function files */ |
| 102 | fs::path signedConfPath; |
| 103 | |
| 104 | /** @brief key type defined in mainfest file */ |
| 105 | Key_t keyType; |
| 106 | |
| 107 | /** @brief Hash type defined in mainfest file */ |
| 108 | Hash_t hashType; |
Jayanth Othayoth | 9d7cd83 | 2018-02-21 05:12:39 -0600 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | } // namespace image |
| 112 | } // namespace software |
| 113 | } // namespace phosphor |