Skip to content

Commit

Permalink
fixed authority mapping and [wip] github/workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tarach committed Dec 17, 2023
1 parent 350004a commit 9b7b322
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Context testing
on: push

jobs:
dump_contexts_to_log:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
.idea/
ssl-cert/
sslgen.phar
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```bash
export USR=userName
ssh ${USR}@192.168.56.10 mkdir ssl-cert/
cd ssl-cert/
sftp ${USR}@192.168.56.10:ssl-cert
put *

ssh ${USR}@192.168.56.10:ssl-cert
sudo cp ca.pem /root/.docker/
sudo cp server.key /root/.docker/key.pem
sudo cp server.pem /root/.docker/cert.pem

cat client.pem >> cert-and-key.pem
cat client.key >> cert-and-key.pem
curl -vv --cacert ca.pem --cert cert-and-key.pem https://192.168.56.10:2376/version
```
10 changes: 8 additions & 2 deletions src/Command/Config/Authority.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@

readonly class Authority
{
public ?string $cert;
public ?string $pkey;

public function __construct(
public ?string $cert,
public ?string $pkey
?string $cert,
?string $pkey
){
$this->cert = $cert ? realpath($cert) : null;
$this->pkey = $pkey ? realpath($pkey) : null;

$files = [
'cert' => $this->cert,
'pkey' => $this->pkey,
Expand Down
6 changes: 5 additions & 1 deletion src/SSLExporterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public function toFiles(SSLGeneratorOutput $ssl, string $directory): void

private function normalizeDirectoryPath(string $directory): string
{
$directory = realpath(rtrim($directory, '\\/')) . DIRECTORY_SEPARATOR;
$directory = rtrim($directory, '\\/') . DIRECTORY_SEPARATOR;

if ('.' === $directory[0]) {
$directory = getcwd() . DIRECTORY_SEPARATOR . $directory;
}

if (!file_exists($directory)) {
if (!@mkdir($directory)) {
Expand Down
9 changes: 7 additions & 2 deletions src/SSLGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ public function generate(DistinguishedNames $names): SSLGeneratorOutput
{
$privateKey = openssl_pkey_new($this->config->getPrivateKeyFile()->getOptions());

$days = 365;
$options = [
'digest_alg' => 'sha256',
];

// Certificate signing request
$csr = openssl_csr_new($names->getArray(), $privateKey, ['digest_alg' => 'sha256']);
$csr = openssl_csr_new($names->getArray(), $privateKey, $options);

$authority = $this->config->getAuthority();
$key = $authority->getPrivateKey() ?: $privateKey;
$certificate = openssl_csr_sign($csr, $authority->getCertificate(), $key, $days=365, ['digest_alg' => 'sha256']);
$certificate = openssl_csr_sign($csr, $authority->getCertificate(), $key, $days, $options);

return new SSLGeneratorOutput(
$privateKey,
Expand Down

0 comments on commit 9b7b322

Please sign in to comment.