@ -71,6 +71,11 @@ func testConsulCAConfig() *structs.CAConfiguration {
}
}
func requireNotEncoded ( t * testing . T , v [ ] byte ) {
t . Helper ( )
require . False ( t , connect . IsHexString ( v ) )
}
func TestConsulCAProvider_Bootstrap ( t * testing . T ) {
t . Parallel ( )
@ -94,6 +99,8 @@ func TestConsulCAProvider_Bootstrap(t *testing.T) {
parsed , err := connect . ParseCert ( root )
require . NoError ( err )
require . Equal ( parsed . URIs [ 0 ] . String ( ) , fmt . Sprintf ( "spiffe://%s.consul" , conf . ClusterID ) )
requireNotEncoded ( t , parsed . SubjectKeyId )
requireNotEncoded ( t , parsed . AuthorityKeyId )
}
func TestConsulCAProvider_Bootstrap_WithCert ( t * testing . T ) {
@ -152,6 +159,8 @@ func TestConsulCAProvider_SignLeaf(t *testing.T) {
require . Equal ( parsed . URIs [ 0 ] , spiffeService . URI ( ) )
require . Equal ( parsed . Subject . CommonName , "foo" )
require . Equal ( uint64 ( 2 ) , parsed . SerialNumber . Uint64 ( ) )
requireNotEncoded ( t , parsed . SubjectKeyId )
requireNotEncoded ( t , parsed . AuthorityKeyId )
// Ensure the cert is valid now and expires within the correct limit.
now := time . Now ( )
@ -176,6 +185,8 @@ func TestConsulCAProvider_SignLeaf(t *testing.T) {
require . Equal ( parsed . URIs [ 0 ] , spiffeService . URI ( ) )
require . Equal ( parsed . Subject . CommonName , "bar" )
require . Equal ( parsed . SerialNumber . Uint64 ( ) , uint64 ( 2 ) )
requireNotEncoded ( t , parsed . SubjectKeyId )
requireNotEncoded ( t , parsed . AuthorityKeyId )
// Ensure the cert is valid now and expires within the correct limit.
require . True ( time . Until ( parsed . NotAfter ) < 3 * 24 * time . Hour )
@ -202,6 +213,8 @@ func TestConsulCAProvider_SignLeaf(t *testing.T) {
require . Equal ( spiffeAgent . URI ( ) , parsed . URIs [ 0 ] )
require . Equal ( "uuid" , parsed . Subject . CommonName )
require . Equal ( uint64 ( 2 ) , parsed . SerialNumber . Uint64 ( ) )
requireNotEncoded ( t , parsed . SubjectKeyId )
requireNotEncoded ( t , parsed . AuthorityKeyId )
// Ensure the cert is valid now and expires within the correct limit.
now := time . Now ( )
@ -240,22 +253,30 @@ func testCrossSignProviders(t *testing.T, provider1, provider2 Provider) {
newRoot , err := connect . ParseCert ( newRootPEM )
require . NoError ( err )
oldSubject := newRoot . Subject . CommonName
requireNotEncoded ( t , newRoot . SubjectKeyId )
requireNotEncoded ( t , newRoot . AuthorityKeyId )
newInterPEM , err := provider2 . ActiveIntermediate ( )
require . NoError ( err )
newIntermediate , err := connect . ParseCert ( newInterPEM )
require . NoError ( err )
requireNotEncoded ( t , newIntermediate . SubjectKeyId )
requireNotEncoded ( t , newIntermediate . AuthorityKeyId )
// Have provider1 cross sign our new root cert.
xcPEM , err := provider1 . CrossSignCA ( newRoot )
require . NoError ( err )
xc , err := connect . ParseCert ( xcPEM )
require . NoError ( err )
requireNotEncoded ( t , xc . SubjectKeyId )
requireNotEncoded ( t , xc . AuthorityKeyId )
oldRootPEM , err := provider1 . ActiveRoot ( )
require . NoError ( err )
oldRoot , err := connect . ParseCert ( oldRootPEM )
require . NoError ( err )
requireNotEncoded ( t , oldRoot . SubjectKeyId )
requireNotEncoded ( t , oldRoot . AuthorityKeyId )
// AuthorityKeyID should now be the signing root's, SubjectKeyId should be kept.
require . Equal ( oldRoot . AuthorityKeyId , xc . AuthorityKeyId )
@ -284,6 +305,8 @@ func testCrossSignProviders(t *testing.T, provider1, provider2 Provider) {
cert , err := connect . ParseCert ( leafPEM )
require . NoError ( err )
requireNotEncoded ( t , cert . SubjectKeyId )
requireNotEncoded ( t , cert . AuthorityKeyId )
// Check that the leaf signed by the new cert can be verified by either root
// certificate by using the new intermediate + cross-signed cert.
@ -357,6 +380,8 @@ func testSignIntermediateCrossDC(t *testing.T, provider1, provider2 Provider) {
cert , err := connect . ParseCert ( leafPEM )
require . NoError ( err )
requireNotEncoded ( t , cert . SubjectKeyId )
requireNotEncoded ( t , cert . AuthorityKeyId )
// Check that the leaf signed by the new cert can be verified using the
// returned cert chain (signed intermediate + remote root).