|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Console\Commands\Oauth2; |
|
6
|
|
|
|
|
7
|
|
|
use Opulence\Console\Commands\Command; |
|
8
|
|
|
use Opulence\Console\Responses\IResponse; |
|
9
|
|
|
|
|
10
|
|
|
class GenerateKeys extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
const NAME = 'oauth2:generatekeys'; |
|
13
|
|
|
|
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
protected $privateKeyPassword; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
protected $privateKeyPath; |
|
19
|
|
|
|
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
protected $publicKeyPath; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* GenerateKeys constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $privateKeyPassword |
|
27
|
|
|
* @param string $privateKeyPath |
|
28
|
|
|
* @param string $publicKeyPath |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(string $privateKeyPassword, string $privateKeyPath, string $publicKeyPath) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->privateKeyPassword = $privateKeyPassword; |
|
33
|
|
|
$this->privateKeyPath = $privateKeyPath; |
|
34
|
|
|
$this->publicKeyPath = $publicKeyPath; |
|
35
|
|
|
|
|
36
|
|
|
parent::__construct(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function define() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->setName(static::NAME) |
|
45
|
|
|
->setDescription('Generates openssl keys'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @inheritdoc |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function doExecute(IResponse $response) |
|
52
|
|
|
{ |
|
53
|
|
|
exec( |
|
54
|
|
|
sprintf( |
|
55
|
|
|
'openssl genrsa -passout pass:%s -out %s 2048', |
|
56
|
|
|
$this->privateKeyPassword, |
|
57
|
|
|
$this->privateKeyPath |
|
58
|
|
|
) |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
exec( |
|
62
|
|
|
sprintf( |
|
63
|
|
|
'openssl rsa -in %s -passin pass:%s -pubout -out %s', |
|
64
|
|
|
$this->privateKeyPath, |
|
65
|
|
|
$this->privateKeyPassword, |
|
66
|
|
|
$this->publicKeyPath |
|
67
|
|
|
) |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
chmod($this->privateKeyPath, 0600); |
|
71
|
|
|
chmod($this->publicKeyPath, 0600); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|