1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Unify loading of client certs in checker and uploader.

This commit is contained in:
Sascha L. Teichmann 2022-07-27 01:28:37 +02:00
parent 1241429d19
commit e5f584092c
2 changed files with 30 additions and 13 deletions

View file

@ -13,6 +13,7 @@ import (
"crypto/tls"
_ "embed" // Used for embedding.
"encoding/json"
"errors"
"fmt"
"html/template"
"io"
@ -51,7 +52,12 @@ func errCheck(err error) {
func (o *options) prepare() error {
// Load client certs.
if o.ClientCert != nil && o.ClientKey != nil {
switch hasCert, hasKey := o.ClientCert != nil, o.ClientKey != nil; {
case hasCert && !hasKey || !hasCert && hasKey:
return errors.New("both client-key and client-cert options must be set for the authentication")
case hasCert:
cert, err := tls.LoadX509KeyPair(*o.ClientCert, *o.ClientKey)
if err != nil {
return err