netbirdio/netbird · error
invalid key length: expected 32 bytes, got
Error message
invalid key length: expected 32 bytes, got %d
What it means
Guard in hexToWireguardKey: the input decoded to valid hex but not exactly 32 bytes, so it cannot be a WireGuard key. This indicates corrupted or truncated key data in the userspace status output; parseStatus stops rather than using a wrong-length key.
Solutions
- Reject the peer entry with the bad key
- Verify the key source emits 64 hex chars (32 bytes)
- Log key length seen to trace the producer
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at client/iface/configurer/usp.go:519 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16).
Data as JSON: /api/errors/fc1fb1890fb7b9a4.
Report an issue: GitHub.
Appendix: source
Thrown at client/iface/configurer/usp.go:519
}
func getFwmark() int {
if nbnet.AdvancedRouting() && runtime.GOOS == "linux" {
return nbnet.ControlPlaneMark
}
return 0
}
func hexToWireguardKey(hexKey string) (wgtypes.Key, error) {
// Decode hex string to bytes
keyBytes, err := hex.DecodeString(hexKey)
if err != nil {
return wgtypes.Key{}, fmt.Errorf("failed to decode hex key: %w", err)
}
// Check if we have the right number of bytes (WireGuard keys are 32 bytes)
if len(keyBytes) != 32 {
return wgtypes.Key{}, fmt.Errorf("invalid key length: expected 32 bytes, got %d", len(keyBytes))
}
// Convert to wgtypes.Key
var key wgtypes.Key
copy(key[:], keyBytes)
return key, nil
}
func parseStatus(deviceName, ipcStr string) (*Stats, error) {
stats := &Stats{DeviceName: deviceName}
var currentPeer *Peer
for _, line := range strings.Split(strings.TrimSpace(ipcStr), "\n") {
if line == "" {
continue
}
parts := strings.SplitN(line, "=", 2)
if len(parts) != 2 {View on GitHub (pinned to 93e97f4bf1)