Credential.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include <cstdio>
  21. #include <cstdlib>
  22. #include <cstdint>
  23. #include <cstring>
  24. namespace ZeroTier {
  25. class Capability;
  26. class Revocation;
  27. class Tag;
  28. class CertificateOfMembership;
  29. class CertificateOfOwnership;
  30. class RuntimeEnvironment;
  31. /**
  32. * Base class for credentials
  33. *
  34. * Note that all credentials are and must be trivially copyable.
  35. *
  36. * All credential verification methods are implemented in Credential.cpp as they share a lot
  37. * of common code and logic and grouping them makes auditing easier.
  38. */
  39. class Credential : public TriviallyCopyable
  40. {
  41. public:
  42. /**
  43. * Result of verify() operations
  44. */
  45. enum VerifyResult
  46. {
  47. VERIFY_OK = 0,
  48. VERIFY_BAD_SIGNATURE = 1,
  49. VERIFY_NEED_IDENTITY = 2
  50. };
  51. protected:
  52. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const CertificateOfMembership &credential) const;
  53. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const Revocation &credential) const;
  54. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const Tag &credential) const;
  55. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const CertificateOfOwnership &credential) const;
  56. VerifyResult _verify(const RuntimeEnvironment *RR,void *tPtr,const Capability &credential) const;
  57. };
  58. } // namespace ZeroTier
  59. #endif