;; disfluid, implementation of the Solid specification
;; Copyright (C) 2020, 2021 Vivien Kraus
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Affero General Public License for more details.
;; You should have received a copy of the GNU Affero General Public License
;; along with this program. If not, see .
(use-modules (webid-oidc provider-confirmation)
(webid-oidc jti)
(webid-oidc jwk)
(webid-oidc jws)
(webid-oidc oidc-configuration)
(webid-oidc access-token)
(webid-oidc dpop-proof)
(webid-oidc resource-server)
(webid-oidc testing)
((webid-oidc parameters) #:prefix p:)
(web uri)
(web request)
(srfi srfi-19)
(web response)
(ice-9 optargs)
(ice-9 receive)
(oop goops))
(with-test-environment
"resource-server"
(lambda ()
(define client-key (generate-key #:n-size 2048))
(define idp-key (generate-key #:n-size 2048))
(define jwks (make #:keys (list idp-key)))
(define jwks-uri (string->uri "https://identity.provider/keys"))
(define oidc-config
`((jwks_uri . ,(uri->string jwks-uri))
(authorization_endpoint . "https://identity.provider/authorize")
(token_endpoint . "https://identity.provider/token")
(solid_oidc_supported . "https://solidproject.org/TR/solid-oidc")))
(define oidc-config-uri
(string->uri
"https://identity.provider/.well-known/openid-configuration"))
(define subject (string->uri "https://identity.provider/subject#me"))
(define* (http-get uri #:key (headers '()))
(define exp (time-utc->date (make-time time-utc 0 3600)))
(cond ((equal? uri oidc-config-uri)
(serve-oidc-configuration exp oidc-config))
((equal? uri jwks-uri)
(serve jwks exp))
(else (exit 1))))
(define access-token
(parameterize ((p:current-date 10))
(issue-access-token
idp-key
#:alg 'RS256
#:webid subject
#:iss (string->uri "https://identity.provider")
#:validity 3600
#:client-key client-key
#:client-id (string->uri "https://client"))))
(define uri (string->uri "https://resource.server/resource"))
(define server-uri (string->uri "https://resource.server/"))
(define method 'GET)
(define dpop-proof
(parameterize ((p:current-date 15))
(issue-dpop-proof
client-key
#:alg 'RS256
#:htm method
#:htu uri
#:access-token access-token)))
(define rq
(call-with-input-string
(format #f "GET /resource HTTP/1.1\r\n\
Host: resource.server\r\n\
User-Agent: Test Suite\r\n\
Upgrade-Insecure-Requests: 1\r\n\
Cache-Control: max-age=0\r\n\
Authorization: DPoP ~a\r\n\
DPoP: ~a\r\n\r\n"
access-token
dpop-proof)
read-request))
(define rq-body "")
(define authenticator
(make-authenticator
#:server-uri server-uri
#:http-get http-get))
(define parsed
(parameterize ((p:current-date 20))
(authenticator rq rq-body)))
(unless (uri? parsed)
(exit 2))
(unless (equal? parsed subject)
(exit 3))))