Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
d1d7565
added certz3.1
priyacj Aug 3, 2024
8faeda2
Merge branch 'openconfig:main' into certz3.1
priyacj Aug 3, 2024
1d6388a
fixed metadeta
priyacj Aug 3, 2024
c7a894a
Merge branch 'openconfig:main' into certz3.1
priyacj Aug 14, 2024
0861011
Merge branch 'openconfig:main' into certz3.1
priyacj Aug 19, 2024
8cff47c
Merge branch 'openconfig:main' into certz3.1
priyacj Aug 20, 2024
ca5c17f
Merge branch 'openconfig:main' into certz3.1
priyacj Aug 23, 2024
4262121
Merge branch 'openconfig:main' into certz3.1
priyacj Aug 28, 2024
bab7239
Merge branch 'openconfig:main' into certz3.1
priyacj Aug 28, 2024
1b74542
Merge branch 'openconfig:main' into certz3.1
priyacj Sep 10, 2024
f153984
Merge branch 'openconfig:main' into certz3.1
priyacj Sep 18, 2024
706d978
Merge branch 'openconfig:main' into certz3.1
priyacj Sep 21, 2024
214a690
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 21, 2024
9194eea
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 14, 2024
d66833a
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 18, 2024
546b494
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 20, 2024
7ffbd0b
fixed the deprecated grpc.WithBlock:DialOption
priyacj Nov 20, 2024
5384f15
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 21, 2024
7bcec00
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 25, 2024
a23257d
fixed the script
priyacj Nov 25, 2024
f8d55a6
fixed the static check error
priyacj Nov 25, 2024
93ce953
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 26, 2024
045cfe3
fixed the string error
priyacj Nov 26, 2024
66a6820
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 4, 2024
248a099
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 5, 2024
a16194f
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 5, 2024
77e13a1
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 5, 2024
0fbe47b
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 12, 2024
e796a3c
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 16, 2024
9b626c0
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 19, 2024
b67b595
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 2, 2025
0110a8d
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 3, 2025
6c60550
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 6, 2025
f177e8b
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 7, 2025
8f9bc0c
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 7, 2025
60e89b8
fixed the lint static errors and feedback comments
priyacj Jan 7, 2025
9cc0aad
modified server_certificate_rotation/server_certificate_rotation_test.go
priyacj Jan 7, 2025
6d8646b
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 9, 2025
4d7d198
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 10, 2025
d2530c3
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 13, 2025
69c668a
taken care of the comments
priyacj Jan 13, 2025
c4fe8b5
fixed the package name
priyacj Jan 13, 2025
3efbc73
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 16, 2025
75e4cde
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 17, 2025
7eaf25b
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 23, 2025
6381337
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 27, 2025
e0f1f19
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 30, 2025
926ee91
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 7, 2025
315ffdd
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 10, 2025
7917055
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 14, 2025
12a1378
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 16, 2025
cb157aa
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 18, 2025
919a23f
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 20, 2025
9a8ece4
Merge branch 'openconfig:main' into certz3.1
priyacj Mar 10, 2025
32aca1a
Merge branch 'openconfig:main' into certz3.1
priyacj Mar 13, 2025
2652703
Merge branch 'openconfig:main' into certz3.1
priyacj Mar 27, 2025
0a96f5e
Merge branch 'openconfig:main' into certz3.1
priyacj Apr 14, 2025
c77d11e
Merge branch 'openconfig:main' into certz3.1
priyacj Apr 23, 2025
07b5372
Merge branch 'openconfig:main' into certz3.1
priyacj Apr 29, 2025
7af9533
Merge branch 'openconfig:main' into certz3.1
priyacj May 13, 2025
47e8a0e
Merge branch 'openconfig:main' into certz3.1
priyacj Sep 15, 2025
61021e3
Merge branch 'openconfig:main' into certz3.1
priyacj Sep 21, 2025
96a1d57
Merge branch 'openconfig:main' into certz3.1
priyacj Sep 23, 2025
2d41950
Merge branch 'openconfig:main' into certz3.1
priyacj Sep 26, 2025
600ffad
Merge branch 'openconfig:main' into certz3.1
priyacj Sep 29, 2025
7352fb0
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 1, 2025
e6042f1
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 1, 2025
942dd0f
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 2, 2025
0aefcee
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 7, 2025
2ab3c4b
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 7, 2025
af6c215
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 8, 2025
74e9a32
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 9, 2025
9999487
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 10, 2025
5df887b
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 10, 2025
025a925
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 13, 2025
b433c6f
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 13, 2025
cdd9da3
Update README.md with OC canonical comments
priyacj Oct 14, 2025
c2d78d2
removed unwanted files
priyacj Oct 14, 2025
cdfb873
fixed the codepath
priyacj Oct 14, 2025
8522ae4
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 14, 2025
4ea07cd
fixed package in go script
priyacj Oct 14, 2025
39c7ba7
fixed metadatfile
priyacj Oct 14, 2025
5bac8a1
edited metadata file
priyacj Oct 14, 2025
161b28e
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 16, 2025
f8fc7f4
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 17, 2025
91861ee
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 21, 2025
da68fb9
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 22, 2025
de3688c
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 28, 2025
6d76d44
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 29, 2025
d36699a
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 31, 2025
c3ae494
fixed the given feedback comments
priyacj Oct 31, 2025
849962e
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 31, 2025
db3a5f5
Merge branch 'openconfig:main' into certz3.1
priyacj Oct 31, 2025
5c0c06e
fixed the fmt error
priyacj Oct 31, 2025
d4828aa
Merge branch 'main' into certz3.1
lvaish05 Nov 3, 2025
54334d5
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 4, 2025
130ec9c
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 5, 2025
ec6c156
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 5, 2025
1b568ae
Merge branch 'main' into certz3.1
lvaish05 Nov 6, 2025
13c5a39
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 7, 2025
a060061
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 10, 2025
d428e27
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 13, 2025
49d0242
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 19, 2025
4eeae8b
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 20, 2025
65e21d9
Merge branch 'openconfig:main' into certz3.1
priyacj Nov 21, 2025
fa4e06d
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 1, 2025
b9d36ac
Merge branch 'openconfig:main' into certz3.1
priyacj Dec 8, 2025
23d659e
fixed the go.mod
priyacj Jan 8, 2026
fde7e6b
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 13, 2026
15484b1
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 14, 2026
258f81a
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 16, 2026
6da0111
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 20, 2026
4114ba1
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 22, 2026
73e9259
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 23, 2026
c770e4a
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 26, 2026
021da42
Merge branch 'openconfig:main' into certz3.1
priyacj Jan 31, 2026
8fa5832
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 3, 2026
cff88b3
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 4, 2026
f00a281
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 6, 2026
eec42de
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 9, 2026
8aa1d7e
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 10, 2026
d576edc
Merge branch 'openconfig:main' into certz3.1
priyacj Feb 12, 2026
d2457cf
Merge branch 'main' into certz3.1
morrowc Feb 15, 2026
21ac2db
Update feature/gnsi/certz/tests/server_certificate_rotation/server_ce…
morrowc Feb 15, 2026
a46af8f
Update feature/gnsi/certz/tests/server_certificate_rotation/README.md
morrowc Feb 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions feature/gnsi/certz/tests/server_certificate_rotation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,6 @@ Perform this test with both the RSA and ECDSA types.
connections to the service impaired / restarted / delayed due to
the rotation event.


