mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 03:27:31 +00:00
ASN1: make methods static
This commit is contained in:
parent
df6d55fd97
commit
874ada8d93
@ -4,7 +4,6 @@ php:
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- hhvm
|
||||
|
||||
env:
|
||||
global:
|
||||
|
@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Common ASN1 Functions
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Common
|
||||
* @package Functions\ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2016 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Common\Functions;
|
||||
|
||||
/**
|
||||
* Common ASN1 Functions
|
||||
*
|
||||
* @package Functions\ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class ASN1
|
||||
{
|
||||
/**
|
||||
* DER-decode the length
|
||||
*
|
||||
* DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See
|
||||
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
|
||||
*
|
||||
* @access public
|
||||
* @param string $string
|
||||
* @return int
|
||||
*/
|
||||
static function decodeLength(&$string)
|
||||
{
|
||||
$length = ord(Strings::shift($string));
|
||||
if ($length & 0x80) { // definite length, long form
|
||||
$length&= 0x7F;
|
||||
$temp = Strings::shift($string, $length);
|
||||
list(, $length) = unpack('N', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4));
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* DER-encode the length
|
||||
*
|
||||
* DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See
|
||||
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
|
||||
*
|
||||
* @access public
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
static function encodeLength($length)
|
||||
{
|
||||
if ($length <= 0x7F) {
|
||||
return chr($length);
|
||||
}
|
||||
|
||||
$temp = ltrim(pack('N', $length), chr(0));
|
||||
return pack('Ca*', 0x80 | strlen($temp), $temp);
|
||||
}
|
||||
}
|
@ -37,51 +37,9 @@ use phpseclib\Crypt\Common\BlockCipher;
|
||||
use phpseclib\Crypt\Random;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\File\ASN1;
|
||||
use phpseclib\File\ASN1\Maps;
|
||||
use phpseclib\Exception\UnsupportedAlgorithmException;
|
||||
|
||||
// from https://tools.ietf.org/html/rfc2898
|
||||
define(__NAMESPACE__ . '\oids', [
|
||||
// PBES1 encryption schemes
|
||||
'1.2.840.113549.1.5.1' => 'pbeWithMD2AndDES-CBC',
|
||||
'1.2.840.113549.1.5.4' => 'pbeWithMD2AndRC2-CBC',
|
||||
'1.2.840.113549.1.5.3' => 'pbeWithMD5AndDES-CBC',
|
||||
'1.2.840.113549.1.5.6' => 'pbeWithMD5AndRC2-CBC',
|
||||
'1.2.840.113549.1.5.10'=> 'pbeWithSHA1AndDES-CBC',
|
||||
'1.2.840.113549.1.5.11'=> 'pbeWithSHA1AndRC2-CBC',
|
||||
|
||||
// from PKCS#12:
|
||||
// https://tools.ietf.org/html/rfc7292
|
||||
'1.2.840.113549.1.12.1.1' => 'pbeWithSHAAnd128BitRC4',
|
||||
'1.2.840.113549.1.12.1.2' => 'pbeWithSHAAnd40BitRC4',
|
||||
'1.2.840.113549.1.12.1.3' => 'pbeWithSHAAnd3-KeyTripleDES-CBC',
|
||||
'1.2.840.113549.1.12.1.4' => 'pbeWithSHAAnd2-KeyTripleDES-CBC',
|
||||
'1.2.840.113549.1.12.1.5' => 'pbeWithSHAAnd128BitRC2-CBC',
|
||||
'1.2.840.113549.1.12.1.6' => 'pbeWithSHAAnd40BitRC2-CBC',
|
||||
|
||||
'1.2.840.113549.1.5.12' => 'id-PBKDF2',
|
||||
'1.2.840.113549.1.5.13' => 'id-PBES2',
|
||||
'1.2.840.113549.1.5.14' => 'id-PBMAC1',
|
||||
|
||||
// from PKCS#5 v2.1:
|
||||
// http://www.rsa.com/rsalabs/pkcs/files/h11302-wp-pkcs5v2-1-password-based-cryptography-standard.pdf
|
||||
'1.2.840.113549.2.7' => 'id-hmacWithSHA1',
|
||||
'1.2.840.113549.2.8' => 'id-hmacWithSHA224',
|
||||
'1.2.840.113549.2.9' => 'id-hmacWithSHA256',
|
||||
'1.2.840.113549.2.10'=> 'id-hmacWithSHA384',
|
||||
'1.2.840.113549.2.11'=> 'id-hmacWithSHA512',
|
||||
'1.2.840.113549.2.12'=> 'id-hmacWithSHA512-224',
|
||||
'1.2.840.113549.2.13'=> 'id-hmacWithSHA512-256',
|
||||
|
||||
'1.3.14.3.2.7' => 'desCBC',
|
||||
'1.2.840.113549.3.7' => 'des-EDE3-CBC',
|
||||
'1.2.840.113549.3.2' => 'rc2CBC',
|
||||
'1.2.840.113549.3.9' => 'rc5-CBC-PAD',
|
||||
|
||||
'2.16.840.1.101.3.4.1.2' => 'aes128-CBC-PAD',
|
||||
'2.16.840.1.101.3.4.1.22'=> 'aes192-CBC-PAD',
|
||||
'2.16.840.1.101.3.4.1.42'=> 'aes256-CBC-PAD'
|
||||
]);
|
||||
|
||||
/**
|
||||
* PKCS#8 Formatted Key Handler
|
||||
*
|
||||
@ -127,6 +85,14 @@ class PKCS8 extends PKCS
|
||||
*/
|
||||
static $defaultIterationCount = 2048;
|
||||
|
||||
/**
|
||||
* OIDs loaded
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
static $oidsLoaded = false;
|
||||
|
||||
/**
|
||||
* Sets the default encryption algorithm
|
||||
*
|
||||
@ -291,6 +257,59 @@ class PKCS8 extends PKCS
|
||||
return $cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize static variables
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
static function _initialize_static_variables()
|
||||
{
|
||||
if (!self::$oidsLoaded) {
|
||||
// from https://tools.ietf.org/html/rfc2898
|
||||
ASN1::loadOIDs([
|
||||
// PBES1 encryption schemes
|
||||
'1.2.840.113549.1.5.1' => 'pbeWithMD2AndDES-CBC',
|
||||
'1.2.840.113549.1.5.4' => 'pbeWithMD2AndRC2-CBC',
|
||||
'1.2.840.113549.1.5.3' => 'pbeWithMD5AndDES-CBC',
|
||||
'1.2.840.113549.1.5.6' => 'pbeWithMD5AndRC2-CBC',
|
||||
'1.2.840.113549.1.5.10'=> 'pbeWithSHA1AndDES-CBC',
|
||||
'1.2.840.113549.1.5.11'=> 'pbeWithSHA1AndRC2-CBC',
|
||||
|
||||
// from PKCS#12:
|
||||
// https://tools.ietf.org/html/rfc7292
|
||||
'1.2.840.113549.1.12.1.1' => 'pbeWithSHAAnd128BitRC4',
|
||||
'1.2.840.113549.1.12.1.2' => 'pbeWithSHAAnd40BitRC4',
|
||||
'1.2.840.113549.1.12.1.3' => 'pbeWithSHAAnd3-KeyTripleDES-CBC',
|
||||
'1.2.840.113549.1.12.1.4' => 'pbeWithSHAAnd2-KeyTripleDES-CBC',
|
||||
'1.2.840.113549.1.12.1.5' => 'pbeWithSHAAnd128BitRC2-CBC',
|
||||
'1.2.840.113549.1.12.1.6' => 'pbeWithSHAAnd40BitRC2-CBC',
|
||||
|
||||
'1.2.840.113549.1.5.12' => 'id-PBKDF2',
|
||||
'1.2.840.113549.1.5.13' => 'id-PBES2',
|
||||
'1.2.840.113549.1.5.14' => 'id-PBMAC1',
|
||||
|
||||
// from PKCS#5 v2.1:
|
||||
// http://www.rsa.com/rsalabs/pkcs/files/h11302-wp-pkcs5v2-1-password-based-cryptography-standard.pdf
|
||||
'1.2.840.113549.2.7' => 'id-hmacWithSHA1',
|
||||
'1.2.840.113549.2.8' => 'id-hmacWithSHA224',
|
||||
'1.2.840.113549.2.9' => 'id-hmacWithSHA256',
|
||||
'1.2.840.113549.2.10'=> 'id-hmacWithSHA384',
|
||||
'1.2.840.113549.2.11'=> 'id-hmacWithSHA512',
|
||||
'1.2.840.113549.2.12'=> 'id-hmacWithSHA512-224',
|
||||
'1.2.840.113549.2.13'=> 'id-hmacWithSHA512-256',
|
||||
|
||||
'1.3.14.3.2.7' => 'desCBC',
|
||||
'1.2.840.113549.3.7' => 'des-EDE3-CBC',
|
||||
'1.2.840.113549.3.2' => 'rc2CBC',
|
||||
'1.2.840.113549.3.9' => 'rc5-CBC-PAD',
|
||||
|
||||
'2.16.840.1.101.3.4.1.2' => 'aes128-CBC-PAD',
|
||||
'2.16.840.1.101.3.4.1.22'=> 'aes192-CBC-PAD',
|
||||
'2.16.840.1.101.3.4.1.42'=> 'aes256-CBC-PAD'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
*
|
||||
@ -301,6 +320,8 @@ class PKCS8 extends PKCS
|
||||
*/
|
||||
static function load($key, $password = '')
|
||||
{
|
||||
self::_initialize_static_variables();
|
||||
|
||||
if (!is_string($key)) {
|
||||
return false;
|
||||
}
|
||||
@ -314,16 +335,14 @@ class PKCS8 extends PKCS
|
||||
}
|
||||
}
|
||||
|
||||
$asn1 = new ASN1();
|
||||
$decoded = $asn1->decodeBER($key);
|
||||
$decoded = ASN1::decodeBER($key);
|
||||
if (empty($decoded)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$meta = [];
|
||||
|
||||
$asn1->loadOIDs(oids);
|
||||
$decrypted = $asn1->asn1map($decoded[0], ASN1\EncryptedPrivateKeyInfo::MAP);
|
||||
$decrypted = ASN1::asn1map($decoded[0], Maps\EncryptedPrivateKeyInfo::MAP);
|
||||
if (strlen($password) && is_array($decrypted)) {
|
||||
$algorithm = $decrypted['encryptionAlgorithm']['algorithm'];
|
||||
switch ($algorithm) {
|
||||
@ -346,12 +365,12 @@ class PKCS8 extends PKCS
|
||||
|
||||
$meta['meta']['algorithm'] = $algorithm;
|
||||
|
||||
$temp = $asn1->decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
extract($asn1->asn1map($temp[0], ASN1\PBEParameter::MAP));
|
||||
$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
extract(ASN1::asn1map($temp[0], Maps\PBEParameter::MAP));
|
||||
$iterationCount = (int) $iterationCount->toString();
|
||||
$cipher->setPassword($password, $kdf, $hash, Base64::decode($salt), $iterationCount);
|
||||
$key = $cipher->decrypt(Base64::decode($decrypted['encryptedData']));
|
||||
$decoded = $asn1->decodeBER($key);
|
||||
$decoded = ASN1::decodeBER($key);
|
||||
if (empty($decoded)) {
|
||||
return false;
|
||||
}
|
||||
@ -360,22 +379,22 @@ class PKCS8 extends PKCS
|
||||
case 'id-PBES2':
|
||||
$meta['meta']['algorithm'] = $algorithm;
|
||||
|
||||
$temp = $asn1->decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
$temp = $asn1->asn1map($temp[0], ASN1\PBES2params::MAP);
|
||||
$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
$temp = ASN1::asn1map($temp[0], Maps\PBES2params::MAP);
|
||||
extract($temp);
|
||||
|
||||
$cipher = self::getPBES2EncryptionObject($encryptionScheme['algorithm']);
|
||||
$meta['meta']['cipher'] = $encryptionScheme['algorithm'];
|
||||
|
||||
$temp = $asn1->decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
$temp = $asn1->asn1map($temp[0], ASN1\PBES2params::MAP);
|
||||
$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
$temp = ASN1::asn1map($temp[0], Maps\PBES2params::MAP);
|
||||
extract($temp);
|
||||
|
||||
if (!$cipher instanceof RC2) {
|
||||
$cipher->setIV(Base64::decode($encryptionScheme['parameters']['octetString']));
|
||||
} else {
|
||||
$temp = $asn1->decodeBER($encryptionScheme['parameters']);
|
||||
extract($asn1->asn1map($temp[0], ASN1\RC2CBCParameter::MAP));
|
||||
$temp = ASN1::decodeBER($encryptionScheme['parameters']);
|
||||
extract(ASN1::asn1map($temp[0], Maps\RC2CBCParameter::MAP));
|
||||
$effectiveKeyLength = (int) $rc2ParametersVersion->toString();
|
||||
switch ($effectiveKeyLength) {
|
||||
case 160:
|
||||
@ -396,9 +415,9 @@ class PKCS8 extends PKCS
|
||||
$meta['meta']['keyDerivationFunc'] = $keyDerivationFunc['algorithm'];
|
||||
switch ($keyDerivationFunc['algorithm']) {
|
||||
case 'id-PBKDF2':
|
||||
$temp = $asn1->decodeBER($keyDerivationFunc['parameters']);
|
||||
$temp = ASN1::decodeBER($keyDerivationFunc['parameters']);
|
||||
$prf = ['algorithm' => 'id-hmacWithSHA1'];
|
||||
$params = $asn1->asn1map($temp[0], ASN1\PBKDF2params::MAP);
|
||||
$params = ASN1::asn1map($temp[0], Maps\PBKDF2params::MAP);
|
||||
extract($params);
|
||||
$meta['meta']['prf'] = $prf['algorithm'];
|
||||
$hash = str_replace('-', '/', substr($prf['algorithm'], 11));
|
||||
@ -414,7 +433,7 @@ class PKCS8 extends PKCS
|
||||
}
|
||||
call_user_func_array([$cipher, 'setPassword'], $params);
|
||||
$key = $cipher->decrypt(Base64::decode($decrypted['encryptedData']));
|
||||
$decoded = $asn1->decodeBER($key);
|
||||
$decoded = ASN1::decodeBER($key);
|
||||
if (empty($decoded)) {
|
||||
return false;
|
||||
}
|
||||
@ -424,15 +443,15 @@ class PKCS8 extends PKCS
|
||||
}
|
||||
break;
|
||||
case 'id-PBMAC1':
|
||||
//$temp = $asn1->decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
//$value = $asn1->asn1map($temp[0], ASN1\PBMAC1params::MAP);
|
||||
//$temp = ASN1::decodeBER($decrypted['encryptionAlgorithm']['parameters']);
|
||||
//$value = ASN1::asn1map($temp[0], Maps\PBMAC1params::MAP);
|
||||
// since i can't find any implementation that does PBMAC1 it is unsupported
|
||||
throw new UnsupportedAlgorithmException('Only PBES1 and PBES2 PKCS#8 keys are supported.');
|
||||
// at this point we'll assume that the key conforms to PublicKeyInfo
|
||||
}
|
||||
}
|
||||
|
||||
$private = $asn1->asn1map($decoded[0], ASN1\PrivateKeyInfo::MAP);
|
||||
$private = ASN1::asn1map($decoded[0], Maps\PrivateKeyInfo::MAP);
|
||||
if (is_array($private)) {
|
||||
return $private + $meta;
|
||||
}
|
||||
@ -441,7 +460,7 @@ class PKCS8 extends PKCS
|
||||
// is that the former has an octet string and the later has a bit string. the first byte of a bit
|
||||
// string represents the number of bits in the last byte that are to be ignored but, currently,
|
||||
// bit strings wanting a non-zero amount of bits trimmed are not supported
|
||||
$public = $asn1->asn1map($decoded[0], ASN1\PublicKeyInfo::MAP);
|
||||
$public = ASN1::asn1map($decoded[0], Maps\PublicKeyInfo::MAP);
|
||||
if (is_array($public)) {
|
||||
$public['publicKey'] = base64_decode($public['publicKey']);
|
||||
if ($public['publicKey'][0] != "\0") {
|
||||
@ -466,8 +485,7 @@ class PKCS8 extends PKCS
|
||||
*/
|
||||
static function wrapPrivateKey($key, $algorithm, $attr, $password)
|
||||
{
|
||||
$asn1 = new ASN1();
|
||||
$asn1->loadOIDs(oids);
|
||||
self::_initialize_static_variables();
|
||||
|
||||
$key = [
|
||||
'version' => 'v1',
|
||||
@ -477,7 +495,7 @@ class PKCS8 extends PKCS
|
||||
if (!empty($attr)) {
|
||||
$key['attributes'] = $attr;
|
||||
}
|
||||
$key = $asn1->encodeDER($key, ASN1\PrivateKeyInfo::MAP);
|
||||
$key = ASN1::encodeDER($key, Maps\PrivateKeyInfo::MAP);
|
||||
if (!empty($password) && is_string($password)) {
|
||||
$salt = Random::string(8);
|
||||
$iterationCount = self::$defaultIterationCount;
|
||||
@ -493,7 +511,7 @@ class PKCS8 extends PKCS
|
||||
'iterationCount' => $iterationCount,
|
||||
'prf' => ['algorithm' => self::$defaultPRF, 'parameters' => null]
|
||||
];
|
||||
$PBKDF2params = $asn1->encodeDER($PBKDF2params, ASN1\PBKDF2params::MAP);
|
||||
$PBKDF2params = ASN1::encodeDER($PBKDF2params, Maps\PBKDF2params::MAP);
|
||||
|
||||
if (!$crypto instanceof RC2) {
|
||||
$params = ['octetString' => Base64::encode($iv)];
|
||||
@ -502,7 +520,7 @@ class PKCS8 extends PKCS
|
||||
'rc2ParametersVersion' => 58,
|
||||
'iv' => Base64::encode($iv)
|
||||
];
|
||||
$params = $asn1->encodeDER($params, ASN1\RC2CBCParameter::MAP);
|
||||
$params = ASN1::encodeDER($params, Maps\RC2CBCParameter::MAP);
|
||||
$params = new ASN1\Element($params);
|
||||
}
|
||||
|
||||
@ -516,7 +534,7 @@ class PKCS8 extends PKCS
|
||||
'parameters' => $params
|
||||
]
|
||||
];
|
||||
$params = $asn1->encodeDER($params, ASN1\PBES2params::MAP);
|
||||
$params = ASN1::encodeDER($params, Maps\PBES2params::MAP);
|
||||
|
||||
$crypto->setIV($iv);
|
||||
} else {
|
||||
@ -528,7 +546,7 @@ class PKCS8 extends PKCS
|
||||
'salt' => Base64::encode($salt),
|
||||
'iterationCount' => $iterationCount
|
||||
];
|
||||
$params = $asn1->encodeDER($params, ASN1\PBEParameter::MAP);
|
||||
$params = ASN1::encodeDER($params, Maps\PBEParameter::MAP);
|
||||
}
|
||||
$crypto->setPassword($password, $kdf, $hash, $salt, $iterationCount);
|
||||
$key = $crypto->encrypt($key);
|
||||
@ -541,7 +559,7 @@ class PKCS8 extends PKCS
|
||||
'encryptedData' => Base64::encode($key)
|
||||
];
|
||||
|
||||
$key = $asn1->encodeDER($key, ASN1\EncryptedPrivateKeyInfo::MAP);
|
||||
$key = ASN1::encodeDER($key, Maps\EncryptedPrivateKeyInfo::MAP);
|
||||
|
||||
return "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
@ -562,7 +580,7 @@ class PKCS8 extends PKCS
|
||||
*/
|
||||
static function wrapPublicKey($key, $algorithm)
|
||||
{
|
||||
$asn1 = new ASN1();
|
||||
self::_initialize_static_variables();
|
||||
|
||||
$key = [
|
||||
'publicKeyAlgorithm' => [
|
||||
@ -572,7 +590,7 @@ class PKCS8 extends PKCS
|
||||
'publicKey' => Base64::encode("\0" . $key)
|
||||
];
|
||||
|
||||
$key = $asn1->encodeDER($key, ASN1\PublicKeyInfo::MAP);
|
||||
$key = ASN1::encodeDER($key, Maps\PublicKeyInfo::MAP);
|
||||
|
||||
return "-----BEGIN PUBLIC KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
|
@ -49,6 +49,7 @@ use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib\File\ASN1;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\File\ASN1\Maps\DigestInfo;
|
||||
|
||||
/**
|
||||
* Pure-PHP PKCS#1 compliant implementation of RSA.
|
||||
@ -2012,48 +2013,30 @@ class RSA
|
||||
return false;
|
||||
}
|
||||
|
||||
$asn1 = new ASN1();
|
||||
$decoded = $asn1->decodeBER($em);
|
||||
$decoded = ASN1::decodeBER($em);
|
||||
if (!is_array($decoded) || empty($decoded[0]) || strlen($em) > $decoded[0]['length']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$AlgorithmIdentifier = array(
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'algorithm' => array('type' => ASN1::TYPE_OBJECT_IDENTIFIER),
|
||||
'parameters' => array(
|
||||
'type' => ASN1::TYPE_ANY,
|
||||
'optional' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
static $oids;
|
||||
if (!isset($oids)) {
|
||||
$oids = [
|
||||
'1.2.840.113549.2.2' => 'md2',
|
||||
'1.2.840.113549.2.4' => 'md4', // from PKCS1 v1.5
|
||||
'1.2.840.113549.2.5' => 'md5',
|
||||
'1.3.14.3.2.26' => 'id-sha1',
|
||||
'2.16.840.1.101.3.4.2.1' => 'id-sha256',
|
||||
'2.16.840.1.101.3.4.2.2' => 'id-sha384',
|
||||
'2.16.840.1.101.3.4.2.3' => 'id-sha512',
|
||||
// from PKCS1 v2.2
|
||||
'2.16.840.1.101.3.4.2.4' => 'id-sha224',
|
||||
'2.16.840.1.101.3.4.2.5' => 'id-sha512/224',
|
||||
'2.16.840.1.101.3.4.2.6' => 'id-sha512/256',
|
||||
];
|
||||
ASN1::loadOIDs($oids);
|
||||
}
|
||||
|
||||
$DigestInfo = array(
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'digestAlgorithm' => $AlgorithmIdentifier,
|
||||
'digest' => array('type' => ASN1::TYPE_OCTET_STRING)
|
||||
)
|
||||
);
|
||||
|
||||
$oids = array(
|
||||
'1.2.840.113549.2.2' => 'md2',
|
||||
'1.2.840.113549.2.4' => 'md4', // from PKCS1 v1.5
|
||||
'1.2.840.113549.2.5' => 'md5',
|
||||
'1.3.14.3.2.26' => 'sha1',
|
||||
'2.16.840.1.101.3.4.2.1' => 'sha256',
|
||||
'2.16.840.1.101.3.4.2.2' => 'sha384',
|
||||
'2.16.840.1.101.3.4.2.3' => 'sha512',
|
||||
// from PKCS1 v2.2
|
||||
'2.16.840.1.101.3.4.2.4' => 'sha224',
|
||||
'2.16.840.1.101.3.4.2.5' => 'sha512/224',
|
||||
'2.16.840.1.101.3.4.2.6' => 'sha512/256',
|
||||
);
|
||||
|
||||
$asn1->loadOIDs($oids);
|
||||
|
||||
$decoded = $asn1->asn1map($decoded[0], $DigestInfo);
|
||||
$decoded = ASN1::asn1map($decoded[0], DigestInfo::MAP);
|
||||
if (!isset($decoded) || $decoded === false) {
|
||||
return false;
|
||||
}
|
||||
@ -2062,7 +2045,11 @@ class RSA
|
||||
return false;
|
||||
}
|
||||
|
||||
$hash = new Hash($decoded['digestAlgorithm']['algorithm']);
|
||||
$hash = $decoded['digestAlgorithm']['algorithm'];
|
||||
$hash = substr($hash, 0, 3) == 'id-' ?
|
||||
substr($hash, 3) :
|
||||
$hash;
|
||||
$hash = new Hash($hash);
|
||||
$em = $hash->hash($m);
|
||||
$em2 = Base64::decode($decoded['digest']);
|
||||
|
||||
|
@ -27,6 +27,7 @@ namespace phpseclib\Crypt\RSA;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\Common\PKCS1 as Progenitor;
|
||||
use phpseclib\File\ASN1;
|
||||
use phpseclib\File\ASN1\Maps;
|
||||
|
||||
/**
|
||||
* PKCS#1 Formatted RSA Key Handler
|
||||
@ -58,13 +59,12 @@ class PKCS1 extends Progenitor
|
||||
return false;
|
||||
}
|
||||
|
||||
$asn1 = new ASN1();
|
||||
$decoded = $asn1->decodeBER($key);
|
||||
$decoded = ASN1::decodeBER($key);
|
||||
if (empty($decoded)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$key = $asn1->asn1map($decoded[0], ASN1\RSAPrivateKey::MAP);
|
||||
$key = ASN1::asn1map($decoded[0], Maps\RSAPrivateKey::MAP);
|
||||
if (is_array($key)) {
|
||||
$components+= [
|
||||
'modulus' => $key['modulus'],
|
||||
@ -84,7 +84,7 @@ class PKCS1 extends Progenitor
|
||||
return $components;
|
||||
}
|
||||
|
||||
$key = $asn1->asn1map($decoded[0], ASN1\RSAPublicKey::MAP);
|
||||
$key = ASN1::asn1map($decoded[0], Maps\RSAPublicKey::MAP);
|
||||
|
||||
return is_array($key) ? $components + $key : false;
|
||||
}
|
||||
@ -124,8 +124,7 @@ class PKCS1 extends Progenitor
|
||||
];
|
||||
}
|
||||
|
||||
$asn1 = new ASN1();
|
||||
$key = $asn1->encodeDER($key, ASN1\RSAPrivateKey::MAP);
|
||||
$key = ASN1::encodeDER($key, Maps\RSAPrivateKey::MAP);
|
||||
|
||||
return self::wrapPrivateKey($key, 'RSA', $password);
|
||||
}
|
||||
@ -145,8 +144,7 @@ class PKCS1 extends Progenitor
|
||||
'publicExponent' => $e
|
||||
];
|
||||
|
||||
$asn1 = new ASN1();
|
||||
$key = $asn1->encodeDER($key, ASN1\RSAPublicKey::MAP);
|
||||
$key = ASN1::encodeDER($key, Maps\RSAPublicKey::MAP);
|
||||
|
||||
return self::wrapPublicKey($key, 'RSA');
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ namespace phpseclib\File;
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib\File\ASN1\Element;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Common\Functions\ASN1 as Functions;
|
||||
|
||||
/**
|
||||
* Pure-PHP ASN.1 Parser
|
||||
@ -104,13 +103,21 @@ class ASN1
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* ASN.1 object identifier
|
||||
* ASN.1 object identifiers
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
* @link http://en.wikipedia.org/wiki/Object_identifier
|
||||
*/
|
||||
var $oids = array();
|
||||
static $oids = [];
|
||||
|
||||
/**
|
||||
* ASN.1 object identifier reverse mapping
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
static $reverseOIDs = [];
|
||||
|
||||
/**
|
||||
* Default date format
|
||||
@ -119,18 +126,7 @@ class ASN1
|
||||
* @access private
|
||||
* @link http://php.net/class.datetime
|
||||
*/
|
||||
var $format = 'D, d M Y H:i:s O';
|
||||
|
||||
/**
|
||||
* Default date format
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
* @see self::setTimeFormat()
|
||||
* @see self::asn1map()
|
||||
* @link http://php.net/class.datetime
|
||||
*/
|
||||
var $encoded;
|
||||
static $format = 'D, d M Y H:i:s O';
|
||||
|
||||
/**
|
||||
* Filters
|
||||
@ -141,7 +137,29 @@ class ASN1
|
||||
* @access private
|
||||
* @see self::_encode_der()
|
||||
*/
|
||||
var $filters;
|
||||
static $filters;
|
||||
|
||||
/**
|
||||
* Current Location of most recent ASN.1 encode process
|
||||
*
|
||||
* Useful for debug purposes
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
* @see self::_encode_der()
|
||||
*/
|
||||
static $location;
|
||||
|
||||
/**
|
||||
* DER Encoded String
|
||||
*
|
||||
* In case we need to create ASN1\Element object's..
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
* @see self::decodeDER()
|
||||
*/
|
||||
static $encoded;
|
||||
|
||||
/**
|
||||
* Type mapping table for the ANY type.
|
||||
@ -153,7 +171,7 @@ class ASN1
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $ANYmap = array(
|
||||
const ANY_MAP = [
|
||||
self::TYPE_BOOLEAN => true,
|
||||
self::TYPE_INTEGER => true,
|
||||
self::TYPE_BIT_STRING => 'bitString',
|
||||
@ -176,7 +194,7 @@ class ASN1
|
||||
self::TYPE_UNIVERSAL_STRING => 'universalString',
|
||||
//self::TYPE_CHARACTER_STRING => 'characterString',
|
||||
self::TYPE_BMP_STRING => 'bmpString'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* String type to character size mapping table.
|
||||
@ -187,7 +205,7 @@ class ASN1
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $stringTypeSize = array(
|
||||
const STRING_TYPE_SIZE = [
|
||||
self::TYPE_UTF8_STRING => 0,
|
||||
self::TYPE_BMP_STRING => 2,
|
||||
self::TYPE_UNIVERSAL_STRING => 4,
|
||||
@ -195,7 +213,7 @@ class ASN1
|
||||
self::TYPE_TELETEX_STRING => 1,
|
||||
self::TYPE_IA5_STRING => 1,
|
||||
self::TYPE_VISIBLE_STRING => 1,
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Parse BER-encoding
|
||||
@ -206,15 +224,40 @@ class ASN1
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function decodeBER($encoded)
|
||||
static function decodeBER($encoded)
|
||||
{
|
||||
if ($encoded instanceof Element) {
|
||||
$encoded = $encoded->element;
|
||||
}
|
||||
|
||||
$this->encoded = $encoded;
|
||||
self::$encoded = $encoded;
|
||||
|
||||
$decoded = [self::_decode_ber($encoded)];
|
||||
|
||||
//self::_addEncodings($decoded[0], $encoded);
|
||||
|
||||
// encapsulate in an array for BC with the old decodeBER
|
||||
return array($this->_decode_ber($encoded));
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add encoded DER substrings to decoded array
|
||||
*
|
||||
* @param array $decoded
|
||||
* @param string $encoded
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _addEncodings(&$decoded, $encoded)
|
||||
{
|
||||
$decoded['encoded'] = substr($encoded, $decoded['start'], $decoded['length']);
|
||||
if (!is_array($decoded['content'])) {
|
||||
return $decoded;
|
||||
}
|
||||
for ($i = 0; $i < count($decoded['content']); $i++) {
|
||||
self::addEncodings($decoded['content'][$i], $encoded);
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,9 +273,9 @@ class ASN1
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
function _decode_ber($encoded, $start = 0, $encoded_pos = 0)
|
||||
static function _decode_ber($encoded, $start = 0, $encoded_pos = 0)
|
||||
{
|
||||
$current = array('start' => $start);
|
||||
$current = ['start' => $start];
|
||||
|
||||
$type = ord($encoded[$encoded_pos++]);
|
||||
$start++;
|
||||
@ -265,11 +308,11 @@ class ASN1
|
||||
$temp = substr($encoded, $encoded_pos, $length);
|
||||
$encoded_pos += $length;
|
||||
// tags of indefinte length don't really have a header length; this length includes the tag
|
||||
$current+= array('headerlength' => $length + 2);
|
||||
$current+= ['headerlength' => $length + 2];
|
||||
$start+= $length;
|
||||
extract(unpack('Nlength', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4)));
|
||||
} else {
|
||||
$current+= array('headerlength' => 2);
|
||||
$current+= ['headerlength' => 2];
|
||||
}
|
||||
|
||||
if ($length > (strlen($encoded) - $encoded_pos)) {
|
||||
@ -296,18 +339,18 @@ class ASN1
|
||||
case self::CLASS_PRIVATE:
|
||||
case self::CLASS_CONTEXT_SPECIFIC:
|
||||
if (!$constructed) {
|
||||
return array(
|
||||
return [
|
||||
'type' => $class,
|
||||
'constant' => $tag,
|
||||
'content' => $content,
|
||||
'length' => $length + $start - $current['start']
|
||||
);
|
||||
] + $current;
|
||||
}
|
||||
|
||||
$newcontent = array();
|
||||
$newcontent = [];
|
||||
$remainingLength = $length;
|
||||
while ($remainingLength > 0) {
|
||||
$temp = $this->_decode_ber($content, $start, $content_pos);
|
||||
$temp = self::_decode_ber($content, $start, $content_pos);
|
||||
$length = $temp['length'];
|
||||
// end-of-content octets - see paragraph 8.1.5
|
||||
if (substr($content, $content_pos + $length, 2) == "\0\0") {
|
||||
@ -322,7 +365,7 @@ class ASN1
|
||||
$content_pos += $length;
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'type' => $class,
|
||||
'constant' => $tag,
|
||||
// the array encapsulation is for BC with the old format
|
||||
@ -331,10 +374,10 @@ class ASN1
|
||||
// the absence of $content['headerlength'] is how we know if something is indefinite or not.
|
||||
// technically, it could be defined to be 2 and then another indicator could be used but whatever.
|
||||
'length' => $start - $current['start']
|
||||
) + $current;
|
||||
] + $current;
|
||||
}
|
||||
|
||||
$current+= array('type' => $tag);
|
||||
$current+= ['type' => $tag];
|
||||
|
||||
// decode UNIVERSAL tags
|
||||
switch ($tag) {
|
||||
@ -358,7 +401,7 @@ class ASN1
|
||||
if (!$constructed) {
|
||||
$current['content'] = substr($content, $content_pos);
|
||||
} else {
|
||||
$temp = $this->_decode_ber($content, $start, $content_pos);
|
||||
$temp = self::_decode_ber($content, $start, $content_pos);
|
||||
$length-= (strlen($content) - $content_pos);
|
||||
$last = count($temp) - 1;
|
||||
for ($i = 0; $i < $last; $i++) {
|
||||
@ -382,7 +425,7 @@ class ASN1
|
||||
$current['content'] = '';
|
||||
$length = 0;
|
||||
while (substr($content, $content_pos, 2) != "\0\0") {
|
||||
$temp = $this->_decode_ber($content, $length + $start, $content_pos);
|
||||
$temp = self::_decode_ber($content, $length + $start, $content_pos);
|
||||
$content_pos += $temp['length'];
|
||||
// all subtags should be octet strings
|
||||
//if ($temp['type'] != self::TYPE_OCTET_STRING) {
|
||||
@ -405,7 +448,7 @@ class ASN1
|
||||
case self::TYPE_SEQUENCE:
|
||||
case self::TYPE_SET:
|
||||
$offset = 0;
|
||||
$current['content'] = array();
|
||||
$current['content'] = [];
|
||||
$content_len = strlen($content);
|
||||
while ($content_pos < $content_len) {
|
||||
// if indefinite length construction was used and we have an end-of-content string next
|
||||
@ -414,7 +457,7 @@ class ASN1
|
||||
$length = $offset + 2; // +2 for the EOC
|
||||
break 2;
|
||||
}
|
||||
$temp = $this->_decode_ber($content, $start + $offset, $content_pos);
|
||||
$temp = self::_decode_ber($content, $start + $offset, $content_pos);
|
||||
$content_pos += $temp['length'];
|
||||
$current['content'][] = $temp;
|
||||
$offset+= $temp['length'];
|
||||
@ -472,14 +515,14 @@ class ASN1
|
||||
break;
|
||||
case self::TYPE_UTC_TIME:
|
||||
case self::TYPE_GENERALIZED_TIME:
|
||||
$current['content'] = $this->_decodeTime(substr($content, $content_pos), $tag);
|
||||
$current['content'] = self::_decodeTime(substr($content, $content_pos), $tag);
|
||||
default:
|
||||
}
|
||||
|
||||
$start+= $length;
|
||||
|
||||
// ie. length is the length of the full TLV encoding - it's not just the length of the value
|
||||
return $current + array('length' => $start - $current['start']);
|
||||
return $current + ['length' => $start - $current['start']];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -495,7 +538,7 @@ class ASN1
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function asn1map($decoded, $mapping, $special = array())
|
||||
static function asn1map($decoded, $mapping, $special = [])
|
||||
{
|
||||
if (isset($mapping['explicit']) && is_array($decoded['content'])) {
|
||||
$decoded = $decoded['content'][0];
|
||||
@ -504,12 +547,15 @@ class ASN1
|
||||
switch (true) {
|
||||
case $mapping['type'] == self::TYPE_ANY:
|
||||
$intype = $decoded['type'];
|
||||
if (isset($decoded['constant']) || !isset($this->ANYmap[$intype]) || (ord($this->encoded[$decoded['start']]) & 0x20)) {
|
||||
return new Element(substr($this->encoded, $decoded['start'], $decoded['length']));
|
||||
// !isset(self::ANY_MAP[$intype]) produces a fatal error on PHP 5.6
|
||||
//if (isset($decoded['constant']) || !isset(self::ANY_MAP[$intype]) || (ord($decoded['encoded'][0]) & 0x20)) {
|
||||
if (isset($decoded['constant']) || !array_key_exists($intype, self::ANY_MAP) || (ord(self::$encoded[$decoded['start']]) & 0x20)) {
|
||||
//return new Element($decoded['encoded']);
|
||||
return new Element(substr(self::$encoded, $decoded['start'], $decoded['length']));
|
||||
}
|
||||
$inmap = $this->ANYmap[$intype];
|
||||
$inmap = self::ANY_MAP[$intype];
|
||||
if (is_string($inmap)) {
|
||||
return array($inmap => $this->asn1map($decoded, array('type' => $intype) + $mapping, $special));
|
||||
return [$inmap => self::asn1map($decoded, ['type' => $intype] + $mapping, $special)];
|
||||
}
|
||||
break;
|
||||
case $mapping['type'] == self::TYPE_CHOICE:
|
||||
@ -517,10 +563,10 @@ class ASN1
|
||||
switch (true) {
|
||||
case isset($option['constant']) && $option['constant'] == $decoded['constant']:
|
||||
case !isset($option['constant']) && $option['type'] == $decoded['type']:
|
||||
$value = $this->asn1map($decoded, $option, $special);
|
||||
$value = self::asn1map($decoded, $option, $special);
|
||||
break;
|
||||
case !isset($option['constant']) && $option['type'] == self::TYPE_CHOICE:
|
||||
$v = $this->asn1map($decoded, $option, $special);
|
||||
$v = self::asn1map($decoded, $option, $special);
|
||||
if (isset($v)) {
|
||||
$value = $v;
|
||||
}
|
||||
@ -529,7 +575,7 @@ class ASN1
|
||||
if (isset($special[$key])) {
|
||||
$value = call_user_func($special[$key], $value);
|
||||
}
|
||||
return array($key => $value);
|
||||
return [$key => $value];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -555,13 +601,13 @@ class ASN1
|
||||
|
||||
switch ($decoded['type']) {
|
||||
case self::TYPE_SEQUENCE:
|
||||
$map = array();
|
||||
$map = [];
|
||||
|
||||
// ignore the min and max
|
||||
if (isset($mapping['min']) && isset($mapping['max'])) {
|
||||
$child = $mapping['children'];
|
||||
foreach ($decoded['content'] as $content) {
|
||||
if (($map[] = $this->asn1map($content, $child, $special)) === null) {
|
||||
if (($map[] = self::asn1map($content, $child, $special)) === null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -597,14 +643,14 @@ class ASN1
|
||||
$maymatch = $constant == $temp['constant'] && $childClass == $tempClass;
|
||||
} else {
|
||||
// Can only match if no constant expected and type matches or is generic.
|
||||
$maymatch = !isset($child['constant']) && array_search($child['type'], array($temp['type'], self::TYPE_ANY, self::TYPE_CHOICE)) !== false;
|
||||
$maymatch = !isset($child['constant']) && array_search($child['type'], [$temp['type'], self::TYPE_ANY, self::TYPE_CHOICE]) !== false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($maymatch) {
|
||||
// Attempt submapping.
|
||||
$candidate = $this->asn1map($temp, $child, $special);
|
||||
$candidate = self::asn1map($temp, $child, $special);
|
||||
$maymatch = $candidate !== null;
|
||||
}
|
||||
|
||||
@ -634,13 +680,13 @@ class ASN1
|
||||
|
||||
// the main diff between sets and sequences is the encapsulation of the foreach in another for loop
|
||||
case self::TYPE_SET:
|
||||
$map = array();
|
||||
$map = [];
|
||||
|
||||
// ignore the min and max
|
||||
if (isset($mapping['min']) && isset($mapping['max'])) {
|
||||
$child = $mapping['children'];
|
||||
foreach ($decoded['content'] as $content) {
|
||||
if (($map[] = $this->asn1map($content, $child, $special)) === null) {
|
||||
if (($map[] = self::asn1map($content, $child, $special)) === null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -676,13 +722,13 @@ class ASN1
|
||||
$maymatch = $constant == $temp['constant'] && $childClass == $tempClass;
|
||||
} else {
|
||||
// Can only match if no constant expected and type matches or is generic.
|
||||
$maymatch = !isset($child['constant']) && array_search($child['type'], array($temp['type'], self::TYPE_ANY, self::TYPE_CHOICE)) !== false;
|
||||
$maymatch = !isset($child['constant']) && array_search($child['type'], [$temp['type'], self::TYPE_ANY, self::TYPE_CHOICE]) !== false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($maymatch) {
|
||||
// Attempt submapping.
|
||||
$candidate = $this->asn1map($temp, $child, $special);
|
||||
$candidate = self::asn1map($temp, $child, $special);
|
||||
$maymatch = $candidate !== null;
|
||||
}
|
||||
|
||||
@ -710,13 +756,13 @@ class ASN1
|
||||
}
|
||||
return $map;
|
||||
case self::TYPE_OBJECT_IDENTIFIER:
|
||||
return isset($this->oids[$decoded['content']]) ? $this->oids[$decoded['content']] : $decoded['content'];
|
||||
return isset(self::$oids[$decoded['content']]) ? self::$oids[$decoded['content']] : $decoded['content'];
|
||||
case self::TYPE_UTC_TIME:
|
||||
case self::TYPE_GENERALIZED_TIME:
|
||||
if (isset($mapping['implicit'])) {
|
||||
$decoded['content'] = $this->_decodeTime($decoded['content'], $decoded['type']);
|
||||
$decoded['content'] = self::_decodeTime($decoded['content'], $decoded['type']);
|
||||
}
|
||||
return @date($this->format, $decoded['content']);
|
||||
return @date(self::$format, $decoded['content']);
|
||||
case self::TYPE_BIT_STRING:
|
||||
if (isset($mapping['mapping'])) {
|
||||
$offset = ord($decoded['content'][0]);
|
||||
@ -729,7 +775,7 @@ class ASN1
|
||||
therefore ensure that different semantics are not associated with such values which differ only in the number of trailing
|
||||
0 bits."
|
||||
*/
|
||||
$bits = count($mapping['mapping']) == $size ? array() : array_fill(0, count($mapping['mapping']) - $size, false);
|
||||
$bits = count($mapping['mapping']) == $size ? [] : array_fill(0, count($mapping['mapping']) - $size, false);
|
||||
for ($i = strlen($decoded['content']) - 1; $i > 0; $i--) {
|
||||
$current = ord($decoded['content'][$i]);
|
||||
for ($j = $offset; $j < 8; $j++) {
|
||||
@ -737,7 +783,7 @@ class ASN1
|
||||
}
|
||||
$offset = 0;
|
||||
}
|
||||
$values = array();
|
||||
$values = [];
|
||||
$map = array_reverse($mapping['mapping']);
|
||||
foreach ($map as $i => $value) {
|
||||
if ($bits[$i]) {
|
||||
@ -794,10 +840,10 @@ class ASN1
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function encodeDER($source, $mapping, $special = array())
|
||||
static function encodeDER($source, $mapping, $special = [])
|
||||
{
|
||||
$this->location = array();
|
||||
return $this->_encode_der($source, $mapping, null, $special);
|
||||
self::$location = [];
|
||||
return self::_encode_der($source, $mapping, null, $special);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -810,7 +856,7 @@ class ASN1
|
||||
* @throws \RuntimeException if the input has an error in it
|
||||
* @access private
|
||||
*/
|
||||
function _encode_der($source, $mapping, $idx = null, $special = array())
|
||||
static function _encode_der($source, $mapping, $idx = null, $special = [])
|
||||
{
|
||||
if ($source instanceof Element) {
|
||||
return $source->element;
|
||||
@ -825,7 +871,7 @@ class ASN1
|
||||
if (isset($special[$idx])) {
|
||||
$source = call_user_func($special[$idx], $source);
|
||||
}
|
||||
$this->location[] = $idx;
|
||||
self::$location[] = $idx;
|
||||
}
|
||||
|
||||
$tag = $mapping['type'];
|
||||
@ -837,11 +883,11 @@ class ASN1
|
||||
|
||||
// ignore the min and max
|
||||
if (isset($mapping['min']) && isset($mapping['max'])) {
|
||||
$value = array();
|
||||
$value = [];
|
||||
$child = $mapping['children'];
|
||||
|
||||
foreach ($source as $content) {
|
||||
$temp = $this->_encode_der($content, $child, null, $special);
|
||||
$temp = self::_encode_der($content, $child, null, $special);
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
@ -868,7 +914,7 @@ class ASN1
|
||||
continue;
|
||||
}
|
||||
|
||||
$temp = $this->_encode_der($source[$key], $child, $key, $special);
|
||||
$temp = self::_encode_der($source[$key], $child, $key, $special);
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
@ -892,7 +938,7 @@ class ASN1
|
||||
*/
|
||||
if (isset($child['explicit']) || $child['type'] == self::TYPE_CHOICE) {
|
||||
$subtag = chr((self::CLASS_CONTEXT_SPECIFIC << 6) | 0x20 | $child['constant']);
|
||||
$temp = $subtag . Functions::encodeLength(strlen($temp)) . $temp;
|
||||
$temp = $subtag . self::encodeLength(strlen($temp)) . $temp;
|
||||
} else {
|
||||
$subtag = chr((self::CLASS_CONTEXT_SPECIFIC << 6) | (ord($temp[0]) & 0x20) | $child['constant']);
|
||||
$temp = $subtag . substr($temp, 1);
|
||||
@ -909,7 +955,7 @@ class ASN1
|
||||
continue;
|
||||
}
|
||||
|
||||
$temp = $this->_encode_der($source[$key], $child, $key, $special);
|
||||
$temp = self::_encode_der($source[$key], $child, $key, $special);
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
@ -926,7 +972,7 @@ class ASN1
|
||||
if (isset($child['constant'])) {
|
||||
if (isset($child['explicit']) || $child['type'] == self::TYPE_CHOICE) {
|
||||
$subtag = chr((self::CLASS_CONTEXT_SPECIFIC << 6) | 0x20 | $child['constant']);
|
||||
$temp = $subtag . Functions::encodeLength(strlen($temp)) . $temp;
|
||||
$temp = $subtag . self::encodeLength(strlen($temp)) . $temp;
|
||||
} else {
|
||||
$subtag = chr((self::CLASS_CONTEXT_SPECIFIC << 6) | (ord($temp[0]) & 0x20) | $child['constant']);
|
||||
$temp = $subtag . substr($temp, 1);
|
||||
@ -935,7 +981,7 @@ class ASN1
|
||||
}
|
||||
|
||||
if (isset($idx)) {
|
||||
array_pop($this->location);
|
||||
array_pop(self::$location);
|
||||
}
|
||||
|
||||
if ($temp && isset($mapping['cast'])) {
|
||||
@ -1008,7 +1054,11 @@ class ASN1
|
||||
$value = Base64::decode($source);
|
||||
break;
|
||||
case self::TYPE_OBJECT_IDENTIFIER:
|
||||
$oid = preg_match('#(?:\d+\.)+#', $source) ? $source : array_search($source, $this->oids);
|
||||
if (!preg_match('#(?:\d+\.)+#', $source)) {
|
||||
$oid = isset(self::$reverseOIDs[$source]) ? self::$reverseOIDs[$source] : false;
|
||||
} else {
|
||||
$oid = $source;
|
||||
}
|
||||
if ($oid === false) {
|
||||
throw new \RuntimeException('Invalid OID');
|
||||
return false;
|
||||
@ -1031,30 +1081,30 @@ class ASN1
|
||||
}
|
||||
break;
|
||||
case self::TYPE_ANY:
|
||||
$loc = $this->location;
|
||||
$loc = self::$location;
|
||||
if (isset($idx)) {
|
||||
array_pop($this->location);
|
||||
array_pop(self::$location);
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case !isset($source):
|
||||
return $this->_encode_der(null, array('type' => self::TYPE_NULL) + $mapping, null, $special);
|
||||
return self::_encode_der(null, ['type' => self::TYPE_NULL] + $mapping, null, $special);
|
||||
case is_int($source):
|
||||
case $source instanceof BigInteger:
|
||||
return $this->_encode_der($source, array('type' => self::TYPE_INTEGER) + $mapping, null, $special);
|
||||
return self::_encode_der($source, ['type' => self::TYPE_INTEGER] + $mapping, null, $special);
|
||||
case is_float($source):
|
||||
return $this->_encode_der($source, array('type' => self::TYPE_REAL) + $mapping, null, $special);
|
||||
return self::_encode_der($source, ['type' => self::TYPE_REAL] + $mapping, null, $special);
|
||||
case is_bool($source):
|
||||
return $this->_encode_der($source, array('type' => self::TYPE_BOOLEAN) + $mapping, null, $special);
|
||||
return self::_encode_der($source, ['type' => self::TYPE_BOOLEAN] + $mapping, null, $special);
|
||||
case is_array($source) && count($source) == 1:
|
||||
$typename = implode('', array_keys($source));
|
||||
$outtype = array_search($typename, $this->ANYmap, true);
|
||||
$outtype = array_search($typename, self::ANY_MAP, true);
|
||||
if ($outtype !== false) {
|
||||
return $this->_encode_der($source[$typename], array('type' => $outtype) + $mapping, null, $special);
|
||||
return self::_encode_der($source[$typename], ['type' => $outtype] + $mapping, null, $special);
|
||||
}
|
||||
}
|
||||
|
||||
$filters = $this->filters;
|
||||
$filters = self::$filters;
|
||||
foreach ($loc as $part) {
|
||||
if (!isset($filters[$part])) {
|
||||
$filters = false;
|
||||
@ -1066,7 +1116,7 @@ class ASN1
|
||||
throw new \RuntimeException('No filters defined for ' . implode('/', $loc));
|
||||
return false;
|
||||
}
|
||||
return $this->_encode_der($source, $filters + $mapping, null, $special);
|
||||
return self::_encode_der($source, $filters + $mapping, null, $special);
|
||||
case self::TYPE_NULL:
|
||||
$value = '';
|
||||
break;
|
||||
@ -1087,24 +1137,24 @@ class ASN1
|
||||
$value = $source ? "\xFF" : "\x00";
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException('Mapping provides no type definition for ' . implode('/', $this->location));
|
||||
throw new \RuntimeException('Mapping provides no type definition for ' . implode('/', self::$location));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($idx)) {
|
||||
array_pop($this->location);
|
||||
array_pop(self::$location);
|
||||
}
|
||||
|
||||
if (isset($mapping['cast'])) {
|
||||
if (isset($mapping['explicit']) || $mapping['type'] == self::TYPE_CHOICE) {
|
||||
$value = chr($tag) . Functions::encodeLength(strlen($value)) . $value;
|
||||
$value = chr($tag) . self::encodeLength(strlen($value)) . $value;
|
||||
$tag = ($mapping['class'] << 6) | 0x20 | $mapping['cast'];
|
||||
} else {
|
||||
$tag = ($mapping['class'] << 6) | (ord($temp[0]) & 0x20) | $mapping['cast'];
|
||||
}
|
||||
}
|
||||
|
||||
return chr($tag) . Functions::encodeLength(strlen($value)) . $value;
|
||||
return chr($tag) . self::encodeLength(strlen($value)) . $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1117,7 +1167,7 @@ class ASN1
|
||||
* @param int $tag
|
||||
* @return string
|
||||
*/
|
||||
function _decodeTime($content, $tag)
|
||||
static function _decodeTime($content, $tag)
|
||||
{
|
||||
/* UTCTime:
|
||||
http://tools.ietf.org/html/rfc5280#section-4.1.2.5.1
|
||||
@ -1164,35 +1214,38 @@ class ASN1
|
||||
* @access public
|
||||
* @param string $format
|
||||
*/
|
||||
function setTimeFormat($format)
|
||||
static function setTimeFormat($format)
|
||||
{
|
||||
$this->format = $format;
|
||||
self::$format = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load OIDs
|
||||
*
|
||||
* Load the relevant OIDs for a particular ASN.1 semantic mapping.
|
||||
* Previously loaded OIDs are retained.
|
||||
*
|
||||
* @access public
|
||||
* @param array $oids
|
||||
*/
|
||||
function loadOIDs($oids)
|
||||
static function loadOIDs($oids)
|
||||
{
|
||||
$this->oids = $oids;
|
||||
self::$oids+= $oids;
|
||||
self::$reverseOIDs = array_flip(self::$oids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load filters
|
||||
* Set filters
|
||||
*
|
||||
* See \phpseclib\File\X509, etc, for an example.
|
||||
* Previously loaded filters are not retained.
|
||||
*
|
||||
* @access public
|
||||
* @param array $filters
|
||||
*/
|
||||
function loadFilters($filters)
|
||||
static function setFilters($filters)
|
||||
{
|
||||
$this->filters = $filters;
|
||||
self::$filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1207,13 +1260,14 @@ class ASN1
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function convert($in, $from = self::TYPE_UTF8_STRING, $to = self::TYPE_UTF8_STRING)
|
||||
static function convert($in, $from = self::TYPE_UTF8_STRING, $to = self::TYPE_UTF8_STRING)
|
||||
{
|
||||
if (!isset($this->stringTypeSize[$from]) || !isset($this->stringTypeSize[$to])) {
|
||||
// isset(self::STRING_TYPE_SIZE[$from] returns a fatal error on PHP 5.6
|
||||
if (!array_key_exists($from, self::STRING_TYPE_SIZE) || !array_key_exists($to, self::STRING_TYPE_SIZE)) {
|
||||
return false;
|
||||
}
|
||||
$insize = $this->stringTypeSize[$from];
|
||||
$outsize = $this->stringTypeSize[$to];
|
||||
$insize = self::STRING_TYPE_SIZE[$from];
|
||||
$outsize = self::STRING_TYPE_SIZE[$to];
|
||||
$inlength = strlen($in);
|
||||
$out = '';
|
||||
|
||||
@ -1316,8 +1370,72 @@ class ASN1
|
||||
// remove the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- stuff
|
||||
$temp = preg_replace('#-+[^-]+-+#', '', $temp);
|
||||
// remove new lines
|
||||
$temp = str_replace(array("\r", "\n", ' '), '', $temp);
|
||||
$temp = str_replace(["\r", "\n", ' '], '', $temp);
|
||||
$temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? Base64::decode($temp) : false;
|
||||
return $temp != false ? $temp : $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* DER-decode the length
|
||||
*
|
||||
* DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See
|
||||
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
|
||||
*
|
||||
* @access public
|
||||
* @param string $string
|
||||
* @return int
|
||||
*/
|
||||
static function decodeLength(&$string)
|
||||
{
|
||||
$length = ord(Strings::shift($string));
|
||||
if ($length & 0x80) { // definite length, long form
|
||||
$length&= 0x7F;
|
||||
$temp = Strings::shift($string, $length);
|
||||
list(, $length) = unpack('N', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4));
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* DER-encode the length
|
||||
*
|
||||
* DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See
|
||||
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
|
||||
*
|
||||
* @access public
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
static function encodeLength($length)
|
||||
{
|
||||
if ($length <= 0x7F) {
|
||||
return chr($length);
|
||||
}
|
||||
|
||||
$temp = ltrim(pack('N', $length), chr(0));
|
||||
return pack('Ca*', 0x80 | strlen($temp), $temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the OID corresponding to a name
|
||||
*
|
||||
* What's returned in the associative array returned by loadX509() (or load*()) is either a name or an OID if
|
||||
* no OID to name mapping is available. The problem with this is that what may be an unmapped OID in one version
|
||||
* of phpseclib may not be unmapped in the next version, so apps that are looking at this OID may not be able
|
||||
* to work from version to version.
|
||||
*
|
||||
* This method will return the OID if a name is passed to it and if no mapping is avialable it'll assume that
|
||||
* what's being passed to it already is an OID and return that instead. A few examples.
|
||||
*
|
||||
* getOID('2.16.840.1.101.3.4.2.1') == '2.16.840.1.101.3.4.2.1'
|
||||
* getOID('id-sha256') == '2.16.840.1.101.3.4.2.1'
|
||||
* getOID('zzz') == 'zzz'
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
static function getOID($name)
|
||||
{
|
||||
return isset(self::$reverseOIDs[$name]) ? self::$reverseOIDs[$name] : $name;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Pure-PHP ASN.1 Parser
|
||||
* ASN.1 Raw Element
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
@ -15,9 +16,10 @@
|
||||
namespace phpseclib\File\ASN1;
|
||||
|
||||
/**
|
||||
* ASN.1 Element
|
||||
* ASN.1 Raw Element
|
||||
*
|
||||
* Bypass normal encoding rules in phpseclib\File\ASN1::encodeDER()
|
||||
* An ASN.1 ANY mapping will return an ASN1\Element object. Use of this object
|
||||
* will also bypass the normal encoding rules in ASN1::encodeDER()
|
||||
*
|
||||
* @package ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
38
phpseclib/File/ASN1/Maps/DigestInfo.php
Normal file
38
phpseclib/File/ASN1/Maps/DigestInfo.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DigestInfo
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category File
|
||||
* @package ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2016 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
||||
/**
|
||||
* DigestInfo
|
||||
*
|
||||
* from https://tools.ietf.org/html/rfc2898#appendix-A.3
|
||||
*
|
||||
* @package ASN1
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class DigestInfo
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
'children' => [
|
||||
'digestAlgorithm' => AlgorithmIdentifier::MAP,
|
||||
'digest' => ['type' => ASN1::TYPE_OCTET_STRING]
|
||||
]
|
||||
];
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
||||
@ -30,15 +30,17 @@ class TBSCertList
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
'children' => [
|
||||
'version' => [
|
||||
'type' => ASN1::TYPE_INTEGER,
|
||||
'mapping' => ['v1', 'v2', 'v3'],
|
||||
'optional' => true,
|
||||
'default' => 'v1'
|
||||
] + Version::MAP,
|
||||
'default' => 'v2'
|
||||
],
|
||||
'signature' => AlgorithmIdentifier::MAP,
|
||||
'issuer' => Name::MAP,
|
||||
'thisUpdate' => Time::MAP,
|
||||
'nextUpdate' => [
|
||||
'optional' => true
|
||||
] + Time,
|
||||
] + Time::MAP,
|
||||
'revokedCertificates' => [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
'optional' => true,
|
@ -13,7 +13,7 @@
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\File\ASN1;
|
||||
namespace phpseclib\File\ASN1\Maps;
|
||||
|
||||
use phpseclib\File\ASN1;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user