From 4563685375f12de71a4fd938a00adabf55ad3c40 Mon Sep 17 00:00:00 2001 From: Ron Arts Date: Mon, 30 Oct 2017 16:21:17 +0100 Subject: [PATCH] Also accept an RSA key with crlf --- .gitattributes | 4 +++- src/CryptKey.php | 2 +- tests/CryptKeyTest.php | 6 ++++++ tests/Stubs/public.key.crlf | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/Stubs/public.key.crlf diff --git a/.gitattributes b/.gitattributes index d85a794e..bea6eefb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,4 +10,6 @@ /phpunit.xml.dist export-ignore /CHANGELOG.md export-ignore /CONTRIBUTING.md export-ignore -/README.md export-ignore \ No newline at end of file +/README.md export-ignore + ++*.crlf eol=crlf diff --git a/src/CryptKey.php b/src/CryptKey.php index 2ede9e33..0e06f7ab 100644 --- a/src/CryptKey.php +++ b/src/CryptKey.php @@ -14,7 +14,7 @@ namespace League\OAuth2\Server; class CryptKey { const RSA_KEY_PATTERN = - '/^(-----BEGIN (RSA )?(PUBLIC|PRIVATE) KEY-----\n)(.|\n)+(-----END (RSA )?(PUBLIC|PRIVATE) KEY-----)$/'; + '/^(-----BEGIN (RSA )?(PUBLIC|PRIVATE) KEY-----)(.|\n|\r)+(-----END (RSA )?(PUBLIC|PRIVATE) KEY-----)$/'; /** * @var string diff --git a/tests/CryptKeyTest.php b/tests/CryptKeyTest.php index c7f7f4a0..08bf27e8 100644 --- a/tests/CryptKeyTest.php +++ b/tests/CryptKeyTest.php @@ -21,6 +21,12 @@ class CryptKeyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('file://' . $keyFile, $key->getKeyPath()); $this->assertEquals('secret', $key->getPassPhrase()); + + $keyFile = __DIR__ . '/Stubs/public.key.crlf'; + $key = new CryptKey($keyFile, 'secret'); + + $this->assertEquals('file://' . $keyFile, $key->getKeyPath()); + $this->assertEquals('secret', $key->getPassPhrase()); } public function testKeyFileCreation() diff --git a/tests/Stubs/public.key.crlf b/tests/Stubs/public.key.crlf new file mode 100644 index 00000000..25010108 --- /dev/null +++ b/tests/Stubs/public.key.crlf @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOBcFjGUlo3BJ9zjwQLgAHn6Oy +5Si0uB7MublTiPob8rWTiCE4weAFqzPoAB07vB0t0f8c1R8rmwHMD5ljWPBgJ8Fe +wtwAUzprOBcau6DWukd/TKxXWeVLAl/NZxijI+jR5QDBYLNBtj1G4LBVHMmINd3r +yCycbf9ac3rcC8zhrQIDAQAB +-----END PUBLIC KEY-----