Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: encrypted credential response #1578

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
347 changes: 177 additions & 170 deletions api/spec/openapi.gen.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/vc-rest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.0
github.com/deepmap/oapi-codegen v1.11.0
github.com/dgraph-io/ristretto v0.1.1
github.com/go-jose/go-jose/v3 v3.0.1-0.20221117193127-916db76e8214
github.com/google/uuid v1.3.0
github.com/labstack/echo/v4 v4.10.2
github.com/ory/dockertest/v3 v3.9.1
Expand Down Expand Up @@ -97,7 +98,6 @@ require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getkin/kin-openapi v0.94.0 // indirect
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 // indirect
github.com/go-jose/go-jose/v3 v3.0.1-0.20221117193127-916db76e8214 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
Expand Down
27 changes: 20 additions & 7 deletions cmd/vc-rest/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@
oapimw "github.com/deepmap/oapi-codegen/pkg/middleware"
"github.com/deepmap/oapi-codegen/pkg/securityprovider"
"github.com/dgraph-io/ristretto"
"github.com/trustbloc/did-go/doc/ld/documentloader"
"github.com/trustbloc/vc-go/proof/defaults"
"github.com/trustbloc/vc-go/vermethod"
"go.mongodb.org/mongo-driver/mongo"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"

"github.com/go-jose/go-jose/v3"
"github.com/labstack/echo/v4"
echomw "github.com/labstack/echo/v4/middleware"
jsonld "github.com/piprate/json-gold/ld"
echopprof "github.com/sevenNt/echo-pprof"
"github.com/spf13/cobra"
"github.com/trustbloc/did-go/doc/ld/context/remote"
"github.com/trustbloc/did-go/doc/ld/documentloader"
"github.com/trustbloc/logutil-go/pkg/log"
"github.com/trustbloc/vc-go/proof/defaults"
"github.com/trustbloc/vc-go/vermethod"
"go.mongodb.org/mongo-driver/mongo"
"go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws"
"go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"

"github.com/trustbloc/vcs/api/spec"
"github.com/trustbloc/vcs/component/credentialstatus"
Expand Down Expand Up @@ -702,6 +702,7 @@
AckStore: ackStore,
ProfileSvc: issuerProfileSvc,
})

oidc4ciService, err = oidc4ci.NewService(&oidc4ci.Config{
TransactionStore: oidc4ciTransactionStore,
ClaimDataStore: oidc4ciClaimDataStore,
Expand Down Expand Up @@ -811,6 +812,17 @@
TransactionStore: oidc4ciTransactionStore,
})

jweEncrypterCreator := func(jwk jose.JSONWebKey, alg jose.KeyAlgorithm, enc jose.ContentEncryption) (jose.Encrypter, error) { //nolint:lll
return jose.NewEncrypter(
enc,
jose.Recipient{
Algorithm: alg,
Key: jwk,
},
nil,
)

Check warning on line 823 in cmd/vc-rest/startcmd/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/vc-rest/startcmd/start.go#L816-L823

Added lines #L816 - L823 were not covered by tests
}

oidc4civ1.RegisterHandlers(e, oidc4civ1.NewController(&oidc4civ1.Config{
OAuth2Provider: oauthProvider,
StateStore: oidc4ciStateStore,
Expand All @@ -824,6 +836,7 @@
ClientIDSchemeService: clientIDSchemeSvc,
Tracer: conf.Tracer,
AckService: ackService,
JWEEncrypterCreator: jweEncrypterCreator,
}))

oidc4vpv1.RegisterHandlers(e, oidc4vpv1.NewController(&oidc4vpv1.Config{
Expand Down
118 changes: 80 additions & 38 deletions docs/v1/openapi.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pkg/profile/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ type OIDCConfig struct {
WalletInitiatedAuthFlowSupported bool `json:"wallet_initiated_auth_flow_supported"`
SignedCredentialOfferSupported bool `json:"signed_credential_offer_supported"`
SignedIssuerMetadataSupported bool `json:"signed_issuer_metadata_supported"`
CredentialResponseAlgValuesSupported []string `json:"credential_response_alg_values_supported"`
CredentialResponseEncValuesSupported []string `json:"credential_response_enc_values_supported"`
CredentialResponseEncryptionRequired bool `json:"credential_response_encryption_required"`
ClaimsEndpoint string `json:"claims_endpoint"`
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/restapi/v1/issuer/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,10 @@
return resterr.NewCustomError(resterr.ClaimsValidationErr, err)
}

if err = validateCredentialResponseEncryption(profile, body.RequestedCredentialResponseEncryption); err != nil {
return err
}

signedCredential, err := c.signCredential(
ctx, result.Credential, profile, issuecredential.WithTransactionID(body.TxId))
if err != nil {
Expand Down Expand Up @@ -906,6 +910,44 @@
return nil, fmt.Errorf("invalid type for credential subject: %T", subject)
}

func validateCredentialResponseEncryption(
profile *profileapi.Issuer,
requested *RequestedCredentialResponseEncryption,
) error {
if profile.OIDCConfig == nil {
return nil

Check warning on line 918 in pkg/restapi/v1/issuer/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/restapi/v1/issuer/controller.go#L918

Added line #L918 was not covered by tests
}

if profile.OIDCConfig.CredentialResponseEncryptionRequired && requested == nil {
return resterr.NewValidationError(resterr.InvalidValue, "credential_response_encryption",
errors.New("credential response encryption is required"))
}

alg := ""
if requested != nil {
alg = requested.Alg
}

if len(profile.OIDCConfig.CredentialResponseAlgValuesSupported) > 0 &&
!lo.Contains(profile.OIDCConfig.CredentialResponseAlgValuesSupported, alg) {
return resterr.NewValidationError(resterr.InvalidValue, "credential_response_encryption.alg",
fmt.Errorf("alg %s not supported", requested.Alg))
}

enc := ""
if requested != nil {
enc = requested.Enc
}

if len(profile.OIDCConfig.CredentialResponseEncValuesSupported) > 0 &&
!lo.Contains(profile.OIDCConfig.CredentialResponseEncValuesSupported, enc) {
return resterr.NewValidationError(resterr.InvalidValue, "credential_response_encryption.enc",
fmt.Errorf("enc %s not supported", requested.Enc))
}

return nil
}

// OpenidCredentialIssuerConfig request VCS IDP OIDC Configuration.
// GET /issuer/{profileID}/{profileVersion}/.well-known/openid-credential-issuer.
func (c *Controller) OpenidCredentialIssuerConfig(ctx echo.Context, profileID, profileVersion string) error {
Expand Down
Loading
Loading