2015-04-24 04:46:21 +00:00
|
|
|
package cert
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2019-04-02 18:49:42 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/elliptic"
|
2017-05-25 14:49:09 +00:00
|
|
|
"crypto/rand"
|
|
|
|
"crypto/rsa"
|
2015-04-24 04:46:21 +00:00
|
|
|
"crypto/tls"
|
2017-05-25 14:49:09 +00:00
|
|
|
"crypto/x509"
|
|
|
|
"crypto/x509/pkix"
|
2021-04-08 16:43:39 +00:00
|
|
|
"encoding/pem"
|
2015-04-24 04:46:21 +00:00
|
|
|
"fmt"
|
2017-09-01 20:55:16 +00:00
|
|
|
"io"
|
2015-04-24 04:46:21 +00:00
|
|
|
"io/ioutil"
|
2017-05-25 14:49:09 +00:00
|
|
|
"math/big"
|
2021-04-08 16:43:39 +00:00
|
|
|
mathrand "math/rand"
|
2017-05-25 14:49:09 +00:00
|
|
|
"net"
|
2021-04-08 16:43:39 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2017-05-25 14:49:09 +00:00
|
|
|
"os"
|
2021-04-08 16:43:39 +00:00
|
|
|
"path/filepath"
|
2016-03-15 18:07:40 +00:00
|
|
|
"reflect"
|
2015-04-24 04:46:21 +00:00
|
|
|
"testing"
|
2015-04-24 19:58:39 +00:00
|
|
|
"time"
|
2015-04-24 04:46:21 +00:00
|
|
|
|
2021-04-08 16:43:39 +00:00
|
|
|
"github.com/go-test/deep"
|
|
|
|
"github.com/hashicorp/go-sockaddr"
|
|
|
|
|
|
|
|
"golang.org/x/net/http2"
|
|
|
|
|
2018-02-16 22:42:29 +00:00
|
|
|
cleanhttp "github.com/hashicorp/go-cleanhttp"
|
2018-04-03 00:46:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2018-02-16 22:42:29 +00:00
|
|
|
"github.com/hashicorp/vault/api"
|
|
|
|
vaulthttp "github.com/hashicorp/vault/http"
|
|
|
|
|
2019-01-09 00:48:57 +00:00
|
|
|
rootcerts "github.com/hashicorp/go-rootcerts"
|
2018-02-16 22:42:29 +00:00
|
|
|
"github.com/hashicorp/vault/builtin/logical/pki"
|
2019-04-13 07:44:06 +00:00
|
|
|
logicaltest "github.com/hashicorp/vault/helper/testhelpers/logical"
|
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/certutil"
|
2019-07-01 20:31:37 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/tokenutil"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2018-02-16 22:42:29 +00:00
|
|
|
"github.com/hashicorp/vault/vault"
|
2015-10-15 17:04:54 +00:00
|
|
|
"github.com/mitchellh/mapstructure"
|
2015-04-24 04:46:21 +00:00
|
|
|
)
|
|
|
|
|
2016-04-29 06:32:48 +00:00
|
|
|
const (
|
2016-05-02 16:34:46 +00:00
|
|
|
serverCertPath = "test-fixtures/cacert.pem"
|
|
|
|
serverKeyPath = "test-fixtures/cakey.pem"
|
2016-04-29 06:32:48 +00:00
|
|
|
serverCAPath = serverCertPath
|
|
|
|
|
2016-05-02 16:34:46 +00:00
|
|
|
testRootCACertPath1 = "test-fixtures/testcacert1.pem"
|
|
|
|
testRootCAKeyPath1 = "test-fixtures/testcakey1.pem"
|
|
|
|
testCertPath1 = "test-fixtures/testissuedcert4.pem"
|
|
|
|
testKeyPath1 = "test-fixtures/testissuedkey4.pem"
|
|
|
|
testIssuedCertCRL = "test-fixtures/issuedcertcrl"
|
2016-04-29 06:32:48 +00:00
|
|
|
|
2016-05-02 16:34:46 +00:00
|
|
|
testRootCACertPath2 = "test-fixtures/testcacert2.pem"
|
|
|
|
testRootCAKeyPath2 = "test-fixtures/testcakey2.pem"
|
|
|
|
testRootCertCRL = "test-fixtures/cacert2crl"
|
2016-04-29 06:32:48 +00:00
|
|
|
)
|
|
|
|
|
2019-04-02 18:49:42 +00:00
|
|
|
func generateTestCertAndConnState(t *testing.T, template *x509.Certificate) (string, tls.ConnectionState, error) {
|
|
|
|
t.Helper()
|
|
|
|
tempDir, err := ioutil.TempDir("", "vault-cert-auth-test-")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Logf("test %s, temp dir %s", t.Name(), tempDir)
|
|
|
|
caCertTemplate := &x509.Certificate{
|
|
|
|
Subject: pkix.Name{
|
|
|
|
CommonName: "localhost",
|
|
|
|
},
|
|
|
|
DNSNames: []string{"localhost"},
|
|
|
|
IPAddresses: []net.IP{net.ParseIP("127.0.0.1")},
|
|
|
|
KeyUsage: x509.KeyUsage(x509.KeyUsageCertSign | x509.KeyUsageCRLSign),
|
|
|
|
SerialNumber: big.NewInt(mathrand.Int63()),
|
|
|
|
NotBefore: time.Now().Add(-30 * time.Second),
|
|
|
|
NotAfter: time.Now().Add(262980 * time.Hour),
|
|
|
|
BasicConstraintsValid: true,
|
|
|
|
IsCA: true,
|
|
|
|
}
|
|
|
|
caKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
caBytes, err := x509.CreateCertificate(rand.Reader, caCertTemplate, caCertTemplate, caKey.Public(), caKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
caCert, err := x509.ParseCertificate(caBytes)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
caCertPEMBlock := &pem.Block{
|
|
|
|
Type: "CERTIFICATE",
|
|
|
|
Bytes: caBytes,
|
|
|
|
}
|
2021-04-08 16:43:39 +00:00
|
|
|
err = ioutil.WriteFile(filepath.Join(tempDir, "ca_cert.pem"), pem.EncodeToMemory(caCertPEMBlock), 0o755)
|
2019-04-02 18:49:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
marshaledCAKey, err := x509.MarshalECPrivateKey(caKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
caKeyPEMBlock := &pem.Block{
|
|
|
|
Type: "EC PRIVATE KEY",
|
|
|
|
Bytes: marshaledCAKey,
|
|
|
|
}
|
2021-04-08 16:43:39 +00:00
|
|
|
err = ioutil.WriteFile(filepath.Join(tempDir, "ca_key.pem"), pem.EncodeToMemory(caKeyPEMBlock), 0o755)
|
2019-04-02 18:49:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
certBytes, err := x509.CreateCertificate(rand.Reader, template, caCert, key.Public(), caKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
certPEMBlock := &pem.Block{
|
|
|
|
Type: "CERTIFICATE",
|
|
|
|
Bytes: certBytes,
|
|
|
|
}
|
2021-04-08 16:43:39 +00:00
|
|
|
err = ioutil.WriteFile(filepath.Join(tempDir, "cert.pem"), pem.EncodeToMemory(certPEMBlock), 0o755)
|
2019-04-02 18:49:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
marshaledKey, err := x509.MarshalECPrivateKey(key)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
keyPEMBlock := &pem.Block{
|
|
|
|
Type: "EC PRIVATE KEY",
|
|
|
|
Bytes: marshaledKey,
|
|
|
|
}
|
2021-04-08 16:43:39 +00:00
|
|
|
err = ioutil.WriteFile(filepath.Join(tempDir, "key.pem"), pem.EncodeToMemory(keyPEMBlock), 0o755)
|
2019-04-02 18:49:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
connInfo, err := testConnState(filepath.Join(tempDir, "cert.pem"), filepath.Join(tempDir, "key.pem"), filepath.Join(tempDir, "ca_cert.pem"))
|
|
|
|
return tempDir, connInfo, err
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:32:48 +00:00
|
|
|
// Unlike testConnState, this method does not use the same 'tls.Config' objects for
|
|
|
|
// both dialing and listening. Instead, it runs the server without specifying its CA.
|
|
|
|
// But the client, presents the CA cert of the server to trust the server.
|
|
|
|
// The client can present a cert and key which is completely independent of server's CA.
|
|
|
|
// The connection state returned will contain the certificate presented by the client.
|
2017-09-01 20:55:16 +00:00
|
|
|
func connectionState(serverCAPath, serverCertPath, serverKeyPath, clientCertPath, clientKeyPath string) (tls.ConnectionState, error) {
|
2016-04-29 06:32:48 +00:00
|
|
|
serverKeyPair, err := tls.LoadX509KeyPair(serverCertPath, serverKeyPath)
|
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
return tls.ConnectionState{}, err
|
2016-04-29 06:32:48 +00:00
|
|
|
}
|
|
|
|
// Prepare the listener configuration with server's key pair
|
|
|
|
listenConf := &tls.Config{
|
|
|
|
Certificates: []tls.Certificate{serverKeyPair},
|
|
|
|
ClientAuth: tls.RequestClientCert,
|
|
|
|
}
|
|
|
|
|
|
|
|
clientKeyPair, err := tls.LoadX509KeyPair(clientCertPath, clientKeyPath)
|
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
return tls.ConnectionState{}, err
|
2016-04-29 06:32:48 +00:00
|
|
|
}
|
|
|
|
// Load the CA cert required by the client to authenticate the server.
|
2016-05-03 16:23:25 +00:00
|
|
|
rootConfig := &rootcerts.Config{
|
|
|
|
CAFile: serverCAPath,
|
|
|
|
}
|
|
|
|
serverCAs, err := rootcerts.LoadCACerts(rootConfig)
|
2016-04-29 06:32:48 +00:00
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
return tls.ConnectionState{}, err
|
2016-04-29 06:32:48 +00:00
|
|
|
}
|
|
|
|
// Prepare the dial configuration that the client uses to establish the connection.
|
|
|
|
dialConf := &tls.Config{
|
|
|
|
Certificates: []tls.Certificate{clientKeyPair},
|
|
|
|
RootCAs: serverCAs,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the server.
|
|
|
|
list, err := tls.Listen("tcp", "127.0.0.1:0", listenConf)
|
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
return tls.ConnectionState{}, err
|
2016-04-29 06:32:48 +00:00
|
|
|
}
|
|
|
|
defer list.Close()
|
|
|
|
|
2017-09-01 20:55:16 +00:00
|
|
|
// Accept connections.
|
|
|
|
serverErrors := make(chan error, 1)
|
|
|
|
connState := make(chan tls.ConnectionState)
|
|
|
|
go func() {
|
|
|
|
defer close(connState)
|
|
|
|
serverConn, err := list.Accept()
|
|
|
|
if err != nil {
|
|
|
|
serverErrors <- err
|
|
|
|
close(serverErrors)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer serverConn.Close()
|
|
|
|
|
|
|
|
// Read the ping
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
_, err = serverConn.Read(buf)
|
|
|
|
if (err != nil) && (err != io.EOF) {
|
|
|
|
serverErrors <- err
|
|
|
|
close(serverErrors)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
close(serverErrors)
|
|
|
|
connState <- serverConn.(*tls.Conn).ConnectionState()
|
|
|
|
}()
|
|
|
|
|
2016-04-29 06:32:48 +00:00
|
|
|
// Establish a connection from the client side and write a few bytes.
|
2017-09-01 20:55:16 +00:00
|
|
|
clientErrors := make(chan error, 1)
|
2016-04-29 06:32:48 +00:00
|
|
|
go func() {
|
|
|
|
addr := list.Addr().String()
|
|
|
|
conn, err := tls.Dial("tcp", addr, dialConf)
|
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
clientErrors <- err
|
|
|
|
close(clientErrors)
|
|
|
|
return
|
2016-04-29 06:32:48 +00:00
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
// Write ping
|
2017-09-01 20:55:16 +00:00
|
|
|
_, err = conn.Write([]byte("ping"))
|
|
|
|
if err != nil {
|
|
|
|
clientErrors <- err
|
|
|
|
}
|
|
|
|
close(clientErrors)
|
2016-04-29 06:32:48 +00:00
|
|
|
}()
|
|
|
|
|
2017-09-01 20:55:16 +00:00
|
|
|
for err = range clientErrors {
|
|
|
|
if err != nil {
|
|
|
|
return tls.ConnectionState{}, fmt.Errorf("error in client goroutine:%v", err)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 20:55:16 +00:00
|
|
|
for err = range serverErrors {
|
|
|
|
if err != nil {
|
|
|
|
return tls.ConnectionState{}, fmt.Errorf("error in server goroutine:%v", err)
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
// Grab the current state
|
2017-09-01 20:55:16 +00:00
|
|
|
return <-connState, nil
|
2016-04-29 06:32:48 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 22:42:29 +00:00
|
|
|
func TestBackend_PermittedDNSDomainsIntermediateCA(t *testing.T) {
|
|
|
|
// Enable PKI secret engine and Cert auth method
|
|
|
|
coreConfig := &vault.CoreConfig{
|
|
|
|
DisableMlock: true,
|
|
|
|
DisableCache: true,
|
2018-04-03 00:46:59 +00:00
|
|
|
Logger: log.NewNullLogger(),
|
2018-02-16 22:42:29 +00:00
|
|
|
CredentialBackends: map[string]logical.Factory{
|
|
|
|
"cert": Factory,
|
|
|
|
},
|
|
|
|
LogicalBackends: map[string]logical.Factory{
|
|
|
|
"pki": pki.Factory,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{
|
|
|
|
HandlerFunc: vaulthttp.Handler,
|
|
|
|
})
|
|
|
|
cluster.Start()
|
|
|
|
defer cluster.Cleanup()
|
|
|
|
cores := cluster.Cores
|
|
|
|
vault.TestWaitActive(t, cores[0].Core)
|
|
|
|
client := cores[0].Client
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// Mount /pki as a root CA
|
|
|
|
err = client.Sys().Mount("pki", &api.MountInput{
|
|
|
|
Type: "pki",
|
|
|
|
Config: api.MountConfigInput{
|
|
|
|
DefaultLeaseTTL: "16h",
|
|
|
|
MaxLeaseTTL: "32h",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the cluster's certificate as the root CA in /pki
|
|
|
|
pemBundleRootCA := string(cluster.CACertPEM) + string(cluster.CAKeyPEM)
|
|
|
|
_, err = client.Logical().Write("pki/config/ca", map[string]interface{}{
|
|
|
|
"pem_bundle": pemBundleRootCA,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mount /pki2 to operate as an intermediate CA
|
|
|
|
err = client.Sys().Mount("pki2", &api.MountInput{
|
|
|
|
Type: "pki",
|
|
|
|
Config: api.MountConfigInput{
|
|
|
|
DefaultLeaseTTL: "16h",
|
|
|
|
MaxLeaseTTL: "32h",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a CSR for the intermediate CA
|
|
|
|
secret, err := client.Logical().Write("pki2/intermediate/generate/internal", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
intermediateCSR := secret.Data["csr"].(string)
|
|
|
|
|
|
|
|
// Sign the intermediate CSR using /pki
|
|
|
|
secret, err = client.Logical().Write("pki/root/sign-intermediate", map[string]interface{}{
|
|
|
|
"permitted_dns_domains": ".myvault.com",
|
2018-11-07 21:52:01 +00:00
|
|
|
"csr": intermediateCSR,
|
2018-02-16 22:42:29 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
intermediateCertPEM := secret.Data["certificate"].(string)
|
|
|
|
|
|
|
|
// Configure the intermediate cert as the CA in /pki2
|
|
|
|
_, err = client.Logical().Write("pki2/intermediate/set-signed", map[string]interface{}{
|
|
|
|
"certificate": intermediateCertPEM,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a role on the intermediate CA mount
|
|
|
|
_, err = client.Logical().Write("pki2/roles/myvault-dot-com", map[string]interface{}{
|
|
|
|
"allowed_domains": "myvault.com",
|
|
|
|
"allow_subdomains": "true",
|
|
|
|
"max_ttl": "5m",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Issue a leaf cert using the intermediate CA
|
|
|
|
secret, err = client.Logical().Write("pki2/issue/myvault-dot-com", map[string]interface{}{
|
|
|
|
"common_name": "cert.myvault.com",
|
|
|
|
"format": "pem",
|
|
|
|
"ip_sans": "127.0.0.1",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
leafCertPEM := secret.Data["certificate"].(string)
|
|
|
|
leafCertKeyPEM := secret.Data["private_key"].(string)
|
|
|
|
|
|
|
|
// Enable the cert auth method
|
|
|
|
err = client.Sys().EnableAuthWithOptions("cert", &api.EnableAuthOptions{
|
|
|
|
Type: "cert",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the intermediate CA cert as a trusted certificate in the backend
|
|
|
|
_, err = client.Logical().Write("auth/cert/certs/myvault-dot-com", map[string]interface{}{
|
|
|
|
"display_name": "myvault.com",
|
|
|
|
"policies": "default",
|
|
|
|
"certificate": intermediateCertPEM,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create temporary files for CA cert, client cert and client cert key.
|
|
|
|
// This is used to configure TLS in the api client.
|
|
|
|
caCertFile, err := ioutil.TempFile("", "caCert")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.Remove(caCertFile.Name())
|
|
|
|
if _, err := caCertFile.Write([]byte(cluster.CACertPEM)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := caCertFile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
leafCertFile, err := ioutil.TempFile("", "leafCert")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.Remove(leafCertFile.Name())
|
|
|
|
if _, err := leafCertFile.Write([]byte(leafCertPEM)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := leafCertFile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
leafCertKeyFile, err := ioutil.TempFile("", "leafCertKey")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.Remove(leafCertKeyFile.Name())
|
|
|
|
if _, err := leafCertKeyFile.Write([]byte(leafCertKeyPEM)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := leafCertKeyFile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is a copy-pasta from the NewTestCluster, with the
|
|
|
|
// modification to reconfigure the TLS on the api client with the leaf
|
|
|
|
// certificate generated above.
|
|
|
|
getAPIClient := func(port int, tlsConfig *tls.Config) *api.Client {
|
|
|
|
transport := cleanhttp.DefaultPooledTransport()
|
|
|
|
transport.TLSClientConfig = tlsConfig.Clone()
|
|
|
|
if err := http2.ConfigureTransport(transport); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
client := &http.Client{
|
|
|
|
Transport: transport,
|
|
|
|
CheckRedirect: func(*http.Request, []*http.Request) error {
|
|
|
|
// This can of course be overridden per-test by using its own client
|
|
|
|
return fmt.Errorf("redirects not allowed in these tests")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
config := api.DefaultConfig()
|
|
|
|
if config.Error != nil {
|
|
|
|
t.Fatal(config.Error)
|
|
|
|
}
|
|
|
|
config.Address = fmt.Sprintf("https://127.0.0.1:%d", port)
|
|
|
|
config.HttpClient = client
|
|
|
|
|
|
|
|
// Set the above issued certificates as the client certificates
|
|
|
|
config.ConfigureTLS(&api.TLSConfig{
|
|
|
|
CACert: caCertFile.Name(),
|
|
|
|
ClientCert: leafCertFile.Name(),
|
|
|
|
ClientKey: leafCertKeyFile.Name(),
|
|
|
|
})
|
|
|
|
|
|
|
|
apiClient, err := api.NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return apiClient
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new api client with the desired TLS configuration
|
|
|
|
newClient := getAPIClient(cores[0].Listeners[0].Address.Port, cores[0].TLSConfig)
|
|
|
|
|
|
|
|
secret, err = newClient.Logical().Write("auth/cert/login", map[string]interface{}{
|
|
|
|
"name": "myvault-dot-com",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if secret.Auth == nil || secret.Auth.ClientToken == "" {
|
|
|
|
t.Fatalf("expected a successful authentication")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-25 14:49:09 +00:00
|
|
|
func TestBackend_NonCAExpiry(t *testing.T) {
|
|
|
|
var resp *logical.Response
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// Create a self-signed certificate and issue a leaf certificate using the
|
|
|
|
// CA cert
|
|
|
|
template := &x509.Certificate{
|
|
|
|
SerialNumber: big.NewInt(1234),
|
|
|
|
Subject: pkix.Name{
|
|
|
|
CommonName: "localhost",
|
|
|
|
Organization: []string{"hashicorp"},
|
|
|
|
OrganizationalUnit: []string{"vault"},
|
|
|
|
},
|
|
|
|
BasicConstraintsValid: true,
|
|
|
|
NotBefore: time.Now().Add(-30 * time.Second),
|
|
|
|
NotAfter: time.Now().Add(50 * time.Second),
|
|
|
|
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
|
|
|
|
KeyUsage: x509.KeyUsage(x509.KeyUsageCertSign | x509.KeyUsageCRLSign),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set IP SAN
|
|
|
|
parsedIP := net.ParseIP("127.0.0.1")
|
|
|
|
if parsedIP == nil {
|
|
|
|
t.Fatalf("failed to create parsed IP")
|
|
|
|
}
|
|
|
|
template.IPAddresses = []net.IP{parsedIP}
|
|
|
|
|
|
|
|
// Private key for CA cert
|
|
|
|
caPrivateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Marshalling to be able to create PEM file
|
|
|
|
caPrivateKeyBytes := x509.MarshalPKCS1PrivateKey(caPrivateKey)
|
|
|
|
|
|
|
|
caPublicKey := &caPrivateKey.PublicKey
|
|
|
|
|
|
|
|
template.IsCA = true
|
|
|
|
|
|
|
|
caCertBytes, err := x509.CreateCertificate(rand.Reader, template, template, caPublicKey, caPrivateKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
caCert, err := x509.ParseCertificate(caCertBytes)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
parsedCaBundle := &certutil.ParsedCertBundle{
|
|
|
|
Certificate: caCert,
|
|
|
|
CertificateBytes: caCertBytes,
|
|
|
|
PrivateKeyBytes: caPrivateKeyBytes,
|
|
|
|
PrivateKeyType: certutil.RSAPrivateKey,
|
|
|
|
}
|
|
|
|
|
|
|
|
caCertBundle, err := parsedCaBundle.ToCertBundle()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
caCertFile, err := ioutil.TempFile("", "caCert")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer os.Remove(caCertFile.Name())
|
|
|
|
|
|
|
|
if _, err := caCertFile.Write([]byte(caCertBundle.Certificate)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := caCertFile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
caKeyFile, err := ioutil.TempFile("", "caKey")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer os.Remove(caKeyFile.Name())
|
|
|
|
|
|
|
|
if _, err := caKeyFile.Write([]byte(caCertBundle.PrivateKey)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := caKeyFile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare template for non-CA cert
|
|
|
|
|
|
|
|
template.IsCA = false
|
|
|
|
template.SerialNumber = big.NewInt(5678)
|
|
|
|
|
|
|
|
template.KeyUsage = x509.KeyUsage(x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign)
|
|
|
|
issuedPrivateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
issuedPrivateKeyBytes := x509.MarshalPKCS1PrivateKey(issuedPrivateKey)
|
|
|
|
|
|
|
|
issuedPublicKey := &issuedPrivateKey.PublicKey
|
|
|
|
|
|
|
|
// Keep a short certificate lifetime so logins can be tested both when
|
|
|
|
// cert is valid and when it gets expired
|
|
|
|
template.NotBefore = time.Now().Add(-2 * time.Second)
|
|
|
|
template.NotAfter = time.Now().Add(3 * time.Second)
|
|
|
|
|
|
|
|
issuedCertBytes, err := x509.CreateCertificate(rand.Reader, template, caCert, issuedPublicKey, caPrivateKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
issuedCert, err := x509.ParseCertificate(issuedCertBytes)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
parsedIssuedBundle := &certutil.ParsedCertBundle{
|
|
|
|
Certificate: issuedCert,
|
|
|
|
CertificateBytes: issuedCertBytes,
|
|
|
|
PrivateKeyBytes: issuedPrivateKeyBytes,
|
|
|
|
PrivateKeyType: certutil.RSAPrivateKey,
|
|
|
|
}
|
|
|
|
|
|
|
|
issuedCertBundle, err := parsedIssuedBundle.ToCertBundle()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
issuedCertFile, err := ioutil.TempFile("", "issuedCert")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer os.Remove(issuedCertFile.Name())
|
|
|
|
|
|
|
|
if _, err := issuedCertFile.Write([]byte(issuedCertBundle.Certificate)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := issuedCertFile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
issuedKeyFile, err := ioutil.TempFile("", "issuedKey")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer os.Remove(issuedKeyFile.Name())
|
|
|
|
|
|
|
|
if _, err := issuedKeyFile.Write([]byte(issuedCertBundle.PrivateKey)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := issuedKeyFile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
storage := &logical.InmemStorage{}
|
|
|
|
config.StorageView = storage
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
b, err := Factory(context.Background(), config)
|
2017-05-25 14:49:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the Non-CA certificate of the client key pair
|
|
|
|
certData := map[string]interface{}{
|
|
|
|
"certificate": issuedCertBundle.Certificate,
|
|
|
|
"policies": "abc",
|
|
|
|
"display_name": "cert1",
|
|
|
|
"ttl": 10000,
|
|
|
|
}
|
|
|
|
certReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "certs/cert1",
|
|
|
|
Storage: storage,
|
|
|
|
Data: certData,
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), certReq)
|
2017-05-25 14:49:09 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create connection state using the certificates generated
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := connectionState(caCertFile.Name(), caCertFile.Name(), caKeyFile.Name(), issuedCertFile.Name(), issuedKeyFile.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state:%v", err)
|
|
|
|
}
|
2017-05-25 14:49:09 +00:00
|
|
|
|
|
|
|
loginReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Storage: storage,
|
|
|
|
Path: "login",
|
|
|
|
Connection: &logical.Connection{
|
|
|
|
ConnState: &connState,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Login when the certificate is still valid. Login should succeed.
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2017-05-25 14:49:09 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait until the certificate expires
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
|
|
|
// Login attempt after certificate expiry should fail
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2017-05-25 14:49:09 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected error due to expired certificate")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 18:37:07 +00:00
|
|
|
func TestBackend_RegisteredNonCA_CRL(t *testing.T) {
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
storage := &logical.InmemStorage{}
|
|
|
|
config.StorageView = storage
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
b, err := Factory(context.Background(), config)
|
2016-05-12 18:37:07 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
nonCACert, err := ioutil.ReadFile(testCertPath1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the Non-CA certificate of the client key pair
|
|
|
|
certData := map[string]interface{}{
|
|
|
|
"certificate": nonCACert,
|
|
|
|
"policies": "abc",
|
|
|
|
"display_name": "cert1",
|
|
|
|
"ttl": 10000,
|
|
|
|
}
|
|
|
|
certReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "certs/cert1",
|
|
|
|
Storage: storage,
|
|
|
|
Data: certData,
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err := b.HandleRequest(context.Background(), certReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-05-12 18:37:07 +00:00
|
|
|
|
|
|
|
// Connection state is presenting the client Non-CA cert and its key.
|
|
|
|
// This is exactly what is registered at the backend.
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := connectionState(serverCAPath, serverCertPath, serverKeyPath, testCertPath1, testKeyPath1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state:%v", err)
|
|
|
|
}
|
2016-05-12 18:37:07 +00:00
|
|
|
loginReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Storage: storage,
|
|
|
|
Path: "login",
|
|
|
|
Connection: &logical.Connection{
|
|
|
|
ConnState: &connState,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
// Login should succeed.
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-05-12 18:37:07 +00:00
|
|
|
|
|
|
|
// Register a CRL containing the issued client certificate used above.
|
|
|
|
issuedCRL, err := ioutil.ReadFile(testIssuedCertCRL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
crlData := map[string]interface{}{
|
|
|
|
"crl": issuedCRL,
|
|
|
|
}
|
|
|
|
crlReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Storage: storage,
|
|
|
|
Path: "crls/issuedcrl",
|
|
|
|
Data: crlData,
|
|
|
|
}
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), crlReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-05-12 18:37:07 +00:00
|
|
|
|
|
|
|
// Attempt login with the same connection state but with the CRL registered
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2016-05-12 18:37:07 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected failure due to revoked certificate")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:32:48 +00:00
|
|
|
func TestBackend_CRLs(t *testing.T) {
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
storage := &logical.InmemStorage{}
|
|
|
|
config.StorageView = storage
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
b, err := Factory(context.Background(), config)
|
2016-04-29 06:32:48 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
clientCA1, err := ioutil.ReadFile(testRootCACertPath1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Register the CA certificate of the client key pair
|
|
|
|
certData := map[string]interface{}{
|
|
|
|
"certificate": clientCA1,
|
|
|
|
"policies": "abc",
|
|
|
|
"display_name": "cert1",
|
|
|
|
"ttl": 10000,
|
|
|
|
}
|
|
|
|
|
|
|
|
certReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "certs/cert1",
|
|
|
|
Storage: storage,
|
|
|
|
Data: certData,
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err := b.HandleRequest(context.Background(), certReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
|
|
|
|
// Connection state is presenting the client CA cert and its key.
|
|
|
|
// This is exactly what is registered at the backend.
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := connectionState(serverCAPath, serverCertPath, serverKeyPath, testRootCACertPath1, testRootCAKeyPath1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state:%v", err)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
loginReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Storage: storage,
|
|
|
|
Path: "login",
|
|
|
|
Connection: &logical.Connection{
|
|
|
|
ConnState: &connState,
|
|
|
|
},
|
|
|
|
}
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
|
|
|
|
// Now, without changing the registered client CA cert, present from
|
|
|
|
// the client side, a cert issued using the registered CA.
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err = connectionState(serverCAPath, serverCertPath, serverKeyPath, testCertPath1, testKeyPath1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
loginReq.Connection.ConnState = &connState
|
|
|
|
|
|
|
|
// Attempt login with the updated connection
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
|
|
|
|
// Register a CRL containing the issued client certificate used above.
|
|
|
|
issuedCRL, err := ioutil.ReadFile(testIssuedCertCRL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
crlData := map[string]interface{}{
|
|
|
|
"crl": issuedCRL,
|
|
|
|
}
|
|
|
|
|
|
|
|
crlReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Storage: storage,
|
|
|
|
Path: "crls/issuedcrl",
|
|
|
|
Data: crlData,
|
|
|
|
}
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), crlReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
|
|
|
|
// Attempt login with the revoked certificate.
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2016-04-29 06:32:48 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected failure due to revoked certificate")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register a different client CA certificate.
|
|
|
|
clientCA2, err := ioutil.ReadFile(testRootCACertPath2)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
certData["certificate"] = clientCA2
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), certReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
|
|
|
|
// Test login using a different client CA cert pair.
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err = connectionState(serverCAPath, serverCertPath, serverKeyPath, testRootCACertPath2, testRootCAKeyPath2)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
loginReq.Connection.ConnState = &connState
|
|
|
|
|
|
|
|
// Attempt login with the updated connection
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
|
|
|
|
// Register a CRL containing the root CA certificate used above.
|
|
|
|
rootCRL, err := ioutil.ReadFile(testRootCertCRL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
crlData["crl"] = rootCRL
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), crlReq)
|
2016-06-01 20:01:28 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
2016-04-29 06:32:48 +00:00
|
|
|
|
|
|
|
// Attempt login with the same connection state but with the CRL registered
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), loginReq)
|
2016-04-29 06:32:48 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected failure due to revoked certificate")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 01:10:20 +00:00
|
|
|
func testFactory(t *testing.T) logical.Backend {
|
2018-01-19 06:44:44 +00:00
|
|
|
b, err := Factory(context.Background(), &logical.BackendConfig{
|
2015-10-06 01:10:20 +00:00
|
|
|
System: &logical.StaticSystemView{
|
2017-12-18 20:29:45 +00:00
|
|
|
DefaultLeaseTTLVal: 1000 * time.Second,
|
2015-10-06 01:10:20 +00:00
|
|
|
MaxLeaseTTLVal: 1800 * time.Second,
|
|
|
|
},
|
2015-10-15 17:04:54 +00:00
|
|
|
StorageView: &logical.InmemStorage{},
|
2015-10-06 01:10:20 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2016-04-13 19:38:29 +00:00
|
|
|
t.Fatalf("error: %s", err)
|
2015-10-06 01:10:20 +00:00
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2016-02-29 21:02:19 +00:00
|
|
|
// Test the certificates being registered to the backend
|
|
|
|
func TestBackend_CertWrites(t *testing.T) {
|
|
|
|
// CA cert
|
|
|
|
ca1, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
// Non CA Cert
|
|
|
|
ca2, err := ioutil.ReadFile("test-fixtures/keys/cert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
// Non CA cert without TLS web client authentication
|
|
|
|
ca3, err := ioutil.ReadFile("test-fixtures/noclientauthcert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
2016-03-15 18:07:40 +00:00
|
|
|
|
|
|
|
tc := logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2016-02-29 21:02:19 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "aaa", ca1, "foo", allowed{}, false),
|
|
|
|
testAccStepCert(t, "bbb", ca2, "foo", allowed{}, false),
|
|
|
|
testAccStepCert(t, "ccc", ca3, "foo", allowed{}, true),
|
2016-02-29 21:02:19 +00:00
|
|
|
},
|
2016-03-15 18:07:40 +00:00
|
|
|
}
|
|
|
|
tc.Steps = append(tc.Steps, testAccStepListCerts(t, []string{"aaa", "bbb"})...)
|
|
|
|
logicaltest.Test(t, tc)
|
2016-02-29 21:02:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 04:46:21 +00:00
|
|
|
// Test a client trusted by a CA
|
|
|
|
func TestBackend_basic_CA(t *testing.T) {
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := testConnState("test-fixtures/keys/cert.pem",
|
2016-02-29 20:48:09 +00:00
|
|
|
"test-fixtures/keys/key.pem", "test-fixtures/root/rootcacert.pem")
|
2017-09-01 20:55:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2016-02-29 20:48:09 +00:00
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
2015-04-24 04:46:21 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2015-04-24 04:46:21 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{}, false),
|
2015-04-24 04:46:21 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2015-10-06 01:10:20 +00:00
|
|
|
testAccStepCertLease(t, "web", ca, "foo"),
|
2015-09-18 18:01:28 +00:00
|
|
|
testAccStepCertTTL(t, "web", ca, "foo"),
|
|
|
|
testAccStepLogin(t, connState),
|
2017-12-18 20:29:45 +00:00
|
|
|
testAccStepCertMaxTTL(t, "web", ca, "foo"),
|
|
|
|
testAccStepLogin(t, connState),
|
2015-09-18 18:01:28 +00:00
|
|
|
testAccStepCertNoLease(t, "web", ca, "foo"),
|
|
|
|
testAccStepLoginDefaultLease(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "*.example.com"}, false),
|
2017-04-30 15:37:10 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "*.invalid.com"}, false),
|
2017-04-30 15:37:10 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2015-10-30 17:32:51 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test CRL behavior
|
2016-04-29 06:32:48 +00:00
|
|
|
func TestBackend_Basic_CRLs(t *testing.T) {
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := testConnState("test-fixtures/keys/cert.pem",
|
2016-02-29 20:48:09 +00:00
|
|
|
"test-fixtures/keys/key.pem", "test-fixtures/root/rootcacert.pem")
|
2017-09-01 20:55:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2016-02-29 20:48:09 +00:00
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
2015-10-30 17:32:51 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
2016-02-29 20:48:09 +00:00
|
|
|
crl, err := ioutil.ReadFile("test-fixtures/root/root.crl")
|
2015-10-30 17:32:51 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2015-10-30 17:32:51 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepCertNoLease(t, "web", ca, "foo"),
|
|
|
|
testAccStepLoginDefaultLease(t, connState),
|
2015-10-15 17:04:54 +00:00
|
|
|
testAccStepAddCRL(t, crl, connState),
|
|
|
|
testAccStepReadCRL(t, connState),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepDeleteCRL(t, connState),
|
|
|
|
testAccStepLoginDefaultLease(t, connState),
|
2015-04-24 04:46:21 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-30 15:37:10 +00:00
|
|
|
// Test a self-signed client (root CA) that is trusted
|
2015-04-24 04:46:21 +00:00
|
|
|
func TestBackend_basic_singleCert(t *testing.T) {
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := testConnState("test-fixtures/root/rootcacert.pem",
|
2017-04-30 15:37:10 +00:00
|
|
|
"test-fixtures/root/rootcakey.pem", "test-fixtures/root/rootcacert.pem")
|
2017-09-01 20:55:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2017-04-30 15:37:10 +00:00
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2017-04-30 15:37:10 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{}, false),
|
2017-04-30 15:37:10 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "example.com"}, false),
|
2017-04-30 15:37:10 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "invalid"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "1.2.3.4:invalid"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-25 14:34:46 +00:00
|
|
|
func TestBackend_common_name_singleCert(t *testing.T) {
|
|
|
|
connState, err := testConnState("test-fixtures/root/rootcacert.pem",
|
|
|
|
"test-fixtures/root/rootcakey.pem", "test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2018-05-25 14:34:46 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{common_names: "example.com"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{common_names: "invalid"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "1.2.3.4:invalid"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a self-signed client with custom ext (root CA) that is trusted
|
|
|
|
func TestBackend_ext_singleCert(t *testing.T) {
|
2017-12-18 17:53:44 +00:00
|
|
|
connState, err := testConnState(
|
|
|
|
"test-fixtures/root/rootcawextcert.pem",
|
|
|
|
"test-fixtures/root/rootcawextkey.pem",
|
|
|
|
"test-fixtures/root/rootcacert.pem",
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2017-12-18 17:53:44 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "2.1.1.1:A UTF8String Extension"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "2.1.1.1:*,2.1.1.2:A UTF8*"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "1.2.3.45:*"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "2.1.1.1:The Wrong Value"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "2.1.1.1:*,2.1.1.2:The Wrong Value"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "2.1.1.1:"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{ext: "2.1.1.1:,2.1.1.2:*"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "example.com", ext: "2.1.1.1:A UTF8String Extension"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "example.com", ext: "2.1.1.1:*,2.1.1.2:A UTF8*"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "example.com", ext: "1.2.3.45:*"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "example.com", ext: "2.1.1.1:The Wrong Value"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "example.com", ext: "2.1.1.1:*,2.1.1.2:The Wrong Value"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "invalid", ext: "2.1.1.1:A UTF8String Extension"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "invalid", ext: "2.1.1.1:*,2.1.1.2:A UTF8*"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "invalid", ext: "1.2.3.45:*"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "invalid", ext: "2.1.1.1:The Wrong Value"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{names: "invalid", ext: "2.1.1.1:*,2.1.1.2:The Wrong Value"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a self-signed client with URI alt names (root CA) that is trusted
|
|
|
|
func TestBackend_dns_singleCert(t *testing.T) {
|
2019-04-26 23:49:30 +00:00
|
|
|
certTemplate := &x509.Certificate{
|
|
|
|
Subject: pkix.Name{
|
|
|
|
CommonName: "example.com",
|
|
|
|
},
|
|
|
|
DNSNames: []string{"example.com"},
|
|
|
|
IPAddresses: []net.IP{net.ParseIP("127.0.0.1")},
|
|
|
|
ExtKeyUsage: []x509.ExtKeyUsage{
|
|
|
|
x509.ExtKeyUsageServerAuth,
|
|
|
|
x509.ExtKeyUsageClientAuth,
|
|
|
|
},
|
|
|
|
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment | x509.KeyUsageKeyAgreement,
|
|
|
|
SerialNumber: big.NewInt(mathrand.Int63()),
|
|
|
|
NotBefore: time.Now().Add(-30 * time.Second),
|
|
|
|
NotAfter: time.Now().Add(262980 * time.Hour),
|
|
|
|
}
|
|
|
|
|
|
|
|
tempDir, connState, err := generateTestCertAndConnState(t, certTemplate)
|
|
|
|
if tempDir != "" {
|
|
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
}
|
2018-05-25 14:34:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2019-04-26 23:49:30 +00:00
|
|
|
ca, err := ioutil.ReadFile(filepath.Join(tempDir, "ca_cert.pem"))
|
2018-05-25 14:34:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
2019-04-26 23:49:30 +00:00
|
|
|
|
2018-05-25 14:34:46 +00:00
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2018-05-25 14:34:46 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{dns: "example.com"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{dns: "*ample.com"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{dns: "notincert.com"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{dns: "abc"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{dns: "*.example.com"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a self-signed client with URI alt names (root CA) that is trusted
|
|
|
|
func TestBackend_email_singleCert(t *testing.T) {
|
2019-04-26 23:49:30 +00:00
|
|
|
certTemplate := &x509.Certificate{
|
|
|
|
Subject: pkix.Name{
|
|
|
|
CommonName: "example.com",
|
|
|
|
},
|
2019-05-20 22:15:05 +00:00
|
|
|
EmailAddresses: []string{"valid@example.com"},
|
|
|
|
IPAddresses: []net.IP{net.ParseIP("127.0.0.1")},
|
2019-04-26 23:49:30 +00:00
|
|
|
ExtKeyUsage: []x509.ExtKeyUsage{
|
|
|
|
x509.ExtKeyUsageServerAuth,
|
|
|
|
x509.ExtKeyUsageClientAuth,
|
|
|
|
},
|
|
|
|
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment | x509.KeyUsageKeyAgreement,
|
|
|
|
SerialNumber: big.NewInt(mathrand.Int63()),
|
|
|
|
NotBefore: time.Now().Add(-30 * time.Second),
|
|
|
|
NotAfter: time.Now().Add(262980 * time.Hour),
|
|
|
|
}
|
|
|
|
|
|
|
|
tempDir, connState, err := generateTestCertAndConnState(t, certTemplate)
|
|
|
|
if tempDir != "" {
|
|
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
}
|
2018-05-25 14:34:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2019-04-26 23:49:30 +00:00
|
|
|
ca, err := ioutil.ReadFile(filepath.Join(tempDir, "ca_cert.pem"))
|
2018-05-25 14:34:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
2019-04-26 23:49:30 +00:00
|
|
|
|
2018-05-25 14:34:46 +00:00
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2018-05-25 14:34:46 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{emails: "valid@example.com"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{emails: "*@example.com"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{emails: "invalid@notincert.com"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{emails: "abc"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{emails: "*.example.com"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-28 00:04:55 +00:00
|
|
|
// Test a self-signed client with OU (root CA) that is trusted
|
|
|
|
func TestBackend_organizationalUnit_singleCert(t *testing.T) {
|
|
|
|
connState, err := testConnState(
|
|
|
|
"test-fixtures/root/rootcawoucert.pem",
|
|
|
|
"test-fixtures/root/rootcawoukey.pem",
|
|
|
|
"test-fixtures/root/rootcawoucert.pem",
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcawoucert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2018-09-28 00:04:55 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{organizational_units: "engineering"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{organizational_units: "eng*"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{organizational_units: "engineering,finance"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{organizational_units: "foo"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-25 14:34:46 +00:00
|
|
|
// Test a self-signed client with URI alt names (root CA) that is trusted
|
|
|
|
func TestBackend_uri_singleCert(t *testing.T) {
|
2019-04-02 18:49:42 +00:00
|
|
|
u, err := url.Parse("spiffe://example.com/host")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
certTemplate := &x509.Certificate{
|
|
|
|
Subject: pkix.Name{
|
|
|
|
CommonName: "example.com",
|
|
|
|
},
|
|
|
|
DNSNames: []string{"example.com"},
|
|
|
|
IPAddresses: []net.IP{net.ParseIP("127.0.0.1")},
|
|
|
|
URIs: []*url.URL{u},
|
|
|
|
ExtKeyUsage: []x509.ExtKeyUsage{
|
|
|
|
x509.ExtKeyUsageServerAuth,
|
|
|
|
x509.ExtKeyUsageClientAuth,
|
|
|
|
},
|
|
|
|
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment | x509.KeyUsageKeyAgreement,
|
|
|
|
SerialNumber: big.NewInt(mathrand.Int63()),
|
|
|
|
NotBefore: time.Now().Add(-30 * time.Second),
|
|
|
|
NotAfter: time.Now().Add(262980 * time.Hour),
|
|
|
|
}
|
|
|
|
|
|
|
|
tempDir, connState, err := generateTestCertAndConnState(t, certTemplate)
|
2019-04-02 19:09:31 +00:00
|
|
|
if tempDir != "" {
|
|
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
}
|
2018-05-25 14:34:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2019-04-02 18:49:42 +00:00
|
|
|
ca, err := ioutil.ReadFile(filepath.Join(tempDir, "ca_cert.pem"))
|
2018-05-25 14:34:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2018-05-25 14:34:46 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{uris: "spiffe://example.com/*"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{uris: "spiffe://example.com/host"}, false),
|
|
|
|
testAccStepLogin(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{uris: "spiffe://example.com/invalid"}, false),
|
2017-12-18 17:53:44 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{uris: "abc"}, false),
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
testAccStepCert(t, "web", ca, "foo", allowed{uris: "http://www.google.com"}, false),
|
2017-04-30 15:37:10 +00:00
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test against a collection of matching and non-matching rules
|
|
|
|
func TestBackend_mixed_constraints(t *testing.T) {
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := testConnState("test-fixtures/keys/cert.pem",
|
2016-02-29 20:48:09 +00:00
|
|
|
"test-fixtures/keys/key.pem", "test-fixtures/root/rootcacert.pem")
|
2017-09-01 20:55:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2016-02-29 20:48:09 +00:00
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
2015-04-24 04:46:21 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2015-04-24 04:46:21 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
2018-05-25 14:34:46 +00:00
|
|
|
testAccStepCert(t, "1unconstrained", ca, "foo", allowed{}, false),
|
|
|
|
testAccStepCert(t, "2matching", ca, "foo", allowed{names: "*.example.com,whatever"}, false),
|
|
|
|
testAccStepCert(t, "3invalid", ca, "foo", allowed{names: "invalid"}, false),
|
2015-04-24 04:46:21 +00:00
|
|
|
testAccStepLogin(t, connState),
|
2017-04-30 15:37:10 +00:00
|
|
|
// Assumes CertEntries are processed in alphabetical order (due to store.List), so we only match 2matching if 1unconstrained doesn't match
|
|
|
|
testAccStepLoginWithName(t, connState, "2matching"),
|
|
|
|
testAccStepLoginWithNameInvalid(t, connState, "3invalid"),
|
2015-04-24 04:46:21 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-30 15:37:10 +00:00
|
|
|
// Test an untrusted client
|
2015-04-24 04:46:21 +00:00
|
|
|
func TestBackend_untrusted(t *testing.T) {
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := testConnState("test-fixtures/keys/cert.pem",
|
2016-02-29 20:48:09 +00:00
|
|
|
"test-fixtures/keys/key.pem", "test-fixtures/root/rootcacert.pem")
|
2017-09-01 20:55:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2015-04-24 04:46:21 +00:00
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2018-11-07 01:21:24 +00:00
|
|
|
CredentialBackend: testFactory(t),
|
2015-04-24 04:46:21 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepLoginInvalid(t, connState),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-09 22:39:55 +00:00
|
|
|
func TestBackend_validCIDR(t *testing.T) {
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
storage := &logical.InmemStorage{}
|
|
|
|
config.StorageView = storage
|
|
|
|
|
|
|
|
b, err := Factory(context.Background(), config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
connState, err := testConnState("test-fixtures/keys/cert.pem",
|
|
|
|
"test-fixtures/keys/key.pem", "test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := "web"
|
2019-02-08 03:41:38 +00:00
|
|
|
boundCIDRs := []string{"127.0.0.1", "128.252.0.0/16"}
|
2018-05-09 22:39:55 +00:00
|
|
|
|
|
|
|
addCertReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "certs/" + name,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"certificate": string(ca),
|
|
|
|
"policies": "foo",
|
|
|
|
"display_name": name,
|
|
|
|
"allowed_names": "",
|
|
|
|
"required_extensions": "",
|
|
|
|
"lease": 1000,
|
2019-02-08 03:41:38 +00:00
|
|
|
"bound_cidrs": boundCIDRs,
|
2018-05-09 22:39:55 +00:00
|
|
|
},
|
|
|
|
Storage: storage,
|
|
|
|
Connection: &logical.Connection{ConnState: &connState},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = b.HandleRequest(context.Background(), addCertReq)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-02-08 03:41:38 +00:00
|
|
|
readCertReq := &logical.Request{
|
2019-02-08 14:12:55 +00:00
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Path: "certs/" + name,
|
2019-02-08 03:41:38 +00:00
|
|
|
Storage: storage,
|
|
|
|
Connection: &logical.Connection{ConnState: &connState},
|
|
|
|
}
|
|
|
|
|
|
|
|
readResult, err := b.HandleRequest(context.Background(), readCertReq)
|
|
|
|
cidrsResult := readResult.Data["bound_cidrs"].([]*sockaddr.SockAddrMarshaler)
|
|
|
|
|
|
|
|
if cidrsResult[0].String() != boundCIDRs[0] ||
|
|
|
|
cidrsResult[1].String() != boundCIDRs[1] {
|
2019-02-08 14:12:55 +00:00
|
|
|
t.Fatalf("bound_cidrs couldn't be set correctly, EXPECTED: %v, ACTUAL: %v", boundCIDRs, cidrsResult)
|
2019-02-08 03:41:38 +00:00
|
|
|
}
|
|
|
|
|
2018-05-09 22:39:55 +00:00
|
|
|
loginReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "login",
|
|
|
|
Unauthenticated: true,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"name": name,
|
|
|
|
},
|
|
|
|
Storage: storage,
|
|
|
|
Connection: &logical.Connection{ConnState: &connState},
|
|
|
|
}
|
|
|
|
|
|
|
|
// override the remote address with an IPV4 that is authorized
|
|
|
|
loginReq.Connection.RemoteAddr = "127.0.0.1/32"
|
|
|
|
|
|
|
|
_, err = b.HandleRequest(context.Background(), loginReq)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackend_invalidCIDR(t *testing.T) {
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
storage := &logical.InmemStorage{}
|
|
|
|
config.StorageView = storage
|
|
|
|
|
|
|
|
b, err := Factory(context.Background(), config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
connState, err := testConnState("test-fixtures/keys/cert.pem",
|
|
|
|
"test-fixtures/keys/key.pem", "test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := "web"
|
|
|
|
|
|
|
|
addCertReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "certs/" + name,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"certificate": string(ca),
|
|
|
|
"policies": "foo",
|
|
|
|
"display_name": name,
|
|
|
|
"allowed_names": "",
|
|
|
|
"required_extensions": "",
|
|
|
|
"lease": 1000,
|
|
|
|
"bound_cidrs": []string{"127.0.0.1/32", "128.252.0.0/16"},
|
|
|
|
},
|
|
|
|
Storage: storage,
|
|
|
|
Connection: &logical.Connection{ConnState: &connState},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = b.HandleRequest(context.Background(), addCertReq)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
loginReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "login",
|
|
|
|
Unauthenticated: true,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"name": name,
|
|
|
|
},
|
|
|
|
Storage: storage,
|
|
|
|
Connection: &logical.Connection{ConnState: &connState},
|
|
|
|
}
|
|
|
|
|
|
|
|
// override the remote address with an IPV4 that isn't authorized
|
|
|
|
loginReq.Connection.RemoteAddr = "127.0.0.1/8"
|
|
|
|
|
|
|
|
_, err = b.HandleRequest(context.Background(), loginReq)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected \"ERROR: permission denied\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 17:04:54 +00:00
|
|
|
func testAccStepAddCRL(t *testing.T, crl []byte, connState tls.ConnectionState) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-10-15 17:04:54 +00:00
|
|
|
Path: "crls/test",
|
|
|
|
ConnState: &connState,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"crl": crl,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccStepReadCRL(t *testing.T, connState tls.ConnectionState) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Path: "crls/test",
|
|
|
|
ConnState: &connState,
|
|
|
|
Check: func(resp *logical.Response) error {
|
|
|
|
crlInfo := CRLInfo{}
|
|
|
|
err := mapstructure.Decode(resp.Data, &crlInfo)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if len(crlInfo.Serials) != 1 {
|
|
|
|
t.Fatalf("bad: expected CRL with length 1, got %d", len(crlInfo.Serials))
|
|
|
|
}
|
2016-02-29 03:15:54 +00:00
|
|
|
if _, ok := crlInfo.Serials["637101449987587619778072672905061040630001617053"]; !ok {
|
2016-02-29 15:41:10 +00:00
|
|
|
t.Fatalf("bad: expected serial number not found in CRL")
|
2015-10-15 17:04:54 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccStepDeleteCRL(t *testing.T, connState tls.ConnectionState) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.DeleteOperation,
|
|
|
|
Path: "crls/test",
|
|
|
|
ConnState: &connState,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 04:46:21 +00:00
|
|
|
func testAccStepLogin(t *testing.T, connState tls.ConnectionState) logicaltest.TestStep {
|
2017-04-30 15:37:10 +00:00
|
|
|
return testAccStepLoginWithName(t, connState, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccStepLoginWithName(t *testing.T, connState tls.ConnectionState, certName string) logicaltest.TestStep {
|
2015-04-24 04:46:21 +00:00
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-04-24 04:46:21 +00:00
|
|
|
Path: "login",
|
|
|
|
Unauthenticated: true,
|
|
|
|
ConnState: &connState,
|
2015-04-24 19:58:39 +00:00
|
|
|
Check: func(resp *logical.Response) error {
|
2015-08-21 00:47:17 +00:00
|
|
|
if resp.Auth.TTL != 1000*time.Second {
|
2015-04-24 19:58:39 +00:00
|
|
|
t.Fatalf("bad lease length: %#v", resp.Auth)
|
|
|
|
}
|
|
|
|
|
2017-04-30 15:37:10 +00:00
|
|
|
if certName != "" && resp.Auth.DisplayName != ("mnt-"+certName) {
|
|
|
|
t.Fatalf("matched the wrong cert: %#v", resp.Auth.DisplayName)
|
|
|
|
}
|
|
|
|
|
2016-03-15 18:07:40 +00:00
|
|
|
fn := logicaltest.TestCheckAuth([]string{"default", "foo"})
|
2015-04-24 19:58:39 +00:00
|
|
|
return fn(resp)
|
|
|
|
},
|
2017-04-30 15:37:10 +00:00
|
|
|
Data: map[string]interface{}{
|
|
|
|
"name": certName,
|
|
|
|
},
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 18:01:28 +00:00
|
|
|
func testAccStepLoginDefaultLease(t *testing.T, connState tls.ConnectionState) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-09-18 18:01:28 +00:00
|
|
|
Path: "login",
|
|
|
|
Unauthenticated: true,
|
|
|
|
ConnState: &connState,
|
|
|
|
Check: func(resp *logical.Response) error {
|
2017-12-18 20:29:45 +00:00
|
|
|
if resp.Auth.TTL != 1000*time.Second {
|
2015-09-18 18:01:28 +00:00
|
|
|
t.Fatalf("bad lease length: %#v", resp.Auth)
|
|
|
|
}
|
|
|
|
|
2016-03-15 18:07:40 +00:00
|
|
|
fn := logicaltest.TestCheckAuth([]string{"default", "foo"})
|
2015-09-18 18:01:28 +00:00
|
|
|
return fn(resp)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 04:46:21 +00:00
|
|
|
func testAccStepLoginInvalid(t *testing.T, connState tls.ConnectionState) logicaltest.TestStep {
|
2017-04-30 15:37:10 +00:00
|
|
|
return testAccStepLoginWithNameInvalid(t, connState, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccStepLoginWithNameInvalid(t *testing.T, connState tls.ConnectionState, certName string) logicaltest.TestStep {
|
2015-04-24 04:46:21 +00:00
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-04-24 04:46:21 +00:00
|
|
|
Path: "login",
|
|
|
|
Unauthenticated: true,
|
|
|
|
ConnState: &connState,
|
|
|
|
Check: func(resp *logical.Response) error {
|
2015-04-24 17:39:44 +00:00
|
|
|
if resp.Auth != nil {
|
|
|
|
return fmt.Errorf("should not be authorized: %#v", resp)
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2017-04-30 15:37:10 +00:00
|
|
|
Data: map[string]interface{}{
|
|
|
|
"name": certName,
|
|
|
|
},
|
2015-04-24 17:39:44 +00:00
|
|
|
ErrorOk: true,
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-15 18:07:40 +00:00
|
|
|
func testAccStepListCerts(
|
|
|
|
t *testing.T, certs []string) []logicaltest.TestStep {
|
|
|
|
return []logicaltest.TestStep{
|
2021-04-08 16:43:39 +00:00
|
|
|
{
|
2016-03-15 18:07:40 +00:00
|
|
|
Operation: logical.ListOperation,
|
|
|
|
Path: "certs",
|
|
|
|
Check: func(resp *logical.Response) error {
|
|
|
|
if resp == nil {
|
|
|
|
return fmt.Errorf("nil response")
|
|
|
|
}
|
|
|
|
if resp.Data == nil {
|
|
|
|
return fmt.Errorf("nil data")
|
|
|
|
}
|
|
|
|
if resp.Data["keys"] == interface{}(nil) {
|
|
|
|
return fmt.Errorf("nil keys")
|
|
|
|
}
|
|
|
|
keys := resp.Data["keys"].([]string)
|
|
|
|
if !reflect.DeepEqual(keys, certs) {
|
|
|
|
return fmt.Errorf("mismatch: keys is %#v, certs is %#v", keys, certs)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
}, {
|
2016-03-15 18:07:40 +00:00
|
|
|
Operation: logical.ListOperation,
|
|
|
|
Path: "certs/",
|
|
|
|
Check: func(resp *logical.Response) error {
|
2016-03-15 18:18:35 +00:00
|
|
|
if resp == nil {
|
|
|
|
return fmt.Errorf("nil response")
|
|
|
|
}
|
|
|
|
if resp.Data == nil {
|
|
|
|
return fmt.Errorf("nil data")
|
|
|
|
}
|
|
|
|
if resp.Data["keys"] == interface{}(nil) {
|
|
|
|
return fmt.Errorf("nil keys")
|
|
|
|
}
|
|
|
|
keys := resp.Data["keys"].([]string)
|
|
|
|
if !reflect.DeepEqual(keys, certs) {
|
|
|
|
return fmt.Errorf("mismatch: keys is %#v, certs is %#v", keys, certs)
|
|
|
|
}
|
2016-03-15 18:07:40 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 14:34:46 +00:00
|
|
|
type allowed struct {
|
2018-09-28 00:04:55 +00:00
|
|
|
names string // allowed names in the certificate, looks at common, name, dns, email [depricated]
|
|
|
|
common_names string // allowed common names in the certificate
|
|
|
|
dns string // allowed dns names in the SAN extension of the certificate
|
|
|
|
emails string // allowed email names in SAN extension of the certificate
|
|
|
|
uris string // allowed uris in SAN extension of the certificate
|
|
|
|
organizational_units string // allowed OUs in the certificate
|
|
|
|
ext string // required extensions in the certificate
|
2018-05-25 14:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 04:46:21 +00:00
|
|
|
func testAccStepCert(
|
2018-05-25 14:34:46 +00:00
|
|
|
t *testing.T, name string, cert []byte, policies string, testData allowed, expectError bool) logicaltest.TestStep {
|
2015-04-24 04:46:21 +00:00
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-04-24 17:31:57 +00:00
|
|
|
Path: "certs/" + name,
|
2016-02-29 23:29:41 +00:00
|
|
|
ErrorOk: expectError,
|
2015-04-24 04:46:21 +00:00
|
|
|
Data: map[string]interface{}{
|
2018-09-28 00:04:55 +00:00
|
|
|
"certificate": string(cert),
|
|
|
|
"policies": policies,
|
|
|
|
"display_name": name,
|
|
|
|
"allowed_names": testData.names,
|
|
|
|
"allowed_common_names": testData.common_names,
|
|
|
|
"allowed_dns_sans": testData.dns,
|
|
|
|
"allowed_email_sans": testData.emails,
|
|
|
|
"allowed_uri_sans": testData.uris,
|
|
|
|
"allowed_organizational_units": testData.organizational_units,
|
|
|
|
"required_extensions": testData.ext,
|
|
|
|
"lease": 1000,
|
2015-04-24 04:46:21 +00:00
|
|
|
},
|
2016-02-29 21:02:19 +00:00
|
|
|
Check: func(resp *logical.Response) error {
|
|
|
|
if resp == nil && expectError {
|
|
|
|
return fmt.Errorf("expected error but received nil")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 01:10:20 +00:00
|
|
|
func testAccStepCertLease(
|
|
|
|
t *testing.T, name string, cert []byte, policies string) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-10-06 01:10:20 +00:00
|
|
|
Path: "certs/" + name,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"certificate": string(cert),
|
|
|
|
"policies": policies,
|
|
|
|
"display_name": name,
|
|
|
|
"lease": 1000,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 18:01:28 +00:00
|
|
|
func testAccStepCertTTL(
|
|
|
|
t *testing.T, name string, cert []byte, policies string) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-09-18 18:01:28 +00:00
|
|
|
Path: "certs/" + name,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"certificate": string(cert),
|
|
|
|
"policies": policies,
|
|
|
|
"display_name": name,
|
2015-10-06 01:10:20 +00:00
|
|
|
"ttl": "1000s",
|
2015-09-18 18:01:28 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 20:29:45 +00:00
|
|
|
func testAccStepCertMaxTTL(
|
|
|
|
t *testing.T, name string, cert []byte, policies string) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "certs/" + name,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"certificate": string(cert),
|
|
|
|
"policies": policies,
|
|
|
|
"display_name": name,
|
|
|
|
"ttl": "1000s",
|
|
|
|
"max_ttl": "1200s",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 18:01:28 +00:00
|
|
|
func testAccStepCertNoLease(
|
|
|
|
t *testing.T, name string, cert []byte, policies string) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-09-18 18:01:28 +00:00
|
|
|
Path: "certs/" + name,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"certificate": string(cert),
|
|
|
|
"policies": policies,
|
|
|
|
"display_name": name,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 20:55:16 +00:00
|
|
|
func testConnState(certPath, keyPath, rootCertPath string) (tls.ConnectionState, error) {
|
2015-04-24 04:46:21 +00:00
|
|
|
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
|
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
return tls.ConnectionState{}, err
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
2016-05-03 16:23:25 +00:00
|
|
|
rootConfig := &rootcerts.Config{
|
|
|
|
CAFile: rootCertPath,
|
|
|
|
}
|
|
|
|
rootCAs, err := rootcerts.LoadCACerts(rootConfig)
|
2016-02-29 03:15:54 +00:00
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
return tls.ConnectionState{}, err
|
2016-02-29 03:15:54 +00:00
|
|
|
}
|
2015-09-03 17:04:32 +00:00
|
|
|
listenConf := &tls.Config{
|
2015-04-24 04:46:21 +00:00
|
|
|
Certificates: []tls.Certificate{cert},
|
|
|
|
ClientAuth: tls.RequestClientCert,
|
2016-02-29 03:15:54 +00:00
|
|
|
InsecureSkipVerify: false,
|
|
|
|
RootCAs: rootCAs,
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
2018-02-05 19:26:31 +00:00
|
|
|
dialConf := listenConf.Clone()
|
2017-09-01 20:55:16 +00:00
|
|
|
// start a server
|
2015-09-03 17:04:32 +00:00
|
|
|
list, err := tls.Listen("tcp", "127.0.0.1:0", listenConf)
|
2015-04-24 04:46:21 +00:00
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
return tls.ConnectionState{}, err
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
|
|
|
defer list.Close()
|
|
|
|
|
2017-09-01 20:55:16 +00:00
|
|
|
// Accept connections.
|
|
|
|
serverErrors := make(chan error, 1)
|
|
|
|
connState := make(chan tls.ConnectionState)
|
|
|
|
go func() {
|
|
|
|
defer close(connState)
|
|
|
|
serverConn, err := list.Accept()
|
|
|
|
serverErrors <- err
|
|
|
|
if err != nil {
|
|
|
|
close(serverErrors)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer serverConn.Close()
|
|
|
|
|
|
|
|
// Read the ping
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
_, err = serverConn.Read(buf)
|
|
|
|
if (err != nil) && (err != io.EOF) {
|
|
|
|
serverErrors <- err
|
|
|
|
close(serverErrors)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
// EOF is a reasonable error condition, so swallow it.
|
|
|
|
serverErrors <- nil
|
|
|
|
}
|
|
|
|
close(serverErrors)
|
|
|
|
connState <- serverConn.(*tls.Conn).ConnectionState()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Establish a connection from the client side and write a few bytes.
|
|
|
|
clientErrors := make(chan error, 1)
|
2015-04-24 04:46:21 +00:00
|
|
|
go func() {
|
|
|
|
addr := list.Addr().String()
|
2015-09-03 17:04:32 +00:00
|
|
|
conn, err := tls.Dial("tcp", addr, dialConf)
|
2017-09-01 20:55:16 +00:00
|
|
|
clientErrors <- err
|
2015-04-24 04:46:21 +00:00
|
|
|
if err != nil {
|
2017-09-01 20:55:16 +00:00
|
|
|
close(clientErrors)
|
|
|
|
return
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
// Write ping
|
2017-09-01 20:55:16 +00:00
|
|
|
_, err = conn.Write([]byte("ping"))
|
|
|
|
clientErrors <- err
|
|
|
|
close(clientErrors)
|
2015-04-24 04:46:21 +00:00
|
|
|
}()
|
|
|
|
|
2017-09-01 20:55:16 +00:00
|
|
|
for err = range clientErrors {
|
|
|
|
if err != nil {
|
|
|
|
return tls.ConnectionState{}, fmt.Errorf("error in client goroutine:%v", err)
|
|
|
|
}
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 20:55:16 +00:00
|
|
|
for err = range serverErrors {
|
|
|
|
if err != nil {
|
|
|
|
return tls.ConnectionState{}, fmt.Errorf("error in server goroutine:%v", err)
|
|
|
|
}
|
|
|
|
}
|
2015-04-24 04:46:21 +00:00
|
|
|
// Grab the current state
|
2017-09-01 20:55:16 +00:00
|
|
|
return <-connState, nil
|
2015-04-24 04:46:21 +00:00
|
|
|
}
|
2016-03-17 18:22:24 +00:00
|
|
|
|
|
|
|
func Test_Renew(t *testing.T) {
|
|
|
|
storage := &logical.InmemStorage{}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
lb, err := Factory(context.Background(), &logical.BackendConfig{
|
2016-03-17 18:22:24 +00:00
|
|
|
System: &logical.StaticSystemView{
|
|
|
|
DefaultLeaseTTLVal: 300 * time.Second,
|
|
|
|
MaxLeaseTTLVal: 1800 * time.Second,
|
|
|
|
},
|
|
|
|
StorageView: storage,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2016-12-21 18:08:27 +00:00
|
|
|
t.Fatalf("error: %s", err)
|
2016-03-17 18:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b := lb.(*backend)
|
2017-09-01 20:55:16 +00:00
|
|
|
connState, err := testConnState("test-fixtures/keys/cert.pem",
|
2016-03-17 18:22:24 +00:00
|
|
|
"test-fixtures/keys/key.pem", "test-fixtures/root/rootcacert.pem")
|
2017-09-01 20:55:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error testing connection state: %v", err)
|
|
|
|
}
|
2016-03-17 18:22:24 +00:00
|
|
|
ca, err := ioutil.ReadFile("test-fixtures/root/rootcacert.pem")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req := &logical.Request{
|
|
|
|
Connection: &logical.Connection{
|
|
|
|
ConnState: &connState,
|
|
|
|
},
|
|
|
|
Storage: storage,
|
|
|
|
Auth: &logical.Auth{},
|
|
|
|
}
|
|
|
|
|
|
|
|
fd := &framework.FieldData{
|
|
|
|
Raw: map[string]interface{}{
|
|
|
|
"name": "test",
|
|
|
|
"certificate": ca,
|
|
|
|
"policies": "foo,bar",
|
|
|
|
},
|
|
|
|
Schema: pathCerts(b).Fields,
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err := b.pathCertWrite(context.Background(), req, fd)
|
2016-03-17 18:22:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-04-30 15:37:10 +00:00
|
|
|
empty_login_fd := &framework.FieldData{
|
|
|
|
Raw: map[string]interface{}{},
|
|
|
|
Schema: pathLogin(b).Fields,
|
|
|
|
}
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.pathLogin(context.Background(), req, empty_login_fd)
|
2016-03-17 18:22:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-04-30 15:37:10 +00:00
|
|
|
if resp.IsError() {
|
|
|
|
t.Fatalf("got error: %#v", *resp)
|
|
|
|
}
|
2016-03-17 18:22:24 +00:00
|
|
|
req.Auth.InternalData = resp.Auth.InternalData
|
|
|
|
req.Auth.Metadata = resp.Auth.Metadata
|
|
|
|
req.Auth.LeaseOptions = resp.Auth.LeaseOptions
|
2016-03-24 13:41:51 +00:00
|
|
|
req.Auth.Policies = resp.Auth.Policies
|
2018-07-24 19:03:11 +00:00
|
|
|
req.Auth.TokenPolicies = req.Auth.Policies
|
2018-01-18 17:19:18 +00:00
|
|
|
req.Auth.Period = resp.Auth.Period
|
2016-03-17 18:22:24 +00:00
|
|
|
|
|
|
|
// Normal renewal
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.pathLoginRenew(context.Background(), req, empty_login_fd)
|
2016-03-17 18:22:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("got nil response from renew")
|
|
|
|
}
|
|
|
|
if resp.IsError() {
|
|
|
|
t.Fatalf("got error: %#v", *resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the policies -- this should fail
|
|
|
|
fd.Raw["policies"] = "zip,zap"
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.pathCertWrite(context.Background(), req, fd)
|
2016-03-17 18:22:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.pathLoginRenew(context.Background(), req, empty_login_fd)
|
2016-05-26 15:06:46 +00:00
|
|
|
if err == nil {
|
2016-03-17 18:22:24 +00:00
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:54:10 +00:00
|
|
|
// Put the policies back, this should be okay
|
2016-03-17 18:22:24 +00:00
|
|
|
fd.Raw["policies"] = "bar,foo"
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.pathCertWrite(context.Background(), req, fd)
|
2016-03-17 18:22:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.pathLoginRenew(context.Background(), req, empty_login_fd)
|
2016-03-17 18:22:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("got nil response from renew")
|
|
|
|
}
|
|
|
|
if resp.IsError() {
|
2016-12-21 18:08:27 +00:00
|
|
|
t.Fatalf("got error: %#v", *resp)
|
2016-03-17 18:22:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 17:19:18 +00:00
|
|
|
// Add period value to cert entry
|
|
|
|
period := 350 * time.Second
|
|
|
|
fd.Raw["period"] = period.String()
|
|
|
|
resp, err = b.pathCertWrite(context.Background(), req, fd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = b.pathLoginRenew(context.Background(), req, empty_login_fd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("got nil response from renew")
|
|
|
|
}
|
|
|
|
if resp.IsError() {
|
|
|
|
t.Fatalf("got error: %#v", *resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Auth.Period != period {
|
|
|
|
t.Fatalf("expected a period value of %s in the response, got: %s", period, resp.Auth.Period)
|
|
|
|
}
|
|
|
|
|
2016-03-17 18:22:24 +00:00
|
|
|
// Delete CA, make sure we can't renew
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.pathCertDelete(context.Background(), req, fd)
|
2016-03-17 18:22:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.pathLoginRenew(context.Background(), req, empty_login_fd)
|
2016-03-17 18:22:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("got nil response from renew")
|
|
|
|
}
|
|
|
|
if !resp.IsError() {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
}
|
2019-07-01 20:31:37 +00:00
|
|
|
|
|
|
|
func TestBackend_CertUpgrade(t *testing.T) {
|
|
|
|
s := &logical.InmemStorage{}
|
|
|
|
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
config.StorageView = s
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
b := Backend()
|
|
|
|
if b == nil {
|
|
|
|
t.Fatalf("failed to create backend")
|
|
|
|
}
|
|
|
|
if err := b.Setup(ctx, config); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
foo := &CertEntry{
|
|
|
|
Policies: []string{"foo"},
|
|
|
|
Period: time.Second,
|
|
|
|
TTL: time.Second,
|
|
|
|
MaxTTL: time.Second,
|
2021-04-08 16:43:39 +00:00
|
|
|
BoundCIDRs: []*sockaddr.SockAddrMarshaler{{SockAddr: sockaddr.MustIPAddr("127.0.0.1")}},
|
2019-07-01 20:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
entry, err := logical.StorageEntryJSON("cert/foo", foo)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = s.Put(ctx, entry)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
certEntry, err := b.Cert(ctx, s, "foo")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
exp := &CertEntry{
|
|
|
|
Policies: []string{"foo"},
|
|
|
|
Period: time.Second,
|
|
|
|
TTL: time.Second,
|
|
|
|
MaxTTL: time.Second,
|
2021-04-08 16:43:39 +00:00
|
|
|
BoundCIDRs: []*sockaddr.SockAddrMarshaler{{SockAddr: sockaddr.MustIPAddr("127.0.0.1")}},
|
2019-07-01 20:31:37 +00:00
|
|
|
TokenParams: tokenutil.TokenParams{
|
|
|
|
TokenPolicies: []string{"foo"},
|
|
|
|
TokenPeriod: time.Second,
|
|
|
|
TokenTTL: time.Second,
|
|
|
|
TokenMaxTTL: time.Second,
|
2021-04-08 16:43:39 +00:00
|
|
|
TokenBoundCIDRs: []*sockaddr.SockAddrMarshaler{{SockAddr: sockaddr.MustIPAddr("127.0.0.1")}},
|
2019-07-01 20:31:37 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
if diff := deep.Equal(certEntry, exp); diff != nil {
|
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
}
|