diff --git a/bindings/ndf.go b/bindings/ndf.go index e367765e0d33b2a197692bcef2055dbca2ca7f87..d176c7b6045d20e81a7ba01c42e8af9f7dccfd85 100644 --- a/bindings/ndf.go +++ b/bindings/ndf.go @@ -22,12 +22,11 @@ import ( // ndfUrl is a hardcoded url to a bucket containing the signed NDF message. const ndfUrl = `elixxir.io` -// DownloadSignedNdf retrieves the NDF from a hardcoded bucket URL. -// The NDF returned requires further processing and verification -// before being used. Use ProcessSignedNdf to properly process -// the downloaded data returned. -// DO NOT USE THE RETURNED DATA TO START A CLIENT. -func DownloadSignedNdf() ([]byte, error) { +// 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 { @@ -43,16 +42,16 @@ func DownloadSignedNdf() ([]byte, error) { "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. -// The NDF returned requires further processing and verification -// before being used. Use ProcessSignedNdf to properly process -// the downloaded data returned. -// DO NOT USE THE RETURNED DATA TO START A CLIENT. -func DownloadSignedNdfWithUrl(url string) ([]byte, error) { - // Build a reqeust for the file +// DownloadAndVerifySignedNdfWithUrl retrieves the NDF from a specified 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 DownloadAndVerifySignedNdfWithUrl(url, cert string) ([]byte, error) { + // Build a request for the file resp, err := http.Get(url) if err != nil { return nil, errors.WithMessagef(err, "Failed to retrieve "+ @@ -67,16 +66,15 @@ func DownloadSignedNdfWithUrl(url string) ([]byte, error) { "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 -// DownloadSignedNdf or DownloadSignedNdfWithUrl (signedNdfEncoded) -// and the scheduling certificate (cert). The downloaded NDF is parsed +// processAndVerifySignedNdf is a helper function which parses the downloaded NDF // into a protobuf containing a signature. The signature is verified using the // passed in cert. Upon successful parsing and verification, the NDF is -// returned as byte data, which may be used to start a client. -func ProcessSignedNdf(signedNdfEncoded []byte, cert string) ([]byte, error) { +// returned as byte data. +func processAndVerifySignedNdf(signedNdfEncoded []byte, cert string) ([]byte, error) { // Base64 decode the signed NDF signedNdfMarshaled, err := base64.StdEncoding.DecodeString( string(signedNdfEncoded)) diff --git a/bindings/ndf_test.go b/bindings/ndf_test.go index b77b41b44499adda3a996ec9bef9e13004d8e853..7b1698e3a03895e5fcad478f426f8a540c932cb4 100644 --- a/bindings/ndf_test.go +++ b/bindings/ndf_test.go @@ -11,7 +11,7 @@ import "testing" func TestDownloadSignedNdf(t *testing.T) { // Todo: test once a proper URL is hardcoded - //content, err := DownloadSignedNdf() + //content, err := DownloadAndVerifySignedNdf(testCert) //if err != nil { // t.Errorf("Failed to download signed NDF: %v") //} @@ -21,7 +21,7 @@ func TestDownloadSignedNdf(t *testing.T) { func TestDownloadSignedNdfWithUrl(t *testing.T) { // todo: write test once a proper URL can be passed in - //content, err := DownloadSignedNdfWithUrl(exampleURL) + //content, err := DownloadAndVerifySignedNdfWithUrl(exampleURL, testCert) //if err != nil { // t.Errorf("Failed to download signed NDF: %v") //} @@ -31,7 +31,7 @@ func TestDownloadSignedNdfWithUrl(t *testing.T) { // Tests func TestVerifySignedNdf(t *testing.T) { // todo write test once example data is collected - //ndf, err := VerifySignedNdf(testSignedNdf, testCert) + //ndf, err := processAndVerifySignedNdf(testSignedNdf, testCert) //if err != nil { // //}