Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 1 | #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 | |
| 13 | varnishtest "Test the 'set ssl ca-file' feature of the CLI" |
| 14 | feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'" |
| 15 | feature cmd "$HAPROXY_PROGRAM -cc 'feature(OPENSSL)'" |
| 16 | feature cmd "command -v socat" |
| 17 | feature ignore_unknown_macro |
| 18 | |
Remi Tricot-Le Breton | 7da35bf | 2021-10-29 15:25:19 +0200 | [diff] [blame] | 19 | server s1 -repeat 22 { |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 20 | rxreq |
| 21 | txresp |
| 22 | } -start |
| 23 | |
| 24 | haproxy 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 | |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 39 | use_backend hsXXX_be if { path_beg /hs } |
| 40 | use_backend rsXXX_be if { path_beg /rs } |
| 41 | use_backend esXXX_be if { path_beg /es } |
Remi Tricot-Le Breton | 7da35bf | 2021-10-29 15:25:19 +0200 | [diff] [blame] | 42 | use_backend auth_bearer_be if { path /auth_bearer } |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 43 | default_backend dflt_be |
| 44 | |
| 45 | |
| 46 | backend hsXXX_be |
| 47 | http-request set-var(txn.bearer) http_auth_bearer |
| 48 | http-request set-var(txn.jwt_alg) var(txn.bearer),jwt_header_query('$.alg') |
| 49 | |
| 50 | http-request deny unless { var(txn.jwt_alg) -m beg "HS" } |
| 51 | |
| 52 | http-response set-header x-jwt-token %[var(txn.bearer)] |
| 53 | http-response set-header x-jwt-alg %[var(txn.jwt_alg)] |
| 54 | |
| 55 | 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" } |
| 56 | 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" } |
| 57 | 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" } |
| 58 | server s1 ${s1_addr}:${s1_port} |
| 59 | |
| 60 | backend rsXXX_be |
| 61 | http-request set-var(txn.bearer) http_auth_bearer |
| 62 | http-request set-var(txn.jwt_alg) var(txn.bearer),jwt_header_query('$.alg') |
| 63 | |
| 64 | http-request deny unless { var(txn.jwt_alg) -m beg "RS" } |
| 65 | |
| 66 | http-response set-header x-jwt-token %[var(txn.bearer)] |
| 67 | http-response set-header x-jwt-alg %[var(txn.jwt_alg)] |
| 68 | |
| 69 | 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" } |
| 70 | 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" } |
| 71 | 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" } |
| 72 | server s1 ${s1_addr}:${s1_port} |
| 73 | |
| 74 | backend esXXX_be |
| 75 | http-request set-var(txn.bearer) http_auth_bearer |
| 76 | http-request set-var(txn.jwt_alg) var(txn.bearer),jwt_header_query('$.alg') |
| 77 | |
| 78 | http-request deny unless { var(txn.jwt_alg) -m beg "ES" } |
| 79 | |
| 80 | http-response set-header x-jwt-token %[var(txn.bearer)] |
| 81 | http-response set-header x-jwt-alg %[var(txn.jwt_alg)] |
| 82 | |
| 83 | 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" } |
| 84 | 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" } |
| 85 | 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" } |
| 86 | server s1 ${s1_addr}:${s1_port} |
| 87 | |
Remi Tricot-Le Breton | 7da35bf | 2021-10-29 15:25:19 +0200 | [diff] [blame] | 88 | |
| 89 | # This backend will only be used to test the http_auth_bearer sample fetch. |
| 90 | # No jwt_verify will then be performed. |
| 91 | backend auth_bearer_be |
| 92 | http-request set-var(txn.bearer) http_auth_bearer("Custom-Authorization") |
| 93 | |
| 94 | http-response set-header x-jwt-token %[var(txn.bearer)] |
| 95 | |
| 96 | server s1 ${s1_addr}:${s1_port} |
| 97 | |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 98 | # This backend will mostly be used to test error cases (invalid tokens, algorithm and so on) |
| 99 | backend dflt_be |
| 100 | http-request set-var(txn.bearer) http_auth_bearer |
| 101 | http-request set-var(txn.jwt_alg) var(txn.bearer),jwt_header_query('$.alg') |
| 102 | |
| 103 | http-request set-var(txn.jwt_verify) var(txn.bearer),jwt_verify(txn.jwt_alg,"unknown_cert.pem") |
| 104 | |
| 105 | http-response set-header x-jwt-token %[var(txn.bearer)] |
| 106 | http-response set-header x-jwt-alg %[var(txn.jwt_alg)] |
| 107 | http-response set-header x-jwt-verify %[var(txn.jwt_verify)] |
| 108 | |
| 109 | server s1 ${s1_addr}:${s1_port} |
| 110 | |
| 111 | } -start |
| 112 | |
| 113 | |
| 114 | client c1 -connect ${h1_mainfe_sock} { |
| 115 | # Token content : {"alg":"HS256","typ":"JWT"} |
| 116 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 117 | # HMAC key : 'hmac key hs256' |
| 118 | # OpenSSL cmd : openssl dgst -sha256 -mac HMAC -macopt key:'hmac key hs256' data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 119 | |
| 120 | txreq -url "/hs256" -hdr "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.hhj1mbYgezxFoYwinThsZQbckYHt4jJlRoQ7W8ksrFM" |
| 121 | rxresp |
| 122 | expect resp.status == 200 |
| 123 | expect resp.http.x-jwt-alg == "HS256" |
| 124 | expect resp.http.x-jwt-verify-HS256 == "1" |
| 125 | } -run |
| 126 | |
| 127 | client c2 -connect ${h1_mainfe_sock} { |
| 128 | # Token content : {"alg":"HS384","typ":"JWT"} |
| 129 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 130 | # HMAC key : 'hmac key hs384' |
| 131 | # OpenSSL cmd : openssl dgst -sha384 -mac HMAC -macopt key:'hmac key hs384' data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 132 | |
| 133 | txreq -url "/hs384" -hdr "Authorization: Bearer eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.3EsbLfl6DDh5nZMkLWg3ssCurFHyOhXP28a4PDS48aPAIoYLzHchtXmNaYI8He-R" |
| 134 | rxresp |
| 135 | expect resp.status == 200 |
| 136 | expect resp.http.x-jwt-alg == "HS384" |
| 137 | expect resp.http.x-jwt-verify-HS384 == "1" |
| 138 | } -run |
| 139 | |
| 140 | client c3 -connect ${h1_mainfe_sock} { |
| 141 | # Token content : {"alg":"HS512","typ":"JWT"} |
| 142 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 143 | # HMAC key : 'hmac key hs512' |
| 144 | # OpenSSL cmd : openssl dgst -sha512 -mac HMAC -macopt key:'hmac key hs512' data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 145 | |
| 146 | txreq -url "/hs512" -hdr "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.K4Yze5N7jeJrDbJymphaH1YsFlYph5F-U75HzBRKDybrN7WBO494EgNG77mAQj4CVci_xbTD_IsqY2umO0f47A" |
| 147 | rxresp |
| 148 | expect resp.status == 200 |
| 149 | expect resp.http.x-jwt-alg == "HS512" |
| 150 | expect resp.http.x-jwt-verify-HS512 == "1" |
| 151 | } -run |
| 152 | |
| 153 | # The following token is invalid (it has three extra characters at the end of the signature) |
| 154 | client c4 -connect ${h1_mainfe_sock} { |
| 155 | # Token content : {"alg":"HS512","typ":"JWT"} |
| 156 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 157 | # HMAC key : 'hmac key hs512' |
| 158 | # OpenSSL cmd : openssl dgst -sha512 -mac HMAC -macopt key:'hmac key hs512' data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 159 | |
| 160 | txreq -url "/hs512" -hdr "Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.K4Yze5N7jeJrDbJymphaH1YsFlYph5F-U75HzBRKDybrN7WBO494EgNG77mAQj4CVci_xbTD_IsqY2umO0f47AAAA" |
| 161 | rxresp |
| 162 | expect resp.status == 200 |
| 163 | expect resp.http.x-jwt-alg == "HS512" |
Remi Tricot-Le Breton | 1c891bc | 2021-10-18 15:14:49 +0200 | [diff] [blame] | 164 | expect resp.http.x-jwt-verify-HS512 == "-3" |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 165 | } -run |
| 166 | |
| 167 | |
| 168 | client c5 -connect ${h1_mainfe_sock} { |
| 169 | # Token content : {"alg":"RS256","typ":"JWT"} |
| 170 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 171 | # OpenSSL cmd : openssl dgst -sha256 -sign rsa-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 172 | |
| 173 | txreq -url "/rs256" -hdr "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.hRqFM87JzV_YinYhdERp2E9BLhl6s7I5J37GTXAeT5fixJx-OCjTFvwKssyVo7fWAFcQMdQU7vGEXDOiWbNaMUFGIsMxx0Uflk0BeNwk6pWvNGk8KZGMtiqOv-IuPdAiaSW_xhxLHIk7eOwVefvBfk8j2hgU9yoHN87AYnl8oEnzrkzwWvEt-x-P2zB4s_VwhF0gbL1G4FsP5hxWL1HWmSFLBpvWaL5Lx3OJE7mLRLRf8TpMwEe4ROakzMpiv9Xk1H3mZth6d2a91F5Bm65MIJpJ7P2kEL3tdS62VRx8DM_SlsFuWcsqryO3CDQquMbwzAvfRgLPy8PBLRLT64wM3mZtue5GI2KUlqSYsSwKwK580b4drosLvAS75l_4jJwdwuQEvVd8Gry3DWS2mKJSMefmGfD-cdty1vvszs5sUa96Gf7Ro5DvkgXtVCKYk8KJLI62YgZd5S3M0ucP5NLBc_flUi4A2B_aSkd7NDM0ELddk0y48pcF95tejcvliGIy1GRRwevdqensXXQrFweFSZVvuKo8c9pcCBVfKTSllgL0lFGyI_vz6dUYt69I1gqWBDeGcA2XQUBJqfX3o9nkhZspA7b7QxMESatoATsM_XmfhbwsyY-sTq25XIGC4awaZHViZr1YFVD6BwNZWBCEBvW5zObiD5h5A5AgWoBv14E" |
| 174 | rxresp |
| 175 | expect resp.status == 200 |
| 176 | expect resp.http.x-jwt-alg == "RS256" |
| 177 | expect resp.http.x-jwt-verify-RS256 == "1" |
| 178 | } -run |
| 179 | |
| 180 | client c6 -connect ${h1_mainfe_sock} { |
| 181 | # Token content : {"alg":"RS384","typ":"JWT"} |
| 182 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 183 | # OpenSSL cmd : openssl dgst -sha384 -sign rsa-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 184 | |
| 185 | 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" |
| 186 | rxresp |
| 187 | expect resp.status == 200 |
| 188 | expect resp.http.x-jwt-alg == "RS384" |
| 189 | expect resp.http.x-jwt-verify-RS384 == "1" |
| 190 | } -run |
| 191 | |
| 192 | client c7 -connect ${h1_mainfe_sock} { |
| 193 | # Token content : {"alg":"RS512","typ":"JWT"} |
| 194 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 195 | # OpenSSL cmd : openssl dgst -sha512 -sign rsa-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 196 | |
| 197 | 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" |
| 198 | rxresp |
| 199 | expect resp.status == 200 |
| 200 | expect resp.http.x-jwt-alg == "RS512" |
| 201 | expect resp.http.x-jwt-verify-RS512 == "1" |
| 202 | } -run |
| 203 | |
| 204 | # The following token is invalid (the signature used SHA384 instead of SHA512) |
| 205 | client c8 -connect ${h1_mainfe_sock} { |
| 206 | # Token content : {"alg":"RS512","typ":"JWT"} |
| 207 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 208 | # OpenSSL cmd : openssl dgst -sha512 -sign rsa-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 209 | |
| 210 | 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" |
| 211 | rxresp |
| 212 | expect resp.status == 200 |
| 213 | expect resp.http.x-jwt-alg == "RS512" |
| 214 | expect resp.http.x-jwt-verify-RS512 == "0" |
| 215 | } -run |
| 216 | |
| 217 | |
| 218 | |
| 219 | client c9 -connect ${h1_mainfe_sock} { |
| 220 | # Token content : {"alg":"ES256","typ":"JWT"} |
| 221 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 222 | # 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 |
| 223 | # OpenSSL cmd : openssl dgst -sha256 -sign es256-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 224 | |
| 225 | txreq -url "/es256" -hdr "Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MEYCIQCkHcfMhzhP3FvZqjaqEDW89_5QEhBwUvpXv535lAnRuQIhALc62LiFZz0oDuKeqI3ogto336D7kEg4Uat8qm_iW6ur" |
| 226 | rxresp |
| 227 | expect resp.status == 200 |
| 228 | expect resp.http.x-jwt-alg == "ES256" |
| 229 | expect resp.http.x-jwt-verify-ES256 == "1" |
| 230 | } -run |
| 231 | |
| 232 | client c10 -connect ${h1_mainfe_sock} { |
| 233 | # Token content : {"alg":"ES384","typ":"JWT"} |
| 234 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 235 | # 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 |
| 236 | # OpenSSL cmd : openssl dgst -sha384 -sign es384-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 237 | |
| 238 | txreq -url "/es384" -hdr "Authorization: Bearer eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MGUCMQDQFs6fqnmoxbw3eIQCT6km0TnMakpGy2F-8ZgGu5G8nFQKzCAO-V-UTOD0OqxHUa8CMBqHfZ6pjqRaLK-PebsvbGSzneAG7Id3oN78n2wWGKcYCI_s0KSO88thboaR9AS4tA" |
| 239 | rxresp |
| 240 | expect resp.status == 200 |
| 241 | expect resp.http.x-jwt-alg == "ES384" |
| 242 | expect resp.http.x-jwt-verify-ES384 == "1" |
| 243 | } -run |
| 244 | |
| 245 | client c11 -connect ${h1_mainfe_sock} { |
| 246 | # Token content : {"alg":"ES512","typ":"JWT"} |
| 247 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 248 | # 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 |
| 249 | # OpenSSL cmd : openssl dgst -sha512 -sign es512-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 250 | |
| 251 | txreq -url "/es512" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5fSIWfRa" |
| 252 | rxresp |
| 253 | expect resp.status == 200 |
| 254 | expect resp.http.x-jwt-alg == "ES512" |
| 255 | expect resp.http.x-jwt-verify-ES512 == "1" |
| 256 | } -run |
| 257 | |
| 258 | # The following token is invalid (too short) |
| 259 | client c12 -connect ${h1_mainfe_sock} { |
| 260 | # Token content : {"alg":"ES512","typ":"JWT"} |
| 261 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 262 | # OpenSSL cmd : openssl dgst -sha512 -sign es512-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 263 | |
| 264 | txreq -url "/es512" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5f" |
| 265 | rxresp |
| 266 | expect resp.status == 200 |
| 267 | expect resp.http.x-jwt-alg == "ES512" |
| 268 | expect resp.http.x-jwt-verify-ES512 == "0" |
| 269 | } -run |
| 270 | |
| 271 | |
| 272 | # Unmanaged algorithm |
| 273 | client c13 -connect ${h1_mainfe_sock} { |
| 274 | # Token content : {"alg":"PS512","typ":"JWT"} |
| 275 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 276 | txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJQUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5f" |
| 277 | rxresp |
| 278 | expect resp.status == 200 |
| 279 | expect resp.http.x-jwt-alg == "PS512" |
| 280 | # Unmanaged algorithm |
Remi Tricot-Le Breton | 1c891bc | 2021-10-18 15:14:49 +0200 | [diff] [blame] | 281 | expect resp.http.x-jwt-verify == "-2" |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 282 | } -run |
| 283 | |
| 284 | # Unknown algorithm |
| 285 | client c14 -connect ${h1_mainfe_sock} { |
| 286 | # Token content : {"alg":"UNKNOWN_ALG","typ":"JWT"} |
| 287 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 288 | txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJVTktOT1dOX0FMRyIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5f" |
| 289 | rxresp |
| 290 | expect resp.status == 200 |
| 291 | expect resp.http.x-jwt-alg == "UNKNOWN_ALG" |
| 292 | # Unmanaged algorithm |
Remi Tricot-Le Breton | 1c891bc | 2021-10-18 15:14:49 +0200 | [diff] [blame] | 293 | expect resp.http.x-jwt-verify == "-1" |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 294 | } -run |
| 295 | |
| 296 | # Invalid token (not enough fields) |
| 297 | client c15 -connect ${h1_mainfe_sock} { |
| 298 | # Token content : {"alg":"ES512","typ":"JWT"} |
| 299 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 300 | txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ" |
| 301 | rxresp |
| 302 | expect resp.status == 200 |
| 303 | expect resp.http.x-jwt-alg == "ES512" |
| 304 | # Unmanaged algorithm |
Remi Tricot-Le Breton | 1c891bc | 2021-10-18 15:14:49 +0200 | [diff] [blame] | 305 | expect resp.http.x-jwt-verify == "-3" |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 306 | } -run |
| 307 | |
| 308 | # Invalid token (too many fields) |
| 309 | client c16 -connect ${h1_mainfe_sock} { |
| 310 | # Token content : {"alg":"ES512","typ":"JWT"} |
| 311 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 312 | txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5f.unexpectedextrafield" |
| 313 | rxresp |
| 314 | expect resp.status == 200 |
| 315 | expect resp.http.x-jwt-alg == "ES512" |
| 316 | # Unmanaged algorithm |
Remi Tricot-Le Breton | 1c891bc | 2021-10-18 15:14:49 +0200 | [diff] [blame] | 317 | expect resp.http.x-jwt-verify == "-3" |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 318 | } -run |
| 319 | |
| 320 | # Invalid token (empty signature) |
| 321 | client c17 -connect ${h1_mainfe_sock} { |
| 322 | # Token content : {"alg":"ES512","typ":"JWT"} |
| 323 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 324 | txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ." |
| 325 | rxresp |
| 326 | expect resp.status == 200 |
| 327 | expect resp.http.x-jwt-alg == "ES512" |
| 328 | # Unmanaged algorithm |
Remi Tricot-Le Breton | 1c891bc | 2021-10-18 15:14:49 +0200 | [diff] [blame] | 329 | expect resp.http.x-jwt-verify == "-3" |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 330 | } -run |
| 331 | |
| 332 | # Unknown certificate |
| 333 | client c18 -connect ${h1_mainfe_sock} { |
| 334 | # Token content : {"alg":"ES512","typ":"JWT"} |
| 335 | # {"sub":"1234567890","name":"John Doe","iat":1516239022} |
| 336 | # 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 |
| 337 | # OpenSSL cmd : openssl dgst -sha512 -sign es512-private.pem data.txt | base64 | tr -d '=\n' | tr '/+' '_-' |
| 338 | |
| 339 | txreq -url "/errors" -hdr "Authorization: Bearer eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.MIGHAkEEPEgIrFKIDofBpFKX_mtya55QboGr09P6--v8uO85DwQWR0iKgMNSzYkL3K1lwyExG0Vtwfnife0lNe7Fn5TigAJCAY95NShiTn3tvleXVGCkkD0-HcribnMhd34QPGRc4rlwTkUg9umIUhxnEhPR--OohlmhJyIYGHuH8Ksm5fSIWfRa" |
| 340 | rxresp |
| 341 | expect resp.status == 200 |
| 342 | expect resp.http.x-jwt-alg == "ES512" |
| 343 | # Unmanaged algorithm |
Remi Tricot-Le Breton | 1c891bc | 2021-10-18 15:14:49 +0200 | [diff] [blame] | 344 | expect resp.http.x-jwt-verify == "-5" |
Remi Tricot-Le Breton | 36da606 | 2021-10-01 15:36:59 +0200 | [diff] [blame] | 345 | } -run |
Remi Tricot-Le Breton | 7da35bf | 2021-10-29 15:25:19 +0200 | [diff] [blame] | 346 | |
| 347 | |
| 348 | # Test the http_auth_bearer special cases (other header than the default "Authorization" one) |
| 349 | client c19 -connect ${h1_mainfe_sock} { |
| 350 | txreq -url "/auth_bearer" -hdr "Custom-Authorization: Bearer random_value" |
| 351 | rxresp |
| 352 | expect resp.status == 200 |
| 353 | expect resp.http.x-jwt-token == "random_value" |
| 354 | } -run |
| 355 | |
| 356 | # Test the http_auth_bearer special cases (multiple spaces after the scheme) |
| 357 | client c20 -connect ${h1_mainfe_sock} { |
| 358 | txreq -url "/auth_bearer" -hdr "Custom-Authorization: Bearer random_value" |
| 359 | rxresp |
| 360 | expect resp.status == 200 |
| 361 | expect resp.http.x-jwt-token == "random_value" |
| 362 | } -run |
| 363 | |
| 364 | # Test the http_auth_bearer special cases (no value after the scheme) |
| 365 | client c21 -connect ${h1_mainfe_sock} { |
| 366 | txreq -url "/auth_bearer" -hdr "Custom-Authorization: Bearer " |
| 367 | rxresp |
| 368 | expect resp.status == 200 |
| 369 | expect resp.http.x-jwt-token == "" |
| 370 | } -run |
| 371 | |
| 372 | # Test the http_auth_bearer special cases (no value after the scheme) |
| 373 | client c22 -connect ${h1_mainfe_sock} { |
| 374 | txreq -url "/errors" -hdr "Authorization: Bearer " |
| 375 | rxresp |
| 376 | expect resp.status == 200 |
| 377 | expect resp.http.x-jwt-token == "" |
| 378 | } -run |