Skip to content

Commit

Permalink
DRKey ported from previous SCIONLab branch
Browse files Browse the repository at this point in the history
Squashed changes for DRKey, ported to latest upstream master branch.

This includes the following main commits:

* 707a5e6 DRKey ported from the old SCIONLab (scionproto#77)

  This is itself a squashed commit  containing the bulk of the newly
  added DRKey implementation.

* 5a623a2 Allow a second call to initQUICSockets. (scionproto#79)
* df3a258 unify personal annotations to JordiSubira (scionproto#80)
* 9380c76 fix Level 1 key Exchange (scionproto#81)

  Add sanity check in the drkey_fetcher which validates that the
  response srcIA matches the intended server IA.

* a90f354 Remove redundant fields from Lvl1Req/Resp (scionproto#83)
* 64f4c23 cs/drkey: handle situations where no path to a peer AS can be found (scionproto#90)

  This condition is now handled analog to a similar condition in
  github.com/scionproto/scion/go/pkg/trust.AuthRouter.ChooseServer

The main change applied to make this compatible with the master
branch was to resolve the renaming / moving of what was previously
pkg/sciond to now pkg/daemon.

Co-authored-by: JordiSubira <jordi.subira.nieto@gmail.com>
Co-authored-by: Juan A. Garcia Pardo <juagargi@gmail.com>
  • Loading branch information
3 people committed Oct 5, 2021
1 parent dd9ef5a commit e5719e3
Show file tree
Hide file tree
Showing 148 changed files with 7,493 additions and 89 deletions.
7 changes: 7 additions & 0 deletions go/cs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ go_library(
"//go/cs/segreq:go_default_library",
"//go/cs/segreq/grpc:go_default_library",
"//go/lib/addr:go_default_library",
"//go/lib/drkeystorage:go_default_library",
"//go/lib/fatal:go_default_library",
"//go/lib/infra/infraenv:go_default_library",
"//go/lib/infra/messenger:go_default_library",
"//go/lib/infra/modules/itopo:go_default_library",
"//go/lib/infra/modules/segfetcher/grpc:go_default_library",
"//go/lib/infra/modules/seghandler:go_default_library",
"//go/lib/keyconf:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/metrics:go_default_library",
"//go/lib/periodic:go_default_library",
Expand All @@ -44,6 +46,8 @@ go_library(
"//go/pkg/command:go_default_library",
"//go/pkg/cs:go_default_library",
"//go/pkg/cs/api:go_default_library",
"//go/pkg/cs/drkey:go_default_library",
"//go/pkg/cs/drkey/grpc:go_default_library",
"//go/pkg/cs/trust/grpc:go_default_library",
"//go/pkg/cs/trust/metrics:go_default_library",
"//go/pkg/discovery:go_default_library",
Expand All @@ -63,9 +67,12 @@ go_library(
"@com_github_go_chi_chi_v5//:go_default_library",
"@com_github_go_chi_cors//:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library",
"@com_github_grpc_ecosystem_grpc_opentracing//go/otgrpc:go_default_library",
"@com_github_opentracing_opentracing_go//:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@in_gopkg_yaml_v2//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials:go_default_library",
"@org_golang_google_grpc//health:go_default_library",
"@org_golang_google_grpc//health/grpc_health_v1:go_default_library",
],
Expand Down
11 changes: 10 additions & 1 deletion go/cs/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ go_library(
srcs = [
"bs_sample.go",
"config.go",
"drkey.go",
"sample.go",
],
importpath = "github.com/scionproto/scion/go/cs/config",
visibility = ["//visibility:public"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/config:go_default_library",
"//go/lib/drkey/protocol:go_default_library",
"//go/lib/env:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/serrors:go_default_library",
Expand All @@ -24,15 +27,21 @@ go_library(

go_test(
name = "go_default_test",
srcs = ["config_test.go"],
srcs = [
"config_test.go",
"drkey_test.go",
],
embed = [":go_default_library"],
deps = [
"//go/lib/env/envtest:go_default_library",
"//go/lib/log/logtest:go_default_library",
"//go/pkg/api/apitest:go_default_library",
"//go/pkg/api/jwtauth:go_default_library",
"//go/pkg/storage:go_default_library",
"//go/pkg/storage/test:go_default_library",
"@com_github_burntsushi_toml//:go_default_library",
"@com_github_pelletier_go_toml//:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
)
4 changes: 4 additions & 0 deletions go/cs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Config struct {
PS PSConfig `toml:"path,omitempty"`
CA CA `toml:"ca,omitempty"`
TrustEngine trustengine.Config `toml:"trustengine,omitempty"`
DRKey DRKeyConfig `toml:"drkey,omitempty"`
}

// InitDefaults initializes the default values for all parts of the config.
Expand All @@ -82,6 +83,7 @@ func (cfg *Config) InitDefaults() {
&cfg.PS,
&cfg.CA,
&cfg.TrustEngine,
&cfg.DRKey,
)
}

Expand All @@ -100,6 +102,7 @@ func (cfg *Config) Validate() error {
&cfg.PS,
&cfg.CA,
&cfg.TrustEngine,
&cfg.DRKey,
)
}

Expand Down Expand Up @@ -138,6 +141,7 @@ func (cfg *Config) Sample(dst io.Writer, path config.Path, _ config.CtxMap) {
&cfg.PS,
&cfg.CA,
&cfg.TrustEngine,
&cfg.DRKey,
)
}

Expand Down
161 changes: 161 additions & 0 deletions go/cs/config/drkey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Copyright 2019 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package config

import (
"io"
"time"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/config"
"github.com/scionproto/scion/go/lib/drkey/protocol"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/util"
"github.com/scionproto/scion/go/pkg/storage"
)

const (
// DefaultEpochDuration is the default duration for the drkey SV and derived keys
DefaultEpochDuration = 24 * time.Hour
)

var _ (config.Config) = (*DRKeyConfig)(nil)

// DRKeyConfig is the configuration for the connection to the trust database.
type DRKeyConfig struct {
// enabled is set to true if we find all the required fields in the configuration.
enabled bool
// DRKeyDB contains the DRKey DB configuration.
DRKeyDB storage.DBConfig `toml:"drkey_db,omitempty"`
// EpochDuration is the duration of the keys in this CS.
EpochDuration util.DurWrap `toml:"epoch_duration,omitempty"`
// AuthorizedDelegations is the DelegationList for this CS.
Delegation DelegationList `toml:"delegation,omitempty"`

//TLS config
CertFile string `toml:"cert_file,omitempty"`
KeyFile string `toml:"key_file,omitempty"`
}

// NewDRKeyConfig returns a pointer to a valid, empty configuration.
func NewDRKeyConfig() *DRKeyConfig {
c := DRKeyConfig{
DRKeyDB: storage.DBConfig{},
Delegation: DelegationList{},
}
return &c
}

// InitDefaults initializes values of unset keys and determines if the configuration enables DRKey.
func (cfg *DRKeyConfig) InitDefaults() {
cfg.enabled = true
if cfg.EpochDuration.Duration == 0 {
cfg.EpochDuration.Duration = DefaultEpochDuration
}
config.InitAll(&cfg.Delegation)
}

// Enabled returns true if DRKey is configured. False otherwise.
func (cfg *DRKeyConfig) Enabled() bool {
if cfg.DRKeyDB.Connection == "" {
return false
}
return true
}

// Validate validates that all values are parsable.
func (cfg *DRKeyConfig) Validate() error {
return config.ValidateAll(&cfg.DRKeyDB, &cfg.Delegation)
}

// Sample writes a config sample to the writer.
func (cfg *DRKeyConfig) Sample(dst io.Writer, path config.Path, ctx config.CtxMap) {
config.WriteString(dst, drkeySample)
config.WriteSample(dst, path,
config.CtxMap{config.ID: idSample},
config.OverrideName(
config.FormatData(
&cfg.DRKeyDB,
storage.SetID(storage.SampleDRKeyDB, idSample).Connection,
),
"drkey_db",
),
&cfg.Delegation,
)
}

// ConfigName is the key in the toml file.
func (cfg *DRKeyConfig) ConfigName() string {
return "drkey"
}

// DelegationList configures which endhosts can get delegation secrets, per protocol.
type DelegationList map[string][]string

var _ (config.Config) = (*DelegationList)(nil)

// InitDefaults will not add or modify any entry in the config.
func (cfg *DelegationList) InitDefaults() {
if *cfg == nil {
*cfg = make(DelegationList)
}
}

// Validate validates that the protocols exist, and their addresses are parsable.
func (cfg *DelegationList) Validate() error {
for proto, list := range *cfg {
if _, found := protocol.KnownDerivations[proto]; !found {
return serrors.New("Configured protocol not found", "protocol", proto)
}
for _, ip := range list {
if h := addr.HostFromIPStr(ip); h == nil {
return serrors.New("Syntax error: not a valid address", "ip", ip)
}
}
}
return nil
}

// Sample writes a config sample to the writer.
func (cfg *DelegationList) Sample(dst io.Writer, path config.Path, ctx config.CtxMap) {
config.WriteString(dst, drkeyDelegationListSample)
}

// ConfigName is the key in the toml file.
func (cfg *DelegationList) ConfigName() string {
return "delegation"
}

// ToMapPerHost will return map where there is a set of supported protocols per host.
func (cfg *DelegationList) ToMapPerHost() map[[16]byte]map[string]struct{} {
m := make(map[[16]byte]map[string]struct{})
for proto, ipList := range *cfg {
for _, ip := range ipList {
host := addr.HostFromIPStr(ip)
if host == nil {
continue
}
var rawHost [16]byte
copy(rawHost[:], host.IP().To16())
protoSet := m[rawHost]
if protoSet == nil {
protoSet = make(map[string]struct{})
}
protoSet[proto] = struct{}{}
m[rawHost] = protoSet
}
}
return m
}
Loading

0 comments on commit e5719e3

Please sign in to comment.