Exemple #1
0
 protected function extract($segment, $as_binary = false)
 {
     $stringified = JOSE_URLSafeBase64::decode($segment);
     if ($as_binary) {
         $extracted = $stringified;
     } else {
         $extracted = json_decode($stringified);
         if ($stringified !== 'null' && $extracted === null) {
             throw new JOSE_Exception_InvalidFormat('Compact de-serialization failed');
         }
     }
     return $extracted;
 }
Exemple #2
0
 function toKey()
 {
     switch ($this->components['kty']) {
         case 'RSA':
             $rsa = new RSA();
             $n = new BigInteger('0x' . bin2hex(JOSE_URLSafeBase64::decode($this->components['n'])), 16);
             $e = new BigInteger('0x' . bin2hex(JOSE_URLSafeBase64::decode($this->components['e'])), 16);
             if (array_key_exists('d', $this->components)) {
                 throw new JOSE_Exception_UnexpectedAlgorithm('RSA private key isn\'t supported');
             } else {
                 $pem_string = $rsa->_convertPublicKey($n, $e);
             }
             $rsa->loadKey($pem_string);
             return $rsa;
         default:
             throw new JOSE_Exception_UnexpectedAlgorithm('Unknown key type');
     }
 }
Exemple #3
0
 function postCheck($post, &$result)
 {
     $result = array();
     $raw = json_decode($post, true);
     // adds my public key
     $public_key = new RSA();
     $public_key->loadKey(file_get_contents('pub.key'));
     $jwk = JOSE_JWK::encode($public_key);
     //print_r($jwk);
     $jwt = new JOSE_JWT();
     $jwt->raw = $raw["protected"] . "." . $raw["payload"] . "." . $raw["signature"];
     $jwt->header = json_decode(JOSE_URLSafeBase64::decode($raw["protected"]), true);
     $jwt->claims = json_decode(JOSE_URLSafeBase64::decode($raw["payload"]), true);
     $jwt->signature = JOSE_URLSafeBase64::decode($raw["signature"]);
     // echo "S:\n"; echo JOSE_URLSafeBase64::decode($raw["signature"]);
     file_put_contents("/tmp/jwt", print_r($jwt, true));
     //print_r($jwt);
     print_r($jwt->verify($public_key));
 }