add the ability to set custom ca certificates

This commit is contained in:
Aaron Bieber 2024-09-22 10:23:57 -06:00
parent 256ca8c9a8
commit 1494131dfa
No known key found for this signature in database
6 changed files with 53 additions and 18 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.direnv .direnv
*.bak *.bak
*.apk
result result
tags tags
fass fass

View File

@ -5,3 +5,4 @@ Icon = "toggleswitch.png"
Name = "fass" Name = "fass"
ID = "dev.suah.fass" ID = "dev.suah.fass"
Version = "1.0.0" Version = "1.0.0"
Build = 5

View File

@ -26,7 +26,7 @@
version = "v0.0.0"; version = "v0.0.0";
src = ./.; src = ./.;
vendorHash = "sha256-RY8ExxmgfKdEcmV8FLM8mhr/CKAL3pPjgzW7zR1HCv4="; vendorHash = "sha256-gyY6JQn2r23Gwh0Dop5BoBT7TbZIxM2Ed+sC+yqTzDQ=";
nativeBuildInputs = [ pkg-config copyDesktopItems ]; nativeBuildInputs = [ pkg-config copyDesktopItems ];
buildInputs = [ buildInputs = [
@ -73,7 +73,7 @@
buildInputs = with pkgs; [ buildInputs = with pkgs; [
fyne fyne
git git
go_1_21 go
gopls gopls
go-tools go-tools
glxinfo glxinfo

6
go.mod
View File

@ -3,7 +3,7 @@ module suah.dev/fass
go 1.22.5 go 1.22.5
require ( require (
fyne.io/fyne/v2 v2.5.0 fyne.io/fyne/v2 v2.5.1
github.com/pawal/go-hass v0.0.0-20230221123149-b1b116a7432d github.com/pawal/go-hass v0.0.0-20230221123149-b1b116a7432d
) )
@ -18,7 +18,7 @@ require (
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/go-text/render v0.1.0 // indirect github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b // indirect
github.com/go-text/typesetting v0.1.0 // indirect github.com/go-text/typesetting v0.1.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect github.com/gopherjs/gopherjs v1.17.2 // indirect
@ -26,7 +26,7 @@ require (
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rymdport/portal v0.2.2 // indirect github.com/rymdport/portal v0.2.6 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/stretchr/testify v1.8.4 // indirect github.com/stretchr/testify v1.8.4 // indirect

12
go.sum
View File

@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
fyne.io/fyne/v2 v2.5.0 h1:lEjEIso0Vi4sJXYngIMoXOM6aUjqnPjK7pBpxRxG9aI= fyne.io/fyne/v2 v2.5.1 h1:jd2mhQz0ViosZjhgR5l2bdCbc5HFqkYnTzEXX8UOC7I=
fyne.io/fyne/v2 v2.5.0/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc= fyne.io/fyne/v2 v2.5.1/go.mod h1:NdxEG8L7EVWo06/cYbXW11uA0X7UG8Q8j5CLebvTZi8=
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg= fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg=
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs= fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@ -94,8 +94,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-text/render v0.1.0 h1:osrmVDZNHuP1RSu3pNG7Z77Sd2xSbcb/xWytAj9kyVs= github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b h1:daoFn+Aw8EIQZO9kYWwHL01FqwwpCl2nTeVEYbsgRHk=
github.com/go-text/render v0.1.0/go.mod h1:jqEuNMenrmj6QRnkdpeaP0oKGFLDNhDkVKwGjsWWYU4= github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b/go.mod h1:jqEuNMenrmj6QRnkdpeaP0oKGFLDNhDkVKwGjsWWYU4=
github.com/go-text/typesetting v0.1.0 h1:vioSaLPYcHwPEPLT7gsjCGDCoYSbljxoHJzMnKwVvHw= github.com/go-text/typesetting v0.1.0 h1:vioSaLPYcHwPEPLT7gsjCGDCoYSbljxoHJzMnKwVvHw=
github.com/go-text/typesetting v0.1.0/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI= github.com/go-text/typesetting v0.1.0/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3 h1:levTnuLLUmpavLGbJYLJA7fQnKeS7P1eCdAlM+vReXk= github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3 h1:levTnuLLUmpavLGbJYLJA7fQnKeS7P1eCdAlM+vReXk=
@ -249,8 +249,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/rymdport/portal v0.2.2 h1:P2Q/4k673zxdFAsbD8EESZ7psfuO6/4jNu6EDrDICkM= github.com/rymdport/portal v0.2.6 h1:HWmU3gORu7vWcpr7VSwUS2Xx1HtJXVcUuTqEZcMEsIg=
github.com/rymdport/portal v0.2.2/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4= github.com/rymdport/portal v0.2.6/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=

39
main.go
View File

@ -1,9 +1,13 @@
package main package main
import ( import (
"crypto/tls"
"crypto/x509"
"fmt" "fmt"
"io" "io"
"log" "log"
"net/http"
"time"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/app" "fyne.io/fyne/v2/app"
@ -71,20 +75,23 @@ func makeEntity(e hass.State, h *hass.Access) *widget.Card {
)) ))
} }
func loadSavedData(a fyne.App, input *widget.Entry, file string) { func loadSavedData(a fyne.App, w fyne.Window, input *widget.Entry, file string) {
uri, err := storage.Child(a.Storage().RootURI(), file) uri, err := storage.Child(a.Storage().RootURI(), file)
if err != nil { if err != nil {
dialog.ShowError(err, w)
return return
} }
reader, err := storage.Reader(uri) reader, err := storage.Reader(uri)
if err != nil { if err != nil {
dialog.ShowError(err, w)
return return
} }
defer reader.Close() defer reader.Close()
content, err := io.ReadAll(reader) content, err := io.ReadAll(reader)
if err != nil { if err != nil {
dialog.ShowError(err, w)
return return
} }
@ -126,15 +133,39 @@ func main() {
haExists, _ := storage.Exists(haFile) haExists, _ := storage.Exists(haFile)
tokenFile, _ := storage.Child(a.Storage().RootURI(), "hatoken") tokenFile, _ := storage.Child(a.Storage().RootURI(), "hatoken")
tkExists, _ := storage.Exists(tokenFile) tkExists, _ := storage.Exists(tokenFile)
certFile, _ := storage.Child(a.Storage().RootURI(), "haCAcert")
certExists, _ := storage.Exists(certFile)
urlEntry := widget.NewEntry() urlEntry := widget.NewEntry()
passEntry := widget.NewPasswordEntry() passEntry := widget.NewPasswordEntry()
certEntry := widget.NewMultiLineEntry()
loadSavedData(a, urlEntry, "haurl") loadSavedData(a, w, urlEntry, "haurl")
loadSavedData(a, passEntry, "hatoken") loadSavedData(a, w, passEntry, "hatoken")
loadSavedData(a, w, certEntry, "haCAcert")
h := hass.NewAccess(urlEntry.Text, "") h := hass.NewAccess(urlEntry.Text, "")
if haExists && tkExists { if haExists && tkExists {
if certExists {
rootCAs, _ := x509.SystemCertPool()
if rootCAs == nil {
rootCAs = x509.NewCertPool()
}
if ok := rootCAs.AppendCertsFromPEM([]byte(certEntry.Text)); !ok {
dialog.ShowError(fmt.Errorf("No certs appended, using system certs only"), w)
}
client := &http.Client{
Timeout: time.Second * 10,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: rootCAs,
},
},
}
h.SetClient(client)
}
h.SetBearerToken(passEntry.Text) h.SetBearerToken(passEntry.Text)
err := h.CheckAPI() err := h.CheckAPI()
if err != nil { if err != nil {
@ -148,9 +179,11 @@ func main() {
Items: []*widget.FormItem{ Items: []*widget.FormItem{
{Text: "Home Assistant URL:", Widget: urlEntry}, {Text: "Home Assistant URL:", Widget: urlEntry},
{Text: "Access Token:", Widget: passEntry}, {Text: "Access Token:", Widget: passEntry},
{Text: "CA Certificate:", Widget: certEntry},
{Text: "", Widget: widget.NewButton("Save", func() { {Text: "", Widget: widget.NewButton("Save", func() {
saveData(a, w, urlEntry, "haurl") saveData(a, w, urlEntry, "haurl")
saveData(a, w, passEntry, "hatoken") saveData(a, w, passEntry, "hatoken")
saveData(a, w, certEntry, "haCAcert")
})}, })},
}, },
} }