mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-31 08:48:17 +00:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user