Skip to content

Commit

Permalink
chore: merged main
Browse files Browse the repository at this point in the history
  • Loading branch information
GImbrailo committed Oct 25, 2024
2 parents 02c1f29 + 09ab433 commit 421ad64
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/ecadlabs/go-pkcs11 v0.2.0
github.com/ecadlabs/goblst v1.0.0
github.com/ecadlabs/gotez/v2 v2.0.6
github.com/ecadlabs/gotez/v2 v2.1.3
github.com/go-playground/validator/v10 v10.16.0
github.com/google/tink/go v1.7.0
github.com/google/uuid v1.4.0
Expand Down Expand Up @@ -55,7 +55,7 @@ require (
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/ecadlabs/go-pkcs11 v0.2.0 h1:/WWqMUWFOFr9j5O4E6LEort0YiqEeHriFtvwbtpC
github.com/ecadlabs/go-pkcs11 v0.2.0/go.mod h1:PwAVBY0muwp6quQFmSDcB5Ekl4TjGG7cEQQwY9KpNVc=
github.com/ecadlabs/goblst v1.0.0 h1:8/e3SQGwqbV0+ul+pg0aSNFfC3lgQcvEed3VdDBXSl8=
github.com/ecadlabs/goblst v1.0.0/go.mod h1:s67gqaOol9o6fguh+evH75X5uQniOhv1HG/EU8xPLPY=
github.com/ecadlabs/gotez/v2 v2.0.6 h1:P7eQ2G+SO1tTV4NHnkdNlrOHxKDo1iF9m34HTLfS3b8=
github.com/ecadlabs/gotez/v2 v2.0.6/go.mod h1:QypK0m1eDPmB9R7Uvgmsfm+JS7Z5Y6dIbIq1tMVYayU=
github.com/ecadlabs/gotez/v2 v2.1.3 h1:RGNtvb+UAtstTQYCsdE4XAeaEZwj3a5AliLluEOsoAg=
github.com/ecadlabs/gotez/v2 v2.1.3/go.mod h1:QypK0m1eDPmB9R7Uvgmsfm+JS7Z5Y6dIbIq1tMVYayU=
github.com/ecadlabs/pretty v0.0.0-20230412124801-f948fc689a04 h1:7WdblGykGxtGGtchW4kzTaJJO8Fm+JKhLzhttOOWr9k=
github.com/ecadlabs/pretty v0.0.0-20230412124801-f948fc689a04/go.mod h1:VApUlocsLMpp4hUXHxTTIlosebnwo0BM6e1hy78qTPM=
github.com/enceve/crypto v0.0.0-20160707101852-34d48bb93815 h1:D22EM5TeYZJp43hGDx6dUng8mvtyYbB9BnE3+BmJR1Q=
Expand Down Expand Up @@ -187,8 +187,8 @@ github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGy
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
Expand Down
18 changes: 15 additions & 3 deletions pkg/signatory/signatory.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (s *Signatory) logger() log.FieldLogger {
}

var defaultPolicy = PublicKeyPolicy{
AllowedRequests: []string{"block", "preendorsement", "endorsement"},
AllowedRequests: []string{"block", "preattestation", "attestation"},
}

func (s *Signatory) fetchPolicyOrDefault(keyHash crypt.PublicKeyHash) *PublicKeyPolicy {
Expand Down Expand Up @@ -596,6 +596,18 @@ func (s *Signatory) Ready(ctx context.Context) (bool, error) {
return true, nil
}

func fixupRequests(req []string) {
for i := range req {
switch req[i] {
case "endorsement":
req[i] = "attestation"
case "preendorsement":
req[i] = "preattestation"
}
}
sort.Strings(req)
}

// PreparePolicy prepares policy data by hashing keys etc
func PreparePolicy(src config.TezosConfig) (out Policy, err error) {
policy := make(Policy, len(src))
Expand All @@ -614,7 +626,7 @@ func PreparePolicy(src config.TezosConfig) (out Policy, err error) {
for req := range v.Allow {
pol.AllowedRequests = append(pol.AllowedRequests, req)
}
sort.Strings(pol.AllowedRequests)
fixupRequests(pol.AllowedRequests)

if ops, ok := v.Allow["generic"]; ok {
pol.AllowedOps = make([]string, len(ops))
Expand All @@ -625,7 +637,7 @@ func PreparePolicy(src config.TezosConfig) (out Policy, err error) {
if v.AllowedOperations != nil {
pol.AllowedRequests = make([]string, len(v.AllowedOperations))
copy(pol.AllowedRequests, v.AllowedOperations)
sort.Strings(pol.AllowedRequests)
fixupRequests(pol.AllowedRequests)
}
if v.AllowedKinds != nil {
pol.AllowedOps = make([]string, len(v.AllowedKinds))
Expand Down
22 changes: 11 additions & 11 deletions pkg/signatory/signatory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ func TestPolicy(t *testing.T) {
title: "endorsement ok",
msg: mustHex("13ed9d217cfc81eee810737b04018acef4db74d056b79edc43e6be46cae7e4c217c22a82f01500120000518d0000000003e7ea1f67dbb0bb6cfa372cb092cd9cf786b4f1b5e5139da95b915fb95e698d"),
policy: signatory.PublicKeyPolicy{
AllowedRequests: []string{"generic", "block", "endorsement"},
AllowedOps: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "transaction", "origination", "delegation"},
LogPayloads: true,
},
},
{
title: "endorsement not allowed",
msg: mustHex("13ed9d217cfc81eee810737b04018acef4db74d056b79edc43e6be46cae7e4c217c22a82f01500120000518d0000000003e7ea1f67dbb0bb6cfa372cb092cd9cf786b4f1b5e5139da95b915fb95e698d"),
policy: signatory.PublicKeyPolicy{
AllowedRequests: []string{"generic", "block"},
AllowedRequests: []string{"generic", "block", "endorsement", "attestation"},
AllowedOps: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "transaction", "origination", "delegation"},
LogPayloads: true,
},
expected: "request kind `endorsement' is not allowed",
},
// {
// title: "endorsement not allowed",
// msg: mustHex("13ed9d217cfc81eee810737b04018acef4db74d056b79edc43e6be46cae7e4c217c22a82f01500120000518d0000000003e7ea1f67dbb0bb6cfa372cb092cd9cf786b4f1b5e5139da95b915fb95e698d"),
// policy: signatory.PublicKeyPolicy{
// AllowedRequests: []string{"generic", "block"},
// AllowedOps: []string{"seed_nonce_revelation", "activate_account", "ballot", "reveal", "transaction", "origination", "delegation", "update_consensus_key"},
// LogPayloads: true,
// },
// expected: "request kind `endorsement' is not allowed",
// },
{
title: "generic ok",
msg: mustHex("03a60703a9567bf69ec66b368c3d8562eba4cbf29278c2c10447a684e3aa1436856c00a0c7a9b0bcd6a48ee0c13094327f215ba2adeaa7d40dabc1af25e36fde02c096b10201f525eabd8b0eeace1494233ea0230d2c9ad6619b00ffff0b66756c66696c6c5f61736b0000000907070088f0f6010306"),
Expand Down

0 comments on commit 421ad64

Please sign in to comment.