GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — php72 ( 0f804f...6c57e4 )
by Joni
03:03
created
lib/X509/Certificate/Time.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -17,108 +17,108 @@
 block discarded – undo
17 17
  */
18 18
 class Time
19 19
 {
20
-    use DateTimeHelper;
20
+	use DateTimeHelper;
21 21
 
22
-    /**
23
-     * Datetime.
24
-     *
25
-     * @var \DateTimeImmutable
26
-     */
27
-    protected $_dt;
22
+	/**
23
+	 * Datetime.
24
+	 *
25
+	 * @var \DateTimeImmutable
26
+	 */
27
+	protected $_dt;
28 28
 
29
-    /**
30
-     * Time ASN.1 type tag.
31
-     *
32
-     * @var int
33
-     */
34
-    protected $_type;
29
+	/**
30
+	 * Time ASN.1 type tag.
31
+	 *
32
+	 * @var int
33
+	 */
34
+	protected $_type;
35 35
 
36
-    /**
37
-     * Constructor.
38
-     *
39
-     * @param \DateTimeImmutable $dt
40
-     */
41
-    public function __construct(\DateTimeImmutable $dt)
42
-    {
43
-        $this->_dt = $dt;
44
-        $this->_type = self::_determineType($dt);
45
-    }
36
+	/**
37
+	 * Constructor.
38
+	 *
39
+	 * @param \DateTimeImmutable $dt
40
+	 */
41
+	public function __construct(\DateTimeImmutable $dt)
42
+	{
43
+		$this->_dt = $dt;
44
+		$this->_type = self::_determineType($dt);
45
+	}
46 46
 
47
-    /**
48
-     * Initialize from ASN.1.
49
-     *
50
-     * @param TimeType $el
51
-     *
52
-     * @return self
53
-     */
54
-    public static function fromASN1(TimeType $el): self
55
-    {
56
-        $obj = new self($el->dateTime());
57
-        $obj->_type = $el->tag();
58
-        return $obj;
59
-    }
47
+	/**
48
+	 * Initialize from ASN.1.
49
+	 *
50
+	 * @param TimeType $el
51
+	 *
52
+	 * @return self
53
+	 */
54
+	public static function fromASN1(TimeType $el): self
55
+	{
56
+		$obj = new self($el->dateTime());
57
+		$obj->_type = $el->tag();
58
+		return $obj;
59
+	}
60 60
 
61
-    /**
62
-     * Initialize from date string.
63
-     *
64
-     * @param null|string $time
65
-     * @param null|string $tz
66
-     *
67
-     * @return self
68
-     */
69
-    public static function fromString(?string $time, ?string $tz = null): self
70
-    {
71
-        return new self(self::_createDateTime($time, $tz));
72
-    }
61
+	/**
62
+	 * Initialize from date string.
63
+	 *
64
+	 * @param null|string $time
65
+	 * @param null|string $tz
66
+	 *
67
+	 * @return self
68
+	 */
69
+	public static function fromString(?string $time, ?string $tz = null): self
70
+	{
71
+		return new self(self::_createDateTime($time, $tz));
72
+	}
73 73
 
74
-    /**
75
-     * Get datetime.
76
-     *
77
-     * @return \DateTimeImmutable
78
-     */
79
-    public function dateTime(): \DateTimeImmutable
80
-    {
81
-        return $this->_dt;
82
-    }
74
+	/**
75
+	 * Get datetime.
76
+	 *
77
+	 * @return \DateTimeImmutable
78
+	 */
79
+	public function dateTime(): \DateTimeImmutable
80
+	{
81
+		return $this->_dt;
82
+	}
83 83
 
84
-    /**
85
-     * Generate ASN.1.
86
-     *
87
-     * @throws \UnexpectedValueException
88
-     *
89
-     * @return TimeType
90
-     */
91
-    public function toASN1(): TimeType
92
-    {
93
-        $dt = $this->_dt;
94
-        switch ($this->_type) {
95
-            case Element::TYPE_UTC_TIME:
96
-                return new UTCTime($dt);
97
-            case Element::TYPE_GENERALIZED_TIME:
98
-                // GeneralizedTime must not contain fractional seconds
99
-                // (rfc5280 4.1.2.5.2)
100
-                if (0 != $dt->format('u')) {
101
-                    // remove fractional seconds (round down)
102
-                    $dt = self::_roundDownFractionalSeconds($dt);
103
-                }
104
-                return new GeneralizedTime($dt);
105
-        }
106
-        throw new \UnexpectedValueException(
107
-            'Time type ' . Element::tagToName($this->_type) . ' not supported.');
108
-    }
84
+	/**
85
+	 * Generate ASN.1.
86
+	 *
87
+	 * @throws \UnexpectedValueException
88
+	 *
89
+	 * @return TimeType
90
+	 */
91
+	public function toASN1(): TimeType
92
+	{
93
+		$dt = $this->_dt;
94
+		switch ($this->_type) {
95
+			case Element::TYPE_UTC_TIME:
96
+				return new UTCTime($dt);
97
+			case Element::TYPE_GENERALIZED_TIME:
98
+				// GeneralizedTime must not contain fractional seconds
99
+				// (rfc5280 4.1.2.5.2)
100
+				if (0 != $dt->format('u')) {
101
+					// remove fractional seconds (round down)
102
+					$dt = self::_roundDownFractionalSeconds($dt);
103
+				}
104
+				return new GeneralizedTime($dt);
105
+		}
106
+		throw new \UnexpectedValueException(
107
+			'Time type ' . Element::tagToName($this->_type) . ' not supported.');
108
+	}
109 109
 
110
-    /**
111
-     * Determine whether to use UTCTime or GeneralizedTime ASN.1 type.
112
-     *
113
-     * @param \DateTimeImmutable $dt
114
-     *
115
-     * @return int Type tag
116
-     */
117
-    protected static function _determineType(\DateTimeImmutable $dt): int
118
-    {
119
-        if ($dt->format('Y') >= 2050) {
120
-            return Element::TYPE_GENERALIZED_TIME;
121
-        }
122
-        return Element::TYPE_UTC_TIME;
123
-    }
110
+	/**
111
+	 * Determine whether to use UTCTime or GeneralizedTime ASN.1 type.
112
+	 *
113
+	 * @param \DateTimeImmutable $dt
114
+	 *
115
+	 * @return int Type tag
116
+	 */
117
+	protected static function _determineType(\DateTimeImmutable $dt): int
118
+	{
119
+		if ($dt->format('Y') >= 2050) {
120
+			return Element::TYPE_GENERALIZED_TIME;
121
+		}
122
+		return Element::TYPE_UTC_TIME;
123
+	}
124 124
 }
Please login to merge, or discard this patch.
lib/X509/CertificationPath/PathBuilding/CertificationPathBuilder.php 1 patch
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -16,139 +16,139 @@
 block discarded – undo
16 16
  */
17 17
 class CertificationPathBuilder
18 18
 {
19
-    /**
20
-     * Trust anchors.
21
-     *
22
-     * @var CertificateBundle
23
-     */
24
-    protected $_trustList;
19
+	/**
20
+	 * Trust anchors.
21
+	 *
22
+	 * @var CertificateBundle
23
+	 */
24
+	protected $_trustList;
25 25
 
26
-    /**
27
-     * Constructor.
28
-     *
29
-     * @param CertificateBundle $trust_list List of trust anchors
30
-     */
31
-    public function __construct(CertificateBundle $trust_list)
32
-    {
33
-        $this->_trustList = $trust_list;
34
-    }
26
+	/**
27
+	 * Constructor.
28
+	 *
29
+	 * @param CertificateBundle $trust_list List of trust anchors
30
+	 */
31
+	public function __construct(CertificateBundle $trust_list)
32
+	{
33
+		$this->_trustList = $trust_list;
34
+	}
35 35
 
36
-    /**
37
-     * Get all certification paths to given target certificate from
38
-     * any trust anchor.
39
-     *
40
-     * @param Certificate            $target       Target certificate
41
-     * @param null|CertificateBundle $intermediate Optional intermediate certificates
42
-     *
43
-     * @return CertificationPath[]
44
-     */
45
-    public function allPathsToTarget(Certificate $target,
46
-        ?CertificateBundle $intermediate = null): array
47
-    {
48
-        $paths = $this->_resolvePathsToTarget($target, $intermediate);
49
-        // map paths to CertificationPath objects
50
-        return array_map(
51
-            function ($certs) {
52
-                return new CertificationPath(...$certs);
53
-            }, $paths);
54
-    }
36
+	/**
37
+	 * Get all certification paths to given target certificate from
38
+	 * any trust anchor.
39
+	 *
40
+	 * @param Certificate            $target       Target certificate
41
+	 * @param null|CertificateBundle $intermediate Optional intermediate certificates
42
+	 *
43
+	 * @return CertificationPath[]
44
+	 */
45
+	public function allPathsToTarget(Certificate $target,
46
+		?CertificateBundle $intermediate = null): array
47
+	{
48
+		$paths = $this->_resolvePathsToTarget($target, $intermediate);
49
+		// map paths to CertificationPath objects
50
+		return array_map(
51
+			function ($certs) {
52
+				return new CertificationPath(...$certs);
53
+			}, $paths);
54
+	}
55 55
 
56
-    /**
57
-     * Get shortest path to given target certificate from any trust anchor.
58
-     *
59
-     * @param Certificate            $target       Target certificate
60
-     * @param null|CertificateBundle $intermediate Optional intermediate certificates
61
-     *
62
-     * @throws PathBuildingException
63
-     *
64
-     * @return CertificationPath
65
-     */
66
-    public function shortestPathToTarget(Certificate $target,
67
-        ?CertificateBundle $intermediate = null): CertificationPath
68
-    {
69
-        $paths = $this->allPathsToTarget($target, $intermediate);
70
-        if (!count($paths)) {
71
-            throw new PathBuildingException('No certification paths.');
72
-        }
73
-        usort($paths,
74
-            function ($a, $b) {
75
-                return count($a) < count($b) ? -1 : 1;
76
-            });
77
-        return reset($paths);
78
-    }
56
+	/**
57
+	 * Get shortest path to given target certificate from any trust anchor.
58
+	 *
59
+	 * @param Certificate            $target       Target certificate
60
+	 * @param null|CertificateBundle $intermediate Optional intermediate certificates
61
+	 *
62
+	 * @throws PathBuildingException
63
+	 *
64
+	 * @return CertificationPath
65
+	 */
66
+	public function shortestPathToTarget(Certificate $target,
67
+		?CertificateBundle $intermediate = null): CertificationPath
68
+	{
69
+		$paths = $this->allPathsToTarget($target, $intermediate);
70
+		if (!count($paths)) {
71
+			throw new PathBuildingException('No certification paths.');
72
+		}
73
+		usort($paths,
74
+			function ($a, $b) {
75
+				return count($a) < count($b) ? -1 : 1;
76
+			});
77
+		return reset($paths);
78
+	}
79 79
 
80
-    /**
81
-     * Find all issuers of the target certificate from a given bundle.
82
-     *
83
-     * @param Certificate       $target Target certificate
84
-     * @param CertificateBundle $bundle Certificates to search
85
-     *
86
-     * @return Certificate[]
87
-     */
88
-    protected function _findIssuers(Certificate $target,
89
-        CertificateBundle $bundle): array
90
-    {
91
-        $issuers = [];
92
-        $issuer_name = $target->tbsCertificate()->issuer();
93
-        $extensions = $target->tbsCertificate()->extensions();
94
-        // find by authority key identifier
95
-        if ($extensions->hasAuthorityKeyIdentifier()) {
96
-            $ext = $extensions->authorityKeyIdentifier();
97
-            if ($ext->hasKeyIdentifier()) {
98
-                foreach ($bundle->allBySubjectKeyIdentifier(
99
-                    $ext->keyIdentifier()) as $issuer) {
100
-                    // check that issuer name matches
101
-                    if ($issuer->tbsCertificate()->subject()->equals($issuer_name)) {
102
-                        $issuers[] = $issuer;
103
-                    }
104
-                }
105
-            }
106
-        }
107
-        return $issuers;
108
-    }
80
+	/**
81
+	 * Find all issuers of the target certificate from a given bundle.
82
+	 *
83
+	 * @param Certificate       $target Target certificate
84
+	 * @param CertificateBundle $bundle Certificates to search
85
+	 *
86
+	 * @return Certificate[]
87
+	 */
88
+	protected function _findIssuers(Certificate $target,
89
+		CertificateBundle $bundle): array
90
+	{
91
+		$issuers = [];
92
+		$issuer_name = $target->tbsCertificate()->issuer();
93
+		$extensions = $target->tbsCertificate()->extensions();
94
+		// find by authority key identifier
95
+		if ($extensions->hasAuthorityKeyIdentifier()) {
96
+			$ext = $extensions->authorityKeyIdentifier();
97
+			if ($ext->hasKeyIdentifier()) {
98
+				foreach ($bundle->allBySubjectKeyIdentifier(
99
+					$ext->keyIdentifier()) as $issuer) {
100
+					// check that issuer name matches
101
+					if ($issuer->tbsCertificate()->subject()->equals($issuer_name)) {
102
+						$issuers[] = $issuer;
103
+					}
104
+				}
105
+			}
106
+		}
107
+		return $issuers;
108
+	}
109 109
 
110
-    /**
111
-     * Resolve all possible certification paths from any trust anchor to
112
-     * the target certificate, using optional intermediate certificates.
113
-     *
114
-     * Helper method for allPathsToTarget to be called recursively.
115
-     *
116
-     * @todo Implement loop detection
117
-     *
118
-     * @param Certificate            $target
119
-     * @param null|CertificateBundle $intermediate
120
-     *
121
-     * @return array[] Array of arrays containing path certificates
122
-     */
123
-    private function _resolvePathsToTarget(Certificate $target,
124
-        ?CertificateBundle $intermediate = null): array
125
-    {
126
-        // array of possible paths
127
-        $paths = [];
128
-        // signed by certificate in the trust list
129
-        foreach ($this->_findIssuers($target, $this->_trustList) as $issuer) {
130
-            // if target is self-signed, path consists of only
131
-            // the target certificate
132
-            if ($target->equals($issuer)) {
133
-                $paths[] = [$target];
134
-            } else {
135
-                $paths[] = [$issuer, $target];
136
-            }
137
-        }
138
-        if (isset($intermediate)) {
139
-            // signed by intermediate certificate
140
-            foreach ($this->_findIssuers($target, $intermediate) as $issuer) {
141
-                // intermediate certificate must not be self-signed
142
-                if ($issuer->isSelfIssued()) {
143
-                    continue;
144
-                }
145
-                // resolve paths to issuer
146
-                $subpaths = $this->_resolvePathsToTarget($issuer, $intermediate);
147
-                foreach ($subpaths as $path) {
148
-                    $paths[] = array_merge($path, [$target]);
149
-                }
150
-            }
151
-        }
152
-        return $paths;
153
-    }
110
+	/**
111
+	 * Resolve all possible certification paths from any trust anchor to
112
+	 * the target certificate, using optional intermediate certificates.
113
+	 *
114
+	 * Helper method for allPathsToTarget to be called recursively.
115
+	 *
116
+	 * @todo Implement loop detection
117
+	 *
118
+	 * @param Certificate            $target
119
+	 * @param null|CertificateBundle $intermediate
120
+	 *
121
+	 * @return array[] Array of arrays containing path certificates
122
+	 */
123
+	private function _resolvePathsToTarget(Certificate $target,
124
+		?CertificateBundle $intermediate = null): array
125
+	{
126
+		// array of possible paths
127
+		$paths = [];
128
+		// signed by certificate in the trust list
129
+		foreach ($this->_findIssuers($target, $this->_trustList) as $issuer) {
130
+			// if target is self-signed, path consists of only
131
+			// the target certificate
132
+			if ($target->equals($issuer)) {
133
+				$paths[] = [$target];
134
+			} else {
135
+				$paths[] = [$issuer, $target];
136
+			}
137
+		}
138
+		if (isset($intermediate)) {
139
+			// signed by intermediate certificate
140
+			foreach ($this->_findIssuers($target, $intermediate) as $issuer) {
141
+				// intermediate certificate must not be self-signed
142
+				if ($issuer->isSelfIssued()) {
143
+					continue;
144
+				}
145
+				// resolve paths to issuer
146
+				$subpaths = $this->_resolvePathsToTarget($issuer, $intermediate);
147
+				foreach ($subpaths as $path) {
148
+					$paths[] = array_merge($path, [$target]);
149
+				}
150
+			}
151
+		}
152
+		return $paths;
153
+	}
154 154
 }
Please login to merge, or discard this patch.
lib/X509/CertificationPath/PathValidation/ValidatorState.php 1 patch
Indentation   +496 added lines, -496 removed lines patch added patch discarded remove patch
@@ -20,500 +20,500 @@
 block discarded – undo
20 20
  */
21 21
 class ValidatorState
22 22
 {
23
-    /**
24
-     * Length of the certification path (n).
25
-     *
26
-     * @var int
27
-     */
28
-    protected $_pathLength;
29
-
30
-    /**
31
-     * Current index in the certification path in the range of 1..n (i).
32
-     *
33
-     * @var int
34
-     */
35
-    protected $_index;
36
-
37
-    /**
38
-     * Valid policy tree (valid_policy_tree).
39
-     *
40
-     * A tree of certificate policies with their optional qualifiers.
41
-     * Each of the leaves of the tree represents a valid policy at this stage in
42
-     * the certification path validation.
43
-     * Once the tree is set to NULL, policy processing ceases.
44
-     *
45
-     * @var null|PolicyTree
46
-     */
47
-    protected $_validPolicyTree;
48
-
49
-    /**
50
-     * Permitted subtrees (permitted_subtrees).
51
-     *
52
-     * A set of root names for each name type defining a set of subtrees within
53
-     * which all subject names in subsequent certificates in the certification
54
-     * path must fall.
55
-     *
56
-     * @var mixed
57
-     */
58
-    protected $_permittedSubtrees;
59
-
60
-    /**
61
-     * Excluded subtrees (excluded_subtrees).
62
-     *
63
-     * A set of root names for each name type defining a set of subtrees within
64
-     * which no subject name in subsequent certificates in the certification
65
-     * path may fall.
66
-     *
67
-     * @var mixed
68
-     */
69
-    protected $_excludedSubtrees;
70
-
71
-    /**
72
-     * Explicit policy (explicit_policy).
73
-     *
74
-     * An integer that indicates if a non-NULL valid_policy_tree is required.
75
-     *
76
-     * @var int
77
-     */
78
-    protected $_explicitPolicy;
79
-
80
-    /**
81
-     * Inhibit anyPolicy (inhibit_anyPolicy).
82
-     *
83
-     * An integer that indicates whether the anyPolicy policy identifier is
84
-     * considered a match.
85
-     *
86
-     * @var int
87
-     */
88
-    protected $_inhibitAnyPolicy;
89
-
90
-    /**
91
-     * Policy mapping (policy_mapping).
92
-     *
93
-     * An integer that indicates if policy mapping is permitted.
94
-     *
95
-     * @var int
96
-     */
97
-    protected $_policyMapping;
98
-
99
-    /**
100
-     * Working public key algorithm (working_public_key_algorithm).
101
-     *
102
-     * The digital signature algorithm used to verify the signature of a
103
-     * certificate.
104
-     *
105
-     * @var AlgorithmIdentifierType
106
-     */
107
-    protected $_workingPublicKeyAlgorithm;
108
-
109
-    /**
110
-     * Working public key (working_public_key).
111
-     *
112
-     * The public key used to verify the signature of a certificate.
113
-     *
114
-     * @var PublicKeyInfo
115
-     */
116
-    protected $_workingPublicKey;
117
-
118
-    /**
119
-     * Working public key parameters (working_public_key_parameters).
120
-     *
121
-     * Parameters associated with the current public key that may be required to
122
-     * verify a signature.
123
-     *
124
-     * @var null|Element
125
-     */
126
-    protected $_workingPublicKeyParameters;
127
-
128
-    /**
129
-     * Working issuer name (working_issuer_name).
130
-     *
131
-     * The issuer distinguished name expected in the next certificate in the
132
-     * chain.
133
-     *
134
-     * @var Name
135
-     */
136
-    protected $_workingIssuerName;
137
-
138
-    /**
139
-     * Maximum certification path length (max_path_length).
140
-     *
141
-     * @var int
142
-     */
143
-    protected $_maxPathLength;
144
-
145
-    /**
146
-     * Constructor.
147
-     */
148
-    protected function __construct()
149
-    {
150
-    }
151
-
152
-    /**
153
-     * Initialize variables according to RFC 5280 6.1.2.
154
-     *
155
-     * @see https://tools.ietf.org/html/rfc5280#section-6.1.2
156
-     *
157
-     * @param PathValidationConfig $config
158
-     * @param Certificate          $trust_anchor Trust anchor certificate
159
-     * @param int                  $n            Number of certificates
160
-     *                                           in the certification path
161
-     *
162
-     * @return self
163
-     */
164
-    public static function initialize(PathValidationConfig $config,
165
-        Certificate $trust_anchor, int $n): self
166
-    {
167
-        $state = new self();
168
-        $state->_pathLength = $n;
169
-        $state->_index = 1;
170
-        $state->_validPolicyTree = new PolicyTree(PolicyNode::anyPolicyNode());
171
-        $state->_permittedSubtrees = null;
172
-        $state->_excludedSubtrees = null;
173
-        $state->_explicitPolicy = $config->explicitPolicy() ? 0 : $n + 1;
174
-        $state->_inhibitAnyPolicy = $config->anyPolicyInhibit() ? 0 : $n + 1;
175
-        $state->_policyMapping = $config->policyMappingInhibit() ? 0 : $n + 1;
176
-        $state->_workingPublicKeyAlgorithm = $trust_anchor->signatureAlgorithm();
177
-        $tbsCert = $trust_anchor->tbsCertificate();
178
-        $state->_workingPublicKey = $tbsCert->subjectPublicKeyInfo();
179
-        $state->_workingPublicKeyParameters = self::getAlgorithmParameters(
180
-            $state->_workingPublicKey->algorithmIdentifier());
181
-        $state->_workingIssuerName = $tbsCert->issuer();
182
-        $state->_maxPathLength = $config->maxLength();
183
-        return $state;
184
-    }
185
-
186
-    /**
187
-     * Get self with current certification path index set.
188
-     *
189
-     * @param int $index
190
-     *
191
-     * @return self
192
-     */
193
-    public function withIndex(int $index): self
194
-    {
195
-        $state = clone $this;
196
-        $state->_index = $index;
197
-        return $state;
198
-    }
199
-
200
-    /**
201
-     * Get self with valid_policy_tree.
202
-     *
203
-     * @param PolicyTree $policy_tree
204
-     *
205
-     * @return self
206
-     */
207
-    public function withValidPolicyTree(PolicyTree $policy_tree): self
208
-    {
209
-        $state = clone $this;
210
-        $state->_validPolicyTree = $policy_tree;
211
-        return $state;
212
-    }
213
-
214
-    /**
215
-     * Get self with valid_policy_tree set to null.
216
-     *
217
-     * @return self
218
-     */
219
-    public function withoutValidPolicyTree(): self
220
-    {
221
-        $state = clone $this;
222
-        $state->_validPolicyTree = null;
223
-        return $state;
224
-    }
225
-
226
-    /**
227
-     * Get self with explicit_policy.
228
-     *
229
-     * @param int $num
230
-     *
231
-     * @return self
232
-     */
233
-    public function withExplicitPolicy(int $num): self
234
-    {
235
-        $state = clone $this;
236
-        $state->_explicitPolicy = $num;
237
-        return $state;
238
-    }
239
-
240
-    /**
241
-     * Get self with inhibit_anyPolicy.
242
-     *
243
-     * @param int $num
244
-     *
245
-     * @return self
246
-     */
247
-    public function withInhibitAnyPolicy(int $num): self
248
-    {
249
-        $state = clone $this;
250
-        $state->_inhibitAnyPolicy = $num;
251
-        return $state;
252
-    }
253
-
254
-    /**
255
-     * Get self with policy_mapping.
256
-     *
257
-     * @param int $num
258
-     *
259
-     * @return self
260
-     */
261
-    public function withPolicyMapping(int $num): self
262
-    {
263
-        $state = clone $this;
264
-        $state->_policyMapping = $num;
265
-        return $state;
266
-    }
267
-
268
-    /**
269
-     * Get self with working_public_key_algorithm.
270
-     *
271
-     * @param AlgorithmIdentifierType $algo
272
-     *
273
-     * @return self
274
-     */
275
-    public function withWorkingPublicKeyAlgorithm(AlgorithmIdentifierType $algo): self
276
-    {
277
-        $state = clone $this;
278
-        $state->_workingPublicKeyAlgorithm = $algo;
279
-        return $state;
280
-    }
281
-
282
-    /**
283
-     * Get self with working_public_key.
284
-     *
285
-     * @param PublicKeyInfo $pubkey_info
286
-     *
287
-     * @return self
288
-     */
289
-    public function withWorkingPublicKey(PublicKeyInfo $pubkey_info): self
290
-    {
291
-        $state = clone $this;
292
-        $state->_workingPublicKey = $pubkey_info;
293
-        return $state;
294
-    }
295
-
296
-    /**
297
-     * Get self with working_public_key_parameters.
298
-     *
299
-     * @param null|Element $params
300
-     *
301
-     * @return self
302
-     */
303
-    public function withWorkingPublicKeyParameters(?Element $params = null): self
304
-    {
305
-        $state = clone $this;
306
-        $state->_workingPublicKeyParameters = $params;
307
-        return $state;
308
-    }
309
-
310
-    /**
311
-     * Get self with working_issuer_name.
312
-     *
313
-     * @param Name $issuer
314
-     *
315
-     * @return self
316
-     */
317
-    public function withWorkingIssuerName(Name $issuer): self
318
-    {
319
-        $state = clone $this;
320
-        $state->_workingIssuerName = $issuer;
321
-        return $state;
322
-    }
323
-
324
-    /**
325
-     * Get self with max_path_length.
326
-     *
327
-     * @param int $length
328
-     *
329
-     * @return self
330
-     */
331
-    public function withMaxPathLength(int $length): self
332
-    {
333
-        $state = clone $this;
334
-        $state->_maxPathLength = $length;
335
-        return $state;
336
-    }
337
-
338
-    /**
339
-     * Get the certification path length (n).
340
-     *
341
-     * @return int
342
-     */
343
-    public function pathLength(): int
344
-    {
345
-        return $this->_pathLength;
346
-    }
347
-
348
-    /**
349
-     * Get the current index in certification path in the range of 1..n.
350
-     *
351
-     * @return int
352
-     */
353
-    public function index(): int
354
-    {
355
-        return $this->_index;
356
-    }
357
-
358
-    /**
359
-     * Check whether valid_policy_tree is present.
360
-     *
361
-     * @return bool
362
-     */
363
-    public function hasValidPolicyTree(): bool
364
-    {
365
-        return isset($this->_validPolicyTree);
366
-    }
367
-
368
-    /**
369
-     * Get valid_policy_tree.
370
-     *
371
-     * @throws \LogicException If not set
372
-     *
373
-     * @return PolicyTree
374
-     */
375
-    public function validPolicyTree(): PolicyTree
376
-    {
377
-        if (!$this->hasValidPolicyTree()) {
378
-            throw new \LogicException('valid_policy_tree not set.');
379
-        }
380
-        return $this->_validPolicyTree;
381
-    }
382
-
383
-    /**
384
-     * Get permitted_subtrees.
385
-     *
386
-     * @return mixed
387
-     */
388
-    public function permittedSubtrees()
389
-    {
390
-        return $this->_permittedSubtrees;
391
-    }
392
-
393
-    /**
394
-     * Get excluded_subtrees.
395
-     *
396
-     * @return mixed
397
-     */
398
-    public function excludedSubtrees()
399
-    {
400
-        return $this->_excludedSubtrees;
401
-    }
402
-
403
-    /**
404
-     * Get explicit_policy.
405
-     *
406
-     * @return int
407
-     */
408
-    public function explicitPolicy(): int
409
-    {
410
-        return $this->_explicitPolicy;
411
-    }
412
-
413
-    /**
414
-     * Get inhibit_anyPolicy.
415
-     *
416
-     * @return int
417
-     */
418
-    public function inhibitAnyPolicy(): int
419
-    {
420
-        return $this->_inhibitAnyPolicy;
421
-    }
422
-
423
-    /**
424
-     * Get policy_mapping.
425
-     *
426
-     * @return int
427
-     */
428
-    public function policyMapping(): int
429
-    {
430
-        return $this->_policyMapping;
431
-    }
432
-
433
-    /**
434
-     * Get working_public_key_algorithm.
435
-     *
436
-     * @return AlgorithmIdentifierType
437
-     */
438
-    public function workingPublicKeyAlgorithm(): AlgorithmIdentifierType
439
-    {
440
-        return $this->_workingPublicKeyAlgorithm;
441
-    }
442
-
443
-    /**
444
-     * Get working_public_key.
445
-     *
446
-     * @return PublicKeyInfo
447
-     */
448
-    public function workingPublicKey(): PublicKeyInfo
449
-    {
450
-        return $this->_workingPublicKey;
451
-    }
452
-
453
-    /**
454
-     * Get working_public_key_parameters.
455
-     *
456
-     * @return null|Element
457
-     */
458
-    public function workingPublicKeyParameters(): ?Element
459
-    {
460
-        return $this->_workingPublicKeyParameters;
461
-    }
462
-
463
-    /**
464
-     * Get working_issuer_name.
465
-     *
466
-     * @return Name
467
-     */
468
-    public function workingIssuerName(): Name
469
-    {
470
-        return $this->_workingIssuerName;
471
-    }
472
-
473
-    /**
474
-     * Get maximum certification path length.
475
-     *
476
-     * @return int
477
-     */
478
-    public function maxPathLength(): int
479
-    {
480
-        return $this->_maxPathLength;
481
-    }
482
-
483
-    /**
484
-     * Check whether processing the final certificate of the certification path.
485
-     *
486
-     * @return bool
487
-     */
488
-    public function isFinal(): bool
489
-    {
490
-        return $this->_index === $this->_pathLength;
491
-    }
492
-
493
-    /**
494
-     * Get the path validation result.
495
-     *
496
-     * @param Certificate[] $certificates Certificates in a certification path
497
-     *
498
-     * @return PathValidationResult
499
-     */
500
-    public function getResult(array $certificates): PathValidationResult
501
-    {
502
-        return new PathValidationResult($certificates, $this->_validPolicyTree,
503
-            $this->_workingPublicKey, $this->_workingPublicKeyAlgorithm,
504
-            $this->_workingPublicKeyParameters);
505
-    }
506
-
507
-    /**
508
-     * Get ASN.1 parameters from algorithm identifier.
509
-     *
510
-     * @param AlgorithmIdentifierType $algo
511
-     *
512
-     * @return null|Element ASN.1 element or null if parameters are omitted
513
-     */
514
-    public static function getAlgorithmParameters(AlgorithmIdentifierType $algo): ?Element
515
-    {
516
-        $seq = $algo->toASN1();
517
-        return $seq->has(1) ? $seq->at(1)->asElement() : null;
518
-    }
23
+	/**
24
+	 * Length of the certification path (n).
25
+	 *
26
+	 * @var int
27
+	 */
28
+	protected $_pathLength;
29
+
30
+	/**
31
+	 * Current index in the certification path in the range of 1..n (i).
32
+	 *
33
+	 * @var int
34
+	 */
35
+	protected $_index;
36
+
37
+	/**
38
+	 * Valid policy tree (valid_policy_tree).
39
+	 *
40
+	 * A tree of certificate policies with their optional qualifiers.
41
+	 * Each of the leaves of the tree represents a valid policy at this stage in
42
+	 * the certification path validation.
43
+	 * Once the tree is set to NULL, policy processing ceases.
44
+	 *
45
+	 * @var null|PolicyTree
46
+	 */
47
+	protected $_validPolicyTree;
48
+
49
+	/**
50
+	 * Permitted subtrees (permitted_subtrees).
51
+	 *
52
+	 * A set of root names for each name type defining a set of subtrees within
53
+	 * which all subject names in subsequent certificates in the certification
54
+	 * path must fall.
55
+	 *
56
+	 * @var mixed
57
+	 */
58
+	protected $_permittedSubtrees;
59
+
60
+	/**
61
+	 * Excluded subtrees (excluded_subtrees).
62
+	 *
63
+	 * A set of root names for each name type defining a set of subtrees within
64
+	 * which no subject name in subsequent certificates in the certification
65
+	 * path may fall.
66
+	 *
67
+	 * @var mixed
68
+	 */
69
+	protected $_excludedSubtrees;
70
+
71
+	/**
72
+	 * Explicit policy (explicit_policy).
73
+	 *
74
+	 * An integer that indicates if a non-NULL valid_policy_tree is required.
75
+	 *
76
+	 * @var int
77
+	 */
78
+	protected $_explicitPolicy;
79
+
80
+	/**
81
+	 * Inhibit anyPolicy (inhibit_anyPolicy).
82
+	 *
83
+	 * An integer that indicates whether the anyPolicy policy identifier is
84
+	 * considered a match.
85
+	 *
86
+	 * @var int
87
+	 */
88
+	protected $_inhibitAnyPolicy;
89
+
90
+	/**
91
+	 * Policy mapping (policy_mapping).
92
+	 *
93
+	 * An integer that indicates if policy mapping is permitted.
94
+	 *
95
+	 * @var int
96
+	 */
97
+	protected $_policyMapping;
98
+
99
+	/**
100
+	 * Working public key algorithm (working_public_key_algorithm).
101
+	 *
102
+	 * The digital signature algorithm used to verify the signature of a
103
+	 * certificate.
104
+	 *
105
+	 * @var AlgorithmIdentifierType
106
+	 */
107
+	protected $_workingPublicKeyAlgorithm;
108
+
109
+	/**
110
+	 * Working public key (working_public_key).
111
+	 *
112
+	 * The public key used to verify the signature of a certificate.
113
+	 *
114
+	 * @var PublicKeyInfo
115
+	 */
116
+	protected $_workingPublicKey;
117
+
118
+	/**
119
+	 * Working public key parameters (working_public_key_parameters).
120
+	 *
121
+	 * Parameters associated with the current public key that may be required to
122
+	 * verify a signature.
123
+	 *
124
+	 * @var null|Element
125
+	 */
126
+	protected $_workingPublicKeyParameters;
127
+
128
+	/**
129
+	 * Working issuer name (working_issuer_name).
130
+	 *
131
+	 * The issuer distinguished name expected in the next certificate in the
132
+	 * chain.
133
+	 *
134
+	 * @var Name
135
+	 */
136
+	protected $_workingIssuerName;
137
+
138
+	/**
139
+	 * Maximum certification path length (max_path_length).
140
+	 *
141
+	 * @var int
142
+	 */
143
+	protected $_maxPathLength;
144
+
145
+	/**
146
+	 * Constructor.
147
+	 */
148
+	protected function __construct()
149
+	{
150
+	}
151
+
152
+	/**
153
+	 * Initialize variables according to RFC 5280 6.1.2.
154
+	 *
155
+	 * @see https://tools.ietf.org/html/rfc5280#section-6.1.2
156
+	 *
157
+	 * @param PathValidationConfig $config
158
+	 * @param Certificate          $trust_anchor Trust anchor certificate
159
+	 * @param int                  $n            Number of certificates
160
+	 *                                           in the certification path
161
+	 *
162
+	 * @return self
163
+	 */
164
+	public static function initialize(PathValidationConfig $config,
165
+		Certificate $trust_anchor, int $n): self
166
+	{
167
+		$state = new self();
168
+		$state->_pathLength = $n;
169
+		$state->_index = 1;
170
+		$state->_validPolicyTree = new PolicyTree(PolicyNode::anyPolicyNode());
171
+		$state->_permittedSubtrees = null;
172
+		$state->_excludedSubtrees = null;
173
+		$state->_explicitPolicy = $config->explicitPolicy() ? 0 : $n + 1;
174
+		$state->_inhibitAnyPolicy = $config->anyPolicyInhibit() ? 0 : $n + 1;
175
+		$state->_policyMapping = $config->policyMappingInhibit() ? 0 : $n + 1;
176
+		$state->_workingPublicKeyAlgorithm = $trust_anchor->signatureAlgorithm();
177
+		$tbsCert = $trust_anchor->tbsCertificate();
178
+		$state->_workingPublicKey = $tbsCert->subjectPublicKeyInfo();
179
+		$state->_workingPublicKeyParameters = self::getAlgorithmParameters(
180
+			$state->_workingPublicKey->algorithmIdentifier());
181
+		$state->_workingIssuerName = $tbsCert->issuer();
182
+		$state->_maxPathLength = $config->maxLength();
183
+		return $state;
184
+	}
185
+
186
+	/**
187
+	 * Get self with current certification path index set.
188
+	 *
189
+	 * @param int $index
190
+	 *
191
+	 * @return self
192
+	 */
193
+	public function withIndex(int $index): self
194
+	{
195
+		$state = clone $this;
196
+		$state->_index = $index;
197
+		return $state;
198
+	}
199
+
200
+	/**
201
+	 * Get self with valid_policy_tree.
202
+	 *
203
+	 * @param PolicyTree $policy_tree
204
+	 *
205
+	 * @return self
206
+	 */
207
+	public function withValidPolicyTree(PolicyTree $policy_tree): self
208
+	{
209
+		$state = clone $this;
210
+		$state->_validPolicyTree = $policy_tree;
211
+		return $state;
212
+	}
213
+
214
+	/**
215
+	 * Get self with valid_policy_tree set to null.
216
+	 *
217
+	 * @return self
218
+	 */
219
+	public function withoutValidPolicyTree(): self
220
+	{
221
+		$state = clone $this;
222
+		$state->_validPolicyTree = null;
223
+		return $state;
224
+	}
225
+
226
+	/**
227
+	 * Get self with explicit_policy.
228
+	 *
229
+	 * @param int $num
230
+	 *
231
+	 * @return self
232
+	 */
233
+	public function withExplicitPolicy(int $num): self
234
+	{
235
+		$state = clone $this;
236
+		$state->_explicitPolicy = $num;
237
+		return $state;
238
+	}
239
+
240
+	/**
241
+	 * Get self with inhibit_anyPolicy.
242
+	 *
243
+	 * @param int $num
244
+	 *
245
+	 * @return self
246
+	 */
247
+	public function withInhibitAnyPolicy(int $num): self
248
+	{
249
+		$state = clone $this;
250
+		$state->_inhibitAnyPolicy = $num;
251
+		return $state;
252
+	}
253
+
254
+	/**
255
+	 * Get self with policy_mapping.
256
+	 *
257
+	 * @param int $num
258
+	 *
259
+	 * @return self
260
+	 */
261
+	public function withPolicyMapping(int $num): self
262
+	{
263
+		$state = clone $this;
264
+		$state->_policyMapping = $num;
265
+		return $state;
266
+	}
267
+
268
+	/**
269
+	 * Get self with working_public_key_algorithm.
270
+	 *
271
+	 * @param AlgorithmIdentifierType $algo
272
+	 *
273
+	 * @return self
274
+	 */
275
+	public function withWorkingPublicKeyAlgorithm(AlgorithmIdentifierType $algo): self
276
+	{
277
+		$state = clone $this;
278
+		$state->_workingPublicKeyAlgorithm = $algo;
279
+		return $state;
280
+	}
281
+
282
+	/**
283
+	 * Get self with working_public_key.
284
+	 *
285
+	 * @param PublicKeyInfo $pubkey_info
286
+	 *
287
+	 * @return self
288
+	 */
289
+	public function withWorkingPublicKey(PublicKeyInfo $pubkey_info): self
290
+	{
291
+		$state = clone $this;
292
+		$state->_workingPublicKey = $pubkey_info;
293
+		return $state;
294
+	}
295
+
296
+	/**
297
+	 * Get self with working_public_key_parameters.
298
+	 *
299
+	 * @param null|Element $params
300
+	 *
301
+	 * @return self
302
+	 */
303
+	public function withWorkingPublicKeyParameters(?Element $params = null): self
304
+	{
305
+		$state = clone $this;
306
+		$state->_workingPublicKeyParameters = $params;
307
+		return $state;
308
+	}
309
+
310
+	/**
311
+	 * Get self with working_issuer_name.
312
+	 *
313
+	 * @param Name $issuer
314
+	 *
315
+	 * @return self
316
+	 */
317
+	public function withWorkingIssuerName(Name $issuer): self
318
+	{
319
+		$state = clone $this;
320
+		$state->_workingIssuerName = $issuer;
321
+		return $state;
322
+	}
323
+
324
+	/**
325
+	 * Get self with max_path_length.
326
+	 *
327
+	 * @param int $length
328
+	 *
329
+	 * @return self
330
+	 */
331
+	public function withMaxPathLength(int $length): self
332
+	{
333
+		$state = clone $this;
334
+		$state->_maxPathLength = $length;
335
+		return $state;
336
+	}
337
+
338
+	/**
339
+	 * Get the certification path length (n).
340
+	 *
341
+	 * @return int
342
+	 */
343
+	public function pathLength(): int
344
+	{
345
+		return $this->_pathLength;
346
+	}
347
+
348
+	/**
349
+	 * Get the current index in certification path in the range of 1..n.
350
+	 *
351
+	 * @return int
352
+	 */
353
+	public function index(): int
354
+	{
355
+		return $this->_index;
356
+	}
357
+
358
+	/**
359
+	 * Check whether valid_policy_tree is present.
360
+	 *
361
+	 * @return bool
362
+	 */
363
+	public function hasValidPolicyTree(): bool
364
+	{
365
+		return isset($this->_validPolicyTree);
366
+	}
367
+
368
+	/**
369
+	 * Get valid_policy_tree.
370
+	 *
371
+	 * @throws \LogicException If not set
372
+	 *
373
+	 * @return PolicyTree
374
+	 */
375
+	public function validPolicyTree(): PolicyTree
376
+	{
377
+		if (!$this->hasValidPolicyTree()) {
378
+			throw new \LogicException('valid_policy_tree not set.');
379
+		}
380
+		return $this->_validPolicyTree;
381
+	}
382
+
383
+	/**
384
+	 * Get permitted_subtrees.
385
+	 *
386
+	 * @return mixed
387
+	 */
388
+	public function permittedSubtrees()
389
+	{
390
+		return $this->_permittedSubtrees;
391
+	}
392
+
393
+	/**
394
+	 * Get excluded_subtrees.
395
+	 *
396
+	 * @return mixed
397
+	 */
398
+	public function excludedSubtrees()
399
+	{
400
+		return $this->_excludedSubtrees;
401
+	}
402
+
403
+	/**
404
+	 * Get explicit_policy.
405
+	 *
406
+	 * @return int
407
+	 */
408
+	public function explicitPolicy(): int
409
+	{
410
+		return $this->_explicitPolicy;
411
+	}
412
+
413
+	/**
414
+	 * Get inhibit_anyPolicy.
415
+	 *
416
+	 * @return int
417
+	 */
418
+	public function inhibitAnyPolicy(): int
419
+	{
420
+		return $this->_inhibitAnyPolicy;
421
+	}
422
+
423
+	/**
424
+	 * Get policy_mapping.
425
+	 *
426
+	 * @return int
427
+	 */
428
+	public function policyMapping(): int
429
+	{
430
+		return $this->_policyMapping;
431
+	}
432
+
433
+	/**
434
+	 * Get working_public_key_algorithm.
435
+	 *
436
+	 * @return AlgorithmIdentifierType
437
+	 */
438
+	public function workingPublicKeyAlgorithm(): AlgorithmIdentifierType
439
+	{
440
+		return $this->_workingPublicKeyAlgorithm;
441
+	}
442
+
443
+	/**
444
+	 * Get working_public_key.
445
+	 *
446
+	 * @return PublicKeyInfo
447
+	 */
448
+	public function workingPublicKey(): PublicKeyInfo
449
+	{
450
+		return $this->_workingPublicKey;
451
+	}
452
+
453
+	/**
454
+	 * Get working_public_key_parameters.
455
+	 *
456
+	 * @return null|Element
457
+	 */
458
+	public function workingPublicKeyParameters(): ?Element
459
+	{
460
+		return $this->_workingPublicKeyParameters;
461
+	}
462
+
463
+	/**
464
+	 * Get working_issuer_name.
465
+	 *
466
+	 * @return Name
467
+	 */
468
+	public function workingIssuerName(): Name
469
+	{
470
+		return $this->_workingIssuerName;
471
+	}
472
+
473
+	/**
474
+	 * Get maximum certification path length.
475
+	 *
476
+	 * @return int
477
+	 */
478
+	public function maxPathLength(): int
479
+	{
480
+		return $this->_maxPathLength;
481
+	}
482
+
483
+	/**
484
+	 * Check whether processing the final certificate of the certification path.
485
+	 *
486
+	 * @return bool
487
+	 */
488
+	public function isFinal(): bool
489
+	{
490
+		return $this->_index === $this->_pathLength;
491
+	}
492
+
493
+	/**
494
+	 * Get the path validation result.
495
+	 *
496
+	 * @param Certificate[] $certificates Certificates in a certification path
497
+	 *
498
+	 * @return PathValidationResult
499
+	 */
500
+	public function getResult(array $certificates): PathValidationResult
501
+	{
502
+		return new PathValidationResult($certificates, $this->_validPolicyTree,
503
+			$this->_workingPublicKey, $this->_workingPublicKeyAlgorithm,
504
+			$this->_workingPublicKeyParameters);
505
+	}
506
+
507
+	/**
508
+	 * Get ASN.1 parameters from algorithm identifier.
509
+	 *
510
+	 * @param AlgorithmIdentifierType $algo
511
+	 *
512
+	 * @return null|Element ASN.1 element or null if parameters are omitted
513
+	 */
514
+	public static function getAlgorithmParameters(AlgorithmIdentifierType $algo): ?Element
515
+	{
516
+		$seq = $algo->toASN1();
517
+		return $seq->has(1) ? $seq->at(1)->asElement() : null;
518
+	}
519 519
 }
Please login to merge, or discard this patch.
lib/X509/CertificationPath/PathValidation/PathValidationResult.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -18,81 +18,81 @@
 block discarded – undo
18 18
  */
19 19
 class PathValidationResult
20 20
 {
21
-    /**
22
-     * Certificates in a certification path.
23
-     *
24
-     * @var Certificate[]
25
-     */
26
-    protected $_certificates;
21
+	/**
22
+	 * Certificates in a certification path.
23
+	 *
24
+	 * @var Certificate[]
25
+	 */
26
+	protected $_certificates;
27 27
 
28
-    /**
29
-     * Valid policy tree.
30
-     *
31
-     * @var null|PolicyTree
32
-     */
33
-    protected $_policyTree;
28
+	/**
29
+	 * Valid policy tree.
30
+	 *
31
+	 * @var null|PolicyTree
32
+	 */
33
+	protected $_policyTree;
34 34
 
35
-    /**
36
-     * End-entity certificate's public key.
37
-     *
38
-     * @var PublicKeyInfo
39
-     */
40
-    protected $_publicKeyInfo;
35
+	/**
36
+	 * End-entity certificate's public key.
37
+	 *
38
+	 * @var PublicKeyInfo
39
+	 */
40
+	protected $_publicKeyInfo;
41 41
 
42
-    /**
43
-     * Public key algorithm.
44
-     *
45
-     * @var AlgorithmIdentifierType
46
-     */
47
-    protected $_publicKeyAlgo;
42
+	/**
43
+	 * Public key algorithm.
44
+	 *
45
+	 * @var AlgorithmIdentifierType
46
+	 */
47
+	protected $_publicKeyAlgo;
48 48
 
49
-    /**
50
-     * Public key parameters.
51
-     *
52
-     * @var null|Element
53
-     */
54
-    protected $_publicKeyParameters;
49
+	/**
50
+	 * Public key parameters.
51
+	 *
52
+	 * @var null|Element
53
+	 */
54
+	protected $_publicKeyParameters;
55 55
 
56
-    /**
57
-     * Constructor.
58
-     *
59
-     * @param Certificate[]           $certificates Certificates in a certification path
60
-     * @param null|PolicyTree         $policy_tree  Valid policy tree
61
-     * @param PublicKeyInfo           $pubkey_info  Public key of the end-entity certificate
62
-     * @param AlgorithmIdentifierType $algo         Public key algorithm of the end-entity certificate
63
-     * @param null|Element            $params       Algorithm parameters
64
-     */
65
-    public function __construct(array $certificates, ?PolicyTree $policy_tree,
66
-        PublicKeyInfo $pubkey_info, AlgorithmIdentifierType $algo,
67
-        ?Element $params = null)
68
-    {
69
-        $this->_certificates = array_values($certificates);
70
-        $this->_policyTree = $policy_tree;
71
-        $this->_publicKeyInfo = $pubkey_info;
72
-        $this->_publicKeyAlgo = $algo;
73
-        $this->_publicKeyParameters = $params;
74
-    }
56
+	/**
57
+	 * Constructor.
58
+	 *
59
+	 * @param Certificate[]           $certificates Certificates in a certification path
60
+	 * @param null|PolicyTree         $policy_tree  Valid policy tree
61
+	 * @param PublicKeyInfo           $pubkey_info  Public key of the end-entity certificate
62
+	 * @param AlgorithmIdentifierType $algo         Public key algorithm of the end-entity certificate
63
+	 * @param null|Element            $params       Algorithm parameters
64
+	 */
65
+	public function __construct(array $certificates, ?PolicyTree $policy_tree,
66
+		PublicKeyInfo $pubkey_info, AlgorithmIdentifierType $algo,
67
+		?Element $params = null)
68
+	{
69
+		$this->_certificates = array_values($certificates);
70
+		$this->_policyTree = $policy_tree;
71
+		$this->_publicKeyInfo = $pubkey_info;
72
+		$this->_publicKeyAlgo = $algo;
73
+		$this->_publicKeyParameters = $params;
74
+	}
75 75
 
76
-    /**
77
-     * Get end-entity certificate.
78
-     *
79
-     * @return Certificate
80
-     */
81
-    public function certificate(): Certificate
82
-    {
83
-        return $this->_certificates[count($this->_certificates) - 1];
84
-    }
76
+	/**
77
+	 * Get end-entity certificate.
78
+	 *
79
+	 * @return Certificate
80
+	 */
81
+	public function certificate(): Certificate
82
+	{
83
+		return $this->_certificates[count($this->_certificates) - 1];
84
+	}
85 85
 
86
-    /**
87
-     * Get certificate policies of the end-entity certificate.
88
-     *
89
-     * @return PolicyInformation[]
90
-     */
91
-    public function policies(): array
92
-    {
93
-        if (!$this->_policyTree) {
94
-            return [];
95
-        }
96
-        return $this->_policyTree->policiesAtDepth(count($this->_certificates));
97
-    }
86
+	/**
87
+	 * Get certificate policies of the end-entity certificate.
88
+	 *
89
+	 * @return PolicyInformation[]
90
+	 */
91
+	public function policies(): array
92
+	{
93
+		if (!$this->_policyTree) {
94
+			return [];
95
+		}
96
+		return $this->_policyTree->policiesAtDepth(count($this->_certificates));
97
+	}
98 98
 }
Please login to merge, or discard this patch.
lib/X509/CertificationPath/PathValidation/PathValidationConfig.php 1 patch
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -14,282 +14,282 @@
 block discarded – undo
14 14
  */
15 15
 class PathValidationConfig
16 16
 {
17
-    /**
18
-     * Maximum allowed certification path length.
19
-     *
20
-     * @var int
21
-     */
22
-    protected $_maxLength;
17
+	/**
18
+	 * Maximum allowed certification path length.
19
+	 *
20
+	 * @var int
21
+	 */
22
+	protected $_maxLength;
23 23
 
24
-    /**
25
-     * Reference time.
26
-     *
27
-     * @var \DateTimeImmutable
28
-     */
29
-    protected $_dateTime;
24
+	/**
25
+	 * Reference time.
26
+	 *
27
+	 * @var \DateTimeImmutable
28
+	 */
29
+	protected $_dateTime;
30 30
 
31
-    /**
32
-     * List of acceptable policy identifiers.
33
-     *
34
-     * @var string[]
35
-     */
36
-    protected $_policySet;
31
+	/**
32
+	 * List of acceptable policy identifiers.
33
+	 *
34
+	 * @var string[]
35
+	 */
36
+	protected $_policySet;
37 37
 
38
-    /**
39
-     * Trust anchor certificate.
40
-     *
41
-     * If not set, path validation uses the first certificate of the path.
42
-     *
43
-     * @var null|Certificate
44
-     */
45
-    protected $_trustAnchor;
38
+	/**
39
+	 * Trust anchor certificate.
40
+	 *
41
+	 * If not set, path validation uses the first certificate of the path.
42
+	 *
43
+	 * @var null|Certificate
44
+	 */
45
+	protected $_trustAnchor;
46 46
 
47
-    /**
48
-     * Whether policy mapping in inhibited.
49
-     *
50
-     * Setting this to true disallows policy mapping.
51
-     *
52
-     * @var bool
53
-     */
54
-    protected $_policyMappingInhibit;
47
+	/**
48
+	 * Whether policy mapping in inhibited.
49
+	 *
50
+	 * Setting this to true disallows policy mapping.
51
+	 *
52
+	 * @var bool
53
+	 */
54
+	protected $_policyMappingInhibit;
55 55
 
56
-    /**
57
-     * Whether the path must be valid for at least one policy in the
58
-     * initial policy set.
59
-     *
60
-     * @var bool
61
-     */
62
-    protected $_explicitPolicy;
56
+	/**
57
+	 * Whether the path must be valid for at least one policy in the
58
+	 * initial policy set.
59
+	 *
60
+	 * @var bool
61
+	 */
62
+	protected $_explicitPolicy;
63 63
 
64
-    /**
65
-     * Whether anyPolicy OID processing should be inhibited.
66
-     *
67
-     * Setting this to true disallows the usage of anyPolicy.
68
-     *
69
-     * @var bool
70
-     */
71
-    protected $_anyPolicyInhibit;
64
+	/**
65
+	 * Whether anyPolicy OID processing should be inhibited.
66
+	 *
67
+	 * Setting this to true disallows the usage of anyPolicy.
68
+	 *
69
+	 * @var bool
70
+	 */
71
+	protected $_anyPolicyInhibit;
72 72
 
73
-    /**
74
-     * @todo Implement
75
-     *
76
-     * @var mixed
77
-     */
78
-    protected $_permittedSubtrees;
73
+	/**
74
+	 * @todo Implement
75
+	 *
76
+	 * @var mixed
77
+	 */
78
+	protected $_permittedSubtrees;
79 79
 
80
-    /**
81
-     * @todo Implement
82
-     *
83
-     * @var mixed
84
-     */
85
-    protected $_excludedSubtrees;
80
+	/**
81
+	 * @todo Implement
82
+	 *
83
+	 * @var mixed
84
+	 */
85
+	protected $_excludedSubtrees;
86 86
 
87
-    /**
88
-     * Constructor.
89
-     *
90
-     * @param \DateTimeImmutable $dt         Reference date and time
91
-     * @param int                $max_length Maximum certification path length
92
-     */
93
-    public function __construct(\DateTimeImmutable $dt, int $max_length)
94
-    {
95
-        $this->_dateTime = $dt;
96
-        $this->_maxLength = $max_length;
97
-        $this->_policySet = [PolicyInformation::OID_ANY_POLICY];
98
-        $this->_policyMappingInhibit = false;
99
-        $this->_explicitPolicy = false;
100
-        $this->_anyPolicyInhibit = false;
101
-    }
87
+	/**
88
+	 * Constructor.
89
+	 *
90
+	 * @param \DateTimeImmutable $dt         Reference date and time
91
+	 * @param int                $max_length Maximum certification path length
92
+	 */
93
+	public function __construct(\DateTimeImmutable $dt, int $max_length)
94
+	{
95
+		$this->_dateTime = $dt;
96
+		$this->_maxLength = $max_length;
97
+		$this->_policySet = [PolicyInformation::OID_ANY_POLICY];
98
+		$this->_policyMappingInhibit = false;
99
+		$this->_explicitPolicy = false;
100
+		$this->_anyPolicyInhibit = false;
101
+	}
102 102
 
103
-    /**
104
-     * Get default configuration.
105
-     *
106
-     * @return self
107
-     */
108
-    public static function defaultConfig(): self
109
-    {
110
-        return new self(new \DateTimeImmutable(), 3);
111
-    }
103
+	/**
104
+	 * Get default configuration.
105
+	 *
106
+	 * @return self
107
+	 */
108
+	public static function defaultConfig(): self
109
+	{
110
+		return new self(new \DateTimeImmutable(), 3);
111
+	}
112 112
 
113
-    /**
114
-     * Get self with maximum path length.
115
-     *
116
-     * @param int $length
117
-     *
118
-     * @return self
119
-     */
120
-    public function withMaxLength(int $length): self
121
-    {
122
-        $obj = clone $this;
123
-        $obj->_maxLength = $length;
124
-        return $obj;
125
-    }
113
+	/**
114
+	 * Get self with maximum path length.
115
+	 *
116
+	 * @param int $length
117
+	 *
118
+	 * @return self
119
+	 */
120
+	public function withMaxLength(int $length): self
121
+	{
122
+		$obj = clone $this;
123
+		$obj->_maxLength = $length;
124
+		return $obj;
125
+	}
126 126
 
127
-    /**
128
-     * Get self with reference date and time.
129
-     *
130
-     * @param \DateTimeImmutable $dt
131
-     *
132
-     * @return self
133
-     */
134
-    public function withDateTime(\DateTimeImmutable $dt): self
135
-    {
136
-        $obj = clone $this;
137
-        $obj->_dateTime = $dt;
138
-        return $obj;
139
-    }
127
+	/**
128
+	 * Get self with reference date and time.
129
+	 *
130
+	 * @param \DateTimeImmutable $dt
131
+	 *
132
+	 * @return self
133
+	 */
134
+	public function withDateTime(\DateTimeImmutable $dt): self
135
+	{
136
+		$obj = clone $this;
137
+		$obj->_dateTime = $dt;
138
+		return $obj;
139
+	}
140 140
 
141
-    /**
142
-     * Get self with trust anchor certificate.
143
-     *
144
-     * @param Certificate $ca
145
-     *
146
-     * @return self
147
-     */
148
-    public function withTrustAnchor(Certificate $ca): self
149
-    {
150
-        $obj = clone $this;
151
-        $obj->_trustAnchor = $ca;
152
-        return $obj;
153
-    }
141
+	/**
142
+	 * Get self with trust anchor certificate.
143
+	 *
144
+	 * @param Certificate $ca
145
+	 *
146
+	 * @return self
147
+	 */
148
+	public function withTrustAnchor(Certificate $ca): self
149
+	{
150
+		$obj = clone $this;
151
+		$obj->_trustAnchor = $ca;
152
+		return $obj;
153
+	}
154 154
 
155
-    /**
156
-     * Get self with initial-policy-mapping-inhibit set.
157
-     *
158
-     * @param bool $flag
159
-     *
160
-     * @return self
161
-     */
162
-    public function withPolicyMappingInhibit(bool $flag): self
163
-    {
164
-        $obj = clone $this;
165
-        $obj->_policyMappingInhibit = $flag;
166
-        return $obj;
167
-    }
155
+	/**
156
+	 * Get self with initial-policy-mapping-inhibit set.
157
+	 *
158
+	 * @param bool $flag
159
+	 *
160
+	 * @return self
161
+	 */
162
+	public function withPolicyMappingInhibit(bool $flag): self
163
+	{
164
+		$obj = clone $this;
165
+		$obj->_policyMappingInhibit = $flag;
166
+		return $obj;
167
+	}
168 168
 
169
-    /**
170
-     * Get self with initial-explicit-policy set.
171
-     *
172
-     * @param bool $flag
173
-     *
174
-     * @return self
175
-     */
176
-    public function withExplicitPolicy(bool $flag): self
177
-    {
178
-        $obj = clone $this;
179
-        $obj->_explicitPolicy = $flag;
180
-        return $obj;
181
-    }
169
+	/**
170
+	 * Get self with initial-explicit-policy set.
171
+	 *
172
+	 * @param bool $flag
173
+	 *
174
+	 * @return self
175
+	 */
176
+	public function withExplicitPolicy(bool $flag): self
177
+	{
178
+		$obj = clone $this;
179
+		$obj->_explicitPolicy = $flag;
180
+		return $obj;
181
+	}
182 182
 
183
-    /**
184
-     * Get self with initial-any-policy-inhibit set.
185
-     *
186
-     * @param bool $flag
187
-     *
188
-     * @return self
189
-     */
190
-    public function withAnyPolicyInhibit(bool $flag): self
191
-    {
192
-        $obj = clone $this;
193
-        $obj->_anyPolicyInhibit = $flag;
194
-        return $obj;
195
-    }
183
+	/**
184
+	 * Get self with initial-any-policy-inhibit set.
185
+	 *
186
+	 * @param bool $flag
187
+	 *
188
+	 * @return self
189
+	 */
190
+	public function withAnyPolicyInhibit(bool $flag): self
191
+	{
192
+		$obj = clone $this;
193
+		$obj->_anyPolicyInhibit = $flag;
194
+		return $obj;
195
+	}
196 196
 
197
-    /**
198
-     * Get self with user-initial-policy-set set to policy OIDs.
199
-     *
200
-     * @param string ...$policies List of policy OIDs
201
-     *
202
-     * @return self
203
-     */
204
-    public function withPolicySet(string ...$policies): self
205
-    {
206
-        $obj = clone $this;
207
-        $obj->_policySet = $policies;
208
-        return $obj;
209
-    }
197
+	/**
198
+	 * Get self with user-initial-policy-set set to policy OIDs.
199
+	 *
200
+	 * @param string ...$policies List of policy OIDs
201
+	 *
202
+	 * @return self
203
+	 */
204
+	public function withPolicySet(string ...$policies): self
205
+	{
206
+		$obj = clone $this;
207
+		$obj->_policySet = $policies;
208
+		return $obj;
209
+	}
210 210
 
211
-    /**
212
-     * Get maximum certification path length.
213
-     *
214
-     * @return int
215
-     */
216
-    public function maxLength(): int
217
-    {
218
-        return $this->_maxLength;
219
-    }
211
+	/**
212
+	 * Get maximum certification path length.
213
+	 *
214
+	 * @return int
215
+	 */
216
+	public function maxLength(): int
217
+	{
218
+		return $this->_maxLength;
219
+	}
220 220
 
221
-    /**
222
-     * Get reference date and time.
223
-     *
224
-     * @return \DateTimeImmutable
225
-     */
226
-    public function dateTime(): \DateTimeImmutable
227
-    {
228
-        return $this->_dateTime;
229
-    }
221
+	/**
222
+	 * Get reference date and time.
223
+	 *
224
+	 * @return \DateTimeImmutable
225
+	 */
226
+	public function dateTime(): \DateTimeImmutable
227
+	{
228
+		return $this->_dateTime;
229
+	}
230 230
 
231
-    /**
232
-     * Get user-initial-policy-set.
233
-     *
234
-     * @return string[] Array of OID's
235
-     */
236
-    public function policySet(): array
237
-    {
238
-        return $this->_policySet;
239
-    }
231
+	/**
232
+	 * Get user-initial-policy-set.
233
+	 *
234
+	 * @return string[] Array of OID's
235
+	 */
236
+	public function policySet(): array
237
+	{
238
+		return $this->_policySet;
239
+	}
240 240
 
241
-    /**
242
-     * Check whether trust anchor certificate is set.
243
-     *
244
-     * @return bool
245
-     */
246
-    public function hasTrustAnchor(): bool
247
-    {
248
-        return isset($this->_trustAnchor);
249
-    }
241
+	/**
242
+	 * Check whether trust anchor certificate is set.
243
+	 *
244
+	 * @return bool
245
+	 */
246
+	public function hasTrustAnchor(): bool
247
+	{
248
+		return isset($this->_trustAnchor);
249
+	}
250 250
 
251
-    /**
252
-     * Get trust anchor certificate.
253
-     *
254
-     * @throws \LogicException If not set
255
-     *
256
-     * @return Certificate
257
-     */
258
-    public function trustAnchor(): Certificate
259
-    {
260
-        if (!$this->hasTrustAnchor()) {
261
-            throw new \LogicException('No trust anchor.');
262
-        }
263
-        return $this->_trustAnchor;
264
-    }
251
+	/**
252
+	 * Get trust anchor certificate.
253
+	 *
254
+	 * @throws \LogicException If not set
255
+	 *
256
+	 * @return Certificate
257
+	 */
258
+	public function trustAnchor(): Certificate
259
+	{
260
+		if (!$this->hasTrustAnchor()) {
261
+			throw new \LogicException('No trust anchor.');
262
+		}
263
+		return $this->_trustAnchor;
264
+	}
265 265
 
266
-    /**
267
-     * Get initial-policy-mapping-inhibit.
268
-     *
269
-     * @return bool
270
-     */
271
-    public function policyMappingInhibit(): bool
272
-    {
273
-        return $this->_policyMappingInhibit;
274
-    }
266
+	/**
267
+	 * Get initial-policy-mapping-inhibit.
268
+	 *
269
+	 * @return bool
270
+	 */
271
+	public function policyMappingInhibit(): bool
272
+	{
273
+		return $this->_policyMappingInhibit;
274
+	}
275 275
 
276
-    /**
277
-     * Get initial-explicit-policy.
278
-     *
279
-     * @return bool
280
-     */
281
-    public function explicitPolicy(): bool
282
-    {
283
-        return $this->_explicitPolicy;
284
-    }
276
+	/**
277
+	 * Get initial-explicit-policy.
278
+	 *
279
+	 * @return bool
280
+	 */
281
+	public function explicitPolicy(): bool
282
+	{
283
+		return $this->_explicitPolicy;
284
+	}
285 285
 
286
-    /**
287
-     * Get initial-any-policy-inhibit.
288
-     *
289
-     * @return bool
290
-     */
291
-    public function anyPolicyInhibit(): bool
292
-    {
293
-        return $this->_anyPolicyInhibit;
294
-    }
286
+	/**
287
+	 * Get initial-any-policy-inhibit.
288
+	 *
289
+	 * @return bool
290
+	 */
291
+	public function anyPolicyInhibit(): bool
292
+	{
293
+		return $this->_anyPolicyInhibit;
294
+	}
295 295
 }
Please login to merge, or discard this patch.
lib/X509/CertificationPath/PathValidation/PathValidator.php 1 patch
Indentation   +568 added lines, -568 removed lines patch added patch discarded remove patch
@@ -17,599 +17,599 @@
 block discarded – undo
17 17
  */
18 18
 class PathValidator
19 19
 {
20
-    /**
21
-     * Crypto engine.
22
-     *
23
-     * @var Crypto
24
-     */
25
-    protected $_crypto;
20
+	/**
21
+	 * Crypto engine.
22
+	 *
23
+	 * @var Crypto
24
+	 */
25
+	protected $_crypto;
26 26
 
27
-    /**
28
-     * Path validation configuration.
29
-     *
30
-     * @var PathValidationConfig
31
-     */
32
-    protected $_config;
27
+	/**
28
+	 * Path validation configuration.
29
+	 *
30
+	 * @var PathValidationConfig
31
+	 */
32
+	protected $_config;
33 33
 
34
-    /**
35
-     * Certification path.
36
-     *
37
-     * @var Certificate[]
38
-     */
39
-    protected $_certificates;
34
+	/**
35
+	 * Certification path.
36
+	 *
37
+	 * @var Certificate[]
38
+	 */
39
+	protected $_certificates;
40 40
 
41
-    /**
42
-     * Certification path trust anchor.
43
-     *
44
-     * @var Certificate
45
-     */
46
-    protected $_trustAnchor;
41
+	/**
42
+	 * Certification path trust anchor.
43
+	 *
44
+	 * @var Certificate
45
+	 */
46
+	protected $_trustAnchor;
47 47
 
48
-    /**
49
-     * Constructor.
50
-     *
51
-     * @param Crypto               $crypto          Crypto engine
52
-     * @param PathValidationConfig $config          Validation config
53
-     * @param Certificate          ...$certificates Certificates from the trust anchor to
54
-     *                                              the end-entity certificate
55
-     */
56
-    public function __construct(Crypto $crypto, PathValidationConfig $config,
57
-        Certificate ...$certificates)
58
-    {
59
-        if (!count($certificates)) {
60
-            throw new \LogicException('No certificates.');
61
-        }
62
-        $this->_crypto = $crypto;
63
-        $this->_config = $config;
64
-        $this->_certificates = $certificates;
65
-        // if trust anchor is explicitly given in configuration
66
-        if ($config->hasTrustAnchor()) {
67
-            $this->_trustAnchor = $config->trustAnchor();
68
-        } else {
69
-            $this->_trustAnchor = $certificates[0];
70
-        }
71
-    }
48
+	/**
49
+	 * Constructor.
50
+	 *
51
+	 * @param Crypto               $crypto          Crypto engine
52
+	 * @param PathValidationConfig $config          Validation config
53
+	 * @param Certificate          ...$certificates Certificates from the trust anchor to
54
+	 *                                              the end-entity certificate
55
+	 */
56
+	public function __construct(Crypto $crypto, PathValidationConfig $config,
57
+		Certificate ...$certificates)
58
+	{
59
+		if (!count($certificates)) {
60
+			throw new \LogicException('No certificates.');
61
+		}
62
+		$this->_crypto = $crypto;
63
+		$this->_config = $config;
64
+		$this->_certificates = $certificates;
65
+		// if trust anchor is explicitly given in configuration
66
+		if ($config->hasTrustAnchor()) {
67
+			$this->_trustAnchor = $config->trustAnchor();
68
+		} else {
69
+			$this->_trustAnchor = $certificates[0];
70
+		}
71
+	}
72 72
 
73
-    /**
74
-     * Validate certification path.
75
-     *
76
-     * @throws PathValidationException
77
-     *
78
-     * @return PathValidationResult
79
-     */
80
-    public function validate(): PathValidationResult
81
-    {
82
-        $n = count($this->_certificates);
83
-        $state = ValidatorState::initialize(
84
-            $this->_config, $this->_trustAnchor, $n);
85
-        for ($i = 0; $i < $n; ++$i) {
86
-            $state = $state->withIndex($i + 1);
87
-            $cert = $this->_certificates[$i];
88
-            // process certificate (section 6.1.3.)
89
-            $state = $this->_processCertificate($state, $cert);
90
-            if (!$state->isFinal()) {
91
-                // prepare next certificate (section 6.1.4.)
92
-                $state = $this->_prepareNext($state, $cert);
93
-            }
94
-        }
95
-        if (!isset($cert)) {
96
-            throw new \LogicException('No certificates.');
97
-        }
98
-        // wrap-up (section 6.1.5.)
99
-        $state = $this->_wrapUp($state, $cert);
100
-        // return outputs
101
-        return $state->getResult($this->_certificates);
102
-    }
73
+	/**
74
+	 * Validate certification path.
75
+	 *
76
+	 * @throws PathValidationException
77
+	 *
78
+	 * @return PathValidationResult
79
+	 */
80
+	public function validate(): PathValidationResult
81
+	{
82
+		$n = count($this->_certificates);
83
+		$state = ValidatorState::initialize(
84
+			$this->_config, $this->_trustAnchor, $n);
85
+		for ($i = 0; $i < $n; ++$i) {
86
+			$state = $state->withIndex($i + 1);
87
+			$cert = $this->_certificates[$i];
88
+			// process certificate (section 6.1.3.)
89
+			$state = $this->_processCertificate($state, $cert);
90
+			if (!$state->isFinal()) {
91
+				// prepare next certificate (section 6.1.4.)
92
+				$state = $this->_prepareNext($state, $cert);
93
+			}
94
+		}
95
+		if (!isset($cert)) {
96
+			throw new \LogicException('No certificates.');
97
+		}
98
+		// wrap-up (section 6.1.5.)
99
+		$state = $this->_wrapUp($state, $cert);
100
+		// return outputs
101
+		return $state->getResult($this->_certificates);
102
+	}
103 103
 
104
-    /**
105
-     * Apply basic certificate processing according to RFC 5280 section 6.1.3.
106
-     *
107
-     * @see https://tools.ietf.org/html/rfc5280#section-6.1.3
108
-     *
109
-     * @param ValidatorState $state
110
-     * @param Certificate    $cert
111
-     *
112
-     * @throws PathValidationException
113
-     *
114
-     * @return ValidatorState
115
-     */
116
-    private function _processCertificate(ValidatorState $state,
117
-        Certificate $cert): ValidatorState
118
-    {
119
-        // (a.1) verify signature
120
-        $this->_verifySignature($state, $cert);
121
-        // (a.2) check validity period
122
-        $this->_checkValidity($cert);
123
-        // (a.3) check that certificate is not revoked
124
-        $this->_checkRevocation($cert);
125
-        // (a.4) check issuer
126
-        $this->_checkIssuer($state, $cert);
127
-        // (b)(c) if certificate is self-issued and it is not
128
-        // the final certificate in the path, skip this step
129
-        if (!($cert->isSelfIssued() && !$state->isFinal())) {
130
-            // (b) check permitted subtrees
131
-            $this->_checkPermittedSubtrees($state, $cert);
132
-            // (c) check excluded subtrees
133
-            $this->_checkExcludedSubtrees($state, $cert);
134
-        }
135
-        $extensions = $cert->tbsCertificate()->extensions();
136
-        if ($extensions->hasCertificatePolicies()) {
137
-            // (d) process policy information
138
-            if ($state->hasValidPolicyTree()) {
139
-                $state = $state->validPolicyTree()->processPolicies($state, $cert);
140
-            }
141
-        } else {
142
-            // (e) certificate policies extension not present,
143
-            // set the valid_policy_tree to NULL
144
-            $state = $state->withoutValidPolicyTree();
145
-        }
146
-        // (f) check that explicit_policy > 0 or valid_policy_tree is set
147
-        if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) {
148
-            throw new PathValidationException('No valid policies.');
149
-        }
150
-        return $state;
151
-    }
104
+	/**
105
+	 * Apply basic certificate processing according to RFC 5280 section 6.1.3.
106
+	 *
107
+	 * @see https://tools.ietf.org/html/rfc5280#section-6.1.3
108
+	 *
109
+	 * @param ValidatorState $state
110
+	 * @param Certificate    $cert
111
+	 *
112
+	 * @throws PathValidationException
113
+	 *
114
+	 * @return ValidatorState
115
+	 */
116
+	private function _processCertificate(ValidatorState $state,
117
+		Certificate $cert): ValidatorState
118
+	{
119
+		// (a.1) verify signature
120
+		$this->_verifySignature($state, $cert);
121
+		// (a.2) check validity period
122
+		$this->_checkValidity($cert);
123
+		// (a.3) check that certificate is not revoked
124
+		$this->_checkRevocation($cert);
125
+		// (a.4) check issuer
126
+		$this->_checkIssuer($state, $cert);
127
+		// (b)(c) if certificate is self-issued and it is not
128
+		// the final certificate in the path, skip this step
129
+		if (!($cert->isSelfIssued() && !$state->isFinal())) {
130
+			// (b) check permitted subtrees
131
+			$this->_checkPermittedSubtrees($state, $cert);
132
+			// (c) check excluded subtrees
133
+			$this->_checkExcludedSubtrees($state, $cert);
134
+		}
135
+		$extensions = $cert->tbsCertificate()->extensions();
136
+		if ($extensions->hasCertificatePolicies()) {
137
+			// (d) process policy information
138
+			if ($state->hasValidPolicyTree()) {
139
+				$state = $state->validPolicyTree()->processPolicies($state, $cert);
140
+			}
141
+		} else {
142
+			// (e) certificate policies extension not present,
143
+			// set the valid_policy_tree to NULL
144
+			$state = $state->withoutValidPolicyTree();
145
+		}
146
+		// (f) check that explicit_policy > 0 or valid_policy_tree is set
147
+		if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) {
148
+			throw new PathValidationException('No valid policies.');
149
+		}
150
+		return $state;
151
+	}
152 152
 
153
-    /**
154
-     * Apply preparation for the certificate i+1 according to rfc5280 section
155
-     * 6.1.4.
156
-     *
157
-     * @see https://tools.ietf.org/html/rfc5280#section-6.1.4
158
-     *
159
-     * @param ValidatorState $state
160
-     * @param Certificate    $cert
161
-     *
162
-     * @return ValidatorState
163
-     */
164
-    private function _prepareNext(ValidatorState $state,
165
-        Certificate $cert): ValidatorState
166
-    {
167
-        // (a)(b) if policy mappings extension is present
168
-        $state = $this->_preparePolicyMappings($state, $cert);
169
-        // (c) assign working_issuer_name
170
-        $state = $state->withWorkingIssuerName(
171
-            $cert->tbsCertificate()->subject());
172
-        // (d)(e)(f)
173
-        $state = $this->_setPublicKeyState($state, $cert);
174
-        // (g) if name constraints extension is present
175
-        $state = $this->_prepareNameConstraints($state, $cert);
176
-        // (h) if certificate is not self-issued
177
-        if (!$cert->isSelfIssued()) {
178
-            $state = $this->_prepareNonSelfIssued($state);
179
-        }
180
-        // (i) if policy constraints extension is present
181
-        $state = $this->_preparePolicyConstraints($state, $cert);
182
-        // (j) if inhibit any policy extension is present
183
-        $state = $this->_prepareInhibitAnyPolicy($state, $cert);
184
-        // (k) check basic constraints
185
-        $this->_processBasicContraints($cert);
186
-        // (l) verify max_path_length
187
-        $state = $this->_verifyMaxPathLength($state, $cert);
188
-        // (m) check pathLenContraint
189
-        $state = $this->_processPathLengthContraint($state, $cert);
190
-        // (n) check key usage
191
-        $this->_checkKeyUsage($cert);
192
-        // (o) process relevant extensions
193
-        return $this->_processExtensions($state, $cert);
194
-    }
153
+	/**
154
+	 * Apply preparation for the certificate i+1 according to rfc5280 section
155
+	 * 6.1.4.
156
+	 *
157
+	 * @see https://tools.ietf.org/html/rfc5280#section-6.1.4
158
+	 *
159
+	 * @param ValidatorState $state
160
+	 * @param Certificate    $cert
161
+	 *
162
+	 * @return ValidatorState
163
+	 */
164
+	private function _prepareNext(ValidatorState $state,
165
+		Certificate $cert): ValidatorState
166
+	{
167
+		// (a)(b) if policy mappings extension is present
168
+		$state = $this->_preparePolicyMappings($state, $cert);
169
+		// (c) assign working_issuer_name
170
+		$state = $state->withWorkingIssuerName(
171
+			$cert->tbsCertificate()->subject());
172
+		// (d)(e)(f)
173
+		$state = $this->_setPublicKeyState($state, $cert);
174
+		// (g) if name constraints extension is present
175
+		$state = $this->_prepareNameConstraints($state, $cert);
176
+		// (h) if certificate is not self-issued
177
+		if (!$cert->isSelfIssued()) {
178
+			$state = $this->_prepareNonSelfIssued($state);
179
+		}
180
+		// (i) if policy constraints extension is present
181
+		$state = $this->_preparePolicyConstraints($state, $cert);
182
+		// (j) if inhibit any policy extension is present
183
+		$state = $this->_prepareInhibitAnyPolicy($state, $cert);
184
+		// (k) check basic constraints
185
+		$this->_processBasicContraints($cert);
186
+		// (l) verify max_path_length
187
+		$state = $this->_verifyMaxPathLength($state, $cert);
188
+		// (m) check pathLenContraint
189
+		$state = $this->_processPathLengthContraint($state, $cert);
190
+		// (n) check key usage
191
+		$this->_checkKeyUsage($cert);
192
+		// (o) process relevant extensions
193
+		return $this->_processExtensions($state, $cert);
194
+	}
195 195
 
196
-    /**
197
-     * Apply wrap-up procedure according to RFC 5280 section 6.1.5.
198
-     *
199
-     * @see https://tools.ietf.org/html/rfc5280#section-6.1.5
200
-     *
201
-     * @param ValidatorState $state
202
-     * @param Certificate    $cert
203
-     *
204
-     * @throws PathValidationException
205
-     *
206
-     * @return ValidatorState
207
-     */
208
-    private function _wrapUp(ValidatorState $state,
209
-        Certificate $cert): ValidatorState
210
-    {
211
-        $tbs_cert = $cert->tbsCertificate();
212
-        $extensions = $tbs_cert->extensions();
213
-        // (a)
214
-        if ($state->explicitPolicy() > 0) {
215
-            $state = $state->withExplicitPolicy($state->explicitPolicy() - 1);
216
-        }
217
-        // (b)
218
-        if ($extensions->hasPolicyConstraints()) {
219
-            $ext = $extensions->policyConstraints();
220
-            if ($ext->hasRequireExplicitPolicy() &&
221
-                0 === $ext->requireExplicitPolicy()) {
222
-                $state = $state->withExplicitPolicy(0);
223
-            }
224
-        }
225
-        // (c)(d)(e)
226
-        $state = $this->_setPublicKeyState($state, $cert);
227
-        // (f) process relevant extensions
228
-        $state = $this->_processExtensions($state, $cert);
229
-        // (g) intersection of valid_policy_tree and the initial-policy-set
230
-        $state = $this->_calculatePolicyIntersection($state);
231
-        // check that explicit_policy > 0 or valid_policy_tree is set
232
-        if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) {
233
-            throw new PathValidationException('No valid policies.');
234
-        }
235
-        // path validation succeeded
236
-        return $state;
237
-    }
196
+	/**
197
+	 * Apply wrap-up procedure according to RFC 5280 section 6.1.5.
198
+	 *
199
+	 * @see https://tools.ietf.org/html/rfc5280#section-6.1.5
200
+	 *
201
+	 * @param ValidatorState $state
202
+	 * @param Certificate    $cert
203
+	 *
204
+	 * @throws PathValidationException
205
+	 *
206
+	 * @return ValidatorState
207
+	 */
208
+	private function _wrapUp(ValidatorState $state,
209
+		Certificate $cert): ValidatorState
210
+	{
211
+		$tbs_cert = $cert->tbsCertificate();
212
+		$extensions = $tbs_cert->extensions();
213
+		// (a)
214
+		if ($state->explicitPolicy() > 0) {
215
+			$state = $state->withExplicitPolicy($state->explicitPolicy() - 1);
216
+		}
217
+		// (b)
218
+		if ($extensions->hasPolicyConstraints()) {
219
+			$ext = $extensions->policyConstraints();
220
+			if ($ext->hasRequireExplicitPolicy() &&
221
+				0 === $ext->requireExplicitPolicy()) {
222
+				$state = $state->withExplicitPolicy(0);
223
+			}
224
+		}
225
+		// (c)(d)(e)
226
+		$state = $this->_setPublicKeyState($state, $cert);
227
+		// (f) process relevant extensions
228
+		$state = $this->_processExtensions($state, $cert);
229
+		// (g) intersection of valid_policy_tree and the initial-policy-set
230
+		$state = $this->_calculatePolicyIntersection($state);
231
+		// check that explicit_policy > 0 or valid_policy_tree is set
232
+		if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) {
233
+			throw new PathValidationException('No valid policies.');
234
+		}
235
+		// path validation succeeded
236
+		return $state;
237
+	}
238 238
 
239
-    /**
240
-     * Update working_public_key, working_public_key_parameters and
241
-     * working_public_key_algorithm state variables from certificate.
242
-     *
243
-     * @param ValidatorState $state
244
-     * @param Certificate    $cert
245
-     *
246
-     * @return ValidatorState
247
-     */
248
-    private function _setPublicKeyState(ValidatorState $state,
249
-        Certificate $cert): ValidatorState
250
-    {
251
-        $pk_info = $cert->tbsCertificate()->subjectPublicKeyInfo();
252
-        // assign working_public_key
253
-        $state = $state->withWorkingPublicKey($pk_info);
254
-        // assign working_public_key_parameters
255
-        $params = ValidatorState::getAlgorithmParameters(
256
-            $pk_info->algorithmIdentifier());
257
-        if (null !== $params) {
258
-            $state = $state->withWorkingPublicKeyParameters($params);
259
-        } else {
260
-            // if algorithms differ, set parameters to null
261
-            if ($pk_info->algorithmIdentifier()->oid() !==
262
-                    $state->workingPublicKeyAlgorithm()->oid()) {
263
-                $state = $state->withWorkingPublicKeyParameters(null);
264
-            }
265
-        }
266
-        // assign working_public_key_algorithm
267
-        return $state->withWorkingPublicKeyAlgorithm(
268
-            $pk_info->algorithmIdentifier());
269
-    }
239
+	/**
240
+	 * Update working_public_key, working_public_key_parameters and
241
+	 * working_public_key_algorithm state variables from certificate.
242
+	 *
243
+	 * @param ValidatorState $state
244
+	 * @param Certificate    $cert
245
+	 *
246
+	 * @return ValidatorState
247
+	 */
248
+	private function _setPublicKeyState(ValidatorState $state,
249
+		Certificate $cert): ValidatorState
250
+	{
251
+		$pk_info = $cert->tbsCertificate()->subjectPublicKeyInfo();
252
+		// assign working_public_key
253
+		$state = $state->withWorkingPublicKey($pk_info);
254
+		// assign working_public_key_parameters
255
+		$params = ValidatorState::getAlgorithmParameters(
256
+			$pk_info->algorithmIdentifier());
257
+		if (null !== $params) {
258
+			$state = $state->withWorkingPublicKeyParameters($params);
259
+		} else {
260
+			// if algorithms differ, set parameters to null
261
+			if ($pk_info->algorithmIdentifier()->oid() !==
262
+					$state->workingPublicKeyAlgorithm()->oid()) {
263
+				$state = $state->withWorkingPublicKeyParameters(null);
264
+			}
265
+		}
266
+		// assign working_public_key_algorithm
267
+		return $state->withWorkingPublicKeyAlgorithm(
268
+			$pk_info->algorithmIdentifier());
269
+	}
270 270
 
271
-    /**
272
-     * Verify certificate signature.
273
-     *
274
-     * @param ValidatorState $state
275
-     * @param Certificate    $cert
276
-     *
277
-     * @throws PathValidationException
278
-     */
279
-    private function _verifySignature(ValidatorState $state,
280
-        Certificate $cert): void
281
-    {
282
-        try {
283
-            $valid = $cert->verify($state->workingPublicKey(), $this->_crypto);
284
-        } catch (\RuntimeException $e) {
285
-            throw new PathValidationException(
286
-                'Failed to verify signature: ' . $e->getMessage(), 0, $e);
287
-        }
288
-        if (!$valid) {
289
-            throw new PathValidationException(
290
-                "Certificate signature doesn't match.");
291
-        }
292
-    }
271
+	/**
272
+	 * Verify certificate signature.
273
+	 *
274
+	 * @param ValidatorState $state
275
+	 * @param Certificate    $cert
276
+	 *
277
+	 * @throws PathValidationException
278
+	 */
279
+	private function _verifySignature(ValidatorState $state,
280
+		Certificate $cert): void
281
+	{
282
+		try {
283
+			$valid = $cert->verify($state->workingPublicKey(), $this->_crypto);
284
+		} catch (\RuntimeException $e) {
285
+			throw new PathValidationException(
286
+				'Failed to verify signature: ' . $e->getMessage(), 0, $e);
287
+		}
288
+		if (!$valid) {
289
+			throw new PathValidationException(
290
+				"Certificate signature doesn't match.");
291
+		}
292
+	}
293 293
 
294
-    /**
295
-     * Check certificate validity.
296
-     *
297
-     * @param Certificate $cert
298
-     *
299
-     * @throws PathValidationException
300
-     */
301
-    private function _checkValidity(Certificate $cert): void
302
-    {
303
-        $refdt = $this->_config->dateTime();
304
-        $validity = $cert->tbsCertificate()->validity();
305
-        if ($validity->notBefore()->dateTime()->diff($refdt)->invert) {
306
-            throw new PathValidationException(
307
-                'Certificate validity period has not started.');
308
-        }
309
-        if ($refdt->diff($validity->notAfter()->dateTime())->invert) {
310
-            throw new PathValidationException('Certificate has expired.');
311
-        }
312
-    }
294
+	/**
295
+	 * Check certificate validity.
296
+	 *
297
+	 * @param Certificate $cert
298
+	 *
299
+	 * @throws PathValidationException
300
+	 */
301
+	private function _checkValidity(Certificate $cert): void
302
+	{
303
+		$refdt = $this->_config->dateTime();
304
+		$validity = $cert->tbsCertificate()->validity();
305
+		if ($validity->notBefore()->dateTime()->diff($refdt)->invert) {
306
+			throw new PathValidationException(
307
+				'Certificate validity period has not started.');
308
+		}
309
+		if ($refdt->diff($validity->notAfter()->dateTime())->invert) {
310
+			throw new PathValidationException('Certificate has expired.');
311
+		}
312
+	}
313 313
 
314
-    /**
315
-     * Check certificate revocation.
316
-     *
317
-     * @param Certificate $cert
318
-     */
319
-    private function _checkRevocation(Certificate $cert)
320
-    {
321
-        // @todo Implement CRL handling
322
-    }
314
+	/**
315
+	 * Check certificate revocation.
316
+	 *
317
+	 * @param Certificate $cert
318
+	 */
319
+	private function _checkRevocation(Certificate $cert)
320
+	{
321
+		// @todo Implement CRL handling
322
+	}
323 323
 
324
-    /**
325
-     * Check certificate issuer.
326
-     *
327
-     * @param ValidatorState $state
328
-     * @param Certificate    $cert
329
-     *
330
-     * @throws PathValidationException
331
-     */
332
-    private function _checkIssuer(ValidatorState $state, Certificate $cert): void
333
-    {
334
-        if (!$cert->tbsCertificate()->issuer()->equals($state->workingIssuerName())) {
335
-            throw new PathValidationException('Certification issuer mismatch.');
336
-        }
337
-    }
324
+	/**
325
+	 * Check certificate issuer.
326
+	 *
327
+	 * @param ValidatorState $state
328
+	 * @param Certificate    $cert
329
+	 *
330
+	 * @throws PathValidationException
331
+	 */
332
+	private function _checkIssuer(ValidatorState $state, Certificate $cert): void
333
+	{
334
+		if (!$cert->tbsCertificate()->issuer()->equals($state->workingIssuerName())) {
335
+			throw new PathValidationException('Certification issuer mismatch.');
336
+		}
337
+	}
338 338
 
339
-    /**
340
-     * @param ValidatorState $state
341
-     * @param Certificate    $cert
342
-     */
343
-    private function _checkPermittedSubtrees(ValidatorState $state, Certificate $cert)
344
-    {
345
-        // @todo Implement
346
-        $state->permittedSubtrees();
347
-    }
339
+	/**
340
+	 * @param ValidatorState $state
341
+	 * @param Certificate    $cert
342
+	 */
343
+	private function _checkPermittedSubtrees(ValidatorState $state, Certificate $cert)
344
+	{
345
+		// @todo Implement
346
+		$state->permittedSubtrees();
347
+	}
348 348
 
349
-    /**
350
-     * @param ValidatorState $state
351
-     * @param Certificate    $cert
352
-     */
353
-    private function _checkExcludedSubtrees(ValidatorState $state, Certificate $cert)
354
-    {
355
-        // @todo Implement
356
-        $state->excludedSubtrees();
357
-    }
349
+	/**
350
+	 * @param ValidatorState $state
351
+	 * @param Certificate    $cert
352
+	 */
353
+	private function _checkExcludedSubtrees(ValidatorState $state, Certificate $cert)
354
+	{
355
+		// @todo Implement
356
+		$state->excludedSubtrees();
357
+	}
358 358
 
359
-    /**
360
-     * Apply policy mappings handling for the preparation step.
361
-     *
362
-     * @param ValidatorState $state
363
-     * @param Certificate    $cert
364
-     *
365
-     * @throws PathValidationException
366
-     *
367
-     * @return ValidatorState
368
-     */
369
-    private function _preparePolicyMappings(ValidatorState $state,
370
-        Certificate $cert): ValidatorState
371
-    {
372
-        $extensions = $cert->tbsCertificate()->extensions();
373
-        if ($extensions->hasPolicyMappings()) {
374
-            // (a) verify that anyPolicy mapping is not used
375
-            if ($extensions->policyMappings()->hasAnyPolicyMapping()) {
376
-                throw new PathValidationException('anyPolicy mapping found.');
377
-            }
378
-            // (b) process policy mappings
379
-            if ($state->hasValidPolicyTree()) {
380
-                $state = $state->validPolicyTree()->processMappings($state, $cert);
381
-            }
382
-        }
383
-        return $state;
384
-    }
359
+	/**
360
+	 * Apply policy mappings handling for the preparation step.
361
+	 *
362
+	 * @param ValidatorState $state
363
+	 * @param Certificate    $cert
364
+	 *
365
+	 * @throws PathValidationException
366
+	 *
367
+	 * @return ValidatorState
368
+	 */
369
+	private function _preparePolicyMappings(ValidatorState $state,
370
+		Certificate $cert): ValidatorState
371
+	{
372
+		$extensions = $cert->tbsCertificate()->extensions();
373
+		if ($extensions->hasPolicyMappings()) {
374
+			// (a) verify that anyPolicy mapping is not used
375
+			if ($extensions->policyMappings()->hasAnyPolicyMapping()) {
376
+				throw new PathValidationException('anyPolicy mapping found.');
377
+			}
378
+			// (b) process policy mappings
379
+			if ($state->hasValidPolicyTree()) {
380
+				$state = $state->validPolicyTree()->processMappings($state, $cert);
381
+			}
382
+		}
383
+		return $state;
384
+	}
385 385
 
386
-    /**
387
-     * Apply name constraints handling for the preparation step.
388
-     *
389
-     * @param ValidatorState $state
390
-     * @param Certificate    $cert
391
-     *
392
-     * @return ValidatorState
393
-     */
394
-    private function _prepareNameConstraints(ValidatorState $state,
395
-        Certificate $cert): ValidatorState
396
-    {
397
-        $extensions = $cert->tbsCertificate()->extensions();
398
-        if ($extensions->hasNameConstraints()) {
399
-            $state = $this->_processNameConstraints($state, $cert);
400
-        }
401
-        return $state;
402
-    }
386
+	/**
387
+	 * Apply name constraints handling for the preparation step.
388
+	 *
389
+	 * @param ValidatorState $state
390
+	 * @param Certificate    $cert
391
+	 *
392
+	 * @return ValidatorState
393
+	 */
394
+	private function _prepareNameConstraints(ValidatorState $state,
395
+		Certificate $cert): ValidatorState
396
+	{
397
+		$extensions = $cert->tbsCertificate()->extensions();
398
+		if ($extensions->hasNameConstraints()) {
399
+			$state = $this->_processNameConstraints($state, $cert);
400
+		}
401
+		return $state;
402
+	}
403 403
 
404
-    /**
405
-     * Apply preparation for a non-self-signed certificate.
406
-     *
407
-     * @param ValidatorState $state
408
-     *
409
-     * @return ValidatorState
410
-     */
411
-    private function _prepareNonSelfIssued(ValidatorState $state): ValidatorState
412
-    {
413
-        // (h.1)
414
-        if ($state->explicitPolicy() > 0) {
415
-            $state = $state->withExplicitPolicy($state->explicitPolicy() - 1);
416
-        }
417
-        // (h.2)
418
-        if ($state->policyMapping() > 0) {
419
-            $state = $state->withPolicyMapping($state->policyMapping() - 1);
420
-        }
421
-        // (h.3)
422
-        if ($state->inhibitAnyPolicy() > 0) {
423
-            $state = $state->withInhibitAnyPolicy($state->inhibitAnyPolicy() - 1);
424
-        }
425
-        return $state;
426
-    }
404
+	/**
405
+	 * Apply preparation for a non-self-signed certificate.
406
+	 *
407
+	 * @param ValidatorState $state
408
+	 *
409
+	 * @return ValidatorState
410
+	 */
411
+	private function _prepareNonSelfIssued(ValidatorState $state): ValidatorState
412
+	{
413
+		// (h.1)
414
+		if ($state->explicitPolicy() > 0) {
415
+			$state = $state->withExplicitPolicy($state->explicitPolicy() - 1);
416
+		}
417
+		// (h.2)
418
+		if ($state->policyMapping() > 0) {
419
+			$state = $state->withPolicyMapping($state->policyMapping() - 1);
420
+		}
421
+		// (h.3)
422
+		if ($state->inhibitAnyPolicy() > 0) {
423
+			$state = $state->withInhibitAnyPolicy($state->inhibitAnyPolicy() - 1);
424
+		}
425
+		return $state;
426
+	}
427 427
 
428
-    /**
429
-     * Apply policy constraints handling for the preparation step.
430
-     *
431
-     * @param ValidatorState $state
432
-     * @param Certificate    $cert
433
-     *
434
-     * @return ValidatorState
435
-     */
436
-    private function _preparePolicyConstraints(ValidatorState $state,
437
-        Certificate $cert): ValidatorState
438
-    {
439
-        $extensions = $cert->tbsCertificate()->extensions();
440
-        if (!$extensions->hasPolicyConstraints()) {
441
-            return $state;
442
-        }
443
-        $ext = $extensions->policyConstraints();
444
-        // (i.1)
445
-        if ($ext->hasRequireExplicitPolicy() &&
446
-                $ext->requireExplicitPolicy() < $state->explicitPolicy()) {
447
-            $state = $state->withExplicitPolicy($ext->requireExplicitPolicy());
448
-        }
449
-        // (i.2)
450
-        if ($ext->hasInhibitPolicyMapping() &&
451
-                $ext->inhibitPolicyMapping() < $state->policyMapping()) {
452
-            $state = $state->withPolicyMapping($ext->inhibitPolicyMapping());
453
-        }
454
-        return $state;
455
-    }
428
+	/**
429
+	 * Apply policy constraints handling for the preparation step.
430
+	 *
431
+	 * @param ValidatorState $state
432
+	 * @param Certificate    $cert
433
+	 *
434
+	 * @return ValidatorState
435
+	 */
436
+	private function _preparePolicyConstraints(ValidatorState $state,
437
+		Certificate $cert): ValidatorState
438
+	{
439
+		$extensions = $cert->tbsCertificate()->extensions();
440
+		if (!$extensions->hasPolicyConstraints()) {
441
+			return $state;
442
+		}
443
+		$ext = $extensions->policyConstraints();
444
+		// (i.1)
445
+		if ($ext->hasRequireExplicitPolicy() &&
446
+				$ext->requireExplicitPolicy() < $state->explicitPolicy()) {
447
+			$state = $state->withExplicitPolicy($ext->requireExplicitPolicy());
448
+		}
449
+		// (i.2)
450
+		if ($ext->hasInhibitPolicyMapping() &&
451
+				$ext->inhibitPolicyMapping() < $state->policyMapping()) {
452
+			$state = $state->withPolicyMapping($ext->inhibitPolicyMapping());
453
+		}
454
+		return $state;
455
+	}
456 456
 
457
-    /**
458
-     * Apply inhibit any-policy handling for the preparation step.
459
-     *
460
-     * @param ValidatorState $state
461
-     * @param Certificate    $cert
462
-     *
463
-     * @return ValidatorState
464
-     */
465
-    private function _prepareInhibitAnyPolicy(ValidatorState $state,
466
-        Certificate $cert): ValidatorState
467
-    {
468
-        $extensions = $cert->tbsCertificate()->extensions();
469
-        if ($extensions->hasInhibitAnyPolicy()) {
470
-            $ext = $extensions->inhibitAnyPolicy();
471
-            if ($ext->skipCerts() < $state->inhibitAnyPolicy()) {
472
-                $state = $state->withInhibitAnyPolicy($ext->skipCerts());
473
-            }
474
-        }
475
-        return $state;
476
-    }
457
+	/**
458
+	 * Apply inhibit any-policy handling for the preparation step.
459
+	 *
460
+	 * @param ValidatorState $state
461
+	 * @param Certificate    $cert
462
+	 *
463
+	 * @return ValidatorState
464
+	 */
465
+	private function _prepareInhibitAnyPolicy(ValidatorState $state,
466
+		Certificate $cert): ValidatorState
467
+	{
468
+		$extensions = $cert->tbsCertificate()->extensions();
469
+		if ($extensions->hasInhibitAnyPolicy()) {
470
+			$ext = $extensions->inhibitAnyPolicy();
471
+			if ($ext->skipCerts() < $state->inhibitAnyPolicy()) {
472
+				$state = $state->withInhibitAnyPolicy($ext->skipCerts());
473
+			}
474
+		}
475
+		return $state;
476
+	}
477 477
 
478
-    /**
479
-     * Verify maximum certification path length for the preparation step.
480
-     *
481
-     * @param ValidatorState $state
482
-     * @param Certificate    $cert
483
-     *
484
-     * @throws PathValidationException
485
-     *
486
-     * @return ValidatorState
487
-     */
488
-    private function _verifyMaxPathLength(ValidatorState $state,
489
-        Certificate $cert): ValidatorState
490
-    {
491
-        if (!$cert->isSelfIssued()) {
492
-            if ($state->maxPathLength() <= 0) {
493
-                throw new PathValidationException(
494
-                    'Certification path length exceeded.');
495
-            }
496
-            $state = $state->withMaxPathLength($state->maxPathLength() - 1);
497
-        }
498
-        return $state;
499
-    }
478
+	/**
479
+	 * Verify maximum certification path length for the preparation step.
480
+	 *
481
+	 * @param ValidatorState $state
482
+	 * @param Certificate    $cert
483
+	 *
484
+	 * @throws PathValidationException
485
+	 *
486
+	 * @return ValidatorState
487
+	 */
488
+	private function _verifyMaxPathLength(ValidatorState $state,
489
+		Certificate $cert): ValidatorState
490
+	{
491
+		if (!$cert->isSelfIssued()) {
492
+			if ($state->maxPathLength() <= 0) {
493
+				throw new PathValidationException(
494
+					'Certification path length exceeded.');
495
+			}
496
+			$state = $state->withMaxPathLength($state->maxPathLength() - 1);
497
+		}
498
+		return $state;
499
+	}
500 500
 
501
-    /**
502
-     * Check key usage extension for the preparation step.
503
-     *
504
-     * @param Certificate $cert
505
-     *
506
-     * @throws PathValidationException
507
-     */
508
-    private function _checkKeyUsage(Certificate $cert): void
509
-    {
510
-        $extensions = $cert->tbsCertificate()->extensions();
511
-        if ($extensions->hasKeyUsage()) {
512
-            $ext = $extensions->keyUsage();
513
-            if (!$ext->isKeyCertSign()) {
514
-                throw new PathValidationException('keyCertSign usage not set.');
515
-            }
516
-        }
517
-    }
501
+	/**
502
+	 * Check key usage extension for the preparation step.
503
+	 *
504
+	 * @param Certificate $cert
505
+	 *
506
+	 * @throws PathValidationException
507
+	 */
508
+	private function _checkKeyUsage(Certificate $cert): void
509
+	{
510
+		$extensions = $cert->tbsCertificate()->extensions();
511
+		if ($extensions->hasKeyUsage()) {
512
+			$ext = $extensions->keyUsage();
513
+			if (!$ext->isKeyCertSign()) {
514
+				throw new PathValidationException('keyCertSign usage not set.');
515
+			}
516
+		}
517
+	}
518 518
 
519
-    /**
520
-     * @param ValidatorState $state
521
-     * @param Certificate    $cert
522
-     *
523
-     * @return ValidatorState
524
-     */
525
-    private function _processNameConstraints(ValidatorState $state,
526
-        Certificate $cert): ValidatorState
527
-    {
528
-        // @todo Implement
529
-        return $state;
530
-    }
519
+	/**
520
+	 * @param ValidatorState $state
521
+	 * @param Certificate    $cert
522
+	 *
523
+	 * @return ValidatorState
524
+	 */
525
+	private function _processNameConstraints(ValidatorState $state,
526
+		Certificate $cert): ValidatorState
527
+	{
528
+		// @todo Implement
529
+		return $state;
530
+	}
531 531
 
532
-    /**
533
-     * Process basic constraints extension.
534
-     *
535
-     * @param Certificate $cert
536
-     *
537
-     * @throws PathValidationException
538
-     */
539
-    private function _processBasicContraints(Certificate $cert): void
540
-    {
541
-        if (TBSCertificate::VERSION_3 === $cert->tbsCertificate()->version()) {
542
-            $extensions = $cert->tbsCertificate()->extensions();
543
-            if (!$extensions->hasBasicConstraints()) {
544
-                throw new PathValidationException(
545
-                    'v3 certificate must have basicConstraints extension.');
546
-            }
547
-            // verify that cA is set to TRUE
548
-            if (!$extensions->basicConstraints()->isCA()) {
549
-                throw new PathValidationException(
550
-                    'Certificate is not a CA certificate.');
551
-            }
552
-        }
553
-    }
532
+	/**
533
+	 * Process basic constraints extension.
534
+	 *
535
+	 * @param Certificate $cert
536
+	 *
537
+	 * @throws PathValidationException
538
+	 */
539
+	private function _processBasicContraints(Certificate $cert): void
540
+	{
541
+		if (TBSCertificate::VERSION_3 === $cert->tbsCertificate()->version()) {
542
+			$extensions = $cert->tbsCertificate()->extensions();
543
+			if (!$extensions->hasBasicConstraints()) {
544
+				throw new PathValidationException(
545
+					'v3 certificate must have basicConstraints extension.');
546
+			}
547
+			// verify that cA is set to TRUE
548
+			if (!$extensions->basicConstraints()->isCA()) {
549
+				throw new PathValidationException(
550
+					'Certificate is not a CA certificate.');
551
+			}
552
+		}
553
+	}
554 554
 
555
-    /**
556
-     * Process pathLenConstraint.
557
-     *
558
-     * @param ValidatorState $state
559
-     * @param Certificate    $cert
560
-     *
561
-     * @return ValidatorState
562
-     */
563
-    private function _processPathLengthContraint(ValidatorState $state,
564
-        Certificate $cert): ValidatorState
565
-    {
566
-        $extensions = $cert->tbsCertificate()->extensions();
567
-        if ($extensions->hasBasicConstraints()) {
568
-            $ext = $extensions->basicConstraints();
569
-            if ($ext->hasPathLen()) {
570
-                if ($ext->pathLen() < $state->maxPathLength()) {
571
-                    $state = $state->withMaxPathLength($ext->pathLen());
572
-                }
573
-            }
574
-        }
575
-        return $state;
576
-    }
555
+	/**
556
+	 * Process pathLenConstraint.
557
+	 *
558
+	 * @param ValidatorState $state
559
+	 * @param Certificate    $cert
560
+	 *
561
+	 * @return ValidatorState
562
+	 */
563
+	private function _processPathLengthContraint(ValidatorState $state,
564
+		Certificate $cert): ValidatorState
565
+	{
566
+		$extensions = $cert->tbsCertificate()->extensions();
567
+		if ($extensions->hasBasicConstraints()) {
568
+			$ext = $extensions->basicConstraints();
569
+			if ($ext->hasPathLen()) {
570
+				if ($ext->pathLen() < $state->maxPathLength()) {
571
+					$state = $state->withMaxPathLength($ext->pathLen());
572
+				}
573
+			}
574
+		}
575
+		return $state;
576
+	}
577 577
 
578
-    /**
579
-     * @param ValidatorState $state
580
-     * @param Certificate    $cert
581
-     *
582
-     * @return ValidatorState
583
-     */
584
-    private function _processExtensions(ValidatorState $state,
585
-        Certificate $cert): ValidatorState
586
-    {
587
-        // @todo Implement
588
-        return $state;
589
-    }
578
+	/**
579
+	 * @param ValidatorState $state
580
+	 * @param Certificate    $cert
581
+	 *
582
+	 * @return ValidatorState
583
+	 */
584
+	private function _processExtensions(ValidatorState $state,
585
+		Certificate $cert): ValidatorState
586
+	{
587
+		// @todo Implement
588
+		return $state;
589
+	}
590 590
 
591
-    /**
592
-     * @param ValidatorState $state
593
-     *
594
-     * @return ValidatorState
595
-     */
596
-    private function _calculatePolicyIntersection(ValidatorState $state): ValidatorState
597
-    {
598
-        // (i) If the valid_policy_tree is NULL, the intersection is NULL
599
-        if (!$state->hasValidPolicyTree()) {
600
-            return $state;
601
-        }
602
-        // (ii) If the valid_policy_tree is not NULL and
603
-        // the user-initial-policy-set is any-policy, the intersection
604
-        // is the entire valid_policy_tree
605
-        $initial_policies = $this->_config->policySet();
606
-        if (in_array(PolicyInformation::OID_ANY_POLICY, $initial_policies)) {
607
-            return $state;
608
-        }
609
-        // (iii) If the valid_policy_tree is not NULL and the
610
-        // user-initial-policy-set is not any-policy, calculate
611
-        // the intersection of the valid_policy_tree and the
612
-        // user-initial-policy-set as follows
613
-        return $state->validPolicyTree()->calculateIntersection($state, $initial_policies);
614
-    }
591
+	/**
592
+	 * @param ValidatorState $state
593
+	 *
594
+	 * @return ValidatorState
595
+	 */
596
+	private function _calculatePolicyIntersection(ValidatorState $state): ValidatorState
597
+	{
598
+		// (i) If the valid_policy_tree is NULL, the intersection is NULL
599
+		if (!$state->hasValidPolicyTree()) {
600
+			return $state;
601
+		}
602
+		// (ii) If the valid_policy_tree is not NULL and
603
+		// the user-initial-policy-set is any-policy, the intersection
604
+		// is the entire valid_policy_tree
605
+		$initial_policies = $this->_config->policySet();
606
+		if (in_array(PolicyInformation::OID_ANY_POLICY, $initial_policies)) {
607
+			return $state;
608
+		}
609
+		// (iii) If the valid_policy_tree is not NULL and the
610
+		// user-initial-policy-set is not any-policy, calculate
611
+		// the intersection of the valid_policy_tree and the
612
+		// user-initial-policy-set as follows
613
+		return $state->validPolicyTree()->calculateIntersection($state, $initial_policies);
614
+	}
615 615
 }
Please login to merge, or discard this patch.
lib/X509/CertificationPath/Policy/PolicyNode.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -16,267 +16,267 @@
 block discarded – undo
16 16
  */
17 17
 class PolicyNode implements \IteratorAggregate, \Countable
18 18
 {
19
-    /**
20
-     * Policy OID.
21
-     *
22
-     * @var string
23
-     */
24
-    protected $_validPolicy;
19
+	/**
20
+	 * Policy OID.
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $_validPolicy;
25 25
 
26
-    /**
27
-     * List of qualifiers.
28
-     *
29
-     * @var PolicyQualifierInfo[]
30
-     */
31
-    protected $_qualifiers;
26
+	/**
27
+	 * List of qualifiers.
28
+	 *
29
+	 * @var PolicyQualifierInfo[]
30
+	 */
31
+	protected $_qualifiers;
32 32
 
33
-    /**
34
-     * List of expected policy OIDs.
35
-     *
36
-     * @var string[]
37
-     */
38
-    protected $_expectedPolicies;
33
+	/**
34
+	 * List of expected policy OIDs.
35
+	 *
36
+	 * @var string[]
37
+	 */
38
+	protected $_expectedPolicies;
39 39
 
40
-    /**
41
-     * List of child nodes.
42
-     *
43
-     * @var PolicyNode[]
44
-     */
45
-    protected $_children;
40
+	/**
41
+	 * List of child nodes.
42
+	 *
43
+	 * @var PolicyNode[]
44
+	 */
45
+	protected $_children;
46 46
 
47
-    /**
48
-     * Reference to the parent node.
49
-     *
50
-     * @var null|PolicyNode
51
-     */
52
-    protected $_parent;
47
+	/**
48
+	 * Reference to the parent node.
49
+	 *
50
+	 * @var null|PolicyNode
51
+	 */
52
+	protected $_parent;
53 53
 
54
-    /**
55
-     * Constructor.
56
-     *
57
-     * @param string                $valid_policy      Policy OID
58
-     * @param PolicyQualifierInfo[] $qualifiers
59
-     * @param string[]              $expected_policies
60
-     */
61
-    public function __construct(string $valid_policy, array $qualifiers,
62
-        array $expected_policies)
63
-    {
64
-        $this->_validPolicy = $valid_policy;
65
-        $this->_qualifiers = $qualifiers;
66
-        $this->_expectedPolicies = $expected_policies;
67
-        $this->_children = [];
68
-    }
54
+	/**
55
+	 * Constructor.
56
+	 *
57
+	 * @param string                $valid_policy      Policy OID
58
+	 * @param PolicyQualifierInfo[] $qualifiers
59
+	 * @param string[]              $expected_policies
60
+	 */
61
+	public function __construct(string $valid_policy, array $qualifiers,
62
+		array $expected_policies)
63
+	{
64
+		$this->_validPolicy = $valid_policy;
65
+		$this->_qualifiers = $qualifiers;
66
+		$this->_expectedPolicies = $expected_policies;
67
+		$this->_children = [];
68
+	}
69 69
 
70
-    /**
71
-     * Create initial node for the policy tree.
72
-     *
73
-     * @return self
74
-     */
75
-    public static function anyPolicyNode(): self
76
-    {
77
-        return new self(PolicyInformation::OID_ANY_POLICY, [],
78
-            [PolicyInformation::OID_ANY_POLICY]);
79
-    }
70
+	/**
71
+	 * Create initial node for the policy tree.
72
+	 *
73
+	 * @return self
74
+	 */
75
+	public static function anyPolicyNode(): self
76
+	{
77
+		return new self(PolicyInformation::OID_ANY_POLICY, [],
78
+			[PolicyInformation::OID_ANY_POLICY]);
79
+	}
80 80
 
81
-    /**
82
-     * Get the valid policy OID.
83
-     *
84
-     * @return string
85
-     */
86
-    public function validPolicy(): string
87
-    {
88
-        return $this->_validPolicy;
89
-    }
81
+	/**
82
+	 * Get the valid policy OID.
83
+	 *
84
+	 * @return string
85
+	 */
86
+	public function validPolicy(): string
87
+	{
88
+		return $this->_validPolicy;
89
+	}
90 90
 
91
-    /**
92
-     * Check whether node has anyPolicy as a valid policy.
93
-     *
94
-     * @return bool
95
-     */
96
-    public function isAnyPolicy(): bool
97
-    {
98
-        return PolicyInformation::OID_ANY_POLICY === $this->_validPolicy;
99
-    }
91
+	/**
92
+	 * Check whether node has anyPolicy as a valid policy.
93
+	 *
94
+	 * @return bool
95
+	 */
96
+	public function isAnyPolicy(): bool
97
+	{
98
+		return PolicyInformation::OID_ANY_POLICY === $this->_validPolicy;
99
+	}
100 100
 
101
-    /**
102
-     * Get the qualifier set.
103
-     *
104
-     * @return PolicyQualifierInfo[]
105
-     */
106
-    public function qualifiers(): array
107
-    {
108
-        return $this->_qualifiers;
109
-    }
101
+	/**
102
+	 * Get the qualifier set.
103
+	 *
104
+	 * @return PolicyQualifierInfo[]
105
+	 */
106
+	public function qualifiers(): array
107
+	{
108
+		return $this->_qualifiers;
109
+	}
110 110
 
111
-    /**
112
-     * Check whether node has OID as an expected policy.
113
-     *
114
-     * @param string $oid
115
-     *
116
-     * @return bool
117
-     */
118
-    public function hasExpectedPolicy(string $oid): bool
119
-    {
120
-        return in_array($oid, $this->_expectedPolicies);
121
-    }
111
+	/**
112
+	 * Check whether node has OID as an expected policy.
113
+	 *
114
+	 * @param string $oid
115
+	 *
116
+	 * @return bool
117
+	 */
118
+	public function hasExpectedPolicy(string $oid): bool
119
+	{
120
+		return in_array($oid, $this->_expectedPolicies);
121
+	}
122 122
 
123
-    /**
124
-     * Get the expected policy set.
125
-     *
126
-     * @return string[]
127
-     */
128
-    public function expectedPolicies(): array
129
-    {
130
-        return $this->_expectedPolicies;
131
-    }
123
+	/**
124
+	 * Get the expected policy set.
125
+	 *
126
+	 * @return string[]
127
+	 */
128
+	public function expectedPolicies(): array
129
+	{
130
+		return $this->_expectedPolicies;
131
+	}
132 132
 
133
-    /**
134
-     * Set expected policies.
135
-     *
136
-     * @param string ...$oids Policy OIDs
137
-     */
138
-    public function setExpectedPolicies(string ...$oids): void
139
-    {
140
-        $this->_expectedPolicies = $oids;
141
-    }
133
+	/**
134
+	 * Set expected policies.
135
+	 *
136
+	 * @param string ...$oids Policy OIDs
137
+	 */
138
+	public function setExpectedPolicies(string ...$oids): void
139
+	{
140
+		$this->_expectedPolicies = $oids;
141
+	}
142 142
 
143
-    /**
144
-     * Check whether node has a child node with given valid policy OID.
145
-     *
146
-     * @param string $oid
147
-     *
148
-     * @return bool
149
-     */
150
-    public function hasChildWithValidPolicy(string $oid): bool
151
-    {
152
-        foreach ($this->_children as $node) {
153
-            if ($node->validPolicy() == $oid) {
154
-                return true;
155
-            }
156
-        }
157
-        return false;
158
-    }
143
+	/**
144
+	 * Check whether node has a child node with given valid policy OID.
145
+	 *
146
+	 * @param string $oid
147
+	 *
148
+	 * @return bool
149
+	 */
150
+	public function hasChildWithValidPolicy(string $oid): bool
151
+	{
152
+		foreach ($this->_children as $node) {
153
+			if ($node->validPolicy() == $oid) {
154
+				return true;
155
+			}
156
+		}
157
+		return false;
158
+	}
159 159
 
160
-    /**
161
-     * Add child node.
162
-     *
163
-     * @param PolicyNode $node
164
-     *
165
-     * @return self
166
-     */
167
-    public function addChild(PolicyNode $node): self
168
-    {
169
-        $id = spl_object_hash($node);
170
-        $node->_parent = $this;
171
-        $this->_children[$id] = $node;
172
-        return $this;
173
-    }
160
+	/**
161
+	 * Add child node.
162
+	 *
163
+	 * @param PolicyNode $node
164
+	 *
165
+	 * @return self
166
+	 */
167
+	public function addChild(PolicyNode $node): self
168
+	{
169
+		$id = spl_object_hash($node);
170
+		$node->_parent = $this;
171
+		$this->_children[$id] = $node;
172
+		return $this;
173
+	}
174 174
 
175
-    /**
176
-     * Get the child nodes.
177
-     *
178
-     * @return PolicyNode[]
179
-     */
180
-    public function children(): array
181
-    {
182
-        return array_values($this->_children);
183
-    }
175
+	/**
176
+	 * Get the child nodes.
177
+	 *
178
+	 * @return PolicyNode[]
179
+	 */
180
+	public function children(): array
181
+	{
182
+		return array_values($this->_children);
183
+	}
184 184
 
185
-    /**
186
-     * Remove this node from the tree.
187
-     *
188
-     * @return self The removed node
189
-     */
190
-    public function remove(): self
191
-    {
192
-        if ($this->_parent) {
193
-            $id = spl_object_hash($this);
194
-            unset($this->_parent->_children[$id], $this->_parent);
195
-        }
196
-        return $this;
197
-    }
185
+	/**
186
+	 * Remove this node from the tree.
187
+	 *
188
+	 * @return self The removed node
189
+	 */
190
+	public function remove(): self
191
+	{
192
+		if ($this->_parent) {
193
+			$id = spl_object_hash($this);
194
+			unset($this->_parent->_children[$id], $this->_parent);
195
+		}
196
+		return $this;
197
+	}
198 198
 
199
-    /**
200
-     * Check whether node has a parent.
201
-     *
202
-     * @return bool
203
-     */
204
-    public function hasParent(): bool
205
-    {
206
-        return isset($this->_parent);
207
-    }
199
+	/**
200
+	 * Check whether node has a parent.
201
+	 *
202
+	 * @return bool
203
+	 */
204
+	public function hasParent(): bool
205
+	{
206
+		return isset($this->_parent);
207
+	}
208 208
 
209
-    /**
210
-     * Get the parent node.
211
-     *
212
-     * @return null|PolicyNode
213
-     */
214
-    public function parent(): ?PolicyNode
215
-    {
216
-        return $this->_parent;
217
-    }
209
+	/**
210
+	 * Get the parent node.
211
+	 *
212
+	 * @return null|PolicyNode
213
+	 */
214
+	public function parent(): ?PolicyNode
215
+	{
216
+		return $this->_parent;
217
+	}
218 218
 
219
-    /**
220
-     * Get chain of parent nodes from this node's parent to the root node.
221
-     *
222
-     * @return PolicyNode[]
223
-     */
224
-    public function parents(): array
225
-    {
226
-        if (!$this->_parent) {
227
-            return [];
228
-        }
229
-        $nodes = $this->_parent->parents();
230
-        $nodes[] = $this->_parent;
231
-        return array_reverse($nodes);
232
-    }
219
+	/**
220
+	 * Get chain of parent nodes from this node's parent to the root node.
221
+	 *
222
+	 * @return PolicyNode[]
223
+	 */
224
+	public function parents(): array
225
+	{
226
+		if (!$this->_parent) {
227
+			return [];
228
+		}
229
+		$nodes = $this->_parent->parents();
230
+		$nodes[] = $this->_parent;
231
+		return array_reverse($nodes);
232
+	}
233 233
 
234
-    /**
235
-     * Walk tree from this node, applying a callback for each node.
236
-     *
237
-     * Nodes are traversed depth-first and callback shall be applied post-order.
238
-     *
239
-     * @param callable $fn
240
-     */
241
-    public function walkNodes(callable $fn): void
242
-    {
243
-        foreach ($this->_children as $node) {
244
-            $node->walkNodes($fn);
245
-        }
246
-        $fn($this);
247
-    }
234
+	/**
235
+	 * Walk tree from this node, applying a callback for each node.
236
+	 *
237
+	 * Nodes are traversed depth-first and callback shall be applied post-order.
238
+	 *
239
+	 * @param callable $fn
240
+	 */
241
+	public function walkNodes(callable $fn): void
242
+	{
243
+		foreach ($this->_children as $node) {
244
+			$node->walkNodes($fn);
245
+		}
246
+		$fn($this);
247
+	}
248 248
 
249
-    /**
250
-     * Get the total number of nodes in a tree.
251
-     *
252
-     * @return int
253
-     */
254
-    public function nodeCount(): int
255
-    {
256
-        $c = 1;
257
-        foreach ($this->_children as $child) {
258
-            $c += $child->nodeCount();
259
-        }
260
-        return $c;
261
-    }
249
+	/**
250
+	 * Get the total number of nodes in a tree.
251
+	 *
252
+	 * @return int
253
+	 */
254
+	public function nodeCount(): int
255
+	{
256
+		$c = 1;
257
+		foreach ($this->_children as $child) {
258
+			$c += $child->nodeCount();
259
+		}
260
+		return $c;
261
+	}
262 262
 
263
-    /**
264
-     * Get the number of child nodes.
265
-     *
266
-     * @see \Countable::count()
267
-     */
268
-    public function count(): int
269
-    {
270
-        return count($this->_children);
271
-    }
263
+	/**
264
+	 * Get the number of child nodes.
265
+	 *
266
+	 * @see \Countable::count()
267
+	 */
268
+	public function count(): int
269
+	{
270
+		return count($this->_children);
271
+	}
272 272
 
273
-    /**
274
-     * Get iterator for the child nodes.
275
-     *
276
-     * @see \IteratorAggregate::getIterator()
277
-     */
278
-    public function getIterator(): \ArrayIterator
279
-    {
280
-        return new \ArrayIterator($this->_children);
281
-    }
273
+	/**
274
+	 * Get iterator for the child nodes.
275
+	 *
276
+	 * @see \IteratorAggregate::getIterator()
277
+	 */
278
+	public function getIterator(): \ArrayIterator
279
+	{
280
+		return new \ArrayIterator($this->_children);
281
+	}
282 282
 }
Please login to merge, or discard this patch.
lib/X509/AttributeCertificate/Validation/ACValidationConfig.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -12,114 +12,114 @@
 block discarded – undo
12 12
  */
13 13
 class ACValidationConfig
