Skip to content

Commit 06f1aa4

Browse files
authored
Merge pull request #75 from FIWARE/fix/empty-scopes
Fix VC authentication
2 parents 860bc6b + 9378297 commit 06f1aa4

5 files changed

Lines changed: 55 additions & 45 deletions

File tree

.github/workflows/release.yml

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ jobs:
1717
version: ${{ steps.out.outputs.version }}
1818

1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v6
2121

22-
- uses: actions/setup-java@v1
22+
- uses: actions/setup-java@v5
2323
with:
24+
distribution: 'temurin'
2425
java-version: '11'
25-
java-package: jdk
2626

2727
- id: pr
2828
uses: actions-ecosystem/action-get-merged-pull-request@v1.0.1
2929
with:
3030
github_token: ${{ secrets.GITHUB_TOKEN }}
3131

32-
- uses: zwaldowski/semver-release-action@v2
32+
- uses: zwaldowski/semver-release-action@v6
3333
with:
3434
dry_run: true
3535
bump: ${{ steps.pr.outputs.labels }}
@@ -44,40 +44,45 @@ jobs:
4444
vcverifier:
4545
needs: [ "generate-version" ]
4646
runs-on: ubuntu-latest
47-
47+
4848
steps:
49-
- uses: actions/checkout@v2
49+
- uses: actions/checkout@v6
5050

51-
- name: Build Image
52-
id: build-image
53-
uses: redhat-actions/buildah-build@v2
54-
with:
55-
image: vcverifier
56-
tags: latest ${{ github.sha }} ${{needs.generate-version.outputs.version}}
57-
dockerfiles: |
58-
./Dockerfile
59-
context: ./
60-
61-
- name: Push To quay.io
62-
id: push-to-quay
63-
uses: redhat-actions/push-to-registry@v2
51+
- name: Set up QEMU
52+
uses: docker/setup-qemu-action@v3
53+
54+
- name: Set up Docker Buildx
55+
uses: docker/setup-buildx-action@v3
56+
57+
- name: Login to Quay.io
58+
uses: docker/login-action@v3
6459
with:
65-
image: ${{ steps.build-image.outputs.image }}
66-
tags: ${{ steps.build-image.outputs.tags }}
67-
registry: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}
60+
registry: quay.io
6861
username: ${{ secrets.QUAY_USERNAME }}
6962
password: ${{ secrets.QUAY_PASSWORD }}
7063

64+
- name: Build and push
65+
uses: docker/build-push-action@v6
66+
with:
67+
context: .
68+
file: ./Dockerfile
69+
platforms: linux/amd64,linux/arm64
70+
push: true
71+
tags: |
72+
quay.io/${{ env.REPOSITORY }}/vcverifier:latest
73+
quay.io/${{ env.REPOSITORY }}/vcverifier:${{ github.sha }}
74+
quay.io/${{ env.REPOSITORY }}/vcverifier:${{ needs.generate-version.outputs.version }}
75+
7176
git-release:
7277
needs:
7378
- generate-version
7479
- vcverifier
75-
80+
7681
runs-on: ubuntu-latest
7782

7883
steps:
7984

80-
- uses: actions/checkout@v2
85+
- uses: actions/checkout@v6
8186

8287
- uses: "marvinpinto/action-automatic-releases@latest"
8388
with:

Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
FROM golang:1.24-alpine AS build
1+
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS build
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
25

36
WORKDIR /go/src/app
47
COPY ./ ./
58

6-
RUN apk add build-base
9+
RUN apk add --no-cache build-base
10+
11+
RUN go mod download
712

8-
RUN go get -d -v ./...
9-
RUN go build -v .
13+
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w" -o VCVerifier .
1014

11-
FROM golang:1.24-alpine
15+
FROM alpine:3.23
1216

1317
LABEL org.opencontainers.image.source="https://github.com/FIWARE/VCVerifier"
1418

15-
WORKDIR /go/src/app
19+
WORKDIR /app
1620

