Skip to content

Commit 3d5c9c9

Browse files
committed
bad timeStampResponse
1 parent cc9ba76 commit 3d5c9c9

22 files changed

Lines changed: 147 additions & 73 deletions

src/EncapsulatedContentInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EncapsulatedContentInfo extends \Adapik\CMS\EncapsulatedContentInfo
2929
* @return EncapsulatedContentInfo
3030
* @throws Exception
3131
*/
32-
public function setEContent(OctetString $octetString)
32+
public function setEContent(OctetString $octetString): self
3333
{
3434
$children = $this->object->getChildren();
3535

@@ -51,7 +51,7 @@ public function setEContent(OctetString $octetString)
5151
* @return EncapsulatedContentInfo
5252
* @throws Exception
5353
*/
54-
public function unSetEContent()
54+
public function unSetEContent(): self
5555
{
5656
$children = $this->object->getChildren();
5757
if (count($children) == 2) {

src/Maps/PKIStatusInfo.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class PKIStatusInfo
1818
* PKIStatusInfo ::= SEQUENCE {
1919
* status PKIStatus,
2020
* --XXX dont implement PKIXCMP yet
21-
* -- statusString PKIFreeText OPTIONAL,
21+
* statusString PKIFreeText OPTIONAL,
2222
* failInfo PKIFailureInfo OPTIONAL
2323
* }
2424
*
@@ -62,6 +62,13 @@ abstract class PKIStatusInfo
6262
'type' => Identifier::SEQUENCE,
6363
'children' => [
6464
'status' => ['type' => Identifier::INTEGER],
65+
'statusString' => [
66+
'optional' => true,
67+
'type' => Identifier::SEQUENCE,
68+
'children' => [
69+
'statusString' => ['type' => Identifier::UTF8_STRING],
70+
]
71+
],
6572
'failInfo' => ['optional' => true, 'type' => Identifier::BITSTRING],
6673
]
6774
];

src/OCSPRequest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class OCSPRequest extends CMSBase
4646
* @return OCSPRequest
4747
* @throws FormatException
4848
*/
49-
public static function createFromContent(string $content)
49+
public static function createFromContent(string $content): self
5050
{
5151
return new self(self::makeFromContent($content, Maps\OCSPRequest::class, Sequence::class));
5252
}
@@ -59,7 +59,7 @@ public static function createFromContent(string $content)
5959
* @return OCSPRequest
6060
* @throws FormatException
6161
*/
62-
public static function createSimple(Certificate $publicCertificate, Certificate $intermediateCertificate, string $hashAlgorithmOID = Algorithm::OID_SHA1)
62+
public static function createSimple(Certificate $publicCertificate, Certificate $intermediateCertificate, string $hashAlgorithmOID = Algorithm::OID_SHA1): self
6363
{
6464
/** @see Maps\TBSRequest */
6565
$tbsRequest = Sequence::create([
@@ -111,7 +111,7 @@ public static function createSimple(Certificate $publicCertificate, Certificate
111111
)
112112
]
113113
);
114-
// TODO: signature create and test
114+
115115
return new self(Sequence::create([$tbsRequest/*, $optionalSignature*/]));
116116
}
117117

@@ -120,15 +120,15 @@ public static function createSimple(Certificate $publicCertificate, Certificate
120120
* @return string
121121
* @throws Exception
122122
*/
123-
protected static function generateNonce(int $length = null)
123+
protected static function generateNonce(int $length = null): string
124124
{
125125
return random_bytes($length ?? self::OCSP_DEFAULT_NONCE_LENGTH);
126126
}
127127

128128
/**
129129
* @return TBSRequest
130130
*/
131-
public function getTBSRequest()
131+
public function getTBSRequest(): TBSRequest
132132
{
133133
return new TBSRequest($this->object->getChildren()[0]);
134134
}
@@ -137,7 +137,7 @@ public function getTBSRequest()
137137
* @return Signature|null
138138
* @throws ParserException
139139
*/
140-
public function getOptionalSignature()
140+
public function getOptionalSignature(): ?Signature
141141
{
142142
$children = $this->object->getChildren();
143143

src/OCSPResponse.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,42 @@ class OCSPResponse extends CMSBase
3535
* @return OCSPResponse
3636
* @throws FormatException
3737
*/
38-
public static function createFromContent(string $content)
38+
public static function createFromContent(string $content): self
3939
{
4040
return new self(self::makeFromContent($content, Maps\OCSPResponse::class, Sequence::class));
4141
}
4242

4343
/**
4444
* @return OCSPResponseStatus
4545
*/
46-
public function getResponseStatus()
46+
public function getResponseStatus(): OCSPResponseStatus
4747
{
4848
$enum = $this->object->getChildren()[0];
4949

5050
return new OCSPResponseStatus($enum);
5151
}
5252

5353
/**
54-
* @return BasicOCSPResponse
54+
* @return BasicOCSPResponse|null
5555
* @throws FormatException
5656
*/
57-
public function getBasicOCSPResponse()
57+
public function getBasicOCSPResponse(): ?BasicOCSPResponse
5858
{
59-
return BasicOCSPResponse::createFromContent($this->getResponseBytes()->getResponse());
59+
$responseBytes = $this->getResponseBytes();
60+
61+
if (is_null($responseBytes))
62+
return null;
63+
else
64+
return BasicOCSPResponse::createFromContent($responseBytes->getResponse());
6065
}
6166

6267
/**
6368
* Note: we lost parenthesis cause parsing binary content
64-
* @return ResponseBytes|null
69+
*
70+
* @return ResponseBytes|null cause response if optional
6571
* @throws FormatException
6672
*/
67-
public function getResponseBytes()
73+
public function getResponseBytes(): ?ResponseBytes
6874
{
6975
$children = $this->object->getChildren();
7076

src/OCSPResponseStatus.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class OCSPResponseStatus extends CMSBase
3232
* @return OCSPResponseStatus
3333
* @throws FormatException
3434
*/
35-
public static function createFromContent(string $content)
35+
public static function createFromContent(string $content): self
3636
{
3737
return new self(self::makeFromContent($content, Maps\OCSPResponseStatus::class, Enumerated::class));
3838
}
3939

4040
/**
41-
* @return mixed
41+
* @return array
4242
*/
43-
public function getMapping()
43+
public function getMapping(): array
4444
{
4545
return Maps\OCSPResponseStatus::MAP['mapping'];
4646
}
@@ -50,7 +50,7 @@ public function getMapping()
5050
*
5151
* @return bool
5252
*/
53-
public function isSuccessful()
53+
public function isSuccessful(): bool
5454
{
5555
return intval($this->object->value) === 0;
5656
}

src/PKIStatusInfo.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
use Adapik\CMS\CMSBase;
1414
use Adapik\CMS\Exception\FormatException;
15+
use Exception;
16+
use FG\ASN1\Universal\BitString;
1517
use FG\ASN1\Universal\Sequence;
1618

1719
/**
@@ -32,38 +34,57 @@ class PKIStatusInfo extends CMSBase
3234
* @return PKIStatusInfo
3335
* @throws FormatException
3436
*/
35-
public static function createFromContent(string $content)
37+
public static function createFromContent(string $content): self
3638
{
3739
return new self(self::makeFromContent($content, Maps\PKIStatusInfo::class, Sequence::class));
3840
}
3941

4042
/**
4143
* @return bool
4244
*/
43-
public function isGranted()
45+
public function isGranted(): bool
4446
{
4547
return $this->getStatus() == 0;
4648
}
4749

4850
/**
4951
* @return int
5052
*/
51-
public function getStatus()
53+
public function getStatus(): int
5254
{
5355
$integer = $this->object->getChildren()[0];
5456

5557
return intval($integer->__toString());
5658
}
5759

5860
/**
59-
* @return string
61+
* @return string|null
62+
* @throws Exception
6063
*/
61-
public function getFailInfo()
64+
public function getStatusString(): ?string
65+
{
66+
$children = $this->object->getChildren();
67+
if (count($children) > 1) {
68+
$utf8Strings = $this->object->findChildrenByType(Sequence::class);
69+
if (count($utf8Strings) > 0) {
70+
return $utf8Strings[0]->__toString();
71+
}
72+
}
73+
74+
return null;
75+
}
76+
77+
/**
78+
* @return string|null
79+
* @throws Exception
80+
*/
81+
public function getFailureInfo(): ?string
6282
{
6383
$children = $this->object->getChildren();
6484

65-
if (count($children) == 2) {
66-
return $children[1]->__toString();
85+
if (count($children) > 1) {
86+
$bitStrings = $this->object->findChildrenByType(BitString::class);
87+
return $bitStrings[0]->__toString();
6788
}
6889
return null;
6990
}

src/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ class Request extends CMSBase
3535
* @return Request
3636
* @throws FormatException
3737
*/
38-
public static function createFromContent(string $content)
38+
public static function createFromContent(string $content): self
3939
{
4040
return new self(self::makeFromContent($content, Maps\Request::class, Sequence::class));
4141
}
4242

4343
/**
4444
* @return CertID
4545
*/
46-
public function getRequestedCertificate()
46+
public function getRequestedCertificate(): CertID
4747
{
4848
return new CertID($this->object->getChildren()[0]);
4949
}

src/ResponseBytes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class ResponseBytes extends CMSBase
3434
* @return ResponseBytes
3535
* @throws FormatException
3636
*/
37-
public static function createFromContent(string $content)
37+
public static function createFromContent(string $content): self
3838
{
3939
return new self(self::makeFromContent($content, Maps\ResponseBytes::class, Sequence::class));
4040
}
4141

4242
/**
4343
* @return string
4444
*/
45-
public function getResponseType()
45+
public function getResponseType(): string
4646
{
4747
/** @var ObjectIdentifier $objectIdentifier */
4848
$objectIdentifier = $this->object->getChildren()[0];
@@ -53,7 +53,7 @@ public function getResponseType()
5353
/**
5454
* @return string
5555
*/
56-
public function getResponse()
56+
public function getResponse(): string
5757
{
5858
/** @var OctetString $octetString */
5959
$octetString = $this->object->getChildren()[1];

src/RevocationValues.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class RevocationValues extends \Adapik\CMS\RevocationValues
3434
* @return RevocationValues
3535
* @throws ParserException
3636
*/
37-
public static function createFromOCSPResponse(?BasicOCSPResponse $basicOCSPResponse = null, ?CertificateList $certificateList = null, ?Sequence $otherRevValues = null)
37+
public static function createFromOCSPResponse(?BasicOCSPResponse $basicOCSPResponse = null, ?CertificateList $certificateList = null, ?Sequence $otherRevValues = null): self
3838
{
3939
return new self(self::sequenceFromOCSPResponse($basicOCSPResponse, $certificateList, $otherRevValues));
4040
}
@@ -46,7 +46,7 @@ public static function createFromOCSPResponse(?BasicOCSPResponse $basicOCSPRespo
4646
* @return Sequence
4747
* @throws ParserException
4848
*/
49-
public static function sequenceFromOCSPResponse(?BasicOCSPResponse $basicOCSPResponse = null, ?CertificateList $certificateList = null, ?Sequence $otherRevValues = null)
49+
public static function sequenceFromOCSPResponse(?BasicOCSPResponse $basicOCSPResponse = null, ?CertificateList $certificateList = null, ?Sequence $otherRevValues = null): Sequence
5050
{
5151
if (is_null($basicOCSPResponse) and is_null($certificateList) and is_null($otherRevValues)) {
5252
throw new Exception("At least 1 parameter must be not null");

src/SignedData.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SignedData extends \Adapik\CMS\SignedData
3131
* @return SignedData
3232
* @throws FormatException
3333
*/
34-
public static function createFromContent(string $content)
34+
public static function createFromContent(string $content): self
3535
{
3636
return new self(self::makeFromContent($content, \Adapik\CMS\Maps\SignedData::class, Sequence::class));
3737
}
@@ -42,7 +42,7 @@ public static function createFromContent(string $content)
4242
* @return $this
4343
* @throws Exception
4444
*/
45-
public function mergeCMS(SignedData $signedData)
45+
public function mergeCMS(SignedData $signedData): SignedData
4646
{
4747
$initialContent = $this->getSignedDataContent();
4848
$newContent = $signedData->getSignedDataContent();
@@ -83,7 +83,7 @@ public function mergeCMS(SignedData $signedData)
8383
* @return SignedDataContent
8484
* @throws Exception
8585
*/
86-
public function getSignedDataContent()
86+
public function getSignedDataContent(): SignedDataContent
8787
{
8888
$SignedDataContent = $this->object->findChildrenByType(ExplicitlyTaggedObject::class)[0];
8989

0 commit comments

Comments
 (0)