mirror of
https://github.com/syncthing/syncthing.git
synced 2026-11-29 13:22:53 -08:00
3 files changed
+12
-8
No files matched your search
@@ -19,14 +19,19 @@ import (
|
||||
"golang.org/x/crypto/hkdf"
|
||||
)
|
||||
|
||||
const (
|
||||
discoveryKeySalt = "syncthing-dht-record-key-v1"
|
||||
encryptionKeySalt = "syncthing-dht-encryption-key-v1"
|
||||
)
|
||||
|
||||
// deriveRecordKey derives the daily discovery lookup key for id.
|
||||
func deriveRecordKey(id protocol.DeviceID, date time.Time) [32]byte {
|
||||
return deriveDiscoveryKey(id, date, "syncthing-dht-record-key-v1")
|
||||
return deriveDiscoveryKey(id, date, discoveryKeySalt)
|
||||
}
|
||||
|
||||
// deriveEncryptionKey derives the daily record encryption key for id.
|
||||
func deriveEncryptionKey(id protocol.DeviceID, date time.Time) [32]byte {
|
||||
return deriveDiscoveryKey(id, date, "syncthing-dht-encryption-key-v1")
|
||||
return deriveDiscoveryKey(id, date, encryptionKeySalt)
|
||||
}
|
||||
|
||||
func deriveDiscoveryKey(id protocol.DeviceID, date time.Time, salt string) [32]byte {
|
||||
@@ -84,7 +89,7 @@ func (c *discoveryKeyCache) get(id protocol.DeviceID, date time.Time) discoveryK
|
||||
// discoveryDay staggers daily rotation across devices. The first eight bytes
|
||||
// of the device ID select a cutoff in seconds after UTC midnight.
|
||||
func discoveryDay(id protocol.DeviceID, now time.Time) string {
|
||||
offset := time.Duration(binary.BigEndian.Uint64(id[:8])%(24*60*60)) * time.Second
|
||||
offset := time.Duration(binary.BigEndian.Uint64(id[:8])%86400) * time.Second
|
||||
return now.UTC().Add(-offset).Format(time.DateOnly)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
func TestDiscoveryKeyDerivation(t *testing.T) {
|
||||
id := protocol.NewDeviceID([]byte("test certificate"))
|
||||
offset := time.Duration(binary.BigEndian.Uint64(id[:8])%(24*60*60)) * time.Second
|
||||
offset := time.Duration(binary.BigEndian.Uint64(id[:8])%84600) * time.Second
|
||||
date := time.Date(2026, time.November, 16, 0, 0, 0, 0, time.UTC).Add(offset)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
|
||||
@@ -30,8 +30,9 @@ import (
|
||||
const (
|
||||
RecordLifetime = 2 * time.Hour
|
||||
|
||||
dhtRecordNamespace = "device"
|
||||
dhtSignatureDomain = "syncthing-dht-discovery-v1\x00"
|
||||
dhtRecordNamespace = "device"
|
||||
dhtSignatureDomain = "syncthing-dht-discovery-v1\x00"
|
||||
encryptedRecordDomain = "syncthing-dht-encrypted-record-v1\x00"
|
||||
)
|
||||
|
||||
// dhtRecordKey encodes the public half of the daily record signing key.
|
||||
@@ -157,8 +158,6 @@ func dhtSignatureAlgorithm(public crypto.PublicKey) (x509.SignatureAlgorithm, er
|
||||
// them from the network
|
||||
type dhtRecordValidator struct{}
|
||||
|
||||
const encryptedRecordDomain = "syncthing-dht-encrypted-record-v1\x00"
|
||||
|
||||
// wrapperMetadata is also used as AEAD additional data, binding encryption
|
||||
// to the wrapper version, sequence and expiration.
|
||||
func wrapperMetadata(w *discoproto.DHTWrapper) ([]byte, error) {
|
||||
|
||||
Reference in new issue
Block a user