Merge pull request #34 from nspcc-dev/object-verification-change

Add public key header for new object verification routine
remotes/KirillovDenis/feature/refactor-sig-rpc
Alex Vanin 2020-01-17 11:44:41 +03:00 committed by GitHub
commit beb13d5a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 435 additions and 83 deletions

View File

@ -33,6 +33,7 @@
- [IntegrityHeader](#object.IntegrityHeader)
- [Link](#object.Link)
- [Object](#object.Object)
- [PublicKey](#object.PublicKey)
- [Range](#object.Range)
- [SystemHeader](#object.SystemHeader)
- [Tombstone](#object.Tombstone)
@ -368,6 +369,7 @@ in distributed system.
| PayloadChecksum | [bytes](#bytes) | | PayloadChecksum of actual object's payload |
| Integrity | [IntegrityHeader](#object.IntegrityHeader) | | Integrity header with checksum of all above headers in the object |
| StorageGroup | [storagegroup.StorageGroup](#storagegroup.StorageGroup) | | StorageGroup contains meta information for the data audit |
| PublicKey | [PublicKey](#object.PublicKey) | | PublicKey of owner of the object. Key is used for verification and can be based on NeoID or x509 cert. |
<a name="object.IntegrityHeader"></a>
@ -407,6 +409,17 @@ in distributed system.
| Payload | [bytes](#bytes) | | Payload is an object's payload |
<a name="object.PublicKey"></a>
### Message PublicKey
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| Value | [bytes](#bytes) | | Value contains marshaled ecdsa public key |
<a name="object.Range"></a>
### Message Range

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/golang/protobuf v1.3.2
github.com/google/uuid v1.1.1
github.com/mr-tron/base58 v1.1.3
github.com/nspcc-dev/neofs-crypto v0.2.2
github.com/nspcc-dev/neofs-crypto v0.2.3
github.com/nspcc-dev/netmap v1.6.1
github.com/nspcc-dev/tzhash v1.3.0
github.com/pkg/errors v0.8.1

8
go.sum
View File

@ -106,12 +106,12 @@ github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjW
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nspcc-dev/hrw v1.0.8 h1:vwRuJXZXgkMvf473vFzeWGCfY1WBVeSHAEHvR4u3/Cg=
github.com/nspcc-dev/hrw v1.0.8/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU=
github.com/nspcc-dev/neofs-crypto v0.2.2 h1:jLc5O+Wdpaq7L4lNYFX7li+OP4I1FsvvcPW1NXm3erY=
github.com/nspcc-dev/neofs-crypto v0.2.2/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
github.com/nspcc-dev/neofs-crypto v0.2.3 h1:aca3X2aly92ENRbFK+kH6Hd+J9EQ4Eu6XMVoITSIKtc=
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
github.com/nspcc-dev/netmap v1.6.1 h1:Pigqpqi6QSdRiusbq5XlO20A18k6Eyu7j9MzOfAE3CM=
github.com/nspcc-dev/netmap v1.6.1/go.mod h1:mhV3UOg9ljQmu0teQShD6+JYX09XY5gu2I4hIByCH9M=
github.com/nspcc-dev/rfc6979 v0.1.0 h1:Lwg7esRRoyK1Up/IN1vAef1EmvrBeMHeeEkek2fAJ6c=
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
github.com/nspcc-dev/tzhash v1.3.0 h1:n6FTHsfPYbMi5Jmo6SwGVVRQD8i2w1P2ScCaW6rz69Q=
github.com/nspcc-dev/tzhash v1.3.0/go.mod h1:Lc4DersKS8MNIrunTmsAzANO56qnG+LZ4GOE/WYGVzU=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=

View File

@ -1,4 +1,5 @@
package object
// todo: all extensions must be transferred to the separate util library
import "github.com/nspcc-dev/neofs-proto/storagegroup"

View File

@ -67,6 +67,8 @@ const (
IntegrityHdr
// StorageGroupHdr is a storage group header type.
StorageGroupHdr
// PublicKeyHdr is a public key header type.
PublicKeyHdr
)
var (
@ -140,6 +142,8 @@ func (m Header) typeOf(t isHeader_Value) (ok bool) {
_, ok = m.Value.(*Header_Integrity)
case *Header_StorageGroup:
_, ok = m.Value.(*Header_StorageGroup)
case *Header_PublicKey:
_, ok = m.Value.(*Header_PublicKey)
}
return
}
@ -168,6 +172,8 @@ func HeaderType(t headerType) Pred {
return func(h *Header) bool { _, ok := h.Value.(*Header_Integrity); return ok }
case StorageGroupHdr:
return func(h *Header) bool { _, ok := h.Value.(*Header_StorageGroup); return ok }
case PublicKeyHdr:
return func(h *Header) bool { _, ok := h.Value.(*Header_PublicKey); return ok }
default:
return nil
}

View File

@ -220,6 +220,7 @@ type Header struct {
// *Header_PayloadChecksum
// *Header_Integrity
// *Header_StorageGroup
// *Header_PublicKey
Value isHeader_Value `protobuf_oneof:"Value"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
@ -291,6 +292,9 @@ type Header_Integrity struct {
type Header_StorageGroup struct {
StorageGroup *storagegroup.StorageGroup `protobuf:"bytes,10,opt,name=StorageGroup,proto3,oneof" json:"StorageGroup,omitempty"`
}
type Header_PublicKey struct {
PublicKey *PublicKey `protobuf:"bytes,11,opt,name=PublicKey,proto3,oneof" json:"PublicKey,omitempty"`
}
func (*Header_Link) isHeader_Value() {}
func (*Header_Redirect) isHeader_Value() {}
@ -302,6 +306,7 @@ func (*Header_HomoHash) isHeader_Value() {}
func (*Header_PayloadChecksum) isHeader_Value() {}
func (*Header_Integrity) isHeader_Value() {}
func (*Header_StorageGroup) isHeader_Value() {}
func (*Header_PublicKey) isHeader_Value() {}
func (m *Header) GetValue() isHeader_Value {
if m != nil {
@ -373,6 +378,13 @@ func (m *Header) GetStorageGroup() *storagegroup.StorageGroup {
return nil
}
func (m *Header) GetPublicKey() *PublicKey {
if x, ok := m.GetValue().(*Header_PublicKey); ok {
return x.PublicKey
}
return nil
}
// XXX_OneofWrappers is for the internal use of the proto package.
func (*Header) XXX_OneofWrappers() []interface{} {
return []interface{}{
@ -386,6 +398,7 @@ func (*Header) XXX_OneofWrappers() []interface{} {
(*Header_PayloadChecksum)(nil),
(*Header_Integrity)(nil),
(*Header_StorageGroup)(nil),
(*Header_PublicKey)(nil),
}
}
@ -750,6 +763,50 @@ func (m *Object) GetPayload() []byte {
return nil
}
type PublicKey struct {
// Value contains marshaled ecdsa public key
Value []byte `protobuf:"bytes,1,opt,name=Value,proto3" json:"Value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *PublicKey) Reset() { *m = PublicKey{} }
func (m *PublicKey) String() string { return proto.CompactTextString(m) }
func (*PublicKey) ProtoMessage() {}
func (*PublicKey) Descriptor() ([]byte, []int) {
return fileDescriptor_02021a1d39b1aee0, []int{10}
}
func (m *PublicKey) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *PublicKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
func (m *PublicKey) XXX_Merge(src proto.Message) {
xxx_messageInfo_PublicKey.Merge(m, src)
}
func (m *PublicKey) XXX_Size() int {
return m.Size()
}
func (m *PublicKey) XXX_DiscardUnknown() {
xxx_messageInfo_PublicKey.DiscardUnknown(m)
}
var xxx_messageInfo_PublicKey proto.InternalMessageInfo
func (m *PublicKey) GetValue() []byte {
if m != nil {
return m.Value
}
return nil
}
func init() {
proto.RegisterEnum("object.Link_Type", Link_Type_name, Link_Type_value)
proto.RegisterEnum("object.Transform_Type", Transform_Type_name, Transform_Type_value)
@ -763,66 +820,69 @@ func init() {
proto.RegisterType((*Link)(nil), "object.Link")
proto.RegisterType((*Transform)(nil), "object.Transform")
proto.RegisterType((*Object)(nil), "object.Object")
proto.RegisterType((*PublicKey)(nil), "object.PublicKey")
}
func init() { proto.RegisterFile("object/types.proto", fileDescriptor_02021a1d39b1aee0) }
var fileDescriptor_02021a1d39b1aee0 = []byte{
// 863 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x55, 0xcb, 0x8e, 0xe3, 0x44,
0x14, 0xb5, 0x13, 0xe7, 0x75, 0xe3, 0x99, 0xf6, 0x14, 0xc3, 0x60, 0x05, 0x91, 0x6e, 0x59, 0x3c,
0x9a, 0x81, 0x76, 0x8b, 0x1e, 0xd0, 0x88, 0x05, 0x88, 0x4e, 0x07, 0xe1, 0x88, 0x81, 0x6e, 0x55,
0x3f, 0x16, 0xec, 0x9c, 0xb8, 0xe2, 0x14, 0x9d, 0x54, 0x45, 0x55, 0x95, 0x99, 0xc9, 0x9e, 0x2f,
0x60, 0xc5, 0x8e, 0xdf, 0x99, 0x25, 0x4b, 0x34, 0x8b, 0x16, 0x6a, 0x3e, 0x80, 0x5f, 0x40, 0x55,
0xb6, 0x13, 0xbb, 0x67, 0x36, 0x56, 0xdd, 0x7b, 0xce, 0x29, 0xdf, 0xba, 0xf7, 0x94, 0x0d, 0x88,
0x8f, 0x7f, 0x25, 0x13, 0x75, 0xa8, 0xd6, 0x4b, 0x22, 0xc3, 0xa5, 0xe0, 0x8a, 0xa3, 0x66, 0x96,
0xeb, 0x79, 0x82, 0x4c, 0x65, 0x19, 0xe9, 0xbd, 0x23, 0x89, 0x94, 0x94, 0xb3, 0x4a, 0xd2, 0x97,
0x8a, 0x8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FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x55, 0xcb, 0x72, 0x1b, 0x45,
0x14, 0xd5, 0x48, 0xa3, 0xd7, 0xd5, 0x38, 0x9e, 0x34, 0x21, 0x4c, 0x89, 0x42, 0x36, 0x53, 0x3c,
0x4c, 0xc0, 0xe3, 0xc2, 0x81, 0x4a, 0xb1, 0x80, 0xc2, 0xb2, 0x28, 0xa4, 0x22, 0x60, 0x55, 0xfb,
0xb1, 0x60, 0x37, 0x92, 0x5a, 0xa3, 0xc6, 0x52, 0xb7, 0xaa, 0xbb, 0x27, 0x89, 0x7e, 0x83, 0x15,
0x3b, 0x3e, 0x83, 0x5f, 0xc8, 0x92, 0x25, 0x95, 0x85, 0x8b, 0x32, 0x1f, 0xc0, 0x2f, 0xa4, 0xba,
0xe7, 0xa1, 0x19, 0x27, 0x1b, 0x55, 0x9f, 0x7b, 0xce, 0x69, 0xdd, 0xb9, 0x7d, 0x7a, 0x06, 0x10,
0x9f, 0xfc, 0x46, 0xa6, 0xea, 0x48, 0x6d, 0xd6, 0x44, 0x06, 0x6b, 0xc1, 0x15, 0x47, 0x8d, 0xa4,
0xd6, 0x75, 0x05, 0x99, 0xcb, 0x22, 0xd3, 0x7d, 0x47, 0x12, 0x29, 0x29, 0x67, 0xa5, 0xa2, 0x27,
0x15, 0x17, 0x61, 0x44, 0x22, 0xc1, 0xe3, 0x75, 0x89, 0x39, 0x8c, 0xa8, 0x5a, 0xc4, 0x93, 0x60,
0xca, 0x57, 0x47, 0x11, 0x8f, 0xf8, 0x91, 0x29, 0x4f, 0xe2, 0xb9, 0x41, 0x06, 0x98, 0x55, 0x22,
0xf7, 0x9f, 0x40, 0x1d, 0x87, 0x2c, 0x22, 0xe8, 0x21, 0x34, 0xce, 0xe6, 0x73, 0x49, 0x94, 0x67,
0xed, 0x5b, 0x07, 0x36, 0x4e, 0x91, 0xae, 0x3f, 0x25, 0x2c, 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3e, 0x7c, 0xe3, 0xfa, 0x17, 0x5a, 0xf5, 0x1f, 0xbf, 0xad, 0x9d, 0x36, 0xd4, 0xcf,
0xd7, 0x4b, 0xaa, 0xbb, 0x69, 0x81, 0xad, 0xe7, 0xe0, 0x56, 0x75, 0xf1, 0x67, 0x1e, 0x2f, 0x67,
0x6e, 0xcd, 0xff, 0xdd, 0x82, 0xc6, 0x99, 0xd9, 0x14, 0x7d, 0x57, 0x4e, 0x6e, 0xfa, 0xfa, 0x7b,
0x90, 0xfd, 0x67, 0x91, 0x4b, 0x53, 0x50, 0x4e, 0x7a, 0x00, 0xcd, 0xf4, 0x6c, 0xbc, 0xea, 0x7e,
0xed, 0xa0, 0x73, 0x7c, 0x2f, 0xb3, 0x96, 0x4c, 0x99, 0x48, 0xdf, 0x8c, 0x34, 0xea, 0x49, 0xbc,
0x71, 0x06, 0xfd, 0x0f, 0x0b, 0xb7, 0x71, 0xfb, 0xba, 0x4e, 0xce, 0x3f, 0x01, 0xfd, 0x6f, 0x5f,
0xde, 0xf6, 0xac, 0xbf, 0x6f, 0x7b, 0xd6, 0x3f, 0xb7, 0x3d, 0xeb, 0xdf, 0xdb, 0x9e, 0xf5, 0xc7,
0x7f, 0xbd, 0xca, 0xaf, 0x9f, 0x16, 0x3e, 0x31, 0x4c, 0xae, 0xa7, 0xd3, 0xc3, 0x19, 0x79, 0x76,
0xc4, 0x08, 0x9f, 0xcb, 0xc3, 0xe4, 0x03, 0x93, 0x74, 0x34, 0x69, 0x18, 0xf4, 0xf8, 0x75, 0x00,
0x00, 0x00, 0xff, 0xff, 0x95, 0x5d, 0xc3, 0x1e, 0xf1, 0x06, 0x00, 0x00,
}
func (m *Range) Marshal() (dAtA []byte, err error) {
@ -1142,6 +1202,27 @@ func (m *Header_StorageGroup) MarshalToSizedBuffer(dAtA []byte) (int, error) {
}
return len(dAtA) - i, nil
}
func (m *Header_PublicKey) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Header_PublicKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
if m.PublicKey != nil {
{
size, err := m.PublicKey.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTypes(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x5a
}
return len(dAtA) - i, nil
}
func (m *Tombstone) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
@ -1456,6 +1537,40 @@ func (m *Object) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *PublicKey) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *PublicKey) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *PublicKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Value) > 0 {
i -= len(m.Value)
copy(dAtA[i:], m.Value)
i = encodeVarintTypes(dAtA, i, uint64(len(m.Value)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintTypes(dAtA []byte, offset int, v uint64) int {
offset -= sovTypes(v)
base := offset
@ -1638,6 +1753,18 @@ func (m *Header_StorageGroup) Size() (n int) {
}
return n
}
func (m *Header_PublicKey) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.PublicKey != nil {
l = m.PublicKey.Size()
n += 1 + l + sovTypes(uint64(l))
}
return n
}
func (m *Tombstone) Size() (n int) {
if m == nil {
return 0
@ -1770,6 +1897,22 @@ func (m *Object) Size() (n int) {
return n
}
func (m *PublicKey) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Value)
if l > 0 {
n += 1 + l + sovTypes(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func sovTypes(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
@ -2364,6 +2507,41 @@ func (m *Header) Unmarshal(dAtA []byte) error {
}
m.Value = &Header_StorageGroup{v}
iNdEx = postIndex
case 11:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTypes
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTypes
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &PublicKey{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
m.Value = &Header_PublicKey{v}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTypes(dAtA[iNdEx:])
@ -3215,6 +3393,94 @@ func (m *Object) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *PublicKey) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: PublicKey: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: PublicKey: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthTypes
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthTypes
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...)
if m.Value == nil {
m.Value = []byte{}
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTypes(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthTypes
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthTypes
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipTypes(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0

View File

@ -45,6 +45,8 @@ message Header {
IntegrityHeader Integrity = 9;
// StorageGroup contains meta information for the data audit
storagegroup.StorageGroup StorageGroup = 10;
// PublicKey of owner of the object. Key is used for verification and can be based on NeoID or x509 cert.
PublicKey PublicKey = 11;
}
}
@ -122,3 +124,8 @@ message Object {
// Payload is an object's payload
bytes Payload = 3;
}
message PublicKey {
// Value contains marshaled ecdsa public key
bytes Value = 1;
}

View File

@ -63,28 +63,35 @@ func (m Object) verifySignature(key []byte, ih *IntegrityHeader) error {
// Verify performs local integrity check by finding verification header and
// integrity header. If header integrity is passed, function verifies
// checksum of the object payload.
// todo: move this verification logic into separate library
func (m Object) Verify() error {
var (
err error
checksum []byte
pubkey []byte
)
// Prepare structures
_, vh := m.LastHeader(HeaderType(VerifyHdr))
if vh == nil {
return ErrHeaderNotFound
}
verify := vh.Value.(*Header_Verify).Verify
_, ih := m.LastHeader(HeaderType(IntegrityHdr))
if ih == nil {
ind, ih := m.LastHeader(HeaderType(IntegrityHdr))
if ih == nil || ind != len(m.Headers) - 1{
return ErrHeaderNotFound
}
integrity := ih.Value.(*Header_Integrity).Integrity
// Prepare structures
_, vh := m.LastHeader(HeaderType(VerifyHdr))
if vh == nil {
_, pkh := m.LastHeader(HeaderType(PublicKeyHdr))
if pkh == nil {
return ErrHeaderNotFound
}
pubkey = pkh.Value.(*Header_PublicKey).PublicKey.Value
} else {
pubkey = vh.Value.(*Header_Verify).Verify.PublicKey
}
// Verify signature
err = m.verifySignature(verify.PublicKey, integrity)
err = m.verifySignature(pubkey, integrity)
if err != nil {
return errors.Wrapf(err, "public key: %x", verify.PublicKey)
return errors.Wrapf(err, "public key: %x", pubkey)
}
// Verify checksum of header
@ -111,22 +118,32 @@ func (m Object) Verify() error {
return nil
}
// Sign creates new integrity header and adds it to the end of the list of
// extended headers.
func (m *Object) Sign(key *ecdsa.PrivateKey) error {
headerChecksum, err := m.headersChecksum(false)
// CreateIntegrityHeader returns signed integrity header for the object
func CreateIntegrityHeader(obj *Object, key *ecdsa.PrivateKey) (*Header, error) {
headerChecksum, err := obj.headersChecksum(false)
if err != nil {
return err
return nil, err
}
headerChecksumSignature, err := crypto.Sign(key, headerChecksum)
if err != nil {
return err
return nil, err
}
m.AddHeader(&Header{Value: &Header_Integrity{
return &Header{Value: &Header_Integrity{
Integrity: &IntegrityHeader{
HeadersChecksum: headerChecksum,
ChecksumSignature: headerChecksumSignature,
},
}})
}}, nil
}
// Sign creates new integrity header and adds it to the end of the list of
// extended headers.
func (m *Object) Sign(key *ecdsa.PrivateKey) error {
ih, err := CreateIntegrityHeader(m, key)
if err != nil {
return err
}
m.AddHeader(ih)
return nil
}

View File

@ -56,7 +56,7 @@ func TestObject_Verify(t *testing.T) {
obj.SetPayload(payload)
obj.SetHeader(&Header{Value: &Header_PayloadChecksum{[]byte("incorrect checksum")}})
t.Run("error no integrity header", func(t *testing.T) {
t.Run("error no integrity header and pubkey", func(t *testing.T) {
err = obj.Verify()
require.EqualError(t, err, ErrHeaderNotFound.Error())
})
@ -83,12 +83,25 @@ func TestObject_Verify(t *testing.T) {
}
obj.SetVerificationHeader(vh)
// validation header is not last
t.Run("error validation header is not last", func(t *testing.T) {
err = obj.Verify()
require.EqualError(t, err, ErrHeaderNotFound.Error())
})
obj.Headers = obj.Headers[:len(obj.Headers)-2]
obj.SetVerificationHeader(vh)
obj.SetHeader(&Header{Value: &Header_Integrity{ih}})
t.Run("error invalid header checksum", func(t *testing.T) {
err = obj.Verify()
require.EqualError(t, err, ErrVerifyHeader.Error())
})
require.NoError(t, obj.Sign(sessionkey))
obj.Headers = obj.Headers[:len(obj.Headers)-1]
genIH, err := CreateIntegrityHeader(obj, sessionkey)
require.NoError(t, err)
obj.SetHeader(genIH)
t.Run("error invalid payload checksum", func(t *testing.T) {
err = obj.Verify()
@ -96,10 +109,39 @@ func TestObject_Verify(t *testing.T) {
})
obj.SetHeader(&Header{Value: &Header_PayloadChecksum{obj.PayloadChecksum()}})
require.NoError(t, obj.Sign(sessionkey))
t.Run("correct", func(t *testing.T) {
obj.Headers = obj.Headers[:len(obj.Headers)-1]
genIH, err = CreateIntegrityHeader(obj, sessionkey)
require.NoError(t, err)
obj.SetHeader(genIH)
t.Run("correct with vh", func(t *testing.T) {
err = obj.Verify()
require.NoError(t, err)
})
pkh := Header{Value: &Header_PublicKey{&PublicKey{
Value: crypto.MarshalPublicKey(&key.PublicKey),
}}}
// replace vh with pkh
obj.Headers[len(obj.Headers)-2] = pkh
// re-sign object
obj.Sign(sessionkey)
t.Run("incorrect with bad public key", func(t *testing.T) {
err = obj.Verify()
require.Error(t, err)
})
obj.SetHeader(&Header{Value: &Header_PublicKey{&PublicKey{
Value: dataPK,
}}})
obj.Sign(sessionkey)
t.Run("correct with good public key", func(t *testing.T) {
err = obj.Verify()
require.NoError(t, err)
})
}