Skip to content

Commit 5faf843

Browse files
authored
adapt hellodrkey (#235)
* adapt hellodrkey * fix go.mod * updated scionlab * lint * fix comments
1 parent ef97227 commit 5faf843

File tree

4 files changed

+92
-31
lines changed

4 files changed

+92
-31
lines changed

_examples/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ require (
88
github.com/netsec-ethz/scion-apps v0.5.1-0.20220504120040-79211109ed3f
99
github.com/scionproto/scion v0.6.1-0.20220202161514-5883c725f748
1010
google.golang.org/grpc v1.40.0
11+
google.golang.org/protobuf v1.27.1
1112
inet.af/netaddr v0.0.0-20210903134321-85fa6c94624e
1213
)
1314

14-
replace github.com/scionproto/scion => github.com/netsec-ethz/scion v0.6.1-0.20220422080039-25976708fd6b
15+
replace github.com/scionproto/scion => github.com/netsec-ethz/scion v0.6.1-0.20220929101513-2408583f35d1
1516

1617
replace github.com/netsec-ethz/scion-apps => ../

_examples/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJE
462462
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
463463
github.com/netsec-ethz/rains v0.5.0 h1:5x+C7aIVZNLtlonyA5JWUXR+MQXMuJzxK8PwnLWQV1E=
464464
github.com/netsec-ethz/rains v0.5.0/go.mod h1:+H9/DeJoYmFtcpLqFUJFQgALVWO675XdBZJdALL5ltU=
465-
github.com/netsec-ethz/scion v0.6.1-0.20220422080039-25976708fd6b h1:cLQzuQ51QiGVdwGgUZdFh6QyoXAM64YkdWqdGjBgfSg=
466-
github.com/netsec-ethz/scion v0.6.1-0.20220422080039-25976708fd6b/go.mod h1:9EyDb3Bfn7kDmy6v+gHKwl2eIxFo3Reod4TwDaKY5zo=
465+
github.com/netsec-ethz/scion v0.6.1-0.20220929101513-2408583f35d1 h1:6u2UB/od3ZQFQpHYsf/ZsJssrGlXMCmlwqbT0sIXLLw=
466+
github.com/netsec-ethz/scion v0.6.1-0.20220929101513-2408583f35d1/go.mod h1:9EyDb3Bfn7kDmy6v+gHKwl2eIxFo3Reod4TwDaKY5zo=
467467
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
468468
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
469469
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=

_examples/hellodrkey/README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ The application mimics the behavior using DRKey that would be observed by both a
88
The client uses the slow path to obtain a DRKey, and the server uses the fast path.
99

1010
Slow path (client):
11-
1. Obtain a connection to the designated `sciondForClient` and encapsulate it in the `Client` class.
11+
1. Obtain a connection to the designated Control Service and encapsulate it in the `Client` class.
1212
1. Obtain the metadata for the DRKey.
1313
1. Request the DRKey with that metadata.
1414

1515
Fast path (server):
16-
1. Obtain a connection to the designated `sciondForServer` and encapsulate it in the `Server` class.
17-
1. Obtain the Secret Value (SV) for the designated protocol.
18-
1. Derive the DRKey with the SV and the metadata.
16+
1. Obtain a connection to the designated Control Service and encapsulate it in the `Server` class.
17+
1. Obtain the Secret Value for that metadata. The Secret Value does not change with the destination host.
18+
1. Derive the DRKey with the SecretValue and the metadata.
1919

2020
Both slow and fast paths should obtain the same key.
2121
And both slow and fast path are measured for performance and their times displayed at the end.
@@ -26,12 +26,9 @@ For this example to work, you must configure your devel SCION with an appropriat
2626
Follow these steps:
2727

2828
1. Create a local topology with the `tiny.topo` description: `./scion.sh topology -c ./topology/tiny.topo`.
29-
1. Allow the server of the example setup to obtain the Secret Value (SV) for the DNS protocol.
30-
Edit `gen/ASff00_0_111/cs1-ff00_0_111-1.toml` and include an entry for `dns` under `drkey.delegation`:
31-
32-
```toml
33-
[drkey.delegation]
34-
dns = [ "127.0.0.1",]
35-
```
36-
37-
1. Start scion with `./scion.sh start` and run hellodrkey.
29+
1. Add the following entry to `gen/ASff00_0_111/cs1-ff00_0_111-1.toml`:
30+
```
31+
[drkey.delegation]
32+
scmp = [ "<application network address>",] (e.g., scmp = [ "127.0.0.1",] )
33+
```
34+
1. Restart scion with `./scion.sh stop; ./scion.sh start nobuild` and run hellodrkey.

_examples/hellodrkey/hellodrkey.go

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ import (
1818
"context"
1919
"encoding/hex"
2020
"fmt"
21+
"net"
2122
"time"
2223

2324
"github.com/scionproto/scion/go/lib/addr"
24-
drkeyctrl "github.com/scionproto/scion/go/lib/ctrl/drkey"
2525
"github.com/scionproto/scion/go/lib/daemon"
2626
"github.com/scionproto/scion/go/lib/drkey"
27+
"github.com/scionproto/scion/go/lib/drkey/fetcher"
28+
"github.com/scionproto/scion/go/lib/scrypto/cppki"
2729
cppb "github.com/scionproto/scion/go/pkg/proto/control_plane"
30+
dkpb "github.com/scionproto/scion/go/pkg/proto/drkey"
2831
"google.golang.org/grpc"
32+
"google.golang.org/protobuf/types/known/timestamppb"
2933
)
3034

3135
// check just ensures the error is nil, or complains and quits
@@ -35,21 +39,42 @@ func check(e error) {
3539
}
3640
}
3741

