Credential.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2019 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #ifndef ZT_CREDENTIAL_HPP
  27. #define ZT_CREDENTIAL_HPP
  28. #include <string>
  29. #include <memory>
  30. #include <stdexcept>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <stdint.h>
  34. #include <string.h>
  35. #include "Constants.hpp"
  36. namespace ZeroTier {
  37. class Capability;
  38. class Revocation;
  39. class Tag;
  40. class CertificateOfMembership;
  41. class CertificateOfOwnership;
  42. class RuntimeEnvironment;
  43. /**
  44. * Base class for credentials
  45. */
  46. class Credential
  47. {
  48. public:
  49. /**
  50. * Do not change type code IDs -- these are used in Revocation objects and elsewhere
  51. */
  52. enum Type
  53. {
  54. CREDENTIAL_TYPE_NULL = 0,
  55. CREDENTIAL_TYPE_COM = 1, // CertificateOfMembership
  56. CREDENTIAL_TYPE_CAPABILITY = 2,
  57. CREDENTIAL_TYPE_TAG = 3,
  58. CREDENTIAL_TYPE_COO = 4, // CertificateOfOwnership
  59. CREDENTIAL_TYPE_REVOCATION = 6
  60. };
  61. /**
  62. * Result of verify() operations
  63. */
  64. enum VerifyResult
  65. {
  66. VERIFY_OK = 0,
  67. VERIFY_BAD_SIGNATURE = 1,
  68. VERIFY_NEED_IDENTITY = 2
  69. };
  70. protected:
  71. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const CertificateOfMembership &credential) const;
  72. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const Revocation &credential) const;
  73. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const Tag &credential) const;
  74. VerifyResult _verify(const RuntimeEnvironment *const RR,void *tPtr,const CertificateOfOwnership &credential) const;
  75. };
  76. } // namespace ZeroTier
  77. #endif