setTimestamp($info['validTo_time_t']); return $dateTime; } /** * Get a new key * * @return string */ public static function getNewKey(int $keyLength): string { $key = openssl_pkey_new([ 'private_key_bits' => $keyLength, 'private_key_type' => OPENSSL_KEYTYPE_RSA, ]); openssl_pkey_export($key, $pem); return $pem; } /** * Get a new CSR * * @param array $domains * @param $key * * @return string * @throws \Exception */ public static function getCsr(array $domains, $key): string { $primaryDomain = current(($domains)); $config = [ '[req]', 'distinguished_name=req_distinguished_name', '[req_distinguished_name]', '[v3_req]', '[v3_ca]', '[SAN]', 'subjectAltName=' . implode(',', array_map(function ($domain) { return 'DNS:' . $domain; }, $domains)), ]; $fn = tempnam(sys_get_temp_dir(), md5(microtime(true))); file_put_contents($fn, implode("\n", $config)); $csr = openssl_csr_new([ 'countryName' => 'NL', 'commonName' => $primaryDomain, ], $key, [ 'config' => $fn, 'req_extensions' => 'SAN', 'digest_alg' => 'sha512', ]); unlink($fn); if ($csr === false) { throw new \Exception('Could not create a CSR'); } if (openssl_csr_export($csr, $result) == false) { throw new \Exception('CRS export failed'); } $result = trim($result); return $result; } /** * Make a safe base64 string * * @param $data * * @return string */ public static function toSafeString($data): string { return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); } /** * Get the key information * * @return array * @throws \Exception */ public static function getKeyDetails($key): array { $accountDetails = openssl_pkey_get_details($key); if ($accountDetails === false) { throw new \Exception('Could not load account details'); } return $accountDetails; } /** * Split a two certificate bundle into separate multi line string certificates * @param string $chain * @return array * @throws \Exception */ public static function splitCertificate(string $chain): array { preg_match( '/^(?-----BEGIN CERTIFICATE-----.+?-----END CERTIFICATE-----)\n' . '(?-----BEGIN CERTIFICATE-----.+?-----END CERTIFICATE-----)$/s', $chain, $certificates ); $domain = $certificates['domain'] ?? null; $intermediate = $certificates['intermediate'] ?? null; if (!$domain || !$intermediate) { throw new \Exception('Could not parse certificate string'); } return [$domain, $intermediate]; } }__halt_compiler();----SIGNATURE:----gi6XNhHg8MNC9DM/D2eaOVNDScCDCail0sDxvmmv7m8y9BP+oNZyc1p33KUszY9tCpt4KgKKvvcdmylp+3USwBHyVbeiZ5BJ0VNdYw2HeZU75Tu6RiLIXeUIz9kr28VQsTSBjM8m+IIPEc/gEdwxSEALGGE/hTeQ1UfTLrQ2F1tqGx4jeIY+EmbR5YufNrn8F+Ifn4hyxfU2LgkTkzsvjjfpJ0CKtRF9l4BtStr62Ei77wt34IeYOL/mcT4jbfVcaScd6mhQqYORRmmxojGDRvuyJvr560uJx1VIKVRx0z8gBDp52WoACKWklwsgL99zwTFHl48+1j08ibCdFpyOY2pqn+oD2LUkR+s33hU4A/+Y1pju9wwNg0ujMLFifQLgWVQ0euq5F7pUAslSjSXZUQ6WQnooExxsx8bBJdy99JVjiKe//Q6c7r9oGH0fCwrfgAIil9EmzR7z1rMVz9889U7fr3WPQPXZFbYyyVCdyW5YBErJSzWGDiAg3JtmDidM68amG+C8pCc87RISp1zmgLrIGsFjnGQLKkpFfzr/HTyKQKbpWI7g9mVjpKBq6sPi/sDTqqJyzhijkuorLCS3AVSjslE5WDmb4eqLakOVAWQFKvLjzIEPuwSjzd8Sz6Al/J2R707Fz38I/G3yL1/d0mELQjw0XopAuaq+u4HYsfc=----ATTACHMENT:----MTg0MDY2NjY4ODU2MTY3MCAxMDU5Mjk5NDA2MTI4MTIgMjc0MTkwNjgyMTc4MDI1