38-
type Client struct {
42+
type dialer struct {
3943
daemon daemon.Connector
4044
}
4145

46+
func (d *dialer) Dial(ctx context.Context, _ net.Addr) (*grpc.ClientConn, error) {
47+
// Obtain CS address from scion daemon
48+
svcs, err := d.daemon.SVCInfo(ctx, nil)
49+
check(err)
50+
cs := svcs[addr.SvcCS]
51+
if len(cs) == 0 {
52+
panic("no CS svc address")
53+
}
54+
55+
// Contact CS directly for SV
56+
return grpc.DialContext(ctx, cs, grpc.WithInsecure())
57+
}
58+
59+
type Client struct {
60+
fetcher *fetcher.FromCS
61+
}
62+
4263
func NewClient(ctx context.Context, sciondPath string) Client {
4364
daemon, err := daemon.NewService(sciondPath).Connect(ctx)
4465
check(err)
4566
return Client{
46-
daemon: daemon,
67+
fetcher: &fetcher.FromCS{
68+
Dialer: &dialer{
69+
daemon: daemon,
70+
},
71+
},
4772
}
4873
}
4974

5075
func (c Client) HostHostKey(ctx context.Context, meta drkey.HostHostMeta) drkey.HostHostKey {
5176
// get L2 key: (slow path)
52-
key, err := c.daemon.DRKeyGetHostHostKey(ctx, meta)
77+
key, err := c.fetcher.DRKeyGetHostHostKey(ctx, meta)
5378
check(err)
5479
return key
5580
}
@@ -68,36 +93,47 @@ func NewServer(ctx context.Context, sciondPath string) Server {
6893

6994
// fetchSV obtains the Secret Value (SV) for the selected protocol/epoch.
7095
// From this SV, all keys for this protocol/epoch can be derived locally.
71-
// The IP address of the server must be explicitly allowed to abtain this SV
96+
// The IP address of the server must be explicitly allowed to obtain this SV
7297
// from the the control server.
7398
func (s Server) fetchSV(ctx context.Context, meta drkey.SVMeta) drkey.SV {
74-
// Obtain CS address from scion daemon
99+
// Obtain CS address from scion daemon. Note there's no need to use
100+
// the daemon as long as a valid address could be passed to the dialing
101+
// function.
75102
svcs, err := s.daemon.SVCInfo(ctx, nil)
76103
check(err)
77104
cs := svcs[addr.SvcCS]
105+
if len(cs) == 0 {
106+
panic("no CS svc address")
107+
}
78108

79109
// Contact CS directly for SV
80110
conn, err := grpc.DialContext(ctx, cs, grpc.WithInsecure())
81111
check(err)
82112
defer conn.Close()
83113
client := cppb.NewDRKeyIntraServiceClient(conn)
84-
protoReq, err := drkeyctrl.SVMetaToProtoRequest(meta)
85-
check(err)
86-
rep, err := client.SV(ctx, protoReq)
114+
115+
rep, err := client.SV(ctx, &dkpb.SVRequest{
116+
ValTime: timestamppb.New(meta.Validity),
117+
ProtocolId: dkpb.Protocol(meta.ProtoId),
118+
})
87119
check(err)
88-
key, err := drkeyctrl.GetSVFromReply(meta.ProtoId, rep)
120+
key, err := getSecretFromReply(meta.ProtoId, rep)
89121
check(err)
90122
return key
91123
}
92124

93125
func (s Server) HostHostKey(sv drkey.SV, meta drkey.HostHostMeta) drkey.HostHostKey {
94-
var deriver drkey.SpecificDeriver
126+
deriver := (&drkey.SpecificDeriver{})
95127
lvl1, err := deriver.DeriveLvl1(drkey.Lvl1Meta{
96-
DstIA: meta.DstIA,
128+
Validity: meta.Validity,
129+
ProtoId: meta.ProtoId,
130+
SrcIA: meta.SrcIA,
131+
DstIA: meta.DstIA,
97132
}, sv.Key)
98133
check(err)
99134
asHost, err := deriver.DeriveHostAS(drkey.HostASMeta{
100-
SrcHost: meta.SrcHost,
135+
Lvl2Meta: meta.Lvl2Meta,
136+
SrcHost: meta.SrcHost,
101137
}, lvl1)
102138
check(err)
103139
hosthost, err := deriver.DeriveHostToHost(meta.DstHost, asHost)
@@ -122,15 +158,15 @@ func main() {
122158
const sciondForClient = "[fd00:f00d:cafe::7f00:c]:30255"
123159
clientIA, err := addr.ParseIA("1-ff00:0:112")
124160
check(err)
125-
const clientIP = "fd00:f00d:cafe::7f00:c"
161+
const clientIP = "fd00:f00d:cafe::7f00:b"
126162

127163
ctx, cancelF := context.WithTimeout(context.Background(), 4*time.Second)
128164
defer cancelF()
129165

130166
// meta describes the key that both client and server derive
131167
meta := drkey.HostHostMeta{
132168
Lvl2Meta: drkey.Lvl2Meta{
133-
ProtoId: drkey.DNS,
169+
ProtoId: drkey.SCMP,
134170
// Validity timestamp; both sides need to use the same time stamp when deriving the key
135171
// to ensure they derive keys for the same epoch.
136172
// Usually this is coordinated by means of a timestamp in the message.
@@ -168,3 +204,30 @@ func main() {
168204

169205
fmt.Printf("Server,\thost key = %s\tduration = %s\n", hex.EncodeToString(serverKey.Key[:]), durationServer)
170206
}
207+
208+
func getSecretFromReply(
209+
proto drkey.Protocol,
210+
rep *dkpb.SVResponse,
211+
) (drkey.SV, error) {
212+
213+
err := rep.EpochBegin.CheckValid()
214+
if err != nil {
215+
return drkey.SV{}, err
216+
}
217+
err = rep.EpochEnd.CheckValid()
218+
if err != nil {
219+
return drkey.SV{}, err
220+
}
221+
epoch := drkey.Epoch{
222+
Validity: cppki.Validity{
223+
NotBefore: rep.EpochBegin.AsTime(),
224+
NotAfter: rep.EpochEnd.AsTime(),
225+
},
226+
}
227+
returningKey := drkey.SV{
228+
ProtoId: proto,
229+
Epoch: epoch,
230+
}
231+
copy(returningKey.Key[:], rep.Key)
232+
return returningKey, nil
233+
}

0 commit comments

Comments
 (0)