1
0
mirror of https://github.com/coalaura/up.git synced 2025-07-17 21:44:35 +00:00

improvements

This commit is contained in:
Laura
2025-06-20 19:39:05 +02:00
parent a1c89b6511
commit d14c200b56
2 changed files with 32 additions and 15 deletions

View File

@ -8,11 +8,13 @@ import (
"encoding/hex"
"errors"
"fmt"
"net"
"net/http"
"os"
"path/filepath"
"strings"
"sync"
"time"
)
type PinnedCertificate struct {
@ -96,13 +98,13 @@ func LoadCertificateStore() (*CertificateStore, error) {
continue
}
index := bytes.Index(line, []byte(" "))
if index == -1 {
fields := bytes.Fields(line)
if len(fields) != 2 {
return nil, fmt.Errorf("Invalid pinned certificate on line %d\n", index)
}
name := line[:index]
fingerprint := line[index:]
name := bytes.ToLower(fields[0])
fingerprint := bytes.ToLower(fields[1])
if len(fingerprint) < 64 {
return nil, fmt.Errorf("Invalid fingerprint on line %d\n", index)
@ -173,6 +175,11 @@ func NewPinnedClient(store *CertificateStore) *http.Client {
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: config,
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
IdleConnTimeout: 10 * time.Second,
},
}
}