fixes to identities

* include a hash in "identity list"
* fixed using identities on a folder
This commit is contained in:
tjp 2024-01-10 11:04:52 -07:00
parent aa46d49b89
commit 99a0553452
2 changed files with 18 additions and 6 deletions

View File

@ -2,12 +2,12 @@ package main
import (
"bytes"
"crypto/sha256"
"crypto/tls"
"encoding/hex"
"errors"
"fmt"
"io"
"net/url"
"os"
"strings"
)
@ -43,6 +43,9 @@ func (ids Identities) Get(u *url.URL) *tls.Config {
return conf
}
if conf, ok := ids.ByFolder[u.Hostname()+u.Path]; ok {
return conf
}
pathsegments := strings.Split(strings.TrimLeft(u.Path, "/"), "/")
for len(pathsegments) > 0 {
pathsegments = pathsegments[0 : len(pathsegments)-1]
@ -70,7 +73,7 @@ func IdentityCreate(state *BrowserState, name string) error {
func IdentityList(state *BrowserState) error {
buf := &bytes.Buffer{}
for name, ident := range state.Identities.ByName {
if _, err := fmt.Fprintf(buf, "%s:\n", name); err != nil {
if _, err := fmt.Fprintf(buf, "%s (%s):\n", name, showIdent(ident)); err != nil {
return err
}
@ -97,8 +100,11 @@ func IdentityList(state *BrowserState) error {
}
}
_, err := io.Copy(os.Stdout, buf)
return err
state.Modal = buf.Bytes()
if len(state.Modal) == 0 {
state.Modal = []byte("(empty)\n")
}
return Print(state)
}
func IdentityDelete(state *BrowserState, name string) error {
@ -176,7 +182,7 @@ func IdentityUseFolder(state *BrowserState, name string, domain string) error {
return err
}
state.Identities.ByFolder[fmt.Sprintf("%s/%s", u.Hostname(), u.Path)] = ident
state.Identities.ByFolder[u.Hostname()+u.Path] = ident
return saveIdentities(state.Identities)
}
@ -203,3 +209,8 @@ func IdentityUsePage(state *BrowserState, name string, domain string) error {
state.Identities.ByPage[u.String()] = ident
return saveIdentities(state.Identities)
}
func showIdent(ident *tls.Config) string {
hash := sha256.Sum256(ident.Certificates[0].Certificate[0])
return strings.ToUpper(hex.EncodeToString(hash[:])[:10])
}

1
tls.go
View File

@ -98,6 +98,7 @@ func createIdentity(state *BrowserState, name string) (*tls.Config, error) {
Subject: pkix.Name{CommonName: commonName},
NotAfter: expiration,
KeyUsage: x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
BasicConstraintsValid: true,
}