Use a more secure PIN config by default

The server used to use the hap default PIN, but using a fixed PIN is not
secure. A random PIN is now generated on first run and displayed to the
console (or journal), similar to how homebridge does it. It can also be
specified explicitly by the user in the config file.
This commit is contained in:
Darell Tan
2023-08-12 01:35:07 +08:00
parent fe5d0ce14c
commit 1fbc4d520a
3 changed files with 73 additions and 0 deletions

View File

@@ -36,6 +36,8 @@ type config struct {
ListenAddr string
Interfaces []string
Pin string
Server, Username, Password string
}
@@ -89,6 +91,10 @@ func main() {
log.Fatalf("-quiet and -debug options are mutually-exclusive")
}
if _, err := br.SetPin(cfg.Pin); err != nil {
log.Fatalf("cannot set PIN code: %v", err)
}
// validate ListenAddr if specified
if cfg.ListenAddr != "" {
_, _, err := net.SplitHostPort(cfg.ListenAddr)
@@ -120,6 +126,9 @@ func main() {
log.Println("hapz2m configured. starting HAP server...")
pin := br.GetPin()
log.Printf("server PIN is %s-%s", pin[:4], pin[4:])
err = br.StartHAP()
if err != nil {
if err == http.ErrServerClosed {