CredentialIssuerCommands.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2021-2022 Project CHIP Authors
  3. * All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #pragma once
  19. #include <app/util/basic-types.h>
  20. #include <credentials/attestation_verifier/DeviceAttestationVerifier.h>
  21. #include <lib/core/CHIPCore.h>
  22. #include <lib/core/CHIPPersistentStorageDelegate.h>
  23. #include <vector>
  24. namespace chip {
  25. namespace Controller {
  26. struct SetupParams;
  27. class OperationalCredentialsDelegate;
  28. } // namespace Controller
  29. } // namespace chip
  30. class CredentialIssuerCommands
  31. {
  32. public:
  33. virtual ~CredentialIssuerCommands() {}
  34. /**
  35. * @brief
  36. * This function is used to initialize the Credentials Issuer, if needed.
  37. *
  38. * @param[in] storage A reference to the storage, where the Credentials Issuer can optionally use to access the keypair in
  39. * storage.
  40. *
  41. * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code.
  42. */
  43. virtual CHIP_ERROR InitializeCredentialsIssuer(chip::PersistentStorageDelegate & storage) = 0;
  44. /**
  45. * @brief
  46. * This function is used to setup Device Attestation Singletons and intialize Setup/Commissioning Parameters with a custom
  47. * Device Attestation Verifier object.
  48. *
  49. * @param[in] setupParams A reference to the Setup/Commissioning Parameters, to be initialized with custom Device Attestation
  50. * Verifier.
  51. * @param[in] trustStore A pointer to the PAA trust store to use to find valid PAA roots.
  52. *
  53. * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code.
  54. */
  55. virtual CHIP_ERROR SetupDeviceAttestation(chip::Controller::SetupParams & setupParams,
  56. const chip::Credentials::AttestationTrustStore * trustStore) = 0;
  57. /**
  58. * @brief Add a list of additional non-default CD verifying keys (by certificate)
  59. *
  60. * Must be called AFTER SetupDeviceAttestation.
  61. *
  62. * @param additionalCdCerts - vector of X.509 DER verifying cert bodies
  63. * @return CHIP_NO_ERROR on succes, another CHIP_ERROR on internal failures.
  64. */
  65. virtual CHIP_ERROR AddAdditionalCDVerifyingCerts(const std::vector<std::vector<uint8_t>> & additionalCdCerts) = 0;
  66. virtual chip::Controller::OperationalCredentialsDelegate * GetCredentialIssuer() = 0;
  67. virtual void SetCredentialIssuerCATValues(chip::CATValues cats) = 0;
  68. /**
  69. * @brief
  70. * This function is used to Generate NOC Chain for the Controller/Commissioner. Parameters follow the example implementation,
  71. * so some parameters may not translate to the real remote Credentials Issuer policy.
  72. *
  73. * @param[in] nodeId The desired NodeId for the generated NOC Chain - May be optional/unused in some implementations.
  74. * @param[in] fabricId The desired FabricId for the generated NOC Chain - May be optional/unused in some implementations.
  75. * @param[in] cats The desired CATs for the generated NOC Chain - May be optional/unused in some implementations.
  76. * @param[in] keypair The desired Keypair for the generated NOC Chain - May be optional/unused in some implementations.
  77. * @param[in,out] rcac Buffer to hold the Root Certificate of the generated NOC Chain.
  78. * @param[in,out] icac Buffer to hold the Intermediate Certificate of the generated NOC Chain.
  79. * @param[in,out] noc Buffer to hold the Leaf Certificate of the generated NOC Chain.
  80. *
  81. * @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code.
  82. */
  83. virtual CHIP_ERROR GenerateControllerNOCChain(chip::NodeId nodeId, chip::FabricId fabricId, const chip::CATValues & cats,
  84. chip::Crypto::P256Keypair & keypair, chip::MutableByteSpan & rcac,
  85. chip::MutableByteSpan & icac, chip::MutableByteSpan & noc) = 0;
  86. // All options must start false
  87. enum CredentialIssuerOptions : uint8_t
  88. {
  89. kMaximizeCertificateSizes = 0, // If set, certificate chains will be maximized for testing via padding
  90. kAllowTestCdSigningKey = 1, // If set, allow development/test SDK CD verifying key to be used
  91. };
  92. virtual void SetCredentialIssuerOption(CredentialIssuerOptions option, bool isEnabled)
  93. {
  94. // Do nothing
  95. (void) option;
  96. (void) isEnabled;
  97. }
  98. virtual bool GetCredentialIssuerOption(CredentialIssuerOptions option)
  99. {
  100. // All options always start false
  101. return false;
  102. }
  103. };