From 5844f56f6d08a76f8a33a661db169ecddfb638ab Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 14:31:09 +0300 Subject: [PATCH 1/9] [api] removed old json api added key store Get --- api/api.go | 5 +- api/device/api.go | 153 --------------- api/device/api_test.go | 118 ----------- api/device/rpc/contacts.go | 15 -- api/device/rpc/main.go | 12 -- api/device/state.go | 62 ------ api/device/state_test.go | 32 --- api/dr_key_store.go | 99 ++++++++++ .../dr_key_store_test.go | 2 +- api/pb/request.pb.go | 83 ++++++-- api/pb/request.proto | 9 +- api/pb/response.pb.go | 79 ++++++-- api/pb/response.proto | 6 + client/client_key_store.go | 184 ------------------ 14 files changed, 255 insertions(+), 604 deletions(-) delete mode 100644 api/device/api.go delete mode 100644 api/device/api_test.go delete mode 100644 api/device/rpc/contacts.go delete mode 100644 api/device/rpc/main.go delete mode 100644 api/device/state.go delete mode 100644 api/device/state_test.go create mode 100644 api/dr_key_store.go rename client/client_key_store_test.go => api/dr_key_store_test.go (99%) delete mode 100644 client/client_key_store.go diff --git a/api/api.go b/api/api.go index f36c38f..22565d2 100644 --- a/api/api.go +++ b/api/api.go @@ -125,7 +125,10 @@ func (a *API) request(req *pb.Request, timeOut time.Duration) (*Response, error) // or time out select { case res := <-reqChan: - return res, nil + if res.Error != nil { + res.Closer <- nil + } + return res, res.Error case <-time.After(timeOut): // remove request from stack _, err := a.cutRequest(requestId.String()) diff --git a/api/device/api.go b/api/device/api.go deleted file mode 100644 index b833503..0000000 --- a/api/device/api.go +++ /dev/null @@ -1,153 +0,0 @@ -package device_api - -import ( - "encoding/json" - "errors" - - "fmt" - "github.com/Bit-Nation/panthalassa/api/device/rpc" - log "github.com/ipfs/go-log" -) - -var logger = log.Logger("device_api") - -type UpStream interface { - //Send data to client - Send(data string) -} - -type ApiCall struct { - Type string `json:"type"` - Id string `json:"id"` - Data string `json:"data"` -} - -func (c *ApiCall) Marshal() ([]byte, error) { - return json.Marshal(c) -} - -func UnmarshalApiCall(call string) (ApiCall, error) { - - var apiCall ApiCall - - err := json.Unmarshal([]byte(call), &apiCall) - - return apiCall, err -} - -type rawResponse struct { - Error string `json:"error"` - Payload string `json:"payload"` -} - -type Response struct { - Error error - Payload string - Closer chan error -} - -func (r *Response) Close(err error) { - r.Closer <- err -} - -type Api struct { - device UpStream - state *State -} - -func New(deviceInterface UpStream) *Api { - - api := Api{ - state: newState(), - device: deviceInterface, - } - - return &api -} - -//Send a call to the api -func (a *Api) Send(call rpc.JsonRPCCall) (<-chan Response, error) { - - //Validate call - if err := call.Valid(); err != nil { - return nil, err - } - - //Get call data - callContent, err := call.Data() - if err != nil { - return nil, err - } - - //Create internal representation - c := ApiCall{ - Type: call.Type(), - Data: callContent, - } - respChan := make(chan Response, 1) - c.Id, err = a.state.Add(respChan) - if err != nil { - return nil, err - } - - //Marshal the call data - callData, err := c.Marshal() - if err != nil { - return nil, err - } - - //Send json rpc call to device - // @todo maybe it's worth making this sync and let the caller decide - // @todo if they want to wait till the data has been send - go a.device.Send(string(callData)) - - return respChan, nil - -} - -// @todo at the moment the fetched response channel will never close in case there we return earlier with an error -func (a *Api) Receive(id string, data string) error { - - logger.Debug(fmt.Sprintf("Got response for request (%s) - with data: %s", id, data)) - - // get the response channel - resp, err := a.state.Cut(id) - - if err != nil { - // only try to send a response if a channel exist - if resp != nil { - resp <- Response{Error: err} - } - return err - } - - // closer - closer := make(chan error) - - // decode raw response - var rr rawResponse - if err := json.Unmarshal([]byte(data), &rr); err != nil { - resp <- Response{ - Error: err, - } - return err - } - - // construct response - r := Response{ - Error: err, - Payload: rr.Payload, - Closer: closer, - } - if rr.Error != "" { - r.Error = errors.New(rr.Error) - } - - // send response to response channel - resp <- r - - logger.Debug("send response", r) - - return <-closer - -} diff --git a/api/device/api_test.go b/api/device/api_test.go deleted file mode 100644 index c2e3275..0000000 --- a/api/device/api_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package device_api - -import ( - "encoding/json" - "errors" - "fmt" - "testing" - - require "github.com/stretchr/testify/require" -) - -type upStreamTest struct { - send func(string) -} - -func (u *upStreamTest) Send(data string) { - u.send(data) -} - -type testRPCCall struct { - callType string - data string - dataError error - valid func(data string) error -} - -func (c *testRPCCall) Type() string { - return c.callType -} -func (c *testRPCCall) Data() (string, error) { - return c.data, c.dataError -} -func (c *testRPCCall) Valid() error { - return c.valid(c.data) -} - -func TestSuccess(t *testing.T) { - - //The api call we got from the send function - var receivedApiCall ApiCall - - // this is the sample response - const data = `{"error":"","payload":"my_data"}` - - // for internal use - c := make(chan struct{}, 1) - - //Create up stream test implementation - upStream := upStreamTest{ - // this method is implemented by the client - // and called in an async way. - send: func(data string) { - // we set receivedApiCall to the call in order to use it later in the test - var call ApiCall - require.Nil(t, json.Unmarshal([]byte(data), &call)) - receivedApiCall = call - c <- struct{}{} - }, - } - - //Create api - api := New(&upStream) - - //Send api call with test data - respChan, err := api.Send(&testRPCCall{ - callType: "Test", - data: `{"key": "value"}`, - dataError: nil, - valid: func(data string) error { - return nil - }, - }) - - // here we are waiting for the upstream to set "receivedApiCall" to the received call - <-c - - require.Nil(t, err) - require.Equal(t, "Test", receivedApiCall.Type) - require.Equal(t, `{"key": "value"}`, receivedApiCall.Data) - - //Waiting for the response form the api AND we then close it - go func() { - for { - select { - case res := <-respChan: - if res.Payload != "my_data" { - res.Closer <- errors.New(fmt.Sprintf("payload (%s) doesn't match expected payload (%s)", res.Payload, `my_data`)) - return - } - res.Closer <- nil - } - } - }() - - //This assertion will be evaluated then "res.Closer <- nil" will be "done" - //"Receive" will only return after a value was send into the "res.Closer" channel - require.Nil(t, api.Receive(receivedApiCall.Id, data)) - -} - -func TestApi_SendWithMissingRequest(t *testing.T) { - - //Create up stream test implementation - upStream := upStreamTest{ - send: func(data string) { - panic("I am not supposed to be called") - }, - } - - //Create api - api := New(&upStream) - - // send a response to the api with an id that doesn't exist - err := api.Receive("ahdsf3rpoiasdökfj", "") - - require.EqualError(t, err, "a request channel for id ("+"ahdsf3rpoiasdökfj"+") does not exist") - -} diff --git a/api/device/rpc/contacts.go b/api/device/rpc/contacts.go deleted file mode 100644 index 2f7c062..0000000 --- a/api/device/rpc/contacts.go +++ /dev/null @@ -1,15 +0,0 @@ -package rpc - -type ContactListRequest struct{} - -func (f *ContactListRequest) Type() string { - return "CONTACT:LIST" -} - -func (f *ContactListRequest) Data() (string, error) { - return "", nil -} - -func (f *ContactListRequest) Valid() error { - return nil -} diff --git a/api/device/rpc/main.go b/api/device/rpc/main.go deleted file mode 100644 index ae4f558..0000000 --- a/api/device/rpc/main.go +++ /dev/null @@ -1,12 +0,0 @@ -package rpc - -type JsonRPCCall interface { - Type() string - Data() (string, error) - Valid() error -} - -type JsonRPCResponse interface { - Valid() - Close() -} diff --git a/api/device/state.go b/api/device/state.go deleted file mode 100644 index 44795fc..0000000 --- a/api/device/state.go +++ /dev/null @@ -1,62 +0,0 @@ -package device_api - -import ( - "errors" - "fmt" - "sync" - - uuid "github.com/satori/go.uuid" -) - -type State struct { - requests map[string]chan Response - m *sync.Mutex -} - -func newState() *State { - - return &State{ - requests: make(map[string]chan Response), - m: &sync.Mutex{}, - } - -} - -func (s *State) Add(respChan chan Response) (string, error) { - - s.m.Lock() - var id string - //@todo we should have a backup break for the for loop - for { - uid, err := uuid.NewV4() - if err != nil { - return "", err - } - id = uid.String() - - if _, exist := s.requests[id]; !exist { - break - } - } - logger.Debug(fmt.Sprintf("added response channel with id: %s", id)) - s.requests[id] = respChan - s.m.Unlock() - - return id, nil - -} - -//Return's the channel an removes it from the state map -func (s *State) Cut(id string) (chan Response, error) { - - s.m.Lock() - respChan, exist := s.requests[id] - if !exist { - return nil, errors.New(fmt.Sprintf("a request channel for id (%s) does not exist", id)) - } - delete(s.requests, id) - s.m.Unlock() - logger.Debug(fmt.Sprintf("fetched response channel: for id: %s", id)) - return respChan, nil - -} diff --git a/api/device/state_test.go b/api/device/state_test.go deleted file mode 100644 index 5f10385..0000000 --- a/api/device/state_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package device_api - -import ( - "github.com/stretchr/testify/require" - "testing" -) - -func TestState(t *testing.T) { - - s := newState() - - testChan := make(chan Response) - - //Register test channel - id, err := s.Add(testChan) - require.Nil(t, err) - - //Check if successfully registered - s.m.Lock() - require.Equal(t, testChan, s.requests[id]) - s.m.Unlock() - - //Cut should remove the channel from the state and return it - registeredChan, err := s.Cut(id) - require.Nil(t, err) - require.Equal(t, testChan, registeredChan) - - //Cutting a already received channel should as well result in an error - registeredChan, err = s.Cut(id) - require.EqualError(t, err, "a request channel for id ("+id+") does not exist") - -} diff --git a/api/dr_key_store.go b/api/dr_key_store.go new file mode 100644 index 0000000..d7326ef --- /dev/null +++ b/api/dr_key_store.go @@ -0,0 +1,99 @@ +package api + +import ( + "errors" + "time" + + keyManager "github.com/Bit-Nation/panthalassa/keyManager" + dr "github.com/tiabc/doubleratchet" + pb "github.com/Bit-Nation/panthalassa/api/pb" + aes "github.com/Bit-Nation/panthalassa/crypto/aes" +) + +type DoubleRatchetKeyStoreApi struct { + api *API + km *keyManager.KeyManager +} + +// get a key by it's key and msg number +func (s *DoubleRatchetKeyStoreApi) Get(k dr.Key, msgNum uint) (mk dr.Key, ok bool) { + + req := pb.Request{ + DRKeyStoreGet: &pb.Request_DRKeyStoreGet{ + DrKey: k[:], + MessageNumber: uint64(msgNum), + }, + } + + resp, err := s.api.request(&req, time.Second * 8) + if err != nil { + logger.Error(err) + return dr.Key{}, false + } + + ct, err := aes.Unmarshal(resp.Msg.DRKeyStoreGet.MessageKey) + if err != nil { + logger.Error(err) + resp.Closer <- err + return dr.Key{}, false + } + + messageKey, err := s.km.AESDecrypt(ct) + if err != nil { + logger.Error(err) + resp.Closer <- err + return dr.Key{}, false + } + + if len(messageKey) != 32 { + e := errors.New("a decrypted message key must have exactly 32 bytes") + logger.Error(e) + resp.Closer <- e + return dr.Key{}, false + } + + resp.Closer <- nil + + var msgKey dr.Key + copy(msgKey[:], messageKey) + + return msgKey, true + +} + +// save message key (double ratchet key) +func (s *DoubleRatchetKeyStoreApi) Put(k dr.Key, msgNum uint, mk dr.Key) { + + + +} + +func (s *DoubleRatchetKeyStoreApi) DeleteMk(k dr.Key, msgNum uint) { + + + +} + +func (s *DoubleRatchetKeyStoreApi) DeletePk(k dr.Key) { + + +} + +func (s *DoubleRatchetKeyStoreApi) Count(k dr.Key) uint { + + + +} + +func (s *DoubleRatchetKeyStoreApi) All() map[dr.Key]map[uint]dr.Key { + + + +} + +func NewDRKeyStoreApi(api *API, km *keyManager.KeyManager) *DoubleRatchetKeyStoreApi { + return &DoubleRatchetKeyStoreApi{ + api: api, + km: km, + } +} diff --git a/client/client_key_store_test.go b/api/dr_key_store_test.go similarity index 99% rename from client/client_key_store_test.go rename to api/dr_key_store_test.go index 1d2c974..cf50ebd 100644 --- a/client/client_key_store_test.go +++ b/api/dr_key_store_test.go @@ -1,4 +1,4 @@ -package client +package api import ( "encoding/hex" diff --git a/api/pb/request.pb.go b/api/pb/request.pb.go index 41b3ec9..be64ebe 100644 --- a/api/pb/request.pb.go +++ b/api/pb/request.pb.go @@ -19,17 +19,18 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Request struct { - RequestID string `protobuf:"bytes,2,opt,name=requestID" json:"requestID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` + DRKeyStoreGet *Request_DRKeyStoreGet `protobuf:"bytes,2,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_request_ede251829f267d9a, []int{0} + return fileDescriptor_request_2127127062921383, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -56,17 +57,77 @@ func (m *Request) GetRequestID() string { return "" } +func (m *Request) GetDRKeyStoreGet() *Request_DRKeyStoreGet { + if m != nil { + return m.DRKeyStoreGet + } + return nil +} + +type Request_DRKeyStoreGet struct { + DrKey []byte `protobuf:"bytes,1,opt,name=drKey,proto3" json:"drKey,omitempty"` + MessageNumber uint64 `protobuf:"varint,2,opt,name=messageNumber" json:"messageNumber,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request_DRKeyStoreGet) Reset() { *m = Request_DRKeyStoreGet{} } +func (m *Request_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } +func (*Request_DRKeyStoreGet) ProtoMessage() {} +func (*Request_DRKeyStoreGet) Descriptor() ([]byte, []int) { + return fileDescriptor_request_2127127062921383, []int{0, 0} +} +func (m *Request_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request_DRKeyStoreGet.Unmarshal(m, b) +} +func (m *Request_DRKeyStoreGet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request_DRKeyStoreGet.Marshal(b, m, deterministic) +} +func (dst *Request_DRKeyStoreGet) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request_DRKeyStoreGet.Merge(dst, src) +} +func (m *Request_DRKeyStoreGet) XXX_Size() int { + return xxx_messageInfo_Request_DRKeyStoreGet.Size(m) +} +func (m *Request_DRKeyStoreGet) XXX_DiscardUnknown() { + xxx_messageInfo_Request_DRKeyStoreGet.DiscardUnknown(m) +} + +var xxx_messageInfo_Request_DRKeyStoreGet proto.InternalMessageInfo + +func (m *Request_DRKeyStoreGet) GetDrKey() []byte { + if m != nil { + return m.DrKey + } + return nil +} + +func (m *Request_DRKeyStoreGet) GetMessageNumber() uint64 { + if m != nil { + return m.MessageNumber + } + return 0 +} + func init() { proto.RegisterType((*Request)(nil), "api.Request") + proto.RegisterType((*Request_DRKeyStoreGet)(nil), "api.Request.DRKeyStoreGet") } -func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_ede251829f267d9a) } +func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_2127127062921383) } -var fileDescriptor_request_ede251829f267d9a = []byte{ - // 80 bytes of a gzipped FileDescriptorProto +var fileDescriptor_request_2127127062921383 = []byte{ + // 165 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x49, 0x2c, 0xc8, 0xd4, 0x2f, 0x48, 0xd2, 0x2f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, - 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x52, 0xe7, 0x62, 0x0f, 0x82, 0x88, 0x0a, 0xc9, 0x70, 0x71, - 0x42, 0x15, 0x78, 0xba, 0x48, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x06, 0x21, 0x04, 0x92, 0xd8, 0xc0, - 0x9a, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xff, 0x96, 0x28, 0x6f, 0x4c, 0x00, 0x00, 0x00, + 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0xda, 0xc6, 0xc8, 0xc5, 0x1e, 0x04, 0x11, 0x16, 0x92, 0xe1, + 0xe2, 0x84, 0xaa, 0xf0, 0x74, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x08, 0x08, 0x39, + 0x70, 0xf1, 0xa6, 0x04, 0x79, 0xa7, 0x56, 0x06, 0x97, 0xe4, 0x17, 0xa5, 0xba, 0xa7, 0x96, 0x48, + 0x30, 0x29, 0x30, 0x6a, 0x70, 0x1b, 0x49, 0xe9, 0x25, 0x16, 0x64, 0xea, 0x41, 0x8d, 0xd0, 0x73, + 0x41, 0x56, 0x11, 0x84, 0xaa, 0x41, 0xca, 0x9b, 0x8b, 0x17, 0x45, 0x5e, 0x48, 0x84, 0x8b, 0x35, + 0xa5, 0xc8, 0x3b, 0xb5, 0x12, 0x6c, 0x19, 0x4f, 0x10, 0x84, 0x23, 0xa4, 0xc2, 0xc5, 0x9b, 0x9b, + 0x5a, 0x5c, 0x9c, 0x98, 0x9e, 0xea, 0x57, 0x9a, 0x9b, 0x94, 0x5a, 0x04, 0xb6, 0x88, 0x25, 0x08, + 0x55, 0x30, 0x89, 0x0d, 0xec, 0x09, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x25, 0x45, 0x47, + 0x0c, 0xdc, 0x00, 0x00, 0x00, } diff --git a/api/pb/request.proto b/api/pb/request.proto index e590988..31f6e72 100644 --- a/api/pb/request.proto +++ b/api/pb/request.proto @@ -4,6 +4,13 @@ package api; message Request { - string requestID = 2; + string requestID = 1; + + message DRKeyStoreGet { + bytes drKey = 1; + uint64 messageNumber = 2; + } + + DRKeyStoreGet dRKeyStoreGet = 2; } \ No newline at end of file diff --git a/api/pb/response.pb.go b/api/pb/response.pb.go index e755ac3..f679827 100644 --- a/api/pb/response.pb.go +++ b/api/pb/response.pb.go @@ -19,18 +19,19 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Response struct { - RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` - Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"` + DRKeyStoreGet *Response_DRKeyStoreGet `protobuf:"bytes,3,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_response_7403bc5e7bae8b03, []int{0} + return fileDescriptor_response_4423047fe5a6c89d, []int{0} } func (m *Response) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response.Unmarshal(m, b) @@ -64,19 +65,69 @@ func (m *Response) GetError() string { return "" } +func (m *Response) GetDRKeyStoreGet() *Response_DRKeyStoreGet { + if m != nil { + return m.DRKeyStoreGet + } + return nil +} + +type Response_DRKeyStoreGet struct { + MessageKey []byte `protobuf:"bytes,1,opt,name=messageKey,proto3" json:"messageKey,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Response_DRKeyStoreGet) Reset() { *m = Response_DRKeyStoreGet{} } +func (m *Response_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } +func (*Response_DRKeyStoreGet) ProtoMessage() {} +func (*Response_DRKeyStoreGet) Descriptor() ([]byte, []int) { + return fileDescriptor_response_4423047fe5a6c89d, []int{0, 0} +} +func (m *Response_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Response_DRKeyStoreGet.Unmarshal(m, b) +} +func (m *Response_DRKeyStoreGet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Response_DRKeyStoreGet.Marshal(b, m, deterministic) +} +func (dst *Response_DRKeyStoreGet) XXX_Merge(src proto.Message) { + xxx_messageInfo_Response_DRKeyStoreGet.Merge(dst, src) +} +func (m *Response_DRKeyStoreGet) XXX_Size() int { + return xxx_messageInfo_Response_DRKeyStoreGet.Size(m) +} +func (m *Response_DRKeyStoreGet) XXX_DiscardUnknown() { + xxx_messageInfo_Response_DRKeyStoreGet.DiscardUnknown(m) +} + +var xxx_messageInfo_Response_DRKeyStoreGet proto.InternalMessageInfo + +func (m *Response_DRKeyStoreGet) GetMessageKey() []byte { + if m != nil { + return m.MessageKey + } + return nil +} + func init() { proto.RegisterType((*Response)(nil), "api.Response") + proto.RegisterType((*Response_DRKeyStoreGet)(nil), "api.Response.DRKeyStoreGet") } -func init() { proto.RegisterFile("api/pb/response.proto", fileDescriptor_response_7403bc5e7bae8b03) } +func init() { proto.RegisterFile("api/pb/response.proto", fileDescriptor_response_4423047fe5a6c89d) } -var fileDescriptor_response_7403bc5e7bae8b03 = []byte{ - // 101 bytes of a gzipped FileDescriptorProto +var fileDescriptor_response_4423047fe5a6c89d = []byte{ + // 167 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4d, 0x2c, 0xc8, 0xd4, 0x2f, 0x48, 0xd2, 0x2f, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0xb2, 0xe3, 0xe2, 0x08, 0x82, 0x0a, 0x0b, 0xc9, 0x70, - 0x71, 0x16, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x78, 0xba, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, - 0x06, 0x21, 0x04, 0x84, 0x44, 0xb8, 0x58, 0x53, 0x8b, 0x8a, 0xf2, 0x8b, 0x24, 0x98, 0xc0, 0x32, - 0x10, 0x4e, 0x12, 0x1b, 0xd8, 0x2c, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x26, 0xe3, 0x38, - 0x5a, 0x64, 0x00, 0x00, 0x00, + 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0xda, 0xc4, 0xc8, 0xc5, 0x11, 0x04, 0x15, 0x17, 0x92, + 0xe1, 0xe2, 0x2c, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xf1, 0x74, 0x91, 0x60, 0x54, 0x60, 0xd4, + 0xe0, 0x0c, 0x42, 0x08, 0x08, 0x89, 0x70, 0xb1, 0xa6, 0x16, 0x15, 0xe5, 0x17, 0x49, 0x30, 0x81, + 0x65, 0x20, 0x1c, 0x21, 0x47, 0x2e, 0xde, 0x94, 0x20, 0xef, 0xd4, 0xca, 0xe0, 0x92, 0xfc, 0xa2, + 0x54, 0xf7, 0xd4, 0x12, 0x09, 0x66, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x69, 0xbd, 0xc4, 0x82, 0x4c, + 0x3d, 0x98, 0xc9, 0x7a, 0x2e, 0xc8, 0x4a, 0x82, 0x50, 0x75, 0x48, 0xe9, 0x73, 0xf1, 0xa2, 0xc8, + 0x0b, 0xc9, 0x71, 0x71, 0xe5, 0xa6, 0x16, 0x17, 0x27, 0xa6, 0xa7, 0x7a, 0xa7, 0x56, 0x82, 0x1d, + 0xc2, 0x13, 0x84, 0x24, 0x92, 0xc4, 0x06, 0xf6, 0x80, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xec, + 0x47, 0x3d, 0xfe, 0xd9, 0x00, 0x00, 0x00, } diff --git a/api/pb/response.proto b/api/pb/response.proto index f6afaae..1f7c27f 100644 --- a/api/pb/response.proto +++ b/api/pb/response.proto @@ -7,4 +7,10 @@ message Response { string requestID = 1; string error = 2; + message DRKeyStoreGet { + bytes messageKey = 1; + } + + DRKeyStoreGet dRKeyStoreGet = 3; + } \ No newline at end of file diff --git a/client/client_key_store.go b/client/client_key_store.go deleted file mode 100644 index bf998f8..0000000 --- a/client/client_key_store.go +++ /dev/null @@ -1,184 +0,0 @@ -package client - -import ( - "encoding/hex" - "encoding/json" - - deviceApi "github.com/Bit-Nation/panthalassa/api/device" - keyManager "github.com/Bit-Nation/panthalassa/keyManager" - log "github.com/ipfs/go-log" - dr "github.com/tiabc/doubleratchet" -) - -var logger = log.Logger("client - double ratchet key") - -type DoubleRatchetKeyStore struct { - api *deviceApi.Api - km *keyManager.KeyManager -} - -// get a key by it's key and msg number -func (s *DoubleRatchetKeyStore) Get(k dr.Key, msgNum uint) (mk dr.Key, ok bool) { - - respCha, err := s.api.Send(&DRKeyStoreGetCall{ - Key: hex.EncodeToString(k[:]), - MsgNum: msgNum, - }) - - if err != nil { - return dr.Key{}, false - } - - resp := <-respCha - - if resp.Error != nil { - resp.Close(nil) - return dr.Key{}, false - } - - keyResp, err := UnmarshalDRKeyStoreGetResponse(resp.Payload, s.km) - if err != nil { - resp.Close(err) - return keyResp.Key, false - } - - resp.Close(nil) - return keyResp.Key, keyResp.Ok - -} - -// save message key (double ratchet key) -func (s *DoubleRatchetKeyStore) Put(k dr.Key, msgNum uint, mk dr.Key) { - - // encrypt message key - ct, err := s.km.AESEncrypt(mk[:]) - if err != nil { - logger.Error(err) - } - - // send request to device api - respChan, err := s.api.Send(&DRKeyStorePutCall{ - IndexKey: hex.EncodeToString(k[:]), - MsgNumber: msgNum, - DoubleRatchetKey: ct, - }) - if err != nil { - logger.Error(err) - return - } - - // wait for response and close it since we don't need it somewhere else - resp := <-respChan - resp.Close(nil) - - if resp.Error != nil { - logger.Error(resp.Error) - } - -} - -func (s *DoubleRatchetKeyStore) DeleteMk(k dr.Key, msgNum uint) { - - respCha, err := s.api.Send(&DRKeyStoreDeleteMK{ - IndexKey: hex.EncodeToString(k[:]), - MsgNumber: msgNum, - }) - if err != nil { - logger.Error(err) - return - } - - resp := <-respCha - resp.Close(nil) - - if resp.Error != nil { - logger.Error(resp.Error) - } - -} - -func (s *DoubleRatchetKeyStore) DeletePk(k dr.Key) { - - respCha, err := s.api.Send(&DRKeyStoreDeleteIndexKey{ - IndexKey: hex.EncodeToString(k[:]), - }) - if err != nil { - logger.Error(err) - return - } - - resp := <-respCha - resp.Close(nil) - - if resp.Error != nil { - logger.Error(resp.Error) - } - -} - -func (s *DoubleRatchetKeyStore) Count(k dr.Key) uint { - - respCha, err := s.api.Send(&DRKeyStoreCountCall{ - IndexKey: hex.EncodeToString(k[:]), - }) - if err != nil { - logger.Error(err) - return 0 - } - - resp := <-respCha - - // exit on error - if resp.Error != nil { - resp.Close(nil) - logger.Error(resp.Error) - return 0 - } - - // unmarshal payload - var respStr = struct { - Count uint `json:"count"` - }{} - if err := json.Unmarshal([]byte(resp.Payload), &respStr); err != nil { - resp.Close(err) - logger.Error(err) - return 0 - } - resp.Close(nil) - return respStr.Count - -} - -func (s *DoubleRatchetKeyStore) All() map[dr.Key]map[uint]dr.Key { - - respCha, err := s.api.Send(&DRKeyStoreFetchAllKeys{}) - - if err != nil { - logger.Error(err) - return map[dr.Key]map[uint]dr.Key{} - } - - resp := <-respCha - if resp.Error != nil { - logger.Error(resp.Error) - resp.Close(nil) - return map[dr.Key]map[uint]dr.Key{} - } - - keys, err := UnmarshalFetchAllKeysPayload(resp.Payload, s.km) - if err != nil { - resp.Close(err) - logger.Error(err) - return map[dr.Key]map[uint]dr.Key{} - } - - return keys - -} - -func New(api *deviceApi.Api, km *keyManager.KeyManager) *DoubleRatchetKeyStore { - return &DoubleRatchetKeyStore{ - api: api, - km: km, - } -} From 91b97f7229994788df24486fd9f1d90e93e14fb4 Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 14:38:41 +0300 Subject: [PATCH 2/9] [api] key store api - added put request --- api/dr_key_store.go | 27 +++++++++++++- api/pb/request.pb.go | 88 ++++++++++++++++++++++++++++++++++++++------ api/pb/request.proto | 7 ++++ 3 files changed, 110 insertions(+), 12 deletions(-) diff --git a/api/dr_key_store.go b/api/dr_key_store.go index d7326ef..ec51b92 100644 --- a/api/dr_key_store.go +++ b/api/dr_key_store.go @@ -64,7 +64,32 @@ func (s *DoubleRatchetKeyStoreApi) Get(k dr.Key, msgNum uint) (mk dr.Key, ok boo // save message key (double ratchet key) func (s *DoubleRatchetKeyStoreApi) Put(k dr.Key, msgNum uint, mk dr.Key) { - + ct, err := s.km.AESEncrypt(mk[:]) + if err != nil { + logger.Error(err) + return + } + + rawCt, err := ct.Marshal() + if err != nil { + logger.Error(err) + return + } + + resp, err := s.api.request(&pb.Request{ + DRKeyStorePut: &pb.Request_DRKeyStorePut{ + MessageKey: k[:], + MessageNumber: uint64(msgNum), + Key: rawCt, + }, + }, time.Second * 8) + + if err != nil { + logger.Error(err) + return + } + + resp.Closer <- nil } diff --git a/api/pb/request.pb.go b/api/pb/request.pb.go index be64ebe..74a00dd 100644 --- a/api/pb/request.pb.go +++ b/api/pb/request.pb.go @@ -21,6 +21,7 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Request struct { RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` DRKeyStoreGet *Request_DRKeyStoreGet `protobuf:"bytes,2,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` + DRKeyStorePut *Request_DRKeyStorePut `protobuf:"bytes,3,opt,name=dRKeyStorePut" json:"dRKeyStorePut,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -30,7 +31,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_request_2127127062921383, []int{0} + return fileDescriptor_request_0ee5a049207ecabb, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -64,6 +65,13 @@ func (m *Request) GetDRKeyStoreGet() *Request_DRKeyStoreGet { return nil } +func (m *Request) GetDRKeyStorePut() *Request_DRKeyStorePut { + if m != nil { + return m.DRKeyStorePut + } + return nil +} + type Request_DRKeyStoreGet struct { DrKey []byte `protobuf:"bytes,1,opt,name=drKey,proto3" json:"drKey,omitempty"` MessageNumber uint64 `protobuf:"varint,2,opt,name=messageNumber" json:"messageNumber,omitempty"` @@ -76,7 +84,7 @@ func (m *Request_DRKeyStoreGet) Reset() { *m = Request_DRKeyStoreGet{} } func (m *Request_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreGet) ProtoMessage() {} func (*Request_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_request_2127127062921383, []int{0, 0} + return fileDescriptor_request_0ee5a049207ecabb, []int{0, 0} } func (m *Request_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreGet.Unmarshal(m, b) @@ -110,24 +118,82 @@ func (m *Request_DRKeyStoreGet) GetMessageNumber() uint64 { return 0 } +type Request_DRKeyStorePut struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + MessageNumber uint64 `protobuf:"varint,2,opt,name=messageNumber" json:"messageNumber,omitempty"` + MessageKey []byte `protobuf:"bytes,3,opt,name=messageKey,proto3" json:"messageKey,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request_DRKeyStorePut) Reset() { *m = Request_DRKeyStorePut{} } +func (m *Request_DRKeyStorePut) String() string { return proto.CompactTextString(m) } +func (*Request_DRKeyStorePut) ProtoMessage() {} +func (*Request_DRKeyStorePut) Descriptor() ([]byte, []int) { + return fileDescriptor_request_0ee5a049207ecabb, []int{0, 1} +} +func (m *Request_DRKeyStorePut) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request_DRKeyStorePut.Unmarshal(m, b) +} +func (m *Request_DRKeyStorePut) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request_DRKeyStorePut.Marshal(b, m, deterministic) +} +func (dst *Request_DRKeyStorePut) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request_DRKeyStorePut.Merge(dst, src) +} +func (m *Request_DRKeyStorePut) XXX_Size() int { + return xxx_messageInfo_Request_DRKeyStorePut.Size(m) +} +func (m *Request_DRKeyStorePut) XXX_DiscardUnknown() { + xxx_messageInfo_Request_DRKeyStorePut.DiscardUnknown(m) +} + +var xxx_messageInfo_Request_DRKeyStorePut proto.InternalMessageInfo + +func (m *Request_DRKeyStorePut) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func (m *Request_DRKeyStorePut) GetMessageNumber() uint64 { + if m != nil { + return m.MessageNumber + } + return 0 +} + +func (m *Request_DRKeyStorePut) GetMessageKey() []byte { + if m != nil { + return m.MessageKey + } + return nil +} + func init() { proto.RegisterType((*Request)(nil), "api.Request") proto.RegisterType((*Request_DRKeyStoreGet)(nil), "api.Request.DRKeyStoreGet") + proto.RegisterType((*Request_DRKeyStorePut)(nil), "api.Request.DRKeyStorePut") } -func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_2127127062921383) } +func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_0ee5a049207ecabb) } -var fileDescriptor_request_2127127062921383 = []byte{ - // 165 bytes of a gzipped FileDescriptorProto +var fileDescriptor_request_0ee5a049207ecabb = []byte{ + // 214 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x49, 0x2c, 0xc8, 0xd4, 0x2f, 0x48, 0xd2, 0x2f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, - 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0xda, 0xc6, 0xc8, 0xc5, 0x1e, 0x04, 0x11, 0x16, 0x92, 0xe1, + 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x7a, 0xc8, 0xc4, 0xc5, 0x1e, 0x04, 0x11, 0x16, 0x92, 0xe1, 0xe2, 0x84, 0xaa, 0xf0, 0x74, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x08, 0x08, 0x39, 0x70, 0xf1, 0xa6, 0x04, 0x79, 0xa7, 0x56, 0x06, 0x97, 0xe4, 0x17, 0xa5, 0xba, 0xa7, 0x96, 0x48, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x1b, 0x49, 0xe9, 0x25, 0x16, 0x64, 0xea, 0x41, 0x8d, 0xd0, 0x73, - 0x41, 0x56, 0x11, 0x84, 0xaa, 0x41, 0xca, 0x9b, 0x8b, 0x17, 0x45, 0x5e, 0x48, 0x84, 0x8b, 0x35, - 0xa5, 0xc8, 0x3b, 0xb5, 0x12, 0x6c, 0x19, 0x4f, 0x10, 0x84, 0x23, 0xa4, 0xc2, 0xc5, 0x9b, 0x9b, - 0x5a, 0x5c, 0x9c, 0x98, 0x9e, 0xea, 0x57, 0x9a, 0x9b, 0x94, 0x5a, 0x04, 0xb6, 0x88, 0x25, 0x08, - 0x55, 0x30, 0x89, 0x0d, 0xec, 0x09, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x25, 0x45, 0x47, - 0x0c, 0xdc, 0x00, 0x00, 0x00, + 0x41, 0x56, 0x11, 0x84, 0xaa, 0x01, 0xd5, 0x84, 0x80, 0xd2, 0x12, 0x09, 0x66, 0xbc, 0x26, 0x04, + 0x94, 0xa2, 0x98, 0x10, 0x50, 0x5a, 0x22, 0xe5, 0xcd, 0xc5, 0x8b, 0x62, 0x83, 0x90, 0x08, 0x17, + 0x6b, 0x4a, 0x91, 0x77, 0x6a, 0x25, 0xd8, 0xb9, 0x3c, 0x41, 0x10, 0x8e, 0x90, 0x0a, 0x17, 0x6f, + 0x6e, 0x6a, 0x71, 0x71, 0x62, 0x7a, 0xaa, 0x5f, 0x69, 0x6e, 0x52, 0x6a, 0x11, 0xd8, 0xa9, 0x2c, + 0x41, 0xa8, 0x82, 0x52, 0xe9, 0xc8, 0x86, 0x05, 0x94, 0x96, 0x08, 0x09, 0x70, 0x31, 0x67, 0xc3, + 0x8d, 0x02, 0x31, 0x89, 0x33, 0x48, 0x48, 0x8e, 0x8b, 0x0b, 0x2a, 0x00, 0x72, 0x09, 0x33, 0x58, + 0x3b, 0x92, 0x48, 0x12, 0x1b, 0x38, 0xbc, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x6b, 0xad, + 0x48, 0x10, 0x87, 0x01, 0x00, 0x00, } diff --git a/api/pb/request.proto b/api/pb/request.proto index 31f6e72..c969325 100644 --- a/api/pb/request.proto +++ b/api/pb/request.proto @@ -11,6 +11,13 @@ message Request { uint64 messageNumber = 2; } + message DRKeyStorePut { + bytes key = 1; + uint64 messageNumber = 2; + bytes messageKey = 3; + } + DRKeyStoreGet dRKeyStoreGet = 2; + DRKeyStorePut dRKeyStorePut = 3; } \ No newline at end of file From e277912c72ebd7f7dd6c88579954a0eca3b61af4 Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 14:56:13 +0300 Subject: [PATCH 3/9] [api] key store - delete message key --- api/dr_key_store.go | 16 ++++++- api/pb/request.pb.go | 112 ++++++++++++++++++++++++++++++++----------- api/pb/request.proto | 6 +++ 3 files changed, 105 insertions(+), 29 deletions(-) diff --git a/api/dr_key_store.go b/api/dr_key_store.go index ec51b92..e65303c 100644 --- a/api/dr_key_store.go +++ b/api/dr_key_store.go @@ -94,8 +94,20 @@ func (s *DoubleRatchetKeyStoreApi) Put(k dr.Key, msgNum uint, mk dr.Key) { } func (s *DoubleRatchetKeyStoreApi) DeleteMk(k dr.Key, msgNum uint) { - - + + resp, err := s.api.request(&pb.Request{ + DRKeyStoreDeleteMK: &pb.Request_DRKeyStoreDeleteMK{ + Key: k[:], + MsgNum: uint64(msgNum), + }, + }, time.Second * 8) + + if err != nil { + logger.Error(err) + return + } + + resp.Closer <- nil } diff --git a/api/pb/request.pb.go b/api/pb/request.pb.go index 74a00dd..1ca3475 100644 --- a/api/pb/request.pb.go +++ b/api/pb/request.pb.go @@ -19,19 +19,20 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Request struct { - RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` - DRKeyStoreGet *Request_DRKeyStoreGet `protobuf:"bytes,2,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` - DRKeyStorePut *Request_DRKeyStorePut `protobuf:"bytes,3,opt,name=dRKeyStorePut" json:"dRKeyStorePut,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` + DRKeyStoreGet *Request_DRKeyStoreGet `protobuf:"bytes,2,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` + DRKeyStorePut *Request_DRKeyStorePut `protobuf:"bytes,3,opt,name=dRKeyStorePut" json:"dRKeyStorePut,omitempty"` + DRKeyStoreDeleteMK *Request_DRKeyStoreDeleteMK `protobuf:"bytes,4,opt,name=dRKeyStoreDeleteMK" json:"dRKeyStoreDeleteMK,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_request_0ee5a049207ecabb, []int{0} + return fileDescriptor_request_91f0a006ebf754d3, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -72,6 +73,13 @@ func (m *Request) GetDRKeyStorePut() *Request_DRKeyStorePut { return nil } +func (m *Request) GetDRKeyStoreDeleteMK() *Request_DRKeyStoreDeleteMK { + if m != nil { + return m.DRKeyStoreDeleteMK + } + return nil +} + type Request_DRKeyStoreGet struct { DrKey []byte `protobuf:"bytes,1,opt,name=drKey,proto3" json:"drKey,omitempty"` MessageNumber uint64 `protobuf:"varint,2,opt,name=messageNumber" json:"messageNumber,omitempty"` @@ -84,7 +92,7 @@ func (m *Request_DRKeyStoreGet) Reset() { *m = Request_DRKeyStoreGet{} } func (m *Request_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreGet) ProtoMessage() {} func (*Request_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_request_0ee5a049207ecabb, []int{0, 0} + return fileDescriptor_request_91f0a006ebf754d3, []int{0, 0} } func (m *Request_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreGet.Unmarshal(m, b) @@ -131,7 +139,7 @@ func (m *Request_DRKeyStorePut) Reset() { *m = Request_DRKeyStorePut{} } func (m *Request_DRKeyStorePut) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStorePut) ProtoMessage() {} func (*Request_DRKeyStorePut) Descriptor() ([]byte, []int) { - return fileDescriptor_request_0ee5a049207ecabb, []int{0, 1} + return fileDescriptor_request_91f0a006ebf754d3, []int{0, 1} } func (m *Request_DRKeyStorePut) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStorePut.Unmarshal(m, b) @@ -172,28 +180,78 @@ func (m *Request_DRKeyStorePut) GetMessageKey() []byte { return nil } +type Request_DRKeyStoreDeleteMK struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + MsgNum uint64 `protobuf:"varint,2,opt,name=msgNum" json:"msgNum,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request_DRKeyStoreDeleteMK) Reset() { *m = Request_DRKeyStoreDeleteMK{} } +func (m *Request_DRKeyStoreDeleteMK) String() string { return proto.CompactTextString(m) } +func (*Request_DRKeyStoreDeleteMK) ProtoMessage() {} +func (*Request_DRKeyStoreDeleteMK) Descriptor() ([]byte, []int) { + return fileDescriptor_request_91f0a006ebf754d3, []int{0, 2} +} +func (m *Request_DRKeyStoreDeleteMK) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request_DRKeyStoreDeleteMK.Unmarshal(m, b) +} +func (m *Request_DRKeyStoreDeleteMK) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request_DRKeyStoreDeleteMK.Marshal(b, m, deterministic) +} +func (dst *Request_DRKeyStoreDeleteMK) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request_DRKeyStoreDeleteMK.Merge(dst, src) +} +func (m *Request_DRKeyStoreDeleteMK) XXX_Size() int { + return xxx_messageInfo_Request_DRKeyStoreDeleteMK.Size(m) +} +func (m *Request_DRKeyStoreDeleteMK) XXX_DiscardUnknown() { + xxx_messageInfo_Request_DRKeyStoreDeleteMK.DiscardUnknown(m) +} + +var xxx_messageInfo_Request_DRKeyStoreDeleteMK proto.InternalMessageInfo + +func (m *Request_DRKeyStoreDeleteMK) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func (m *Request_DRKeyStoreDeleteMK) GetMsgNum() uint64 { + if m != nil { + return m.MsgNum + } + return 0 +} + func init() { proto.RegisterType((*Request)(nil), "api.Request") proto.RegisterType((*Request_DRKeyStoreGet)(nil), "api.Request.DRKeyStoreGet") proto.RegisterType((*Request_DRKeyStorePut)(nil), "api.Request.DRKeyStorePut") + proto.RegisterType((*Request_DRKeyStoreDeleteMK)(nil), "api.Request.DRKeyStoreDeleteMK") } -func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_0ee5a049207ecabb) } - -var fileDescriptor_request_0ee5a049207ecabb = []byte{ - // 214 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x49, 0x2c, 0xc8, 0xd4, - 0x2f, 0x48, 0xd2, 0x2f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, - 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x7a, 0xc8, 0xc4, 0xc5, 0x1e, 0x04, 0x11, 0x16, 0x92, 0xe1, - 0xe2, 0x84, 0xaa, 0xf0, 0x74, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x08, 0x08, 0x39, - 0x70, 0xf1, 0xa6, 0x04, 0x79, 0xa7, 0x56, 0x06, 0x97, 0xe4, 0x17, 0xa5, 0xba, 0xa7, 0x96, 0x48, - 0x30, 0x29, 0x30, 0x6a, 0x70, 0x1b, 0x49, 0xe9, 0x25, 0x16, 0x64, 0xea, 0x41, 0x8d, 0xd0, 0x73, - 0x41, 0x56, 0x11, 0x84, 0xaa, 0x01, 0xd5, 0x84, 0x80, 0xd2, 0x12, 0x09, 0x66, 0xbc, 0x26, 0x04, - 0x94, 0xa2, 0x98, 0x10, 0x50, 0x5a, 0x22, 0xe5, 0xcd, 0xc5, 0x8b, 0x62, 0x83, 0x90, 0x08, 0x17, - 0x6b, 0x4a, 0x91, 0x77, 0x6a, 0x25, 0xd8, 0xb9, 0x3c, 0x41, 0x10, 0x8e, 0x90, 0x0a, 0x17, 0x6f, - 0x6e, 0x6a, 0x71, 0x71, 0x62, 0x7a, 0xaa, 0x5f, 0x69, 0x6e, 0x52, 0x6a, 0x11, 0xd8, 0xa9, 0x2c, - 0x41, 0xa8, 0x82, 0x52, 0xe9, 0xc8, 0x86, 0x05, 0x94, 0x96, 0x08, 0x09, 0x70, 0x31, 0x67, 0xc3, - 0x8d, 0x02, 0x31, 0x89, 0x33, 0x48, 0x48, 0x8e, 0x8b, 0x0b, 0x2a, 0x00, 0x72, 0x09, 0x33, 0x58, - 0x3b, 0x92, 0x48, 0x12, 0x1b, 0x38, 0xbc, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x6b, 0xad, - 0x48, 0x10, 0x87, 0x01, 0x00, 0x00, +func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_91f0a006ebf754d3) } + +var fileDescriptor_request_91f0a006ebf754d3 = []byte{ + // 259 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x4a, 0xc3, 0x40, + 0x10, 0x87, 0x89, 0x5b, 0x2b, 0x1d, 0x0d, 0xc8, 0x50, 0x24, 0x04, 0xd1, 0x22, 0x1e, 0x7a, 0x4a, + 0x41, 0xef, 0xe2, 0x21, 0x20, 0x12, 0xac, 0x61, 0x7d, 0x82, 0x84, 0x0e, 0x21, 0xe8, 0x92, 0x75, + 0xff, 0x1c, 0xfa, 0xda, 0x3e, 0x81, 0x64, 0xbb, 0xda, 0x2c, 0x46, 0xf1, 0xb6, 0xf3, 0x31, 0xf3, + 0xcd, 0xfc, 0x60, 0x61, 0x5e, 0xc9, 0x76, 0x25, 0xeb, 0x95, 0xa2, 0x77, 0x4b, 0xda, 0x64, 0x52, + 0x75, 0xa6, 0x43, 0x56, 0xc9, 0xf6, 0xea, 0x83, 0xc1, 0x11, 0xdf, 0x61, 0x3c, 0x87, 0x99, 0xef, + 0x78, 0xcc, 0x93, 0x68, 0x11, 0x2d, 0x67, 0x7c, 0x0f, 0xf0, 0x1e, 0xe2, 0x0d, 0x2f, 0x68, 0xfb, + 0x62, 0x3a, 0x45, 0x0f, 0x64, 0x92, 0x83, 0x45, 0xb4, 0x3c, 0xbe, 0x49, 0xb3, 0x4a, 0xb6, 0x99, + 0x57, 0x64, 0xf9, 0xb0, 0x83, 0x87, 0x03, 0xa1, 0xa1, 0xb4, 0x26, 0x61, 0x7f, 0x1a, 0x4a, 0x1b, + 0x18, 0x4a, 0x6b, 0xf0, 0x19, 0x70, 0x0f, 0x72, 0x7a, 0x23, 0x43, 0x4f, 0x45, 0x32, 0x71, 0x9a, + 0xcb, 0x5f, 0x34, 0x5f, 0x6d, 0x7c, 0x64, 0x34, 0x2d, 0x20, 0x0e, 0x4e, 0xc6, 0x39, 0x1c, 0x6e, + 0x54, 0x41, 0x5b, 0x97, 0xff, 0x84, 0xef, 0x0a, 0xbc, 0x86, 0x58, 0x90, 0xd6, 0x55, 0x43, 0x6b, + 0x2b, 0x6a, 0x52, 0x2e, 0xfb, 0x84, 0x87, 0x30, 0x6d, 0x86, 0xb2, 0xfe, 0xdc, 0x53, 0x60, 0xaf, + 0xdf, 0xaa, 0xfe, 0xf9, 0x3f, 0x11, 0x5e, 0x00, 0x78, 0xd0, 0x5f, 0xc2, 0xdc, 0xf8, 0x80, 0xa4, + 0x77, 0x80, 0x3f, 0xf3, 0x8d, 0x6c, 0x3b, 0x83, 0xa9, 0xd0, 0xcd, 0xda, 0x0a, 0xbf, 0xc6, 0x57, + 0xf5, 0xd4, 0x7d, 0x80, 0xdb, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc5, 0xc9, 0x5c, 0x7a, 0x18, + 0x02, 0x00, 0x00, } diff --git a/api/pb/request.proto b/api/pb/request.proto index c969325..82409df 100644 --- a/api/pb/request.proto +++ b/api/pb/request.proto @@ -17,7 +17,13 @@ message Request { bytes messageKey = 3; } + message DRKeyStoreDeleteMK { + bytes key = 1; + uint64 msgNum = 2; + } + DRKeyStoreGet dRKeyStoreGet = 2; DRKeyStorePut dRKeyStorePut = 3; + DRKeyStoreDeleteMK dRKeyStoreDeleteMK = 4; } \ No newline at end of file From 1f96458c9d7dfde756f346619b500e41ff3eb996 Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 15:00:22 +0300 Subject: [PATCH 4/9] [api] key store - delete pk --- api/dr_key_store.go | 14 +++++- api/pb/request.pb.go | 112 ++++++++++++++++++++++++++++++------------- api/pb/request.proto | 5 ++ 3 files changed, 98 insertions(+), 33 deletions(-) diff --git a/api/dr_key_store.go b/api/dr_key_store.go index e65303c..bc56de0 100644 --- a/api/dr_key_store.go +++ b/api/dr_key_store.go @@ -112,7 +112,19 @@ func (s *DoubleRatchetKeyStoreApi) DeleteMk(k dr.Key, msgNum uint) { } func (s *DoubleRatchetKeyStoreApi) DeletePk(k dr.Key) { - + + resp, err := s.api.request(&pb.Request{ + DRKeyStoreDeleteKeys: &pb.Request_DRKeyStoreDeleteKeys{ + Key: k[:], + }, + }, time.Second * 8) + + if err != nil { + logger.Error(err) + return + } + + resp.Closer <- nil } diff --git a/api/pb/request.pb.go b/api/pb/request.pb.go index 1ca3475..2de52a6 100644 --- a/api/pb/request.pb.go +++ b/api/pb/request.pb.go @@ -19,20 +19,21 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Request struct { - RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` - DRKeyStoreGet *Request_DRKeyStoreGet `protobuf:"bytes,2,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` - DRKeyStorePut *Request_DRKeyStorePut `protobuf:"bytes,3,opt,name=dRKeyStorePut" json:"dRKeyStorePut,omitempty"` - DRKeyStoreDeleteMK *Request_DRKeyStoreDeleteMK `protobuf:"bytes,4,opt,name=dRKeyStoreDeleteMK" json:"dRKeyStoreDeleteMK,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` + DRKeyStoreGet *Request_DRKeyStoreGet `protobuf:"bytes,2,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` + DRKeyStorePut *Request_DRKeyStorePut `protobuf:"bytes,3,opt,name=dRKeyStorePut" json:"dRKeyStorePut,omitempty"` + DRKeyStoreDeleteMK *Request_DRKeyStoreDeleteMK `protobuf:"bytes,4,opt,name=dRKeyStoreDeleteMK" json:"dRKeyStoreDeleteMK,omitempty"` + DRKeyStoreDeleteKeys *Request_DRKeyStoreDeleteKeys `protobuf:"bytes,5,opt,name=dRKeyStoreDeleteKeys" json:"dRKeyStoreDeleteKeys,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_request_91f0a006ebf754d3, []int{0} + return fileDescriptor_request_e89cb34cacb448bf, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -80,6 +81,13 @@ func (m *Request) GetDRKeyStoreDeleteMK() *Request_DRKeyStoreDeleteMK { return nil } +func (m *Request) GetDRKeyStoreDeleteKeys() *Request_DRKeyStoreDeleteKeys { + if m != nil { + return m.DRKeyStoreDeleteKeys + } + return nil +} + type Request_DRKeyStoreGet struct { DrKey []byte `protobuf:"bytes,1,opt,name=drKey,proto3" json:"drKey,omitempty"` MessageNumber uint64 `protobuf:"varint,2,opt,name=messageNumber" json:"messageNumber,omitempty"` @@ -92,7 +100,7 @@ func (m *Request_DRKeyStoreGet) Reset() { *m = Request_DRKeyStoreGet{} } func (m *Request_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreGet) ProtoMessage() {} func (*Request_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_request_91f0a006ebf754d3, []int{0, 0} + return fileDescriptor_request_e89cb34cacb448bf, []int{0, 0} } func (m *Request_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreGet.Unmarshal(m, b) @@ -139,7 +147,7 @@ func (m *Request_DRKeyStorePut) Reset() { *m = Request_DRKeyStorePut{} } func (m *Request_DRKeyStorePut) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStorePut) ProtoMessage() {} func (*Request_DRKeyStorePut) Descriptor() ([]byte, []int) { - return fileDescriptor_request_91f0a006ebf754d3, []int{0, 1} + return fileDescriptor_request_e89cb34cacb448bf, []int{0, 1} } func (m *Request_DRKeyStorePut) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStorePut.Unmarshal(m, b) @@ -192,7 +200,7 @@ func (m *Request_DRKeyStoreDeleteMK) Reset() { *m = Request_DRKeyStoreDe func (m *Request_DRKeyStoreDeleteMK) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreDeleteMK) ProtoMessage() {} func (*Request_DRKeyStoreDeleteMK) Descriptor() ([]byte, []int) { - return fileDescriptor_request_91f0a006ebf754d3, []int{0, 2} + return fileDescriptor_request_e89cb34cacb448bf, []int{0, 2} } func (m *Request_DRKeyStoreDeleteMK) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreDeleteMK.Unmarshal(m, b) @@ -226,32 +234,72 @@ func (m *Request_DRKeyStoreDeleteMK) GetMsgNum() uint64 { return 0 } +type Request_DRKeyStoreDeleteKeys struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request_DRKeyStoreDeleteKeys) Reset() { *m = Request_DRKeyStoreDeleteKeys{} } +func (m *Request_DRKeyStoreDeleteKeys) String() string { return proto.CompactTextString(m) } +func (*Request_DRKeyStoreDeleteKeys) ProtoMessage() {} +func (*Request_DRKeyStoreDeleteKeys) Descriptor() ([]byte, []int) { + return fileDescriptor_request_e89cb34cacb448bf, []int{0, 3} +} +func (m *Request_DRKeyStoreDeleteKeys) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request_DRKeyStoreDeleteKeys.Unmarshal(m, b) +} +func (m *Request_DRKeyStoreDeleteKeys) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request_DRKeyStoreDeleteKeys.Marshal(b, m, deterministic) +} +func (dst *Request_DRKeyStoreDeleteKeys) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request_DRKeyStoreDeleteKeys.Merge(dst, src) +} +func (m *Request_DRKeyStoreDeleteKeys) XXX_Size() int { + return xxx_messageInfo_Request_DRKeyStoreDeleteKeys.Size(m) +} +func (m *Request_DRKeyStoreDeleteKeys) XXX_DiscardUnknown() { + xxx_messageInfo_Request_DRKeyStoreDeleteKeys.DiscardUnknown(m) +} + +var xxx_messageInfo_Request_DRKeyStoreDeleteKeys proto.InternalMessageInfo + +func (m *Request_DRKeyStoreDeleteKeys) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + func init() { proto.RegisterType((*Request)(nil), "api.Request") proto.RegisterType((*Request_DRKeyStoreGet)(nil), "api.Request.DRKeyStoreGet") proto.RegisterType((*Request_DRKeyStorePut)(nil), "api.Request.DRKeyStorePut") proto.RegisterType((*Request_DRKeyStoreDeleteMK)(nil), "api.Request.DRKeyStoreDeleteMK") + proto.RegisterType((*Request_DRKeyStoreDeleteKeys)(nil), "api.Request.DRKeyStoreDeleteKeys") } -func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_91f0a006ebf754d3) } - -var fileDescriptor_request_91f0a006ebf754d3 = []byte{ - // 259 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x4a, 0xc3, 0x40, - 0x10, 0x87, 0x89, 0x5b, 0x2b, 0x1d, 0x0d, 0xc8, 0x50, 0x24, 0x04, 0xd1, 0x22, 0x1e, 0x7a, 0x4a, - 0x41, 0xef, 0xe2, 0x21, 0x20, 0x12, 0xac, 0x61, 0x7d, 0x82, 0x84, 0x0e, 0x21, 0xe8, 0x92, 0x75, - 0xff, 0x1c, 0xfa, 0xda, 0x3e, 0x81, 0x64, 0xbb, 0xda, 0x2c, 0x46, 0xf1, 0xb6, 0xf3, 0x31, 0xf3, - 0xcd, 0xfc, 0x60, 0x61, 0x5e, 0xc9, 0x76, 0x25, 0xeb, 0x95, 0xa2, 0x77, 0x4b, 0xda, 0x64, 0x52, - 0x75, 0xa6, 0x43, 0x56, 0xc9, 0xf6, 0xea, 0x83, 0xc1, 0x11, 0xdf, 0x61, 0x3c, 0x87, 0x99, 0xef, - 0x78, 0xcc, 0x93, 0x68, 0x11, 0x2d, 0x67, 0x7c, 0x0f, 0xf0, 0x1e, 0xe2, 0x0d, 0x2f, 0x68, 0xfb, - 0x62, 0x3a, 0x45, 0x0f, 0x64, 0x92, 0x83, 0x45, 0xb4, 0x3c, 0xbe, 0x49, 0xb3, 0x4a, 0xb6, 0x99, - 0x57, 0x64, 0xf9, 0xb0, 0x83, 0x87, 0x03, 0xa1, 0xa1, 0xb4, 0x26, 0x61, 0x7f, 0x1a, 0x4a, 0x1b, - 0x18, 0x4a, 0x6b, 0xf0, 0x19, 0x70, 0x0f, 0x72, 0x7a, 0x23, 0x43, 0x4f, 0x45, 0x32, 0x71, 0x9a, - 0xcb, 0x5f, 0x34, 0x5f, 0x6d, 0x7c, 0x64, 0x34, 0x2d, 0x20, 0x0e, 0x4e, 0xc6, 0x39, 0x1c, 0x6e, - 0x54, 0x41, 0x5b, 0x97, 0xff, 0x84, 0xef, 0x0a, 0xbc, 0x86, 0x58, 0x90, 0xd6, 0x55, 0x43, 0x6b, - 0x2b, 0x6a, 0x52, 0x2e, 0xfb, 0x84, 0x87, 0x30, 0x6d, 0x86, 0xb2, 0xfe, 0xdc, 0x53, 0x60, 0xaf, - 0xdf, 0xaa, 0xfe, 0xf9, 0x3f, 0x11, 0x5e, 0x00, 0x78, 0xd0, 0x5f, 0xc2, 0xdc, 0xf8, 0x80, 0xa4, - 0x77, 0x80, 0x3f, 0xf3, 0x8d, 0x6c, 0x3b, 0x83, 0xa9, 0xd0, 0xcd, 0xda, 0x0a, 0xbf, 0xc6, 0x57, - 0xf5, 0xd4, 0x7d, 0x80, 0xdb, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc5, 0xc9, 0x5c, 0x7a, 0x18, - 0x02, 0x00, 0x00, +func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_e89cb34cacb448bf) } + +var fileDescriptor_request_e89cb34cacb448bf = []byte{ + // 285 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x4b, 0x84, 0x40, + 0x18, 0xc6, 0xd9, 0x74, 0x37, 0xf6, 0x2d, 0x21, 0x5e, 0x24, 0x44, 0xa2, 0xb6, 0xe8, 0xe0, 0xc9, + 0x85, 0xba, 0x47, 0x07, 0x21, 0x42, 0xda, 0x64, 0xa2, 0x0f, 0xa0, 0xec, 0x8b, 0x48, 0x89, 0x36, + 0x7f, 0x0e, 0x7e, 0xee, 0xbe, 0x40, 0x38, 0x3b, 0xb5, 0x4e, 0x6b, 0x4b, 0x37, 0xe7, 0xc7, 0xf3, + 0xfc, 0x46, 0x1e, 0x06, 0xfc, 0xbc, 0xad, 0x96, 0x6d, 0xb1, 0xe4, 0xf4, 0xa1, 0x48, 0xc8, 0xb8, + 0xe5, 0x8d, 0x6c, 0xd0, 0xc9, 0xdb, 0xea, 0xea, 0xd3, 0x85, 0x43, 0xb6, 0xc1, 0x78, 0x06, 0x73, + 0x93, 0x78, 0x4c, 0x82, 0xc9, 0x62, 0x12, 0xcd, 0xd9, 0x16, 0xe0, 0x3d, 0x78, 0x6b, 0x96, 0x52, + 0xf7, 0x22, 0x1b, 0x4e, 0x0f, 0x24, 0x83, 0x83, 0xc5, 0x24, 0x3a, 0xba, 0x09, 0xe3, 0xbc, 0xad, + 0x62, 0xa3, 0x88, 0x93, 0x61, 0x82, 0xd9, 0x05, 0xdb, 0x90, 0x29, 0x19, 0x38, 0x7b, 0x0d, 0x99, + 0xb2, 0x0c, 0x99, 0x92, 0xf8, 0x0c, 0xb8, 0x05, 0x09, 0xbd, 0x93, 0xa4, 0xa7, 0x34, 0x70, 0xb5, + 0xe6, 0xe2, 0x0f, 0xcd, 0x77, 0x8c, 0x8d, 0x54, 0xf1, 0x15, 0xfc, 0xdf, 0x34, 0xa5, 0x4e, 0x04, + 0x53, 0xad, 0xbc, 0xdc, 0xab, 0xec, 0x83, 0x6c, 0xb4, 0x1e, 0xa6, 0xe0, 0x59, 0x4b, 0xa0, 0x0f, + 0xd3, 0x35, 0x4f, 0xa9, 0xd3, 0xb3, 0x1e, 0xb3, 0xcd, 0x01, 0xaf, 0xc1, 0xab, 0x49, 0x88, 0xbc, + 0xa4, 0x95, 0xaa, 0x0b, 0xe2, 0x7a, 0x52, 0x97, 0xd9, 0x30, 0x2c, 0x87, 0xb2, 0x7e, 0x85, 0x13, + 0x70, 0xde, 0x7e, 0x54, 0xfd, 0xe7, 0xff, 0x44, 0x78, 0x0e, 0x60, 0x40, 0xff, 0x27, 0x8e, 0xae, + 0x0f, 0x48, 0x78, 0x07, 0xb8, 0x3b, 0xdb, 0xc8, 0x6d, 0xa7, 0x30, 0xab, 0x45, 0xb9, 0x52, 0xb5, + 0xb9, 0xc6, 0x9c, 0xc2, 0x08, 0xfc, 0xb1, 0x8d, 0x76, 0x0d, 0xc5, 0x4c, 0xbf, 0xc0, 0xdb, 0xaf, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x9c, 0x52, 0x5c, 0x5f, 0x99, 0x02, 0x00, 0x00, } diff --git a/api/pb/request.proto b/api/pb/request.proto index 82409df..a0dce62 100644 --- a/api/pb/request.proto +++ b/api/pb/request.proto @@ -22,8 +22,13 @@ message Request { uint64 msgNum = 2; } + message DRKeyStoreDeleteKeys { + bytes key = 1; + } + DRKeyStoreGet dRKeyStoreGet = 2; DRKeyStorePut dRKeyStorePut = 3; DRKeyStoreDeleteMK dRKeyStoreDeleteMK = 4; + DRKeyStoreDeleteKeys dRKeyStoreDeleteKeys = 5; } \ No newline at end of file From f949b8b01fbd8cd18d4c59b50013070ae3cb323f Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 15:04:21 +0300 Subject: [PATCH 5/9] [api] key store - added count --- api/dr_key_store.go | 17 ++++++- api/pb/request.pb.go | 107 ++++++++++++++++++++++++++++++------------ api/pb/request.proto | 5 ++ api/pb/response.pb.go | 82 +++++++++++++++++++++++++------- api/pb/response.proto | 5 ++ 5 files changed, 169 insertions(+), 47 deletions(-) diff --git a/api/dr_key_store.go b/api/dr_key_store.go index bc56de0..e12c2bd 100644 --- a/api/dr_key_store.go +++ b/api/dr_key_store.go @@ -129,8 +129,21 @@ func (s *DoubleRatchetKeyStoreApi) DeletePk(k dr.Key) { } func (s *DoubleRatchetKeyStoreApi) Count(k dr.Key) uint { - - + + resp, err := s.api.request(&pb.Request{ + DRKeyStoreCount: &pb.Request_DRKeyStoreCount{ + Key: k[:], + }, + }, time.Second * 8) + + if err != nil { + logger.Error(err) + return 0 + } + + resp.Closer <- nil + + return uint(resp.Msg.DRKeyStoreCount.Count) } diff --git a/api/pb/request.pb.go b/api/pb/request.pb.go index 2de52a6..246a0dc 100644 --- a/api/pb/request.pb.go +++ b/api/pb/request.pb.go @@ -24,6 +24,7 @@ type Request struct { DRKeyStorePut *Request_DRKeyStorePut `protobuf:"bytes,3,opt,name=dRKeyStorePut" json:"dRKeyStorePut,omitempty"` DRKeyStoreDeleteMK *Request_DRKeyStoreDeleteMK `protobuf:"bytes,4,opt,name=dRKeyStoreDeleteMK" json:"dRKeyStoreDeleteMK,omitempty"` DRKeyStoreDeleteKeys *Request_DRKeyStoreDeleteKeys `protobuf:"bytes,5,opt,name=dRKeyStoreDeleteKeys" json:"dRKeyStoreDeleteKeys,omitempty"` + DRKeyStoreCount *Request_DRKeyStoreCount `protobuf:"bytes,6,opt,name=dRKeyStoreCount" json:"dRKeyStoreCount,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -33,7 +34,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_request_e89cb34cacb448bf, []int{0} + return fileDescriptor_request_224cd0a37c9476b3, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -88,6 +89,13 @@ func (m *Request) GetDRKeyStoreDeleteKeys() *Request_DRKeyStoreDeleteKeys { return nil } +func (m *Request) GetDRKeyStoreCount() *Request_DRKeyStoreCount { + if m != nil { + return m.DRKeyStoreCount + } + return nil +} + type Request_DRKeyStoreGet struct { DrKey []byte `protobuf:"bytes,1,opt,name=drKey,proto3" json:"drKey,omitempty"` MessageNumber uint64 `protobuf:"varint,2,opt,name=messageNumber" json:"messageNumber,omitempty"` @@ -100,7 +108,7 @@ func (m *Request_DRKeyStoreGet) Reset() { *m = Request_DRKeyStoreGet{} } func (m *Request_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreGet) ProtoMessage() {} func (*Request_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_request_e89cb34cacb448bf, []int{0, 0} + return fileDescriptor_request_224cd0a37c9476b3, []int{0, 0} } func (m *Request_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreGet.Unmarshal(m, b) @@ -147,7 +155,7 @@ func (m *Request_DRKeyStorePut) Reset() { *m = Request_DRKeyStorePut{} } func (m *Request_DRKeyStorePut) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStorePut) ProtoMessage() {} func (*Request_DRKeyStorePut) Descriptor() ([]byte, []int) { - return fileDescriptor_request_e89cb34cacb448bf, []int{0, 1} + return fileDescriptor_request_224cd0a37c9476b3, []int{0, 1} } func (m *Request_DRKeyStorePut) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStorePut.Unmarshal(m, b) @@ -200,7 +208,7 @@ func (m *Request_DRKeyStoreDeleteMK) Reset() { *m = Request_DRKeyStoreDe func (m *Request_DRKeyStoreDeleteMK) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreDeleteMK) ProtoMessage() {} func (*Request_DRKeyStoreDeleteMK) Descriptor() ([]byte, []int) { - return fileDescriptor_request_e89cb34cacb448bf, []int{0, 2} + return fileDescriptor_request_224cd0a37c9476b3, []int{0, 2} } func (m *Request_DRKeyStoreDeleteMK) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreDeleteMK.Unmarshal(m, b) @@ -245,7 +253,7 @@ func (m *Request_DRKeyStoreDeleteKeys) Reset() { *m = Request_DRKeyStore func (m *Request_DRKeyStoreDeleteKeys) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreDeleteKeys) ProtoMessage() {} func (*Request_DRKeyStoreDeleteKeys) Descriptor() ([]byte, []int) { - return fileDescriptor_request_e89cb34cacb448bf, []int{0, 3} + return fileDescriptor_request_224cd0a37c9476b3, []int{0, 3} } func (m *Request_DRKeyStoreDeleteKeys) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreDeleteKeys.Unmarshal(m, b) @@ -272,34 +280,75 @@ func (m *Request_DRKeyStoreDeleteKeys) GetKey() []byte { return nil } +type Request_DRKeyStoreCount struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request_DRKeyStoreCount) Reset() { *m = Request_DRKeyStoreCount{} } +func (m *Request_DRKeyStoreCount) String() string { return proto.CompactTextString(m) } +func (*Request_DRKeyStoreCount) ProtoMessage() {} +func (*Request_DRKeyStoreCount) Descriptor() ([]byte, []int) { + return fileDescriptor_request_224cd0a37c9476b3, []int{0, 4} +} +func (m *Request_DRKeyStoreCount) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request_DRKeyStoreCount.Unmarshal(m, b) +} +func (m *Request_DRKeyStoreCount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request_DRKeyStoreCount.Marshal(b, m, deterministic) +} +func (dst *Request_DRKeyStoreCount) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request_DRKeyStoreCount.Merge(dst, src) +} +func (m *Request_DRKeyStoreCount) XXX_Size() int { + return xxx_messageInfo_Request_DRKeyStoreCount.Size(m) +} +func (m *Request_DRKeyStoreCount) XXX_DiscardUnknown() { + xxx_messageInfo_Request_DRKeyStoreCount.DiscardUnknown(m) +} + +var xxx_messageInfo_Request_DRKeyStoreCount proto.InternalMessageInfo + +func (m *Request_DRKeyStoreCount) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + func init() { proto.RegisterType((*Request)(nil), "api.Request") proto.RegisterType((*Request_DRKeyStoreGet)(nil), "api.Request.DRKeyStoreGet") proto.RegisterType((*Request_DRKeyStorePut)(nil), "api.Request.DRKeyStorePut") proto.RegisterType((*Request_DRKeyStoreDeleteMK)(nil), "api.Request.DRKeyStoreDeleteMK") proto.RegisterType((*Request_DRKeyStoreDeleteKeys)(nil), "api.Request.DRKeyStoreDeleteKeys") -} - -func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_e89cb34cacb448bf) } - -var fileDescriptor_request_e89cb34cacb448bf = []byte{ - // 285 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x4b, 0x84, 0x40, - 0x18, 0xc6, 0xd9, 0x74, 0x37, 0xf6, 0x2d, 0x21, 0x5e, 0x24, 0x44, 0xa2, 0xb6, 0xe8, 0xe0, 0xc9, - 0x85, 0xba, 0x47, 0x07, 0x21, 0x42, 0xda, 0x64, 0xa2, 0x0f, 0xa0, 0xec, 0x8b, 0x48, 0x89, 0x36, - 0x7f, 0x0e, 0x7e, 0xee, 0xbe, 0x40, 0x38, 0x3b, 0xb5, 0x4e, 0x6b, 0x4b, 0x37, 0xe7, 0xc7, 0xf3, - 0xfc, 0x46, 0x1e, 0x06, 0xfc, 0xbc, 0xad, 0x96, 0x6d, 0xb1, 0xe4, 0xf4, 0xa1, 0x48, 0xc8, 0xb8, - 0xe5, 0x8d, 0x6c, 0xd0, 0xc9, 0xdb, 0xea, 0xea, 0xd3, 0x85, 0x43, 0xb6, 0xc1, 0x78, 0x06, 0x73, - 0x93, 0x78, 0x4c, 0x82, 0xc9, 0x62, 0x12, 0xcd, 0xd9, 0x16, 0xe0, 0x3d, 0x78, 0x6b, 0x96, 0x52, - 0xf7, 0x22, 0x1b, 0x4e, 0x0f, 0x24, 0x83, 0x83, 0xc5, 0x24, 0x3a, 0xba, 0x09, 0xe3, 0xbc, 0xad, - 0x62, 0xa3, 0x88, 0x93, 0x61, 0x82, 0xd9, 0x05, 0xdb, 0x90, 0x29, 0x19, 0x38, 0x7b, 0x0d, 0x99, - 0xb2, 0x0c, 0x99, 0x92, 0xf8, 0x0c, 0xb8, 0x05, 0x09, 0xbd, 0x93, 0xa4, 0xa7, 0x34, 0x70, 0xb5, - 0xe6, 0xe2, 0x0f, 0xcd, 0x77, 0x8c, 0x8d, 0x54, 0xf1, 0x15, 0xfc, 0xdf, 0x34, 0xa5, 0x4e, 0x04, - 0x53, 0xad, 0xbc, 0xdc, 0xab, 0xec, 0x83, 0x6c, 0xb4, 0x1e, 0xa6, 0xe0, 0x59, 0x4b, 0xa0, 0x0f, - 0xd3, 0x35, 0x4f, 0xa9, 0xd3, 0xb3, 0x1e, 0xb3, 0xcd, 0x01, 0xaf, 0xc1, 0xab, 0x49, 0x88, 0xbc, - 0xa4, 0x95, 0xaa, 0x0b, 0xe2, 0x7a, 0x52, 0x97, 0xd9, 0x30, 0x2c, 0x87, 0xb2, 0x7e, 0x85, 0x13, - 0x70, 0xde, 0x7e, 0x54, 0xfd, 0xe7, 0xff, 0x44, 0x78, 0x0e, 0x60, 0x40, 0xff, 0x27, 0x8e, 0xae, - 0x0f, 0x48, 0x78, 0x07, 0xb8, 0x3b, 0xdb, 0xc8, 0x6d, 0xa7, 0x30, 0xab, 0x45, 0xb9, 0x52, 0xb5, - 0xb9, 0xc6, 0x9c, 0xc2, 0x08, 0xfc, 0xb1, 0x8d, 0x76, 0x0d, 0xc5, 0x4c, 0xbf, 0xc0, 0xdb, 0xaf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x9c, 0x52, 0x5c, 0x5f, 0x99, 0x02, 0x00, 0x00, + proto.RegisterType((*Request_DRKeyStoreCount)(nil), "api.Request.DRKeyStoreCount") +} + +func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_224cd0a37c9476b3) } + +var fileDescriptor_request_224cd0a37c9476b3 = []byte{ + // 313 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x5d, 0x4b, 0xbc, 0x40, + 0x14, 0xc6, 0xd9, 0xbf, 0xab, 0x7f, 0xf6, 0x94, 0x6c, 0x0c, 0x12, 0xc3, 0xb0, 0xd4, 0xf6, 0x72, + 0xe1, 0x95, 0x0b, 0x75, 0x1f, 0x41, 0x52, 0x84, 0xb4, 0xc9, 0x44, 0x1f, 0x40, 0xd9, 0x83, 0x48, + 0x99, 0xa6, 0x33, 0x17, 0x7e, 0xdb, 0x3e, 0x4a, 0x38, 0x6b, 0xf9, 0xba, 0x4b, 0x77, 0x9e, 0x87, + 0xe7, 0xf9, 0x1d, 0x79, 0xce, 0x80, 0x15, 0x64, 0xf1, 0x2a, 0x0b, 0x57, 0x39, 0x7e, 0x4a, 0x2c, + 0x84, 0x93, 0xe5, 0xa9, 0x48, 0x89, 0x16, 0x64, 0xf1, 0xf9, 0x97, 0x0e, 0xff, 0xf9, 0x56, 0x26, + 0x0b, 0x98, 0xd5, 0x8e, 0x47, 0x97, 0x4e, 0x96, 0x13, 0x7b, 0xc6, 0x1b, 0x81, 0xdc, 0x82, 0xb9, + 0xe1, 0x1e, 0x96, 0x2f, 0x22, 0xcd, 0xf1, 0x01, 0x05, 0xfd, 0xb7, 0x9c, 0xd8, 0x07, 0x57, 0xcc, + 0x09, 0xb2, 0xd8, 0xa9, 0x11, 0x8e, 0xdb, 0x76, 0xf0, 0x6e, 0xa0, 0x4b, 0xf0, 0xa5, 0xa0, 0xda, + 0x5e, 0x82, 0x2f, 0x3b, 0x04, 0x5f, 0x0a, 0xf2, 0x0c, 0xa4, 0x11, 0x5c, 0x7c, 0x47, 0x81, 0x4f, + 0x1e, 0x9d, 0x2a, 0xcc, 0xe9, 0x0e, 0xcc, 0x8f, 0x8d, 0x8f, 0x44, 0xc9, 0x2b, 0x58, 0x7d, 0xd5, + 0xc3, 0xb2, 0xa0, 0xba, 0x42, 0x9e, 0xed, 0x45, 0x56, 0x46, 0x3e, 0x1a, 0x27, 0xf7, 0x30, 0x6f, + 0xf4, 0xbb, 0x54, 0x7e, 0x08, 0x6a, 0x28, 0xe2, 0x62, 0x07, 0x51, 0x79, 0x78, 0x3f, 0xc4, 0x3c, + 0x30, 0x3b, 0x8d, 0x12, 0x0b, 0xf4, 0x4d, 0xee, 0x61, 0xa9, 0xce, 0x73, 0xc8, 0xb7, 0x03, 0xb9, + 0x04, 0x33, 0xc1, 0xa2, 0x08, 0x22, 0x5c, 0xcb, 0x24, 0xc4, 0x5c, 0x9d, 0x66, 0xca, 0xbb, 0x22, + 0x8b, 0xda, 0xb0, 0xaa, 0xcd, 0x23, 0xd0, 0xde, 0x7e, 0x51, 0xd5, 0xe7, 0xdf, 0x40, 0xe4, 0x04, + 0xa0, 0x16, 0xaa, 0x3f, 0xd1, 0x54, 0xbc, 0xa5, 0xb0, 0x1b, 0x20, 0xc3, 0xfa, 0x47, 0xb6, 0x1d, + 0x83, 0x91, 0x14, 0xd1, 0x5a, 0x26, 0xf5, 0x9a, 0x7a, 0x62, 0x36, 0x58, 0x63, 0x5d, 0x0f, 0x09, + 0xec, 0x02, 0xe6, 0xbd, 0x0e, 0x87, 0xa6, 0xd0, 0x50, 0xcf, 0xfd, 0xfa, 0x3b, 0x00, 0x00, 0xff, + 0xff, 0x10, 0xf8, 0x67, 0xe2, 0x06, 0x03, 0x00, 0x00, } diff --git a/api/pb/request.proto b/api/pb/request.proto index a0dce62..317450b 100644 --- a/api/pb/request.proto +++ b/api/pb/request.proto @@ -26,9 +26,14 @@ message Request { bytes key = 1; } + message DRKeyStoreCount { + bytes key = 1; + } + DRKeyStoreGet dRKeyStoreGet = 2; DRKeyStorePut dRKeyStorePut = 3; DRKeyStoreDeleteMK dRKeyStoreDeleteMK = 4; DRKeyStoreDeleteKeys dRKeyStoreDeleteKeys = 5; + DRKeyStoreCount dRKeyStoreCount = 6; } \ No newline at end of file diff --git a/api/pb/response.pb.go b/api/pb/response.pb.go index f679827..817307c 100644 --- a/api/pb/response.pb.go +++ b/api/pb/response.pb.go @@ -19,19 +19,20 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Response struct { - RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` - Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"` - DRKeyStoreGet *Response_DRKeyStoreGet `protobuf:"bytes,3,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"` + DRKeyStoreGet *Response_DRKeyStoreGet `protobuf:"bytes,3,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` + DRKeyStoreCount *Response_DRKeyStoreCount `protobuf:"bytes,4,opt,name=dRKeyStoreCount" json:"dRKeyStoreCount,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_response_4423047fe5a6c89d, []int{0} + return fileDescriptor_response_2742ca6801746f02, []int{0} } func (m *Response) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response.Unmarshal(m, b) @@ -72,6 +73,13 @@ func (m *Response) GetDRKeyStoreGet() *Response_DRKeyStoreGet { return nil } +func (m *Response) GetDRKeyStoreCount() *Response_DRKeyStoreCount { + if m != nil { + return m.DRKeyStoreCount + } + return nil +} + type Response_DRKeyStoreGet struct { MessageKey []byte `protobuf:"bytes,1,opt,name=messageKey,proto3" json:"messageKey,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -83,7 +91,7 @@ func (m *Response_DRKeyStoreGet) Reset() { *m = Response_DRKeyStoreGet{} func (m *Response_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Response_DRKeyStoreGet) ProtoMessage() {} func (*Response_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_response_4423047fe5a6c89d, []int{0, 0} + return fileDescriptor_response_2742ca6801746f02, []int{0, 0} } func (m *Response_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response_DRKeyStoreGet.Unmarshal(m, b) @@ -110,24 +118,66 @@ func (m *Response_DRKeyStoreGet) GetMessageKey() []byte { return nil } +type Response_DRKeyStoreCount struct { + Count uint64 `protobuf:"varint,1,opt,name=count" json:"count,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Response_DRKeyStoreCount) Reset() { *m = Response_DRKeyStoreCount{} } +func (m *Response_DRKeyStoreCount) String() string { return proto.CompactTextString(m) } +func (*Response_DRKeyStoreCount) ProtoMessage() {} +func (*Response_DRKeyStoreCount) Descriptor() ([]byte, []int) { + return fileDescriptor_response_2742ca6801746f02, []int{0, 1} +} +func (m *Response_DRKeyStoreCount) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Response_DRKeyStoreCount.Unmarshal(m, b) +} +func (m *Response_DRKeyStoreCount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Response_DRKeyStoreCount.Marshal(b, m, deterministic) +} +func (dst *Response_DRKeyStoreCount) XXX_Merge(src proto.Message) { + xxx_messageInfo_Response_DRKeyStoreCount.Merge(dst, src) +} +func (m *Response_DRKeyStoreCount) XXX_Size() int { + return xxx_messageInfo_Response_DRKeyStoreCount.Size(m) +} +func (m *Response_DRKeyStoreCount) XXX_DiscardUnknown() { + xxx_messageInfo_Response_DRKeyStoreCount.DiscardUnknown(m) +} + +var xxx_messageInfo_Response_DRKeyStoreCount proto.InternalMessageInfo + +func (m *Response_DRKeyStoreCount) GetCount() uint64 { + if m != nil { + return m.Count + } + return 0 +} + func init() { proto.RegisterType((*Response)(nil), "api.Response") proto.RegisterType((*Response_DRKeyStoreGet)(nil), "api.Response.DRKeyStoreGet") + proto.RegisterType((*Response_DRKeyStoreCount)(nil), "api.Response.DRKeyStoreCount") } -func init() { proto.RegisterFile("api/pb/response.proto", fileDescriptor_response_4423047fe5a6c89d) } +func init() { proto.RegisterFile("api/pb/response.proto", fileDescriptor_response_2742ca6801746f02) } -var fileDescriptor_response_4423047fe5a6c89d = []byte{ - // 167 bytes of a gzipped FileDescriptorProto +var fileDescriptor_response_2742ca6801746f02 = []byte{ + // 209 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4d, 0x2c, 0xc8, 0xd4, 0x2f, 0x48, 0xd2, 0x2f, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0xda, 0xc4, 0xc8, 0xc5, 0x11, 0x04, 0x15, 0x17, 0x92, + 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x5a, 0xc2, 0xc4, 0xc5, 0x11, 0x04, 0x15, 0x17, 0x92, 0xe1, 0xe2, 0x2c, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xf1, 0x74, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x08, 0x08, 0x89, 0x70, 0xb1, 0xa6, 0x16, 0x15, 0xe5, 0x17, 0x49, 0x30, 0x81, 0x65, 0x20, 0x1c, 0x21, 0x47, 0x2e, 0xde, 0x94, 0x20, 0xef, 0xd4, 0xca, 0xe0, 0x92, 0xfc, 0xa2, 0x54, 0xf7, 0xd4, 0x12, 0x09, 0x66, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x69, 0xbd, 0xc4, 0x82, 0x4c, - 0x3d, 0x98, 0xc9, 0x7a, 0x2e, 0xc8, 0x4a, 0x82, 0x50, 0x75, 0x48, 0xe9, 0x73, 0xf1, 0xa2, 0xc8, - 0x0b, 0xc9, 0x71, 0x71, 0xe5, 0xa6, 0x16, 0x17, 0x27, 0xa6, 0xa7, 0x7a, 0xa7, 0x56, 0x82, 0x1d, - 0xc2, 0x13, 0x84, 0x24, 0x92, 0xc4, 0x06, 0xf6, 0x80, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xec, - 0x47, 0x3d, 0xfe, 0xd9, 0x00, 0x00, 0x00, + 0x3d, 0x98, 0xc9, 0x7a, 0x2e, 0xc8, 0x4a, 0x82, 0x50, 0x75, 0x08, 0xb9, 0x73, 0xf1, 0x23, 0x04, + 0x9c, 0xf3, 0x4b, 0xf3, 0x4a, 0x24, 0x58, 0xc0, 0x86, 0xc8, 0xe2, 0x32, 0x04, 0xac, 0x28, 0x08, + 0x5d, 0x97, 0x94, 0x3e, 0x17, 0x2f, 0x8a, 0x45, 0x42, 0x72, 0x5c, 0x5c, 0xb9, 0xa9, 0xc5, 0xc5, + 0x89, 0xe9, 0xa9, 0xde, 0xa9, 0x95, 0x60, 0x1f, 0xf1, 0x04, 0x21, 0x89, 0x48, 0xa9, 0x73, 0xf1, + 0xa3, 0x19, 0x0a, 0xf2, 0x65, 0x32, 0xd8, 0x09, 0x20, 0xd5, 0x2c, 0x41, 0x10, 0x4e, 0x12, 0x1b, + 0x38, 0xc8, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x65, 0x32, 0x20, 0xde, 0x4b, 0x01, 0x00, + 0x00, } diff --git a/api/pb/response.proto b/api/pb/response.proto index 1f7c27f..d607b23 100644 --- a/api/pb/response.proto +++ b/api/pb/response.proto @@ -11,6 +11,11 @@ message Response { bytes messageKey = 1; } + message DRKeyStoreCount { + uint64 count = 1; + } + DRKeyStoreGet dRKeyStoreGet = 3; + DRKeyStoreCount dRKeyStoreCount = 4; } \ No newline at end of file From 05a945daeb061142e85167b4404eef764548e261 Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 15:31:06 +0300 Subject: [PATCH 6/9] [api] implemented key store - get all --- api/dr_key_store.go | 66 ++++++++++++++++++- api/pb/request.pb.go | 104 ++++++++++++++++++++---------- api/pb/request.proto | 3 + api/pb/response.pb.go | 144 ++++++++++++++++++++++++++++++++++++------ api/pb/response.proto | 12 ++++ 5 files changed, 274 insertions(+), 55 deletions(-) diff --git a/api/dr_key_store.go b/api/dr_key_store.go index e12c2bd..d678462 100644 --- a/api/dr_key_store.go +++ b/api/dr_key_store.go @@ -147,9 +147,71 @@ func (s *DoubleRatchetKeyStoreApi) Count(k dr.Key) uint { } +// @todo the all method is way to heavy. Long term we need to have another solution func (s *DoubleRatchetKeyStoreApi) All() map[dr.Key]map[uint]dr.Key { - - + + resp, err := s.api.request(&pb.Request{ + DRKeyStoreAll: &pb.Request_DRKeyStoreAll{}, + }, time.Second * 8) + + if err != nil { + logger.Error(err) + return map[dr.Key]map[uint]dr.Key{} + } + + var keys = map[dr.Key]map[uint]dr.Key{} + + for _, k := range resp.Msg.DRKeyStoreAll.All { + + // exit if key len is incorrect + if len(k.Key) != 32 { + e := errors.New("got invalid key in All() (expected key len == 32 bytes)") + logger.Error(e) + resp.Closer <- e + return map[dr.Key]map[uint]dr.Key{} + } + + indexKey := dr.Key{} + copy(indexKey[:], k.Key) + + messages := map[uint]dr.Key{} + + for msgNum, key := range k.MessageKeys { + + ct, err := aes.Unmarshal(key) + if err != nil { + resp.Closer <- err + logger.Error(err) + return map[dr.Key]map[uint]dr.Key{} + } + + rawMsgKey, err := s.km.AESDecrypt(ct) + if err != nil { + resp.Closer <- err + logger.Error(err) + return map[dr.Key]map[uint]dr.Key{} + } + + if len(rawMsgKey) != 32 { + e := errors.New("got invalid key in All() (expected key len == 32 bytes)") + logger.Error(e) + resp.Closer <- e + return map[dr.Key]map[uint]dr.Key{} + } + + msgKey := dr.Key{} + copy(msgKey[:], rawMsgKey) + + messages[uint(msgNum)] = msgKey + } + + keys[indexKey] = messages + + } + + resp.Closer <- nil + + return keys } diff --git a/api/pb/request.pb.go b/api/pb/request.pb.go index 246a0dc..52c219d 100644 --- a/api/pb/request.pb.go +++ b/api/pb/request.pb.go @@ -25,6 +25,7 @@ type Request struct { DRKeyStoreDeleteMK *Request_DRKeyStoreDeleteMK `protobuf:"bytes,4,opt,name=dRKeyStoreDeleteMK" json:"dRKeyStoreDeleteMK,omitempty"` DRKeyStoreDeleteKeys *Request_DRKeyStoreDeleteKeys `protobuf:"bytes,5,opt,name=dRKeyStoreDeleteKeys" json:"dRKeyStoreDeleteKeys,omitempty"` DRKeyStoreCount *Request_DRKeyStoreCount `protobuf:"bytes,6,opt,name=dRKeyStoreCount" json:"dRKeyStoreCount,omitempty"` + DRKeyStoreAll *Request_DRKeyStoreAll `protobuf:"bytes,7,opt,name=dRKeyStoreAll" json:"dRKeyStoreAll,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -34,7 +35,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_request_224cd0a37c9476b3, []int{0} + return fileDescriptor_request_a72ad79a9cec03a3, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -96,6 +97,13 @@ func (m *Request) GetDRKeyStoreCount() *Request_DRKeyStoreCount { return nil } +func (m *Request) GetDRKeyStoreAll() *Request_DRKeyStoreAll { + if m != nil { + return m.DRKeyStoreAll + } + return nil +} + type Request_DRKeyStoreGet struct { DrKey []byte `protobuf:"bytes,1,opt,name=drKey,proto3" json:"drKey,omitempty"` MessageNumber uint64 `protobuf:"varint,2,opt,name=messageNumber" json:"messageNumber,omitempty"` @@ -108,7 +116,7 @@ func (m *Request_DRKeyStoreGet) Reset() { *m = Request_DRKeyStoreGet{} } func (m *Request_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreGet) ProtoMessage() {} func (*Request_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_request_224cd0a37c9476b3, []int{0, 0} + return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 0} } func (m *Request_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreGet.Unmarshal(m, b) @@ -155,7 +163,7 @@ func (m *Request_DRKeyStorePut) Reset() { *m = Request_DRKeyStorePut{} } func (m *Request_DRKeyStorePut) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStorePut) ProtoMessage() {} func (*Request_DRKeyStorePut) Descriptor() ([]byte, []int) { - return fileDescriptor_request_224cd0a37c9476b3, []int{0, 1} + return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 1} } func (m *Request_DRKeyStorePut) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStorePut.Unmarshal(m, b) @@ -208,7 +216,7 @@ func (m *Request_DRKeyStoreDeleteMK) Reset() { *m = Request_DRKeyStoreDe func (m *Request_DRKeyStoreDeleteMK) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreDeleteMK) ProtoMessage() {} func (*Request_DRKeyStoreDeleteMK) Descriptor() ([]byte, []int) { - return fileDescriptor_request_224cd0a37c9476b3, []int{0, 2} + return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 2} } func (m *Request_DRKeyStoreDeleteMK) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreDeleteMK.Unmarshal(m, b) @@ -253,7 +261,7 @@ func (m *Request_DRKeyStoreDeleteKeys) Reset() { *m = Request_DRKeyStore func (m *Request_DRKeyStoreDeleteKeys) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreDeleteKeys) ProtoMessage() {} func (*Request_DRKeyStoreDeleteKeys) Descriptor() ([]byte, []int) { - return fileDescriptor_request_224cd0a37c9476b3, []int{0, 3} + return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 3} } func (m *Request_DRKeyStoreDeleteKeys) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreDeleteKeys.Unmarshal(m, b) @@ -291,7 +299,7 @@ func (m *Request_DRKeyStoreCount) Reset() { *m = Request_DRKeyStoreCount func (m *Request_DRKeyStoreCount) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreCount) ProtoMessage() {} func (*Request_DRKeyStoreCount) Descriptor() ([]byte, []int) { - return fileDescriptor_request_224cd0a37c9476b3, []int{0, 4} + return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 4} } func (m *Request_DRKeyStoreCount) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreCount.Unmarshal(m, b) @@ -318,6 +326,36 @@ func (m *Request_DRKeyStoreCount) GetKey() []byte { return nil } +type Request_DRKeyStoreAll struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request_DRKeyStoreAll) Reset() { *m = Request_DRKeyStoreAll{} } +func (m *Request_DRKeyStoreAll) String() string { return proto.CompactTextString(m) } +func (*Request_DRKeyStoreAll) ProtoMessage() {} +func (*Request_DRKeyStoreAll) Descriptor() ([]byte, []int) { + return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 5} +} +func (m *Request_DRKeyStoreAll) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request_DRKeyStoreAll.Unmarshal(m, b) +} +func (m *Request_DRKeyStoreAll) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request_DRKeyStoreAll.Marshal(b, m, deterministic) +} +func (dst *Request_DRKeyStoreAll) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request_DRKeyStoreAll.Merge(dst, src) +} +func (m *Request_DRKeyStoreAll) XXX_Size() int { + return xxx_messageInfo_Request_DRKeyStoreAll.Size(m) +} +func (m *Request_DRKeyStoreAll) XXX_DiscardUnknown() { + xxx_messageInfo_Request_DRKeyStoreAll.DiscardUnknown(m) +} + +var xxx_messageInfo_Request_DRKeyStoreAll proto.InternalMessageInfo + func init() { proto.RegisterType((*Request)(nil), "api.Request") proto.RegisterType((*Request_DRKeyStoreGet)(nil), "api.Request.DRKeyStoreGet") @@ -325,30 +363,32 @@ func init() { proto.RegisterType((*Request_DRKeyStoreDeleteMK)(nil), "api.Request.DRKeyStoreDeleteMK") proto.RegisterType((*Request_DRKeyStoreDeleteKeys)(nil), "api.Request.DRKeyStoreDeleteKeys") proto.RegisterType((*Request_DRKeyStoreCount)(nil), "api.Request.DRKeyStoreCount") -} - -func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_224cd0a37c9476b3) } - -var fileDescriptor_request_224cd0a37c9476b3 = []byte{ - // 313 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x5d, 0x4b, 0xbc, 0x40, - 0x14, 0xc6, 0xd9, 0xbf, 0xab, 0x7f, 0xf6, 0x94, 0x6c, 0x0c, 0x12, 0xc3, 0xb0, 0xd4, 0xf6, 0x72, - 0xe1, 0x95, 0x0b, 0x75, 0x1f, 0x41, 0x52, 0x84, 0xb4, 0xc9, 0x44, 0x1f, 0x40, 0xd9, 0x83, 0x48, - 0x99, 0xa6, 0x33, 0x17, 0x7e, 0xdb, 0x3e, 0x4a, 0x38, 0x6b, 0xf9, 0xba, 0x4b, 0x77, 0x9e, 0x87, - 0xe7, 0xf9, 0x1d, 0x79, 0xce, 0x80, 0x15, 0x64, 0xf1, 0x2a, 0x0b, 0x57, 0x39, 0x7e, 0x4a, 0x2c, - 0x84, 0x93, 0xe5, 0xa9, 0x48, 0x89, 0x16, 0x64, 0xf1, 0xf9, 0x97, 0x0e, 0xff, 0xf9, 0x56, 0x26, - 0x0b, 0x98, 0xd5, 0x8e, 0x47, 0x97, 0x4e, 0x96, 0x13, 0x7b, 0xc6, 0x1b, 0x81, 0xdc, 0x82, 0xb9, - 0xe1, 0x1e, 0x96, 0x2f, 0x22, 0xcd, 0xf1, 0x01, 0x05, 0xfd, 0xb7, 0x9c, 0xd8, 0x07, 0x57, 0xcc, - 0x09, 0xb2, 0xd8, 0xa9, 0x11, 0x8e, 0xdb, 0x76, 0xf0, 0x6e, 0xa0, 0x4b, 0xf0, 0xa5, 0xa0, 0xda, - 0x5e, 0x82, 0x2f, 0x3b, 0x04, 0x5f, 0x0a, 0xf2, 0x0c, 0xa4, 0x11, 0x5c, 0x7c, 0x47, 0x81, 0x4f, - 0x1e, 0x9d, 0x2a, 0xcc, 0xe9, 0x0e, 0xcc, 0x8f, 0x8d, 0x8f, 0x44, 0xc9, 0x2b, 0x58, 0x7d, 0xd5, - 0xc3, 0xb2, 0xa0, 0xba, 0x42, 0x9e, 0xed, 0x45, 0x56, 0x46, 0x3e, 0x1a, 0x27, 0xf7, 0x30, 0x6f, - 0xf4, 0xbb, 0x54, 0x7e, 0x08, 0x6a, 0x28, 0xe2, 0x62, 0x07, 0x51, 0x79, 0x78, 0x3f, 0xc4, 0x3c, - 0x30, 0x3b, 0x8d, 0x12, 0x0b, 0xf4, 0x4d, 0xee, 0x61, 0xa9, 0xce, 0x73, 0xc8, 0xb7, 0x03, 0xb9, - 0x04, 0x33, 0xc1, 0xa2, 0x08, 0x22, 0x5c, 0xcb, 0x24, 0xc4, 0x5c, 0x9d, 0x66, 0xca, 0xbb, 0x22, - 0x8b, 0xda, 0xb0, 0xaa, 0xcd, 0x23, 0xd0, 0xde, 0x7e, 0x51, 0xd5, 0xe7, 0xdf, 0x40, 0xe4, 0x04, - 0xa0, 0x16, 0xaa, 0x3f, 0xd1, 0x54, 0xbc, 0xa5, 0xb0, 0x1b, 0x20, 0xc3, 0xfa, 0x47, 0xb6, 0x1d, - 0x83, 0x91, 0x14, 0xd1, 0x5a, 0x26, 0xf5, 0x9a, 0x7a, 0x62, 0x36, 0x58, 0x63, 0x5d, 0x0f, 0x09, - 0xec, 0x02, 0xe6, 0xbd, 0x0e, 0x87, 0xa6, 0xd0, 0x50, 0xcf, 0xfd, 0xfa, 0x3b, 0x00, 0x00, 0xff, - 0xff, 0x10, 0xf8, 0x67, 0xe2, 0x06, 0x03, 0x00, 0x00, + proto.RegisterType((*Request_DRKeyStoreAll)(nil), "api.Request.DRKeyStoreAll") +} + +func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_a72ad79a9cec03a3) } + +var fileDescriptor_request_a72ad79a9cec03a3 = []byte{ + // 334 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x4a, 0xf3, 0x40, + 0x14, 0xc5, 0xe9, 0x97, 0x36, 0xa5, 0xf7, 0xb3, 0x54, 0x86, 0x20, 0xc3, 0x50, 0xb4, 0xfe, 0x59, + 0x74, 0x95, 0x82, 0xee, 0xc5, 0x62, 0x51, 0x24, 0x58, 0xcb, 0x88, 0x0f, 0x90, 0xd2, 0x4b, 0x09, + 0x4e, 0x4c, 0x4c, 0x66, 0x16, 0x79, 0x2e, 0x5f, 0x50, 0x32, 0x8d, 0x26, 0x93, 0xa6, 0xc1, 0x5d, + 0xee, 0xe1, 0x9c, 0xdf, 0x4d, 0xee, 0x21, 0xe0, 0xf8, 0x71, 0x30, 0x8b, 0xd7, 0xb3, 0x04, 0x3f, + 0x15, 0xa6, 0xd2, 0x8d, 0x93, 0x48, 0x46, 0xc4, 0xf2, 0xe3, 0xe0, 0xe2, 0xcb, 0x86, 0x3e, 0xdf, + 0xc9, 0x64, 0x0c, 0x83, 0xc2, 0xf1, 0xb4, 0xa0, 0x9d, 0x49, 0x67, 0x3a, 0xe0, 0xa5, 0x40, 0xee, + 0x60, 0xb8, 0xe1, 0x1e, 0x66, 0xaf, 0x32, 0x4a, 0xf0, 0x11, 0x25, 0xfd, 0x37, 0xe9, 0x4c, 0xff, + 0x5f, 0x33, 0xd7, 0x8f, 0x03, 0xb7, 0x40, 0xb8, 0x8b, 0xaa, 0x83, 0x9b, 0x01, 0x93, 0xb0, 0x52, + 0x92, 0x5a, 0xad, 0x84, 0x95, 0x32, 0x08, 0x2b, 0x25, 0xc9, 0x0b, 0x90, 0x52, 0x58, 0xa0, 0x40, + 0x89, 0xcf, 0x1e, 0xed, 0x6a, 0xcc, 0xd9, 0x01, 0xcc, 0x8f, 0x8d, 0x37, 0x44, 0xc9, 0x1b, 0x38, + 0x75, 0xd5, 0xc3, 0x2c, 0xa5, 0x3d, 0x8d, 0x3c, 0x6f, 0x45, 0xe6, 0x46, 0xde, 0x18, 0x27, 0x0f, + 0x30, 0x2a, 0xf5, 0xfb, 0x48, 0x7d, 0x48, 0x6a, 0x6b, 0xe2, 0xf8, 0x00, 0x51, 0x7b, 0x78, 0x3d, + 0x64, 0x5e, 0x6c, 0x2e, 0x04, 0xed, 0xb7, 0x5e, 0x6c, 0x2e, 0x04, 0x37, 0x03, 0xcc, 0x83, 0xa1, + 0xd1, 0x09, 0x71, 0xa0, 0xb7, 0x49, 0x3c, 0xcc, 0x74, 0xc1, 0x47, 0x7c, 0x37, 0x90, 0x2b, 0x18, + 0x86, 0x98, 0xa6, 0xfe, 0x16, 0x97, 0x2a, 0x5c, 0x63, 0xa2, 0xcb, 0xed, 0x72, 0x53, 0x64, 0xdb, + 0x2a, 0x2c, 0xef, 0xe3, 0x18, 0xac, 0xf7, 0x5f, 0x54, 0xfe, 0xf8, 0x37, 0x10, 0x39, 0x05, 0x28, + 0x84, 0xfc, 0x4d, 0x2c, 0x1d, 0xaf, 0x28, 0xec, 0x16, 0xc8, 0x7e, 0x81, 0x0d, 0xdb, 0x4e, 0xc0, + 0x0e, 0xd3, 0xed, 0x52, 0x85, 0xc5, 0x9a, 0x62, 0x62, 0x53, 0x70, 0x9a, 0xda, 0xda, 0x27, 0xb0, + 0x4b, 0x18, 0xd5, 0x5a, 0x68, 0x30, 0x8d, 0xaa, 0xdf, 0x3d, 0x17, 0x62, 0x6d, 0xeb, 0x3f, 0xe8, + 0xe6, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xbb, 0xdb, 0x2f, 0x89, 0x59, 0x03, 0x00, 0x00, } diff --git a/api/pb/request.proto b/api/pb/request.proto index 317450b..0c4386d 100644 --- a/api/pb/request.proto +++ b/api/pb/request.proto @@ -30,10 +30,13 @@ message Request { bytes key = 1; } + message DRKeyStoreAll {} + DRKeyStoreGet dRKeyStoreGet = 2; DRKeyStorePut dRKeyStorePut = 3; DRKeyStoreDeleteMK dRKeyStoreDeleteMK = 4; DRKeyStoreDeleteKeys dRKeyStoreDeleteKeys = 5; DRKeyStoreCount dRKeyStoreCount = 6; + DRKeyStoreAll dRKeyStoreAll = 7; } \ No newline at end of file diff --git a/api/pb/response.pb.go b/api/pb/response.pb.go index 817307c..d68e27d 100644 --- a/api/pb/response.pb.go +++ b/api/pb/response.pb.go @@ -23,6 +23,7 @@ type Response struct { Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"` DRKeyStoreGet *Response_DRKeyStoreGet `protobuf:"bytes,3,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` DRKeyStoreCount *Response_DRKeyStoreCount `protobuf:"bytes,4,opt,name=dRKeyStoreCount" json:"dRKeyStoreCount,omitempty"` + DRKeyStoreAll *Response_DRKeyStoreAll `protobuf:"bytes,5,opt,name=dRKeyStoreAll" json:"dRKeyStoreAll,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -32,7 +33,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_response_2742ca6801746f02, []int{0} + return fileDescriptor_response_c70b48d1fa0aa3de, []int{0} } func (m *Response) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response.Unmarshal(m, b) @@ -80,6 +81,13 @@ func (m *Response) GetDRKeyStoreCount() *Response_DRKeyStoreCount { return nil } +func (m *Response) GetDRKeyStoreAll() *Response_DRKeyStoreAll { + if m != nil { + return m.DRKeyStoreAll + } + return nil +} + type Response_DRKeyStoreGet struct { MessageKey []byte `protobuf:"bytes,1,opt,name=messageKey,proto3" json:"messageKey,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -91,7 +99,7 @@ func (m *Response_DRKeyStoreGet) Reset() { *m = Response_DRKeyStoreGet{} func (m *Response_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Response_DRKeyStoreGet) ProtoMessage() {} func (*Response_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_response_2742ca6801746f02, []int{0, 0} + return fileDescriptor_response_c70b48d1fa0aa3de, []int{0, 0} } func (m *Response_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response_DRKeyStoreGet.Unmarshal(m, b) @@ -129,7 +137,7 @@ func (m *Response_DRKeyStoreCount) Reset() { *m = Response_DRKeyStoreCou func (m *Response_DRKeyStoreCount) String() string { return proto.CompactTextString(m) } func (*Response_DRKeyStoreCount) ProtoMessage() {} func (*Response_DRKeyStoreCount) Descriptor() ([]byte, []int) { - return fileDescriptor_response_2742ca6801746f02, []int{0, 1} + return fileDescriptor_response_c70b48d1fa0aa3de, []int{0, 1} } func (m *Response_DRKeyStoreCount) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response_DRKeyStoreCount.Unmarshal(m, b) @@ -156,28 +164,122 @@ func (m *Response_DRKeyStoreCount) GetCount() uint64 { return 0 } +type Response_DRKeyStoreAll struct { + All []*Response_DRKeyStoreAll_Key `protobuf:"bytes,1,rep,name=all" json:"all,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Response_DRKeyStoreAll) Reset() { *m = Response_DRKeyStoreAll{} } +func (m *Response_DRKeyStoreAll) String() string { return proto.CompactTextString(m) } +func (*Response_DRKeyStoreAll) ProtoMessage() {} +func (*Response_DRKeyStoreAll) Descriptor() ([]byte, []int) { + return fileDescriptor_response_c70b48d1fa0aa3de, []int{0, 2} +} +func (m *Response_DRKeyStoreAll) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Response_DRKeyStoreAll.Unmarshal(m, b) +} +func (m *Response_DRKeyStoreAll) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Response_DRKeyStoreAll.Marshal(b, m, deterministic) +} +func (dst *Response_DRKeyStoreAll) XXX_Merge(src proto.Message) { + xxx_messageInfo_Response_DRKeyStoreAll.Merge(dst, src) +} +func (m *Response_DRKeyStoreAll) XXX_Size() int { + return xxx_messageInfo_Response_DRKeyStoreAll.Size(m) +} +func (m *Response_DRKeyStoreAll) XXX_DiscardUnknown() { + xxx_messageInfo_Response_DRKeyStoreAll.DiscardUnknown(m) +} + +var xxx_messageInfo_Response_DRKeyStoreAll proto.InternalMessageInfo + +func (m *Response_DRKeyStoreAll) GetAll() []*Response_DRKeyStoreAll_Key { + if m != nil { + return m.All + } + return nil +} + +type Response_DRKeyStoreAll_Key struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + MessageKeys map[uint64][]byte `protobuf:"bytes,2,rep,name=messageKeys" json:"messageKeys,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Response_DRKeyStoreAll_Key) Reset() { *m = Response_DRKeyStoreAll_Key{} } +func (m *Response_DRKeyStoreAll_Key) String() string { return proto.CompactTextString(m) } +func (*Response_DRKeyStoreAll_Key) ProtoMessage() {} +func (*Response_DRKeyStoreAll_Key) Descriptor() ([]byte, []int) { + return fileDescriptor_response_c70b48d1fa0aa3de, []int{0, 2, 0} +} +func (m *Response_DRKeyStoreAll_Key) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Response_DRKeyStoreAll_Key.Unmarshal(m, b) +} +func (m *Response_DRKeyStoreAll_Key) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Response_DRKeyStoreAll_Key.Marshal(b, m, deterministic) +} +func (dst *Response_DRKeyStoreAll_Key) XXX_Merge(src proto.Message) { + xxx_messageInfo_Response_DRKeyStoreAll_Key.Merge(dst, src) +} +func (m *Response_DRKeyStoreAll_Key) XXX_Size() int { + return xxx_messageInfo_Response_DRKeyStoreAll_Key.Size(m) +} +func (m *Response_DRKeyStoreAll_Key) XXX_DiscardUnknown() { + xxx_messageInfo_Response_DRKeyStoreAll_Key.DiscardUnknown(m) +} + +var xxx_messageInfo_Response_DRKeyStoreAll_Key proto.InternalMessageInfo + +func (m *Response_DRKeyStoreAll_Key) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func (m *Response_DRKeyStoreAll_Key) GetMessageKeys() map[uint64][]byte { + if m != nil { + return m.MessageKeys + } + return nil +} + func init() { proto.RegisterType((*Response)(nil), "api.Response") proto.RegisterType((*Response_DRKeyStoreGet)(nil), "api.Response.DRKeyStoreGet") proto.RegisterType((*Response_DRKeyStoreCount)(nil), "api.Response.DRKeyStoreCount") + proto.RegisterType((*Response_DRKeyStoreAll)(nil), "api.Response.DRKeyStoreAll") + proto.RegisterType((*Response_DRKeyStoreAll_Key)(nil), "api.Response.DRKeyStoreAll.Key") + proto.RegisterMapType((map[uint64][]byte)(nil), "api.Response.DRKeyStoreAll.Key.MessageKeysEntry") } -func init() { proto.RegisterFile("api/pb/response.proto", fileDescriptor_response_2742ca6801746f02) } - -var fileDescriptor_response_2742ca6801746f02 = []byte{ - // 209 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4d, 0x2c, 0xc8, 0xd4, - 0x2f, 0x48, 0xd2, 0x2f, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x5a, 0xc2, 0xc4, 0xc5, 0x11, 0x04, 0x15, 0x17, 0x92, - 0xe1, 0xe2, 0x2c, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xf1, 0x74, 0x91, 0x60, 0x54, 0x60, 0xd4, - 0xe0, 0x0c, 0x42, 0x08, 0x08, 0x89, 0x70, 0xb1, 0xa6, 0x16, 0x15, 0xe5, 0x17, 0x49, 0x30, 0x81, - 0x65, 0x20, 0x1c, 0x21, 0x47, 0x2e, 0xde, 0x94, 0x20, 0xef, 0xd4, 0xca, 0xe0, 0x92, 0xfc, 0xa2, - 0x54, 0xf7, 0xd4, 0x12, 0x09, 0x66, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x69, 0xbd, 0xc4, 0x82, 0x4c, - 0x3d, 0x98, 0xc9, 0x7a, 0x2e, 0xc8, 0x4a, 0x82, 0x50, 0x75, 0x08, 0xb9, 0x73, 0xf1, 0x23, 0x04, - 0x9c, 0xf3, 0x4b, 0xf3, 0x4a, 0x24, 0x58, 0xc0, 0x86, 0xc8, 0xe2, 0x32, 0x04, 0xac, 0x28, 0x08, - 0x5d, 0x97, 0x94, 0x3e, 0x17, 0x2f, 0x8a, 0x45, 0x42, 0x72, 0x5c, 0x5c, 0xb9, 0xa9, 0xc5, 0xc5, - 0x89, 0xe9, 0xa9, 0xde, 0xa9, 0x95, 0x60, 0x1f, 0xf1, 0x04, 0x21, 0x89, 0x48, 0xa9, 0x73, 0xf1, - 0xa3, 0x19, 0x0a, 0xf2, 0x65, 0x32, 0xd8, 0x09, 0x20, 0xd5, 0x2c, 0x41, 0x10, 0x4e, 0x12, 0x1b, - 0x38, 0xc8, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x65, 0x32, 0x20, 0xde, 0x4b, 0x01, 0x00, - 0x00, +func init() { proto.RegisterFile("api/pb/response.proto", fileDescriptor_response_c70b48d1fa0aa3de) } + +var fileDescriptor_response_c70b48d1fa0aa3de = []byte{ + // 323 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcd, 0x4a, 0xfb, 0x40, + 0x14, 0xc5, 0x99, 0x26, 0xfd, 0xf3, 0xef, 0x6d, 0x4b, 0xcb, 0x50, 0x61, 0x88, 0x5f, 0xc5, 0x8d, + 0x5d, 0xa5, 0x5a, 0x37, 0xe2, 0x42, 0x08, 0x56, 0x8a, 0x04, 0x37, 0xd7, 0x27, 0x48, 0xf5, 0x22, + 0xc5, 0xb1, 0x19, 0x67, 0xa6, 0x42, 0x9e, 0xc9, 0x37, 0xf2, 0x29, 0x7c, 0x04, 0xc9, 0x44, 0xcd, + 0x07, 0x58, 0x77, 0xb9, 0x27, 0xe7, 0x9c, 0xf9, 0xcd, 0x70, 0x61, 0x27, 0x51, 0xab, 0xa9, 0x5a, + 0x4e, 0x35, 0x19, 0x95, 0xae, 0x0d, 0x85, 0x4a, 0xa7, 0x36, 0xe5, 0x5e, 0xa2, 0x56, 0x47, 0xef, + 0x3e, 0xfc, 0xc7, 0x2f, 0x9d, 0xef, 0x41, 0x47, 0xd3, 0xcb, 0x86, 0x8c, 0xbd, 0x99, 0x0b, 0x36, + 0x66, 0x93, 0x0e, 0x96, 0x02, 0x1f, 0x41, 0x9b, 0xb4, 0x4e, 0xb5, 0x68, 0xb9, 0x3f, 0xc5, 0xc0, + 0x23, 0xe8, 0x3f, 0x60, 0x4c, 0xd9, 0x9d, 0x4d, 0x35, 0x2d, 0xc8, 0x0a, 0x6f, 0xcc, 0x26, 0xdd, + 0xd9, 0x6e, 0x98, 0xa8, 0x55, 0xf8, 0xdd, 0x1c, 0xce, 0xab, 0x16, 0xac, 0x27, 0xf8, 0x02, 0x06, + 0xa5, 0x70, 0x95, 0x6e, 0xd6, 0x56, 0xf8, 0xae, 0x64, 0xff, 0xb7, 0x12, 0x67, 0xc2, 0x66, 0xaa, + 0xce, 0x12, 0x49, 0x29, 0xda, 0xdb, 0x59, 0x22, 0x29, 0xb1, 0x9e, 0x08, 0xa6, 0xd0, 0xaf, 0xb1, + 0xf2, 0x03, 0x80, 0x67, 0x32, 0x26, 0x79, 0xa4, 0x98, 0x32, 0xf7, 0x28, 0x3d, 0xac, 0x28, 0xc1, + 0x31, 0x0c, 0x1a, 0x5c, 0xf9, 0x43, 0xdd, 0xbb, 0x5b, 0xe4, 0x6e, 0x1f, 0x8b, 0x21, 0xf8, 0x60, + 0xd5, 0xea, 0x48, 0x4a, 0x7e, 0x0a, 0x5e, 0x22, 0xa5, 0x60, 0x63, 0x6f, 0xd2, 0x9d, 0x1d, 0x6e, + 0x81, 0x0c, 0x63, 0xca, 0x30, 0xf7, 0x06, 0x6f, 0x0c, 0xbc, 0x98, 0x32, 0x3e, 0x04, 0xef, 0xe9, + 0x07, 0x27, 0xff, 0xe4, 0x08, 0xdd, 0x92, 0xca, 0x88, 0x96, 0x2b, 0x3d, 0xf9, 0xa3, 0x34, 0xbc, + 0x2d, 0x23, 0xd7, 0x6b, 0xab, 0x33, 0xac, 0x96, 0x04, 0x97, 0x30, 0x6c, 0x1a, 0xaa, 0x27, 0xfb, + 0xc5, 0xc9, 0x23, 0x68, 0xbf, 0x26, 0x72, 0x43, 0x6e, 0x2f, 0x7a, 0x58, 0x0c, 0x17, 0xad, 0x73, + 0xb6, 0xfc, 0xe7, 0x16, 0xed, 0xec, 0x33, 0x00, 0x00, 0xff, 0xff, 0x05, 0x18, 0x2d, 0xf6, 0x81, + 0x02, 0x00, 0x00, } diff --git a/api/pb/response.proto b/api/pb/response.proto index d607b23..7598b56 100644 --- a/api/pb/response.proto +++ b/api/pb/response.proto @@ -15,7 +15,19 @@ message Response { uint64 count = 1; } + message DRKeyStoreAll { + + message Key { + bytes key = 1; + map messageKeys = 2; + } + + repeated Key all = 1; + + } + DRKeyStoreGet dRKeyStoreGet = 3; DRKeyStoreCount dRKeyStoreCount = 4; + DRKeyStoreAll dRKeyStoreAll = 5; } \ No newline at end of file From ccc97c91f796ef7939de8e297b1033c7a598bcc7 Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 18:45:31 +0300 Subject: [PATCH 7/9] [api] fixed tests --- api/api.go | 2 +- api/api_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/api/api.go b/api/api.go index 22565d2..caccdb2 100644 --- a/api/api.go +++ b/api/api.go @@ -40,7 +40,7 @@ type API struct { type Response struct { Msg *pb.Response Error error - Closer <-chan error + Closer chan error } // send a response for a received api request diff --git a/api/api_test.go b/api/api_test.go index 650b2f9..a184679 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -74,6 +74,7 @@ func TestRequestResponse(t *testing.T) { }() resp, err := api.request(&pb.Request{}, time.Second) + resp.Closer <- nil require.Nil(t, err) require.Equal(t, resp.Msg.RequestID, receivedRequestID) From 0ad334b417a9d96656acaeb4caf253e57b7ea4fc Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 21:48:51 +0300 Subject: [PATCH 8/9] [api] fixed tests and imports --- Gopkg.lock | 10 +- Gopkg.toml | 4 - api/api.go | 1 + api/api_test.go | 5 +- api/dr_key_store.go | 104 ++++----- api/dr_key_store_test.go | 445 ++++++++++++++++++------------------ api/pb/request.pb.go | 84 +++---- api/pb/request.proto | 2 +- api/pb/response.pb.go | 92 +++----- api/pb/response.proto | 5 +- mesh/dht_store.go | 158 ------------- mesh/dht_store_rpc_calls.go | 97 -------- mesh/dht_store_test.go | 406 -------------------------------- mesh/mesh.go | 4 +- mobile_interface.go | 34 ++- panthalassa.go | 13 +- 16 files changed, 386 insertions(+), 1078 deletions(-) delete mode 100644 mesh/dht_store.go delete mode 100644 mesh/dht_store_rpc_calls.go delete mode 100644 mesh/dht_store_test.go diff --git a/Gopkg.lock b/Gopkg.lock index 36e9805..909e5c3 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -35,12 +35,6 @@ ] revision = "5312a61534124124185d41f09206b9fef1d88403" -[[projects]] - name = "github.com/asaskevich/govalidator" - packages = ["."] - revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f" - version = "v9" - [[projects]] branch = "master" name = "github.com/btcsuite/btcd" @@ -734,7 +728,7 @@ "unix", "windows" ] - revision = "6c888cc515d3ed83fc103cf1d84468aad274b0a7" + revision = "fc8bd948cf46f9c7af0f07d34151ce25fe90e477" [[projects]] name = "golang.org/x/text" @@ -778,6 +772,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "057a273c85db906caa048e9aa8d3347a430575f2521681d5e07d52b9bf8041e2" + inputs-digest = "c13e934bd3381f6c5dc279b09d49986d6388cdf1d73eb401339cb7113ed42e47" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 75c1d3a..3e4eb56 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -32,10 +32,6 @@ branch = "master" name = "github.com/Bit-Nation/x3dh" -[[constraint]] - name = "github.com/asaskevich/govalidator" - version = "9.0.0" - [[constraint]] name = "github.com/ethereum/go-ethereum" version = "1.8.11" diff --git a/api/api.go b/api/api.go index caccdb2..6f78240 100644 --- a/api/api.go +++ b/api/api.go @@ -28,6 +28,7 @@ func New(client UpStream) *API { } type API struct { + DoubleRatchetKeyStoreApi lock sync.Mutex requests map[string]chan *Response client UpStream diff --git a/api/api_test.go b/api/api_test.go index a184679..0275db6 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -64,9 +64,7 @@ func TestRequestResponse(t *testing.T) { panic(err) } receivedRequestID = req.RequestID - out := api.Respond(req.RequestID, &pb.Response{ - RequestID: req.RequestID, - }, nil, time.Second) + out := api.Respond(req.RequestID, &pb.Response{}, nil, time.Second) if out != nil { panic("expected nil but got: " + out.Error()) } @@ -76,6 +74,5 @@ func TestRequestResponse(t *testing.T) { resp, err := api.request(&pb.Request{}, time.Second) resp.Closer <- nil require.Nil(t, err) - require.Equal(t, resp.Msg.RequestID, receivedRequestID) } diff --git a/api/dr_key_store.go b/api/dr_key_store.go index d678462..9632a4c 100644 --- a/api/dr_key_store.go +++ b/api/dr_key_store.go @@ -3,11 +3,11 @@ package api import ( "errors" "time" - - keyManager "github.com/Bit-Nation/panthalassa/keyManager" - dr "github.com/tiabc/doubleratchet" + pb "github.com/Bit-Nation/panthalassa/api/pb" aes "github.com/Bit-Nation/panthalassa/crypto/aes" + keyManager "github.com/Bit-Nation/panthalassa/keyManager" + dr "github.com/tiabc/doubleratchet" ) type DoubleRatchetKeyStoreApi struct { @@ -17,48 +17,48 @@ type DoubleRatchetKeyStoreApi struct { // get a key by it's key and msg number func (s *DoubleRatchetKeyStoreApi) Get(k dr.Key, msgNum uint) (mk dr.Key, ok bool) { - + req := pb.Request{ DRKeyStoreGet: &pb.Request_DRKeyStoreGet{ - DrKey: k[:], + DrKey: k[:], MessageNumber: uint64(msgNum), }, } - resp, err := s.api.request(&req, time.Second * 8) + resp, err := s.api.request(&req, time.Second*8) if err != nil { logger.Error(err) return dr.Key{}, false } - + ct, err := aes.Unmarshal(resp.Msg.DRKeyStoreGet.MessageKey) if err != nil { logger.Error(err) resp.Closer <- err return dr.Key{}, false } - + messageKey, err := s.km.AESDecrypt(ct) if err != nil { logger.Error(err) resp.Closer <- err return dr.Key{}, false } - + if len(messageKey) != 32 { e := errors.New("a decrypted message key must have exactly 32 bytes") logger.Error(e) resp.Closer <- e return dr.Key{}, false } - + resp.Closer <- nil - + var msgKey dr.Key copy(msgKey[:], messageKey) - + return msgKey, true - + } // save message key (double ratchet key) @@ -69,100 +69,100 @@ func (s *DoubleRatchetKeyStoreApi) Put(k dr.Key, msgNum uint, mk dr.Key) { logger.Error(err) return } - + rawCt, err := ct.Marshal() if err != nil { logger.Error(err) return } - + resp, err := s.api.request(&pb.Request{ DRKeyStorePut: &pb.Request_DRKeyStorePut{ - MessageKey: k[:], + Key: k[:], MessageNumber: uint64(msgNum), - Key: rawCt, + MessageKey: rawCt, }, - }, time.Second * 8) - + }, time.Second*8) + if err != nil { logger.Error(err) return } - + resp.Closer <- nil } func (s *DoubleRatchetKeyStoreApi) DeleteMk(k dr.Key, msgNum uint) { - + resp, err := s.api.request(&pb.Request{ DRKeyStoreDeleteMK: &pb.Request_DRKeyStoreDeleteMK{ - Key: k[:], + Key: k[:], MsgNum: uint64(msgNum), }, - }, time.Second * 8) - + }, time.Second*8) + if err != nil { logger.Error(err) return } - + resp.Closer <- nil } func (s *DoubleRatchetKeyStoreApi) DeletePk(k dr.Key) { - + resp, err := s.api.request(&pb.Request{ DRKeyStoreDeleteKeys: &pb.Request_DRKeyStoreDeleteKeys{ Key: k[:], }, - }, time.Second * 8) - + }, time.Second*8) + if err != nil { logger.Error(err) return } - + resp.Closer <- nil } func (s *DoubleRatchetKeyStoreApi) Count(k dr.Key) uint { - + resp, err := s.api.request(&pb.Request{ DRKeyStoreCount: &pb.Request_DRKeyStoreCount{ Key: k[:], }, - }, time.Second * 8) - + }, time.Second*8) + if err != nil { logger.Error(err) return 0 } - + resp.Closer <- nil - + return uint(resp.Msg.DRKeyStoreCount.Count) } // @todo the all method is way to heavy. Long term we need to have another solution func (s *DoubleRatchetKeyStoreApi) All() map[dr.Key]map[uint]dr.Key { - + resp, err := s.api.request(&pb.Request{ DRKeyStoreAll: &pb.Request_DRKeyStoreAll{}, - }, time.Second * 8) - + }, time.Second*8) + if err != nil { logger.Error(err) return map[dr.Key]map[uint]dr.Key{} } - + var keys = map[dr.Key]map[uint]dr.Key{} - + for _, k := range resp.Msg.DRKeyStoreAll.All { - + // exit if key len is incorrect if len(k.Key) != 32 { e := errors.New("got invalid key in All() (expected key len == 32 bytes)") @@ -170,47 +170,47 @@ func (s *DoubleRatchetKeyStoreApi) All() map[dr.Key]map[uint]dr.Key { resp.Closer <- e return map[dr.Key]map[uint]dr.Key{} } - + indexKey := dr.Key{} copy(indexKey[:], k.Key) - + messages := map[uint]dr.Key{} - + for msgNum, key := range k.MessageKeys { - + ct, err := aes.Unmarshal(key) if err != nil { resp.Closer <- err logger.Error(err) return map[dr.Key]map[uint]dr.Key{} } - + rawMsgKey, err := s.km.AESDecrypt(ct) if err != nil { resp.Closer <- err logger.Error(err) return map[dr.Key]map[uint]dr.Key{} } - + if len(rawMsgKey) != 32 { e := errors.New("got invalid key in All() (expected key len == 32 bytes)") logger.Error(e) resp.Closer <- e return map[dr.Key]map[uint]dr.Key{} } - + msgKey := dr.Key{} copy(msgKey[:], rawMsgKey) - + messages[uint(msgNum)] = msgKey } - + keys[indexKey] = messages - + } - + resp.Closer <- nil - + return keys } diff --git a/api/dr_key_store_test.go b/api/dr_key_store_test.go index cf50ebd..3d168a8 100644 --- a/api/dr_key_store_test.go +++ b/api/dr_key_store_test.go @@ -1,15 +1,17 @@ package api import ( - "encoding/hex" - "encoding/json" "fmt" + "sync" "testing" + "time" - deviceApi "github.com/Bit-Nation/panthalassa/api/device" + pb "github.com/Bit-Nation/panthalassa/api/pb" + "github.com/Bit-Nation/panthalassa/crypto/aes" keyManager "github.com/Bit-Nation/panthalassa/keyManager" keyStore "github.com/Bit-Nation/panthalassa/keyStore" mnemonic "github.com/Bit-Nation/panthalassa/mnemonic" + proto "github.com/golang/protobuf/proto" require "github.com/stretchr/testify/require" dr "github.com/tiabc/doubleratchet" ) @@ -54,174 +56,136 @@ func keyManagerFactory() *keyManager.KeyManager { func TestDoubleRatchetKeyStore_GetSuccess(t *testing.T) { - c := make(chan string) - - // fake client - api := deviceApi.New(&UpStreamTestImpl{ - f: func(data string) { - c <- data - }, - }) - - // answer request of fake client - go func() { - for { - select { - case data := <-c: - - rpcCall := deviceApi.ApiCall{} - if err := json.Unmarshal([]byte(data), &rpcCall); err != nil { - panic(err) - } - - mustBeEqual(`{"key":"0000000000000000000100010000000000010001000000000000000100000001","msg_num":7}`, rpcCall.Data) - - requireNil(api.Receive(rpcCall.Id, `{"error":"","payload":"{\"key\":\"{\\\"iv\\\":\\\"3Zd2O1KxUz2OZnWQPrTgCg==\\\",\\\"cipher_text\\\":\\\"q4FO26h5TICATqwwp9RXXXes1jX8asn+0TkL5Khx8Oc=\\\",\\\"mac\\\":\\\"XwX884HeXuodY3vgoKvmZcGkW0oPu2fBvRafxAsMu/I=\\\",\\\"v\\\":2}\"}"}`)) - - } - } - }() - - drk := DoubleRatchetKeyStore{ - api: api, - km: keyManagerFactory(), - } - - k := dr.Key{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, - } + km := keyManagerFactory() - key, exist := drk.Get(k, 7) - require.True(t, exist) - require.Equal(t, dr.Key{ - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }, key) + k := dr.Key{} + k[4] = 0x16 -} + rawMsgKey := dr.Key{} + rawMsgKey[2] = 0x34 -func TestDoubleRatchetKeyStore_GetError(t *testing.T) { + ct, err := km.AESEncrypt(rawMsgKey[:]) + require.Nil(t, err) + rawCt, err := ct.Marshal() + require.Nil(t, err) c := make(chan string) - // fake client - api := deviceApi.New(&UpStreamTestImpl{ - f: func(data string) { - c <- data + api := API{ + lock: sync.Mutex{}, + requests: map[string]chan *Response{}, + client: &UpStreamTestImpl{ + f: func(data string) { + c <- data + }, }, - }) + } - // answer request of fake client go func() { - for { - select { - case data := <-c: - rpcCall := deviceApi.ApiCall{} - if err := json.Unmarshal([]byte(data), &rpcCall); err != nil { - panic(err) - } + select { + case data := <-c: - mustBeEqual(`{"key":"0000000000000000000100010000000000010001000000000000000100000001","msg_num":7}`, rpcCall.Data) + req := pb.Request{} + requireNil(proto.Unmarshal([]byte(data), &req)) - requireNil(api.Receive(rpcCall.Id, `{"error":"I am an error","payload":""}`)) + keyRequest := req.DRKeyStoreGet + key := dr.Key{} + copy(key[:], keyRequest.DrKey) + if k != key { + panic("expected keys to match") } + + mustBeEqual(uint64(5), keyRequest.MessageNumber) + + err = api.Respond(req.RequestID, &pb.Response{ + DRKeyStoreGet: &pb.Response_DRKeyStoreGet{ + MessageKey: rawCt, + }, + }, nil, time.Second) + requireNil(err) + } + }() - drk := DoubleRatchetKeyStore{ - api: api, + dra := DoubleRatchetKeyStoreApi{ + api: &api, km: keyManagerFactory(), } - k := dr.Key{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, - } - - key, exist := drk.Get(k, 7) - require.False(t, exist) - require.Equal(t, dr.Key{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }, key) + key, exist := dra.Get(k, 5) + require.Equal(t, rawMsgKey, key) + require.True(t, exist) } func TestDoubleRatchetKeyStore_PutSuccess(t *testing.T) { - c := make(chan string) - - km := keyManagerFactory() + indexKey := dr.Key{} + indexKey[4] = 0x16 - // fake client - api := deviceApi.New(&UpStreamTestImpl{ - f: func(data string) { - c <- data - }, - }) + msgKey := dr.Key{} + msgKey[2] = 0x34 - pubKey := dr.Key{ - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - } + c := make(chan string) - msgKey := dr.Key{ - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + api := API{ + lock: sync.Mutex{}, + requests: map[string]chan *Response{}, + client: &UpStreamTestImpl{ + f: func(data string) { + c <- data + }, + }, } - // answer request of fake client go func() { - for { - select { - case data := <-c: - - rpcCall := deviceApi.ApiCall{} - if err := json.Unmarshal([]byte(data), &rpcCall); err != nil { - panic(err) - } - // check type - mustBeEqual("DR:KEY_STORE:PUT", rpcCall.Type) + select { + case data := <-c: - var c DRKeyStorePutCall - requireNil(json.Unmarshal([]byte(rpcCall.Data), &c)) + req := pb.Request{} + requireNil(proto.Unmarshal([]byte(data), &req)) - mustBeEqual("0100000000000000000000000000000000000000000000000000000000000000", c.IndexKey) - mustBeEqual(uint(30), c.MsgNumber) + keyRequest := req.DRKeyStorePut + decodedIndexKey := dr.Key{} + copy(decodedIndexKey[:], keyRequest.Key) - plainKey, err := km.AESDecrypt(c.DoubleRatchetKey) - requireNil(err) + // make sure index key is correct + if decodedIndexKey != indexKey { + panic("expected keys to match") + } - mustBeEqual(hex.EncodeToString(msgKey[:]), hex.EncodeToString(plainKey)) + // check that message number is correct + mustBeEqual(uint64(5), keyRequest.MessageNumber) - requireNil(api.Receive(rpcCall.Id, `{"error":"","payload":""}`)) + km := keyManagerFactory() + ct, err := aes.Unmarshal(keyRequest.MessageKey) + requireNil(err) + rawDecodedMsgKey, err := km.AESDecrypt(ct) + decodedMsgKey := dr.Key{} + copy(decodedMsgKey[:], rawDecodedMsgKey) + // make sure message key correct + if decodedMsgKey != msgKey { + panic("expected keys to match") } + + err = api.Respond(req.RequestID, &pb.Response{}, nil, time.Second) + requireNil(err) + } + }() - drk := DoubleRatchetKeyStore{ - api: api, + dra := DoubleRatchetKeyStoreApi{ + api: &api, km: keyManagerFactory(), } - drk.Put(pubKey, 30, msgKey) + dra.Put(indexKey, 5, msgKey) } @@ -229,46 +193,50 @@ func TestDoubleRatchetKeyStore_DeleteMessageKeySuccess(t *testing.T) { c := make(chan string) - // fake client - api := deviceApi.New(&UpStreamTestImpl{ - f: func(data string) { - c <- data + msgKey := dr.Key{} + msgKey[2] = 0x34 + + api := API{ + lock: sync.Mutex{}, + requests: map[string]chan *Response{}, + client: &UpStreamTestImpl{ + f: func(data string) { + c <- data + }, }, - }) + } - // answer request of fake client go func() { - for { - select { - case data := <-c: - rpcCall := deviceApi.ApiCall{} - if err := json.Unmarshal([]byte(data), &rpcCall); err != nil { - panic(err) - } - mustBeEqual("DR:KEY_STORE:DELETE_MESSAGE_KEY", rpcCall.Type) + select { + case data := <-c: - mustBeEqual(`{"index_key":"0000000000000000000100010000000000010001000000000000000100000001","msg_num":3032}`, rpcCall.Data) + req := pb.Request{} + requireNil(proto.Unmarshal([]byte(data), &req)) + keyRequest := req.DRKeyStoreDeleteMK - requireNil(api.Receive(rpcCall.Id, `{"error":"","payload":""}`)) + decodedIndexKey := dr.Key{} + copy(decodedIndexKey[:], keyRequest.Key) + // make sure index key is correct + if decodedIndexKey != msgKey { + panic("expected keys to match") } + + // check that message number is correct + mustBeEqual(uint64(6), keyRequest.MsgNum) + + api.Respond(req.RequestID, &pb.Response{}, nil, time.Second*2) } + }() - drk := DoubleRatchetKeyStore{ - api: api, + dra := DoubleRatchetKeyStoreApi{ + api: &api, km: keyManagerFactory(), } - k := dr.Key{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, - } - - drk.DeleteMk(k, 3032) + dra.DeleteMk(msgKey, 6) } @@ -276,46 +244,47 @@ func TestDoubleRatchetKeyStore_DeleteIndexKeySuccess(t *testing.T) { c := make(chan string) - // fake client - api := deviceApi.New(&UpStreamTestImpl{ - f: func(data string) { - c <- data + msgKey := dr.Key{} + msgKey[2] = 0x34 + + api := API{ + lock: sync.Mutex{}, + requests: map[string]chan *Response{}, + client: &UpStreamTestImpl{ + f: func(data string) { + c <- data + }, }, - }) + } - // answer request of fake client go func() { - for { - select { - case data := <-c: - rpcCall := deviceApi.ApiCall{} - if err := json.Unmarshal([]byte(data), &rpcCall); err != nil { - panic(err) - } - mustBeEqual("DR:KEY_STORE:DELETE_INDEX_KEY", rpcCall.Type) + select { + case data := <-c: - mustBeEqual(`{"index_key":"0000000000000000000100010000000000010001000000000000000100000001"}`, rpcCall.Data) + req := pb.Request{} + requireNil(proto.Unmarshal([]byte(data), &req)) + keyRequest := req.DRKeyStoreDeleteKeys - requireNil(api.Receive(rpcCall.Id, `{"error":"","payload":""}`)) + decodedIndexKey := dr.Key{} + copy(decodedIndexKey[:], keyRequest.Key) + // make sure index key is correct + if decodedIndexKey != msgKey { + panic("expected keys to match") } + + api.Respond(req.RequestID, &pb.Response{}, nil, time.Second*2) } + }() - drk := DoubleRatchetKeyStore{ - api: api, + dra := DoubleRatchetKeyStoreApi{ + api: &api, km: keyManagerFactory(), } - k := dr.Key{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, - } - - drk.DeletePk(k) + dra.DeletePk(msgKey) } @@ -323,47 +292,51 @@ func TestDoubleRatchetKeyStore_CountSuccess(t *testing.T) { c := make(chan string) - // fake client - api := deviceApi.New(&UpStreamTestImpl{ - f: func(data string) { - c <- data + msgKey := dr.Key{} + msgKey[2] = 0x34 + + api := API{ + lock: sync.Mutex{}, + requests: map[string]chan *Response{}, + client: &UpStreamTestImpl{ + f: func(data string) { + c <- data + }, }, - }) + } - // answer request of fake client go func() { - for { - select { - case data := <-c: - rpcCall := deviceApi.ApiCall{} - if err := json.Unmarshal([]byte(data), &rpcCall); err != nil { - panic(err) - } + select { + case data := <-c: - mustBeEqual("DR:KEY_STORE:COUNT_MESSAGES", rpcCall.Type) + req := pb.Request{} + requireNil(proto.Unmarshal([]byte(data), &req)) + keyRequest := req.DRKeyStoreCount - mustBeEqual(`{"index_key":"0000000000000000000100010000000000010001000000000000000100000001"}`, rpcCall.Data) - - requireNil(api.Receive(rpcCall.Id, `{"error":"","payload":"{\"key\":\"{\\\"count\\\":3}\"}"}`)) + decodedIndexKey := dr.Key{} + copy(decodedIndexKey[:], keyRequest.Key) + // make sure index key is correct + if decodedIndexKey != msgKey { + panic("expected keys to match") } + + api.Respond(req.RequestID, &pb.Response{ + DRKeyStoreCount: &pb.Response_DRKeyStoreCount{ + Count: uint64(4), + }, + }, nil, time.Second*2) } + }() - drk := DoubleRatchetKeyStore{ - api: api, + dra := DoubleRatchetKeyStoreApi{ + api: &api, km: keyManagerFactory(), } - k := dr.Key{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, - } - - drk.Count(k) + require.Equal(t, uint(4), dra.Count(msgKey)) } @@ -371,38 +344,56 @@ func TestDoubleRatchetKeyStore_FetchAllKeysSuccess(t *testing.T) { c := make(chan string) - // fake client - api := deviceApi.New(&UpStreamTestImpl{ - f: func(data string) { - c <- data - }, - }) + indexKey := dr.Key{} + indexKey[5] = 0x44 - // answer request of fake client - go func() { - for { - select { - case data := <-c: + msgKey := dr.Key{} + msgKey[2] = 0x34 - rpcCall := deviceApi.ApiCall{} - if err := json.Unmarshal([]byte(data), &rpcCall); err != nil { - panic(err) - } + encryptedMsgKey, err := keyManagerFactory().AESEncrypt(msgKey[:]) + require.Nil(t, err) + rawEncryptedMsgKey, err := encryptedMsgKey.Marshal() + require.Nil(t, err) - mustBeEqual("DR:KEY_STORE:FETCH_ALL_KEYS", rpcCall.Type) - mustBeEqual(``, rpcCall.Data) + api := API{ + lock: sync.Mutex{}, + requests: map[string]chan *Response{}, + client: &UpStreamTestImpl{ + f: func(data string) { + c <- data + }, + }, + } - requireNil(api.Receive(rpcCall.Id, `{"error":"","payload":"{\"0000000000000000000100010000000000010001000000000000000100000001\":{\"444\":\"{\\\"iv\\\":\\\"6IW62YJEo5o+Yc9eeRoyaA==\\\",\\\"cipher_text\\\":\\\"61eWJQS97l2t8ncDpSKKy567kidCKu9Po2cA/ZJZxUQ=\\\",\\\"mac\\\":\\\"v9n9PM68Wdj+g86hQUIS6ZyweDOtjhUyU34+xIos1q8=\\\",\\\"v\\\":1}\"}}"}`)) + go func() { - } + select { + case data := <-c: + + req := pb.Request{} + requireNil(proto.Unmarshal([]byte(data), &req)) + + api.Respond(req.RequestID, &pb.Response{ + DRKeyStoreAll: &pb.Response_DRKeyStoreAll{ + All: []*pb.Response_DRKeyStoreAll_Key{ + &pb.Response_DRKeyStoreAll_Key{ + Key: indexKey[:], + MessageKeys: map[uint64][]byte{ + uint64(4): rawEncryptedMsgKey, + }, + }, + }, + }, + }, nil, time.Second*2) } + }() - drk := DoubleRatchetKeyStore{ - api: api, + dra := DoubleRatchetKeyStoreApi{ + api: &api, km: keyManagerFactory(), } - fmt.Println(drk.All()) + require.Equal(t, msgKey, dra.All()[indexKey][4]) } diff --git a/api/pb/request.pb.go b/api/pb/request.pb.go index 52c219d..cffa0b2 100644 --- a/api/pb/request.pb.go +++ b/api/pb/request.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: api/pb/request.proto -package api +package api_proto import proto "github.com/golang/protobuf/proto" import fmt "fmt" @@ -35,7 +35,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_request_a72ad79a9cec03a3, []int{0} + return fileDescriptor_request_e72907ce72fe1cb6, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -116,7 +116,7 @@ func (m *Request_DRKeyStoreGet) Reset() { *m = Request_DRKeyStoreGet{} } func (m *Request_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreGet) ProtoMessage() {} func (*Request_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 0} + return fileDescriptor_request_e72907ce72fe1cb6, []int{0, 0} } func (m *Request_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreGet.Unmarshal(m, b) @@ -163,7 +163,7 @@ func (m *Request_DRKeyStorePut) Reset() { *m = Request_DRKeyStorePut{} } func (m *Request_DRKeyStorePut) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStorePut) ProtoMessage() {} func (*Request_DRKeyStorePut) Descriptor() ([]byte, []int) { - return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 1} + return fileDescriptor_request_e72907ce72fe1cb6, []int{0, 1} } func (m *Request_DRKeyStorePut) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStorePut.Unmarshal(m, b) @@ -216,7 +216,7 @@ func (m *Request_DRKeyStoreDeleteMK) Reset() { *m = Request_DRKeyStoreDe func (m *Request_DRKeyStoreDeleteMK) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreDeleteMK) ProtoMessage() {} func (*Request_DRKeyStoreDeleteMK) Descriptor() ([]byte, []int) { - return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 2} + return fileDescriptor_request_e72907ce72fe1cb6, []int{0, 2} } func (m *Request_DRKeyStoreDeleteMK) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreDeleteMK.Unmarshal(m, b) @@ -261,7 +261,7 @@ func (m *Request_DRKeyStoreDeleteKeys) Reset() { *m = Request_DRKeyStore func (m *Request_DRKeyStoreDeleteKeys) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreDeleteKeys) ProtoMessage() {} func (*Request_DRKeyStoreDeleteKeys) Descriptor() ([]byte, []int) { - return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 3} + return fileDescriptor_request_e72907ce72fe1cb6, []int{0, 3} } func (m *Request_DRKeyStoreDeleteKeys) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreDeleteKeys.Unmarshal(m, b) @@ -299,7 +299,7 @@ func (m *Request_DRKeyStoreCount) Reset() { *m = Request_DRKeyStoreCount func (m *Request_DRKeyStoreCount) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreCount) ProtoMessage() {} func (*Request_DRKeyStoreCount) Descriptor() ([]byte, []int) { - return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 4} + return fileDescriptor_request_e72907ce72fe1cb6, []int{0, 4} } func (m *Request_DRKeyStoreCount) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreCount.Unmarshal(m, b) @@ -336,7 +336,7 @@ func (m *Request_DRKeyStoreAll) Reset() { *m = Request_DRKeyStoreAll{} } func (m *Request_DRKeyStoreAll) String() string { return proto.CompactTextString(m) } func (*Request_DRKeyStoreAll) ProtoMessage() {} func (*Request_DRKeyStoreAll) Descriptor() ([]byte, []int) { - return fileDescriptor_request_a72ad79a9cec03a3, []int{0, 5} + return fileDescriptor_request_e72907ce72fe1cb6, []int{0, 5} } func (m *Request_DRKeyStoreAll) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request_DRKeyStoreAll.Unmarshal(m, b) @@ -357,38 +357,38 @@ func (m *Request_DRKeyStoreAll) XXX_DiscardUnknown() { var xxx_messageInfo_Request_DRKeyStoreAll proto.InternalMessageInfo func init() { - proto.RegisterType((*Request)(nil), "api.Request") - proto.RegisterType((*Request_DRKeyStoreGet)(nil), "api.Request.DRKeyStoreGet") - proto.RegisterType((*Request_DRKeyStorePut)(nil), "api.Request.DRKeyStorePut") - proto.RegisterType((*Request_DRKeyStoreDeleteMK)(nil), "api.Request.DRKeyStoreDeleteMK") - proto.RegisterType((*Request_DRKeyStoreDeleteKeys)(nil), "api.Request.DRKeyStoreDeleteKeys") - proto.RegisterType((*Request_DRKeyStoreCount)(nil), "api.Request.DRKeyStoreCount") - proto.RegisterType((*Request_DRKeyStoreAll)(nil), "api.Request.DRKeyStoreAll") -} - -func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_a72ad79a9cec03a3) } - -var fileDescriptor_request_a72ad79a9cec03a3 = []byte{ - // 334 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x4a, 0xf3, 0x40, - 0x14, 0xc5, 0xe9, 0x97, 0x36, 0xa5, 0xf7, 0xb3, 0x54, 0x86, 0x20, 0xc3, 0x50, 0xb4, 0xfe, 0x59, - 0x74, 0x95, 0x82, 0xee, 0xc5, 0x62, 0x51, 0x24, 0x58, 0xcb, 0x88, 0x0f, 0x90, 0xd2, 0x4b, 0x09, - 0x4e, 0x4c, 0x4c, 0x66, 0x16, 0x79, 0x2e, 0x5f, 0x50, 0x32, 0x8d, 0x26, 0x93, 0xa6, 0xc1, 0x5d, - 0xee, 0xe1, 0x9c, 0xdf, 0x4d, 0xee, 0x21, 0xe0, 0xf8, 0x71, 0x30, 0x8b, 0xd7, 0xb3, 0x04, 0x3f, - 0x15, 0xa6, 0xd2, 0x8d, 0x93, 0x48, 0x46, 0xc4, 0xf2, 0xe3, 0xe0, 0xe2, 0xcb, 0x86, 0x3e, 0xdf, - 0xc9, 0x64, 0x0c, 0x83, 0xc2, 0xf1, 0xb4, 0xa0, 0x9d, 0x49, 0x67, 0x3a, 0xe0, 0xa5, 0x40, 0xee, - 0x60, 0xb8, 0xe1, 0x1e, 0x66, 0xaf, 0x32, 0x4a, 0xf0, 0x11, 0x25, 0xfd, 0x37, 0xe9, 0x4c, 0xff, - 0x5f, 0x33, 0xd7, 0x8f, 0x03, 0xb7, 0x40, 0xb8, 0x8b, 0xaa, 0x83, 0x9b, 0x01, 0x93, 0xb0, 0x52, - 0x92, 0x5a, 0xad, 0x84, 0x95, 0x32, 0x08, 0x2b, 0x25, 0xc9, 0x0b, 0x90, 0x52, 0x58, 0xa0, 0x40, - 0x89, 0xcf, 0x1e, 0xed, 0x6a, 0xcc, 0xd9, 0x01, 0xcc, 0x8f, 0x8d, 0x37, 0x44, 0xc9, 0x1b, 0x38, - 0x75, 0xd5, 0xc3, 0x2c, 0xa5, 0x3d, 0x8d, 0x3c, 0x6f, 0x45, 0xe6, 0x46, 0xde, 0x18, 0x27, 0x0f, - 0x30, 0x2a, 0xf5, 0xfb, 0x48, 0x7d, 0x48, 0x6a, 0x6b, 0xe2, 0xf8, 0x00, 0x51, 0x7b, 0x78, 0x3d, - 0x64, 0x5e, 0x6c, 0x2e, 0x04, 0xed, 0xb7, 0x5e, 0x6c, 0x2e, 0x04, 0x37, 0x03, 0xcc, 0x83, 0xa1, - 0xd1, 0x09, 0x71, 0xa0, 0xb7, 0x49, 0x3c, 0xcc, 0x74, 0xc1, 0x47, 0x7c, 0x37, 0x90, 0x2b, 0x18, - 0x86, 0x98, 0xa6, 0xfe, 0x16, 0x97, 0x2a, 0x5c, 0x63, 0xa2, 0xcb, 0xed, 0x72, 0x53, 0x64, 0xdb, - 0x2a, 0x2c, 0xef, 0xe3, 0x18, 0xac, 0xf7, 0x5f, 0x54, 0xfe, 0xf8, 0x37, 0x10, 0x39, 0x05, 0x28, - 0x84, 0xfc, 0x4d, 0x2c, 0x1d, 0xaf, 0x28, 0xec, 0x16, 0xc8, 0x7e, 0x81, 0x0d, 0xdb, 0x4e, 0xc0, - 0x0e, 0xd3, 0xed, 0x52, 0x85, 0xc5, 0x9a, 0x62, 0x62, 0x53, 0x70, 0x9a, 0xda, 0xda, 0x27, 0xb0, - 0x4b, 0x18, 0xd5, 0x5a, 0x68, 0x30, 0x8d, 0xaa, 0xdf, 0x3d, 0x17, 0x62, 0x6d, 0xeb, 0x3f, 0xe8, - 0xe6, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xbb, 0xdb, 0x2f, 0x89, 0x59, 0x03, 0x00, 0x00, + proto.RegisterType((*Request)(nil), "api_proto.Request") + proto.RegisterType((*Request_DRKeyStoreGet)(nil), "api_proto.Request.DRKeyStoreGet") + proto.RegisterType((*Request_DRKeyStorePut)(nil), "api_proto.Request.DRKeyStorePut") + proto.RegisterType((*Request_DRKeyStoreDeleteMK)(nil), "api_proto.Request.DRKeyStoreDeleteMK") + proto.RegisterType((*Request_DRKeyStoreDeleteKeys)(nil), "api_proto.Request.DRKeyStoreDeleteKeys") + proto.RegisterType((*Request_DRKeyStoreCount)(nil), "api_proto.Request.DRKeyStoreCount") + proto.RegisterType((*Request_DRKeyStoreAll)(nil), "api_proto.Request.DRKeyStoreAll") +} + +func init() { proto.RegisterFile("api/pb/request.proto", fileDescriptor_request_e72907ce72fe1cb6) } + +var fileDescriptor_request_e72907ce72fe1cb6 = []byte{ + // 336 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4b, 0xc3, 0x30, + 0x18, 0xc5, 0x99, 0xdb, 0x3a, 0xf6, 0xe9, 0x98, 0x84, 0x22, 0xa1, 0x88, 0x8c, 0xa9, 0xb8, 0x53, + 0x07, 0x7a, 0x17, 0x86, 0x43, 0x91, 0xea, 0x28, 0x11, 0x4f, 0x1e, 0xa4, 0x65, 0x1f, 0x65, 0x98, + 0xda, 0xda, 0x26, 0x87, 0xfe, 0xa5, 0xfe, 0x3b, 0xd2, 0xac, 0xae, 0x4d, 0x57, 0x46, 0x6f, 0xc9, + 0xeb, 0x7b, 0xbf, 0x34, 0x79, 0x1f, 0x98, 0x5e, 0xbc, 0x99, 0xc7, 0xfe, 0x3c, 0xc1, 0x1f, 0x89, + 0xa9, 0xb0, 0xe3, 0x24, 0x12, 0x11, 0x19, 0x7a, 0xf1, 0xe6, 0x53, 0x2d, 0xa7, 0xbf, 0x06, 0x0c, + 0xd8, 0xf6, 0x23, 0x39, 0x87, 0x61, 0xe1, 0x7b, 0x5e, 0xd2, 0xce, 0xa4, 0x33, 0x1b, 0xb2, 0x52, + 0x20, 0x8f, 0x30, 0x5a, 0x33, 0x07, 0xb3, 0x37, 0x11, 0x25, 0xf8, 0x84, 0x82, 0x1e, 0x4d, 0x3a, + 0xb3, 0xe3, 0xdb, 0x89, 0xbd, 0x83, 0xd9, 0x05, 0xc8, 0x5e, 0x56, 0x7d, 0x4c, 0x8f, 0xe9, 0x1c, + 0x57, 0x0a, 0xda, 0x6d, 0xc1, 0x71, 0xa5, 0xc6, 0x71, 0xa5, 0x20, 0xef, 0x40, 0x4a, 0x61, 0x89, + 0x1c, 0x05, 0xbe, 0x3a, 0xb4, 0xa7, 0x60, 0xd7, 0x07, 0x61, 0xff, 0x66, 0xd6, 0x00, 0x20, 0x1f, + 0x60, 0xd6, 0x55, 0x07, 0xb3, 0x94, 0xf6, 0x15, 0xf8, 0xa6, 0x05, 0x38, 0xb7, 0xb3, 0x46, 0x08, + 0x79, 0x81, 0x71, 0xa9, 0x3f, 0x44, 0xf2, 0x5b, 0x50, 0x43, 0x71, 0xa7, 0x07, 0xb9, 0xca, 0xc9, + 0xea, 0x51, 0xfd, 0x25, 0x17, 0x9c, 0xd3, 0x41, 0x8b, 0x97, 0x5c, 0x70, 0xce, 0xf4, 0x98, 0xe5, + 0xc0, 0x48, 0x6b, 0x8c, 0x98, 0xd0, 0x5f, 0x27, 0x0e, 0x66, 0x6a, 0x08, 0x4e, 0xd8, 0x76, 0x43, + 0xae, 0x60, 0x14, 0x62, 0x9a, 0x7a, 0x01, 0xae, 0x64, 0xe8, 0x63, 0xa2, 0x06, 0xa0, 0xc7, 0x74, + 0xd1, 0x0a, 0xaa, 0xb0, 0xbc, 0xa7, 0x53, 0xe8, 0x7e, 0xed, 0x50, 0xf9, 0xb2, 0x1d, 0x88, 0x5c, + 0x00, 0x14, 0x42, 0xfe, 0x27, 0x5d, 0x15, 0xaf, 0x28, 0xd6, 0x3d, 0x90, 0xfd, 0x4a, 0x1b, 0x4e, + 0x3b, 0x03, 0x23, 0x4c, 0x83, 0x95, 0x0c, 0x8b, 0x63, 0x8a, 0x9d, 0x35, 0x03, 0xb3, 0xa9, 0xb9, + 0x7d, 0x82, 0x75, 0x09, 0xe3, 0x5a, 0x17, 0x0d, 0xa6, 0x71, 0xf5, 0xde, 0x0b, 0xce, 0x7d, 0x43, + 0x35, 0x70, 0xf7, 0x17, 0x00, 0x00, 0xff, 0xff, 0x06, 0x94, 0xec, 0xd0, 0x83, 0x03, 0x00, 0x00, } diff --git a/api/pb/request.proto b/api/pb/request.proto index 0c4386d..12c8dee 100644 --- a/api/pb/request.proto +++ b/api/pb/request.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package api; +package api_proto; message Request { diff --git a/api/pb/response.pb.go b/api/pb/response.pb.go index d68e27d..086be78 100644 --- a/api/pb/response.pb.go +++ b/api/pb/response.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: api/pb/response.proto -package api +package api_proto import proto "github.com/golang/protobuf/proto" import fmt "fmt" @@ -19,8 +19,6 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Response struct { - RequestID string `protobuf:"bytes,1,opt,name=requestID" json:"requestID,omitempty"` - Error string `protobuf:"bytes,2,opt,name=error" json:"error,omitempty"` DRKeyStoreGet *Response_DRKeyStoreGet `protobuf:"bytes,3,opt,name=dRKeyStoreGet" json:"dRKeyStoreGet,omitempty"` DRKeyStoreCount *Response_DRKeyStoreCount `protobuf:"bytes,4,opt,name=dRKeyStoreCount" json:"dRKeyStoreCount,omitempty"` DRKeyStoreAll *Response_DRKeyStoreAll `protobuf:"bytes,5,opt,name=dRKeyStoreAll" json:"dRKeyStoreAll,omitempty"` @@ -33,7 +31,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_response_c70b48d1fa0aa3de, []int{0} + return fileDescriptor_response_93372bd3fcf2e49f, []int{0} } func (m *Response) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response.Unmarshal(m, b) @@ -53,20 +51,6 @@ func (m *Response) XXX_DiscardUnknown() { var xxx_messageInfo_Response proto.InternalMessageInfo -func (m *Response) GetRequestID() string { - if m != nil { - return m.RequestID - } - return "" -} - -func (m *Response) GetError() string { - if m != nil { - return m.Error - } - return "" -} - func (m *Response) GetDRKeyStoreGet() *Response_DRKeyStoreGet { if m != nil { return m.DRKeyStoreGet @@ -99,7 +83,7 @@ func (m *Response_DRKeyStoreGet) Reset() { *m = Response_DRKeyStoreGet{} func (m *Response_DRKeyStoreGet) String() string { return proto.CompactTextString(m) } func (*Response_DRKeyStoreGet) ProtoMessage() {} func (*Response_DRKeyStoreGet) Descriptor() ([]byte, []int) { - return fileDescriptor_response_c70b48d1fa0aa3de, []int{0, 0} + return fileDescriptor_response_93372bd3fcf2e49f, []int{0, 0} } func (m *Response_DRKeyStoreGet) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response_DRKeyStoreGet.Unmarshal(m, b) @@ -137,7 +121,7 @@ func (m *Response_DRKeyStoreCount) Reset() { *m = Response_DRKeyStoreCou func (m *Response_DRKeyStoreCount) String() string { return proto.CompactTextString(m) } func (*Response_DRKeyStoreCount) ProtoMessage() {} func (*Response_DRKeyStoreCount) Descriptor() ([]byte, []int) { - return fileDescriptor_response_c70b48d1fa0aa3de, []int{0, 1} + return fileDescriptor_response_93372bd3fcf2e49f, []int{0, 1} } func (m *Response_DRKeyStoreCount) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response_DRKeyStoreCount.Unmarshal(m, b) @@ -175,7 +159,7 @@ func (m *Response_DRKeyStoreAll) Reset() { *m = Response_DRKeyStoreAll{} func (m *Response_DRKeyStoreAll) String() string { return proto.CompactTextString(m) } func (*Response_DRKeyStoreAll) ProtoMessage() {} func (*Response_DRKeyStoreAll) Descriptor() ([]byte, []int) { - return fileDescriptor_response_c70b48d1fa0aa3de, []int{0, 2} + return fileDescriptor_response_93372bd3fcf2e49f, []int{0, 2} } func (m *Response_DRKeyStoreAll) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response_DRKeyStoreAll.Unmarshal(m, b) @@ -214,7 +198,7 @@ func (m *Response_DRKeyStoreAll_Key) Reset() { *m = Response_DRKeyStoreA func (m *Response_DRKeyStoreAll_Key) String() string { return proto.CompactTextString(m) } func (*Response_DRKeyStoreAll_Key) ProtoMessage() {} func (*Response_DRKeyStoreAll_Key) Descriptor() ([]byte, []int) { - return fileDescriptor_response_c70b48d1fa0aa3de, []int{0, 2, 0} + return fileDescriptor_response_93372bd3fcf2e49f, []int{0, 2, 0} } func (m *Response_DRKeyStoreAll_Key) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Response_DRKeyStoreAll_Key.Unmarshal(m, b) @@ -249,37 +233,35 @@ func (m *Response_DRKeyStoreAll_Key) GetMessageKeys() map[uint64][]byte { } func init() { - proto.RegisterType((*Response)(nil), "api.Response") - proto.RegisterType((*Response_DRKeyStoreGet)(nil), "api.Response.DRKeyStoreGet") - proto.RegisterType((*Response_DRKeyStoreCount)(nil), "api.Response.DRKeyStoreCount") - proto.RegisterType((*Response_DRKeyStoreAll)(nil), "api.Response.DRKeyStoreAll") - proto.RegisterType((*Response_DRKeyStoreAll_Key)(nil), "api.Response.DRKeyStoreAll.Key") - proto.RegisterMapType((map[uint64][]byte)(nil), "api.Response.DRKeyStoreAll.Key.MessageKeysEntry") -} - -func init() { proto.RegisterFile("api/pb/response.proto", fileDescriptor_response_c70b48d1fa0aa3de) } - -var fileDescriptor_response_c70b48d1fa0aa3de = []byte{ - // 323 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcd, 0x4a, 0xfb, 0x40, - 0x14, 0xc5, 0x99, 0x26, 0xfd, 0xf3, 0xef, 0x6d, 0x4b, 0xcb, 0x50, 0x61, 0x88, 0x5f, 0xc5, 0x8d, - 0x5d, 0xa5, 0x5a, 0x37, 0xe2, 0x42, 0x08, 0x56, 0x8a, 0x04, 0x37, 0xd7, 0x27, 0x48, 0xf5, 0x22, - 0xc5, 0xb1, 0x19, 0x67, 0xa6, 0x42, 0x9e, 0xc9, 0x37, 0xf2, 0x29, 0x7c, 0x04, 0xc9, 0x44, 0xcd, - 0x07, 0x58, 0x77, 0xb9, 0x27, 0xe7, 0x9c, 0xf9, 0xcd, 0x70, 0x61, 0x27, 0x51, 0xab, 0xa9, 0x5a, - 0x4e, 0x35, 0x19, 0x95, 0xae, 0x0d, 0x85, 0x4a, 0xa7, 0x36, 0xe5, 0x5e, 0xa2, 0x56, 0x47, 0xef, - 0x3e, 0xfc, 0xc7, 0x2f, 0x9d, 0xef, 0x41, 0x47, 0xd3, 0xcb, 0x86, 0x8c, 0xbd, 0x99, 0x0b, 0x36, - 0x66, 0x93, 0x0e, 0x96, 0x02, 0x1f, 0x41, 0x9b, 0xb4, 0x4e, 0xb5, 0x68, 0xb9, 0x3f, 0xc5, 0xc0, - 0x23, 0xe8, 0x3f, 0x60, 0x4c, 0xd9, 0x9d, 0x4d, 0x35, 0x2d, 0xc8, 0x0a, 0x6f, 0xcc, 0x26, 0xdd, - 0xd9, 0x6e, 0x98, 0xa8, 0x55, 0xf8, 0xdd, 0x1c, 0xce, 0xab, 0x16, 0xac, 0x27, 0xf8, 0x02, 0x06, - 0xa5, 0x70, 0x95, 0x6e, 0xd6, 0x56, 0xf8, 0xae, 0x64, 0xff, 0xb7, 0x12, 0x67, 0xc2, 0x66, 0xaa, - 0xce, 0x12, 0x49, 0x29, 0xda, 0xdb, 0x59, 0x22, 0x29, 0xb1, 0x9e, 0x08, 0xa6, 0xd0, 0xaf, 0xb1, - 0xf2, 0x03, 0x80, 0x67, 0x32, 0x26, 0x79, 0xa4, 0x98, 0x32, 0xf7, 0x28, 0x3d, 0xac, 0x28, 0xc1, - 0x31, 0x0c, 0x1a, 0x5c, 0xf9, 0x43, 0xdd, 0xbb, 0x5b, 0xe4, 0x6e, 0x1f, 0x8b, 0x21, 0xf8, 0x60, - 0xd5, 0xea, 0x48, 0x4a, 0x7e, 0x0a, 0x5e, 0x22, 0xa5, 0x60, 0x63, 0x6f, 0xd2, 0x9d, 0x1d, 0x6e, - 0x81, 0x0c, 0x63, 0xca, 0x30, 0xf7, 0x06, 0x6f, 0x0c, 0xbc, 0x98, 0x32, 0x3e, 0x04, 0xef, 0xe9, - 0x07, 0x27, 0xff, 0xe4, 0x08, 0xdd, 0x92, 0xca, 0x88, 0x96, 0x2b, 0x3d, 0xf9, 0xa3, 0x34, 0xbc, - 0x2d, 0x23, 0xd7, 0x6b, 0xab, 0x33, 0xac, 0x96, 0x04, 0x97, 0x30, 0x6c, 0x1a, 0xaa, 0x27, 0xfb, - 0xc5, 0xc9, 0x23, 0x68, 0xbf, 0x26, 0x72, 0x43, 0x6e, 0x2f, 0x7a, 0x58, 0x0c, 0x17, 0xad, 0x73, - 0xb6, 0xfc, 0xe7, 0x16, 0xed, 0xec, 0x33, 0x00, 0x00, 0xff, 0xff, 0x05, 0x18, 0x2d, 0xf6, 0x81, - 0x02, 0x00, 0x00, + proto.RegisterType((*Response)(nil), "api_proto.Response") + proto.RegisterType((*Response_DRKeyStoreGet)(nil), "api_proto.Response.DRKeyStoreGet") + proto.RegisterType((*Response_DRKeyStoreCount)(nil), "api_proto.Response.DRKeyStoreCount") + proto.RegisterType((*Response_DRKeyStoreAll)(nil), "api_proto.Response.DRKeyStoreAll") + proto.RegisterType((*Response_DRKeyStoreAll_Key)(nil), "api_proto.Response.DRKeyStoreAll.Key") + proto.RegisterMapType((map[uint64][]byte)(nil), "api_proto.Response.DRKeyStoreAll.Key.MessageKeysEntry") +} + +func init() { proto.RegisterFile("api/pb/response.proto", fileDescriptor_response_93372bd3fcf2e49f) } + +var fileDescriptor_response_93372bd3fcf2e49f = []byte{ + // 298 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x8f, 0x4d, 0x4b, 0xf3, 0x40, + 0x10, 0xc7, 0xd9, 0xbc, 0x3c, 0x3c, 0x4e, 0x2c, 0x2d, 0x4b, 0x85, 0x25, 0x07, 0x89, 0x8a, 0x98, + 0xd3, 0x06, 0x2a, 0xa8, 0x78, 0x10, 0x82, 0x4a, 0x0f, 0xa1, 0x97, 0xf5, 0xe2, 0x4d, 0x52, 0x1d, + 0xa4, 0xb8, 0x26, 0x21, 0x49, 0x85, 0xfd, 0x58, 0x7e, 0x07, 0x3f, 0x96, 0x07, 0xc9, 0x46, 0x9b, + 0x4d, 0x0e, 0xda, 0xdb, 0xcc, 0xec, 0xff, 0xe5, 0xb7, 0xb0, 0x97, 0x16, 0xab, 0xa8, 0x58, 0x46, + 0x25, 0x56, 0x45, 0x9e, 0x55, 0xc8, 0x8b, 0x32, 0xaf, 0x73, 0xba, 0x93, 0x16, 0xab, 0x07, 0x3d, + 0x1e, 0x7e, 0x38, 0xf0, 0x5f, 0x7c, 0xbf, 0xd2, 0x39, 0x8c, 0x9e, 0x44, 0x82, 0xea, 0xae, 0xce, + 0x4b, 0x9c, 0x63, 0xcd, 0xec, 0x80, 0x84, 0xde, 0xec, 0x80, 0x6f, 0xf4, 0xfc, 0x47, 0xcb, 0x6f, + 0x4c, 0xa1, 0xe8, 0xfb, 0xe8, 0x02, 0xc6, 0xdd, 0xe1, 0x3a, 0x5f, 0x67, 0x35, 0x73, 0x74, 0xd4, + 0xd1, 0xef, 0x51, 0x5a, 0x2a, 0x86, 0xde, 0x3e, 0x57, 0x2c, 0x25, 0x73, 0xb7, 0xe1, 0x8a, 0xa5, + 0x14, 0x7d, 0x9f, 0x1f, 0xc1, 0xa8, 0xc7, 0x4d, 0xf7, 0x01, 0x5e, 0xb1, 0xaa, 0xd2, 0x67, 0x4c, + 0x50, 0x31, 0x12, 0x90, 0x70, 0x57, 0x18, 0x17, 0xff, 0x04, 0xc6, 0x03, 0x3a, 0x3a, 0x05, 0xf7, + 0x51, 0xff, 0xa8, 0x51, 0x3b, 0xa2, 0x5d, 0xfc, 0x4f, 0x62, 0x46, 0xc7, 0x52, 0xd2, 0x73, 0xb0, + 0x53, 0x29, 0x19, 0x09, 0xec, 0xd0, 0x9b, 0x1d, 0xff, 0x89, 0xca, 0x13, 0x54, 0xa2, 0x71, 0xf8, + 0xef, 0x04, 0xec, 0x04, 0x15, 0x9d, 0x80, 0xfd, 0xb2, 0x81, 0x6a, 0x46, 0x7a, 0x0f, 0x5e, 0xc7, + 0x56, 0x31, 0x4b, 0x47, 0x9f, 0x6d, 0x15, 0xcd, 0x17, 0x9d, 0xf1, 0x36, 0xab, 0x4b, 0x25, 0xcc, + 0x28, 0xff, 0x0a, 0x26, 0x43, 0x81, 0xd9, 0xef, 0xb4, 0xfd, 0x53, 0x70, 0xdf, 0x52, 0xb9, 0x46, + 0x66, 0x69, 0xa6, 0x76, 0xb9, 0xb4, 0x2e, 0xc8, 0xf2, 0x9f, 0xee, 0x3f, 0xfd, 0x0a, 0x00, 0x00, + 0xff, 0xff, 0x8e, 0x89, 0x06, 0x7a, 0x71, 0x02, 0x00, 0x00, } diff --git a/api/pb/response.proto b/api/pb/response.proto index 7598b56..b07fdc5 100644 --- a/api/pb/response.proto +++ b/api/pb/response.proto @@ -1,12 +1,9 @@ syntax = "proto3"; -package api; +package api_proto; message Response { - string requestID = 1; - string error = 2; - message DRKeyStoreGet { bytes messageKey = 1; } diff --git a/mesh/dht_store.go b/mesh/dht_store.go deleted file mode 100644 index 7fd31ce..0000000 --- a/mesh/dht_store.go +++ /dev/null @@ -1,158 +0,0 @@ -package mesh - -import ( - "encoding/json" - "errors" - "fmt" - - api "github.com/Bit-Nation/panthalassa/api/device" - ds "github.com/ipfs/go-datastore" - dsq "github.com/ipfs/go-datastore/query" -) - -type DataStore struct { - deviceApi *api.Api -} - -func NewDataStore(api *api.Api) ds.Batching { - return &DataStore{ - deviceApi: api, - } -} - -func (d *DataStore) Put(key ds.Key, value interface{}) error { - logger.Info(fmt.Sprintf("put key: %s and value: %s in datastore", key.String(), value)) - - call := DHTPutCall{ - Key: key.String(), - Value: value, - } - - respChan, err := d.deviceApi.Send(&call) - if err != nil { - return err - } - - // wait for the response from the client / device - resp := <-respChan - - // close it here since we don't need it anymore - resp.Close(nil) - - return resp.Error - -} - -func (d *DataStore) Get(key ds.Key) (value interface{}, err error) { - - logger.Info(fmt.Sprintf("fetch value for key: %s", key.String())) - - call := DHTGetCall{ - Key: key.String(), - } - - respChan, err := d.deviceApi.Send(&call) - if err != nil { - return nil, err - } - - // wait for the response from the client / device - resp := <-respChan - - // exit if there is an error in the response - if err != resp.Error { - resp.Close(nil) - return nil, resp.Error - } - - payload := &struct { - Value interface{} `json:"value"` - }{} - - if err := json.Unmarshal([]byte(resp.Payload), payload); err != nil { - // send error back to client - resp.Close(err) - return nil, errors.New(fmt.Sprintf("failed to unmarshal response from client for DHT:PUT query (raw response: %s)", resp.Payload)) - } - - resp.Close(err) - - return payload.Value, nil - -} - -func (d *DataStore) Has(key ds.Key) (exists bool, err error) { - - logger.Info(fmt.Sprintf("check if key is mapped to an value: %s exist", key.String())) - - // device api call - call := DHTHasCall{ - Key: key.String(), - } - - // send to device - respChan, err := d.deviceApi.Send(&call) - if err != nil { - return false, err - } - - // wait for a response - resp := <-respChan - - // exit with error if there is one in the response - if resp.Error != nil { - resp.Close(nil) - return false, resp.Error - } - - payload := &struct { - Exist bool `json:"exist"` - }{} - - // validate json response - // @todo we also need to check the response json schema it self since the struct is initialized with it's default values. - // @todo That could be a problem in case we get an invalid response - if err := json.Unmarshal([]byte(resp.Payload), payload); err != nil { - // send error back to client - resp.Close(err) - return false, errors.New(fmt.Sprintf("failed to unmarshal response from client for DHT:HAS query (raw response: %s)", resp.Payload)) - } - - // close the response - resp.Close(nil) - - return payload.Exist, nil -} - -func (d *DataStore) Delete(key ds.Key) error { - - logger.Info(fmt.Sprintf("check if key is mapped to an value: %s exist", key.String())) - - call := &DHTDeleteCall{ - Key: key.String(), - } - - respChan, err := d.deviceApi.Send(call) - if err != nil { - return err - } - - resp := <-respChan - - resp.Close(nil) - - return resp.Error - -} - -func (d *DataStore) Query(q dsq.Query) (dsq.Results, error) { - - panic("not implemented") - - return nil, nil -} - -func (d *DataStore) Batch() (ds.Batch, error) { - panic("batch is not implemented") - return nil, nil -} diff --git a/mesh/dht_store_rpc_calls.go b/mesh/dht_store_rpc_calls.go deleted file mode 100644 index c3d1c4a..0000000 --- a/mesh/dht_store_rpc_calls.go +++ /dev/null @@ -1,97 +0,0 @@ -package mesh - -import ( - "encoding/json" - valid "github.com/asaskevich/govalidator" -) - -type DHTPutCall struct { - Key string `json:"key"` - Value interface{} `json:"value"` -} - -func (c *DHTPutCall) Type() string { - return "DHT:PUT" -} -func (c *DHTPutCall) Data() (string, error) { - - data, err := json.Marshal(c) - if err != nil { - return "", err - } - - return string(data), err - -} -func (c *DHTPutCall) Valid() error { - return nil -} - -type DHTGetCall struct { - Key string `json:"key"` -} - -func (c *DHTGetCall) Type() string { - return "DHT:GET" -} -func (c *DHTGetCall) Data() (string, error) { - - data, err := json.Marshal(c) - if err != nil { - return "", err - } - - return string(data), err - -} -func (c *DHTGetCall) Valid() error { - _, err := valid.ValidateStruct(c) - return err -} - -type DHTHasCall struct { - Key string `json:"key"` -} - -func (d *DHTHasCall) Type() string { - return "DHT:HAS" -} -func (d *DHTHasCall) Data() (string, error) { - - raw, err := json.Marshal(d) - if err != nil { - return "", err - } - return string(raw), nil - -} -func (d *DHTHasCall) Valid() error { - - _, err := valid.ValidateStruct(d) - return err - -} - -type DHTDeleteCall struct { - Key string `json:"key"` -} - -func (d *DHTDeleteCall) Type() string { - return "DHT:DELETE" -} -func (d *DHTDeleteCall) Data() (string, error) { - - raw, err := json.Marshal(d) - if err != nil { - return "", err - } - - return string(raw), err - -} -func (d *DHTDeleteCall) Valid() error { - - _, err := valid.ValidateStruct(d) - return err - -} diff --git a/mesh/dht_store_test.go b/mesh/dht_store_test.go deleted file mode 100644 index 58535ad..0000000 --- a/mesh/dht_store_test.go +++ /dev/null @@ -1,406 +0,0 @@ -package mesh - -import ( - "encoding/json" - "fmt" - "testing" - - deviceApi "github.com/Bit-Nation/panthalassa/api/device" - ds "github.com/ipfs/go-datastore" - require "github.com/stretchr/testify/require" -) - -type testUpStream struct { - commChan chan string -} - -func (u *testUpStream) Send(data string) { - u.commChan <- data -} - -func requireEqual(expected interface{}, value interface{}) { - - if expected != value { - panic(fmt.Sprintf("expected: %s got %s", expected, value)) - } - -} - -func TestRequireEqual(t *testing.T) { - - // should throw since a != b - require.Panics(t, func() { - requireEqual("a", "b") - }) - - // should pass since a == b - require.NotPanics(t, func() { - requireEqual("a", "a") - }) - -} - -func TestDHTPutSuccess(t *testing.T) { - - device := make(chan string, 1) - - u := testUpStream{ - commChan: device, - } - - api := deviceApi.New(&u) - - go func() { - - // wait for the rpc call - rpcCall := <-device - - // unmarshal rpc call - var call deviceApi.ApiCall - if err := json.Unmarshal([]byte(rpcCall), &call); err != nil { - panic(err) - } - - requireEqual("DHT:PUT", call.Type) - - // unmarshal submitted values - var payload DHTPutCall - if err := json.Unmarshal([]byte(call.Data), &payload); err != nil { - panic(err) - } - - requireEqual("/my_key", payload.Key) - requireEqual("my_value", payload.Value) - - err := api.Receive(call.Id, `{}`) - if err != nil { - panic(err) - } - - }() - - dht := DataStore{api} - - err := dht.Put(ds.NewKey("/my_key"), "my_value") - require.Nil(t, err) - -} - -// test PUT but fail to persist and send error back -func TestDHTPutFail(t *testing.T) { - - device := make(chan string, 1) - - u := testUpStream{ - commChan: device, - } - - api := deviceApi.New(&u) - - go func() { - - // wait for the rpc call - rpcCall := <-device - - // unmarshal rpc call - var call deviceApi.ApiCall - if err := json.Unmarshal([]byte(rpcCall), &call); err != nil { - panic(err) - } - - requireEqual("DHT:PUT", call.Type) - - // unmarshal submitted values - var payload DHTPutCall - if err := json.Unmarshal([]byte(call.Data), &payload); err != nil { - panic(err) - } - - requireEqual("/my_key", payload.Key) - requireEqual("my_value", payload.Value) - - err := api.Receive(call.Id, `{"error": "not enough dist space or what ever"}`) - if err != nil { - panic(err) - } - - }() - - dht := DataStore{api} - - err := dht.Put(ds.NewKey("/my_key"), "my_value") - require.EqualError(t, err, "not enough dist space or what ever") - -} - -func TestDHTGetSuccess(t *testing.T) { - - device := make(chan string, 1) - - u := testUpStream{ - commChan: device, - } - - api := deviceApi.New(&u) - - go func() { - - // wait for the rpc call - rpcCall := <-device - - // unmarshal rpc call - var call deviceApi.ApiCall - if err := json.Unmarshal([]byte(rpcCall), &call); err != nil { - panic(err) - } - - requireEqual("DHT:GET", call.Type) - - // unmarshal submitted values - var payload DHTGetCall - if err := json.Unmarshal([]byte(call.Data), &payload); err != nil { - panic(err) - } - - requireEqual("/my_key", payload.Key) - - err := api.Receive(call.Id, `{"payload":"{\"value\":\"mapped_value\"}"}`) - if err != nil { - panic(err) - } - - }() - - dht := DataStore{api} - - value, err := dht.Get(ds.NewKey("my_key")) - require.Nil(t, err) - require.Equal(t, "mapped_value", value) - -} - -func TestDHTGetError(t *testing.T) { - - device := make(chan string, 1) - - u := testUpStream{ - commChan: device, - } - - api := deviceApi.New(&u) - - go func() { - - // wait for the rpc call - rpcCall := <-device - - // unmarshal rpc call - var call deviceApi.ApiCall - if err := json.Unmarshal([]byte(rpcCall), &call); err != nil { - panic(err) - } - - requireEqual("DHT:GET", call.Type) - - // unmarshal submitted values - var payload DHTGetCall - if err := json.Unmarshal([]byte(call.Data), &payload); err != nil { - panic(err) - } - - requireEqual("/my_key", payload.Key) - - err := api.Receive(call.Id, `{"error":"couldn't find mapped value"}`) - if err != nil { - panic(err) - } - - }() - - dht := DataStore{api} - - value, err := dht.Get(ds.NewKey("my_key")) - require.EqualError(t, err, "couldn't find mapped value") - require.Nil(t, value) - -} - -func TestDHTHasSuccess(t *testing.T) { - - device := make(chan string, 1) - - u := testUpStream{ - commChan: device, - } - - api := deviceApi.New(&u) - - go func() { - - // wait for the rpc call - rpcCall := <-device - - // unmarshal rpc call - var call deviceApi.ApiCall - if err := json.Unmarshal([]byte(rpcCall), &call); err != nil { - panic(err) - } - - requireEqual("DHT:HAS", call.Type) - - // unmarshal submitted values - var payload DHTGetCall - if err := json.Unmarshal([]byte(call.Data), &payload); err != nil { - panic(err) - } - - requireEqual("/my_key", payload.Key) - - err := api.Receive(call.Id, `{"payload":"{\"exist\":true}"}`) - if err != nil { - panic(err) - } - - }() - - dht := DataStore{api} - - exist, err := dht.Has(ds.NewKey("my_key")) - require.Nil(t, err) - require.True(t, exist) - -} - -func TestDHTHasError(t *testing.T) { - - device := make(chan string, 1) - - u := testUpStream{ - commChan: device, - } - - api := deviceApi.New(&u) - - go func() { - - // wait for the rpc call - rpcCall := <-device - - // unmarshal rpc call - var call deviceApi.ApiCall - if err := json.Unmarshal([]byte(rpcCall), &call); err != nil { - panic(err) - } - - requireEqual("DHT:HAS", call.Type) - - // unmarshal submitted values - var payload DHTGetCall - if err := json.Unmarshal([]byte(call.Data), &payload); err != nil { - panic(err) - } - - requireEqual("/my_key", payload.Key) - - err := api.Receive(call.Id, `{"error":"my error"}`) - if err != nil { - panic(err) - } - - }() - - dht := DataStore{api} - - exist, err := dht.Has(ds.NewKey("my_key")) - require.EqualError(t, err, "my error") - require.False(t, exist) - -} - -func TestDHTDeleteSuccess(t *testing.T) { - - device := make(chan string, 1) - - u := testUpStream{ - commChan: device, - } - - api := deviceApi.New(&u) - - go func() { - - // wait for the rpc call - rpcCall := <-device - - // unmarshal rpc call - var call deviceApi.ApiCall - if err := json.Unmarshal([]byte(rpcCall), &call); err != nil { - panic(err) - } - - requireEqual("DHT:DELETE", call.Type) - - // unmarshal submitted values - var payload DHTGetCall - if err := json.Unmarshal([]byte(call.Data), &payload); err != nil { - panic(err) - } - - requireEqual("/my_key", payload.Key) - - err := api.Receive(call.Id, `{}`) - if err != nil { - panic(err) - } - - }() - - dht := DataStore{api} - - err := dht.Delete(ds.NewKey("my_key")) - require.Nil(t, err) -} - -func TestDHTDeleteError(t *testing.T) { - - device := make(chan string, 1) - - u := testUpStream{ - commChan: device, - } - - api := deviceApi.New(&u) - - go func() { - - // wait for the rpc call - rpcCall := <-device - - // unmarshal rpc call - var call deviceApi.ApiCall - if err := json.Unmarshal([]byte(rpcCall), &call); err != nil { - panic(err) - } - - requireEqual("DHT:DELETE", call.Type) - - // unmarshal submitted values - var payload DHTGetCall - if err := json.Unmarshal([]byte(call.Data), &payload); err != nil { - panic(err) - } - - requireEqual("/my_key", payload.Key) - - err := api.Receive(call.Id, `{"error": "my custom error message"}`) - if err != nil { - panic(err) - } - - }() - - dht := DataStore{api} - - err := dht.Delete(ds.NewKey("my_key")) - require.EqualError(t, err, "my custom error message") -} diff --git a/mesh/mesh.go b/mesh/mesh.go index 4042782..4e27afd 100644 --- a/mesh/mesh.go +++ b/mesh/mesh.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - deviceApi "github.com/Bit-Nation/panthalassa/api/device" + api "github.com/Bit-Nation/panthalassa/api" bootstrap "github.com/florianlenz/go-libp2p-bootstrap" ds "github.com/ipfs/go-datastore" log "github.com/ipfs/go-log" @@ -26,7 +26,7 @@ var bootstrapPeers = []string{ var logger = log.Logger("mesh") -func New(meshPk lp2pCrypto.PrivKey, api *deviceApi.Api, rendezvousKey, signedProfile string) (*Network, <-chan error, error) { +func New(meshPk lp2pCrypto.PrivKey, api *api.API, rendezvousKey, signedProfile string) (*Network, <-chan error, error) { //Create host h, err := lp2p.New(context.Background(), func(cfg *lp2p.Config) error { diff --git a/mobile_interface.go b/mobile_interface.go index baa5a4c..a3bfe8b 100644 --- a/mobile_interface.go +++ b/mobile_interface.go @@ -4,13 +4,15 @@ import ( "encoding/json" "errors" - deviceApi "github.com/Bit-Nation/panthalassa/api/device" + api "github.com/Bit-Nation/panthalassa/api" + apiPB "github.com/Bit-Nation/panthalassa/api/pb" chat "github.com/Bit-Nation/panthalassa/chat" - clientImpl "github.com/Bit-Nation/panthalassa/client" keyManager "github.com/Bit-Nation/panthalassa/keyManager" mesh "github.com/Bit-Nation/panthalassa/mesh" profile "github.com/Bit-Nation/panthalassa/profile" + proto "github.com/golang/protobuf/proto" log "github.com/ipfs/go-log" + "time" ) var panthalassaInstance *Panthalassa @@ -40,7 +42,7 @@ func start(km *keyManager.KeyManager, config StartConfig, client UpStream) error } // device api - api := deviceApi.New(client) + api := api.New(client) // we don't need the rendevouz key for now m, errReporter, err := mesh.New(pk, api, "", config.SignedProfile) @@ -63,18 +65,18 @@ func start(km *keyManager.KeyManager, config StartConfig, client UpStream) error return err } - c, err := chat.New(chatKeyPair, km, clientImpl.New(api, km)) + c, err := chat.New(chatKeyPair, km, api) if err != nil { return err } //Create panthalassa instance panthalassaInstance = &Panthalassa{ - km: km, - upStream: client, - deviceApi: api, - mesh: m, - chat: &c, + km: km, + upStream: client, + api: api, + mesh: m, + chat: &c, } return nil @@ -148,13 +150,23 @@ func EthAddress() (string, error) { return panthalassaInstance.km.GetEthereumAddress() } -func SendResponse(id string, data string) error { +func SendResponse(id string, data string, responseError string, timeout uint) error { if panthalassaInstance == nil { return errors.New("you have to start panthalassa") } - return panthalassaInstance.deviceApi.Receive(id, data) + resp := &apiPB.Response{} + if err := proto.Unmarshal([]byte(data), resp); err != nil { + return err + } + + var err error + if responseError != "" { + err = errors.New(responseError) + } + + return panthalassaInstance.api.Respond(id, resp, err, time.Duration(timeout)*time.Second) } //Export the current account store with given password diff --git a/panthalassa.go b/panthalassa.go index 275a01b..5e3af1d 100644 --- a/panthalassa.go +++ b/panthalassa.go @@ -4,8 +4,7 @@ import ( "encoding/hex" "fmt" - api "github.com/Bit-Nation/panthalassa/api/device" - deviceApi "github.com/Bit-Nation/panthalassa/api/device" + api "github.com/Bit-Nation/panthalassa/api" chat "github.com/Bit-Nation/panthalassa/chat" keyManager "github.com/Bit-Nation/panthalassa/keyManager" mesh "github.com/Bit-Nation/panthalassa/mesh" @@ -14,11 +13,11 @@ import ( ) type Panthalassa struct { - km *keyManager.KeyManager - upStream api.UpStream - deviceApi *deviceApi.Api - mesh *mesh.Network - chat *chat.Chat + km *keyManager.KeyManager + upStream api.UpStream + api *api.API + mesh *mesh.Network + chat *chat.Chat } //Stop the panthalassa instance From bd7e612b52669fd4cc60989d722190fb019f727e Mon Sep 17 00:00:00 2001 From: Florian Lenz Date: Tue, 19 Jun 2018 21:51:21 +0300 Subject: [PATCH 9/9] [cli] removed --- cli/main.go | 364 ---------------------------------------- cli/pangea_key_store.go | 44 ----- cli/upstream.go | 89 ---------- 3 files changed, 497 deletions(-) delete mode 100644 cli/main.go delete mode 100644 cli/pangea_key_store.go delete mode 100644 cli/upstream.go diff --git a/cli/main.go b/cli/main.go deleted file mode 100644 index c9a91c4..0000000 --- a/cli/main.go +++ /dev/null @@ -1,364 +0,0 @@ -package main - -import ( - "encoding/json" - "errors" - "fmt" - "os" - "path/filepath" - - panthalassa "github.com/Bit-Nation/panthalassa" - km "github.com/Bit-Nation/panthalassa/keyManager" - ks "github.com/Bit-Nation/panthalassa/keyStore" - mnemonic "github.com/Bit-Nation/panthalassa/mnemonic" - profile "github.com/Bit-Nation/panthalassa/profile" - log "github.com/ipfs/go-log" - jsonDB "github.com/nanobox-io/golang-scribble" - uuid "github.com/satori/go.uuid" - iShell "gopkg.in/abiosoft/ishell.v2" -) - -const DevRendezvousKey = "akhgp58izorhalsdipfo3uh5orpawoudshfalskduf43topa" -const LogFile = "log.out" -const DBName = ".database" - -var logger = log.Logger("cli") - -type Account struct { - ID string `json:"id"` - Name string `json:"name"` - AccountStore string `json:"account_store"` - Profile string `json:"profile"` -} - -func (a Account) String() string { - return fmt.Sprintf("%s, (%s)", a.Name, a.ID) -} - -func main() { - - //Database - db, err := jsonDB.New(DBName, nil) - if err != nil { - panic(err) - } - - shell := iShell.New() - - var userDB *jsonDB.Driver - - // register command to start panthalassa - shell.AddCmd(&iShell.Cmd{ - Name: "start", - Help: "start panthalassa", - Func: func(c *iShell.Context) { - - // fetch account's - rawAccounts, err := db.ReadAll("account") - if err != nil { - c.Err(err) - return - } - - // exit if not enough account's - if len(rawAccounts) == 0 { - c.Err(errors.New("please create an account first")) - return - } - - accounts := []string{} - myAccounts := map[int]Account{} - - for k, v := range rawAccounts { - - var acc Account - - if err := json.Unmarshal([]byte(v), &acc); err != nil { - c.Err(err) - continue - } - - accounts = append(accounts, acc.String()) - myAccounts[k] = acc - } - - choice := c.MultiChoice(accounts, "Chose your account:") - - selectedAccount, exist := myAccounts[choice] - if !exist { - c.Err(errors.New("account does not exist")) - return - } - - //Ask for password to decrypt account - c.Print("Please enter your password for this account: ") - password := c.ReadLine() - - // create account database - userDB, err = jsonDB.New(filepath.FromSlash(fmt.Sprintf("%s/%s", DBName, selectedAccount.ID)), nil) - if err != nil { - c.Err(err) - return - } - - config := panthalassa.StartConfig{ - EncryptedKeyManager: selectedAccount.AccountStore, - SignedProfile: selectedAccount.Profile, - } - - rawConfig, err := json.Marshal(config) - if err != nil { - c.Err(err) - return - } - - err = panthalassa.Start(string(rawConfig), password, &Store{ - Account: selectedAccount, - DB: userDB, - }) - if err != nil { - c.Err(err) - return - } - - c.Println("Started panthalassa") - - //fetch id key - idPubKey, err := panthalassa.IdentityPublicKey() - if err != nil { - c.Err(err) - return - } - - c.Println("Your identity is: ", idPubKey) - - }, - }) - - // stop panthalassa - shell.AddCmd(&iShell.Cmd{ - Name: "stop", - Help: "stop's the current panthalassa instance", - Func: func(c *iShell.Context) { - userDB = nil - err := panthalassa.Stop() - if err != nil { - c.Err(err) - return - } - c.Println("stopped panthalassa") - }, - }) - - // display private key - shell.AddCmd(&iShell.Cmd{ - Name: "eth:private", - Help: "show's the ethereum private key", - Func: func(c *iShell.Context) { - pk, err := panthalassa.EthPrivateKey() - if err != nil { - c.Err(err) - return - } - c.Println("your private key is: ", pk) - }, - }) - - // display address - shell.AddCmd(&iShell.Cmd{ - Name: "eth:address", - Help: "display ethereum address", - Func: func(c *iShell.Context) { - addr, err := panthalassa.EthAddress() - if err != nil { - c.Err(err) - return - } - - c.Println("your ethereum address is:", addr) - }, - }) - - shell.AddCmd(&iShell.Cmd{ - Name: "log:debug", - Help: "Enable debug logging", - Func: func(c *iShell.Context) { - f, err := os.Create(LogFile) - if err != nil { - c.Err(err) - return - } - log.Configure(log.Output(f), log.LevelDebug) - c.Println("Enabled logging (for debug). Output file: ", f.Name()) - }, - }) - - shell.AddCmd(&iShell.Cmd{ - Name: "log:warn", - Help: "Enable debug logging", - Func: func(c *iShell.Context) { - f, err := os.Create(LogFile) - if err != nil { - c.Err(err) - return - } - log.Configure(log.Output(f)) - //2 = WARNING - log.SetAllLoggers(2) - c.Println("Enabled logging (for warning's). Output file: ", f.Name()) - }, - }) - - shell.AddCmd(&iShell.Cmd{ - Name: "log:info", - Help: "Enable info logging", - Func: func(c *iShell.Context) { - f, err := os.Create(LogFile) - if err != nil { - c.Err(err) - return - } - log.Configure(log.Output(f)) - //2 = WARNING - log.SetAllLoggers(4) - c.Println("Enabled logging (for info's). Output file: ", f.Name()) - }, - }) - - shell.AddCmd(&iShell.Cmd{ - Name: "account:new", - Help: "Create a new Account", - Func: func(c *iShell.Context) { - - c.ShowPrompt(false) - - // get username - c.Println("Account name: ") - accountName := c.ReadLine() - - // get password - c.Print("Password for account: ") - password := c.ReadLine() - - // get location - c.Print("Location: ") - location := c.ReadLine() - - // get image - c.Print("Image") - image := c.ReadLine() - - // create mnemonic - mne, err := mnemonic.New() - if err != nil { - c.Err(err) - return - } - - // create key store form mnemonic - store, err := ks.NewFromMnemonic(mne) - if err != nil { - c.Err(err) - return - } - - // create key manager from key store - keyManager := km.CreateFromKeyStore(store) - exportedAccount, err := keyManager.Export(password, password) - if err != nil { - c.Err(err) - return - } - - // create profile - p, err := profile.SignWithKeyManagerStore(accountName, location, image, exportedAccount, password) - if err != nil { - c.Err(err) - return - } - rawProfile, err := json.Marshal(p) - if err != nil { - c.Err(err) - return - } - - // uuid - id, err := uuid.NewV4() - if err != nil { - c.Err(err) - return - } - - rawStore, err := exportedAccount.Marshal() - if err != nil { - panic(err) - } - - err = db.Write("account", id.String(), &Account{ - ID: id.String(), - Name: accountName, - AccountStore: string(rawStore), - Profile: string(rawProfile), - }) - - c.ShowPrompt(true) - - if err != nil { - c.Err(err) - return - } - - c.Println("safed account store") - - }, - }) - - shell.AddCmd(&iShell.Cmd{ - Name: "contact:add", - Help: "adds a contact to your database", - Func: func(c *iShell.Context) { - - if userDB == nil { - c.Err(errors.New("you need to start panthalassa first")) - return - } - - c.Print("Enter the public key of your contract: ") - pubKey := c.ReadLine() - - err := userDB.Write("contact", pubKey, pubKey) - if err != nil { - c.Err(err) - return - } - c.Println("Safed friend with public key: ", pubKey) - }, - }) - - shell.AddCmd(&iShell.Cmd{ - Name: "contact:list", - Help: "list your contacts", - Func: func(c *iShell.Context) { - - if userDB == nil { - c.Err(errors.New("you need to start panthalassa first")) - return - } - - contacts, err := userDB.ReadAll("contact") - if err != nil { - c.Err(err) - } - - c.Println("your contract's: ") - - for _, contact := range contacts { - c.Println(contact) - } - - }, - }) - - // run shell - shell.Run() -} diff --git a/cli/pangea_key_store.go b/cli/pangea_key_store.go deleted file mode 100644 index f7e3a60..0000000 --- a/cli/pangea_key_store.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "encoding/json" - "strconv" -) - -func NewKeyStore() PangeaKeyStoreDB { - return PangeaKeyStoreDB{ - db: make(map[string]map[string]string), - } -} - -type PangeaKeyStoreDB struct { - db map[string]map[string]string -} - -func (p *PangeaKeyStoreDB) Get(key, msgNum string) string { - return p.db[key][msgNum] -} - -func (p *PangeaKeyStoreDB) Put(key string, msgNum string, messageKey string) { - p.db[key][msgNum] = messageKey -} - -func (p *PangeaKeyStoreDB) DeleteMk(key string, msgNum string) { - delete(p.db[key], msgNum) -} - -func (p *PangeaKeyStoreDB) DeletePk(key string) { - delete(p.db, key) -} - -func (p *PangeaKeyStoreDB) Count(key string) string { - return strconv.Itoa(len(p.db[key])) -} - -func (p *PangeaKeyStoreDB) All() string { - data, err := json.Marshal(p.db) - if err != nil { - panic(err) - } - return string(data) -} diff --git a/cli/upstream.go b/cli/upstream.go deleted file mode 100644 index d624d42..0000000 --- a/cli/upstream.go +++ /dev/null @@ -1,89 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - - panthalassa "github.com/Bit-Nation/panthalassa" - jsonDB "github.com/nanobox-io/golang-scribble" -) - -type apiCall struct { - Type string `json:"type"` - ID string `json:"id"` - Data string `json:"data"` -} - -type response struct { - Error string `json:"error"` - Payload string `json:"payload"` -} - -func unmarshalCall(call string) (apiCall, error) { - - var c apiCall - - if err := json.Unmarshal([]byte(call), &c); err != nil { - return apiCall{}, nil - } - - return c, nil - -} - -type Store struct { - Account Account - DB *jsonDB.Driver -} - -func (s Store) SendResponse(id string, r response) { - - data, err := json.Marshal(r) - if err != nil { - logger.Error(err) - return - } - - logger.Info("answer request: ", id, " data: ", string(data)) - err = panthalassa.SendResponse(id, string(data)) - if err != nil { - logger.Error(err) - return - } - logger.Info("finished request: ", id) - -} - -func (s *Store) Send(data string) { - - call, err := unmarshalCall(data) - if err != nil { - panic(err) - } - - switch call.Type { - case "CONTACT:LIST": - contacts, err := s.DB.ReadAll("contact") - if err != nil { - s.SendResponse(call.ID, response{ - Error: err.Error(), - }) - return - } - jContacts, err := json.Marshal(contacts) - if err != nil { - s.SendResponse(call.ID, response{ - Error: err.Error(), - }) - return - } - s.SendResponse(call.ID, response{ - Payload: string(jContacts), - }) - default: - s.SendResponse(call.ID, response{ - Error: fmt.Sprintf("couldn't process call with type: %s", call.Type), - }) - } - -}