Files
mc/pkg/minio/auth.go
T

58 lines
1.1 KiB
Go

package minio
import (
"crypto/tls"
"io/ioutil"
"net/http"
)
type Auth struct {
AccessKey string
SecretAccessKey string
Hostname string
CertPEM string
KeyPEM string
}
type TlsConfig struct {
CertPEMBlock []byte
KeyPEMBlock []byte
}
func (a *Auth) loadKeys(cert string, key string) (*TlsConfig, error) {
certBlock, err := ioutil.ReadFile(cert)
if err != nil {
return nil, err
}
keyBlock, err := ioutil.ReadFile(key)
if err != nil {
return nil, err
}
t := &TlsConfig{}
t.CertPEMBlock = certBlock
t.KeyPEMBlock = keyBlock
return t, nil
}
func (a *Auth) getTlsTransport() (*http.Transport, error) {
tlsconfig, err := a.loadKeys(a.CertPEM, a.KeyPEM)
if err != nil {
return nil, err
}
var cert tls.Certificate
cert, err = tls.X509KeyPair(tlsconfig.CertPEMBlock, tlsconfig.KeyPEMBlock)
if err != nil {
return nil, err
}
// Setup HTTPS client
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
InsecureSkipVerify: true,
}
tlsConfig.BuildNameToCertificate()
transport := &http.Transport{TLSClientConfig: tlsConfig}
return transport, nil
}