mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Cache S/MIME certificates info #259
This commit is contained in:
parent
f5f3a90275
commit
479452ad7b
2 changed files with 51 additions and 51 deletions
|
|
@ -51,20 +51,6 @@ trait SMime
|
||||||
$this->SMIME()->certificates()
|
$this->SMIME()->certificates()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
DoGetPGPKeys() : array
|
|
||||||
DoPgpSearchKey() : array
|
|
||||||
DoGnupgDecrypt() : array
|
|
||||||
DoGnupgGetKeys() : array
|
|
||||||
DoGnupgExportKey() : array
|
|
||||||
DoGnupgGenerateKey() : array
|
|
||||||
DoGnupgDeleteKey() : array
|
|
||||||
DoPgpImportKey() : array
|
|
||||||
DoGetStoredPGPKeys() : array
|
|
||||||
DoPgpStoreKeyPair() : array
|
|
||||||
DoStorePGPKey() : array
|
|
||||||
DoPgpVerifyMessage() : array
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be use by Identity
|
* Can be use by Identity
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ class OpenSSL
|
||||||
public function certificates() : array
|
public function certificates() : array
|
||||||
{
|
{
|
||||||
$keys = [];
|
$keys = [];
|
||||||
|
|
||||||
|
$cacheFile = "{$this->homedir}/certificates.json";
|
||||||
|
if (\file_exists($cacheFile)) {
|
||||||
|
$keys = \json_decode(\file_get_contents($cacheFile), true);
|
||||||
|
} else {
|
||||||
foreach (\glob("{$this->homedir}/*.key") as $file) {
|
foreach (\glob("{$this->homedir}/*.key") as $file) {
|
||||||
$data = \file_get_contents($file);
|
$data = \file_get_contents($file);
|
||||||
// Can't check ENCRYPTED PRIVATE KEY
|
// Can't check ENCRYPTED PRIVATE KEY
|
||||||
|
|
@ -37,12 +42,18 @@ class OpenSSL
|
||||||
}
|
}
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach (\glob("{$this->homedir}/*.crt") as $file) {
|
foreach (\glob("{$this->homedir}/*.crt") as $file) {
|
||||||
$name = \basename($file);
|
$filename = \basename($file);
|
||||||
$certificate = \file_get_contents($file);
|
$certificate = \file_get_contents($file);
|
||||||
$data = \openssl_x509_parse($certificate);
|
$data = \openssl_x509_parse($certificate);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
|
$key = \str_replace(':', '', $data['extensions']['subjectKeyIdentifier'] ?? $data['hash']);
|
||||||
|
if ("{$key}.crt" != $filename && \rename("{$this->homedir}/{$filename}", "{$this->homedir}/{$key}.crt")) {
|
||||||
|
$filename = "{$key}.crt";
|
||||||
|
}
|
||||||
|
// Use $data['extensions']['authorityKeyIdentifier'] to bundle parent certificate
|
||||||
$short = [
|
$short = [
|
||||||
'file' => \basename($file),
|
'file' => $filename,
|
||||||
|
'id' => $key,
|
||||||
'CN' => $data['subject']['CN'],
|
'CN' => $data['subject']['CN'],
|
||||||
'emailAddress' => $data['subject']['emailAddress'],
|
'emailAddress' => $data['subject']['emailAddress'],
|
||||||
// 'validTo' => \gmdate('Y-m-d\\TH:i:s\\Z', $data['validTo_time_t']),
|
// 'validTo' => \gmdate('Y-m-d\\TH:i:s\\Z', $data['validTo_time_t']),
|
||||||
|
|
@ -68,6 +79,9 @@ class OpenSSL
|
||||||
\error_log("OpenSSL parse({$file}): " . \openssl_error_string());
|
\error_log("OpenSSL parse({$file}): " . \openssl_error_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
\file_put_contents($cacheFile, \json_encode($result));
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue