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
01e2ff8c
Commit
01e2ff8c
authored
Nov 23, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Combine Download and VerifyNdf into a single API call
parent
c3bbc1ca
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
+18
-20
18 additions, 20 deletions
bindings/ndf.go
bindings/ndf_test.go
+3
-3
3 additions, 3 deletions
bindings/ndf_test.go
with
21 additions
and
23 deletions
bindings/ndf.go
+
18
−
20
View file @
01e2ff8c
...
@@ -22,12 +22,11 @@ import (
...
@@ -22,12 +22,11 @@ import (
// ndfUrl is a hardcoded url to a bucket containing the signed NDF message.
// ndfUrl is a hardcoded url to a bucket containing the signed NDF message.
const
ndfUrl
=
`elixxir.io`
const
ndfUrl
=
`elixxir.io`
// DownloadSignedNdf retrieves the NDF from a hardcoded bucket URL.
// DownloadAndVerifySignedNdf retrieves the NDF from a hardcoded bucket URL.
// The NDF returned requires further processing and verification
// The NDF is processed into a protobuf containing a signature which
// before being used. Use ProcessSignedNdf to properly process
// is verified using the cert string passed in. The NDF is returned as marshaled
// the downloaded data returned.
// byte data which may be used to start a client.
// DO NOT USE THE RETURNED DATA TO START A CLIENT.
func
DownloadAndVerifySignedNdf
(
cert
string
)
([]
byte
,
error
)
{
func
DownloadSignedNdf
()
([]
byte
,
error
)
{
// Build a request for the file
// Build a request for the file
resp
,
err
:=
http
.
Get
(
ndfUrl
)
resp
,
err
:=
http
.
Get
(
ndfUrl
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -43,16 +42,16 @@ func DownloadSignedNdf() ([]byte, error) {
...
@@ -43,16 +42,16 @@ func DownloadSignedNdf() ([]byte, error) {
"NDF response request"
)
"NDF response request"
)
}
}
return
signedNdfEncoded
,
nil
// Process the download NDF and return the marshaled NDF
return
processAndVerifySignedNdf
(
signedNdfEncoded
,
cert
)
}
}
// DownloadSignedNdfWithUrl retrieves the NDF from a specified URL.
// DownloadAndVerifySignedNdfWithUrl retrieves the NDF from a specified URL.
// The NDF returned requires further processing and verification
// The NDF is processed into a protobuf containing a signature which
// before being used. Use ProcessSignedNdf to properly process
// is verified using the cert string passed in. The NDF is returned as marshaled
// the downloaded data returned.
// byte data which may be used to start a client.
// DO NOT USE THE RETURNED DATA TO START A CLIENT.
func
DownloadAndVerifySignedNdfWithUrl
(
url
,
cert
string
)
([]
byte
,
error
)
{
func
DownloadSignedNdfWithUrl
(
url
string
)
([]
byte
,
error
)
{
// Build a request for the file
// Build a reqeust for the file
resp
,
err
:=
http
.
Get
(
url
)
resp
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
WithMessagef
(
err
,
"Failed to retrieve "
+
return
nil
,
errors
.
WithMessagef
(
err
,
"Failed to retrieve "
+
...
@@ -67,16 +66,15 @@ func DownloadSignedNdfWithUrl(url string) ([]byte, error) {
...
@@ -67,16 +66,15 @@ func DownloadSignedNdfWithUrl(url string) ([]byte, error) {
"NDF response request"
)
"NDF response request"
)
}
}
return
signedNdfEncoded
,
nil
// Process the download NDF and return the marshaled NDF
return
processAndVerifySignedNdf
(
signedNdfEncoded
,
cert
)
}
}
// ProcessSignedNdf takes the downloaded NDF from either
// processAndVerifySignedNdf is a helper function which parses the downloaded NDF
// DownloadSignedNdf or DownloadSignedNdfWithUrl (signedNdfEncoded)
// and the scheduling certificate (cert). The downloaded NDF is parsed
// into a protobuf containing a signature. The signature is verified using the
// into a protobuf containing a signature. The signature is verified using the
// passed in cert. Upon successful parsing and verification, the NDF is
// passed in cert. Upon successful parsing and verification, the NDF is
// returned as byte data
, which may be used to start a client
.
// returned as byte data.
func
P
rocessSignedNdf
(
signedNdfEncoded
[]
byte
,
cert
string
)
([]
byte
,
error
)
{
func
p
rocess
AndVerify
SignedNdf
(
signedNdfEncoded
[]
byte
,
cert
string
)
([]
byte
,
error
)
{
// Base64 decode the signed NDF
// Base64 decode the signed NDF
signedNdfMarshaled
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
signedNdfMarshaled
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
string
(
signedNdfEncoded
))
string
(
signedNdfEncoded
))
...
...
This diff is collapsed.
Click to expand it.
bindings/ndf_test.go
+
3
−
3
View file @
01e2ff8c
...
@@ -11,7 +11,7 @@ import "testing"
...
@@ -11,7 +11,7 @@ import "testing"
func
TestDownloadSignedNdf
(
t
*
testing
.
T
)
{
func
TestDownloadSignedNdf
(
t
*
testing
.
T
)
{
// Todo: test once a proper URL is hardcoded
// Todo: test once a proper URL is hardcoded
//content, err := DownloadSignedNdf()
//content, err := Download
AndVerify
SignedNdf(
testCert
)
//if err != nil {
//if err != nil {
// t.Errorf("Failed to download signed NDF: %v")
// t.Errorf("Failed to download signed NDF: %v")
//}
//}
...
@@ -21,7 +21,7 @@ func TestDownloadSignedNdf(t *testing.T) {
...
@@ -21,7 +21,7 @@ func TestDownloadSignedNdf(t *testing.T) {
func
TestDownloadSignedNdfWithUrl
(
t
*
testing
.
T
)
{
func
TestDownloadSignedNdfWithUrl
(
t
*
testing
.
T
)
{
// todo: write test once a proper URL can be passed in
// todo: write test once a proper URL can be passed in
//content, err := DownloadSignedNdfWithUrl(exampleURL)
//content, err := Download
AndVerify
SignedNdfWithUrl(exampleURL
, testCert
)
//if err != nil {
//if err != nil {
// t.Errorf("Failed to download signed NDF: %v")
// t.Errorf("Failed to download signed NDF: %v")
//}
//}
...
@@ -31,7 +31,7 @@ func TestDownloadSignedNdfWithUrl(t *testing.T) {
...
@@ -31,7 +31,7 @@ func TestDownloadSignedNdfWithUrl(t *testing.T) {
// Tests
// Tests
func
TestVerifySignedNdf
(
t
*
testing
.
T
)
{
func
TestVerifySignedNdf
(
t
*
testing
.
T
)
{
// todo write test once example data is collected
// todo write test once example data is collected
//ndf, err := VerifySignedNdf(testSignedNdf, testCert)
//ndf, err :=
processAnd
VerifySignedNdf(testSignedNdf, testCert)
//if err != nil {
//if err != nil {
//
//
//}
//}
...
...
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