Locator.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "Locator.hpp"
  27. #include "Utils.hpp"
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #define ZT_LOCATOR_SIGNING_BUFFER_SIZE (64 + (18 * ZT_LOCATOR_MAX_PHYSICAL_ENDPOINTS) + (256 * ZT_LOCATOR_MAX_VIRTUAL_ENDPOINTS))
  31. namespace ZeroTier {
  32. void Locator::sign(const Identity &id,const Identity &organization,const int64_t timestamp)
  33. {
  34. Buffer<ZT_LOCATOR_SIGNING_BUFFER_SIZE> *const sb = new Buffer<ZT_LOCATOR_SIGNING_BUFFER_SIZE>();
  35. _ts = timestamp;
  36. _id = id;
  37. _organization = organization;
  38. serialize(*sb,true);
  39. if (id)
  40. _signatureLength = id.sign(sb->data(),sb->size(),_signature,sizeof(_signature));
  41. if (organization)
  42. _orgSignatureLength = organization.sign(sb->data(),sb->size(),_orgSignature,sizeof(_orgSignature));
  43. delete sb;
  44. }
  45. bool Locator::verify() const
  46. {
  47. Buffer<ZT_LOCATOR_SIGNING_BUFFER_SIZE> *const sb = new Buffer<ZT_LOCATOR_SIGNING_BUFFER_SIZE>();
  48. serialize(*sb,true);
  49. bool ok = _id.verify(sb->data(),sb->size(),_signature,_signatureLength);
  50. if ((ok)&&(_organization))
  51. ok &= _organization.verify(sb->data(),sb->size(),_orgSignature,_orgSignatureLength);
  52. delete sb;
  53. return ok;
  54. }
  55. void Locator::generateDNSRecords(char *buf,unsigned int buflen)
  56. {
  57. Buffer<ZT_LOCATOR_SIGNING_BUFFER_SIZE> *const sb = new Buffer<ZT_LOCATOR_SIGNING_BUFFER_SIZE>();
  58. delete sb;
  59. }
  60. } // namespace ZeroTier