Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MainNet commitments
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
archives
MainNet commitments
Commits
2386926c
Commit
2386926c
authored
Oct 22, 2021
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
validate contract
parent
ee25dacf
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!5
validate contract
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/server.go
+1
-0
1 addition, 0 deletions
cmd/server.go
server/serverImpl.go
+51
-28
51 additions, 28 deletions
server/serverImpl.go
with
52 additions
and
28 deletions
cmd/server.go
+
1
−
0
View file @
2386926c
...
...
@@ -69,6 +69,7 @@ var serverCmd = &cobra.Command{
Address
:
addr
,
Port
:
port
,
},
ContractPath
:
viper
.
GetString
(
"contractPath"
),
}
err
=
server
.
StartServer
(
params
)
var
stopCh
=
make
(
chan
bool
)
...
...
This diff is collapsed.
Click to expand it.
server/serverImpl.go
+
51
−
28
View file @
2386926c
...
...
@@ -8,6 +8,7 @@
package
server
import
(
"bytes"
"context"
gorsa
"crypto/rsa"
"crypto/x509"
...
...
@@ -26,6 +27,7 @@ import (
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/idf"
utils2
"gitlab.com/xx_network/primitives/utils"
"net/http"
"testing"
"time"
...
...
@@ -35,6 +37,7 @@ import (
type
Params
struct
{
KeyPath
string
CertPath
string
ContractPath
string
Port
string
StorageParams
storage
.
Params
}
...
...
@@ -46,8 +49,19 @@ func StartServer(params Params) error {
if
err
!=
nil
{
return
err
}
cp
,
err
:=
utils2
.
ExpandPath
(
params
.
ContractPath
)
if
err
!=
nil
{
return
err
}
validContractBytes
,
err
:=
utils2
.
ReadFile
(
cp
)
if
err
!=
nil
{
return
err
}
impl
:=
&
Impl
{
s
:
s
,
contract
:
validContractBytes
,
}
// Build gin server, link to verify code
...
...
@@ -89,6 +103,7 @@ func StartServer(params Params) error {
type
Impl
struct
{
comms
*
gin
.
Engine
s
*
storage
.
Storage
contract
[]
byte
}
// Verify func is the main endpoint for the mainnet-commitments server
...
...
@@ -107,53 +122,60 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error {
jww
.
ERROR
.
Println
(
err
)
return
err
}
jww
.
INFO
.
Printf
(
"Received verification request from %+v"
,
idfStruct
.
ID
)
ok
,
err
:=
wallet
.
ValidateXXNetworkAddress
(
msg
.
Wallet
)
// Check hex node ID (betanet nodes don't have this)
if
idfStruct
.
HexNodeID
==
""
{
nid
,
err
:=
id
.
Unmarshal
(
idfStruct
.
IdBytes
[
:
])
if
err
!=
nil
{
err
=
errors
.
WithMessage
(
err
,
"Failed to
validate wallet address
"
)
err
=
errors
.
WithMessage
(
err
,
"Failed to
unmarshal ID
"
)
jww
.
ERROR
.
Println
(
err
)
return
err
}
if
!
ok
{
err
=
errors
.
New
(
"Wallet validation returned false"
)
idfStruct
.
HexNodeID
=
nid
.
HexEncode
()
}
// Get member info from database
hexId
:=
"
\\
"
+
idfStruct
.
HexNodeID
[
1
:
]
m
,
err
:=
i
.
s
.
GetMember
(
hexId
)
if
err
!=
nil
{
err
=
errors
.
WithMessagef
(
err
,
"Member %s [%+v] not found"
,
idfStruct
.
ID
,
idfStruct
.
IdBytes
)
jww
.
ERROR
.
Println
(
err
)
return
err
}
//
Hash node info from message
//
Load contract from request & compare to ours
contractBytes
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
msg
.
Contract
)
if
err
!=
nil
{
err
=
errors
.
WithMessage
(
err
,
"Failed to decode contract from base64"
)
}
hashed
,
hash
,
err
:=
utils
.
HashNodeInfo
(
msg
.
Wallet
,
idfBytes
,
contractBytes
)
if
err
!=
nil
{
err
=
errors
.
WithMessage
(
err
,
"Failed to hash node info"
)
jww
.
ERROR
.
Println
(
err
)
return
err
if
bytes
.
Compare
(
contractBytes
,
i
.
contract
)
!=
0
{
err
=
errors
.
Errorf
(
"Contract received [%+v] did not match server contract [%+v]"
,
contractBytes
,
i
.
contract
)
}
if
idfStruct
.
HexNodeID
==
""
{
nid
,
err
:=
id
.
Unmarsh
al
(
id
fStruct
.
IdBytes
[
:
]
)
// Validate wallet
ok
,
err
:=
wallet
.
V
alid
ateXXNetworkAddress
(
msg
.
Wallet
)
if
err
!=
nil
{
err
=
errors
.
WithMessage
(
err
,
"Failed to
unmarshal ID
"
)
err
=
errors
.
WithMessage
(
err
,
"Failed to
validate wallet address
"
)
jww
.
ERROR
.
Println
(
err
)
return
err
}
idfStruct
.
HexNodeID
=
nid
.
HexEncode
()
if
!
ok
{
err
=
errors
.
New
(
"Wallet validation returned false"
)
jww
.
ERROR
.
Println
(
err
)
return
err
}
// Get member info from database
hexId
:=
"
\\
"
+
idfStruct
.
HexNodeID
[
1
:
]
m
,
err
:=
i
.
s
.
GetMember
(
hexId
)
// Hash node info from message
hashed
,
hash
,
err
:=
utils
.
HashNodeInfo
(
msg
.
Wallet
,
idfBytes
,
contractBytes
)
if
err
!=
nil
{
err
=
errors
.
WithMessage
f
(
err
,
"
Member %s [%+v] not found"
,
idfStruct
.
ID
,
idfStruct
.
IdBytes
)
err
=
errors
.
WithMessage
(
err
,
"
Failed to hash node info"
)
jww
.
ERROR
.
Println
(
err
)
return
err
}
// Decode certificate & extract public component
block
,
rest
:=
pem
.
Decode
(
m
.
Cert
)
jww
.
INFO
.
Printf
(
"Decoded cert into block: %+v, rest: %+v"
,
block
,
rest
)
var
cert
*
x509
.
Certificate
...
...
@@ -165,6 +187,7 @@ func (i *Impl) Verify(_ context.Context, msg messages.Commitment) error {
}
rsaPublicKey
:=
cert
.
PublicKey
.
(
*
gorsa
.
PublicKey
)
// Decode signature
sigBytes
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
msg
.
Signature
)
if
err
!=
nil
{
err
=
errors
.
WithMessage
(
err
,
"Failed to decode signature from base64"
)
...
...
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