Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RevocationDB fixes #866

Merged
merged 4 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions cmd/captplanet/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net"
"os"
"path/filepath"
"regexp"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -51,7 +50,6 @@ func init() {
}

func cmdSetup(cmd *cobra.Command, args []string) (err error) {
redisURL := regexp.MustCompile("^redis://")
setupCfg.BasePath, err = filepath.Abs(setupCfg.BasePath)
if err != nil {
return err
Expand Down Expand Up @@ -112,9 +110,6 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
setupCfg.UplinkCA.KeyPath = filepath.Join(uplinkPath, "ca.key")
setupCfg.UplinkIdentity.CertPath = filepath.Join(uplinkPath, "identity.cert")
setupCfg.UplinkIdentity.KeyPath = filepath.Join(uplinkPath, "identity.key")
if redisURL.MatchString(setupCfg.SatelliteIdentity.Server.RevocationDBURL) {
setupCfg.UplinkIdentity.Server.RevocationDBURL = setupCfg.SatelliteIdentity.Server.RevocationDBURL
}
fmt.Printf("creating identity for uplink\n")
err = provider.SetupIdentity(process.Ctx(cmd), setupCfg.UplinkCA, setupCfg.UplinkIdentity)
if err != nil {
Expand Down Expand Up @@ -143,7 +138,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
"satellite.identity.key-path": setupCfg.SatelliteIdentity.KeyPath,
"satellite.identity.server.address": joinHostPort(
setupCfg.ListenHost, startingPort+1),
"satellite.identity.server.revocation-dburl": setupCfg.SatelliteIdentity.Server.RevocationDBURL,
"satellite.identity.server.revocation-dburl": "redis://127.0.0.1:6378?db=2&password=abc123",
"satellite.kademlia.bootstrap-addr": joinHostPort(
setupCfg.ListenHost, startingPort+1),
"satellite.pointer-db.database-url": "bolt://" + filepath.Join(
Expand All @@ -160,7 +155,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
"uplink.identity.key-path": setupCfg.UplinkIdentity.KeyPath,
"uplink.identity.server.address": joinHostPort(
setupCfg.ListenHost, startingPort),
"uplink.identity.server.revocation-dburl": setupCfg.SatelliteIdentity.Server.RevocationDBURL,
"uplink.identity.server.revocation-dburl": "redis://127.0.0.1:6378?db=2&password=abc123",
"uplink.client.overlay-addr": joinHostPort(
setupCfg.ListenHost, startingPort+1),
"uplink.client.pointer-db-addr": joinHostPort(
Expand Down Expand Up @@ -198,9 +193,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
setupCfg.ListenHost, startingPort+i*2+3)
overrides[storagenode+"identity.server.revocation-dburl"] = "bolt://" + filepath.Join(
storagenodePath, "revocations.db")
if redisURL.MatchString(setupCfg.SatelliteIdentity.Server.RevocationDBURL) {
overrides[storagenode+"identity.server.revocation-dburl"] = setupCfg.SatelliteIdentity.Server.RevocationDBURL
}
overrides[storagenode+"identity.server.revocation-dburl"] = "redis://127.0.0.1:6378?db=2&password=abc123"
overrides[storagenode+"kademlia.bootstrap-addr"] = joinHostPort(
setupCfg.ListenHost, startingPort+1)
overrides[storagenode+"storage.path"] = filepath.Join(storagenodePath, "data")
Expand Down
5 changes: 5 additions & 0 deletions pkg/peertls/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ func (r RevocationDB) Put(chain []*x509.Certificate, revExt pkix.Extension) erro
return nil
}

// Close closes the underlying store
func (r RevocationDB) Close() error {
return r.DB.Close()
}

// Verify checks if the signature of the revocation was produced by the passed cert's public key.
func (r Revocation) Verify(signingCert *x509.Certificate) error {
pubKey, ok := signingCert.PublicKey.(crypto.PublicKey)
Expand Down
34 changes: 21 additions & 13 deletions pkg/provider/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ type ServerConfig struct {
type ServerOptions struct {
Config ServerConfig
Ident *FullIdentity
RevDB *peertls.RevocationDB
Copy link
Member

@egonelbre egonelbre Dec 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks very weird to close "Options".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have an alternate name or flow in mind?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not at the moment

PCVFuncs []peertls.PeerCertVerificationFunc
}

// NewServerOptions is a constructor for `serverOptions` given an identity and config
func NewServerOptions(i *FullIdentity, c ServerConfig) (*ServerOptions, error) {
pcvFuncs, err := c.PCVFuncs()
serverOpts := &ServerOptions{
Config: c,
Ident: i,
}

err := c.configure(serverOpts)
if err != nil {
return nil, err
}

return &ServerOptions{
Config: c,
Ident: i,
PCVFuncs: pcvFuncs,
}, nil
return serverOpts, nil
}

// FullIdentityFromPEM loads a FullIdentity from a certificate chain and
Expand Down Expand Up @@ -294,11 +296,14 @@ func (ic IdentityConfig) Run(ctx context.Context, interceptor grpc.UnaryServerIn
if err != nil {
return err
}
defer func() { err = utils.CombineErrors(err, opts.RevDB.Close()) }()

s, err := NewProvider(opts, lis, interceptor, responsibilities...)
if err != nil {
return err
}
defer func() { _ = s.Close() }()

zap.S().Infof("Node %s started", s.Identity().ID)
return s.Run(ctx)
}
Expand Down Expand Up @@ -389,25 +394,26 @@ func (c ServerConfig) NewRevDB() (*peertls.RevocationDB, error) {
return db, nil
}

// PCVFuncs returns a slice of peer certificate verification functions based on the config.
func (c ServerConfig) PCVFuncs() (pcvs []peertls.PeerCertVerificationFunc, err error) {
// configure adds peer certificate verification functions and revocation datase to the config.
func (c ServerConfig) configure(opts *ServerOptions) (err error) {
var pcvs []peertls.PeerCertVerificationFunc
parseOpts := peertls.ParseExtOptions{}

if c.PeerCAWhitelistPath != "" {
caWhitelist, err := loadWhitelist(c.PeerCAWhitelistPath)
if err != nil {
return nil, err
return err
}
parseOpts.CAWhitelist = caWhitelist
pcvs = append(pcvs, peertls.VerifyCAWhitelist(caWhitelist))
}

if c.Extensions.Revocation {
revDB, err := c.NewRevDB()
opts.RevDB, err = c.NewRevDB()
if err != nil {
return nil, err
return err
}
pcvs = append(pcvs, peertls.VerifyUnrevokedChainFunc(revDB))
pcvs = append(pcvs, peertls.VerifyUnrevokedChainFunc(opts.RevDB))
}

exts := peertls.ParseExtensions(c.Extensions, parseOpts)
Expand All @@ -420,7 +426,9 @@ func (c ServerConfig) PCVFuncs() (pcvs []peertls.PeerCertVerificationFunc, err e
pcvs = pcvs[:len(pcvs)-1]
}
}
return pcvs, nil

opts.PCVFuncs = pcvs
return nil
}

func (so *ServerOptions) grpcOpts() (grpc.ServerOption, error) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-captplanet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -ueo pipefail
go install -v storj.io/storj/cmd/captplanet

captplanet setup --overwrite --satellite-identity.server.revocation-dburl="redis://127.0.0.1:6378?db=2&password=abc123"
captplanet setup --overwrite

unamestr=`uname`
if [[ "$unamestr" == 'Darwin' ]]; then
Expand Down Expand Up @@ -84,7 +84,7 @@ fi

kill -9 $CAPT_PID

captplanet setup --listen-host ::1 --overwrite --satellite-identity.server.revocation-dburl="redis://127.0.0.1:6378?db=2&password=abc123"
captplanet setup --listen-host ::1 --overwrite
if [[ "$unamestr" == 'Darwin' ]]; then
sed -i~ 's/interval:.*/interval: 1s/g' $HOME/Library/Application\ Support/Storj/Capt/config.yaml
else
Expand Down