Capability.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 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. #include "Capability.hpp"
  19. #include "RuntimeEnvironment.hpp"
  20. #include "Identity.hpp"
  21. #include "Topology.hpp"
  22. #include "Switch.hpp"
  23. namespace ZeroTier {
  24. int Capability::verify(const RuntimeEnvironment *RR) const
  25. {
  26. try {
  27. Buffer<(sizeof(Capability) * 2)> tmp;
  28. this->serialize(tmp,true);
  29. for(unsigned int c=0;c<ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH;++c) {
  30. if (!_custody[c].to)
  31. return ((c == 0) ? -1 : 0);
  32. if (!_custody[c].from)
  33. return -1;
  34. const Identity id(RR->topology->getIdentity(_custody[c].from));
  35. if (id) {
  36. if (!id.verify(tmp.data(),tmp.size(),_custody[c].signature))
  37. return -1;
  38. } else {
  39. RR->sw->requestWhois(_custody[c].from);
  40. return 1;
  41. }
  42. }
  43. return 0;
  44. } catch ( ... ) {
  45. return -1;
  46. }
  47. }
  48. } // namespace ZeroTier