diff --git a/bin/generate-keys.php b/bin/generate-keys.php deleted file mode 100644 index 38454b5..0000000 --- a/bin/generate-keys.php +++ /dev/null @@ -1,38 +0,0 @@ - 1024, - 'private_key_type' => OPENSSL_KEYTYPE_RSA, -]; - -// Private key -$res = openssl_pkey_new($config); -openssl_pkey_export($res, $privateKey); -file_put_contents($filePrivateKey, $privateKey); -printf("Private key stored in:\n%s\n", $filePrivateKey); - -// Public key -$publicKey = openssl_pkey_get_details($res); -file_put_contents($filePublicKey, $publicKey["key"]); -printf("Public key stored in:\n%s\n", $filePublicKey); - -// Encryption key -$encKey = base64_encode(random_bytes(32)); -file_put_contents($fileEncryptionKey, sprintf(" $bits = 2048, + 'private_key_type' => OPENSSL_KEYTYPE_RSA, +]; + +printf('Using %d bits to generate key of type RSA' . "\n\n", $bits); + +// Private key +$res = openssl_pkey_new($config); + +if (!is_resource($res)) { + fwrite(STDERR, 'Failed to create private key.' . PHP_EOL); + fwrite(STDERR, 'Check your openssl extension settings.' . PHP_EOL); + exit(1); +} + +openssl_pkey_export($res, $privateKey); +file_put_contents($filePrivateKey, $privateKey); +printf("Private key stored in:\n%s\n", $filePrivateKey); + +// Public key +$publicKey = openssl_pkey_get_details($res); +file_put_contents($filePublicKey, $publicKey['key']); +printf("Public key stored in:\n%s\n", $filePublicKey); + +// Encryption key +$encKey = base64_encode(random_bytes(32)); +file_put_contents($fileEncryptionKey, sprintf(" __DIR__ . '/../data/private.key', - 'public_key' => __DIR__ . '/../data/public.key', - 'encryption_key' => require __DIR__ . '/../data/encryption.key', + 'private_key' => __DIR__ . '/../data/oauth/private.key', + 'public_key' => __DIR__ . '/../data/oauth/public.key', + 'encryption_key' => require __DIR__ . '/../data/oauth/encryption.key', 'access_token_expire' => 'P1D', 'refresh_token_expire' => 'P1M', 'auth_code_expire' => 'PT10M', @@ -68,7 +68,7 @@ return [ The `private_key` and `public_key` values contains the paths to the previous generated pair of keys. The `encryption_key` contains the encryption key value -as a string, as stored in the `data/encryption.key` file. +as a string, as stored in the `data/oauth/encryption.key` file. The `access_token_expire` value is the time-to-live (TTL) value of the access token. The time period is represented using the [DateInterval](http://php.net/manual/en/class.dateinterval.php)