4
0

pairproof.go 873 B

12345678910111213141516171819202122232425
  1. // Package pairproof is the proof a NetPulse server gives, at pairing, that
  2. // the key it serves is the real server's: an HMAC keyed with the pairing
  3. // token, which only the server and the admin who copied it know. The agent
  4. // and the server both compute it here, so the two cannot drift apart.
  5. //
  6. // FORK: see runtime.ProveServerKey for the exchange.
  7. package pairproof
  8. import (
  9. "crypto/hmac"
  10. "crypto/sha256"
  11. "encoding/hex"
  12. "fmt"
  13. )
  14. // Label separates this MAC from any other use of the pairing token.
  15. const Label = "netpulse-pair-v1"
  16. // MAC is HMAC-SHA256 keyed with the pairing token over the label, the
  17. // agent's nonce and the server's key fingerprint, in hex.
  18. func MAC(pairingToken, nonce, serverFP string) string {
  19. m := hmac.New(sha256.New, []byte(pairingToken))
  20. fmt.Fprintf(m, "%s\n%s\n%s", Label, nonce, serverFP)
  21. return hex.EncodeToString(m.Sum(nil))
  22. }