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: wallet-cli add SignJwtClaims #1523

Merged
merged 3 commits into from
Nov 20, 2023
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
18 changes: 18 additions & 0 deletions component/wallet-cli/pkg/walletrunner/wallet_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package walletrunner
import (
"crypto/tls"
_ "embed"
"errors"
"fmt"
"net/http"
"net/http/cookiejar"
Expand Down Expand Up @@ -160,6 +161,23 @@ func New(vcProviderType string, opts ...vcprovider.ConfigOption) (*Service, erro
}, nil
}

func (s *Service) SignJwtClaims(
claims interface{},
headers map[string]interface{},
) (string, error) {
jws, err := signTokenJWT(claims,
s.vcProviderConf.WalletParams.DidKeyID[0],
s.ariesServices.suite,
s.vcProviderConf.WalletParams.SignType,
headers,
)
if err != nil {
return "", errors.Join(err, errors.New("can not sign claims"))
}

return jws, nil
}

func (s *Service) GetConfig() *vcprovider.Config {
return s.vcProviderConf
}
Expand Down
28 changes: 23 additions & 5 deletions component/wallet-cli/pkg/walletrunner/wallet_runner_oidc4vp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"github.com/trustbloc/vcs/component/wallet-cli/pkg/oidc4vp"
"io"
"log"
"net/http"
"net/url"
"strings"
"time"

"github.com/trustbloc/vcs/component/wallet-cli/pkg/oidc4vp"

"github.com/google/uuid"
"github.com/trustbloc/did-go/method/jwk"
"github.com/trustbloc/kms-go/spi/kms"
Expand Down Expand Up @@ -373,7 +374,13 @@ func (e *VPFlowExecutor) getIDTokenClaims(requestPresentationSubmission *presexc
}

func (e *VPFlowExecutor) signIDTokenJWT(idToken *IDTokenClaims, signatureType vcs.SignatureType) (string, error) {
idTokenJWS, err := signTokenJWT(idToken, e.walletDidKeyID[0], e.ariesServices.suite, signatureType)
idTokenJWS, err := signTokenJWT(
idToken,
e.walletDidKeyID[0],
e.ariesServices.suite,
signatureType,
map[string]interface{}{"typ": "JWT"},
)
if err != nil {
return "", fmt.Errorf("sign id_token: %w", err)
}
Expand Down Expand Up @@ -527,7 +534,13 @@ func (e *VPFlowExecutor) signPresentationJWT(vp *verifiable.Presentation, signat

vpTokenJWS := strings.ReplaceAll(string(vpTokenBytes), `"type":"VerifiablePresentation"`, `"type":["VerifiablePresentation"]`)

vpTokenJWS, err = signTokenJWT(vpTokenJWS, didKeyID, e.ariesServices.suite, signatureType)
vpTokenJWS, err = signTokenJWT(
vpTokenJWS,
didKeyID,
e.ariesServices.suite,
signatureType,
map[string]interface{}{"typ": "JWT"},
)
if err != nil {
return "", fmt.Errorf("sign vp_token: %w", err)
}
Expand Down Expand Up @@ -617,7 +630,12 @@ func (e *VPFlowExecutor) GetSubjectID(creds []*verifiable.Credential) (string, e
return subjectID, nil
}

func signTokenJWT(claims interface{}, didKeyID string, suite api.Suite, signType vcs.SignatureType,
func signTokenJWT(
claims interface{},
didKeyID string,
suite api.Suite,
signType vcs.SignatureType,
headers map[string]interface{},
) (string, error) {
fks, err := suite.FixedKeyMultiSigner(strings.Split(didKeyID, "#")[1])
if err != nil {
Expand All @@ -644,7 +662,7 @@ func signTokenJWT(claims interface{}, didKeyID string, suite api.Suite, signType
signerKeyID = res.DIDDocument.VerificationMethod[0].ID
}

token, err := jwt.NewJoseSigned(claims, map[string]interface{}{"typ": "JWT"}, NewJWSSigner(signerKeyID,
token, err := jwt.NewJoseSigned(claims, headers, NewJWSSigner(signerKeyID,
string(signType), kmsSigner))
if err != nil {
return "", fmt.Errorf("initiate oidc interaction: sign token failed: %w", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/kms/mocks/kms_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading