mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Load client certs early to detect misconfiguration
* Move loading of client certificate into the TLS handling code to an earlier position.
This commit is contained in:
parent
be15d43dd3
commit
1241429d19
2 changed files with 19 additions and 6 deletions
|
|
@ -10,6 +10,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"crypto/tls"
|
||||||
_ "embed" // Used for embedding.
|
_ "embed" // Used for embedding.
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -35,6 +36,8 @@ type options struct {
|
||||||
Verbose bool `long:"verbose" short:"v" description:"Verbose output"`
|
Verbose bool `long:"verbose" short:"v" description:"Verbose output"`
|
||||||
Rate *float64 `long:"rate" short:"r" description:"The average upper limit of https operations per second"`
|
Rate *float64 `long:"rate" short:"r" description:"The average upper limit of https operations per second"`
|
||||||
Years *uint `long:"years" short:"y" description:"Number of years to look back from now" value-name:"YEARS"`
|
Years *uint `long:"years" short:"y" description:"Number of years to look back from now" value-name:"YEARS"`
|
||||||
|
|
||||||
|
clientCerts []tls.Certificate
|
||||||
}
|
}
|
||||||
|
|
||||||
func errCheck(err error) {
|
func errCheck(err error) {
|
||||||
|
|
@ -46,6 +49,18 @@ func errCheck(err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *options) prepare() error {
|
||||||
|
// Load client certs.
|
||||||
|
if o.ClientCert != nil && o.ClientKey != nil {
|
||||||
|
cert, err := tls.LoadX509KeyPair(*o.ClientCert, *o.ClientKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
o.clientCerts = []tls.Certificate{cert}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// writeJSON writes the JSON encoding of the given report to the given stream.
|
// writeJSON writes the JSON encoding of the given report to the given stream.
|
||||||
// It returns nil, otherwise an error.
|
// It returns nil, otherwise an error.
|
||||||
func writeJSON(report *Report, w io.WriteCloser) error {
|
func writeJSON(report *Report, w io.WriteCloser) error {
|
||||||
|
|
@ -143,6 +158,8 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errCheck(opts.prepare())
|
||||||
|
|
||||||
if len(domains) == 0 {
|
if len(domains) == 0 {
|
||||||
log.Println("No domains given.")
|
log.Println("No domains given.")
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -359,12 +359,8 @@ func (p *processor) httpClient() util.Client {
|
||||||
tlsConfig.InsecureSkipVerify = true
|
tlsConfig.InsecureSkipVerify = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.opts.ClientCert != nil && p.opts.ClientKey != nil {
|
if len(p.opts.clientCerts) != 0 {
|
||||||
cert, err := tls.LoadX509KeyPair(*p.opts.ClientCert, *p.opts.ClientKey)
|
tlsConfig.Certificates = p.opts.clientCerts
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
tlsConfig.Certificates = []tls.Certificate{cert}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hClient.Transport = &http.Transport{
|
hClient.Transport = &http.Transport{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue