summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/validator/src/X509CertValidator.php
blob: 7dfc4f7a605a55c3b61303371f5b6066aceca1d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

namespace ipl\Validator;

use ipl\I18n\Translation;

/**
 * Validates an X.509 certificate
 */
class X509CertValidator extends BaseValidator
{
    use Translation;

    public function isValid($value)
    {
        // Multiple isValid() calls must not stack validation messages
        $this->clearMessages();

        if (preg_match('/\A\s*\w+:/', $value)) {
            $this->addMessage($this->translate('URLs are not allowed'));

            return false;
        }

        if (openssl_x509_parse($value) === false) {
            $this->addMessage($this->translate('Not a valid PEM-encoded X.509 certificate'));

            return false;
        }

        return true;
    }
}