17-
COPY --from=build /go/src/app/views /go/src/app/views
18-
COPY --from=build /go/src/app/VCVerifier /go/src/app/VCVerifier
19-
COPY --from=build /go/src/app/server.yaml /go/src/app/server.yaml
21+
COPY --from=build /go/src/app/views ./views
22+
COPY --from=build /go/src/app/VCVerifier ./VCVerifier
23+
COPY --from=build /go/src/app/server.yaml ./server.yaml
2024

2125
CMD ["./VCVerifier"]

config/configClient.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212

1313
const SERVICES_PATH = "service"
1414

15-
const SERVICE_DEFAULT_SCOPE = ""
16-
1715
var ErrorCcsNoResponse = errors.New("no_response_from_ccs")
1816
var ErrorCcsErrorResponse = errors.New("error_response_from_ccs")
1917
var ErrorCcsEmptyResponse = errors.New("empty_response_from_ccs")

verifier/verifier.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ type loginSession struct {
227227
requestObject string
228228
// inidicates if the cross device session is v1 or v2
229229
version int
230+
// scope requested for the session
231+
scope string
230232
}
231233

232234
// struct to represent a token, accessible through the token endpoint
@@ -435,7 +437,7 @@ func (v *CredentialVerifier) StartSameDeviceFlow(host string, protocol string, s
435437
nonce = v.nonceGenerator.GenerateNonce()
436438
}
437439

438-
loginSession := loginSession{callback: fmt.Sprintf("%s://%s%s", protocol, host, redirectPath), sessionId: state, nonce: nonce, clientId: clientId, version: SAME_DEVICE}
440+
loginSession := loginSession{callback: fmt.Sprintf("%s://%s%s", protocol, host, redirectPath), sessionId: state, nonce: nonce, clientId: clientId, version: SAME_DEVICE, scope: scope}
439441
err = v.sessionCache.Add(state, loginSession, cache.DefaultExpiration)
440442
if err != nil {
441443
logging.Log().Warnf("Was not able to store the login session %s in cache. Err: %v", logging.PrettyPrintObject(loginSession), err)
@@ -797,7 +799,7 @@ func (v *CredentialVerifier) AuthenticationResponse(state string, verifiablePres
797799

798800
for _, credential := range verifiablePresentation.Credentials() {
799801

800-
verificationContext, err := v.getTrustRegistriesValidationContext(loginSession.clientId, credential.Contents().Types)
802+
verificationContext, err := v.getTrustRegistriesValidationContext(loginSession.clientId, credential.Contents().Types, loginSession.scope)
801803
if err != nil {
802804
logging.Log().Warnf("Was not able to create a valid verification context. Credential will be rejected. Err: %v", err)
803805
return sameDevice, ErrorVerficationContextSetup
@@ -837,7 +839,7 @@ func (v *CredentialVerifier) AuthenticationResponse(state string, verifiablePres
837839
toBeIncluded = append(toBeIncluded, credential.ToRawJSON())
838840
}
839841

840-
flatClaims, _ := v.credentialsConfig.GetFlatClaims(loginSession.clientId, configModel.SERVICE_DEFAULT_SCOPE)
842+
flatClaims, _ := v.credentialsConfig.GetFlatClaims(loginSession.clientId, loginSession.scope)
841843
token, err := v.generateJWT(toBeIncluded, verifiablePresentation.Holder, hostname, flatClaims)
842844
if err != nil {
843845
logging.Log().Warnf("Was not able to create a jwt for %s. Err: %v", state, err)
@@ -949,17 +951,18 @@ func (v *CredentialVerifier) getHolderValidationContext(clientId string, scope s
949951
return validationContexts, err
950952
}
951953

952-
func (v *CredentialVerifier) getTrustRegistriesValidationContext(clientId string, credentialTypes []string) (verificationContext TrustRegistriesValidationContext, err error) {
954+
func (v *CredentialVerifier) getTrustRegistriesValidationContext(clientId string, credentialTypes []string, scope string) (verificationContext TrustRegistriesValidationContext, err error) {
955+
logging.Log().Debugf("Create trust registry validation context for client '%s', scope '%s' and credential types %s", clientId, scope, credentialTypes)
953956
trustedIssuersLists := map[string][]string{}
954957
trustedParticipantsRegistries := map[string][]configModel.TrustedParticipantsList{}
955958

956959
for _, credentialType := range credentialTypes {
957-
issuersLists, err := v.credentialsConfig.GetTrustedIssuersLists(clientId, configModel.SERVICE_DEFAULT_SCOPE, credentialType)
960+
issuersLists, err := v.credentialsConfig.GetTrustedIssuersLists(clientId, scope, credentialType)
958961
if err != nil {
959962
logging.Log().Warnf("Was not able to get valid trusted-issuers-lists for client %s and type %s. Err: %v", clientId, credentialType, err)
960963
return verificationContext, err
961964
}
962-
participantsLists, err := v.credentialsConfig.GetTrustedParticipantLists(clientId, configModel.SERVICE_DEFAULT_SCOPE, credentialType)
965+
participantsLists, err := v.credentialsConfig.GetTrustedParticipantLists(clientId, scope, credentialType)
963966
if err != nil {
964967
logging.Log().Warnf("Was not able to get valid trusted-pariticpants-registries for client %s and type %s. Err: %v", clientId, credentialType, err)
965968
return verificationContext, err
@@ -1047,7 +1050,7 @@ func verifyChain(vcs []*verifiable.Credential) (bool, error) {
10471050
// intialize the OID4VP cross device flow
10481051
func (v *CredentialVerifier) initOid4VPCrossDevice(host string, protocol string, redirectUri string, state string, clientId string, scope string, nonce string, requestMode string) (authenticationRequest string, err error) {
10491052

1050-
loginSession := loginSession{redirectUri, state, nonce, clientId, "", CROSS_DEVICE_V2}
1053+
loginSession := loginSession{redirectUri, state, nonce, clientId, "", CROSS_DEVICE_V2, scope}
10511054
err = v.sessionCache.Add(state, loginSession, cache.DefaultExpiration)
10521055

10531056
if err != nil {
@@ -1066,7 +1069,7 @@ func (v *CredentialVerifier) initSiopFlow(host string, protocol string, callback
10661069
logging.Log().Debugf("No nonce provided, generate one.")
10671070
nonce = v.nonceGenerator.GenerateNonce()
10681071
}
1069-
loginSession := loginSession{callback, state, nonce, clientId, "", CROSS_DEVICE_V1}
1072+
loginSession := loginSession{callback, state, nonce, clientId, "", CROSS_DEVICE_V1, ""}
10701073
err = v.sessionCache.Add(state, loginSession, cache.DefaultExpiration)
10711074

10721075
if err != nil {

verifier/verifier_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,10 @@ func verifyInitTest(t *testing.T, tc siopInitTest, authRequest string, err error
376376
expectedNonce = "randomNonce"
377377
}
378378
if tc.requestMode == REQUEST_MODE_BY_REFERENCE {
379-
expectedSession = loginSession{version: flowVersion, callback: tc.expectedCallback, nonce: expectedNonce, sessionId: tc.testState, clientId: tc.testClientId, requestObject: tc.testRequestObjectJwt}
379+
expectedSession = loginSession{version: flowVersion, callback: tc.expectedCallback, nonce: expectedNonce, sessionId: tc.testState, clientId: tc.testClientId, requestObject: tc.testRequestObjectJwt, scope: tc.testScope}
380380
cachedSession.requestObject = removeSignature(cachedSession.requestObject)
381381
} else {
382-
expectedSession = loginSession{version: flowVersion, callback: tc.expectedCallback, nonce: expectedNonce, sessionId: tc.testState, clientId: tc.testClientId, requestObject: tc.testRequestObjectJwt}
382+
expectedSession = loginSession{version: flowVersion, callback: tc.expectedCallback, nonce: expectedNonce, sessionId: tc.testState, clientId: tc.testClientId, requestObject: tc.testRequestObjectJwt, scope: tc.testScope}
383383
}
384384
if cachedSession != expectedSession {
385385
t.Errorf("%s - The login session was expected to be %v but was %v.", tc.testName, expectedSession, cachedSession)

0 commit comments

Comments
 (0)