Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(manage cert): adds legacy option on cert conversion #145

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Sign/ManageCert.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@

class ManageCert
{
private string $tempDir, $originalCertContent, $password, $hashKey;
private string $tempDir;
private string $originalCertContent;
private string $password;
private string $hashKey;

private bool $preservePfx = false;
private bool $isLegacy = false;

private array $parsedData;

private OpenSSLCertificate|bool $certContent;

const CIPHER = 'aes-128-cbc';
const LEGACY_FLAG = '-legacy';

private Encrypter $encrypter;

Expand All @@ -45,6 +50,12 @@ public function setPreservePfx(bool $preservePfx = true): self
return $this;
}

public function setIsLegacy(bool $isLegacy = true): self
{
$this->isLegacy = $isLegacy;
return $this;
}

/**
* @throws CertificateOutputNotFoundException
* @throws FileNotFoundException
Expand All @@ -64,8 +75,9 @@ public function fromPfx(string $pfxPath, string $password): self
}

$this->password = $password;
$output = a1TempDir(true, '.crt');
$openSslCommand = "openssl pkcs12 -in {$pfxPath} -out {$output} -nodes -password pass:'{$this->password}'";
$output = a1TempDir(true, '.crt');
$legacyFlag = $this->isLegacy ? self::LEGACY_FLAG : '';
$openSslCommand = "openssl pkcs12 -in {$pfxPath} -out {$output} -nodes -password pass:'{$this->password}' {$legacyFlag}";

runCliCommandProcesses($openSslCommand);

Expand Down