|
5 | 5 | use Lcobucci\JWT\Parser; |
6 | 6 | use Lcobucci\JWT\Signer\Key; |
7 | 7 | use Lcobucci\JWT\ValidationData; |
8 | | -use CoderCat\JWKToPEM\JWKConverter; |
| 8 | +use Jose\Component\Core\JWK; |
| 9 | +use Jose\Component\Core\Util\ECKey; |
| 10 | +use Jose\Component\Core\Util\RSAKey; |
9 | 11 |
|
10 | 12 | class DPop { |
11 | 13 | public function getWebId($request) { |
@@ -111,17 +113,25 @@ private function validateDpop($dpop, $request) { |
111 | 113 | if ($alg == "none") { |
112 | 114 | throw new \Exception("alg is none"); |
113 | 115 | } |
114 | | - if ($alg != "RS256") { |
115 | | - throw new \Exception("alg is not supported"); |
116 | | - } |
117 | 116 |
|
118 | 117 | //error_log("5"); |
119 | 118 | // 5. that the JWT is signed using the public key contained in the |
120 | 119 | // "jwk" header of the JWT, |
121 | 120 | $jwk = $dpop->getHeader("jwk"); |
122 | | - $jwkConverter = new JWKConverter(); |
123 | | - $pem = $jwkConverter->toPEM(json_decode(json_encode($jwk), true)); |
124 | | - $signer = new \Lcobucci\JWT\Signer\Rsa\Sha256(); |
| 121 | + $webTokenJwk = \Jose\Component\Core\JWK::createFromJson(json_encode($jwk)); |
| 122 | + switch ($alg) { |
| 123 | + case "RS256": |
| 124 | + $pem = \Jose\Component\Core\Util\RSAKey::createFromJWK($webTokenJwk)->toPEM(); |
| 125 | + $signer = new \Lcobucci\JWT\Signer\Rsa\Sha256(); |
| 126 | + break; |
| 127 | + case "ES256": |
| 128 | + $pem = \Jose\Component\Core\Util\ECKey::convertToPEM($webTokenJwk); |
| 129 | + $signer = new \Lcobucci\JWT\Signer\Ecdsa\Sha256(); |
| 130 | + break; |
| 131 | + default: |
| 132 | + throw new \Exception("unsupported algorithm"); |
| 133 | + break; |
| 134 | + } |
125 | 135 | $key = new \Lcobucci\JWT\Signer\Key($pem); |
126 | 136 | if (!$dpop->verify($signer, $key)) { |
127 | 137 | throw new \Exception("invalid signature"); |
|
0 commit comments