good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
5918b88a
Commit
5918b88a
authored
6 years ago
by
Elad
Committed by
Balint Gabor
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
cmd/swarm: added publisher key assertion to act tests (#17471)
parent
8711e2b6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/swarm/access_test.go
+40
-4
40 additions, 4 deletions
cmd/swarm/access_test.go
cmd/swarm/main.go
+24
-0
24 additions, 0 deletions
cmd/swarm/main.go
with
64 additions
and
4 deletions
cmd/swarm/access_test.go
+
40
−
4
View file @
5918b88a
...
@@ -145,7 +145,9 @@ func TestAccessPassword(t *testing.T) {
...
@@ -145,7 +145,9 @@ func TestAccessPassword(t *testing.T) {
if
a
.
KdfParams
==
nil
{
if
a
.
KdfParams
==
nil
{
t
.
Fatal
(
"manifest access kdf params is nil"
)
t
.
Fatal
(
"manifest access kdf params is nil"
)
}
}
if
a
.
Publisher
!=
""
{
t
.
Fatal
(
"should be empty"
)
}
client
:=
swarm
.
NewClient
(
cluster
.
Nodes
[
0
]
.
URL
)
client
:=
swarm
.
NewClient
(
cluster
.
Nodes
[
0
]
.
URL
)
hash
,
err
:=
client
.
UploadManifest
(
&
m
,
false
)
hash
,
err
:=
client
.
UploadManifest
(
&
m
,
false
)
...
@@ -222,7 +224,7 @@ func TestAccessPassword(t *testing.T) {
...
@@ -222,7 +224,7 @@ func TestAccessPassword(t *testing.T) {
// the test will fail if the proxy's given private key is not granted on the ACT.
// the test will fail if the proxy's given private key is not granted on the ACT.
func
TestAccessPK
(
t
*
testing
.
T
)
{
func
TestAccessPK
(
t
*
testing
.
T
)
{
// Setup Swarm and upload a test file to it
// Setup Swarm and upload a test file to it
cluster
:=
newTestCluster
(
t
,
1
)
cluster
:=
newTestCluster
(
t
,
2
)
defer
cluster
.
Shutdown
()
defer
cluster
.
Shutdown
()
// create a tmp file
// create a tmp file
...
@@ -302,6 +304,20 @@ func TestAccessPK(t *testing.T) {
...
@@ -302,6 +304,20 @@ func TestAccessPK(t *testing.T) {
t
.
Fatalf
(
"stdout not matched"
)
t
.
Fatalf
(
"stdout not matched"
)
}
}
//get the public key from the publisher directory
publicKeyFromDataDir
:=
runSwarm
(
t
,
"--bzzaccount"
,
publisherAccount
.
Address
.
String
(),
"--password"
,
passFile
.
Name
(),
"--datadir"
,
publisherDir
,
"print-keys"
,
"--compressed"
,
)
_
,
publicKeyString
:=
publicKeyFromDataDir
.
ExpectRegexp
(
".+"
)
publicKeyFromDataDir
.
ExpectExit
()
pkComp
:=
strings
.
Split
(
publicKeyString
[
0
],
"="
)[
1
]
var
m
api
.
Manifest
var
m
api
.
Manifest
err
=
json
.
Unmarshal
([]
byte
(
matches
[
0
]),
&
m
)
err
=
json
.
Unmarshal
([]
byte
(
matches
[
0
]),
&
m
)
...
@@ -335,7 +351,9 @@ func TestAccessPK(t *testing.T) {
...
@@ -335,7 +351,9 @@ func TestAccessPK(t *testing.T) {
if
a
.
KdfParams
!=
nil
{
if
a
.
KdfParams
!=
nil
{
t
.
Fatal
(
"manifest access kdf params should be nil"
)
t
.
Fatal
(
"manifest access kdf params should be nil"
)
}
}
if
a
.
Publisher
!=
pkComp
{
t
.
Fatal
(
"publisher key did not match"
)
}
client
:=
swarm
.
NewClient
(
cluster
.
Nodes
[
0
]
.
URL
)
client
:=
swarm
.
NewClient
(
cluster
.
Nodes
[
0
]
.
URL
)
hash
,
err
:=
client
.
UploadManifest
(
&
m
,
false
)
hash
,
err
:=
client
.
UploadManifest
(
&
m
,
false
)
...
@@ -499,6 +517,22 @@ func testAccessACT(t *testing.T, bogusEntries int) {
...
@@ -499,6 +517,22 @@ func testAccessACT(t *testing.T, bogusEntries int) {
if
len
(
matches
)
==
0
{
if
len
(
matches
)
==
0
{
t
.
Fatalf
(
"stdout not matched"
)
t
.
Fatalf
(
"stdout not matched"
)
}
}
//get the public key from the publisher directory
publicKeyFromDataDir
:=
runSwarm
(
t
,
"--bzzaccount"
,
publisherAccount
.
Address
.
String
(),
"--password"
,
passFile
.
Name
(),
"--datadir"
,
publisherDir
,
"print-keys"
,
"--compressed"
,
)
_
,
publicKeyString
:=
publicKeyFromDataDir
.
ExpectRegexp
(
".+"
)
publicKeyFromDataDir
.
ExpectExit
()
pkComp
:=
strings
.
Split
(
publicKeyString
[
0
],
"="
)[
1
]
hash
:=
matches
[
0
]
hash
:=
matches
[
0
]
m
,
_
,
err
:=
client
.
DownloadManifest
(
hash
)
m
,
_
,
err
:=
client
.
DownloadManifest
(
hash
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -531,7 +565,9 @@ func testAccessACT(t *testing.T, bogusEntries int) {
...
@@ -531,7 +565,9 @@ func testAccessACT(t *testing.T, bogusEntries int) {
if
a
.
KdfParams
!=
nil
{
if
a
.
KdfParams
!=
nil
{
t
.
Fatal
(
"manifest access kdf params should be nil"
)
t
.
Fatal
(
"manifest access kdf params should be nil"
)
}
}
if
a
.
Publisher
!=
pkComp
{
t
.
Fatal
(
"publisher key did not match"
)
}
httpClient
:=
&
http
.
Client
{}
httpClient
:=
&
http
.
Client
{}
// all nodes except the skipped node should be able to decrypt the content
// all nodes except the skipped node should be able to decrypt the content
...
...
This diff is collapsed.
Click to expand it.
cmd/swarm/main.go
+
24
−
0
View file @
5918b88a
...
@@ -18,6 +18,7 @@ package main
...
@@ -18,6 +18,7 @@ package main
import
(
import
(
"crypto/ecdsa"
"crypto/ecdsa"
"encoding/hex"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
...
@@ -208,6 +209,10 @@ var (
...
@@ -208,6 +209,10 @@ var (
Name
:
"data"
,
Name
:
"data"
,
Usage
:
"Initializes the resource with the given hex-encoded data. Data must be prefixed by 0x"
,
Usage
:
"Initializes the resource with the given hex-encoded data. Data must be prefixed by 0x"
,
}
}
SwarmCompressedFlag
=
cli
.
BoolFlag
{
Name
:
"compressed"
,
Usage
:
"Prints encryption keys in compressed form"
,
}
)
)
//declare a few constant error messages, useful for later error check comparisons in test
//declare a few constant error messages, useful for later error check comparisons in test
...
@@ -252,6 +257,14 @@ func init() {
...
@@ -252,6 +257,14 @@ func init() {
Usage
:
"Print version numbers"
,
Usage
:
"Print version numbers"
,
Description
:
"The output of this command is supposed to be machine-readable"
,
Description
:
"The output of this command is supposed to be machine-readable"
,
},
},
{
Action
:
keys
,
CustomHelpTemplate
:
helpTemplate
,
Name
:
"print-keys"
,
Flags
:
[]
cli
.
Flag
{
SwarmCompressedFlag
},
Usage
:
"Print public key information"
,
Description
:
"The output of this command is supposed to be machine-readable"
,
},
{
{
Action
:
upload
,
Action
:
upload
,
CustomHelpTemplate
:
helpTemplate
,
CustomHelpTemplate
:
helpTemplate
,
...
@@ -580,6 +593,17 @@ func main() {
...
@@ -580,6 +593,17 @@ func main() {
}
}
}
}
func
keys
(
ctx
*
cli
.
Context
)
error
{
privateKey
:=
getPrivKey
(
ctx
)
pub
:=
hex
.
EncodeToString
(
crypto
.
FromECDSAPub
(
&
privateKey
.
PublicKey
))
pubCompressed
:=
hex
.
EncodeToString
(
crypto
.
CompressPubkey
(
&
privateKey
.
PublicKey
))
if
!
ctx
.
Bool
(
SwarmCompressedFlag
.
Name
)
{
fmt
.
Println
(
fmt
.
Sprintf
(
"publicKey=%s"
,
pub
))
}
fmt
.
Println
(
fmt
.
Sprintf
(
"publicKeyCompressed=%s"
,
pubCompressed
))
return
nil
}
func
version
(
ctx
*
cli
.
Context
)
error
{
func
version
(
ctx
*
cli
.
Context
)
error
{
fmt
.
Println
(
strings
.
Title
(
clientIdentifier
))
fmt
.
Println
(
strings
.
Title
(
clientIdentifier
))
fmt
.
Println
(
"Version:"
,
sv
.
VersionWithMeta
)
fmt
.
Println
(
"Version:"
,
sv
.
VersionWithMeta
)
...
...
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