Skip to content

Commit 8963f6b

Browse files
committed
fix timestamp mappings
1 parent 191d9f8 commit 8963f6b

12 files changed

Lines changed: 74 additions & 24 deletions

src/Maps/TimeStampRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ abstract class TimeStampRequest
4848
'certReq' => [
4949
'type' => Identifier::BOOLEAN,
5050
'default' => true,
51+
'optional' => true,
5152
],
5253
'extensions' => [
5354
'constant' => 0,

src/Signature.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Class Signature
2424
*
2525
* @see Maps\Signature
26-
* @package Adapik\CMS
26+
* @package Falseclock\AdvancedCMS
2727
*/
2828
class Signature extends CMSBase
2929
{

src/SignedData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public function mergeCMS(SignedData $signedData): SignedData
6565
$initialContent->appendCertificate($certificate);
6666
}
6767

68-
$revocationInfoChoices = $newContent->getRevocationInfoChoices();
68+
/* $revocationInfoChoices = $newContent->getRevocationInfoChoices();
6969
if ($revocationInfoChoices) {
7070
foreach ($revocationInfoChoices as $revocationInfoChoice) {
7171
$initialContent->appendRevocationInfoChoices($revocationInfoChoice);
7272
}
73-
}
73+
}*/
7474

7575
foreach ($newContent->getSignerInfoSet() as $signerInfo) {
7676
$initialContent->appendSignerInfo($signerInfo);

src/SignedDataContent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public function appendCertificate(Certificate $certificate): self
5959
* @return SignedDataContent
6060
* @todo implement
6161
*/
62-
public function appendRevocationInfoChoices(RevocationInfoChoices $revocationInfoChoice): self
62+
/* public function appendRevocationInfoChoices(RevocationInfoChoices $revocationInfoChoice): self
6363
{
6464
return $this;
65-
}
65+
}*/
6666

6767
/**
6868
* @param SignerInfo $signerInfo

src/TimeStampRequest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ public static function createSimple(OctetString $data, string $hashAlgorithmOID
8181
* @throws Exception
8282
* @noinspection PhpUnnecessaryFullyQualifiedNameInspection
8383
*/
84-
public function getCertReq(): \FG\ASN1\Universal\Boolean
84+
public function getCertReq(): ?\FG\ASN1\Universal\Boolean
8585
{
86-
/** @var Boolean $boolean */
87-
$boolean = $this->object->findChildrenByType(Boolean::class)[0]->getBinary();
86+
$return = null;
87+
$boolean = $this->object->findChildrenByType(Boolean::class);
88+
if (count($boolean) > 0) {
89+
$binary = $boolean[0]->getBinary();
90+
$return = Boolean::fromBinary($binary);
91+
}
8892

89-
return Boolean::fromBinary($boolean);
93+
return $return;
9094
}
9195

9296
/**
@@ -104,13 +108,14 @@ public function getMessageImprint(): MessageImprint
104108
*/
105109
public function getNonce()
106110
{
111+
$return = null;
107112
$integers = $this->object->findChildrenByType(Integer::class);
108113
if (count($integers) == 2) {
109114
$binary = $integers[1]->getBinary();
110-
return Integer::fromBinary($binary);
115+
$return = Integer::fromBinary($binary);
111116
}
112117

113-
return null;
118+
return $return;
114119
}
115120

116121
/**
@@ -119,12 +124,13 @@ public function getNonce()
119124
*/
120125
public function getReqPolicy()
121126
{
127+
$return = null;
122128
$objects = $this->object->findChildrenByType(ObjectIdentifier::class);
123129
if (count($objects)) {
124130
$binary = $objects[0]->getBinary();
125-
return ObjectIdentifier::fromBinary($binary);
131+
$return = ObjectIdentifier::fromBinary($binary);
126132
}
127133

128-
return null;
134+
return $return;
129135
}
130136
}

src/TimeStampResponse.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ public function getStatusInfo(): PKIStatusInfo
5252
*/
5353
public function getSignedData(): ?SignedData
5454
{
55+
$return = null;
5556
$children = $this->object->getChildren();
5657

5758
if (count($children) == 2) {
58-
return new SignedData($children[1]);
59+
$return = new SignedData($children[1]);
5960
}
6061

61-
return null;
62+
return $return;
6263
}
6364
}

tests/MainTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public function getOCSPResponse()
1818
return file_get_contents(__DIR__ . '/fixtures/OCSPResponse.pem');
1919
}
2020

21+
public function getTimeStampRequestWithPolicy()
22+
{
23+
return file_get_contents(__DIR__ . '/fixtures/TimeStampRequestWithPolicy.pem');
24+
}
25+
2126
public function getFullCMS()
2227
{
2328
return file_get_contents(__DIR__ . '/fixtures/full.cms');
@@ -48,6 +53,11 @@ public function getTimeStampResponse()
4853
return file_get_contents(__DIR__ . '/fixtures/TimeStampResponse.pem');
4954
}
5055

56+
public function getTimeStampResponseTSA()
57+
{
58+
return file_get_contents(__DIR__ . '/fixtures/response.tsr');
59+
}
60+
5161
public function getBadTimeStampResponse()
5262
{
5363
return file_get_contents(__DIR__ . '/fixtures/BadTimeStampResponse.pem');
@@ -63,15 +73,15 @@ public function getOCSPRequestWithSignature()
6373
return file_get_contents(__DIR__ . '/fixtures/OCSPRequestWithSignature.pem');
6474
}
6575

66-
public function getRevokedCertificate()
67-
{
68-
return file_get_contents(__DIR__ . '/fixtures/revokedCertificate.pem');
69-
}
76+
public function getRevokedCertificate()
77+
{
78+
return file_get_contents(__DIR__ . '/fixtures/revokedCertificate.pem');
79+
}
7080

71-
public function getDoubleOCSPRequest()
72-
{
73-
return file_get_contents(__DIR__ . '/fixtures/DoubleOCSPRequest.pem');
74-
}
81+
public function getDoubleOCSPRequest()
82+
{
83+
return file_get_contents(__DIR__ . '/fixtures/DoubleOCSPRequest.pem');
84+
}
7585

7686
protected function curlRequest(string $url, string $binaryContent, string $requestContentType, string $responseContentType)
7787
{

tests/SignatureTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Falseclock\AdvancedCMS\Test;
5+
6+
use Falseclock\AdvancedCMS\OCSPRequest;
7+
use Falseclock\AdvancedCMS\Signature;
8+
9+
class SignatureTest extends MainTest
10+
{
11+
public function testCreation() {
12+
$OCSPRequest = OCSPRequest::createFromContent($this->getOCSPRequestWithSignature());
13+
14+
$optionalSignature = $OCSPRequest->getOptionalSignature();
15+
16+
$binary = $optionalSignature->getBinary();
17+
$newSignature = Signature::createFromContent($binary);
18+
self::assertEquals($binary, $newSignature->getBinary());
19+
}
20+
}

tests/TimeStampRequestTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88
use Falseclock\AdvancedCMS\TimeStampResponse;
99
use FG\ASN1\Universal\Boolean;
1010
use FG\ASN1\Universal\Integer;
11+
use FG\ASN1\Universal\ObjectIdentifier;
1112
use FG\ASN1\Universal\OctetString;
1213

1314
class TimeStampRequestTest extends MainTest
1415
{
16+
public function testPolicy()
17+
{
18+
$timeStampRequest = TimeStampRequest::createFromContent($this->getTimeStampRequestWithPolicy());
19+
20+
$policy = $timeStampRequest->getReqPolicy();
21+
self::assertInstanceOf(ObjectIdentifier::class, $policy);
22+
self::assertEquals("1.2.3.4.5.6.7.8.9", (string)$policy);
23+
self::assertNull($timeStampRequest->getCertReq());
24+
}
25+
1526
function testCreate()
1627
{
1728
$binary = "123456";

tests/TimeStampResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TimeStampResponseTest extends MainTest
1111
{
1212
public function testBase()
1313
{
14-
$timeStampResponse = TimeStampResponse::createFromContent($this->getTimeStampResponse());
14+
$timeStampResponse = TimeStampResponse::createFromContent($this->getTimeStampResponseTSA());
1515
self::assertInstanceOf(TimeStampResponse::class, $timeStampResponse);
1616

1717
self::assertInstanceOf(SignedData::class, $timeStampResponse->getSignedData());

0 commit comments

Comments
 (0)