From dba30a63a95cbd440a7d49ffbe32110e505734d7 Mon Sep 17 00:00:00 2001 From: Derek Trider Date: Wed, 30 Sep 2020 14:41:23 -0400 Subject: [PATCH] WIP: feat: SDS EDV provider skeleton Signed-off-by: Derek Trider --- .../encryptedstorage/sds/edv/edvstore.go | 68 +++++++++++++++++++ .../ariesencrypteddocumentprocessor.go | 32 +++++++++ .../encrypteddocumentprocessor.go | 14 ++++ .../encryptedstorage/sds/edv/models.go | 65 ++++++++++++++++++ .../sds/edv/restprovider/restprovider.go | 48 +++++++++++++ pkg/storage/jsindexeddb/jsindexeddb.go | 4 ++ pkg/storage/leveldb/leveldb_store.go | 4 ++ pkg/storage/mem/mem_store.go | 4 ++ pkg/storage/mysql/mysqlstore.go | 4 ++ pkg/storage/store.go | 4 ++ 10 files changed, 247 insertions(+) create mode 100644 pkg/storage/encryptedstorage/sds/edv/edvstore.go create mode 100644 pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor/ariesencrypteddocumentprocessor/ariesencrypteddocumentprocessor.go create mode 100644 pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor/encrypteddocumentprocessor.go create mode 100644 pkg/storage/encryptedstorage/sds/edv/models.go create mode 100644 pkg/storage/encryptedstorage/sds/edv/restprovider/restprovider.go diff --git a/pkg/storage/encryptedstorage/sds/edv/edvstore.go b/pkg/storage/encryptedstorage/sds/edv/edvstore.go new file mode 100644 index 0000000000..13727e8419 --- /dev/null +++ b/pkg/storage/encryptedstorage/sds/edv/edvstore.go @@ -0,0 +1,68 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package edvstore + +import ( + "github.com/hyperledger/aries-framework-go/pkg/storage" + "github.com/hyperledger/aries-framework-go/pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor" +) + +type Provider struct { + underlyingProvider storage.Provider + encryptedDocumentProcessor encrypteddocumentprocessor.EncryptedDocumentProcessor +} + +func New(underlyingProvider storage.Provider, + encryptedDocumentProcessor encrypteddocumentprocessor.EncryptedDocumentProcessor) (Provider, error) { + return Provider{ + underlyingProvider: underlyingProvider, + encryptedDocumentProcessor: encryptedDocumentProcessor, + }, nil +} + +func (p Provider) OpenStore(name string) (Store, error) { + panic("implement me") +} + +func (p Provider) CloseStore(name string) error { + panic("implement me") +} + +func (p Provider) Close() error { + panic("implement me") +} + +type Store struct { + underlyingStore storage.Store + encryptedDocumentProcessor encrypteddocumentprocessor.EncryptedDocumentProcessor +} + +func (s Store) Put(k string, v []byte) error { + // Use encrypted document processor to take the raw data v and convert it into an encrypted document. + // Then, we'll marshal it back into bytes and put it in the underlying store. + + panic("implement me") +} + +func (s Store) Get(k string) ([]byte, error) { + // Get the encrypted document from the underlying store. Then, feed it into the processor to get the original + // raw data back. Then, marshal back to bytes so we can return it back. + + panic("implement me") +} + +func (s Store) Iterator(startKey, endKey string) storage.StoreIterator { + panic("implement me") +} + +func (s Store) Delete(k string) error { + panic("implement me") +} + +func (s Store) Query(query string) ([]string, error) { + panic("implement me") +} diff --git a/pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor/ariesencrypteddocumentprocessor/ariesencrypteddocumentprocessor.go b/pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor/ariesencrypteddocumentprocessor/ariesencrypteddocumentprocessor.go new file mode 100644 index 0000000000..8d6f2b2c29 --- /dev/null +++ b/pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor/ariesencrypteddocumentprocessor/ariesencrypteddocumentprocessor.go @@ -0,0 +1,32 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package ariesencrypteddocumentprocessor + +import ( + "github.com/hyperledger/aries-framework-go/pkg/doc/jose" + "github.com/hyperledger/aries-framework-go/pkg/storage/encryptedstorage/sds/edv" +) + +type EncryptedDocumentProcessor struct { + jweEncryptor jose.Encrypter + jweDecryptor jose.Decrypter +} + +func New(jweEncryptor jose.Encrypter, jweDecryptor jose.Decrypter) (EncryptedDocumentProcessor, error) { + return EncryptedDocumentProcessor{ + jweEncryptor: jweEncryptor, + jweDecryptor: jweDecryptor, + }, nil +} + +func (e EncryptedDocumentProcessor) Encrypt(bytes []byte) (edvstore.EncryptedDocument, error) { + panic("implement me") +} + +func (e EncryptedDocumentProcessor) Decrypt(document edvstore.EncryptedDocument) ([]byte, error) { + panic("implement me") +} diff --git a/pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor/encrypteddocumentprocessor.go b/pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor/encrypteddocumentprocessor.go new file mode 100644 index 0000000000..1f2e301a2f --- /dev/null +++ b/pkg/storage/encryptedstorage/sds/edv/encrypteddocumentprocessor/encrypteddocumentprocessor.go @@ -0,0 +1,14 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package encrypteddocumentprocessor + +import "github.com/hyperledger/aries-framework-go/pkg/storage/encryptedstorage/sds/edv" + +type EncryptedDocumentProcessor interface { + Encrypt([]byte) (edvstore.EncryptedDocument, error) + Decrypt(edvstore.EncryptedDocument) ([]byte, error) +} diff --git a/pkg/storage/encryptedstorage/sds/edv/models.go b/pkg/storage/encryptedstorage/sds/edv/models.go new file mode 100644 index 0000000000..422cb12bcc --- /dev/null +++ b/pkg/storage/encryptedstorage/sds/edv/models.go @@ -0,0 +1,65 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package edvstore + +import "encoding/json" + +// DataVaultConfiguration represents a Data Vault Configuration. +type DataVaultConfiguration struct { + Sequence int `json:"sequence"` + Controller string `json:"controller"` + Invoker string `json:"invoker"` + Delegator string `json:"delegator"` + ReferenceID string `json:"referenceId"` + KEK IDTypePair `json:"kek"` + HMAC IDTypePair `json:"hmac"` +} + +// StructuredDocument represents a Structured Document. +type StructuredDocument struct { + ID string `json:"id"` + Meta map[string]interface{} `json:"meta"` + Content map[string]interface{} `json:"content"` +} + +// EncryptedDocument represents an Encrypted Document. +type EncryptedDocument struct { + ID string `json:"id"` + Sequence int `json:"sequence"` + IndexedAttributeCollections []IndexedAttributeCollection `json:"indexed,omitempty"` + JWE json.RawMessage `json:"jwe"` +} + +// IndexedAttributeCollection represents a collection of indexed attributes, +// all of which share a common MAC algorithm and key. +type IndexedAttributeCollection struct { + Sequence int `json:"sequence"` + HMAC IDTypePair `json:"hmac"` + IndexedAttributes []IndexedAttribute `json:"attributes"` +} + +// IndexedAttribute represents a single indexed attribute. +type IndexedAttribute struct { + Name string `json:"name"` + Value string `json:"value"` + Unique bool `json:"unique"` +} + +// IDTypePair represents an ID+Type pair. +type IDTypePair struct { + ID string `json:"id"` + Type string `json:"type"` +} + +// Query represents a name+value pair that can be used to query the encrypted indices for specific data. +// The format of the "equals" part does not seem to be fully defined in the spec currently, hence why in this +// model it was left as a general json.RawMessage for now. +// https://github.com/decentralized-identity/secure-data-store/issues/34 +type Query struct { + Name string `json:"index"` + Value json.RawMessage `json:"equals"` +} diff --git a/pkg/storage/encryptedstorage/sds/edv/restprovider/restprovider.go b/pkg/storage/encryptedstorage/sds/edv/restprovider/restprovider.go new file mode 100644 index 0000000000..d1c1703311 --- /dev/null +++ b/pkg/storage/encryptedstorage/sds/edv/restprovider/restprovider.go @@ -0,0 +1,48 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package restprovider + +import "github.com/hyperledger/aries-framework-go/pkg/storage" + +// Talks to an SDS EDV server via REST calls. +type RESTProvider struct { +} + +func (R RESTProvider) OpenStore(name string) (storage.Store, error) { + panic("implement me") +} + +func (R RESTProvider) CloseStore(name string) error { + panic("implement me") +} + +func (R RESTProvider) Close() error { + panic("implement me") +} + +type RESTStore struct { +} + +func (R RESTStore) Put(k string, v []byte) error { + panic("implement me") +} + +func (R RESTStore) Get(k string) ([]byte, error) { + panic("implement me") +} + +func (R RESTStore) Iterator(startKey, endKey string) storage.StoreIterator { + panic("implement me") +} + +func (R RESTStore) Delete(k string) error { + panic("implement me") +} + +func (R RESTStore) Query(query string) (storage.StoreIterator, error) { + panic("implement me") +} diff --git a/pkg/storage/jsindexeddb/jsindexeddb.go b/pkg/storage/jsindexeddb/jsindexeddb.go index a53b05ef76..786391f594 100644 --- a/pkg/storage/jsindexeddb/jsindexeddb.go +++ b/pkg/storage/jsindexeddb/jsindexeddb.go @@ -196,6 +196,10 @@ func (s *store) Delete(k string) error { return nil } +func (s *store) Query(query string) (StoreIterator, error) { + panic("implement me") +} + type iterator struct { batch *js.Value err error diff --git a/pkg/storage/leveldb/leveldb_store.go b/pkg/storage/leveldb/leveldb_store.go index 42a41c147b..3f799f37c5 100644 --- a/pkg/storage/leveldb/leveldb_store.go +++ b/pkg/storage/leveldb/leveldb_store.go @@ -113,6 +113,10 @@ type leveldbStore struct { db *leveldb.DB } +func (s *leveldbStore) Query(query string) (storage.StoreIterator, error) { + panic("implement me") +} + // Put stores the key and the record. func (s *leveldbStore) Put(k string, v []byte) error { if k == "" || v == nil { diff --git a/pkg/storage/mem/mem_store.go b/pkg/storage/mem/mem_store.go index c58ced1f05..7efab0dd3d 100644 --- a/pkg/storage/mem/mem_store.go +++ b/pkg/storage/mem/mem_store.go @@ -96,6 +96,10 @@ type memStore struct { sync.RWMutex } +func (s *memStore) Query(query string) (storage.StoreIterator, error) { + panic("implement me") +} + // Put stores the key and the record. func (s *memStore) Put(k string, v []byte) error { if k == "" || v == nil { diff --git a/pkg/storage/mysql/mysqlstore.go b/pkg/storage/mysql/mysqlstore.go index 705ff28d58..acf46fcb51 100644 --- a/pkg/storage/mysql/mysqlstore.go +++ b/pkg/storage/mysql/mysqlstore.go @@ -32,6 +32,10 @@ type sqlDBStore struct { tableName string } +func (s *sqlDBStore) Query(query string) (storage.StoreIterator, error) { + panic("implement me") +} + type result struct { key string value []byte diff --git a/pkg/storage/store.go b/pkg/storage/store.go index 286e987064..ee3a57ee87 100644 --- a/pkg/storage/store.go +++ b/pkg/storage/store.go @@ -55,6 +55,10 @@ type Store interface { // Delete will delete a record with k key Delete(k string) error + + // Query queries the store for data based on the provided query string, the format of + // which will be dependent on what the underlying store requires. + Query(query string) (StoreIterator, error) } // StoreIterator is the iterator for the latest snapshot of the underlying store.