c35b93766d
this change removes the cryptopasta dependency. a couple possible sources of problem with this change: * the encoding used for ECDSA signatures on SignedMessage has changed. the encoding employed by cryptopasta was workable, but not the same as the encoding used for such signatures in the rest of the world (most particularly, on ECDSA signatures in X.509 certificates). I think we'll be best served by using one ECDSA signature encoding from here on, but if we need to use the old encoding for backwards compatibility with existing nodes, that can be arranged. * since there's already a breaking change in SignedMessage, I changed it to send and receive public keys in raw PKIX format, instead of PEM. PEM just adds unhelpful overhead for this case.
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package pointerdb
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
"storj.io/storj/pkg/auth"
|
|
"storj.io/storj/pkg/certdb"
|
|
"storj.io/storj/pkg/identity"
|
|
"storj.io/storj/pkg/pb"
|
|
)
|
|
|
|
// AllocationSigner structure
|
|
type AllocationSigner struct {
|
|
satelliteIdentity *identity.FullIdentity
|
|
bwExpiration int
|
|
certdb certdb.DB
|
|
}
|
|
|
|
// NewAllocationSigner creates new instance
|
|
func NewAllocationSigner(satelliteIdentity *identity.FullIdentity, bwExpiration int, upldb certdb.DB) *AllocationSigner {
|
|
return &AllocationSigner{
|
|
satelliteIdentity: satelliteIdentity,
|
|
bwExpiration: bwExpiration,
|
|
certdb: upldb,
|
|
}
|
|
}
|
|
|
|
// PayerBandwidthAllocation returns generated payer bandwidth allocation
|
|
func (allocation *AllocationSigner) PayerBandwidthAllocation(ctx context.Context, peerIdentity *identity.PeerIdentity, action pb.BandwidthAction) (pba *pb.PayerBandwidthAllocation, err error) {
|
|
if peerIdentity == nil {
|
|
return nil, Error.New("missing peer identity")
|
|
}
|
|
serialNum, err := uuid.New()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
created := time.Now().Unix()
|
|
// convert ttl from days to seconds
|
|
ttl := allocation.bwExpiration
|
|
ttl *= 86400
|
|
|
|
// store the corresponding uplink's id and public key into certDB db
|
|
err = allocation.certdb.SavePublicKey(ctx, peerIdentity.ID, peerIdentity.Leaf.PublicKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pba = &pb.PayerBandwidthAllocation{
|
|
SatelliteId: allocation.satelliteIdentity.ID,
|
|
UplinkId: peerIdentity.ID,
|
|
CreatedUnixSec: created,
|
|
ExpirationUnixSec: created + int64(ttl),
|
|
Action: action,
|
|
SerialNumber: serialNum.String(),
|
|
}
|
|
if err := auth.SignMessage(pba, *allocation.satelliteIdentity); err != nil {
|
|
return nil, err
|
|
}
|
|
return pba, nil
|
|
}
|