mirror of
https://github.com/coalaura/up.git
synced 2025-07-17 21:44:35 +00:00
improvements
This commit is contained in:
@ -8,11 +8,13 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PinnedCertificate struct {
|
type PinnedCertificate struct {
|
||||||
@ -96,13 +98,13 @@ func LoadCertificateStore() (*CertificateStore, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
index := bytes.Index(line, []byte(" "))
|
fields := bytes.Fields(line)
|
||||||
if index == -1 {
|
if len(fields) != 2 {
|
||||||
return nil, fmt.Errorf("Invalid pinned certificate on line %d\n", index)
|
return nil, fmt.Errorf("Invalid pinned certificate on line %d\n", index)
|
||||||
}
|
}
|
||||||
|
|
||||||
name := line[:index]
|
name := bytes.ToLower(fields[0])
|
||||||
fingerprint := line[index:]
|
fingerprint := bytes.ToLower(fields[1])
|
||||||
|
|
||||||
if len(fingerprint) < 64 {
|
if len(fingerprint) < 64 {
|
||||||
return nil, fmt.Errorf("Invalid fingerprint on line %d\n", index)
|
return nil, fmt.Errorf("Invalid fingerprint on line %d\n", index)
|
||||||
@ -173,6 +175,11 @@ func NewPinnedClient(store *CertificateStore) *http.Client {
|
|||||||
return &http.Client{
|
return &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
TLSClientConfig: config,
|
TLSClientConfig: config,
|
||||||
|
Dial: (&net.Dialer{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}).Dial,
|
||||||
|
TLSHandshakeTimeout: 5 * time.Second,
|
||||||
|
IdleConnTimeout: 10 * time.Second,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,20 +74,26 @@ func run(_ context.Context, cmd *cli.Command) error {
|
|||||||
return fmt.Errorf("failed to load SSH config: %v", err)
|
return fmt.Errorf("failed to load SSH config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostname := hostArg
|
var (
|
||||||
identity := cmd.String("identity")
|
port string
|
||||||
|
hostname = hostArg
|
||||||
|
identity = cmd.String("identity")
|
||||||
|
)
|
||||||
|
|
||||||
if cfg != nil {
|
if index := strings.Index(hostArg, ":"); index != -1 {
|
||||||
if found, _ := cfg.Get(hostArg, "HostName"); found != "" {
|
hostname = hostname[:index]
|
||||||
hostname = found
|
port = hostArg[index+1:]
|
||||||
|
}
|
||||||
|
|
||||||
if port := strings.Index(hostname, ":"); port != -1 {
|
if found, _ := cfg.Get(hostname, "IdentityFile"); found != "" {
|
||||||
hostname = hostname[:port]
|
identity = found
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if found, _ := cfg.Get(hostArg, "IdentityFile"); found != "" {
|
if found, _ := cfg.Get(hostname, "HostName"); found != "" {
|
||||||
identity = found
|
hostname = found
|
||||||
|
|
||||||
|
if index := strings.Index(hostname, ":"); index != -1 {
|
||||||
|
hostname = hostname[:index]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +101,10 @@ func run(_ context.Context, cmd *cli.Command) error {
|
|||||||
return errors.New("missing or invalid host")
|
return errors.New("missing or invalid host")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if port != "" {
|
||||||
|
hostname += ":" + port
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("Using host: %s\n", hostname)
|
log.Printf("Using host: %s\n", hostname)
|
||||||
|
|
||||||
if identity == "" {
|
if identity == "" {
|
||||||
|
Reference in New Issue
Block a user