Skip to content

Commit 4fe16a7

Browse files
committed
php 5.5 support
phpspeclib@^2.0 v1.3.2
1 parent 2633526 commit 4fe16a7

File tree

7 files changed

+94
-75
lines changed

7 files changed

+94
-75
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ EDI-X12, EDIFACT, XML, or binary payloads between trading partners.
1414
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
1515
Either run
1616
```
17-
php composer.phar require --prefer-dist tiamo/phpas2 "*"
17+
composer require --prefer-dist tiamo/phpas2 "^1.3"
1818
```
1919
or add
2020
```
21-
"tiamo/phpas2": "*"
21+
"tiamo/phpas2": "^1.3"
2222
```
2323
to the require section of your `composer.json` file.
2424

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tiamo/phpas2",
33
"description": "PHPAS2 is a php-based implementation of the EDIINT AS2 standard",
4-
"version": "1.3.1",
4+
"version": "1.3.2",
55
"authors": [
66
{
77
"name": "Vladyslav K",
@@ -18,10 +18,11 @@
1818
"license": "MIT",
1919
"require": {
2020
"php": ">=5.5",
21+
"ext-zlib": "*",
2122
"ext-openssl": "*",
2223
"psr/log": "^1.0",
2324
"guzzlehttp/guzzle": "^6.3",
24-
"phpseclib/phpseclib": "dev-master"
25+
"phpseclib/phpseclib": "^2.0"
2526
},
2627
"require-dev": {
2728
"phpunit/phpunit": "~5.0"

examples/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
require_once "../vendor/autoload.php";
4-
require_once "functions.php";
3+
require_once __DIR__ . "/../vendor/autoload.php";
4+
require_once __DIR__ . "/functions.php";
55

66
spl_autoload_register(function ($class) {
77
spl_autoload(strtolower(str_replace("\\", "/", $class)));

examples/inbound.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121

2222
$server = new \AS2\Server($manager, $storage);
2323

24-
//$message = file_get_contents('data/inbound/mendelson_opensource_AS2-1514906682749-1@mycompanyAS2_phpas2.raw');
24+
//$message = file_get_contents('data/inbound/mendelson_opensource_AS2-1514912694550-2@mycompanyAS2_phpas2.raw');
2525
//$payload = \AS2\Utils::parseMessage($message);
26-
////$payload['body'] = \AS2\Utils::encodeBase64($payload['body']);
27-
//
26+
2827
//$serverRequest = new ServerRequest(
2928
// 'POST',
3029
// 'http:://localhost',
@@ -41,8 +40,8 @@
4140

4241
foreach ($response->getHeaders() as $name => $values) {
4342
foreach ($values as $value) {
44-
header(sprintf('%s: %s', $name, $value), false);
43+
@header(sprintf('%s: %s', $name, $value), false);
4544
}
4645
}
4746

48-
echo $response->getBody()->getContents();
47+
echo $response->getBody()->getContents();

src/ASN1Helper.php

Lines changed: 69 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,86 @@
77
class ASN1Helper extends ASN1
88
{
99
const PKCS_OID = '1.2.840.113549';
10-
const PKCS7_OID = self::PKCS_OID . '.1.7';
11-
const PKCS9_OID = self::PKCS_OID . '.1.9';
12-
const PKCS9_CT_OID = self::PKCS9_OID . '.16.1';
10+
const PKCS7_OID = '1.2.840.113549.1.7';
11+
const PKCS9_OID = '1.2.840.113549.1.9';
12+
const PKCS9_CT_OID = '1.2.840.113549.1.9.16.1';
1313

14-
const DATA_OID = self::PKCS7_OID . '.1';
15-
const SIGNED_DATA_OID = self::PKCS7_OID . '.2';
16-
const ENVELOPED_DATA_OID = self::PKCS7_OID . '.3';
17-
const SIGNED_AND_ENVELOPED_DATA_OID = self::PKCS7_OID . '.4';
18-
const DIGEST_DATA_OID = self::PKCS7_OID . '.5';
19-
const ENCRYPTED_DATA_OID = self::PKCS7_OID . '.6';
14+
const DATA_OID = '1.2.840.113549.1.7.1';
15+
const SIGNED_DATA_OID = '1.2.840.113549.1.7.2';
16+
const ENVELOPED_DATA_OID = '1.2.840.113549.1.7.3';
17+
const SIGNED_AND_ENVELOPED_DATA_OID = '1.2.840.113549.1.7.4';
18+
const DIGEST_DATA_OID = '1.2.840.113549.1.7.5';
19+
const ENCRYPTED_DATA_OID = '1.2.840.113549.1.7.6';
2020

21-
const AUTHENTICATED_DATA_OID = self::PKCS9_CT_OID . '.2';
22-
const COMPRESSED_DATA_OID = self::PKCS9_CT_OID . '.9';
23-
const AUTH_ENVELOPED_DATA_OID = self::PKCS9_CT_OID . '.23';
21+
const AUTHENTICATED_DATA_OID = '1.2.840.113549.1.9.16.1.2';
22+
const COMPRESSED_DATA_OID = '1.2.840.113549.1.9.16.1.9';
23+
const AUTH_ENVELOPED_DATA_OID = '1.2.840.113549.1.9.16.1.23';
2424

25-
const ALG_3DES_OID = self::PKCS9_OID . '.16.3.6';
26-
const ALG_RC2_OID = self::PKCS9_OID . '.16.3.7';
27-
const ALG_ZLIB_OID = self::PKCS9_OID . '.16.3.8';
28-
const ALG_PWRI_KEK_OID = self::PKCS9_OID . '.16.3.9';
25+
const ALG_3DES_OID = '1.2.840.113549.1.9.16.3.6';
26+
const ALG_RC2_OID = '1.2.840.113549.1.9.16.3.7';
27+
const ALG_ZLIB_OID = '1.2.840.113549.1.9.16.3.8';
28+
const ALG_PWRI_KEK_OID = '1.2.840.113549.1.9.16.3.9';
2929

30-
const DIGEST_ALGORITHM_OID = self::PKCS_OID . '.2';
31-
const MD2_OID = self::DIGEST_ALGORITHM_OID . '.2';
32-
const MD4_OID = self::DIGEST_ALGORITHM_OID . '.4';
33-
const MD5_OID = self::DIGEST_ALGORITHM_OID . '.5';
34-
const HMAC_WITH_SHA1_OID = self::DIGEST_ALGORITHM_OID . '.7';
30+
const DIGEST_ALGORITHM_OID = '1.2.840.113549.2';
31+
const MD2_OID = '1.2.840.113549.2.2';
32+
const MD4_OID = '1.2.840.113549.2.4';
33+
const MD5_OID = '1.2.840.113549.2.5';
34+
const HMAC_WITH_SHA1_OID = '1.2.840.113549.2.7';
3535

36-
const ENCRYPTION_ALGORITHM_OID = self::PKCS_OID . '.3';
37-
const RC2_CBC = self::ENCRYPTION_ALGORITHM_OID . '.2';
38-
const DES_EDE3_CBC = self::ENCRYPTION_ALGORITHM_OID . '.7';
36+
const ENCRYPTION_ALGORITHM_OID = '1.2.840.113549.3';
37+
const RC2_CBC = '1.2.840.113549.3.2';
38+
const DES_EDE3_CBC = '1.2.840.113549.3.7';
3939

40-
const ALGORITHM_IDENTIFIER_MAP = [
41-
'type' => ASN1::TYPE_SEQUENCE,
42-
'children' => [
43-
'algorithm' => ['type' => ASN1::TYPE_OBJECT_IDENTIFIER],
44-
'parameters' => [
45-
'type' => ASN1::TYPE_ANY,
46-
'optional' => true,
40+
/**
41+
* @return array
42+
*/
43+
public static function getAlgorithmIdentifierMap() {
44+
return [
45+
'type' => ASN1::TYPE_SEQUENCE,
46+
'children' => [
47+
'algorithm' => ['type' => ASN1::TYPE_OBJECT_IDENTIFIER],
48+
'parameters' => [
49+
'type' => ASN1::TYPE_ANY,
50+
'optional' => true,
51+
],
4752
],
48-
],
49-
];
53+
];
54+
}
5055

51-
const CONTENT_INFO_MAP = [
52-
'type' => ASN1::TYPE_SEQUENCE,
53-
'children' => [
54-
'contentType' => ['type' => ASN1::TYPE_OBJECT_IDENTIFIER],
55-
'content' => [
56-
'type' => ASN1::TYPE_OCTET_STRING,
57-
'constant' => 0,
58-
'optional' => true,
59-
'explicit' => true,
56+
/**
57+
* @return array
58+
*/
59+
public static function getContentInfoMap() {
60+
return [
61+
'type' => ASN1::TYPE_SEQUENCE,
62+
'children' => [
63+
'contentType' => ['type' => ASN1::TYPE_OBJECT_IDENTIFIER],
64+
'content' => [
65+
'type' => ASN1::TYPE_OCTET_STRING,
66+
'constant' => 0,
67+
'optional' => true,
68+
'explicit' => true,
69+
],
6070
],
61-
],
62-
];
71+
];
72+
}
6373

64-
const COMPRESSED_DATA_MAP = [
65-
'type' => ASN1::TYPE_SEQUENCE,
66-
'children' => [
67-
'version' => [
68-
'type' => ASN1::TYPE_INTEGER,
69-
'mapping' => ['0', '1', '2', '4', '5'],
74+
/**
75+
* @return array
76+
*/
77+
public static function getCompressedDataMap() {
78+
return [
79+
'type' => ASN1::TYPE_SEQUENCE,
80+
'children' => [
81+
'version' => [
82+
'type' => ASN1::TYPE_INTEGER,
83+
'mapping' => ['0', '1', '2', '4', '5'],
84+
],
85+
'compression' => self::getAlgorithmIdentifierMap(),
86+
'payload' => self::getContentInfoMap(),
7087
],
71-
'compression' => self::ALGORITHM_IDENTIFIER_MAP,
72-
'payload' => self::CONTENT_INFO_MAP,
73-
],
74-
];
88+
];
89+
}
7590

7691
/**
7792
* @param string $data

src/CryptoHelper.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,20 @@ public static function getTempFilename($content = null)
101101

102102
/**
103103
* @param string|MimePart $data
104-
* @param array $caInfo Information about the trusted CA certificates to use in the verification process
104+
* @param array|null $caInfo Information about the trusted CA certificates to use in the verification process
105105
* @return bool
106106
*/
107107
public static function verify($data, $caInfo = [])
108108
{
109109
if ($data instanceof MimePart) {
110110
$data = self::getTempFilename((string) $data);
111111
}
112-
// TODO: implement
112+
// TODO: refactory
113+
// if (! is_array($caInfo)) {
114+
// $caInfo = [
115+
// self::getTempFilename($caInfo),
116+
// ];
117+
// }
113118
// return openssl_pkcs7_verify($data, PKCS7_BINARY | PKCS7_NOSIGS | PKCS7_NOVERIFY, null, $caInfo);
114119
return openssl_pkcs7_verify($data, PKCS7_BINARY | PKCS7_NOSIGS | PKCS7_NOVERIFY);
115120
}
@@ -193,8 +198,8 @@ public static function compress($data, $encoding = MimePart::ENCODING_BASE64)
193198
'contentType' => ASN1Helper::ENVELOPED_DATA_OID,
194199
'content' => gzcompress($content),
195200
],
196-
], ASN1Helper::COMPRESSED_DATA_MAP),
197-
], ASN1Helper::CONTENT_INFO_MAP);
201+
], ASN1Helper::getCompressedDataMap()),
202+
], ASN1Helper::getContentInfoMap());
198203

199204
if ($encoding == MimePart::ENCODING_BASE64) {
200205
$content = Utils::encodeBase64($content);
@@ -222,10 +227,10 @@ public static function decompress($data, $encoding = MimePart::ENCODING_BASE64)
222227
$data = base64_decode($data);
223228
}
224229

225-
$payload = ASN1Helper::decodeDER($data, ASN1Helper::CONTENT_INFO_MAP);
230+
$payload = ASN1Helper::decodeDER($data, ASN1Helper::getContentInfoMap());
226231

227232
if ($payload['contentType'] == ASN1Helper::COMPRESSED_DATA_OID) {
228-
$compressed = ASN1Helper::decodeDER($payload['content'], ASN1Helper::COMPRESSED_DATA_MAP);
233+
$compressed = ASN1Helper::decodeDER($payload['content'], ASN1Helper::getCompressedDataMap());
229234
if (empty($compressed['payload'])) {
230235
throw new \RuntimeException('Invalid compressed data.');
231236
}
@@ -234,5 +239,4 @@ public static function decompress($data, $encoding = MimePart::ENCODING_BASE64)
234239

235240
return MimePart::fromString($data);
236241
}
237-
238242
}

src/Utils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public static function generateMessageID($partner = null)
197197
* @param string $charList
198198
* @return string
199199
*/
200-
public static function random(int $length = 10, $charList = '0-9a-z')
200+
public static function random($length = 10, $charList = '0-9a-z')
201201
{
202202
$charList = count_chars(preg_replace_callback('#.-.#', function (array $m) {
203203
return implode('', range($m[0][0], $m[0][2]));
@@ -222,7 +222,7 @@ public static function random(int $length = 10, $charList = '0-9a-z')
222222
* @param string $s
223223
* @return bool
224224
*/
225-
public static function checkEncoding(string $s)
225+
public static function checkEncoding($s)
226226
{
227227
return $s === self::fixEncoding($s);
228228
}
@@ -233,7 +233,7 @@ public static function checkEncoding(string $s)
233233
* @param string $s
234234
* @return bool
235235
*/
236-
public static function fixEncoding(string $s)
236+
public static function fixEncoding($s)
237237
{
238238
// removes xD800-xDFFF, x110000 and higher
239239
return htmlspecialchars_decode(htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);

0 commit comments

Comments
 (0)