diff --git a/.github/workflows/copyright.yml b/.github/workflows/copyright.yml new file mode 100644 index 0000000..4b1bff4 --- /dev/null +++ b/.github/workflows/copyright.yml @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: Estonian Information System Authority +# SPDX-License-Identifier: MIT + +name: Copyright +on: [push, pull_request] +permissions: + contents: read +jobs: + copyright: + name: Check copyright headers + uses: web-eid/.github/.github/workflows/copyright.yml@copyright diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index dcb7450..31b67bc 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Estonian Information System Authority +# SPDX-License-Identifier: MIT + name: Coverity Scan on: diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index bbf6c5c..9be3325 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Estonian Information System Authority +# SPDX-License-Identifier: MIT + name: PHP Composer on: diff --git a/LICENSE b/LICENSE index 31623c1..422c40b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022-2024 Estonian Information System Authority +Copyright (c) Estonian Information System Authority Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/example/public/index.php b/example/public/index.php index 094c1c1..770c640 100644 --- a/example/public/index.php +++ b/example/public/index.php @@ -1,26 +1,6 @@ configArr = $configArr; - return $instance; - } - - public function overrideFromEnv() - { - foreach ($this->configArr as $key => $value) { - $envKey = 'WEB_EID_SAMPLE_'.strtoupper($key); - $envValue = getenv($envKey); - if ($envValue !== false) { - $this->configArr[$key] = $envValue; - } - } - - return $this; - } - - public function get($name) - { - return isset ($this->configArr[$name]) ? $this->configArr[$name] : null; - } +configArr = $configArr; + return $instance; + } + + public function overrideFromEnv() + { + foreach ($this->configArr as $key => $value) { + $envKey = 'WEB_EID_SAMPLE_'.strtoupper($key); + $envValue = getenv($envKey); + if ($envValue !== false) { + $this->configArr[$key] = $envValue; + } + } + + return $this; + } + + public function get($name) + { + return isset ($this->configArr[$name]) ? $this->configArr[$name] : null; + } } \ No newline at end of file diff --git a/example/src/LogWriter.php b/example/src/LogWriter.php index 62424a3..b9faf6a 100644 --- a/example/src/LogWriter.php +++ b/example/src/LogWriter.php @@ -1,26 +1,6 @@ loadX509($fileContent); - if (!$loaded) { - throw new OcspCertificateException( - "Certificate decoding from Base64 or parsing failed for " . - $pathToFile - ); - } - $this->certificate = $certificate; - return $this; - } - - /** - * Loads the certificate from string and returns the certificate - * - * @param string certString - certificate as string - * @throws OcspCertificateException when the certificate decoding or parse fails - */ - public function fromString(string $certString) - { - $certificate = new X509(); - $loaded = false; - try { - $loaded = $certificate->loadX509($certString); - } catch (Exception $e) { - } - if (!$loaded) { - throw new OcspCertificateException( - "Certificate decoding from Base64 or parsing failed" - ); - } - $this->certificate = $certificate; - return $this; - } - - public function getIssuerCertificateUrl(): string - { - if (!$this->certificate) { - throw new OcspCertificateException("Certificate not loaded"); - } - - $url = ""; - $opts = $this->certificate->getExtension("id-pe-authorityInfoAccess"); - foreach ($opts as $opt) { - if ($opt["accessMethod"] == "id-ad-caIssuers") { - $url = $opt["accessLocation"]["uniformResourceIdentifier"]; - break; - } - } - return $url; - } - - public function getOcspResponderUrl(): string - { - if (!$this->certificate) { - throw new OcspCertificateException("Certificate not loaded"); - } - - $url = ""; - $opts = $this->certificate->getExtension("id-pe-authorityInfoAccess"); - foreach ($opts as $opt) { - if ($opt["accessMethod"] == "id-ad-ocsp" || $opt["accessMethod"] == "id-pkix-ocsp") { - $url = $opt["accessLocation"]["uniformResourceIdentifier"]; - break; - } - } - return $url; - } - - public function getCert(): X509 - { - if (!$this->certificate) { - throw new OcspCertificateException("Certificate not loaded"); - } - return $this->certificate; - } -} +loadX509($fileContent); + if (!$loaded) { + throw new OcspCertificateException( + "Certificate decoding from Base64 or parsing failed for " . + $pathToFile + ); + } + $this->certificate = $certificate; + return $this; + } + + /** + * Loads the certificate from string and returns the certificate + * + * @param string certString - certificate as string + * @throws OcspCertificateException when the certificate decoding or parse fails + */ + public function fromString(string $certString) + { + $certificate = new X509(); + $loaded = false; + try { + $loaded = $certificate->loadX509($certString); + } catch (Exception $e) { + } + if (!$loaded) { + throw new OcspCertificateException( + "Certificate decoding from Base64 or parsing failed" + ); + } + $this->certificate = $certificate; + return $this; + } + + public function getIssuerCertificateUrl(): string + { + if (!$this->certificate) { + throw new OcspCertificateException("Certificate not loaded"); + } + + $url = ""; + $opts = $this->certificate->getExtension("id-pe-authorityInfoAccess"); + foreach ($opts as $opt) { + if ($opt["accessMethod"] == "id-ad-caIssuers") { + $url = $opt["accessLocation"]["uniformResourceIdentifier"]; + break; + } + } + return $url; + } + + public function getOcspResponderUrl(): string + { + if (!$this->certificate) { + throw new OcspCertificateException("Certificate not loaded"); + } + + $url = ""; + $opts = $this->certificate->getExtension("id-pe-authorityInfoAccess"); + foreach ($opts as $opt) { + if ($opt["accessMethod"] == "id-ad-ocsp" || $opt["accessMethod"] == "id-pkix-ocsp") { + $url = $opt["accessLocation"]["uniformResourceIdentifier"]; + break; + } + } + return $url; + } + + public function getCert(): X509 + { + if (!$this->certificate) { + throw new OcspCertificateException("Certificate not loaded"); + } + return $this->certificate; + } +} diff --git a/src/ocsp/exceptions/OcspCertificateException.php b/src/ocsp/exceptions/OcspCertificateException.php index b8c332c..eb03f8f 100644 --- a/src/ocsp/exceptions/OcspCertificateException.php +++ b/src/ocsp/exceptions/OcspCertificateException.php @@ -1,26 +1,6 @@ mockedClock)) { - return $this->mockedClock; - } - return new DateTime(); - } - - public function setClock(DateTime $mockedClock): void - { - $this->mockedClock = $mockedClock; - } - - public function resetClock(): void - { - unset($this->mockedClock); - } +mockedClock)) { + return $this->mockedClock; + } + return new DateTime(); + } + + public function setClock(DateTime $mockedClock): void + { + $this->mockedClock = $mockedClock; + } + + public function resetClock(): void + { + unset($this->mockedClock); + } } \ No newline at end of file diff --git a/src/util/HashAlgorithm.php b/src/util/HashAlgorithm.php index 9a5105a..edb1e50 100644 --- a/src/util/HashAlgorithm.php +++ b/src/util/HashAlgorithm.php @@ -1,4 +1,6 @@