|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace X509\AttributeCertificate; |
|
6
|
|
|
|
|
7
|
|
|
use ASN1\Element; |
|
8
|
|
|
use ASN1\Type\UnspecifiedType; |
|
9
|
|
|
use X501\ASN1\Name; |
|
10
|
|
|
use X509\Certificate\Certificate; |
|
11
|
|
|
use X509\GeneralName\DirectoryName; |
|
12
|
|
|
use X509\GeneralName\GeneralNames; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Base class implementing <i>AttCertIssuer</i> ASN.1 CHOICE type. |
|
16
|
|
|
* |
|
17
|
|
|
* @link https://tools.ietf.org/html/rfc5755#section-4.1 |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AttCertIssuer |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Generate ASN.1 element. |
|
23
|
|
|
* |
|
24
|
|
|
* @return Element |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract public function toASN1(); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Check whether AttCertIssuer identifies given certificate. |
|
30
|
|
|
* |
|
31
|
|
|
* @param Certificate $cert |
|
32
|
|
|
* @return bool |
|
33
|
|
|
*/ |
|
34
|
|
|
abstract public function identifiesPKC(Certificate $cert): bool; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Initialize from distinguished name. |
|
38
|
|
|
* |
|
39
|
|
|
* This conforms to RFC 5755 which states that only v2Form must be used, |
|
40
|
|
|
* and issuerName must contain exactly one GeneralName of DirectoryName |
|
41
|
|
|
* type. |
|
42
|
|
|
* |
|
43
|
|
|
* @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
44
|
|
|
* @param Name $name |
|
45
|
|
|
* @return self |
|
46
|
|
|
*/ |
|
47
|
3 |
|
public static function fromName(Name $name): self |
|
48
|
|
|
{ |
|
49
|
3 |
|
return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Initialize from an issuer's public key certificate. |
|
54
|
|
|
* |
|
55
|
|
|
* @param Certificate $cert |
|
56
|
|
|
* @return self |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public static function fromPKC(Certificate $cert): self |
|
59
|
|
|
{ |
|
60
|
1 |
|
return self::fromName($cert->tbsCertificate()->subject()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Initialize from ASN.1. |
|
65
|
|
|
* |
|
66
|
|
|
* @param UnspecifiedType $el CHOICE |
|
67
|
|
|
* @throws \UnexpectedValueException |
|
68
|
|
|
* @return self |
|
69
|
|
|
*/ |
|
70
|
10 |
|
public static function fromASN1(UnspecifiedType $el): self |
|
71
|
|
|
{ |
|
72
|
10 |
|
if (!$el->isTagged()) { |
|
73
|
1 |
|
throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
74
|
|
|
} |
|
75
|
9 |
|
$tagged = $el->asTagged(); |
|
76
|
9 |
|
switch ($tagged->tag()) { |
|
77
|
9 |
|
case 0: |
|
78
|
8 |
|
return V2Form::fromV2ASN1( |
|
79
|
8 |
|
$tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
80
|
|
|
} |
|
81
|
1 |
|
throw new \UnexpectedValueException("Unsupported issuer type."); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|