From dc7f7e4d859468ce2318fc1562738c4d887d9647 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 23 Jul 2016 11:01:43 -0500 Subject: [PATCH 1/2] ASN1: fix PHP Warning on PHP 7.1 --- phpseclib/File/ASN1.php | 2 +- tests/Unit/File/X509/CSRTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index 0d0e2fa8..b30493e4 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -563,7 +563,7 @@ class File_ASN1 switch (true) { case $mapping['type'] == FILE_ASN1_TYPE_ANY: $intype = $decoded['type']; - if (isset($decoded['constant']) || !isset($this->ANYmap[$intype]) || ($this->encoded[$decoded['start']] & 0x20)) { + if (isset($decoded['constant']) || !isset($this->ANYmap[$intype]) || (ord($this->encoded[$decoded['start']]) & 0x20)) { return new File_ASN1_Element(substr($this->encoded, $decoded['start'], $decoded['length'])); } $inmap = $this->ANYmap[$intype]; diff --git a/tests/Unit/File/X509/CSRTest.php b/tests/Unit/File/X509/CSRTest.php index 131237d5..8d63ecff 100644 --- a/tests/Unit/File/X509/CSRTest.php +++ b/tests/Unit/File/X509/CSRTest.php @@ -6,6 +6,7 @@ */ require_once 'File/X509.php'; +require_once 'Crypt/RSA.php'; class Unit_File_X509_CSRTest extends PhpseclibTestCase { @@ -93,4 +94,28 @@ draiRBZruwMPwPIP $this->assertInternalType('array', $csr); } + + // on PHP 7.1, with older versions of phpseclib, this would produce a "A non-numeric value encountered" warning + public function testNewCSR() + { + $rsa = new Crypt_RSA(); + $x509 = new File_X509(); + + $rsa->loadKey('-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp +wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5 +1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh +3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2 +pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX +GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il +AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF +L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k +X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl +U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ +37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0= +-----END RSA PRIVATE KEY-----'); + $x509->setPrivateKey($rsa); + $x509->setDN(array('cn' => 'ncgamers.org')); + $x509->saveCSR($x509->signCSR('sha256WithRSAEncryption'), FILE_X509_FORMAT_DER); + } } From 2c4dcd96b4a53f52aeaa4ece540019e148b53bf2 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 23 Jul 2016 18:39:25 -0500 Subject: [PATCH 2/2] fix issue with merge --- tests/Unit/File/X509/CSRTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/File/X509/CSRTest.php b/tests/Unit/File/X509/CSRTest.php index 85e43649..849b788e 100644 --- a/tests/Unit/File/X509/CSRTest.php +++ b/tests/Unit/File/X509/CSRTest.php @@ -116,6 +116,6 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ -----END RSA PRIVATE KEY-----'); $x509->setPrivateKey($rsa); $x509->setDN(array('cn' => 'ncgamers.org')); - $x509->saveCSR($x509->signCSR('sha256WithRSAEncryption'), FILE_X509_FORMAT_DER); + $x509->saveCSR($x509->signCSR('sha256WithRSAEncryption'), X509::FORMAT_DER); } }