コード例 #1
0
 /**
  * @return null|OpenIdDirectGenericErrorResponse|\openid\responses\OpenIdAssociationSessionResponse|OpenIdDiffieHellmanAssociationSessionResponse
  */
 public function handle()
 {
     $response = null;
     try {
         $assoc_type = $this->current_request->getAssocType();
         $session_type = $this->current_request->getSessionType();
         //DH parameters
         $public_prime = $this->current_request->getDHModulus();
         //p
         $public_generator = $this->current_request->getDHGen();
         //g
         //get (g ^ xa mod p) where xa is rp secret key
         $rp_public_key = $this->current_request->getDHConsumerPublic();
         //create association
         $association = $this->association_service->addAssociation(AssociationFactory::getInstance()->buildSessionAssociation($assoc_type, $this->server_configuration_service->getConfigValue("Session.Association.Lifetime")));
         $dh = new DiffieHellman($public_prime, $public_generator);
         $dh->generateKeys();
         //server public key (g ^ xb mod p ), where xb is server private key
         // g ^ (xa * xb) mod p = (g ^ xa) ^ xb mod p = (g ^ xb) ^ xa mod p
         $shared_secret = $dh->computeSecretKey($rp_public_key, DiffieHellman::FORMAT_NUMBER, DiffieHellman::FORMAT_BTWOC);
         $hashed_shared_secret = OpenIdCryptoHelper::digest($session_type, $shared_secret);
         $server_public_key = base64_encode($dh->getPublicKey(DiffieHellman::FORMAT_BTWOC));
         $enc_mac_key = base64_encode($association->getSecret() ^ $hashed_shared_secret);
         $response = new OpenIdDiffieHellmanAssociationSessionResponse($association->getHandle(), $session_type, $assoc_type, $association->getLifetime(), $server_public_key, $enc_mac_key);
     } catch (InvalidDHParam $exDH) {
         $response = new OpenIdDirectGenericErrorResponse($exDH->getMessage());
         $this->log_service->error($exDH);
     } catch (InvalidArgumentException $exDH1) {
         $response = new OpenIdDirectGenericErrorResponse($exDH1->getMessage());
         $this->log_service->error($exDH1);
     } catch (RuntimeException $exDH2) {
         $response = new OpenIdDirectGenericErrorResponse($exDH2->getMessage());
         $this->log_service->error($exDH2);
     }
     return $response;
 }
コード例 #2
0
 public function testGenerateKeysWithUnsetPrivateKey()
 {
     $dh = new DiffieHellman(563, 5);
     $dh->generateKeys();
     $privateKey = $dh->getPrivateKey();
     $this->assertNotNull($privateKey);
 }