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
|
|
|
public static function fromName(Name $name) |
48
|
|
|
{ |
49
|
|
|
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
|
|
|
public static function fromPKC(Certificate $cert) |
59
|
|
|
{ |
60
|
|
|
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
|
|
|
public static function fromASN1(UnspecifiedType $el) |
71
|
|
|
{ |
72
|
|
|
if (!$el->isTagged()) { |
73
|
|
|
throw new \UnexpectedValueException("v1Form issuer not supported."); |
74
|
|
|
} |
75
|
|
|
$tagged = $el->asTagged(); |
76
|
|
|
switch ($tagged->tag()) { |
77
|
|
|
case 0: |
78
|
|
|
return V2Form::fromV2ASN1( |
79
|
|
|
$tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
80
|
|
|
} |
81
|
|
|
throw new \UnexpectedValueException("Unsupported issuer type."); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|