### Certz-3.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened to this part?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This testcase 3.2 is being removed based on discussion in b/311141278.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we actually have devices which require this behavior (or which fail to use a cert that can't be validated by the local trustbundle)

I suppose "sure that's not REQUIRED"


Perform these negative tests:

Test that a server certificate can be rotated by using the gNSI certz Rotate()
api if the certificate is requested without the device generated CSR, expect a
failure because the certificate loaded is not signed by a trusted CA.

Perform this test with both the RSA and ECDSA types.

0) Build the test data, configure the DUT to use the ca-0001 form
key/certificate/trust_bundle, use the server-${TYPE}-a key/certificate.

1) With the server running, connect and note that the ceritficate loaded
is the appropriate one.

2) Use the gNSI Rotate RPC to load a ca-02/server-${TYPE}-b key and
certificate on to the server.

3) Test that the certificate load fails, because the certificate is not
trusted by a known CA.

4) Tear down the Rotate RPC, forcing the device to return to the
previously used certificate/key material.

5) Verify that the server is now serving the previous certifcate properly.

## OpenConfig Path and RPC Coverage

The below yaml defines the OC paths intended to be covered by this test. OC paths used for test setup are not listed here.
Expand All @@ -106,6 +78,15 @@ rpcs:
certz.v1.Certz.Rotate:
```

## Canonical OC
No OC configuration is performed in this test as all interaction is via gNSI.Certz

```json
{

}
```

## Minimum DUT Platform Requirement

vRX
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package server_certificate_rotation_test

import (
"context"
"crypto/tls"
"crypto/x509"
"slices"
"testing"
"time"

setupService "github.com/openconfig/featureprofiles/feature/gnsi/certz/tests/internal/setup_service"
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/gnmi/proto/gnmi"
certzpb "github.com/openconfig/gnsi/certz"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/binding"
)

const (
dirPath = "../../test_data/"
timeOutVar time.Duration = 2 * time.Minute
)

// DUTCredentialer is an interface for getting credentials from
type DUTCredentialer interface {
RPCUsername() string
RPCPassword() string
}

var (
serverAddr string
creds DUTCredentialer //an interface for getting credentials from a DUT binding
testProfile string = "newprofile" //sslProfileId name
prevClientCertFile string = ""
prevClientKeyFile string = ""
prevTrustBundleFile string = ""
Comment on lines +48 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The test cases in the cases slice are not independent. They share state through global variables prevClientCertFile, prevClientKeyFile, and prevTrustBundleFile. This makes the tests order-dependent and fragile. For example, running a single test case in isolation would fail. Test cases should be self-contained. Please refactor the test to remove this dependency. One approach is to make each test case perform the full sequence of operations it needs, or structure the test as a sequence of explicit steps rather than a table-driven test with hidden state passing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared state here is going to be a problem, eventually.
Please move the currently shared state into the test definitions / struct.

logTime string = time.Now().String() //Timestamp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The global variable logTime is initialized only once when the test package is loaded. Using it in log messages is misleading because it will show the same timestamp for all test executions, not the time of the log event. It's better to remove this variable and let the testing framework's logger handle timestamps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you just need to move this logTime into each test loop so you get unique times per loop through in the logs.

expectedResult bool = true
success bool
)

func TestMain(m *testing.M) {
fptest.RunTests(m)
}

// TestServerCertRotation tests a server certificate can be rotated by using the gNSI certz Rotate() rpc,
// if the certificate is requested without the device generated CSR.
func TestServerCertRotation(t *testing.T) {

dut := ondatra.DUT(t, "dut")
serverAddr = dut.Name() //returns the device name.
if err := binding.DUTAs(dut.RawAPIs().BindingDUT(), &creds); err != nil {
t.Fatalf("%s:STATUS:Failed to get DUT credentials using binding.DUTAs: %v. The binding for %s must implement the DUTCredentialer interface.", logTime, err, dut.Name())
}
username := creds.RPCUsername()
password := creds.RPCPassword()
t.Logf("%s:STATUS:Validation of all services that are using gRPC before certz rotation.", logTime)
gnmiClient, gnsiC := setupService.PreInitCheck(context.Background(), t, dut)
//Generate testdata certificates.
t.Logf("%s:Creation of test data.", logTime)
if err := setupService.TestdataMakeCleanup(t, dirPath, timeOutVar, "./mk_cas.sh"); err != nil {
t.Fatalf("%s:STATUS:Generation of testdata certificates failed!: %v", logTime, err)
}
//Create a certz client.
ctx := context.Background()
certzClient := gnsiC.Certz()
t.Logf("%s:STATUS:Precheck:checking baseline sslprofile list.", logTime)
//Get sslprofile list.
if getResp := setupService.GetSslProfilelist(ctx, t, certzClient, &certzpb.GetProfileListRequest{}); slices.Contains(getResp.SslProfileIds, testProfile) {
t.Fatalf("%s:STATUS:profileID %s already exists.", logTime, testProfile)
}
//Add new sslprofileID.
t.Logf("%s:Adding new empty sslprofile ID %s.", logTime, testProfile)
if addProfileResponse, err := certzClient.AddProfile(ctx, &certzpb.AddProfileRequest{SslProfileId: testProfile}); err != nil {
t.Fatalf("%s:STATUS:Add profile request failed with %v! ", logTime, err)
} else {
t.Logf("%s:STATUS:Received the AddProfileResponse %v.", logTime, addProfileResponse)
}
//Get sslprofile list after new sslprofile addition.
if getResp := setupService.GetSslProfilelist(ctx, t, certzClient, &certzpb.GetProfileListRequest{}); !slices.Contains(getResp.SslProfileIds, testProfile) {
t.Fatalf("%s:STATUS:newly added profileID is not seen.", logTime)
} else {
t.Logf("%s:STATUS:new profileID %s is seen in sslprofile list", logTime, testProfile)
}
cases := []struct {
desc string
serverCertFile string
serverKeyFile string
trustBundleFile string
clientCertFile string
clientKeyFile string
cversion string
bversion string
newTLScreds bool
serverCertOnlyRotate bool
mismatch bool
scale bool
}{
{
desc: "Certz3.1:Rotate server-rsa-a certificate/key/trustbundle from ca-01",
serverCertFile: dirPath + "ca-01/server-rsa-a-cert.pem",
serverKeyFile: dirPath + "ca-01/server-rsa-a-key.pem",
trustBundleFile: dirPath + "ca-01/trust_bundle_01_rsa.p7b",
clientCertFile: dirPath + "ca-01/client-rsa-a-cert.pem",
clientKeyFile: dirPath + "ca-01/client-rsa-a-key.pem",
cversion: "v1",
bversion: "bundle1",
},
{
desc: "Certz3.1:Rotate server-rsa-b certificate/key/trustbundle from ca-01",
serverCertFile: dirPath + "ca-01/server-rsa-b-cert.pem",
serverKeyFile: dirPath + "ca-01/server-rsa-b-key.pem",
trustBundleFile: dirPath + "ca-01/trust_bundle_01_rsa.p7b",
clientCertFile: dirPath + "ca-01/client-rsa-b-cert.pem",
clientKeyFile: dirPath + "ca-01/client-rsa-b-key.pem",
cversion: "v2",
bversion: "bundle1",
serverCertOnlyRotate: true,
newTLScreds: true,
},
{
desc: "Certz3.1:Rotate server-ecdsa-a certificate/key/trustbundle from ca-01",
serverCertFile: dirPath + "ca-01/server-ecdsa-a-cert.pem",
serverKeyFile: dirPath + "ca-01/server-ecdsa-a-key.pem",
trustBundleFile: dirPath + "ca-01/trust_bundle_01_ecdsa.p7b",
clientCertFile: dirPath + "ca-01/client-ecdsa-a-cert.pem",
clientKeyFile: dirPath + "ca-01/client-ecdsa-a-key.pem",
cversion: "v3",
bversion: "bundle2",
newTLScreds: true,
},
{
desc: "Certz3.1:Rotate server-ecdsa-b certificate/key/trustbundle from ca-01",
serverCertFile: dirPath + "ca-01/server-ecdsa-b-cert.pem",
serverKeyFile: dirPath + "ca-01/server-ecdsa-b-key.pem",
trustBundleFile: dirPath + "ca-01/trust_bundle_01_ecdsa.p7b",
clientCertFile: dirPath + "ca-01/client-ecdsa-b-cert.pem",
clientKeyFile: dirPath + "ca-01/client-ecdsa-b-key.pem",
cversion: "v4",
bversion: "bundle2",
serverCertOnlyRotate: true,
newTLScreds: true,
},
}
for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
t.Logf("%s:STATUS:Starting test case: %s", logTime, tc.desc)
//Read the serverSAN (Subject Alternative Name) from the certificate used for TLS verification.
serverSAN := setupService.ReadDecodeServerCertificate(t, tc.serverCertFile)
//Build serverCertEntity for the server certificate rotation.
serverCert := setupService.CreateCertzChain(t, setupService.CertificateChainRequest{
RequestType: setupService.EntityTypeCertificateChain,
ServerCertFile: tc.serverCertFile,
ServerKeyFile: tc.serverKeyFile})
serverCertEntity := setupService.CreateCertzEntity(t, setupService.EntityTypeCertificateChain, &serverCert, tc.cversion)
//Create a new Cert Pool and add the certs from the trust bundle.
pkcs7certs, pkcs7data, err := setupService.Loadpkcs7TrustBundle(tc.trustBundleFile)
if err != nil {
t.Fatalf("%s:STATUS:failed to load trust bundle: %v", logTime, err)
}
newCaCert := x509.NewCertPool()
for _, c := range pkcs7certs {
newCaCert.AddCert(c)
}
//Build trustBundleEntity for the server certificate rotation.
trustBundleEntity := setupService.CreateCertzEntity(t, setupService.EntityTypeTrustBundle, string(pkcs7data), tc.bversion)
//Load Client certificate.
newClientCert, err := tls.LoadX509KeyPair(tc.clientCertFile, tc.clientKeyFile)
if err != nil {
t.Fatalf("%s:STATUS:Failed to load client cert:%v", logTime, err)
}
if tc.newTLScreds {
t.Logf("%s:STATUS:%s:Creating new TLS credentials for client connection.", logTime, tc.desc)
//Load the prior client keypair for new client TLS credentials.
prevClientCert, err := tls.LoadX509KeyPair(prevClientCertFile, prevClientKeyFile)
if err != nil {
t.Fatalf("%s:STATUS:%s:Failed to load previous client cert: %v", logTime, tc.desc, err)
}
oldPkcs7certs, oldPkcs7data, err := setupService.Loadpkcs7TrustBundle(prevTrustBundleFile)
if err != nil {
t.Fatalf("%s:STATUS:%sFailed to load previous trust bundle,data %v with %v", logTime, tc.desc, oldPkcs7data, err)
}
//Create a old set of Cert Pool and append the certs from previous trust bundle.
prevCaCert := x509.NewCertPool()
for _, c := range oldPkcs7certs {
prevCaCert.AddCert(c)
}
//Before rotation, validation of all services with existing certificates.
if result := setupService.ServicesValidationCheck(t, prevCaCert, expectedResult, serverSAN, serverAddr, username, password, prevClientCert, tc.mismatch); !result {
t.Fatalf("%s:STATUS:%s:service validation failed before rotate- got %v, want %v.", logTime, tc.desc, result, expectedResult)
}
//Retrieve the connection with previous TLS credentials for certz rotation.
conn := setupService.CreateNewDialOption(t, prevClientCert, prevCaCert, serverSAN, username, password, serverAddr)
defer conn.Close()
certzClient = certzpb.NewCertzClient(conn)
gnmiClient = gnmi.NewGNMIClient(conn)
} else {
t.Logf("%s:STATUS:%s:Using existing TLS credentials for client connection in first iteration.", logTime, tc.desc)
}
//Initiate server certitificate rotation.
if tc.serverCertOnlyRotate {
t.Logf("%s:STATUS:%s:Initiating server certificate rotation to server-${TYPE}-b.", logTime, tc.desc)
if success = setupService.CertzRotate(ctx, t, newCaCert, certzClient, gnmiClient, newClientCert, dut, username, password, serverSAN, serverAddr, testProfile, tc.newTLScreds, tc.mismatch, tc.scale, &serverCertEntity); !success {
t.Fatalf("%s STATUS %s:Server certificate rotation failed.", logTime, tc.desc)
}
} else {
t.Logf("%s:STATUS:%s Initiating Certz rotation with server cert: %s and trust bundle: %s", logTime, tc.desc, tc.serverCertFile, tc.trustBundleFile)
if success = setupService.CertzRotate(ctx, t, newCaCert, certzClient, gnmiClient, newClientCert, dut, username, password, serverSAN, serverAddr, testProfile, tc.newTLScreds, tc.mismatch, tc.scale, &serverCertEntity, &trustBundleEntity); !success {
t.Fatalf("%s STATUS %s:Server certificate rotation failed.", logTime, tc.desc)
}
}
t.Logf("%s:STATUS:%s:Server certificate rotation completed!", logTime, tc.desc)
t.Run("Verification of new connection after successful server certificate rotation", func(t *testing.T) {
if result := setupService.ServicesValidationCheck(t, newCaCert, expectedResult, serverSAN, serverAddr, username, password, newClientCert, tc.mismatch); !result {
t.Fatalf("%s:STATUS:%s:service validation failed after rotate- got %v, want %v.", logTime, tc.desc, result, expectedResult)
}
t.Logf("%s:STATUS:%s:service validation done!", logTime, tc.desc)
})
//Archiving previous client cert/key and trustbundle.
prevClientCertFile = tc.clientCertFile
prevClientKeyFile = tc.clientKeyFile
prevTrustBundleFile = tc.trustBundleFile
})
}
t.Logf("%s:STATUS:Cleanup of test data.", logTime)
//Cleanup of test data.
if err := setupService.TestdataMakeCleanup(t, dirPath, timeOutVar, "./cleanup.sh"); err != nil {
t.Logf("%s:STATUS:Cleanup of testdata certificates failed!: %v", logTime, err)
}
t.Logf("%s:STATUS: Testdata cleanup completed!", logTime)
}
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.einride.tech/aip v0.68.0 h1:4seM66oLzTpz50u4K1zlJyOXQ3tCzcJN7I22tKkjipw=
go.einride.tech/aip v0.68.0/go.mod h1:7y9FF8VtPWqpxuAxl0KQWqaULxW4zFIesD6zF5RIHHg=
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 h1:CCriYyAfq1Br1aIYettdHZTy8mBTIPo7We18TuO/bak=
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352/go.mod h1:SNgMg+EgDFwmvSmLRTNKC5fegJjB7v23qTQ0XLGUNHk=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
Expand Down
Loading