Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
09891c3a
Commit
09891c3a
authored
Nov 29, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Remove hardcoded URL for NDF downloading
parent
17e0d275
No related branches found
No related tags found
2 merge requests
!117
Release
,
!74
Implement bindings for downloading and verifying signed partial NDF
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
bindings/ndf.go
+0
-27
0 additions, 27 deletions
bindings/ndf.go
bindings/ndf_test.go
+9
-30
9 additions, 30 deletions
bindings/ndf_test.go
with
9 additions
and
57 deletions
bindings/ndf.go
+
0
−
27
View file @
09891c3a
...
@@ -18,33 +18,6 @@ import (
...
@@ -18,33 +18,6 @@ import (
"net/http"
"net/http"
)
)
// ndfUrl is a hardcoded url to a bucket containing the signed NDF message.
const
ndfUrl
=
`https://elixxir-bins.s3.us-west-1.amazonaws.com/ndf/default.json`
// DownloadAndVerifySignedNdf retrieves the NDF from a hardcoded bucket URL.
// The NDF is processed into a protobuf containing a signature which
// is verified using the cert string passed in. The NDF is returned as marshaled
// byte data which may be used to start a client.
func
DownloadAndVerifySignedNdf
(
cert
string
)
([]
byte
,
error
)
{
// Build a request for the file
resp
,
err
:=
http
.
Get
(
ndfUrl
)
if
err
!=
nil
{
return
nil
,
errors
.
WithMessagef
(
err
,
"Failed to retrieve "
+
"NDF from %s"
,
ndfUrl
)
}
defer
resp
.
Body
.
Close
()
// Download contents of the file
signedNdfEncoded
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed to read signed "
+
"NDF response request"
)
}
// Process the download NDF and return the marshaled NDF
return
processAndVerifySignedNdf
(
signedNdfEncoded
,
cert
)
}
// DownloadAndVerifySignedNdfWithUrl retrieves the NDF from a specified URL.
// DownloadAndVerifySignedNdfWithUrl retrieves the NDF from a specified URL.
// The NDF is processed into a protobuf containing a signature which
// The NDF is processed into a protobuf containing a signature which
// is verified using the cert string passed in. The NDF is returned as marshaled
// is verified using the cert string passed in. The NDF is returned as marshaled
...
...
This diff is collapsed.
Click to expand it.
bindings/ndf_test.go
+
9
−
30
View file @
09891c3a
...
@@ -51,11 +51,11 @@ pipz4Cfpkoc1Gc8xx91iBsWYBpqu4p7SXDU=
...
@@ -51,11 +51,11 @@ pipz4Cfpkoc1Gc8xx91iBsWYBpqu4p7SXDU=
-----END CERTIFICATE-----
-----END CERTIFICATE-----
`
`
// Unit
t
est: Download
and verify NDF from hosted location
.
// Unit
T
est:
Call
Download
AndVerifySignedNdfWithUrl with a specified URL
.
// Ensure validity by unmarshalling NDF and checking the scheduling's cert.
// Ensure validity by unmarshalling NDF and checking the scheduling's cert.
func
TestDownloadSignedNdf
(
t
*
testing
.
T
)
{
func
TestDownloadSignedNdf
WithUrl
(
t
*
testing
.
T
)
{
// Download and verify the
ndf
// Download and verify the
cert with the specified URL
content
,
err
:=
DownloadAndVerifySignedNdf
(
testCert
)
content
,
err
:=
DownloadAndVerifySignedNdf
WithUrl
(
"https://elixxir-bins.s3.us-west-1.amazonaws.com/ndf/default.json"
,
testCert
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to download signed NDF: %v"
,
err
)
t
.
Errorf
(
"Failed to download signed NDF: %v"
,
err
)
}
}
...
@@ -71,42 +71,21 @@ func TestDownloadSignedNdf(t *testing.T) {
...
@@ -71,42 +71,21 @@ func TestDownloadSignedNdf(t *testing.T) {
if
strings
.
Compare
(
downloadedNdf
.
Registration
.
TlsCertificate
,
testCert
)
!=
0
{
if
strings
.
Compare
(
downloadedNdf
.
Registration
.
TlsCertificate
,
testCert
)
!=
0
{
t
.
Fatalf
(
"Unexpected NDF downloaded, has the spec changed?"
)
t
.
Fatalf
(
"Unexpected NDF downloaded, has the spec changed?"
)
}
}
}
}
// Error case: Pass in the incorrect cert forcing a verification failure.
// Error case: Pass in the incorrect cert forcing a verification failure.
func
TestDownloadSignedNdf
_Fail
(
t
*
testing
.
T
)
{
func
TestDownloadSignedNdf
WithUrl_BadCert
(
t
*
testing
.
T
)
{
// Load an unintended cert
// Load an unintended cert
badCert
,
err
:=
utils
.
ReadFile
(
testkeys
.
GetGatewayCertPath
())
badCert
,
err
:=
utils
.
ReadFile
(
testkeys
.
GetGatewayCertPath
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to read test certificate: %v"
,
err
)
t
.
Fatalf
(
"Failed to read test certificate: %v"
,
err
)
}
}
// Download and verify with unintended cert
_
,
err
=
DownloadAndVerifySignedNdf
(
string
(
badCert
))
// Download and attempt to verify with unintended cert
_
,
err
=
DownloadAndVerifySignedNdfWithUrl
(
"https://elixxir-bins.s3.us-west-1.amazonaws.com/ndf/default.json"
,
string
(
badCert
))
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"Expected failure, should not be able to verify with "
+
t
.
Fatalf
(
"Expected failure, should not be able to verify with "
+
"bad certificate"
)
"bad certificate"
)
}
}
}
}
// Unit Test: Call DownloadAndVerifySignedNdfWithUrl with a specified URL.
// Ensure validity by unmarshalling NDF and checking the scheduling's cert.
func
TestDownloadSignedNdfWithUrl
(
t
*
testing
.
T
)
{
// todo: write test once a proper URL can be passed in
content
,
err
:=
DownloadAndVerifySignedNdfWithUrl
(
ndfUrl
,
testCert
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to download signed NDF: %v"
,
err
)
}
fmt
.
Printf
(
"content: %s
\n
"
,
string
(
content
))
// Check that it is a marshallable NDF
downloadedNdf
,
err
:=
ndf
.
Unmarshal
(
content
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to unmarshal downloaded NDF: %v"
,
err
)
}
// Check validity of NDF
if
strings
.
Compare
(
downloadedNdf
.
Registration
.
TlsCertificate
,
testCert
)
!=
0
{
t
.
Fatalf
(
"Unexpected NDF downloaded, has the spec changed?"
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment