mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 23:04:24 +08:00
72d67c80f2
* fix(agent): make discovery enrollment compatible and idempotent * fix(agent): confirm enrollment persistence and document token aliases
26 lines
875 B
Go
26 lines
875 B
Go
// 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
|
|
}
|