blob: 27a187ff7ec98ed8423766f84fab4242ede034f6 [file] [log] [blame]
Remi Tricot-Le Breton36da6062021-10-01 15:36:59 +02001#REGTEST_TYPE=devel
2
3# This reg-test uses the JSON Web Token (JWT) converters to verify a token's signature.
4# It uses the http_auth_bearer sample fetch to fetch a token contained in an
5# HTTP Authorization header (with the Bearer scheme) which is the common way of
6# transmitting a token (see RFC6750). It then uses the jwt_header_query
7# converter to get the "alg" field declared in the token's JOSE header and
8# gives it to the jwt_verify converter with the appropriate certificate.
9#
10# All the supported algorithms are tested at least once (HMAC, RSA and ECDSA)
11# and the errors codes returned by jwt_verify are tested as well.
12
13varnishtest "Test the 'set ssl ca-file' feature of the CLI"
14feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'"
15feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'"
16feature cmd "command -v socat"
17feature ignore_unknown_macro
18
19server s1 -repeat 18 {
20 rxreq
21 txresp
22} -start
23
24haproxy h1 -conf {
25 global
26 tune.ssl.default-dh-param 2048
27 tune.ssl.capture-buffer-size 1
28 stats socket "${tmpdir}/h1/stats" level admin
29
30 defaults
31 mode http
32 timeout connect 100ms
33 timeout client 1s
34 timeout server 1s
35
36 listen main-fe
37 bind "fd@${mainfe}"
38
39 http-request deny unless { req.hdr(authorization) -m found }
40
41 use_backend hsXXX_be if { path_beg /hs }
42 use_backend rsXXX_be if { path_beg /rs }
43 use_backend esXXX_be if { path_beg /es }
44 default_backend dflt_be
45
46
47 backend hsXXX_be
48 http-request set-var(txn.bearer) http_auth_bearer
49 http-request set-var(txn.jwt_alg) var(txn.bearer),jwt_header_query('$.alg')
50
51 http-request deny unless { var(txn.jwt_alg) -m beg "HS" }
52
53 http-response set-header x-jwt-token %[var(txn.bearer)]
54 http-response set-header x-jwt-alg %[var(txn.jwt_alg)]
55
56 http-response set-header x-jwt-verify-HS256 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"hmac key hs256")] if { var(txn.jwt_alg) "HS256" }
57 http-response set-header x-jwt-verify-HS384 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"hmac key hs384")] if { var(txn.jwt_alg) "HS384" }
58 http-response set-header x-jwt-verify-HS512 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"hmac key hs512")] if { var(txn.jwt_alg) "HS512" }
59 server s1 ${s1_addr}:${s1_port}
60
61 backend rsXXX_be
62 http-request set-var(txn.bearer) http_auth_bearer
63 http-request set-var(txn.jwt_alg) var(txn.bearer),jwt_header_query('$.alg')
64
65 http-request deny unless { var(txn.jwt_alg) -m beg "RS" }
66
67 http-response set-header x-jwt-token %[var(txn.bearer)]
68 http-response set-header x-jwt-alg %[var(txn.jwt_alg)]
69
70 http-response set-header x-jwt-verify-RS256 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"${testdir}/rsa-public.pem")] if { var(txn.jwt_alg) "RS256" }
71 http-response set-header x-jwt-verify-RS384 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"${testdir}/rsa-public.pem")] if { var(txn.jwt_alg) "RS384" }
72 http-response set-header x-jwt-verify-RS512 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"${testdir}/rsa-public.pem")] if { var(txn.jwt_alg) "RS512" }
73 server s1 ${s1_addr}:${s1_port}
74
75 backend esXXX_be
76 http-request set-var(txn.bearer) http_auth_bearer
77 http-request set-var(txn.jwt_alg) var(txn.bearer),jwt_header_query('$.alg')
78
79 http-request deny unless { var(txn.jwt_alg) -m beg "ES" }
80
81 http-response set-header x-jwt-token %[var(txn.bearer)]
82 http-response set-header x-jwt-alg %[var(txn.jwt_alg)]
83
84 http-response set-header x-jwt-verify-ES256 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"${testdir}/es256-public.pem")] if { var(txn.jwt_alg) "ES256" }
85 http-response set-header x-jwt-verify-ES384 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"${testdir}/es384-public.pem")] if { var(txn.jwt_alg) "ES384" }
86 http-response set-header x-jwt-verify-ES512 %[var(txn.bearer),jwt_verify(txn.jwt_alg,"${testdir}/es512-public.pem")] if { var(txn.jwt_alg) "ES512" }
87 server s1 ${s1_addr}:${s1_port}
88
89 # This backend will mostly be used to test error cases (invalid tokens, algorithm and so on)
90 backend dflt_be
91 http-request set-var(txn.bearer) http_auth_bearer
92 http-request set-var(txn.jwt_alg) var(txn.bearer),jwt_header_query('$.alg')
93
94 http-request set-var(txn.jwt_verify) var(txn.bearer),jwt_verify(txn.jwt_alg,"unknown_cert.pem")
95
96 http-response set-header x-jwt-token %[var(txn.bearer)]
97 http-response set-header x-jwt-alg %[var(txn.jwt_alg)]
98 http-response set-header x-jwt-verify %[var(txn.jwt_verify)]
99
100 server s1 ${s1_addr}:${s1_port}
101
102} -start
103
104
105client c1 -connect ${h1_mainfe_sock} {
106 # Token content : {"alg":"HS256","typ":"JWT"}
107 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
108 # HMAC key : 'hmac key hs256'
109 # OpenSSL cmd : openssl dgst -sha256 -mac HMAC -macopt key:'hmac key hs256' data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
110
111 txreq -url "/hs256" -hdr "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.hhj1mbYgezxFoYwinThsZQbckYHt4jJlRoQ7W8ksrFM"
112 rxresp
113 expect resp.status == 200
114 expect resp.http.x-jwt-alg == "HS256"
115 expect resp.http.x-jwt-verify-HS256 == "1"
116} -run
117
118client c2 -connect ${h1_mainfe_sock} {
119 # Token content : {"alg":"HS384","typ":"JWT"}
120 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
121 # HMAC key : 'hmac key hs384'
122 # OpenSSL cmd : openssl dgst -sha384 -mac HMAC -macopt key:'hmac key hs384' data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
123
124 txreq -url "/hs384" -hdr "Authorization: Bearer eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.3EsbLfl6DDh5nZMkLWg3ssCurFHyOhXP28a4PDS48aPAIoYLzHchtXmNaYI8He-R"
125 rxresp
126 expect resp.status == 200
127 expect resp.http.x-jwt-alg == "HS384"
128 expect resp.http.x-jwt-verify-HS384 == "1"
129} -run
130
131client c3 -connect ${h1_mainfe_sock} {
132 # Token content : {"alg":"HS512","typ":"JWT"}
133 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
134 # HMAC key : 'hmac key hs512'
135 # OpenSSL cmd : openssl dgst -sha512 -mac HMAC -macopt key:'hmac key hs512' data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
136
137 txreq -url "/hs512" -hdr "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.K4Yze5N7jeJrDbJymphaH1YsFlYph5F-U75HzBRKDybrN7WBO494EgNG77mAQj4CVci_xbTD_IsqY2umO0f47A"
138 rxresp
139 expect resp.status == 200
140 expect resp.http.x-jwt-alg == "HS512"
141 expect resp.http.x-jwt-verify-HS512 == "1"
142} -run
143
144# The following token is invalid (it has three extra characters at the end of the signature)
145client c4 -connect ${h1_mainfe_sock} {
146 # Token content : {"alg":"HS512","typ":"JWT"}
147 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
148 # HMAC key : 'hmac key hs512'
149 # OpenSSL cmd : openssl dgst -sha512 -mac HMAC -macopt key:'hmac key hs512' data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
150
151 txreq -url "/hs512" -hdr "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.K4Yze5N7jeJrDbJymphaH1YsFlYph5F-U75HzBRKDybrN7WBO494EgNG77mAQj4CVci_xbTD_IsqY2umO0f47AAAA"
152 rxresp
153 expect resp.status == 200
154 expect resp.http.x-jwt-alg == "HS512"
155 expect resp.http.x-jwt-verify-HS512 == "0"
156} -run
157
158
159client c5 -connect ${h1_mainfe_sock} {
160 # Token content : {"alg":"RS256","typ":"JWT"}
161 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
162 # OpenSSL cmd : openssl dgst -sha256 -sign rsa-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
163
164 txreq -url "/rs256" -hdr "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.hRqFM87JzV_YinYhdERp2E9BLhl6s7I5J37GTXAeT5fixJx-OCjTFvwKssyVo7fWAFcQMdQU7vGEXDOiWbNaMUFGIsMxx0Uflk0BeNwk6pWvNGk8KZGMtiqOv-IuPdAiaSW_xhxLHIk7eOwVefvBfk8j2hgU9yoHN87AYnl8oEnzrkzwWvEt-x-P2zB4s_VwhF0gbL1G4FsP5hxWL1HWmSFLBpvWaL5Lx3OJE7mLRLRf8TpMwEe4ROakzMpiv9Xk1H3mZth6d2a91F5Bm65MIJpJ7P2kEL3tdS62VRx8DM_SlsFuWcsqryO3CDQquMbwzAvfRgLPy8PBLRLT64wM3mZtue5GI2KUlqSYsSwKwK580b4drosLvAS75l_4jJwdwuQEvVd8Gry3DWS2mKJSMefmGfD-cdty1vvszs5sUa96Gf7Ro5DvkgXtVCKYk8KJLI62YgZd5S3M0ucP5NLBc_flUi4A2B_aSkd7NDM0ELddk0y48pcF95tejcvliGIy1GRRwevdqensXXQrFweFSZVvuKo8c9pcCBVfKTSllgL0lFGyI_vz6dUYt69I1gqWBDeGcA2XQUBJqfX3o9nkhZspA7b7QxMESatoATsM_XmfhbwsyY-sTq25XIGC4awaZHViZr1YFVD6BwNZWBCEBvW5zObiD5h5A5AgWoBv14E"
165 rxresp
166 expect resp.status == 200
167 expect resp.http.x-jwt-alg == "RS256"
168 expect resp.http.x-jwt-verify-RS256 == "1"
169} -run
170
171client c6 -connect ${h1_mainfe_sock} {
172 # Token content : {"alg":"RS384","typ":"JWT"}
173 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
174 # OpenSSL cmd : openssl dgst -sha384 -sign rsa-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
175
176 txreq -url "/rs384" -hdr "Authorization: Bearer eyJhbGciOiJSUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.GuR-v91EMCVvvTTLiE56O0oDAKeQ5JdLqvHtrgOp2MbUtF7zCDutV0LTmMo4qDNVpvTnD3GZfTTGaVUTvW7kIQ3_1iEVAg61qVWkT9rtHHxifDX70RDBKkvNcMWyQH-dFP_FUvCmhCu7q-AzgBT6PHvs5ZqYyQvlQ1gSWZEPFi184dhvcUQrQC6CySEAdOzIryIHH2oQjN_a9lA9V9M_CH3P-AAwFE7NwUE1H1SGIYM4NHcngEZ3B4lBCHOhhgQMpfagcxQjjXv7VfeSqza6OZDpupwlOl34bb0gnFDGMh4hHSS6iHvvwCeCkclbyvKV0Vq0MaRtJuoKRF-_Oww-nKT_bfNtbF6MeOQLNRlYjGCHerWoBtjv3w2KjoLvQ5iGIFI3cEguyrrKNimpovF4Y5uINH0pWdRF99zOwVUlcJBk3RivIb--Y6s47aNFIVWimUpSn-8MSHTla20TYbcdVaZaMur09Cw500jPrOy6jFqVydSnmU6r13NkmCD5-Bl0mgwGtpZcOQExrnIcPQky12kQJAIrffVblvtkd-8FIBPBy1uBKCgkE-q9_suEvBTdvaoTocBmPcIxfPjZUVXeU3UmnRrXEz17pue0YfrwK9CUR9UoP0F5C7O5eSbAtZNm4Hpkiah0w7qugWG3esMgku3-xx0B2xwg6Ul7bAgEJFg"
177 rxresp
178 expect resp.status == 200
179 expect resp.http.x-jwt-alg == "RS384"
180 expect resp.http.x-jwt-verify-RS384 == "1"
181} -run
182
183client c7 -connect ${h1_mainfe_sock} {
184 # Token content : {"alg":"RS512","typ":"JWT"}
185 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
186 # OpenSSL cmd : openssl dgst -sha512 -sign rsa-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
187
188 txreq -url "/rs512" -hdr "Authorization: Bearer eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.dgUDvxbWXV-q9lVFDVDt6zffrAjCMkKL7UURz-vvc6utCNMEgt8jSkDWi-mt-jmttkD5mwHqUf3HxWPhfjYNmkTok_XL79F5RXhiF_cu_2oDLDc-RuXdrHaRt9xjUIyZhVJMhaMLdmpcAokQlZxc2W6aj92HKzk3EjyHwfdwfKQNgMooXNzxjE9vCHUbahyLZvtPwiqDtYUSnvN_XOpAMUilxByJStwNqdB7MaOxeAzn76nITh6DqD1bNtxBiLzA7MxYdfsUSmXHMLpkWNAhlrcEIJui9PKm9E0OLFD3M7cCqi6rVvzDxvHqXz3-fcXiSJSRrSmSTu1_ok35TT4WwA9SkHpGe2MJ3uc-8CRlYmjDTcLyXWs_d8i3iNozo6xgiwqIkty4HqScTjhXndRQdmiK-RcUfNLM0Iqm6wYgOifWj728_9GCtdjup-C2uVPdwVwuOjwLbzctZLlFqH3i5IGrCfuOOCAcc_vN3REFqSrDEi4-9qpXuh7yk5pOaiCZYr3-uVhmY5neo55_eV8N3NooDyztwkzRtB_DdbaNrqxk3WEHU79Hseg7c1mkXGm6Djqt3dkkrdpbltzRLrnGKxA4-FzccKOT_P27UYmxQSkyfpAQhfH3jpOE0n9-UYyULbMOY7ZIypXUTquJnrZM3rD_NypU7Jg8uBBGqcziZFc"
189 rxresp
190 expect resp.status == 200
191 expect resp.http.x-jwt-alg == "RS512"
192 expect resp.http.x-jwt-verify-RS512 == "1"
193} -run
194
195# The following token is invalid (the signature used SHA384 instead of SHA512)
196client c8 -connect ${h1_mainfe_sock} {
197 # Token content : {"alg":"RS512","typ":"JWT"}
198 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
199 # OpenSSL cmd : openssl dgst -sha512 -sign rsa-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
200
201 txreq -url "/rs512" -hdr "Authorization: Bearer eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.GuR-v91EMCVvvTTLiE56O0oDAKeQ5JdLqvHtrgOp2MbUtF7zCDutV0LTmMo4qDNVpvTnD3GZfTTGaVUTvW7kIQ3_1iEVAg61qVWkT9rtHHxifDX70RDBKkvNcMWyQH-dFP_FUvCmhCu7q-AzgBT6PHvs5ZqYyQvlQ1gSWZEPFi184dhvcUQrQC6CySEAdOzIryIHH2oQjN_a9lA9V9M_CH3P-AAwFE7NwUE1H1SGIYM4NHcngEZ3B4lBCHOhhgQMpfagcxQjjXv7VfeSqza6OZDpupwlOl34bb0gnFDGMh4hHSS6iHvvwCeCkclbyvKV0Vq0MaRtJuoKRF-_Oww-nKT_bfNtbF6MeOQLNRlYjGCHerWoBtjv3w2KjoLvQ5iGIFI3cEguyrrKNimpovF4Y5uINH0pWdRF99zOwVUlcJBk3RivIb--Y6s47aNFIVWimUpSn-8MSHTla20TYbcdVaZaMur09Cw500jPrOy6jFqVydSnmU6r13NkmCD5-Bl0mgwGtpZcOQExrnIcPQky12kQJAIrffVblvtkd-8FIBPBy1uBKCgkE-q9_suEvBTdvaoTocBmPcIxfPjZUVXeU3UmnRrXEz17pue0YfrwK9CUR9UoP0F5C7O5eSbAtZNm4Hpkiah0w7qugWG3esMgku3-xx0B2xwg6Ul7bAgEJFg"
202 rxresp
203 expect resp.status == 200
204 expect resp.http.x-jwt-alg == "RS512"
205 expect resp.http.x-jwt-verify-RS512 == "0"
206} -run
207
208
209
210client c9 -connect ${h1_mainfe_sock} {
211 # Token content : {"alg":"ES256","typ":"JWT"}
212 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
213 # Key gen process : openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out es256-private.pem; openssl ec -in es256-private.pem -pubout -out es256-public.pem
214 # OpenSSL cmd : openssl dgst -sha256 -sign es256-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
215
216 txreq -url "/es256" -hdr "Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MEYCIQCkHcfMhzhP3FvZqjaqEDW89_5QEhBwUvpXv535lAnRuQIhALc62LiFZz0oDuKeqI3ogto336D7kEg4Uat8qm_iW6ur"
217 rxresp
218 expect resp.status == 200
219 expect resp.http.x-jwt-alg == "ES256"
220 expect resp.http.x-jwt-verify-ES256 == "1"
221} -run
222
223client c10 -connect ${h1_mainfe_sock} {
224 # Token content : {"alg":"ES384","typ":"JWT"}
225 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
226 # Key gen process : openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-384 -out es384-private.pem; openssl ec -in es384-private.pem -pubout -out es384-public.pem
227 # OpenSSL cmd : openssl dgst -sha384 -sign es384-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
228
229 txreq -url "/es384" -hdr "Authorization: Bearer eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MGUCMQDQFs6fqnmoxbw3eIQCT6km0TnMakpGy2F-8ZgGu5G8nFQKzCAO-V-UTOD0OqxHUa8CMBqHfZ6pjqRaLK-PebsvbGSzneAG7Id3oN78n2wWGKcYCI_s0KSO88thboaR9AS4tA"
230 rxresp
231 expect resp.status == 200
232 expect resp.http.x-jwt-alg == "ES384"
233 expect resp.http.x-jwt-verify-ES384 == "1"
234} -run
235
236client c11 -connect ${h1_mainfe_sock} {
237 # Token content : {"alg":"ES512","typ":"JWT"}
238 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
239 # Key gen process : openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-521 -out es512-private.pem; openssl ec -in es512-private.pem -pubout -out es512-public.pem
240 # OpenSSL cmd : openssl dgst -sha512 -sign es512-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
241
242 txreq -url "/es512" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5fSIWfRa"
243 rxresp
244 expect resp.status == 200
245 expect resp.http.x-jwt-alg == "ES512"
246 expect resp.http.x-jwt-verify-ES512 == "1"
247} -run
248
249# The following token is invalid (too short)
250client c12 -connect ${h1_mainfe_sock} {
251 # Token content : {"alg":"ES512","typ":"JWT"}
252 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
253 # OpenSSL cmd : openssl dgst -sha512 -sign es512-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
254
255 txreq -url "/es512" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5f"
256 rxresp
257 expect resp.status == 200
258 expect resp.http.x-jwt-alg == "ES512"
259 expect resp.http.x-jwt-verify-ES512 == "0"
260} -run
261
262
263# Unmanaged algorithm
264client c13 -connect ${h1_mainfe_sock} {
265 # Token content : {"alg":"PS512","typ":"JWT"}
266 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
267 txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJQUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5f"
268 rxresp
269 expect resp.status == 200
270 expect resp.http.x-jwt-alg == "PS512"
271 # Unmanaged algorithm
272 expect resp.http.x-jwt-verify == "3"
273} -run
274
275# Unknown algorithm
276client c14 -connect ${h1_mainfe_sock} {
277 # Token content : {"alg":"UNKNOWN_ALG","typ":"JWT"}
278 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
279 txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJVTktOT1dOX0FMRyIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5f"
280 rxresp
281 expect resp.status == 200
282 expect resp.http.x-jwt-alg == "UNKNOWN_ALG"
283 # Unmanaged algorithm
284 expect resp.http.x-jwt-verify == "2"
285} -run
286
287# Invalid token (not enough fields)
288client c15 -connect ${h1_mainfe_sock} {
289 # Token content : {"alg":"ES512","typ":"JWT"}
290 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
291 txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ"
292 rxresp
293 expect resp.status == 200
294 expect resp.http.x-jwt-alg == "ES512"
295 # Unmanaged algorithm
296 expect resp.http.x-jwt-verify == "4"
297} -run
298
299# Invalid token (too many fields)
300client c16 -connect ${h1_mainfe_sock} {
301 # Token content : {"alg":"ES512","typ":"JWT"}
302 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
303 txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5f.unexpectedextrafield"
304 rxresp
305 expect resp.status == 200
306 expect resp.http.x-jwt-alg == "ES512"
307 # Unmanaged algorithm
308 expect resp.http.x-jwt-verify == "4"
309} -run
310
311# Invalid token (empty signature)
312client c17 -connect ${h1_mainfe_sock} {
313 # Token content : {"alg":"ES512","typ":"JWT"}
314 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
315 txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ."
316 rxresp
317 expect resp.status == 200
318 expect resp.http.x-jwt-alg == "ES512"
319 # Unmanaged algorithm
320 expect resp.http.x-jwt-verify == "4"
321} -run
322
323# Unknown certificate
324client c18 -connect ${h1_mainfe_sock} {
325 # Token content : {"alg":"ES512","typ":"JWT"}
326 # {"sub":"1234567890","name":"John Doe","iat":1516239022}
327 # Key gen process : openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-521 -out es512-private.pem; openssl ec -in es512-private.pem -pubout -out es512-public.pem
328 # OpenSSL cmd : openssl dgst -sha512 -sign es512-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-'
329
330 txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5fSIWfRa"
331 rxresp
332 expect resp.status == 200
333 expect resp.http.x-jwt-alg == "ES512"
334 # Unmanaged algorithm
335 expect resp.http.x-jwt-verify == "6"
336} -run