netbirdio/netbird · error

failed to decode hex key

Error message

failed to decode hex key: %w

What it means

hexToWireguardKey got a peer public key string from the wireguard-go status output that is not valid hexadecimal, so hex.DecodeString failed. A wgtypes.Key cannot be produced and the caller (parseStatus) aborts, since peer records with unparseable keys cannot be matched or displayed.

Solutions

  1. Validate the key is 64 hex characters before decoding
  2. Skip the malformed peer entry
  3. Check for UAPI stream corruption
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at client/iface/configurer/usp.go:514 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16). Data as JSON: /api/errors/14990b8b871a7871. Report an issue: GitHub.

Appendix: source

Thrown at client/iface/configurer/usp.go:514

	return time.Unix(sec, 0), nil
}

func toBytes(s string) (int64, error) {
	return strconv.ParseInt(s, 10, 64)
}

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") {

View on GitHub (pinned to 93e97f4bf1)