storj/storagenode/vouchers/verification.go
Egon Elbre 5d0816430f
rename all the things (#2531)
* rename pkg/linksharing to linksharing
* rename pkg/httpserver to linksharing/httpserver
* rename pkg/eestream to uplink/eestream
* rename pkg/stream to uplink/stream
* rename pkg/metainfo/kvmetainfo to uplink/metainfo/kvmetainfo
* rename pkg/auth/signing to pkg/signing
* rename pkg/storage to uplink/storage
* rename pkg/accounting to satellite/accounting
* rename pkg/audit to satellite/audit
* rename pkg/certdb to satellite/certdb
* rename pkg/discovery to satellite/discovery
* rename pkg/overlay to satellite/overlay
* rename pkg/datarepair to satellite/repair
2019-07-28 08:55:36 +03:00

53 lines
1.4 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package vouchers
import (
"context"
"time"
"github.com/zeebo/errs"
"storj.io/storj/internal/errs2"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/signing"
"storj.io/storj/pkg/storj"
)
var (
// ErrVerify is returned when voucher fields are not valid.
ErrVerify = errs.Class("verification")
)
// VerifyVoucher verifies that the signature and the information contained in a voucher are valid
func (service *Service) VerifyVoucher(ctx context.Context, satellite storj.NodeID, voucher *pb.Voucher) (err error) {
defer mon.Task()(&ctx)(&err)
if self := service.transport.Identity().ID; voucher.StorageNodeId != self {
return ErrVerify.New("Storage node ID does not match expected: (%v) (%v)", voucher.StorageNodeId, self)
}
if voucher.SatelliteId != satellite {
return ErrVerify.New("Satellite ID does not match expected: (%v) (%v)", voucher.SatelliteId, satellite)
}
if voucher.Expiration.Before(time.Now()) {
return ErrVerify.New("Voucher is already expired")
}
signee, err := service.trust.GetSignee(ctx, voucher.SatelliteId)
if err != nil {
if errs2.IsCanceled(err) {
return err
}
return ErrVerify.New("unable to get signee: %v", err) // TODO: report grpc status bad message
}
if err := signing.VerifyVoucher(ctx, signee, voucher); err != nil {
return ErrVerify.New("invalid voucher signature: %v", err) // TODO: report grpc bad message
}
return nil
}