Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add trust-anchor-cert to progress #339

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ docker-compose exec -T bootstrap curl -i -X GET --user my-admin@example.com:my-s

# check bootstrapping log
docker-compose exec -T bootstrap curl -i -X GET --user my-admin@example.com:my-secret -H "Accept:application/yang-data+json" http://bootstrap:7080/restconf/ds/ietf-datastores:operational/wn-sztpd-1:devices/device=my-serial-number/bootstrapping-log
docker-compose exec -T bootstrap curl -i -X GET --user my-admin@example.com:my-secret -H "Accept:application/yang-data+json" http://bootstrap:7080/restconf/ds/ietf-datastores:operational/wn-sztpd-1:devices/device=my-serial-number/bootstrapping-log | grep -zqv ietf-restconf:errors

# parse the reply some more
jq -r .\"ietf-sztp-conveyed-info:onboarding-information\".\"configuration\" /tmp/post_rpc_fixed.json | base64 --decode
Expand Down
3 changes: 3 additions & 0 deletions sztp-agent/pkg/secureagent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type ProgressJSON struct {
KeyData string `json:"key-data"`
} `json:"ssh-host-key,omitempty"`
} `json:"ssh-host-keys,omitempty"`
TrustAnchorCerts struct {
TrustAnchorCert []string `json:"trust-anchor-cert,omitempty"`
} `json:"trust-anchor-certs,omitempty"`
} `json:"ietf-sztp-bootstrap-server:input"`
}

Expand Down
12 changes: 12 additions & 0 deletions sztp-agent/pkg/secureagent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,9 @@ func TestAgent_GetProgressJson(t *testing.T) {
KeyData string `json:"key-data"`
} `json:"ssh-host-key,omitempty"`
} `json:"ssh-host-keys,omitempty"`
TrustAnchorCerts struct {
TrustAnchorCert []string `json:"trust-anchor-cert,omitempty"`
} `json:"trust-anchor-certs,omitempty"`
}{
ProgressType: "test",
Message: "test",
Expand All @@ -909,6 +912,9 @@ func TestAgent_GetProgressJson(t *testing.T) {
KeyData string `json:"key-data"`
} `json:"ssh-host-key,omitempty"`
} `json:"ssh-host-keys,omitempty"`
TrustAnchorCerts struct {
TrustAnchorCert []string `json:"trust-anchor-cert,omitempty"`
} `json:"trust-anchor-certs,omitempty"`
}{
ProgressType: "test",
Message: "test",
Expand Down Expand Up @@ -980,6 +986,9 @@ func TestAgent_SetProgressJson(t *testing.T) {
KeyData string `json:"key-data"`
} `json:"ssh-host-key,omitempty"`
} `json:"ssh-host-keys,omitempty"`
TrustAnchorCerts struct {
TrustAnchorCert []string `json:"trust-anchor-cert,omitempty"`
} `json:"trust-anchor-certs,omitempty"`
}{
ProgressType: "test",
Message: "test",
Expand All @@ -997,6 +1006,9 @@ func TestAgent_SetProgressJson(t *testing.T) {
KeyData string `json:"key-data"`
} `json:"ssh-host-key,omitempty"`
} `json:"ssh-host-keys,omitempty"`
TrustAnchorCerts struct {
TrustAnchorCert []string `json:"trust-anchor-cert,omitempty"`
} `json:"trust-anchor-certs,omitempty"`
}{
ProgressType: "testNew",
Message: "testNew",
Expand Down
1 change: 1 addition & 0 deletions sztp-agent/pkg/secureagent/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
if s == ProgressTypeBootstrapComplete {
// TODO: generate real key here
encodedKey := base64.StdEncoding.EncodeToString([]byte("mysshpass"))
p.IetfSztpBootstrapServerInput.TrustAnchorCerts.TrustAnchorCert = []string{encodedKey}
p.IetfSztpBootstrapServerInput.SSHHostKeys.SSHHostKey = []struct {
Algorithm string `json:"algorithm"`
KeyData string `json:"key-data"`
Expand Down Expand Up @@ -219,7 +220,7 @@
},
Transport: &http.Transport{
TLSClientConfig: &tls.Config{ //nolint:gosec
InsecureSkipVerify: true, // TODO: remove skip verify

Check failure on line 223 in sztp-agent/pkg/secureagent/daemon.go

View workflow job for this annotation

GitHub Actions / golangci

G402: TLS InsecureSkipVerify set true. (gosec)
RootCAs: caCertPool,
Certificates: []tls.Certificate{cert},
},
Expand Down Expand Up @@ -310,7 +311,7 @@
log.Println("[ERROR] writing the configuration file", err.Error())
return err
}
err = os.Chmod(ARTIFACTS_PATH+a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.InfoTimestampReference+"-config", 0744)

Check failure on line 314 in sztp-agent/pkg/secureagent/daemon.go

View workflow job for this annotation

GitHub Actions / golangci

G302: Expect file permissions to be 0600 or less (gosec)
if err != nil {
log.Println("[ERROR] changing the configuration file permission", err.Error())
return err
Expand All @@ -337,7 +338,7 @@
}
log.Println("[INFO] Starting the " + scriptName + "-configuration.")
_ = a.doReportProgress(reportStart)
file, err := os.Create(ARTIFACTS_PATH + a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.InfoTimestampReference + scriptName + "configuration.sh")

Check failure on line 341 in sztp-agent/pkg/secureagent/daemon.go

View workflow job for this annotation

GitHub Actions / golangci

G304: Potential file inclusion via variable (gosec)
if err != nil {
log.Println("[ERROR] creating the "+scriptName+"-configuration script", err.Error())
return err
Expand All @@ -354,7 +355,7 @@
log.Println("[ERROR] writing the "+scriptName+"-configuration script", err.Error())
return err
}
err = os.Chmod(ARTIFACTS_PATH+a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.InfoTimestampReference+scriptName+"configuration.sh", 0755)

Check failure on line 358 in sztp-agent/pkg/secureagent/daemon.go

View workflow job for this annotation

GitHub Actions / golangci

G302: Expect file permissions to be 0600 or less (gosec)
if err != nil {
log.Println("[ERROR] changing the "+scriptName+"-configuration script permission", err.Error())
return err
Expand Down
Loading