diff --git a/doc/SECURITY.md b/doc/SECURITY.md index b97b3e6c5..b81d0830f 100644 --- a/doc/SECURITY.md +++ b/doc/SECURITY.md @@ -27,7 +27,7 @@ A ZeroTier identity is comprised of one or more cryptographic public keys and a #### Identity Types and Corresponding Algorithms * **Type 0** (v1.x and v2.x): one Curve25519 key for elliptic curve Diffie-Hellman and one Ed25519 key for Ed25519 signatures, with the address and fingerprint computed from a hash of both. -* **Type 1** (v2.x only): Curve25519, Ed25519, and NIST P-384 public keys, with the latter being used for signatures (the Ed25519 key is still there but is presently unused) and with *both* keys being used for elliptic curve Diffie-Hellman key agreement. In key agreement the resulting raw secret keys are hashed together using SHA-384 to combine them and yield a single session key. +* **Type 1** (v2.x only): Curve25519, Ed25519, and NIST P-384 public keys, with the latter being used for signatures (the Ed25519 key is still there but is presently unused) and with *both* Curve25519 and NIST P-384 being used for elliptic curve Diffie-Hellman key agreement. In key agreement the resulting raw secret keys are hashed together using SHA-384 to combine them and yield a single session key. Session keys resulting from identity key exchange and agreement are *long-lived keys* that remain static for the lifetime of a particular pair of identities. A different mechanism is used for ephemeral key negotiation. @@ -52,6 +52,8 @@ bzg7fc3sn46fzyxcxw2ev4c4m2u5fyisb3o4wz5hfmvexbzwk6et3fsglkdcn6nnjobxi3bq7hgxqox3 These are too large to type but not to copy/paste, store in databases, or use in scripts and APIs. +Once a device has joined a network, network controllers will remember and check its full identity or identity fingerprint (depending on implementation) rather than just the device's ZeroTier address. + ## VL1 Wire Protocol ZeroTier's wire protocol is packet based with packets having the following format: diff --git a/go/cmd/zerotier-fuzz/zerotier-fuzz.go b/go/cmd/zerotier-fuzz/zerotier-fuzz.go new file mode 100644 index 000000000..da29a2cad --- /dev/null +++ b/go/cmd/zerotier-fuzz/zerotier-fuzz.go @@ -0,0 +1,4 @@ +package main + +func main() { +} diff --git a/go/cmd/zerotier/cli/help.go b/go/cmd/zerotier/cli/help.go index f3a3bb2cd..924deb543 100644 --- a/go/cmd/zerotier/cli/help.go +++ b/go/cmd/zerotier/cli/help.go @@ -37,7 +37,6 @@ Global Options: Commands: help Show this help version Print version - selftest Run internal tests service Start as service status Show ZeroTier status and config peers Show VL1 peers and link information diff --git a/go/cmd/zerotier/cli/selftest.go b/go/cmd/zerotier/cli/selftest.go deleted file mode 100644 index 0f0a0d529..000000000 --- a/go/cmd/zerotier/cli/selftest.go +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c)2013-2020 ZeroTier, Inc. - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file in the project's root directory. - * - * Change Date: 2024-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2.0 of the Apache License. - */ -/****/ - -package cli - -import ( - "fmt" - "os" - - "zerotier/pkg/zerotier" -) - -func SelfTest() { - if !zerotier.SelfTest() { - fmt.Println("FAILED: at least one ZeroTier self-test reported failure.") - os.Exit(1) - } - os.Exit(0) -} diff --git a/go/cmd/zerotier/zerotier.go b/go/cmd/zerotier/zerotier.go index 293bbffd2..f9bddc176 100644 --- a/go/cmd/zerotier/zerotier.go +++ b/go/cmd/zerotier/zerotier.go @@ -123,9 +123,6 @@ func main() { case "version": fmt.Printf("%d.%d.%d\n", zerotier.CoreVersionMajor, zerotier.CoreVersionMinor, zerotier.CoreVersionRevision) os.Exit(0) - case "selftest": - cli.SelfTest() - os.Exit(0) case "service": cli.Service(basePath, authToken, cmdArgs) case "status": diff --git a/go/pkg/zerotier/identity.go b/go/pkg/zerotier/identity.go index 65ee53bc5..1d7dd35de 100644 --- a/go/pkg/zerotier/identity.go +++ b/go/pkg/zerotier/identity.go @@ -46,7 +46,7 @@ type Identity struct { idtype int publicKey []byte privateKey []byte - cid unsafe.Pointer + cid unsafe.Pointer // ZT_Identity } func identityFinalizer(obj interface{}) { diff --git a/go/pkg/zerotier/localconfig.go b/go/pkg/zerotier/localconfig.go index 17bd1d0e2..7f5165324 100644 --- a/go/pkg/zerotier/localconfig.go +++ b/go/pkg/zerotier/localconfig.go @@ -45,10 +45,10 @@ type ExternalAddress struct { // LocalConfigSettings contains node settings type LocalConfigSettings struct { - // PrimaryPort is the main UDP port and must be set (defaults to 9993) + // PrimaryPort is the main UDP port and must be set. PrimaryPort int `json:"primaryPort"` - // SecondaryPort is the secondary UDP port, set to 0 to disbale (picked at random by default) + // SecondaryPort is the secondary UDP port, set to 0 to disable (picked at random by default) SecondaryPort int `json:"secondaryPort"` // PortSearch causes ZeroTier to try other ports automatically if it can't bind to configured ports @@ -100,6 +100,10 @@ func (lc *LocalConfig) Read(p string, saveDefaultsIfNotExist bool, isTotallyNewN if isTotallyNewNode { lc.Settings.PrimaryPort = 793 } else { + // For legacy reasons we keep nodes that already existed prior to 2.0 (upgraded nodes) + // at 9993 by default if there is no existing primary port configured. This is for + // principle of least surprise since some admins may have special firewall rules for + // this port. lc.Settings.PrimaryPort = 9993 } lc.Settings.SecondaryPort = unassignedPrivilegedPorts[randomUInt()%uint(len(unassignedPrivilegedPorts))] diff --git a/node/AES.cpp b/node/AES.cpp index 641ef06ea..9fa6a9456 100644 --- a/node/AES.cpp +++ b/node/AES.cpp @@ -899,7 +899,7 @@ void AES::CTR::finish() noexcept // Software AES and AES key expansion --------------------------------------------------------------------------------- #ifdef ZT_NO_UNALIGNED_ACCESS -static inline uint32_t readuint32_t(const void *in) +static ZT_INLINE uint32_t readuint32_t(const void *in) { uint32_t v = ((const uint8_t *)in)[0]; v <<= 8; @@ -910,7 +910,7 @@ static inline uint32_t readuint32_t(const void *in) v |= ((const uint8_t *)in)[3]; return v; } -static inline void writeuint32_t(void *out,const uint32_t v) +static ZT_INLINE void writeuint32_t(void *out,const uint32_t v) { ((uint8_t *)out)[0] = (uint8_t)(v >> 24); ((uint8_t *)out)[1] = (uint8_t)(v >> 16); diff --git a/node/Address.hpp b/node/Address.hpp index 61a2527f6..66fa9fc17 100644 --- a/node/Address.hpp +++ b/node/Address.hpp @@ -24,6 +24,8 @@ namespace ZeroTier { /** * A ZeroTier address + * + * This is merely a 40-bit short address packed into a uint64_t and wrapped with methods. */ class Address : public TriviallyCopyable { diff --git a/node/LZ4.hpp b/node/LZ4.hpp deleted file mode 100644 index 227dce627..000000000 --- a/node/LZ4.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c)2013-2020 ZeroTier, Inc. - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file in the project's root directory. - * - * Change Date: 2024-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2.0 of the Apache License. - */ -/****/ - -#ifndef ZT_LZ4_HPP -#define ZT_LZ4_HPP - -#include "Constants.hpp" - -namespace ZeroTier { - -int LZ4_compress_fast(const char *source,char *dest,int inputSize,int maxOutputSize,int acceleration = 1) noexcept; -int LZ4_decompress_safe(const char *source,char *dest,int compressedSize,int maxDecompressedSize) noexcept; - -} // namespace ZeroTier - -#endif diff --git a/node/Node.cpp b/node/Node.cpp index 6e3544319..649861570 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -36,6 +36,13 @@ namespace ZeroTier { namespace { +/** + * All core objects of a ZeroTier node. + * + * This is just a box that allows us to allocate all core objects + * and data structures at once for a bit of memory saves and improved + * cache adjacency. + */ struct _NodeObjects { ZT_INLINE _NodeObjects(RuntimeEnvironment *const RR,void *const tPtr) : @@ -190,11 +197,17 @@ ZT_ResultCode Node::processVirtualNetworkFrame( } } -struct _processBackgroundTasks_ping_eachPeer +struct _processBackgroundTasks_eachPeer { - int64_t now; - Node *parent; - void *tPtr; + ZT_INLINE _processBackgroundTasks_eachPeer(const int64_t now_,Node *const parent_,void *const tPtr_) : + now(now_), + parent(parent_), + tPtr(tPtr_), + online(false), + rootsNotOnline() {} + const int64_t now; + Node *const parent; + void *const tPtr; bool online; std::vector
rootsNotOnline; ZT_INLINE void operator()(const SharedPtr