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

Support key access in all services #110

Merged
merged 14 commits into from
Sep 28, 2022

Conversation

decentralgabe
Copy link
Member

@decentralgabe decentralgabe commented Sep 24, 2022

A few things:

  • Types to support an abstraction over string and []byte request/responses for key access
  • Added key storage to all services
  • Swapped out key storage for the DID service to use the key store
  • Found a few issues with manifest, swapped out the impl to rely on the credential service instead of building credentials directly. Added a number of TODOs to go over with @nitro-neal
  • Refactored some tests to mock out test services/routers a bit more uniformly

next up: actually signing / verifying objects

@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2022

Codecov Report

Attention: Patch coverage is 25.31646% with 59 lines in your changes missing coverage. Please review.

Project coverage is 28.20%. Comparing base (ce425c4) to head (26067d8).
Report is 369 commits behind head on main.

Files with missing lines Patch % Lines
config/config.go 0.00% 26 Missing ⚠️
pkg/service/keystore/keystore.go 0.00% 21 Missing ⚠️
internal/keyaccess/jwt.go 59.25% 6 Missing and 5 partials ⚠️
pkg/server/router/manifest.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #110      +/-   ##
==========================================
- Coverage   28.53%   28.20%   -0.34%     
==========================================
  Files          18       18              
  Lines        1146     1202      +56     
==========================================
+ Hits          327      339      +12     
- Misses        775      815      +40     
- Partials       44       48       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

gabe added 5 commits September 27, 2022 13:50
…-all-services-ose-122

* origin/main:
  SIP-4: DWN Routes (#113)
  Update README.md
  Add Sip 4 to table (#109)
  Adding SIP4 Doc (#108)

# Conflicts:
#	config/compose.toml
#	config/config.go
#	config/config.toml
#	go.mod
#	go.sum
#	pkg/server/server_test.go
#	pkg/service/service.go
@decentralgabe decentralgabe marked this pull request as ready for review September 28, 2022 00:31
func (ka DataIntegrityKeyAccess) Sign(payload cryptosuite.Provable) ([]byte, error) {
// DataIntegrityJSON represents a response from a DataIntegrityKeyAccess.Sign() call represented
// as a serialized JSON object
type DataIntegrityJSON struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -1,13 +1,15 @@
package router

import (
"os"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to make sure I'm on the same linter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2022-09-28 at 2 44 36 PM

@@ -31,16 +33,16 @@ func NewBoltDIDStorage(db *storage.BoltDB) (*BoltDIDStorage, error) {
}

func (b BoltDIDStorage) StoreDID(did StoredDID) error {
couldNotStoreDIDErr := fmt.Sprintf("could not store DID: %s", did.DID.ID)
namespace, err := getNamespaceForDID(did.DID.ID)
couldNotStoreDIDErr := fmt.Sprintf("could not store DID: %s", did.ID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I think Schema does this too?

@@ -10,9 +10,8 @@ import (
)

type StoredDID struct {
ID string `json:"id"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you put a top level ID I see

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for simpler indexing in the db

return nil, errors.Wrap(err, "could not store did:key private key")
}

privKeyBase58, err := privateKeyToBase58(privKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this happen before you store the key?

Because there could be a case where you store a key but you can't convert it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good call out

return b.db.Write(namespace, id, keyBytes)

// encrypt key before storing
encryptedKey, err := util.XChaCha20Poly1305Encrypt(b.serviceKey, keyBytes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wild names for encryption these days

}, nil
}

func (s Service) CreateManifest(request CreateManifestRequest) (*CreateManifestResponse, error) {
logrus.Debugf("creating manifest: %+v", request)
logrus.Debugf("creating m: %+v", request)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change log lines 'm' to manifest

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh

@@ -154,7 +147,7 @@ func isValidApplication(gotManifest *manifeststorage.StoredManifest, application
return nil
}

func (s Service) SubmitApplication(request SubmitApplicationRequest) (*SubmitApplicationResponse, error) {
func (s Service) ProcessApplicationSubmission(request SubmitApplicationRequest) (*SubmitApplicationResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good name change

credentialBuilder.SetIssuanceDate(time.Now().Format(time.RFC3339))

cred, err := credentialBuilder.Build()
createdResponse, err := s.credential.CreateCredential(credentialRequest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to be credentialResponse

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member Author

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made changes

@@ -10,9 +10,8 @@ import (
)

type StoredDID struct {
ID string `json:"id"`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for simpler indexing in the db

}, nil
}

func (s Service) CreateManifest(request CreateManifestRequest) (*CreateManifestResponse, error) {
logrus.Debugf("creating manifest: %+v", request)
logrus.Debugf("creating m: %+v", request)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh

credentialBuilder.SetIssuanceDate(time.Now().Format(time.RFC3339))

cred, err := credentialBuilder.Build()
createdResponse, err := s.credential.CreateCredential(credentialRequest)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@decentralgabe decentralgabe merged commit 23ad921 into main Sep 28, 2022
@decentralgabe decentralgabe deleted the support-key-access-in-all-services-ose-122 branch September 28, 2022 23:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants