AlexxIT/go2rtc · error
hap: wrong PIN format:
Error message
hap: wrong PIN format:
What it means
HAP SanitizePin format guard: after stripping dashes, the PIN is not exactly 8 characters (the HAP standard setup-code length). The offending PIN is appended. Purely an input-format check — credentials were supplied in the wrong shape before any server contact.
Solutions
- Provide the setup code as 8 digits, optionally dashed (e.g. 123-45-678)
- Strip spaces or other characters introduced by copy-paste
- Validate the PIN field in config/UI before calling Init or Pair
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pkg/hap/helpers.go:82 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/e75200bc46046acd.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/hap/helpers.go:82
type JSONCharacters struct {
Value []JSONCharacter `json:"characteristics"`
}
type JSONCharacter struct {
AID uint8 `json:"aid"`
IID uint64 `json:"iid"`
Status any `json:"status,omitempty"`
Value any `json:"value,omitempty"`
Event any `json:"ev,omitempty"`
}
// 4.2.1.2 Invalid Setup Codes
const insecurePINs = "00000000 11111111 22222222 33333333 44444444 55555555 66666666 77777777 88888888 99999999 12345678 87654321"
func SanitizePin(pin string) (string, error) {
s := strings.ReplaceAll(pin, "-", "")
if len(s) != 8 {
return "", errors.New("hap: wrong PIN format: " + pin)
}
if strings.Contains(insecurePINs, s) {
return "", errors.New("hap: insecure PIN: " + pin)
}
// 123-45-678
return s[:3] + "-" + s[3:5] + "-" + s[5:], nil
}
func GenerateKey() []byte {
_, key, _ := ed25519.GenerateKey(nil)
return key
}
func GenerateUUID() string {
//12345678-9012-3456-7890-123456789012
data := make([]byte, 16)
_, _ = rand.Read(data)
s := hex.EncodeToString(data)View on GitHub (pinned to c245815e75)