fix(agent): make discovery enrollment compatible and idempotent (#53)

* fix(agent): make discovery enrollment compatible and idempotent

* fix(agent): confirm enrollment persistence and document token aliases
This commit is contained in:
ArthurKoba
2026-11-07 16:29:47 +03:00
committed by GitHub
parent 1ca03df0ef
commit 72d67c80f2
30 changed files with 1324 additions and 71 deletions
@@ -0,0 +1,25 @@
// Copyright 2026 Arctel.net
// SPDX-License-Identifier: Apache-2.0
package agent
import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"errors"
)
const registrationKeyBytes = 32
// discoveryIdentity derives separate public identity and private credential from a random retry secret.
// Public node IDs cannot be used as registration keys to recover credentials.
func discoveryIdentity(key string) (string, string, error) {
decoded, err := hex.DecodeString(key)
if err != nil || len(decoded) != registrationKeyBytes {
return "", "", errors.New(errRegistrationKeyInvalid)
}
nodeHash := sha256.Sum256(append([]byte("openflare:discovery:node:v1:"), decoded...))
tokenHash := sha256.Sum256(append([]byte("openflare:discovery:token:v1:"), decoded...))
return "node-" + base64.RawURLEncoding.EncodeToString(nodeHash[:]), hex.EncodeToString(tokenHash[:]), nil
}