-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from zwirek/feature/scram-sha-256-authorization
Support for scram-sha-256 authentication method
- Loading branch information
Showing
14 changed files
with
421 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PgAsync\Command; | ||
|
||
use PgAsync\ScramSha256; | ||
|
||
class SaslInitialResponse implements CommandInterface | ||
{ | ||
use CommandTrait; | ||
|
||
const SCRAM_SHA_256 = "SCRAM-SHA-256"; | ||
|
||
/** | ||
* @var ScramSha256 | ||
*/ | ||
private $scramSha265; | ||
|
||
public function __construct(ScramSha256 $scramSha265) | ||
{ | ||
$this->scramSha265 = $scramSha265; | ||
} | ||
|
||
public function encodedMessage(): string | ||
{ | ||
$mechanism = self::SCRAM_SHA_256 . "\0"; | ||
$clientFirstMessage = $this->scramSha265->getClientFirstMessage(); | ||
|
||
$message = "p"; | ||
$messageLength = strlen($mechanism) + strlen($clientFirstMessage) + 8; | ||
$message .= pack("N", $messageLength) . $mechanism; | ||
$message .= pack("N", strlen($clientFirstMessage)) . $clientFirstMessage; | ||
|
||
return $message; | ||
} | ||
|
||
public function shouldWaitForComplete(): bool | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PgAsync\Command; | ||
|
||
use PgAsync\ScramSha256; | ||
|
||
class SaslResponse implements CommandInterface | ||
{ | ||
use CommandTrait; | ||
|
||
/** | ||
* @var ScramSha256 | ||
*/ | ||
private $scramSha265; | ||
|
||
public function __construct(ScramSha256 $scramSha265) | ||
{ | ||
$this->scramSha265 = $scramSha265; | ||
} | ||
|
||
public function encodedMessage(): string | ||
{ | ||
$clientFinalMessage = $this->createClientFinalMessage(); | ||
$messageLength = strlen($clientFinalMessage) + 4; | ||
|
||
return 'p' . pack('N', $messageLength) . $clientFinalMessage; | ||
} | ||
|
||
public function shouldWaitForComplete(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
private function createClientFinalMessage(): string | ||
{ | ||
return $this->scramSha265->getClientFirstMessageWithoutProof() . ',p=' . base64_encode($this->scramSha265->getClientProof()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.