14 14
 {
15
-    /**
16
-     * Certification path of the AC holder.
17
-     *
18
-     * @var CertificationPath
19
-     */
20
-    protected $_holderPath;
15
+	/**
16
+	 * Certification path of the AC holder.
17
+	 *
18
+	 * @var CertificationPath
19
+	 */
20
+	protected $_holderPath;
21 21
 
22
-    /**
23
-     * Certification path of the AC issuer.
24
-     *
25
-     * @var CertificationPath
26
-     */
27
-    protected $_issuerPath;
22
+	/**
23
+	 * Certification path of the AC issuer.
24
+	 *
25
+	 * @var CertificationPath
26
+	 */
27
+	protected $_issuerPath;
28 28
 
29
-    /**
30
-     * Evaluation reference time.
31
-     *
32
-     * @var \DateTimeImmutable
33
-     */
34
-    protected $_evalTime;
29
+	/**
30
+	 * Evaluation reference time.
31
+	 *
32
+	 * @var \DateTimeImmutable
33
+	 */
34
+	protected $_evalTime;
35 35
 
36
-    /**
37
-     * Permitted targets.
38
-     *
39
-     * @var Target[]
40
-     */
41
-    protected $_targets;
36
+	/**
37
+	 * Permitted targets.
38
+	 *
39
+	 * @var Target[]
40
+	 */
41
+	protected $_targets;
42 42
 
43
-    /**
44
-     * Constructor.
45
-     *
46
-     * @param CertificationPath $holder_path Certification path of the AC holder
47
-     * @param CertificationPath $issuer_path Certification path of the AC issuer
48
-     */
49
-    public function __construct(CertificationPath $holder_path,
50
-        CertificationPath $issuer_path)
51
-    {
52
-        $this->_holderPath = $holder_path;
53
-        $this->_issuerPath = $issuer_path;
54
-        $this->_evalTime = new \DateTimeImmutable();
55
-        $this->_targets = [];
56
-    }
43
+	/**
44
+	 * Constructor.
45
+	 *
46
+	 * @param CertificationPath $holder_path Certification path of the AC holder
47
+	 * @param CertificationPath $issuer_path Certification path of the AC issuer
48
+	 */
49
+	public function __construct(CertificationPath $holder_path,
50
+		CertificationPath $issuer_path)
51
+	{
52
+		$this->_holderPath = $holder_path;
53
+		$this->_issuerPath = $issuer_path;
54
+		$this->_evalTime = new \DateTimeImmutable();
55
+		$this->_targets = [];
56
+	}
57 57
 
58
-    /**
59
-     * Get certification path of the AC's holder.
60
-     *
61
-     * @return CertificationPath
62
-     */
63
-    public function holderPath(): CertificationPath
64
-    {
65
-        return $this->_holderPath;
66
-    }
58
+	/**
59
+	 * Get certification path of the AC's holder.
60
+	 *
61
+	 * @return CertificationPath
62
+	 */
63
+	public function holderPath(): CertificationPath
64
+	{
65
+		return $this->_holderPath;
66
+	}
67 67
 
68
-    /**
69
-     * Get certification path of the AC's issuer.
70
-     *
71
-     * @return CertificationPath
72
-     */
73
-    public function issuerPath(): CertificationPath
74
-    {
75
-        return $this->_issuerPath;
76
-    }
68
+	/**
69
+	 * Get certification path of the AC's issuer.
70
+	 *
71
+	 * @return CertificationPath
72
+	 */
73
+	public function issuerPath(): CertificationPath
74
+	{
75
+		return $this->_issuerPath;
76
+	}
77 77
 
78
-    /**
79
-     * Get self with given evaluation reference time.
80
-     *
81
-     * @param \DateTimeImmutable $dt
82
-     *
83
-     * @return self
84
-     */
85
-    public function withEvaluationTime(\DateTimeImmutable $dt): self
86
-    {
87
-        $obj = clone $this;
88
-        $obj->_evalTime = $dt;
89
-        return $obj;
90
-    }
78
+	/**
79
+	 * Get self with given evaluation reference time.
80
+	 *
81
+	 * @param \DateTimeImmutable $dt
82
+	 *
83
+	 * @return self
84
+	 */
85
+	public function withEvaluationTime(\DateTimeImmutable $dt): self
86
+	{
87
+		$obj = clone $this;
88
+		$obj->_evalTime = $dt;
89
+		return $obj;
90
+	}
91 91
 
92
-    /**
93
-     * Get the evaluation reference time.
94
-     *
95
-     * @return \DateTimeImmutable
96
-     */
97
-    public function evaluationTime(): \DateTimeImmutable
98
-    {
99
-        return $this->_evalTime;
100
-    }
92
+	/**
93
+	 * Get the evaluation reference time.
94
+	 *
95
+	 * @return \DateTimeImmutable
96
+	 */
97
+	public function evaluationTime(): \DateTimeImmutable
98
+	{
99
+		return $this->_evalTime;
100
+	}
101 101
 
102
-    /**
103
-     * Get self with permitted targets.
104
-     *
105
-     * @param Target ...$targets
106
-     *
107
-     * @return self
108
-     */
109
-    public function withTargets(Target ...$targets): self
110
-    {
111
-        $obj = clone $this;
112
-        $obj->_targets = $targets;
113
-        return $obj;
114
-    }
102
+	/**
103
+	 * Get self with permitted targets.
104
+	 *
105
+	 * @param Target ...$targets
106
+	 *
107
+	 * @return self
108
+	 */
109
+	public function withTargets(Target ...$targets): self
110
+	{
111
+		$obj = clone $this;
112
+		$obj->_targets = $targets;
113
+		return $obj;
114
+	}
115 115
 
116
-    /**
117
-     * Get array of permitted targets.
118
-     *
119
-     * @return Target[]
120
-     */
121
-    public function targets(): array
122
-    {
123
-        return $this->_targets;
124
-    }
116
+	/**
117
+	 * Get array of permitted targets.
118
+	 *
119
+	 * @return Target[]
120
+	 */
121
+	public function targets(): array
122
+	{
123
+		return $this->_targets;
124
+	}
125 125
 }
Please login to merge, or discard this patch.
lib/X509/AttributeCertificate/Validation/ACValidator.php 1 patch
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -21,186 +21,186 @@
 block discarded – undo
21 21
  */
22 22
 class ACValidator
23 23
 {
24
-    /**
25
-     * Attribute certificate.
26
-     *
27
-     * @var AttributeCertificate
28
-     */
29
-    protected $_ac;
24
+	/**
25
+	 * Attribute certificate.
26
+	 *
27
+	 * @var AttributeCertificate
28
+	 */
29
+	protected $_ac;
30 30
 
31
-    /**
32
-     * Validation configuration.
33
-     *
34
-     * @var ACValidationConfig
35
-     */
36
-    protected $_config;
31
+	/**
32
+	 * Validation configuration.
33
+	 *
34
+	 * @var ACValidationConfig
35
+	 */
36
+	protected $_config;
37 37
 
38
-    /**
39
-     * Crypto engine.
40
-     *
41
-     * @var Crypto
42
-     */
43
-    protected $_crypto;
38
+	/**
39
+	 * Crypto engine.
40
+	 *
41
+	 * @var Crypto
42
+	 */
43
+	protected $_crypto;
44 44
 
45
-    /**
46
-     * Constructor.
47
-     *
48
-     * @param AttributeCertificate $ac     Attribute certificate to validate
49
-     * @param ACValidationConfig   $config Validation configuration
50
-     * @param null|Crypto          $crypto Crypto engine, use default if not set
51
-     */
52
-    public function __construct(AttributeCertificate $ac,
53
-        ACValidationConfig $config, ?Crypto $crypto = null)
54
-    {
55
-        $this->_ac = $ac;
56
-        $this->_config = $config;
57
-        $this->_crypto = $crypto ?? Crypto::getDefault();
58
-    }
45
+	/**
46
+	 * Constructor.
47
+	 *
48
+	 * @param AttributeCertificate $ac     Attribute certificate to validate
49
+	 * @param ACValidationConfig   $config Validation configuration
50
+	 * @param null|Crypto          $crypto Crypto engine, use default if not set
51
+	 */
52
+	public function __construct(AttributeCertificate $ac,
53
+		ACValidationConfig $config, ?Crypto $crypto = null)
54
+	{
55
+		$this->_ac = $ac;
56
+		$this->_config = $config;
57
+		$this->_crypto = $crypto ?? Crypto::getDefault();
58
+	}
59 59
 
60
-    /**
61
-     * Validate attribute certificate.
62
-     *
63
-     * @throws ACValidationException If validation fails
64
-     *
65
-     * @return AttributeCertificate Validated AC
66
-     */
67
-    public function validate(): AttributeCertificate
68
-    {
69
-        $this->_validateHolder();
70
-        $issuer = $this->_verifyIssuer();
71
-        $this->_validateIssuerProfile($issuer);
72
-        $this->_validateTime();
73
-        $this->_validateTargeting();
74
-        return $this->_ac;
75
-    }
60
+	/**
61
+	 * Validate attribute certificate.
62
+	 *
63
+	 * @throws ACValidationException If validation fails
64
+	 *
65
+	 * @return AttributeCertificate Validated AC
66
+	 */
67
+	public function validate(): AttributeCertificate
68
+	{
69
+		$this->_validateHolder();
70
+		$issuer = $this->_verifyIssuer();
71
+		$this->_validateIssuerProfile($issuer);
72
+		$this->_validateTime();
73
+		$this->_validateTargeting();
74
+		return $this->_ac;
75
+	}
76 76
 
77
-    /**
78
-     * Validate AC holder's certification.
79
-     *
80
-     * @throws ACValidationException
81
-     *
82
-     * @return Certificate Certificate of the AC's holder
83
-     */
84
-    private function _validateHolder(): Certificate
85
-    {
86
-        $path = $this->_config->holderPath();
87
-        $config = PathValidationConfig::defaultConfig()
88
-            ->withMaxLength(count($path))
89
-            ->withDateTime($this->_config->evaluationTime());
90
-        try {
91
-            $holder = $path->validate($config, $this->_crypto)->certificate();
92
-        } catch (PathValidationException $e) {
93
-            throw new ACValidationException(
94
-                "Failed to validate holder PKC's certification path.", 0, $e);
95
-        }
96
-        if (!$this->_ac->isHeldBy($holder)) {
97
-            throw new ACValidationException("Name mismatch of AC's holder PKC.");
98
-        }
99
-        return $holder;
100
-    }
77
+	/**
78
+	 * Validate AC holder's certification.
79
+	 *
80
+	 * @throws ACValidationException
81
+	 *
82
+	 * @return Certificate Certificate of the AC's holder
83
+	 */
84
+	private function _validateHolder(): Certificate
85
+	{
86
+		$path = $this->_config->holderPath();
87
+		$config = PathValidationConfig::defaultConfig()
88
+			->withMaxLength(count($path))
89
+			->withDateTime($this->_config->evaluationTime());
90
+		try {
91
+			$holder = $path->validate($config, $this->_crypto)->certificate();
92
+		} catch (PathValidationException $e) {
93
+			throw new ACValidationException(
94
+				"Failed to validate holder PKC's certification path.", 0, $e);
95
+		}
96
+		if (!$this->_ac->isHeldBy($holder)) {
97
+			throw new ACValidationException("Name mismatch of AC's holder PKC.");
98
+		}
99
+		return $holder;
100
+	}
101 101
 
102
-    /**
103
-     * Verify AC's signature and issuer's certification.
104
-     *
105
-     * @throws ACValidationException
106
-     *
107
-     * @return Certificate Certificate of the AC's issuer
108
-     */
109
-    private function _verifyIssuer(): Certificate
110
-    {
111
-        $path = $this->_config->issuerPath();
112
-        $config = PathValidationConfig::defaultConfig()
113
-            ->withMaxLength(count($path))
114
-            ->withDateTime($this->_config->evaluationTime());
115
-        try {
116
-            $issuer = $path->validate($config, $this->_crypto)->certificate();
117
-        } catch (PathValidationException $e) {
118
-            throw new ACValidationException(
119
-                "Failed to validate issuer PKC's certification path.", 0, $e);
120
-        }
121
-        if (!$this->_ac->isIssuedBy($issuer)) {
122
-            throw new ACValidationException("Name mismatch of AC's issuer PKC.");
123
-        }
124
-        $pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo();
125
-        if (!$this->_ac->verify($pubkey_info, $this->_crypto)) {
126
-            throw new ACValidationException('Failed to verify signature.');
127
-        }
128
-        return $issuer;
129
-    }
102
+	/**
103
+	 * Verify AC's signature and issuer's certification.
104
+	 *
105
+	 * @throws ACValidationException
106
+	 *
107
+	 * @return Certificate Certificate of the AC's issuer
108
+	 */
109
+	private function _verifyIssuer(): Certificate
110
+	{
111
+		$path = $this->_config->issuerPath();
112
+		$config = PathValidationConfig::defaultConfig()
113
+			->withMaxLength(count($path))
114
+			->withDateTime($this->_config->evaluationTime());
115
+		try {
116
+			$issuer = $path->validate($config, $this->_crypto)->certificate();
117
+		} catch (PathValidationException $e) {
118
+			throw new ACValidationException(
119
+				"Failed to validate issuer PKC's certification path.", 0, $e);
120
+		}
121
+		if (!$this->_ac->isIssuedBy($issuer)) {
122
+			throw new ACValidationException("Name mismatch of AC's issuer PKC.");
123
+		}
124
+		$pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo();
125
+		if (!$this->_ac->verify($pubkey_info, $this->_crypto)) {
126
+			throw new ACValidationException('Failed to verify signature.');
127
+		}
128
+		return $issuer;
129
+	}
130 130
 
131
-    /**
132
-     * Validate AC issuer's profile.
133
-     *
134
-     * @see https://tools.ietf.org/html/rfc5755#section-4.5
135
-     *
136
-     * @param Certificate $cert
137
-     *
138
-     * @throws ACValidationException
139
-     */
140
-    private function _validateIssuerProfile(Certificate $cert): void
141
-    {
142
-        $exts = $cert->tbsCertificate()->extensions();
143
-        if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) {
144
-            throw new ACValidationException(
145
-                "Issuer PKC's Key Usage extension doesn't permit" .
146
-                     ' verification of digital signatures.');
147
-        }
148
-        if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) {
149
-            throw new ACValidationException('Issuer PKC must not be a CA.');
150
-        }
151
-    }
131
+	/**
132
+	 * Validate AC issuer's profile.
133
+	 *
134
+	 * @see https://tools.ietf.org/html/rfc5755#section-4.5
135
+	 *
136
+	 * @param Certificate $cert
137
+	 *
138
+	 * @throws ACValidationException
139
+	 */
140
+	private function _validateIssuerProfile(Certificate $cert): void
141
+	{
142
+		$exts = $cert->tbsCertificate()->extensions();
143
+		if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) {
144
+			throw new ACValidationException(
145
+				"Issuer PKC's Key Usage extension doesn't permit" .
146
+					 ' verification of digital signatures.');
147
+		}
148
+		if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) {
149
+			throw new ACValidationException('Issuer PKC must not be a CA.');
150
+		}
151
+	}
152 152
 
153
-    /**
154
-     * Validate AC's validity period.
155
-     *
156
-     * @throws ACValidationException
157
-     */
158
-    private function _validateTime(): void
159
-    {
160
-        $t = $this->_config->evaluationTime();
161
-        $validity = $this->_ac->acinfo()->validityPeriod();
162
-        if ($validity->notBeforeTime()->diff($t)->invert) {
163
-            throw new ACValidationException('Validity period has not started.');
164
-        }
165
-        if ($t->diff($validity->notAfterTime())->invert) {
166
-            throw new ACValidationException('Attribute certificate has expired.');
167
-        }
168
-    }
153
+	/**
154
+	 * Validate AC's validity period.
155
+	 *
156
+	 * @throws ACValidationException
157
+	 */
158
+	private function _validateTime(): void
159
+	{
160
+		$t = $this->_config->evaluationTime();
161
+		$validity = $this->_ac->acinfo()->validityPeriod();
162
+		if ($validity->notBeforeTime()->diff($t)->invert) {
163
+			throw new ACValidationException('Validity period has not started.');
164
+		}
165
+		if ($t->diff($validity->notAfterTime())->invert) {
166
+			throw new ACValidationException('Attribute certificate has expired.');
167
+		}
168
+	}
169 169
 
170
-    /**
171
-     * Validate AC's target information.
172
-     *
173
-     * @throws ACValidationException
174
-     */
175
-    private function _validateTargeting(): void
176
-    {
177
-        $exts = $this->_ac->acinfo()->extensions();
178
-        // if target information extension is not present
179
-        if (!$exts->has(Extension::OID_TARGET_INFORMATION)) {
180
-            return;
181
-        }
182
-        $ext = $exts->get(Extension::OID_TARGET_INFORMATION);
183
-        if ($ext instanceof TargetInformationExtension &&
184
-            !$this->_hasMatchingTarget($ext->targets())) {
185
-            throw new ACValidationException(
186
-                "Attribute certificate doesn't have a matching target.");
187
-        }
188
-    }
170
+	/**
171
+	 * Validate AC's target information.
172
+	 *
173
+	 * @throws ACValidationException
174
+	 */
175
+	private function _validateTargeting(): void
176
+	{
177
+		$exts = $this->_ac->acinfo()->extensions();
178
+		// if target information extension is not present
179
+		if (!$exts->has(Extension::OID_TARGET_INFORMATION)) {
180
+			return;
181
+		}
182
+		$ext = $exts->get(Extension::OID_TARGET_INFORMATION);
183
+		if ($ext instanceof TargetInformationExtension &&
184
+			!$this->_hasMatchingTarget($ext->targets())) {
185
+			throw new ACValidationException(
186
+				"Attribute certificate doesn't have a matching target.");
187
+		}
188
+	}
189 189
 
190
-    /**
191
-     * Check whether validation configuration has matching targets.
192
-     *
193
-     * @param Targets $targets Set of eligible targets
194
-     *
195
-     * @return bool
196
-     */
197
-    private function _hasMatchingTarget(Targets $targets): bool
198
-    {
199
-        foreach ($this->_config->targets() as $target) {
200
-            if ($targets->hasTarget($target)) {
201
-                return true;
202
-            }
203
-        }
204
-        return false;
205
-    }
190
+	/**
191
+	 * Check whether validation configuration has matching targets.
192
+	 *
193
+	 * @param Targets $targets Set of eligible targets
194
+	 *
195
+	 * @return bool
196
+	 */
197
+	private function _hasMatchingTarget(Targets $targets): bool
198
+	{
199
+		foreach ($this->_config->targets() as $target) {
200
+			if ($targets->hasTarget($target)) {
201
+				return true;
202
+			}
203
+		}
204
+		return false;
205
+	}
206 206
 }
Please login to merge, or discard this patch.