MCPcopy Index your code
hub / github.com/coder/coder / SSHKeySeed

Function SSHKeySeed

agent/agent.go:2561–2587  ·  view source on GitHub ↗

SSHKeySeed converts an owner userName, workspaceName and agentName to an int64 hash. This uses the FNV-1a hash algorithm which provides decent distribution and collision resistance for string inputs. Why owner username, workspace name, and agent name? These are the components that are used in hostn

(userName, workspaceName, agentName string)

Source from the content-addressed store, hash-verified

2559// The agent UUID is regenerated on each build. Since Coder's Tailnet networking is handling the authentication, we
2560// should not be showing users warnings about host SSH keys.
2561func SSHKeySeed(userName, workspaceName, agentName string) (int64, error) {
2562 h := fnv.New64a()
2563 _, err := h.Write([]byte(userName))
2564 if err != nil {
2565 return 42, err
2566 }
2567 // null separators between strings so that (dog, foodstuff) is distinct from (dogfood, stuff)
2568 _, err = h.Write([]byte{0})
2569 if err != nil {
2570 return 42, err
2571 }
2572 _, err = h.Write([]byte(workspaceName))
2573 if err != nil {
2574 return 42, err
2575 }
2576 _, err = h.Write([]byte{0})
2577 if err != nil {
2578 return 42, err
2579 }
2580 _, err = h.Write([]byte(agentName))
2581 if err != nil {
2582 return 42, err
2583 }
2584
2585 // #nosec G115 - Safe conversion to generate int64 hash from Sum64, data loss acceptable
2586 return int64(h.Sum64()), nil
2587}

Callers 2

TestSSHFunction · 0.92
createOrUpdateNetworkMethod · 0.85

Calls 1

WriteMethod · 0.65

Tested by 1

TestSSHFunction · 0.74