Merge branch 'client-certs' of sloum/bombadillo into develop
This commit is contained in:
commit
b48ad3168e
|
@ -403,6 +403,9 @@ func (c *client) doCommandAs(action string, values []string) {
|
|||
return
|
||||
}
|
||||
c.Options[values[0]] = lowerCaseOpt(values[0], val)
|
||||
if values[0] == "tlskey" || values[0] == "tlscertificate" {
|
||||
c.Certs.LoadCertificate(c.Options["tlscertificate"], c.Options["tlskey"])
|
||||
}
|
||||
err := saveConfig()
|
||||
if err != nil {
|
||||
c.SetMessage("Value set, but error saving config to file", true)
|
||||
|
|
|
@ -21,5 +21,7 @@ var defaultOptions = map[string]string{
|
|||
"configlocation": userinfo.HomeDir,
|
||||
"theme": "normal", // "normal", "inverted"
|
||||
"terminalonly": "true",
|
||||
"tlscertificate": "",
|
||||
"tlskey": "",
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ type Capsule struct {
|
|||
|
||||
|
||||
type TofuDigest struct {
|
||||
certs map[string]string
|
||||
certs map[string]string
|
||||
ClientCert tls.Certificate
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,6 +31,15 @@ type TofuDigest struct {
|
|||
// + + + R E C E I V E R S + + + \\
|
||||
//--------------------------------------------------\\
|
||||
|
||||
func (t *TofuDigest) LoadCertificate(cert, key string) {
|
||||
certificate, err := tls.LoadX509KeyPair(cert, key)
|
||||
if err != nil {
|
||||
t.ClientCert = tls.Certificate{}
|
||||
return
|
||||
}
|
||||
t.ClientCert = certificate
|
||||
}
|
||||
|
||||
func (t *TofuDigest) Purge(host string) error {
|
||||
host = strings.ToLower(host)
|
||||
if host == "*" {
|
||||
|
@ -144,6 +154,10 @@ func Retrieve(host, port, resource string, td *TofuDigest) (string, error) {
|
|||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
conf.GetClientCertificate = func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
|
||||
return &td.ClientCert, nil
|
||||
}
|
||||
|
||||
conn, err := tls.Dial("tcp", addr, conf)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -383,5 +397,5 @@ func MakeCapsule() Capsule {
|
|||
}
|
||||
|
||||
func MakeTofuDigest() TofuDigest {
|
||||
return TofuDigest{make(map[string]string)}
|
||||
return TofuDigest{make(map[string]string), tls.Certificate{}}
|
||||
}
|
||||
|
|
4
go.mod
4
go.mod
|
@ -1,3 +1,5 @@
|
|||
module tildegit.org/sloum/bombadillo
|
||||
|
||||
go 1.10
|
||||
go 1.12
|
||||
|
||||
require tildegit.org/sloum/mailcap v0.0.0-20190706214029-b787a49e9db2
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
tildegit.org/sloum/mailcap v0.0.0-20190706214029-b787a49e9db2 h1:tAPIFBpXwOq1Ytxk8aGsDjCutnwUC01BVkK77QS1bdU=
|
||||
tildegit.org/sloum/mailcap v0.0.0-20190706214029-b787a49e9db2/go.mod h1:m4etAw9DbXsdanDUNS8oERhL+7y4II82ZLHWzw2yibg=
|
3
main.go
3
main.go
|
@ -138,6 +138,9 @@ func initClient() error {
|
|||
bombadillo = MakeClient(" ((( Bombadillo ))) ")
|
||||
cui.SetCharMode()
|
||||
err := loadConfig()
|
||||
if bombadillo.Options["tlscertificate"] != "" && bombadillo.Options["tlskey"] != "" {
|
||||
bombadillo.Certs.LoadCertificate(bombadillo.Options["tlscertificate"], bombadillo.Options["tlskey"])
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue