Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/PHPSecLi.../File
File: ASN1.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Pure-PHP ASN.1 Parser
[3] Fix | Delete
*
[4] Fix | Delete
* PHP versions 4 and 5
[5] Fix | Delete
*
[6] Fix | Delete
* ASN.1 provides the semantics for data encoded using various schemes. The most commonly
[7] Fix | Delete
* utilized scheme is DER or the "Distinguished Encoding Rules". PEM's are base64 encoded
[8] Fix | Delete
* DER blobs.
[9] Fix | Delete
*
[10] Fix | Delete
* File_ASN1 decodes and encodes DER formatted messages and places them in a semantic context.
[11] Fix | Delete
*
[12] Fix | Delete
* Uses the 1988 ASN.1 syntax.
[13] Fix | Delete
*
[14] Fix | Delete
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
[15] Fix | Delete
* of this software and associated documentation files (the "Software"), to deal
[16] Fix | Delete
* in the Software without restriction, including without limitation the rights
[17] Fix | Delete
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
[18] Fix | Delete
* copies of the Software, and to permit persons to whom the Software is
[19] Fix | Delete
* furnished to do so, subject to the following conditions:
[20] Fix | Delete
*
[21] Fix | Delete
* The above copyright notice and this permission notice shall be included in
[22] Fix | Delete
* all copies or substantial portions of the Software.
[23] Fix | Delete
*
[24] Fix | Delete
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
[25] Fix | Delete
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
[26] Fix | Delete
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
[27] Fix | Delete
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
[28] Fix | Delete
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
[29] Fix | Delete
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
[30] Fix | Delete
* THE SOFTWARE.
[31] Fix | Delete
*
[32] Fix | Delete
* @category File
[33] Fix | Delete
* @package File_ASN1
[34] Fix | Delete
* @author Jim Wigginton <terrafrost@php.net>
[35] Fix | Delete
* @copyright MMXII Jim Wigginton
[36] Fix | Delete
* @license http://www.opensource.org/licenses/mit-license.html MIT License
[37] Fix | Delete
* @link http://phpseclib.sourceforge.net
[38] Fix | Delete
*/
[39] Fix | Delete
[40] Fix | Delete
/**#@+
[41] Fix | Delete
* Tag Classes
[42] Fix | Delete
*
[43] Fix | Delete
* @access private
[44] Fix | Delete
* @link http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#page=12
[45] Fix | Delete
*/
[46] Fix | Delete
define('FILE_ASN1_CLASS_UNIVERSAL', 0);
[47] Fix | Delete
define('FILE_ASN1_CLASS_APPLICATION', 1);
[48] Fix | Delete
define('FILE_ASN1_CLASS_CONTEXT_SPECIFIC', 2);
[49] Fix | Delete
define('FILE_ASN1_CLASS_PRIVATE', 3);
[50] Fix | Delete
/**#@-*/
[51] Fix | Delete
[52] Fix | Delete
/**#@+
[53] Fix | Delete
* Tag Classes
[54] Fix | Delete
*
[55] Fix | Delete
* @access private
[56] Fix | Delete
* @link http://www.obj-sys.com/asn1tutorial/node124.html
[57] Fix | Delete
*/
[58] Fix | Delete
define('FILE_ASN1_TYPE_BOOLEAN', 1);
[59] Fix | Delete
define('FILE_ASN1_TYPE_INTEGER', 2);
[60] Fix | Delete
define('FILE_ASN1_TYPE_BIT_STRING', 3);
[61] Fix | Delete
define('FILE_ASN1_TYPE_OCTET_STRING', 4);
[62] Fix | Delete
define('FILE_ASN1_TYPE_NULL', 5);
[63] Fix | Delete
define('FILE_ASN1_TYPE_OBJECT_IDENTIFIER', 6);
[64] Fix | Delete
//define('FILE_ASN1_TYPE_OBJECT_DESCRIPTOR', 7);
[65] Fix | Delete
//define('FILE_ASN1_TYPE_INSTANCE_OF', 8); // EXTERNAL
[66] Fix | Delete
define('FILE_ASN1_TYPE_REAL', 9);
[67] Fix | Delete
define('FILE_ASN1_TYPE_ENUMERATED', 10);
[68] Fix | Delete
//define('FILE_ASN1_TYPE_EMBEDDED', 11);
[69] Fix | Delete
define('FILE_ASN1_TYPE_UTF8_STRING', 12);
[70] Fix | Delete
//define('FILE_ASN1_TYPE_RELATIVE_OID', 13);
[71] Fix | Delete
define('FILE_ASN1_TYPE_SEQUENCE', 16); // SEQUENCE OF
[72] Fix | Delete
define('FILE_ASN1_TYPE_SET', 17); // SET OF
[73] Fix | Delete
/**#@-*/
[74] Fix | Delete
/**#@+
[75] Fix | Delete
* More Tag Classes
[76] Fix | Delete
*
[77] Fix | Delete
* @access private
[78] Fix | Delete
* @link http://www.obj-sys.com/asn1tutorial/node10.html
[79] Fix | Delete
*/
[80] Fix | Delete
define('FILE_ASN1_TYPE_NUMERIC_STRING', 18);
[81] Fix | Delete
define('FILE_ASN1_TYPE_PRINTABLE_STRING', 19);
[82] Fix | Delete
define('FILE_ASN1_TYPE_TELETEX_STRING', 20); // T61String
[83] Fix | Delete
define('FILE_ASN1_TYPE_VIDEOTEX_STRING', 21);
[84] Fix | Delete
define('FILE_ASN1_TYPE_IA5_STRING', 22);
[85] Fix | Delete
define('FILE_ASN1_TYPE_UTC_TIME', 23);
[86] Fix | Delete
define('FILE_ASN1_TYPE_GENERALIZED_TIME', 24);
[87] Fix | Delete
define('FILE_ASN1_TYPE_GRAPHIC_STRING', 25);
[88] Fix | Delete
define('FILE_ASN1_TYPE_VISIBLE_STRING', 26); // ISO646String
[89] Fix | Delete
define('FILE_ASN1_TYPE_GENERAL_STRING', 27);
[90] Fix | Delete
define('FILE_ASN1_TYPE_UNIVERSAL_STRING', 28);
[91] Fix | Delete
//define('FILE_ASN1_TYPE_CHARACTER_STRING', 29);
[92] Fix | Delete
define('FILE_ASN1_TYPE_BMP_STRING', 30);
[93] Fix | Delete
/**#@-*/
[94] Fix | Delete
[95] Fix | Delete
/**#@+
[96] Fix | Delete
* Tag Aliases
[97] Fix | Delete
*
[98] Fix | Delete
* These tags are kinda place holders for other tags.
[99] Fix | Delete
*
[100] Fix | Delete
* @access private
[101] Fix | Delete
*/
[102] Fix | Delete
define('FILE_ASN1_TYPE_CHOICE', -1);
[103] Fix | Delete
define('FILE_ASN1_TYPE_ANY', -2);
[104] Fix | Delete
/**#@-*/
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* ASN.1 Element
[108] Fix | Delete
*
[109] Fix | Delete
* Bypass normal encoding rules in File_ASN1::encodeDER()
[110] Fix | Delete
*
[111] Fix | Delete
* @package File_ASN1
[112] Fix | Delete
* @author Jim Wigginton <terrafrost@php.net>
[113] Fix | Delete
* @access public
[114] Fix | Delete
*/
[115] Fix | Delete
class File_ASN1_Element
[116] Fix | Delete
{
[117] Fix | Delete
/**
[118] Fix | Delete
* Raw element value
[119] Fix | Delete
*
[120] Fix | Delete
* @var String
[121] Fix | Delete
* @access private
[122] Fix | Delete
*/
[123] Fix | Delete
public $element;
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Constructor
[127] Fix | Delete
*
[128] Fix | Delete
* @param String $encoded
[129] Fix | Delete
*
[130] Fix | Delete
* @return File_ASN1_Element
[131] Fix | Delete
* @access public
[132] Fix | Delete
*/
[133] Fix | Delete
public function __construct($encoded)
[134] Fix | Delete
{
[135] Fix | Delete
$this->element = $encoded;
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Pure-PHP ASN.1 Parser
[141] Fix | Delete
*
[142] Fix | Delete
* @package File_ASN1
[143] Fix | Delete
* @author Jim Wigginton <terrafrost@php.net>
[144] Fix | Delete
* @access public
[145] Fix | Delete
*/
[146] Fix | Delete
class File_ASN1
[147] Fix | Delete
{
[148] Fix | Delete
/**
[149] Fix | Delete
* ASN.1 object identifier
[150] Fix | Delete
*
[151] Fix | Delete
* @var Array
[152] Fix | Delete
* @access private
[153] Fix | Delete
* @link http://en.wikipedia.org/wiki/Object_identifier
[154] Fix | Delete
*/
[155] Fix | Delete
public $oids = array();
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Default date format
[159] Fix | Delete
*
[160] Fix | Delete
* @var String
[161] Fix | Delete
* @access private
[162] Fix | Delete
* @link http://php.net/class.datetime
[163] Fix | Delete
*/
[164] Fix | Delete
public $format = 'D, d M Y H:i:s O';
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Default date format
[168] Fix | Delete
*
[169] Fix | Delete
* @var Array
[170] Fix | Delete
* @access private
[171] Fix | Delete
* @see File_ASN1::setTimeFormat()
[172] Fix | Delete
* @see File_ASN1::asn1map()
[173] Fix | Delete
* @link http://php.net/class.datetime
[174] Fix | Delete
*/
[175] Fix | Delete
public $encoded;
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Filters
[179] Fix | Delete
*
[180] Fix | Delete
* If the mapping type is FILE_ASN1_TYPE_ANY what do we actually encode it as?
[181] Fix | Delete
*
[182] Fix | Delete
* @var Array
[183] Fix | Delete
* @access private
[184] Fix | Delete
* @see File_ASN1::_encode_der()
[185] Fix | Delete
*/
[186] Fix | Delete
public $filters;
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Type mapping table for the ANY type.
[190] Fix | Delete
*
[191] Fix | Delete
* Structured or unknown types are mapped to a FILE_ASN1_Element.
[192] Fix | Delete
* Unambiguous types get the direct mapping (int/real/bool).
[193] Fix | Delete
* Others are mapped as a choice, with an extra indexing level.
[194] Fix | Delete
*
[195] Fix | Delete
* @var Array
[196] Fix | Delete
* @access public
[197] Fix | Delete
*/
[198] Fix | Delete
var $ANYmap = array(
[199] Fix | Delete
FILE_ASN1_TYPE_BOOLEAN => true,
[200] Fix | Delete
FILE_ASN1_TYPE_INTEGER => true,
[201] Fix | Delete
FILE_ASN1_TYPE_BIT_STRING => 'bitString',
[202] Fix | Delete
FILE_ASN1_TYPE_OCTET_STRING => 'octetString',
[203] Fix | Delete
FILE_ASN1_TYPE_NULL => 'null',
[204] Fix | Delete
FILE_ASN1_TYPE_OBJECT_IDENTIFIER => 'objectIdentifier',
[205] Fix | Delete
FILE_ASN1_TYPE_REAL => true,
[206] Fix | Delete
FILE_ASN1_TYPE_ENUMERATED => 'enumerated',
[207] Fix | Delete
FILE_ASN1_TYPE_UTF8_STRING => 'utf8String',
[208] Fix | Delete
FILE_ASN1_TYPE_NUMERIC_STRING => 'numericString',
[209] Fix | Delete
FILE_ASN1_TYPE_PRINTABLE_STRING => 'printableString',
[210] Fix | Delete
FILE_ASN1_TYPE_TELETEX_STRING => 'teletexString',
[211] Fix | Delete
FILE_ASN1_TYPE_VIDEOTEX_STRING => 'videotexString',
[212] Fix | Delete
FILE_ASN1_TYPE_IA5_STRING => 'ia5String',
[213] Fix | Delete
FILE_ASN1_TYPE_UTC_TIME => 'utcTime',
[214] Fix | Delete
FILE_ASN1_TYPE_GENERALIZED_TIME => 'generalTime',
[215] Fix | Delete
FILE_ASN1_TYPE_GRAPHIC_STRING => 'graphicString',
[216] Fix | Delete
FILE_ASN1_TYPE_VISIBLE_STRING => 'visibleString',
[217] Fix | Delete
FILE_ASN1_TYPE_GENERAL_STRING => 'generalString',
[218] Fix | Delete
FILE_ASN1_TYPE_UNIVERSAL_STRING => 'universalString',
[219] Fix | Delete
//FILE_ASN1_TYPE_CHARACTER_STRING => 'characterString',
[220] Fix | Delete
FILE_ASN1_TYPE_BMP_STRING => 'bmpString',
[221] Fix | Delete
);
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* String type to character size mapping table.
[225] Fix | Delete
*
[226] Fix | Delete
* Non-convertable types are absent from this table.
[227] Fix | Delete
* size == 0 indicates variable length encoding.
[228] Fix | Delete
*
[229] Fix | Delete
* @var Array
[230] Fix | Delete
* @access public
[231] Fix | Delete
*/
[232] Fix | Delete
var $stringTypeSize = array(
[233] Fix | Delete
FILE_ASN1_TYPE_UTF8_STRING => 0,
[234] Fix | Delete
FILE_ASN1_TYPE_BMP_STRING => 2,
[235] Fix | Delete
FILE_ASN1_TYPE_UNIVERSAL_STRING => 4,
[236] Fix | Delete
FILE_ASN1_TYPE_PRINTABLE_STRING => 1,
[237] Fix | Delete
FILE_ASN1_TYPE_TELETEX_STRING => 1,
[238] Fix | Delete
FILE_ASN1_TYPE_IA5_STRING => 1,
[239] Fix | Delete
FILE_ASN1_TYPE_VISIBLE_STRING => 1,
[240] Fix | Delete
);
[241] Fix | Delete
[242] Fix | Delete
/**
[243] Fix | Delete
* Default Constructor.
[244] Fix | Delete
*
[245] Fix | Delete
* @access public
[246] Fix | Delete
*/
[247] Fix | Delete
public function __construct()
[248] Fix | Delete
{
[249] Fix | Delete
static $static_init = null;
[250] Fix | Delete
if (!$static_init) {
[251] Fix | Delete
$static_init = true;
[252] Fix | Delete
if (!class_exists('Math_BigInteger')) {
[253] Fix | Delete
require_once dirname(__FILE__).'/../Math/BigInteger.php';
[254] Fix | Delete
}
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
/**
[259] Fix | Delete
* Parse BER-encoding
[260] Fix | Delete
*
[261] Fix | Delete
* Serves a similar purpose to openssl's asn1parse
[262] Fix | Delete
*
[263] Fix | Delete
* @param String $encoded
[264] Fix | Delete
*
[265] Fix | Delete
* @return Array
[266] Fix | Delete
* @access public
[267] Fix | Delete
*/
[268] Fix | Delete
public function decodeBER($encoded)
[269] Fix | Delete
{
[270] Fix | Delete
if (is_object($encoded) && strtolower(get_class($encoded)) == 'file_asn1_element') {
[271] Fix | Delete
$encoded = $encoded->element;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
$this->encoded = $encoded;
[275] Fix | Delete
[276] Fix | Delete
return $this->_decode_ber($encoded);
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
/**
[280] Fix | Delete
* Parse BER-encoding (Helper function)
[281] Fix | Delete
*
[282] Fix | Delete
* Sometimes we want to get the BER encoding of a particular tag. $start lets us do that without having to reencode.
[283] Fix | Delete
* $encoded is passed by reference for the recursive calls done for FILE_ASN1_TYPE_BIT_STRING and
[284] Fix | Delete
* FILE_ASN1_TYPE_OCTET_STRING. In those cases, the indefinite length is used.
[285] Fix | Delete
*
[286] Fix | Delete
* @param String $encoded
[287] Fix | Delete
* @param Integer $start
[288] Fix | Delete
*
[289] Fix | Delete
* @return Array
[290] Fix | Delete
* @access private
[291] Fix | Delete
*/
[292] Fix | Delete
public function _decode_ber(&$encoded, $start = 0)
[293] Fix | Delete
{
[294] Fix | Delete
$decoded = array();
[295] Fix | Delete
[296] Fix | Delete
while (strlen($encoded)) {
[297] Fix | Delete
$current = array('start' => $start);
[298] Fix | Delete
[299] Fix | Delete
$type = ord($this->_string_shift($encoded));
[300] Fix | Delete
$start++;
[301] Fix | Delete
[302] Fix | Delete
$constructed = ($type >> 5) & 1;
[303] Fix | Delete
[304] Fix | Delete
$tag = $type & 0x1F;
[305] Fix | Delete
if ($tag == 0x1F) {
[306] Fix | Delete
$tag = 0;
[307] Fix | Delete
// process septets (since the eighth bit is ignored, it's not an octet)
[308] Fix | Delete
do {
[309] Fix | Delete
$loop = ord($encoded[0]) >> 7;
[310] Fix | Delete
$tag <<= 7;
[311] Fix | Delete
$tag |= ord($this->_string_shift($encoded)) & 0x7F;
[312] Fix | Delete
$start++;
[313] Fix | Delete
} while ($loop);
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
// Length, as discussed in paragraph 8.1.3 of X.690-0207.pdf#page=13
[317] Fix | Delete
$length = ord($this->_string_shift($encoded));
[318] Fix | Delete
$start++;
[319] Fix | Delete
if ($length == 0x80) { // indefinite length
[320] Fix | Delete
// "[A sender shall] use the indefinite form (see 8.1.3.6) if the encoding is constructed and is not all
[321] Fix | Delete
// immediately available." -- paragraph 8.1.3.2.c
[322] Fix | Delete
//if ( !$constructed ) {
[323] Fix | Delete
// return false;
[324] Fix | Delete
//}
[325] Fix | Delete
$length = strlen($encoded);
[326] Fix | Delete
} elseif ($length & 0x80) { // definite length, long form
[327] Fix | Delete
// technically, the long form of the length can be represented by up to 126 octets (bytes), but we'll only
[328] Fix | Delete
// support it up to four.
[329] Fix | Delete
$length &= 0x7F;
[330] Fix | Delete
$temp = $this->_string_shift($encoded, $length);
[331] Fix | Delete
// tags of indefinite length don't really have a header length; this length includes the tag
[332] Fix | Delete
$current += array('headerlength' => $length + 2);
[333] Fix | Delete
$start += $length;
[334] Fix | Delete
extract(unpack('Nlength', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4)));
[335] Fix | Delete
} else {
[336] Fix | Delete
$current += array('headerlength' => 2);
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
// End-of-content, see paragraphs 8.1.1.3, 8.1.3.2, 8.1.3.6, 8.1.5, and (for an example) 8.6.4.2
[340] Fix | Delete
if (!$type && !$length) {
[341] Fix | Delete
return $decoded;
[342] Fix | Delete
}
[343] Fix | Delete
$content = $this->_string_shift($encoded, $length);
[344] Fix | Delete
[345] Fix | Delete
/* Class is UNIVERSAL, APPLICATION, PRIVATE, or CONTEXT-SPECIFIC. The UNIVERSAL class is restricted to the ASN.1
[346] Fix | Delete
built-in types. It defines an application-independent data type that must be distinguishable from all other
[347] Fix | Delete
data types. The other three classes are user defined. The APPLICATION class distinguishes data types that
[348] Fix | Delete
have a wide, scattered use within a particular presentation context. PRIVATE distinguishes data types within
[349] Fix | Delete
a particular organization or country. CONTEXT-SPECIFIC distinguishes members of a sequence or set, the
[350] Fix | Delete
alternatives of a CHOICE, or universally tagged set members. Only the class number appears in braces for this
[351] Fix | Delete
data type; the term CONTEXT-SPECIFIC does not appear.
[352] Fix | Delete
[353] Fix | Delete
-- http://www.obj-sys.com/asn1tutorial/node12.html */
[354] Fix | Delete
$class = ($type >> 6) & 3;
[355] Fix | Delete
switch ($class) {
[356] Fix | Delete
case FILE_ASN1_CLASS_APPLICATION:
[357] Fix | Delete
case FILE_ASN1_CLASS_PRIVATE:
[358] Fix | Delete
case FILE_ASN1_CLASS_CONTEXT_SPECIFIC:
[359] Fix | Delete
$decoded[] = array(
[360] Fix | Delete
'type' => $class,
[361] Fix | Delete
'constant' => $tag,
[362] Fix | Delete
'content' => $constructed ? $this->_decode_ber($content, $start) : $content,
[363] Fix | Delete
'length' => $length + $start - $current['start'],
[364] Fix | Delete
) + $current;
[365] Fix | Delete
$start += $length;
[366] Fix | Delete
continue 2;
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
$current += array('type' => $tag);
[370] Fix | Delete
[371] Fix | Delete
// decode UNIVERSAL tags
[372] Fix | Delete
switch ($tag) {
[373] Fix | Delete
case FILE_ASN1_TYPE_BOOLEAN:
[374] Fix | Delete
// "The contents octets shall consist of a single octet." -- paragraph 8.2.1
[375] Fix | Delete
//if (strlen($content) != 1) {
[376] Fix | Delete
// return false;
[377] Fix | Delete
//}
[378] Fix | Delete
$current['content'] = (bool) ord($content[0]);
[379] Fix | Delete
break;
[380] Fix | Delete
case FILE_ASN1_TYPE_INTEGER:
[381] Fix | Delete
case FILE_ASN1_TYPE_ENUMERATED:
[382] Fix | Delete
$current['content'] = new Math_BigInteger($content, -256);
[383] Fix | Delete
break;
[384] Fix | Delete
case FILE_ASN1_TYPE_REAL: // not currently supported
[385] Fix | Delete
return false;
[386] Fix | Delete
case FILE_ASN1_TYPE_BIT_STRING:
[387] Fix | Delete
// The initial octet shall encode, as an unsigned binary integer with bit 1 as the least significant bit,
[388] Fix | Delete
// the number of unused bits in the final subsequent octet. The number shall be in the range zero to
[389] Fix | Delete
// seven.
[390] Fix | Delete
if (!$constructed) {
[391] Fix | Delete
$current['content'] = $content;
[392] Fix | Delete
} else {
[393] Fix | Delete
$temp = $this->_decode_ber($content, $start);
[394] Fix | Delete
$length -= strlen($content);
[395] Fix | Delete
$last = count($temp) - 1;
[396] Fix | Delete
for ($i = 0; $i < $last; $i++) {
[397] Fix | Delete
// all subtags should be bit strings
[398] Fix | Delete
//if ($temp[$i]['type'] != FILE_ASN1_TYPE_BIT_STRING) {
[399] Fix | Delete
// return false;
[400] Fix | Delete
//}
[401] Fix | Delete
$current['content'] .= substr($temp[$i]['content'], 1);
[402] Fix | Delete
}
[403] Fix | Delete
// all subtags should be bit strings
[404] Fix | Delete
//if ($temp[$last]['type'] != FILE_ASN1_TYPE_BIT_STRING) {
[405] Fix | Delete
// return false;
[406] Fix | Delete
//}
[407] Fix | Delete
$current['content'] = $temp[$last]['content'][0].$current['content'].substr($temp[$i]['content'], 1);
[408] Fix | Delete
}
[409] Fix | Delete
break;
[410] Fix | Delete
case FILE_ASN1_TYPE_OCTET_STRING:
[411] Fix | Delete
if (!$constructed) {
[412] Fix | Delete
$current['content'] = $content;
[413] Fix | Delete
} else {
[414] Fix | Delete
$temp = $this->_decode_ber($content, $start);
[415] Fix | Delete
$length -= strlen($content);
[416] Fix | Delete
for ($i = 0, $size = count($temp); $i < $size; $i++) {
[417] Fix | Delete
// all subtags should be octet strings
[418] Fix | Delete
//if ($temp[$i]['type'] != FILE_ASN1_TYPE_OCTET_STRING) {
[419] Fix | Delete
// return false;
[420] Fix | Delete
//}
[421] Fix | Delete
$current['content'] .= $temp[$i]['content'];
[422] Fix | Delete
}
[423] Fix | Delete
// $length =
[424] Fix | Delete
}
[425] Fix | Delete
break;
[426] Fix | Delete
case FILE_ASN1_TYPE_NULL:
[427] Fix | Delete
// "The contents octets shall not contain any octets." -- paragraph 8.8.2
[428] Fix | Delete
//if (strlen($content)) {
[429] Fix | Delete
// return false;
[430] Fix | Delete
//}
[431] Fix | Delete
break;
[432] Fix | Delete
case FILE_ASN1_TYPE_SEQUENCE:
[433] Fix | Delete
case FILE_ASN1_TYPE_SET:
[434] Fix | Delete
$current['content'] = $this->_decode_ber($content, $start);
[435] Fix | Delete
break;
[436] Fix | Delete
case FILE_ASN1_TYPE_OBJECT_IDENTIFIER:
[437] Fix | Delete
$temp = ord($this->_string_shift($content));
[438] Fix | Delete
$current['content'] = sprintf('%d.%d', floor($temp / 40), $temp % 40);
[439] Fix | Delete
$valuen = 0;
[440] Fix | Delete
// process septets
[441] Fix | Delete
while (strlen($content)) {
[442] Fix | Delete
$temp = ord($this->_string_shift($content));
[443] Fix | Delete
$valuen <<= 7;
[444] Fix | Delete
$valuen |= $temp & 0x7F;
[445] Fix | Delete
if (~$temp & 0x80) {
[446] Fix | Delete
$current['content'] .= ".$valuen";
[447] Fix | Delete
$valuen = 0;
[448] Fix | Delete
}
[449] Fix | Delete
}
[450] Fix | Delete
// the eighth bit of the last byte should not be 1
[451] Fix | Delete
//if ($temp >> 7) {
[452] Fix | Delete
// return false;
[453] Fix | Delete
//}
[454] Fix | Delete
break;
[455] Fix | Delete
/* Each character string type shall be encoded as if it had been declared:
[456] Fix | Delete
[UNIVERSAL x] IMPLICIT OCTET STRING
[457] Fix | Delete
[458] Fix | Delete
-- X.690-0207.pdf#page=23 (paragraph 8.21.3)
[459] Fix | Delete
[460] Fix | Delete
Per that, we're not going to do any validation. If there are any illegal characters in the string,
[461] Fix | Delete
we don't really care */
[462] Fix | Delete
case FILE_ASN1_TYPE_NUMERIC_STRING:
[463] Fix | Delete
// 0,1,2,3,4,5,6,7,8,9, and space
[464] Fix | Delete
case FILE_ASN1_TYPE_PRINTABLE_STRING:
[465] Fix | Delete
// Upper and lower case letters, digits, space, apostrophe, left/right parenthesis, plus sign, comma,
[466] Fix | Delete
// hyphen, full stop, solidus, colon, equal sign, question mark
[467] Fix | Delete
case FILE_ASN1_TYPE_TELETEX_STRING:
[468] Fix | Delete
// The Teletex character set in CCITT's T61, space, and delete
[469] Fix | Delete
// see http://en.wikipedia.org/wiki/Teletex#Character_sets
[470] Fix | Delete
case FILE_ASN1_TYPE_VIDEOTEX_STRING:
[471] Fix | Delete
// The Videotex character set in CCITT's T.100 and T.101, space, and delete
[472] Fix | Delete
case FILE_ASN1_TYPE_VISIBLE_STRING:
[473] Fix | Delete
// Printing character sets of international ASCII, and space
[474] Fix | Delete
case FILE_ASN1_TYPE_IA5_STRING:
[475] Fix | Delete
// International Alphabet 5 (International ASCII)
[476] Fix | Delete
case FILE_ASN1_TYPE_GRAPHIC_STRING:
[477] Fix | Delete
// All registered G sets, and space
[478] Fix | Delete
case FILE_ASN1_TYPE_GENERAL_STRING:
[479] Fix | Delete
// All registered C and G sets, space and delete
[480] Fix | Delete
case FILE_ASN1_TYPE_UTF8_STRING:
[481] Fix | Delete
// ????
[482] Fix | Delete
case FILE_ASN1_TYPE_BMP_STRING:
[483] Fix | Delete
$current['content'] = $content;
[484] Fix | Delete
break;
[485] Fix | Delete
case FILE_ASN1_TYPE_UTC_TIME:
[486] Fix | Delete
case FILE_ASN1_TYPE_GENERALIZED_TIME:
[487] Fix | Delete
$current['content'] = $this->_decodeTime($content, $tag);
[488] Fix | Delete
default:
[489] Fix | Delete
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
$start += $length;
[493] Fix | Delete
$decoded[] = $current + array('length' => $start - $current['start']);
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
return $decoded;
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function