Skip to content
Snippets Groups Projects
Commit 01e2ff8c authored by Josh Brooks's avatar Josh Brooks
Browse files

Combine Download and VerifyNdf into a single API call

parent c3bbc1ca
No related branches found
No related tags found
2 merge requests!117Release,!74Implement bindings for downloading and verifying signed partial NDF
...@@ -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 ProcessSignedNdf(signedNdfEncoded []byte, cert string) ([]byte, error) { func processAndVerifySignedNdf(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))
......
...@@ -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 := DownloadAndVerifySignedNdf(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 := DownloadAndVerifySignedNdfWithUrl(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 := processAndVerifySignedNdf(testSignedNdf, testCert)
//if err != nil { //if err != nil {
// //
//} //}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment