Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
WIP: feat: SDS EDV provider skeleton
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Trider <Derek.Trider@securekey.com>
  • Loading branch information
Derek Trider committed Sep 30, 2020
1 parent e42562d commit dba30a6
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 0 deletions.
68 changes: 68 additions & 0 deletions pkg/storage/encryptedstorage/sds/edv/edvstore.go
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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)
}
65 changes: 65 additions & 0 deletions pkg/storage/encryptedstorage/sds/edv/models.go
Original file line number Diff line number Diff line change
@@ -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"`
}
48 changes: 48 additions & 0 deletions pkg/storage/encryptedstorage/sds/edv/restprovider/restprovider.go
Original file line number Diff line number Diff line change
@@ -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")
}
4 changes: 4 additions & 0 deletions pkg/storage/jsindexeddb/jsindexeddb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/leveldb/leveldb_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/mem/mem_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/mysql/mysqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit dba30a6

Please sign in to comment.