Credential.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c)2019 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: 2023-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 <string>
  16. #include <memory>
  17. #include <stdexcept>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <stdint.h>
  21. #include <string.h>
  22. #include "Constants.hpp"
  23. namespace ZeroTier {
  24. class Capability;
  25. class Revocation;
  26. class Tag;
  27. class CertificateOfMembership;
  28. class CertificateOfOwnership;
  29. class RuntimeEnvironment;
  30. /**
  31. * Base class for credentials
  32. */
  33. class Credential
  34. {
  35. public:
  36. /**
  37. * Do not change type code IDs -- these are used in Revocation objects and elsewhere
  38. */
  39. enum Type
  40. {
  41. CREDENTIAL_TYPE_NULL = 0,
  42. CREDENTIAL_TYPE_COM = 1, // CertificateOfMembership
  43. CREDENTIAL_TYPE_CAPABILITY = 2,
  44. CREDENTIAL_TYPE_TAG = 3,
  45. CREDENTIAL_TYPE_COO = 4, // CertificateOfOwnership
  46. CREDENTIAL_TYPE_REVOCATION = 6
  47. };
  48. /**
  49. * Result of verify() operations
  50. */
  51. enum VerifyResult
  52. {
  53. VERIFY_OK = 0,
  54. VERIFY_BAD_SIGNATURE = 1,
  55. VERIFY_NEED_IDENTITY = 2
  56. };
  57. protected:
  58. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const CertificateOfMembership &credential) const;
  59. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const Revocation &credential) const;
  60. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const Tag &credential) const;
  61. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const CertificateOfOwnership &credential) const;
  62. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const Capability &credential) const;
  63. };
  64. } // namespace ZeroTier
  65. #endif