Skip to content

Commit 97e4cb5

Browse files
Guido Gröönmrts
authored andcommitted
WE2-681 Added initial AuthToken validation configuration
WE2-681 Added Uri class to parse URL to parts. Added phpunit test WE2-684 Updated WebEidAuthToken class. Added phpunit tests
1 parent 399d2b7 commit 97e4cb5

File tree

10 files changed

+899
-9
lines changed

10 files changed

+899
-9
lines changed

src/authtoken/WebEidAuthToken.php

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,114 @@
2424

2525
namespace web_eid\web_eid_authtoken_validation_php\authtoken;
2626

27+
use UnexpectedValueException;
28+
2729
class WebEidAuthToken
2830
{
2931

3032
/**
31-
* @var array Disallowed policies
33+
* @var string Unverified certificate
3234
*/
33-
private array $disallowedPolicies = [];
34-
35+
private ?string $unverifiedCertificate = null;
36+
/**
37+
* @var string Signature
38+
*/
39+
private ?string $signature = null;
40+
/**
41+
* @var string Algorithm
42+
*/
43+
private ?string $algorithm = null;
44+
/**
45+
* @var string Format
46+
*/
47+
private ?string $format = null;
3548
/**
36-
* Add disallowed policy to array
37-
*
38-
* @param string $policyOID
39-
*/
40-
public function addDisallowedPolicy(string $policyOID): void {
41-
$this->disallowedPolicies[] = $policyOID;
49+
* @var string App version
50+
*/
51+
private ?string $appVersion = null;
52+
53+
public function __construct(string $authenticationTokenJSON)
54+
{
55+
$jsonDecoded = json_decode($authenticationTokenJSON, true);
56+
if (is_null($jsonDecoded)) {
57+
return null;
58+
}
59+
60+
// unverifiedCertificate
61+
if (isset($jsonDecoded['unverifiedCertificate'])) {
62+
$this->unverifiedCertificate = $this->filterString('unverifiedCertificate', $jsonDecoded['unverifiedCertificate']);
63+
}
64+
// algorithm
65+
if (isset($jsonDecoded['algorithm'])) {
66+
$this->algorithm = $this->filterString('algorithm', $jsonDecoded['algorithm']);
67+
}
68+
// signature
69+
if (isset($jsonDecoded['signature'])) {
70+
$this->signature = $this->filterString('signature', $jsonDecoded['signature']);
71+
}
72+
// format
73+
if (isset($jsonDecoded['format'])) {
74+
$this->format = $this->filterString('format', $jsonDecoded['format']);
75+
}
76+
// appVersion
77+
if (isset($jsonDecoded['appVersion'])) {
78+
$this->appVersion = $this->filterString('appVersion', $jsonDecoded['appVersion']);
79+
}
80+
81+
}
82+
83+
public function getUnverifiedCertificate(): ?string
84+
{
85+
return $this->unverifiedCertificate;
86+
}
87+
88+
public function setUnverifiedCertificate(string $unverifiedCertificate): void
89+
{
90+
$this->unverifiedCertificate = $unverifiedCertificate;
91+
}
92+
93+
public function getAlgorithm(): ?string
94+
{
95+
return $this->algorithm;
96+
}
97+
98+
public function setAlgorithm(string $algorithm): void
99+
{
100+
$this->algorithm = $algorithm;
101+
}
102+
103+
public function getSignature(): ?string
104+
{
105+
return $this->signature;
106+
}
107+
108+
public function setSignature(string $signature): void
109+
{
110+
$this->signature = $signature;
111+
}
112+
113+
public function getFormat(): ?string
114+
{
115+
return $this->format;
116+
}
117+
118+
public function setFormat(string $format): void
119+
{
120+
$this->format = $format;
121+
}
122+
123+
public function getAppVersion(): ?string
124+
{
125+
return $this->appVersion;
126+
}
127+
128+
private function filterString(string $key, $data): string
129+
{
130+
$type = gettype($data);
131+
if ($type != "string") {
132+
throw new UnexpectedValueException("'{$key}' is {$type}, string expected");
133+
}
134+
return $data;
42135
}
43136

44137

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2020-2021 Estonian Information System Authority
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace web_eid\web_eid_authtoken_validation_php\exceptions;
26+
27+
class MalformedUriException extends AuthTokenException
28+
{
29+
public function __construct(string $uri)
30+
{
31+
parent::__construct("Unable to parse URI: $uri");
32+
}
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2020-2021 Estonian Information System Authority
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace web_eid\web_eid_authtoken_validation_php\util;
26+
27+
use BadFunctionCallException;
28+
29+
final class SubjectCertificatePolicies
30+
{
31+
private const ESTEID_SK_2015_MOBILE_ID_POLICY_PREFIX = '1.3.6.1.4.1.10015.1.3';
32+
public static $ESTEID_SK_2015_MOBILE_ID_POLICY = self::ESTEID_SK_2015_MOBILE_ID_POLICY_PREFIX;
33+
public static $ESTEID_SK_2015_MOBILE_ID_POLICY_V1 = self::ESTEID_SK_2015_MOBILE_ID_POLICY_PREFIX.'.1';
34+
public static $ESTEID_SK_2015_MOBILE_ID_POLICY_V2 = self::ESTEID_SK_2015_MOBILE_ID_POLICY_PREFIX.'.2';
35+
public static $ESTEID_SK_2015_MOBILE_ID_POLICY_V3 = self::ESTEID_SK_2015_MOBILE_ID_POLICY_PREFIX.'.3';
36+
37+
public function __construct()
38+
{
39+
throw new BadFunctionCallException('Utility class');
40+
}
41+
42+
}

0 commit comments

Comments
 (0)