From 808a0fde6de622bdd5cb70405308ac5163d8529d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Sat, 7 Mar 2015 02:20:22 -0300 Subject: [PATCH] Adding a way to easily retrieve the keys. --- private_key.pem | 30 ++++++++ src/Signer/Keychain.php | 58 +++++++++++++++ test/RsaKeys.php | 139 ++++++++++++++++++++++++----------- test/Signer/KeychainTest.php | 100 +++++++++++++++++++++++++ 4 files changed, 286 insertions(+), 41 deletions(-) create mode 100644 private_key.pem create mode 100644 src/Signer/Keychain.php create mode 100644 test/Signer/KeychainTest.php diff --git a/private_key.pem b/private_key.pem new file mode 100644 index 00000000..f0cebeb7 --- /dev/null +++ b/private_key.pem @@ -0,0 +1,30 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-128-CBC,0D71668CE71033CB9150ED82FC87F4A1 + +uLzPNDdlHnZ77tAGMHyPYERDMBcdV4SsQJYcSjiHhR2o0dLGTdgOpQrXTHPX4GJF +LlEWLhAAV9wx2mM/2kHDWB4uZwThtT9/v+RFoW1WbVO/d3lhI9fg4/73/DWAH/7/ +afMRc7ZOVoAmVCESotPx4khCHoE97RdY/JtkLTzc3+peqmL53AbYXrg9rTN1B+ZV +U3w4ciQS8Uki87zDYIBjYtaOCyMUTvug25CvdssvUMBoc/Jc0xps6/vAyXrnzlGT +pZD0Tst8idswfDi613BhAaxJspeY0AErWA59qJ3eGzbiQq5RDWcbJe/Tz5r/6+NN +DkvNQ7DaEZ6LpeWX0MUq6/QWfrM8yE95XhjyC1d3LYn32lXHUygbgTFWIgLDoOE6 +nBhu34SWtbLAnqYGewaJFxhlYVS9rb/uvYQg70r5X9Sx6alCQPiPyIv39IItezn2 +HF2GRfE91MPZUeDhdqdvvOlSZVM5KnYc1fhamGAwM48gdDDXe8Czu/JEGoANNvC3 +l/Z1p5RtGF4hrel9WpeX9zQq3pvtfVcVIiW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9c +-----END RSA PRIVATE KEY----- diff --git a/src/Signer/Keychain.php b/src/Signer/Keychain.php new file mode 100644 index 00000000..dff10f5f --- /dev/null +++ b/src/Signer/Keychain.php @@ -0,0 +1,58 @@ + + * @since 2.1.0 + */ +class Keychain +{ + /** + * Returns a private key from file path or content + * + * @param string $key + * @param string $passphrase + * + * @return resource + * + * @throws InvalidArgumentException + */ + public function getPrivateKey($key, $passphrase = '') + { + if ($privateKey = openssl_pkey_get_private($key, $passphrase)) { + return $privateKey; + } + + throw new InvalidArgumentException( + 'You should provid a valid private key (with its passphrase when used)' + ); + } + + /** + * Returns a public key from file path or content + * + * @param string $certificate + * + * @return resource + * + * @throws InvalidArgumentException + */ + public function getPublicKey($certificate) + { + if ($publicKey = openssl_pkey_get_public($certificate)) { + return $publicKey; + } + + throw new InvalidArgumentException('You should provid a valid certificate'); + } +} diff --git a/test/RsaKeys.php b/test/RsaKeys.php index 396b5b38..532faae6 100644 --- a/test/RsaKeys.php +++ b/test/RsaKeys.php @@ -13,41 +13,108 @@ */ trait RsaKeys { + /** + * @return string + */ + protected function encryptedPrivateRsaContent() + { + return '-----BEGIN RSA PRIVATE KEY-----' . PHP_EOL + . 'Proc-Type: 4,ENCRYPTED' . PHP_EOL + . 'DEK-Info: AES-128-CBC,0D71668CE71033CB9150ED82FC87F4A1' . PHP_EOL + . '' . PHP_EOL + . 'uLzPNDdlHnZ77tAGMHyPYERDMBcdV4SsQJYcSjiHhR2o0dLGTdgOpQrXTHPX4GJF' . PHP_EOL + . 'LlEWLhAAV9wx2mM/2kHDWB4uZwThtT9/v+RFoW1WbVO/d3lhI9fg4/73/DWAH/7/' . PHP_EOL + . 'afMRc7ZOVoAmVCESotPx4khCHoE97RdY/JtkLTzc3+peqmL53AbYXrg9rTN1B+ZV' . PHP_EOL + . 'U3w4ciQS8Uki87zDYIBjYtaOCyMUTvug25CvdssvUMBoc/Jc0xps6/vAyXrnzlGT' . PHP_EOL + . 'pZD0Tst8idswfDi613BhAaxJspe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PJk1b1lPq2Ui4hXpVNOYd4Q6OQz7bwxTMRX9XQromUlKMMgAT' . PHP_EOL + . 'edX8v2NdM7Ssy1IwHuGVbDEpZdjoeaWZ1iNRV17i/EaJAqwYDQLfsuHBlzZL1ov1' . PHP_EOL + . 'xkKVJdL8Y3q80oRAzTQDVdzL/rI44LLAfv609YByCnw29feYJY2W6gV0O7ZSw413' . PHP_EOL + . 'XUkc5CaEbR1LuG8NtnOOPJV4Tb/hNsIDtvVm7Hl5npBKBe4iVgQ2LNuC2eT69d/z' . PHP_EOL + . 'uvzgjISlumPiO5ivuYe0QtLPuJSc+/Bl8bPL8gcNQEtqkzj7IftHPPZNs+bJC2uY' . PHP_EOL + . 'bPjq5KoDNAMF6VHuKHwu48MBYpnXDIg3ZenmJwGRULRBhK6324hDS6NJ7ULTBU2M' . PHP_EOL + . 'TZCHmg89ySLBfCAspVeo63o/R7bs9a7BP9x2h5uwCBogSvkEwhhPKnboVN45bp9c' . PHP_EOL + . '-----END RSA PRIVATE KEY-----'; + } + + /** + * @return string + */ + protected function privateRsaContent() + { + return '-----BEGIN PRIVATE KEY-----' . PHP_EOL + . 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDTvwE87MtgREYL' . PHP_EOL + . 'TL4aHhQo3ZzogmxxvMUsKnPzyxRs1YrXOSOpwN0npsXarBKKVIUMNLfFODp/vnQn' . PHP_EOL + . '2Zp06N8XG59WAOKwvC4MfxLDQkA+JXggzHlkbVoTN+dUkdYIFqSKuAPGwiWToRK2' . PHP_EOL + . 'SxEhij3rE2FON8jQZvDxZkiP9a4vxJO3OTPQwKredXFiObsXD/c3RtLFhKctjCyH' . PHP_EOL + . 'OIrP0bQEsee/m7JNtG4ry6BPusN6wb+vJo5ieBYPa3c19akNq6q/nYWhplhkkJSu' . PHP_EOL + . 'aOrL5xXEFzI5TvcvnXR568GVcxK8YLfFkdxpsXGt5rAbeh0h/U5kILEAqv8P9PGT' . PHP_EOL + . 'ZpicKbrnAgMBAAECggEAd3yTQEQHR91/ASVfKPHMQns77eCbPVtekFusbugsMHYY' . PHP_EOL + . 'EPdHbqVMpvFvOMRc+f5Tzd15ziq6qBdbCJm8lThLm4iU0z1QrpaiDZ8vgUvDYM5Y' . PHP_EOL + . 'CXoZDli+uZWUTp60/n94fmb0ipZIChScsI2PrzOJWTvobvD/uso8MJydWc8zafQm' . PHP_EOL + . 'uqYzygOfjFZvU4lSfgzpefhpquy0JUy5TiKRmGUnwLb3TtcsVavjsn4QmNwLYgOF' . PHP_EOL + . '2OE+R12ex3pAKTiRE6FcnE1xFIo1GKhBa2Otgw3MDO6Gg+kn8Q4alKz6C6RRlgaH' . PHP_EOL + . 'R7sYzEfJhsk/GGFTYOzXKQz2lSaStKt9wKCor04RcQKBgQDzPOu5jCTfayUo7xY2' . PHP_EOL + . 'jHtiogHyKLLObt9l3qbwgXnaD6rnxYNvCrA0OMvT+iZXsFZKJkYzJr8ZOxOpPROk' . PHP_EOL + . '10WdOaefiwUyL5dypueSwlIDwVm+hI4Bs82MajHtzOozh+73wA+aw5rPs84Uix9w' . PHP_EOL + . 'VbbwaVR6qP/BV09yJYS5kQ7fmwKBgQDe2xjywX2d2MC+qzRr+LfU+1+gq0jjhBCX' . PHP_EOL + . 'WHqRN6IECB0xTnXUf9WL/VCoI1/55BhdbbEja+4btYgcXSPmlXBIRKQ4VtFfVmYB' . PHP_EOL + . 'kPXeD8oZ7LyuNdCsbKNe+x1IHXDe6Wfs3L9ulCfXxeIE84wy3fd66mQahyXV9iD9' . PHP_EOL + . 'CkuifMqUpQKBgQCiydHlY1LGJ/o9tA2Ewm5Na6mrvOs2V2Ox1NqbObwoYbX62eiF' . PHP_EOL + . '53xX5u8bVl5U75JAm+79it/4bd5RtKux9dUETbLOhwcaOFm+hM+VG/IxyzRZ2nMD' . PHP_EOL + . '1qcpY2U5BpxzknUvYF3RMTop6edxPk7zKpp9ubCtSu+oINvtxAhY/SkcIwKBgGP1' . PHP_EOL + . 'upcImyO2GZ5shLL5eNubdSVILwV+M0LveOqyHYXZbd6z5r5OKKcGFKuWUnJwEU22' . PHP_EOL + . '6gGNY9wh7M9sJ7JBzX9c6pwqtPcidda2AtJ8GpbOTUOG9/afNBhiYpv6OKqD3w2r' . PHP_EOL + . 'ZmJfKg/qvpqh83zNezgy8nvDqwDxyZI2j/5uIx/RAoGBAMWRmxtv6H2cKhibI/aI' . PHP_EOL + . 'MTJM4QRjyPNxQqvAQsv+oHUbid06VK3JE+9iQyithjcfNOwnCaoO7I7qAj9QEfJS' . PHP_EOL + . 'MZQc/W/4DHJebo2kd11yoXPVTXXOuEwLSKCejBXABBY0MPNuPUmiXeU0O3Tyi37J' . PHP_EOL + . 'TUKzrgcd7NvlA41Y4xKcOqEA' . PHP_EOL + . '-----END PRIVATE KEY-----'; + } + + /** + * @return string + */ + protected function publicRsaContent() + { + return '-----BEGIN PUBLIC KEY-----' . PHP_EOL + . 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA078BPOzLYERGC0y+Gh4U' . PHP_EOL + . 'KN2c6IJscbzFLCpz88sUbNWK1zkjqcDdJ6bF2qwSilSFDDS3xTg6f750J9madOjf' . PHP_EOL + . 'FxufVgDisLwuDH8Sw0JAPiV4IMx5ZG1aEzfnVJHWCBakirgDxsIlk6EStksRIYo9' . PHP_EOL + . '6xNhTjfI0Gbw8WZIj/WuL8STtzkz0MCq3nVxYjm7Fw/3N0bSxYSnLYwshziKz9G0' . PHP_EOL + . 'BLHnv5uyTbRuK8ugT7rDesG/ryaOYngWD2t3NfWpDauqv52FoaZYZJCUrmjqy+cV' . PHP_EOL + . 'xBcyOU73L510eevBlXMSvGC3xZHcabFxreawG3odIf1OZCCxAKr/D/Txk2aYnCm6' . PHP_EOL + . '5wIDAQAB' . PHP_EOL + . '-----END PUBLIC KEY-----'; + } + /** * @return string */ protected function privateRsa() { - return openssl_pkey_get_private( - '-----BEGIN PRIVATE KEY-----' . PHP_EOL - . 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDTvwE87MtgREYL' . PHP_EOL - . 'TL4aHhQo3ZzogmxxvMUsKnPzyxRs1YrXOSOpwN0npsXarBKKVIUMNLfFODp/vnQn' . PHP_EOL - . '2Zp06N8XG59WAOKwvC4MfxLDQkA+JXggzHlkbVoTN+dUkdYIFqSKuAPGwiWToRK2' . PHP_EOL - . 'SxEhij3rE2FON8jQZvDxZkiP9a4vxJO3OTPQwKredXFiObsXD/c3RtLFhKctjCyH' . PHP_EOL - . 'OIrP0bQEsee/m7JNtG4ry6BPusN6wb+vJo5ieBYPa3c19akNq6q/nYWhplhkkJSu' . PHP_EOL - . 'aOrL5xXEFzI5TvcvnXR568GVcxK8YLfFkdxpsXGt5rAbeh0h/U5kILEAqv8P9PGT' . PHP_EOL - . 'ZpicKbrnAgMBAAECggEAd3yTQEQHR91/ASVfKPHMQns77eCbPVtekFusbugsMHYY' . PHP_EOL - . 'EPdHbqVMpvFvOMRc+f5Tzd15ziq6qBdbCJm8lThLm4iU0z1QrpaiDZ8vgUvDYM5Y' . PHP_EOL - . 'CXoZDli+uZWUTp60/n94fmb0ipZIChScsI2PrzOJWTvobvD/uso8MJydWc8zafQm' . PHP_EOL - . 'uqYzygOfjFZvU4lSfgzpefhpquy0JUy5TiKRmGUnwLb3TtcsVavjsn4QmNwLYgOF' . PHP_EOL - . '2OE+R12ex3pAKTiRE6FcnE1xFIo1GKhBa2Otgw3MDO6Gg+kn8Q4alKz6C6RRlgaH' . PHP_EOL - . 'R7sYzEfJhsk/GGFTYOzXKQz2lSaStKt9wKCor04RcQKBgQDzPOu5jCTfayUo7xY2' . PHP_EOL - . 'jHtiogHyKLLObt9l3qbwgXnaD6rnxYNvCrA0OMvT+iZXsFZKJkYzJr8ZOxOpPROk' . PHP_EOL - . '10WdOaefiwUyL5dypueSwlIDwVm+hI4Bs82MajHtzOozh+73wA+aw5rPs84Uix9w' . PHP_EOL - . 'VbbwaVR6qP/BV09yJYS5kQ7fmwKBgQDe2xjywX2d2MC+qzRr+LfU+1+gq0jjhBCX' . PHP_EOL - . 'WHqRN6IECB0xTnXUf9WL/VCoI1/55BhdbbEja+4btYgcXSPmlXBIRKQ4VtFfVmYB' . PHP_EOL - . 'kPXeD8oZ7LyuNdCsbKNe+x1IHXDe6Wfs3L9ulCfXxeIE84wy3fd66mQahyXV9iD9' . PHP_EOL - . 'CkuifMqUpQKBgQCiydHlY1LGJ/o9tA2Ewm5Na6mrvOs2V2Ox1NqbObwoYbX62eiF' . PHP_EOL - . '53xX5u8bVl5U75JAm+79it/4bd5RtKux9dUETbLOhwcaOFm+hM+VG/IxyzRZ2nMD' . PHP_EOL - . '1qcpY2U5BpxzknUvYF3RMTop6edxPk7zKpp9ubCtSu+oINvtxAhY/SkcIwKBgGP1' . PHP_EOL - . 'upcImyO2GZ5shLL5eNubdSVILwV+M0LveOqyHYXZbd6z5r5OKKcGFKuWUnJwEU22' . PHP_EOL - . '6gGNY9wh7M9sJ7JBzX9c6pwqtPcidda2AtJ8GpbOTUOG9/afNBhiYpv6OKqD3w2r' . PHP_EOL - . 'ZmJfKg/qvpqh83zNezgy8nvDqwDxyZI2j/5uIx/RAoGBAMWRmxtv6H2cKhibI/aI' . PHP_EOL - . 'MTJM4QRjyPNxQqvAQsv+oHUbid06VK3JE+9iQyithjcfNOwnCaoO7I7qAj9QEfJS' . PHP_EOL - . 'MZQc/W/4DHJebo2kd11yoXPVTXXOuEwLSKCejBXABBY0MPNuPUmiXeU0O3Tyi37J' . PHP_EOL - . 'TUKzrgcd7NvlA41Y4xKcOqEA' . PHP_EOL - . '-----END PRIVATE KEY-----' - ); + return openssl_pkey_get_private($this->privateRsaContent()); + } + + /** + * @return string + */ + protected function encryptedPrivateRsa() + { + return openssl_pkey_get_private($this->encryptedPrivateRsaContent(), 'testing'); } /** @@ -55,16 +122,6 @@ protected function privateRsa() */ protected function publicRsa() { - return openssl_pkey_get_public( - '-----BEGIN PUBLIC KEY-----' . PHP_EOL - . 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA078BPOzLYERGC0y+Gh4U' . PHP_EOL - . 'KN2c6IJscbzFLCpz88sUbNWK1zkjqcDdJ6bF2qwSilSFDDS3xTg6f750J9madOjf' . PHP_EOL - . 'FxufVgDisLwuDH8Sw0JAPiV4IMx5ZG1aEzfnVJHWCBakirgDxsIlk6EStksRIYo9' . PHP_EOL - . '6xNhTjfI0Gbw8WZIj/WuL8STtzkz0MCq3nVxYjm7Fw/3N0bSxYSnLYwshziKz9G0' . PHP_EOL - . 'BLHnv5uyTbRuK8ugT7rDesG/ryaOYngWD2t3NfWpDauqv52FoaZYZJCUrmjqy+cV' . PHP_EOL - . 'xBcyOU73L510eevBlXMSvGC3xZHcabFxreawG3odIf1OZCCxAKr/D/Txk2aYnCm6' . PHP_EOL - . '5wIDAQAB' . PHP_EOL - . '-----END PUBLIC KEY-----' - ); + return openssl_pkey_get_public($this->publicRsaContent()); } } diff --git a/test/Signer/KeychainTest.php b/test/Signer/KeychainTest.php new file mode 100644 index 00000000..897d60b7 --- /dev/null +++ b/test/Signer/KeychainTest.php @@ -0,0 +1,100 @@ + + * @since 2.1.0 + */ +class KeychainTest extends \PHPUnit_Framework_TestCase +{ + use RsaKeys; + + /** + * @test + * + * @covers Lcobucci\JWT\Signer\Keychain::getPrivateKey + * + * @expectedException \InvalidArgumentException + */ + public function getPrivateKeyShouldRaiseExceptionWhenInvalidKeyIsInformed() + { + $keychain = new Keychain(); + $keychain->getPrivateKey('blablabla'); + } + + /** + * @test + * + * @uses Lcobucci\JWT\RsaKeys + * + * @covers Lcobucci\JWT\Signer\Keychain::getPrivateKey + */ + public function getPrivateKeyShouldReturnAValidResource() + { + $keychain = new Keychain(); + + $privateKey = $keychain->getPrivateKey($this->privateRsaContent()); + + $this->assertInternalType('resource', $privateKey); + $this->assertEquals(openssl_pkey_get_details($privateKey), openssl_pkey_get_details($this->privateRsa())); + } + + /** + * @test + * + * @uses Lcobucci\JWT\RsaKeys + * + * @covers Lcobucci\JWT\Signer\Keychain::getPrivateKey + */ + public function getPrivateKeyShouldBeAbleToUseAPassphrase() + { + $keychain = new Keychain(); + + $privateKey = $keychain->getPrivateKey($this->encryptedPrivateRsaContent(), 'testing'); + + $this->assertInternalType('resource', $privateKey); + + $this->assertEquals( + openssl_pkey_get_details($privateKey), + openssl_pkey_get_details($this->encryptedPrivateRsa()) + ); + } + + /** + * @test + * + * @covers Lcobucci\JWT\Signer\Keychain::getPublicKey + * + * @expectedException \InvalidArgumentException + */ + public function getPublicKeyShouldRaiseExceptionWhenInvalidCertificateIsInformed() + { + $keychain = new Keychain(); + $keychain->getPublicKey('blablabla'); + } + + /** + * @test + * + * @uses Lcobucci\JWT\RsaKeys + * + * @covers Lcobucci\JWT\Signer\Keychain::getPublicKey + */ + public function getPublicKeyShouldReturnAValidResource() + { + $keychain = new Keychain(); + + $publicKey = $keychain->getPublicKey($this->publicRsaContent()); + + $this->assertInternalType('resource', $publicKey); + $this->assertEquals(openssl_pkey_get_details($publicKey), openssl_pkey_get_details($this->publicRsa())); + } +}