2013-10-07 19:29:03 +00:00
|
|
|
/*
|
2015-02-17 21:11:34 +00:00
|
|
|
* ZeroTier One - Network Virtualization Everywhere
|
2019-01-14 18:25:53 +00:00
|
|
|
* Copyright (C) 2011-2019 ZeroTier, Inc. https://www.zerotier.com/
|
2013-10-07 19:29:03 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-01-14 18:25:53 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-04-28 03:47:25 +00:00
|
|
|
*
|
|
|
|
* --
|
|
|
|
*
|
|
|
|
* You can be released from the requirements of the license by purchasing
|
|
|
|
* a commercial license. Buying such a license is mandatory as soon as you
|
|
|
|
* develop commercial closed-source software that incorporates or links
|
|
|
|
* directly against ZeroTier software without disclosing the source code
|
|
|
|
* of your own application.
|
2013-10-07 19:29:03 +00:00
|
|
|
*/
|
|
|
|
|
2013-12-07 00:49:20 +00:00
|
|
|
#ifndef ZT_CERTIFICATEOFMEMBERSHIP_HPP
|
|
|
|
#define ZT_CERTIFICATEOFMEMBERSHIP_HPP
|
2013-10-07 19:29:03 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <string>
|
2013-10-07 20:13:52 +00:00
|
|
|
#include <stdexcept>
|
2016-04-12 19:11:34 +00:00
|
|
|
#include <algorithm>
|
2013-10-07 19:29:03 +00:00
|
|
|
|
|
|
|
#include "Constants.hpp"
|
2017-04-04 15:07:38 +00:00
|
|
|
#include "Credential.hpp"
|
2013-10-07 20:13:52 +00:00
|
|
|
#include "Buffer.hpp"
|
2013-10-07 19:29:03 +00:00
|
|
|
#include "Address.hpp"
|
|
|
|
#include "C25519.hpp"
|
|
|
|
#include "Identity.hpp"
|
2015-04-02 02:09:18 +00:00
|
|
|
#include "Utils.hpp"
|
2013-10-07 19:29:03 +00:00
|
|
|
|
2016-04-12 19:11:34 +00:00
|
|
|
/**
|
2016-07-28 17:58:10 +00:00
|
|
|
* Maximum number of qualifiers allowed in a COM (absolute max: 65535)
|
2016-04-12 19:11:34 +00:00
|
|
|
*/
|
2016-08-04 16:02:35 +00:00
|
|
|
#define ZT_NETWORK_COM_MAX_QUALIFIERS 8
|
2016-04-12 19:11:34 +00:00
|
|
|
|
2013-10-07 19:29:03 +00:00
|
|
|
namespace ZeroTier {
|
|
|
|
|
2016-08-04 16:02:35 +00:00
|
|
|
class RuntimeEnvironment;
|
|
|
|
|
2013-10-07 19:29:03 +00:00
|
|
|
/**
|
|
|
|
* Certificate of network membership
|
|
|
|
*
|
|
|
|
* The COM contains a sorted set of three-element tuples called qualifiers.
|
|
|
|
* These contain an id, a value, and a maximum delta.
|
|
|
|
*
|
|
|
|
* The ID is arbitrary and should be assigned using a scheme that makes
|
2013-10-16 21:47:26 +00:00
|
|
|
* every ID globally unique. IDs beneath 65536 are reserved for global
|
|
|
|
* assignment by ZeroTier Networks.
|
2013-10-07 19:29:03 +00:00
|
|
|
*
|
|
|
|
* The value's meaning is ID-specific and isn't important here. What's
|
|
|
|
* important is the value and the third member of the tuple: the maximum
|
|
|
|
* delta. The maximum delta is the maximum difference permitted between
|
|
|
|
* values for a given ID between certificates for the two certificates to
|
|
|
|
* themselves agree.
|
|
|
|
*
|
|
|
|
* Network membership is checked by checking whether a peer's certificate
|
|
|
|
* agrees with your own. The timestamp provides the fundamental criterion--
|
|
|
|
* each member of a private network must constantly obtain new certificates
|
|
|
|
* often enough to stay within the max delta for this qualifier. But other
|
|
|
|
* criteria could be added in the future for very special behaviors, things
|
|
|
|
* like latitude and longitude for instance.
|
2016-04-12 19:11:34 +00:00
|
|
|
*
|
|
|
|
* This is a memcpy()'able structure and is safe (in a crash sense) to modify
|
|
|
|
* without locks.
|
2013-10-07 19:29:03 +00:00
|
|
|
*/
|
2017-04-04 15:07:38 +00:00
|
|
|
class CertificateOfMembership : public Credential
|
2013-10-07 19:29:03 +00:00
|
|
|
{
|
2019-08-14 21:55:37 +00:00
|
|
|
friend class Credential;
|
|
|
|
|
2013-10-07 19:29:03 +00:00
|
|
|
public:
|
2017-04-04 15:07:38 +00:00
|
|
|
static inline Credential::Type credentialType() { return Credential::CREDENTIAL_TYPE_COM; }
|
|
|
|
|
2013-10-07 19:29:03 +00:00
|
|
|
/**
|
2013-10-16 21:47:26 +00:00
|
|
|
* Reserved qualifier IDs
|
2013-10-07 19:29:03 +00:00
|
|
|
*
|
2016-07-28 17:58:10 +00:00
|
|
|
* IDs below 1024 are reserved for use as standard IDs. Others are available
|
|
|
|
* for user-defined use.
|
2013-10-16 21:47:26 +00:00
|
|
|
*
|
|
|
|
* Addition of new required fields requires that code in hasRequiredFields
|
|
|
|
* be updated as well.
|
2013-10-07 19:29:03 +00:00
|
|
|
*/
|
2013-10-07 20:13:52 +00:00
|
|
|
enum ReservedId
|
2013-10-07 19:29:03 +00:00
|
|
|
{
|
2013-10-16 21:47:26 +00:00
|
|
|
/**
|
2016-08-23 01:06:46 +00:00
|
|
|
* Timestamp of certificate
|
2013-10-16 21:47:26 +00:00
|
|
|
*/
|
2016-08-23 01:06:46 +00:00
|
|
|
COM_RESERVED_ID_TIMESTAMP = 0,
|
2013-10-16 21:47:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Network ID for which certificate was issued
|
|
|
|
*/
|
|
|
|
COM_RESERVED_ID_NETWORK_ID = 1,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ZeroTier address to whom certificate was issued
|
|
|
|
*/
|
|
|
|
COM_RESERVED_ID_ISSUED_TO = 2
|
2013-10-07 19:29:03 +00:00
|
|
|
};
|
|
|
|
|
2013-10-16 21:47:26 +00:00
|
|
|
/**
|
2016-07-28 17:58:10 +00:00
|
|
|
* Create an empty certificate of membership
|
2013-10-16 21:47:26 +00:00
|
|
|
*/
|
2019-08-14 17:35:57 +00:00
|
|
|
inline CertificateOfMembership() :
|
2019-07-17 15:52:08 +00:00
|
|
|
_qualifierCount(0),
|
|
|
|
_signatureLength(0) {}
|
2013-10-16 21:47:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create from required fields common to all networks
|
|
|
|
*
|
2016-08-23 01:06:46 +00:00
|
|
|
* @param timestamp Timestamp of certificate
|
2013-10-16 21:47:26 +00:00
|
|
|
* @param timestampMaxDelta Maximum variation between timestamps on this net
|
|
|
|
* @param nwid Network ID
|
|
|
|
* @param issuedTo Certificate recipient
|
|
|
|
*/
|
2019-08-14 17:35:57 +00:00
|
|
|
inline CertificateOfMembership(uint64_t timestamp,uint64_t timestampMaxDelta,uint64_t nwid,const Address &issuedTo)
|
2013-10-16 21:47:26 +00:00
|
|
|
{
|
2016-08-23 01:06:46 +00:00
|
|
|
_qualifiers[0].id = COM_RESERVED_ID_TIMESTAMP;
|
|
|
|
_qualifiers[0].value = timestamp;
|
|
|
|
_qualifiers[0].maxDelta = timestampMaxDelta;
|
2016-04-12 19:11:34 +00:00
|
|
|
_qualifiers[1].id = COM_RESERVED_ID_NETWORK_ID;
|
|
|
|
_qualifiers[1].value = nwid;
|
|
|
|
_qualifiers[1].maxDelta = 0;
|
|
|
|
_qualifiers[2].id = COM_RESERVED_ID_ISSUED_TO;
|
|
|
|
_qualifiers[2].value = issuedTo.toInt();
|
|
|
|
_qualifiers[2].maxDelta = 0xffffffffffffffffULL;
|
|
|
|
_qualifierCount = 3;
|
2019-07-17 15:52:08 +00:00
|
|
|
_signatureLength = 0;
|
2013-10-16 21:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create from binary-serialized COM in buffer
|
|
|
|
*
|
|
|
|
* @param b Buffer to deserialize from
|
|
|
|
* @param startAt Position to start in buffer
|
|
|
|
*/
|
|
|
|
template<unsigned int C>
|
2019-08-14 17:35:57 +00:00
|
|
|
inline CertificateOfMembership(const Buffer<C> &b,unsigned int startAt = 0)
|
2013-10-16 21:47:26 +00:00
|
|
|
{
|
|
|
|
deserialize(b,startAt);
|
|
|
|
}
|
|
|
|
|
2013-10-18 16:01:48 +00:00
|
|
|
/**
|
|
|
|
* @return True if there's something here
|
|
|
|
*/
|
2017-04-04 15:07:38 +00:00
|
|
|
inline operator bool() const { return (_qualifierCount != 0); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Credential ID, always 0 for COMs
|
|
|
|
*/
|
|
|
|
inline uint32_t id() const { return 0; }
|
2013-10-18 16:01:48 +00:00
|
|
|
|
2013-10-07 20:13:52 +00:00
|
|
|
/**
|
2016-08-23 01:06:46 +00:00
|
|
|
* @return Timestamp for this cert and maximum delta for timestamp
|
2013-10-16 21:47:26 +00:00
|
|
|
*/
|
2017-10-02 22:52:57 +00:00
|
|
|
inline int64_t timestamp() const
|
2013-10-16 21:47:26 +00:00
|
|
|
{
|
2016-04-12 19:11:34 +00:00
|
|
|
for(unsigned int i=0;i<_qualifierCount;++i) {
|
2016-08-23 01:06:46 +00:00
|
|
|
if (_qualifiers[i].id == COM_RESERVED_ID_TIMESTAMP)
|
2019-08-14 21:55:37 +00:00
|
|
|
return (int64_t)_qualifiers[i].value;
|
2013-10-16 21:47:26 +00:00
|
|
|
}
|
2017-04-04 15:07:38 +00:00
|
|
|
return 0;
|
2013-10-16 21:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Address to which this cert was issued
|
|
|
|
*/
|
|
|
|
inline Address issuedTo() const
|
|
|
|
{
|
2016-04-12 19:11:34 +00:00
|
|
|
for(unsigned int i=0;i<_qualifierCount;++i) {
|
|
|
|
if (_qualifiers[i].id == COM_RESERVED_ID_ISSUED_TO)
|
|
|
|
return Address(_qualifiers[i].value);
|
2013-10-16 21:47:26 +00:00
|
|
|
}
|
|
|
|
return Address();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Network ID for which this cert was issued
|
|
|
|
*/
|
|
|
|
inline uint64_t networkId() const
|
|
|
|
{
|
2016-04-12 19:11:34 +00:00
|
|
|
for(unsigned int i=0;i<_qualifierCount;++i) {
|
|
|
|
if (_qualifiers[i].id == COM_RESERVED_ID_NETWORK_ID)
|
|
|
|
return _qualifiers[i].value;
|
2013-10-16 21:47:26 +00:00
|
|
|
}
|
|
|
|
return 0ULL;
|
|
|
|
}
|
|
|
|
|
2013-10-07 19:29:03 +00:00
|
|
|
/**
|
|
|
|
* Add or update a qualifier in this certificate
|
|
|
|
*
|
|
|
|
* Any signature is invalidated and signedBy is set to null.
|
|
|
|
*
|
|
|
|
* @param id Qualifier ID
|
|
|
|
* @param value Qualifier value
|
|
|
|
* @param maxDelta Qualifier maximum allowed difference (absolute value of difference)
|
|
|
|
*/
|
2019-08-14 21:55:37 +00:00
|
|
|
inline void setQualifier(uint64_t id,uint64_t value,uint64_t maxDelta)
|
|
|
|
{
|
|
|
|
_signedBy.zero();
|
|
|
|
for(unsigned int i=0;i<_qualifierCount;++i) {
|
|
|
|
if (_qualifiers[i].id == id) {
|
|
|
|
_qualifiers[i].value = value;
|
|
|
|
_qualifiers[i].maxDelta = maxDelta;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_qualifierCount < ZT_NETWORK_COM_MAX_QUALIFIERS) {
|
|
|
|
_qualifiers[_qualifierCount].id = id;
|
|
|
|
_qualifiers[_qualifierCount].value = value;
|
|
|
|
_qualifiers[_qualifierCount].maxDelta = maxDelta;
|
|
|
|
++_qualifierCount;
|
|
|
|
std::sort(&(_qualifiers[0]),&(_qualifiers[_qualifierCount]));
|
|
|
|
}
|
|
|
|
}
|
2013-10-07 19:29:03 +00:00
|
|
|
|
2019-08-14 21:55:37 +00:00
|
|
|
inline void setQualifier(ReservedId id,uint64_t value,uint64_t maxDelta) { setQualifier((uint64_t)id,value,maxDelta); }
|
2013-10-07 19:29:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare two certificates for parameter agreement
|
|
|
|
*
|
|
|
|
* This compares this certificate with the other and returns true if all
|
2018-06-08 00:25:27 +00:00
|
|
|
* parameters in this cert are present in the other and if they agree to
|
2013-10-07 19:29:03 +00:00
|
|
|
* within this cert's max delta value for each given parameter.
|
|
|
|
*
|
|
|
|
* Tuples present in other but not in this cert are ignored, but any
|
|
|
|
* tuples present in this cert but not in other result in 'false'.
|
|
|
|
*
|
|
|
|
* @param other Cert to compare with
|
|
|
|
* @return True if certs agree and 'other' may be communicated with
|
|
|
|
*/
|
2019-08-14 21:55:37 +00:00
|
|
|
inline bool agreesWith(const CertificateOfMembership &other) const
|
|
|
|
{
|
|
|
|
unsigned int myidx = 0;
|
|
|
|
unsigned int otheridx = 0;
|
|
|
|
|
|
|
|
if ((_qualifierCount == 0)||(other._qualifierCount == 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while (myidx < _qualifierCount) {
|
|
|
|
// Fail if we're at the end of other, since this means the field is
|
|
|
|
// missing.
|
|
|
|
if (otheridx >= other._qualifierCount)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Seek to corresponding tuple in other, ignoring tuples that
|
|
|
|
// we may not have. If we run off the end of other, the tuple is
|
|
|
|
// missing. This works because tuples are sorted by ID.
|
|
|
|
while (other._qualifiers[otheridx].id != _qualifiers[myidx].id) {
|
|
|
|
++otheridx;
|
|
|
|
if (otheridx >= other._qualifierCount)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare to determine if the absolute value of the difference
|
|
|
|
// between these two parameters is within our maxDelta.
|
|
|
|
const uint64_t a = _qualifiers[myidx].value;
|
|
|
|
const uint64_t b = other._qualifiers[myidx].value;
|
|
|
|
if (((a >= b) ? (a - b) : (b - a)) > _qualifiers[myidx].maxDelta)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
++myidx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-07 19:29:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sign this certificate
|
|
|
|
*
|
|
|
|
* @param with Identity to sign with, must include private key
|
|
|
|
* @return True if signature was successful
|
|
|
|
*/
|
2019-08-14 21:55:37 +00:00
|
|
|
inline bool sign(const Identity &with)
|
|
|
|
{
|
|
|
|
uint64_t buf[ZT_NETWORK_COM_MAX_QUALIFIERS * 3];
|
|
|
|
unsigned int ptr = 0;
|
|
|
|
for(unsigned int i=0;i<_qualifierCount;++i) {
|
|
|
|
buf[ptr++] = Utils::hton(_qualifiers[i].id);
|
|
|
|
buf[ptr++] = Utils::hton(_qualifiers[i].value);
|
|
|
|
buf[ptr++] = Utils::hton(_qualifiers[i].maxDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
_signatureLength = with.sign(buf,ptr * sizeof(uint64_t),_signature,sizeof(_signature));
|
|
|
|
_signedBy = with.address();
|
|
|
|
return true;
|
|
|
|
} catch ( ... ) {
|
|
|
|
_signedBy.zero();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-10-07 19:29:03 +00:00
|
|
|
|
|
|
|
/**
|
2016-08-04 16:02:35 +00:00
|
|
|
* Verify this COM and its signature
|
2013-10-07 19:29:03 +00:00
|
|
|
*
|
2016-08-04 16:02:35 +00:00
|
|
|
* @param RR Runtime environment for looking up peers
|
2017-03-28 00:03:17 +00:00
|
|
|
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
|
2013-10-07 19:29:03 +00:00
|
|
|
*/
|
2019-08-14 21:55:37 +00:00
|
|
|
inline Credential::VerifyResult verify(const RuntimeEnvironment *RR,void *tPtr) const { return _verify(RR,tPtr,*this); }
|
2013-10-07 19:29:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if signed
|
|
|
|
*/
|
2017-04-04 15:07:38 +00:00
|
|
|
inline bool isSigned() const { return (_signedBy); }
|
2013-10-07 19:29:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Address that signed this certificate or null address if none
|
|
|
|
*/
|
2017-04-04 15:07:38 +00:00
|
|
|
inline const Address &signedBy() const { return _signedBy; }
|
2013-10-07 19:29:03 +00:00
|
|
|
|
2013-10-07 20:13:52 +00:00
|
|
|
template<unsigned int C>
|
|
|
|
inline void serialize(Buffer<C> &b) const
|
|
|
|
{
|
2016-07-28 19:09:58 +00:00
|
|
|
b.append((uint8_t)1);
|
2016-04-12 19:11:34 +00:00
|
|
|
b.append((uint16_t)_qualifierCount);
|
|
|
|
for(unsigned int i=0;i<_qualifierCount;++i) {
|
|
|
|
b.append(_qualifiers[i].id);
|
|
|
|
b.append(_qualifiers[i].value);
|
|
|
|
b.append(_qualifiers[i].maxDelta);
|
2013-10-07 20:13:52 +00:00
|
|
|
}
|
|
|
|
_signedBy.appendTo(b);
|
2019-07-17 15:52:08 +00:00
|
|
|
if ((_signedBy)&&(_signatureLength == 96)) {
|
|
|
|
// UGLY: Ed25519 signatures in ZT are 96 bytes (64 + 32 bytes of hash).
|
|
|
|
// P-384 signatures are also 96 bytes, praise the horned one. That means
|
|
|
|
// we don't need to include a length. If we ever do we will need a new
|
|
|
|
// serialized object version, but only for those with length != 96.
|
|
|
|
b.append(_signature,96);
|
|
|
|
}
|
2013-10-07 20:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<unsigned int C>
|
|
|
|
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
|
|
|
|
{
|
|
|
|
unsigned int p = startAt;
|
|
|
|
|
|
|
|
_signedBy.zero();
|
2019-07-17 15:52:08 +00:00
|
|
|
_qualifierCount = 0;
|
|
|
|
_signatureLength = 0;
|
2013-10-07 20:13:52 +00:00
|
|
|
|
2016-07-28 19:09:58 +00:00
|
|
|
if (b[p++] != 1)
|
2017-07-17 21:21:09 +00:00
|
|
|
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE;
|
2013-10-07 20:13:52 +00:00
|
|
|
|
2013-10-16 21:47:26 +00:00
|
|
|
unsigned int numq = b.template at<uint16_t>(p); p += sizeof(uint16_t);
|
|
|
|
uint64_t lastId = 0;
|
2013-10-07 20:13:52 +00:00
|
|
|
for(unsigned int i=0;i<numq;++i) {
|
2016-04-12 19:11:34 +00:00
|
|
|
const uint64_t qid = b.template at<uint64_t>(p);
|
|
|
|
if (qid < lastId)
|
2017-07-17 21:21:09 +00:00
|
|
|
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_BAD_ENCODING;
|
2016-04-12 19:11:34 +00:00
|
|
|
else lastId = qid;
|
|
|
|
if (_qualifierCount < ZT_NETWORK_COM_MAX_QUALIFIERS) {
|
|
|
|
_qualifiers[_qualifierCount].id = qid;
|
|
|
|
_qualifiers[_qualifierCount].value = b.template at<uint64_t>(p + 8);
|
|
|
|
_qualifiers[_qualifierCount].maxDelta = b.template at<uint64_t>(p + 16);
|
|
|
|
p += 24;
|
|
|
|
++_qualifierCount;
|
|
|
|
} else {
|
2017-07-17 21:21:09 +00:00
|
|
|
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
|
2016-04-12 19:11:34 +00:00
|
|
|
}
|
2013-10-07 20:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_signedBy.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
|
|
|
p += ZT_ADDRESS_LENGTH;
|
|
|
|
|
|
|
|
if (_signedBy) {
|
2019-07-17 15:52:08 +00:00
|
|
|
// See "UGLY" comment in serialize()...
|
|
|
|
_signatureLength = 96;
|
|
|
|
memcpy(_signature,b.field(p,96),96);
|
|
|
|
p += 96;
|
2013-10-07 20:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (p - startAt);
|
|
|
|
}
|
|
|
|
|
2013-10-21 19:47:33 +00:00
|
|
|
inline bool operator==(const CertificateOfMembership &c) const
|
|
|
|
{
|
|
|
|
if (_signedBy != c._signedBy)
|
|
|
|
return false;
|
2016-04-12 19:11:34 +00:00
|
|
|
if (_qualifierCount != c._qualifierCount)
|
2013-10-21 19:47:33 +00:00
|
|
|
return false;
|
2019-07-17 15:52:08 +00:00
|
|
|
if (_signatureLength != c._signatureLength)
|
|
|
|
return false;
|
2016-04-12 19:11:34 +00:00
|
|
|
for(unsigned int i=0;i<_qualifierCount;++i) {
|
2013-10-21 19:47:33 +00:00
|
|
|
const _Qualifier &a = _qualifiers[i];
|
|
|
|
const _Qualifier &b = c._qualifiers[i];
|
|
|
|
if ((a.id != b.id)||(a.value != b.value)||(a.maxDelta != b.maxDelta))
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-17 15:52:08 +00:00
|
|
|
return (memcmp(_signature,c._signature,_signatureLength) == 0);
|
2013-10-21 19:47:33 +00:00
|
|
|
}
|
2017-04-04 15:07:38 +00:00
|
|
|
inline bool operator!=(const CertificateOfMembership &c) const { return (!(*this == c)); }
|
2013-10-21 19:47:33 +00:00
|
|
|
|
2013-10-07 19:29:03 +00:00
|
|
|
private:
|
|
|
|
struct _Qualifier
|
|
|
|
{
|
2016-04-12 19:11:34 +00:00
|
|
|
_Qualifier() : id(0),value(0),maxDelta(0) {}
|
2013-10-07 19:29:03 +00:00
|
|
|
uint64_t id;
|
|
|
|
uint64_t value;
|
|
|
|
uint64_t maxDelta;
|
2017-07-17 21:21:09 +00:00
|
|
|
inline bool operator<(const _Qualifier &q) const { return (id < q.id); } // sort order
|
2013-10-07 19:29:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Address _signedBy;
|
2016-04-12 19:11:34 +00:00
|
|
|
_Qualifier _qualifiers[ZT_NETWORK_COM_MAX_QUALIFIERS];
|
|
|
|
unsigned int _qualifierCount;
|
2019-07-17 15:52:08 +00:00
|
|
|
unsigned int _signatureLength;
|
|
|
|
uint8_t _signature[ZT_SIGNATURE_BUFFER_SIZE];
|
2013-10-07 19:29:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|
|
|
#endif
|