Skip to content

Commit

Permalink
TrustStore: Improve error context (#3620)
Browse files Browse the repository at this point in the history
Attach error context on wrapping:

Before:
````
2020-01-20 08:51:42.945524+0000 [EROR] Unable to get paths debug_id=7d9353b5 err=
>  unable to get latest TRC isd="3"
>      unable to get requested TRC
>      unable to resolve signed TRC from network
>      unable to resolve latest version
>      unable to resolve latest TRC
>      not found
````

After:
````
2020-01-20 15:20:40.198528+0000 [EROR] Unable to get paths debug_id=3b8c4bb6 err=
>  unable to get requested TRC isd="3" version="latest"
>      unable to fetch signed TRC from network addr="1-ff00:0:112,CS A (0x0002)"
>      error resolving latest TRC version number
>      rpc: error from remote: "not found"
````

Additionally, purge remains of trust v1

fixes #3618
  • Loading branch information
oncilla authored Jan 21, 2020
1 parent 6f99584 commit ecadd83
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 236 deletions.
2 changes: 2 additions & 0 deletions go/cs/beaconing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ go_test(
"//go/lib/infra/mock_infra:go_default_library",
"//go/lib/infra/modules/itopo/itopotest:go_default_library",
"//go/lib/infra/modules/trust:go_default_library",
"//go/lib/keyconf:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/serrors:go_default_library",
Expand All @@ -80,5 +81,6 @@ go_test(
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_smartystreets_goconvey//convey:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
)
20 changes: 12 additions & 8 deletions go/cs/beaconing/extender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
"github.com/scionproto/scion/go/cs/ifstate"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl"
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest"
"github.com/scionproto/scion/go/lib/infra/modules/trust"
"github.com/scionproto/scion/go/lib/keyconf"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/util"
Expand Down Expand Up @@ -249,16 +249,20 @@ func TestExtenderExtend(t *testing.T) {
SoMsg("err", err, ShouldNotBeNil)
})
Convey("Signer expiration is to small", func() {
signer, err := trust.NewBasicSigner(priv, infra.SignerMeta{
Src: ctrl.SignSrcDef{
signer, err := trust.NewSigner(
trust.SignerConf{
ChainVer: 42,
TRCVer: 84,
IA: topoProvider.Get().IA(),
Validity: scrypto.Validity{NotAfter: util.UnixTime{Time: time.Now()}},
Key: keyconf.Key{
Type: keyconf.PrivateKey,
Algorithm: scrypto.Ed25519,
Bytes: priv,
ID: keyconf.ID{IA: topoProvider.Get().IA()},
},
},
Algo: scrypto.Ed25519,
ExpTime: time.Now(),
})
xtest.FailOnErr(t, err)
)
SoMsg("err", err, ShouldBeNil)
ext.cfg.Signer = signer
intfs.Get(graph.If_111_B_120_X).Activate(graph.If_120_X_111_B)
err = ext.extend(pseg, graph.If_111_B_120_X, 0, []common.IFIDType{})
Expand Down
22 changes: 14 additions & 8 deletions go/cs/beaconing/registrar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ import (

"github.com/golang/mock/gomock"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/require"

"github.com/scionproto/scion/go/cs/beacon"
"github.com/scionproto/scion/go/cs/beaconing/mock_beaconing"
"github.com/scionproto/scion/go/cs/ifstate"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/infra/mock_infra"
"github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest"
"github.com/scionproto/scion/go/lib/infra/modules/trust"
"github.com/scionproto/scion/go/lib/keyconf"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/util"
"github.com/scionproto/scion/go/lib/xtest"
"github.com/scionproto/scion/go/lib/xtest/graph"
"github.com/scionproto/scion/go/proto"
Expand Down Expand Up @@ -273,15 +275,19 @@ func testBeaconOrErr(g *graph.Graph, desc []common.IFIDType) beacon.BeaconOrErr
}

func testSigner(t *testing.T, priv common.RawBytes, ia addr.IA) infra.Signer {
signer, err := trust.NewBasicSigner(priv, infra.SignerMeta{
Src: ctrl.SignSrcDef{
signer, err := trust.NewSigner(
trust.SignerConf{
ChainVer: 42,
TRCVer: 84,
IA: ia,
Validity: scrypto.Validity{NotAfter: util.UnixTime{Time: time.Now().Add(time.Hour)}},
Key: keyconf.Key{
Type: keyconf.PrivateKey,
Algorithm: scrypto.Ed25519,
Bytes: priv,
ID: keyconf.ID{IA: ia},
},
},
Algo: scrypto.Ed25519,
ExpTime: time.Now().Add(time.Hour),
})
xtest.FailOnErr(t, err)
)
require.NoError(t, err)
return signer
}
2 changes: 1 addition & 1 deletion go/cs/ifstate/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ go_test(
"//go/cs/metrics:go_default_library",
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/ctrl:go_default_library",
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/infra:go_default_library",
"//go/lib/infra/mock_infra:go_default_library",
"//go/lib/infra/modules/itopo/itopotest:go_default_library",
"//go/lib/infra/modules/trust:go_default_library",
"//go/lib/keyconf:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/snet:go_default_library",
Expand Down
20 changes: 13 additions & 7 deletions go/cs/ifstate/revoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ import (

"github.com/golang/mock/gomock"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/require"

"github.com/scionproto/scion/go/cs/ifstate/mock_ifstate"
"github.com/scionproto/scion/go/cs/metrics"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/infra/mock_infra"
"github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest"
"github.com/scionproto/scion/go/lib/infra/modules/trust"
"github.com/scionproto/scion/go/lib/keyconf"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/snet"
Expand Down Expand Up @@ -350,15 +351,20 @@ func activateAll(intfs *Interfaces) {
}

func createTestSigner(t *testing.T, key common.RawBytes) infra.Signer {
signer, err := trust.NewBasicSigner(key, infra.SignerMeta{
Src: ctrl.SignSrcDef{
IA: xtest.MustParseIA("1-ff00:0:84"),
signer, err := trust.NewSigner(
trust.SignerConf{
ChainVer: 42,
TRCVer: 21,
Validity: scrypto.Validity{NotAfter: util.UnixTime{Time: time.Now().Add(time.Hour)}},
Key: keyconf.Key{
Type: keyconf.PrivateKey,
Algorithm: scrypto.Ed25519,
Bytes: key,
ID: keyconf.ID{IA: xtest.MustParseIA("1-ff00:0:84")},
},
},
Algo: scrypto.Ed25519,
})
xtest.FailOnErr(t, err)
)
require.NoError(t, err)
return signer
}

Expand Down
2 changes: 2 additions & 0 deletions go/cs/keepalive/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ go_test(
"//go/lib/infra:go_default_library",
"//go/lib/infra/modules/itopo/itopotest:go_default_library",
"//go/lib/infra/modules/trust:go_default_library",
"//go/lib/keyconf:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/snet/mock_snet:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/topology:go_default_library",
"//go/lib/util:go_default_library",
"//go/lib/xtest:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
Expand Down
18 changes: 13 additions & 5 deletions go/cs/keepalive/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"net"
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
Expand All @@ -29,9 +30,11 @@ import (
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest"
"github.com/scionproto/scion/go/lib/infra/modules/trust"
"github.com/scionproto/scion/go/lib/keyconf"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/snet/mock_snet"
"github.com/scionproto/scion/go/lib/util"
"github.com/scionproto/scion/go/lib/xtest"
)

Expand Down Expand Up @@ -79,14 +82,19 @@ func TestSenderRun(t *testing.T) {
}

func createTestSigner(t *testing.T, key common.RawBytes) infra.Signer {
signer, err := trust.NewBasicSigner(key, infra.SignerMeta{
Src: ctrl.SignSrcDef{
IA: xtest.MustParseIA("1-ff00:0:84"),
signer, err := trust.NewSigner(
trust.SignerConf{
ChainVer: 42,
TRCVer: 21,
Validity: scrypto.Validity{NotAfter: util.UnixTime{Time: time.Now().Add(time.Hour)}},
Key: keyconf.Key{
Type: keyconf.PrivateKey,
Algorithm: scrypto.Ed25519,
Bytes: key,
ID: keyconf.ID{IA: xtest.MustParseIA("1-ff00:0:84")},
},
},
Algo: scrypto.Ed25519,
})
)
require.NoError(t, err)
return signer
}
Expand Down
3 changes: 2 additions & 1 deletion go/cs/revocation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ go_test(
"//go/cs/metrics:go_default_library",
"//go/cs/revocation/mock_revocation:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/ctrl:go_default_library",
"//go/lib/ctrl/ack:go_default_library",
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/infra:go_default_library",
"//go/lib/infra/messenger:go_default_library",
"//go/lib/infra/mock_infra:go_default_library",
"//go/lib/infra/modules/trust:go_default_library",
"//go/lib/keyconf:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/util:go_default_library",
"//go/lib/xtest:go_default_library",
"//go/lib/xtest/matchers:go_default_library",
"//go/proto:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
)
20 changes: 13 additions & 7 deletions go/cs/revocation/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"github.com/scionproto/scion/go/cs/metrics"
"github.com/scionproto/scion/go/cs/revocation/mock_revocation"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl"
"github.com/scionproto/scion/go/lib/ctrl/ack"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/infra/messenger"
"github.com/scionproto/scion/go/lib/infra/mock_infra"
"github.com/scionproto/scion/go/lib/infra/modules/trust"
"github.com/scionproto/scion/go/lib/keyconf"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/util"
Expand Down Expand Up @@ -137,15 +138,20 @@ func TestHandler(t *testing.T) {
}

func createTestSigner(t *testing.T, key common.RawBytes) infra.Signer {
signer, err := trust.NewBasicSigner(key, infra.SignerMeta{
Src: ctrl.SignSrcDef{
IA: xtest.MustParseIA("1-ff00:0:84"),
signer, err := trust.NewSigner(
trust.SignerConf{
ChainVer: 42,
TRCVer: 21,
Validity: scrypto.Validity{NotAfter: util.UnixTime{Time: time.Now().Add(time.Hour)}},
Key: keyconf.Key{
Type: keyconf.PrivateKey,
Algorithm: scrypto.Ed25519,
Bytes: key,
ID: keyconf.ID{IA: xtest.MustParseIA("1-ff00:0:84")},
},
},
Algo: scrypto.Ed25519,
})
xtest.FailOnErr(t, err)
)
require.NoError(t, err)
return signer
}

Expand Down
2 changes: 1 addition & 1 deletion go/lib/infra/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ type Error struct {
}

func (e *Error) Error() string {
return e.Message.ErrDesc
return fmt.Sprintf("rpc: error from remote: %q", e.Message.ErrDesc)
}

// SignerMeta indicates what signature metadata the signer uses as a basis
Expand Down
3 changes: 0 additions & 3 deletions go/lib/infra/modules/trust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ go_library(
"provider.go",
"recurser.go",
"resolver.go",
"resolvers.go",
"router.go",
"rpc.go",
"signer.go",
"signhelper.go",
"store.go",
"verifier.go",
],
Expand All @@ -27,7 +25,6 @@ go_library(
"//go/lib/ctrl:go_default_library",
"//go/lib/ctrl/cert_mgmt:go_default_library",
"//go/lib/infra:go_default_library",
"//go/lib/infra/dedupe:go_default_library",
"//go/lib/infra/messenger:go_default_library",
"//go/lib/infra/modules/db:go_default_library",
"//go/lib/infra/modules/trust/internal/decoded:go_default_library",
Expand Down
5 changes: 2 additions & 3 deletions go/lib/infra/modules/trust/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/scrypto/trc"
"github.com/scionproto/scion/go/lib/serrors"
)

// Inspector gives insights into the primary ASes of a given ISD.
Expand Down Expand Up @@ -56,7 +55,7 @@ func (i DefaultInspector) ByAttributes(parentCtx context.Context, isd addr.ISD,
trcOpts := infra.TRCOpts{TrustStoreOpts: opts.TrustStoreOpts}
t, err := i.Provider.GetTRC(ctx, TRCID{ISD: isd, Version: scrypto.LatestVer}, trcOpts)
if err != nil {
return nil, serrors.WrapStr("unable to get latest TRC", err, "isd", isd)
return nil, err
}
ases := make([]addr.IA, 0, len(t.PrimaryASes))
for as, entry := range t.PrimaryASes {
Expand All @@ -81,7 +80,7 @@ func (i DefaultInspector) HasAttributes(ctx context.Context, ia addr.IA,
trcOpts := infra.TRCOpts{TrustStoreOpts: opts.TrustStoreOpts}
trc, err := i.Provider.GetTRC(ctx, TRCID{ISD: ia.I, Version: scrypto.LatestVer}, trcOpts)
if err != nil {
return false, serrors.WrapStr("unable to get latest TRC", err, "isd", ia.I)
return false, err
}
entry, ok := trc.PrimaryASes[ia.A]
if !ok {
Expand Down
Loading

0 comments on commit ecadd83

Please sign in to comment.