Credential.hpp 1.7 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: 2024-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 Capability;
  22. class Revocation;
  23. class Tag;
  24. class CertificateOfMembership;
  25. class CertificateOfOwnership;
  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. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const CertificateOfMembership &credential) const;
  49. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const Revocation &credential) const;
  50. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const Tag &credential) const;
  51. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const CertificateOfOwnership &credential) const;
  52. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const Capability &credential) const;
  53. };
  54. } // namespace ZeroTier
  55. #endif