-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathauth.go
42 lines (33 loc) · 926 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright (c) 2019 Entrust Datacard Corporation.
* All rights reserved.
*/
package main
import (
"context"
"crypto/tls"
"crypto/x509"
"github.com/hashicorp/vault/logical"
"github.com/pkg/errors"
)
func getTLSConfig(ctx context.Context, req *logical.Request, configCa *CAGWConfigRole) (*tls.Config, error) {
certificate, err := tls.X509KeyPair([]byte(configCa.PEMBundle), []byte(configCa.PEMBundle))
if err != nil {
return nil, errors.Wrap(err, "Error parsing client certificate and key")
}
certPool, _ := x509.SystemCertPool()
if certPool == nil {
certPool = x509.NewCertPool()
}
if ok := certPool.AppendCertsFromPEM([]byte(configCa.CACerts)); !ok {
return nil, errors.New("Error appending CA certs.")
}
tlsClientConfig := tls.Config{
Certificates: []tls.Certificate{
certificate,
},
RootCAs: certPool,
}
tlsClientConfig.BuildNameToCertificate()
return &tlsClientConfig, nil
}