Credential.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_CREDENTIAL_HPP
  14. #define ZT_CREDENTIAL_HPP
  15. #include "Constants.hpp"
  16. #include "TriviallyCopyable.hpp"
  17. #include <string>
  18. #include <memory>
  19. #include <stdexcept>
  20. namespace ZeroTier {
  21. class CapabilityCredential;
  22. class RevocationCredential;
  23. class TagCredential;
  24. class MembershipCredential;
  25. class OwnershipCredential;
  26. class RuntimeEnvironment;
  27. /**
  28. * Base class for credentials
  29. *
  30. * Note that all credentials are and must be trivially copyable.
  31. *
  32. * All credential verification methods are implemented in Credential.cpp as they share a lot
  33. * of common code and logic and grouping them makes auditing easier.
  34. */
  35. class Credential : public TriviallyCopyable
  36. {
  37. public:
  38. /**
  39. * Result of verify() operations
  40. */
  41. enum VerifyResult
  42. {
  43. VERIFY_OK = 0,
  44. VERIFY_BAD_SIGNATURE = 1,
  45. VERIFY_NEED_IDENTITY = 2
  46. };
  47. protected:
  48. static VerifyResult s_verify(const RuntimeEnvironment *RR, void *tPtr, const MembershipCredential &credential);
  49. static VerifyResult s_verify(const RuntimeEnvironment *RR, void *tPtr, const RevocationCredential &credential);
  50. static VerifyResult s_verify(const RuntimeEnvironment *RR, void *tPtr, const TagCredential &credential);
  51. static VerifyResult s_verify(const RuntimeEnvironment *RR, void *tPtr, const OwnershipCredential &credential);
  52. static VerifyResult s_verify(const RuntimeEnvironment *RR, void *tPtr, const CapabilityCredential &credential);
  53. };
  54. } // namespace ZeroTier
  55. #endif