• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / VCVerifier / 15674278844

16 Jun 2025 07:13AM UTC coverage: 37.558% (-7.8%) from 45.372%
15674278844

push

github

web-flow
Merge pull request #58 from FIWARE/jwt-inclusion

Jwt inclusion

99 of 674 new or added lines in 13 files covered. (14.69%)

14 existing lines in 3 files now uncovered.

1215 of 3235 relevant lines covered (37.56%)

0.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/verifier/presentation_parser.go
1
package verifier
2

3
import (
4
        "context"
5
        "errors"
6
        "net/http"
7
        "strings"
8
        "time"
9

10
        configModel "github.com/fiware/VCVerifier/config"
11
        "github.com/fiware/VCVerifier/jades"
12
        "github.com/fiware/VCVerifier/logging"
13
        "github.com/hellofresh/health-go/v5"
14
        "github.com/piprate/json-gold/ld"
15
        "github.com/trustbloc/vc-go/proof/defaults"
16
        sdv "github.com/trustbloc/vc-go/sdjwt/verifier"
17
        "github.com/trustbloc/vc-go/verifiable"
18
)
19

20
var ErrorNoValidationEndpoint = errors.New("no_validation_endpoint_configured")
21
var ErrorNoValidationHost = errors.New("no_validation_host_configured")
22

23
var defaultPresentationOptions = []verifiable.PresentationOpt{
24
        verifiable.WithPresProofChecker(defaults.NewDefaultProofChecker(JWTVerfificationMethodResolver{})),
25
        verifiable.WithPresJSONLDDocumentLoader(NewCachingDocumentLoader(ld.NewDefaultDocumentLoader(http.DefaultClient)))}
26

27
var defaultSdJwtParserOptions = []sdv.ParseOpt{
28
        sdv.WithSignatureVerifier(defaults.NewDefaultProofChecker(JWTVerfificationMethodResolver{})),
29
        sdv.WithHolderVerificationRequired(false),
30
        sdv.WithIssuerSigningAlgorithms([]string{"ES256", "PS256"}),
31
}
32

33
// allow singleton access to the parser
34
var presentationParser PresentationParser
35

36
// allow singleton access to the parser
37
var sdJwtParser SdJwtParser
38

39
// parser interface
40
type PresentationParser interface {
41
        ParsePresentation(tokenBytes []byte) (*verifiable.Presentation, error)
42
}
43

44
type SdJwtParser interface {
45
        Parse(tokenString string) (map[string]interface{}, error)
46
}
47

48
type ConfigurablePresentationParser struct {
49
        PresentationOpts []verifiable.PresentationOpt
50
}
51

52
type ConfigurableSdJwtParser struct {
53
        ParserOpts []sdv.ParseOpt
54
}
55

56
/**
57
* Global singelton access to the parser
58
**/
NEW
59
func GetSdJwtParser() SdJwtParser {
×
NEW
60
        if sdJwtParser == nil {
×
NEW
61
                logging.Log().Error("SdJwtParser is not initialized.")
×
NEW
62
        }
×
NEW
63
        return sdJwtParser
×
64
}
65

66
/**
67
* Global singelton access to the parser
68
**/
69
func GetPresentationParser() PresentationParser {
×
70
        if presentationParser == nil {
×
71
                logging.Log().Error("PresentationParser is not initialized.")
×
72
        }
×
73
        return presentationParser
×
74
}
75

76
// init the presentation parser depending on the config, either with or without did:elsi support
77
func InitPresentationParser(config *configModel.Configuration, healthCheck *health.Health) error {
×
78
        elsiConfig := &config.Elsi
×
79
        err := validateConfig(elsiConfig)
×
80
        if err != nil {
×
81
                logging.Log().Warnf("No valid elsi configuration provided. Error: %v", err)
×
82
                return err
×
83
        }
×
84
        if elsiConfig.Enabled {
×
85
                jAdESValidator := &jades.ExternalJAdESValidator{
×
86
                        HttpClient:        &http.Client{},
×
87
                        ValidationAddress: buildAddress(elsiConfig.ValidationEndpoint.Host, elsiConfig.ValidationEndpoint.ValidationPath),
×
88
                        HealthAddress:     buildAddress(elsiConfig.ValidationEndpoint.Host, elsiConfig.ValidationEndpoint.HealthPath)}
×
89

×
90
                elsiProofChecker := &ElsiProofChecker{
×
91
                        defaultChecker: defaults.NewDefaultProofChecker(JWTVerfificationMethodResolver{}),
×
92
                        jAdESValidator: jAdESValidator,
×
93
                }
×
94

×
95
                healthCheck.Register(health.Config{
×
96
                        Name:      "JAdES-Validator",
×
97
                        Timeout:   time.Second * 5,
×
98
                        SkipOnErr: false,
×
99
                        Check: func(ctx context.Context) error {
×
100
                                return jAdESValidator.IsReady()
×
101
                        },
×
102
                })
103

104
                presentationParser = &ConfigurablePresentationParser{PresentationOpts: []verifiable.PresentationOpt{
×
105
                        verifiable.WithPresProofChecker(elsiProofChecker),
×
106
                        verifiable.WithPresJSONLDDocumentLoader(NewCachingDocumentLoader(ld.NewDefaultDocumentLoader(http.DefaultClient)))}}
×
107
        } else {
×
108
                presentationParser = &ConfigurablePresentationParser{PresentationOpts: defaultPresentationOptions}
×
109
        }
×
NEW
110
        sdJwtParser = &ConfigurableSdJwtParser{ParserOpts: defaultSdJwtParserOptions}
×
NEW
111

×
UNCOV
112
        return nil
×
113
}
114

115
func validateConfig(elsiConfig *configModel.Elsi) error {
×
116
        if !elsiConfig.Enabled {
×
117
                return nil
×
118
        }
×
119
        if elsiConfig.ValidationEndpoint == nil {
×
120
                return ErrorNoValidationEndpoint
×
121
        }
×
122
        if elsiConfig.ValidationEndpoint.Host == "" {
×
123
                return ErrorNoValidationHost
×
124
        }
×
125
        return nil
×
126
}
127

128
func buildAddress(host, path string) string {
×
129
        return strings.TrimSuffix(host, "/") + "/" + strings.TrimPrefix(path, "/")
×
130
}
×
131

132
func (cpp *ConfigurablePresentationParser) ParsePresentation(tokenBytes []byte) (*verifiable.Presentation, error) {
×
133
        return verifiable.ParsePresentation(tokenBytes, cpp.PresentationOpts...)
×
134
}
×
135

NEW
136
func (sjp *ConfigurableSdJwtParser) Parse(tokenString string) (map[string]interface{}, error) {
×
NEW
137
        return sdv.Parse(tokenString, sjp.ParserOpts...)
×
NEW
138
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc