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
3232d7fb
Commit
3232d7fb
authored
Jul 17, 2019
by
Jono
Browse files
Options
Downloads
Patches
Plain Diff
Write VerifyNDF() and its tests
parent
a8e39693
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/client.go
+11
-5
11 additions, 5 deletions
api/client.go
api/ndf_test.go
+160
-0
160 additions, 0 deletions
api/ndf_test.go
with
171 additions
and
5 deletions
api/client.go
+
11
−
5
View file @
3232d7fb
...
...
@@ -64,20 +64,25 @@ func FormatTextMessage(message string) []byte {
// VerifyNDF verifies the signature of the network definition file (NDF) and
// returns the structure. Panics when the NDF string cannot be decoded and when
// the signature cannot be verified. If the NDF public key is empty, then
// the signature cannot be verified. If the NDF public key is empty, then
the
// signature verification is skipped and warning is printed.
func
VerifyNDF
(
ndfString
,
ndfPub
string
)
*
ndf
.
NetworkDefinition
{
// Decode NDF string to a NetworkDefinition and its signature
ndfJSON
,
ndfSignature
,
err
:=
ndf
.
DecodeNDF
(
ndfString
)
if
err
!=
nil
{
globals
.
Log
.
FATAL
.
Panicf
(
"Could not decode NDF: %
+
v"
,
err
)
globals
.
Log
.
FATAL
.
Panicf
(
"Could not decode NDF: %v"
,
err
)
}
// If there is no public key, then skip verification and print warning
if
ndfPub
==
""
{
globals
.
Log
.
WARN
.
Println
(
"Running without signed network definition file"
)
globals
.
Log
.
WARN
.
Printf
(
"Running without signed network "
+
"definition file"
)
}
else
{
// Get public key
pubKey
,
err
:=
rsa
.
LoadPublicKeyFromPem
([]
byte
(
ndfPub
))
if
err
!=
nil
{
globals
.
Log
.
FATAL
.
Panicf
(
"Could not load public key: %v"
,
err
)
}
// Hash NDF JSON
opts
:=
rsa
.
NewDefaultOptions
()
...
...
@@ -85,10 +90,11 @@ func VerifyNDF(ndfString, ndfPub string) *ndf.NetworkDefinition {
rsaHash
.
Write
(
ndfJSON
.
Serialize
())
// Verify signature
err
=
rsa
.
Verify
(
pubKey
,
opts
.
Hash
,
rsaHash
.
Sum
(
nil
),
ndfSignature
,
nil
)
err
=
rsa
.
Verify
(
pubKey
,
opts
.
Hash
,
rsaHash
.
Sum
(
nil
),
ndfSignature
,
nil
)
if
err
!=
nil
{
globals
.
Log
.
FATAL
.
Panicf
(
"Could not verify NDF: %
+
v"
,
err
)
globals
.
Log
.
FATAL
.
Panicf
(
"Could not verify NDF: %v"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
api/ndf_test.go
0 → 100644
+
160
−
0
View file @
3232d7fb
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