8000 [VarDumper] add caster for OpenSSL X.509 resources · symfony/symfony@5e88dc6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e88dc6

Browse files
[VarDumper] add caster for OpenSSL X.509 resources
1 parent 006dacd commit 5e88dc6

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/Symfony/Component/VarDumper/Caster/ConstStub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
*/
2121
class ConstStub extends Stub
2222
{
23-
public function __construct(string $name, $value)
23+
public function __construct(string $name, $value = null)
2424
{
2525
$this->class = $name;
26-
$this->value = $value;
26+
$this->value = 1 < \func_num_args() ? $value : $name;
2727
}
2828

2929
public function __toString()

src/Symfony/Component/VarDumper/Caster/ResourceCaster.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,30 @@ public static function castMysqlLink($h, array $a, Stub $stub, $isNested)
6969

7070
return $a;
7171
}
72+
73+
public static function castOpensslX509($h, array $a, Stub $stub, $isNested)
74+
{
75+
$stub->cut = -1;
76+
$info = openssl_x509_parse($h, false);
77+
78+
$pin = openssl_pkey_get_public($h);
79+
$pin = openssl_pkey_get_details($pin)['key'];
80+
$pin = \array_slice(explode("\n", $pin), 1, -2);
81+
$pin = base64_decode(implode('', $pin));
82+
$pin = base64_encode(hash('sha256', $pin, true));
83+
84+
$a += array(
85+
'subject' => new EnumStub(array_intersect_key($info['subject'], array('organizationName' => true, 'commonName' => true))),
86+
'issuer' => new EnumStub(array_intersect_key($info['issuer'], array('organizationName' => true, 'commonName' => true))),
87+
'expiry' => new ConstStub(date(\DateTime::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
88+
'fingerprint' => new EnumStub(array(
89+
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
90+
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
91+
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
92+
'pin-sha256' => new ConstStub($pin),
93+
)),
94+
);
95+
96+
return $a;
97+
}
7298
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ abstract class AbstractCloner implements ClonerInterface
136136
':pgsql result' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'),
137137
':process' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'),
138138
':stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'),
139+
':OpenSSL X.509' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'),
139140
':persistent stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'),
140141
':stream-context' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'),
141142
':xml' => array('Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'),
@@ -176,7 +177,7 @@ public function __construct(array $casters = null)
176177
public function addCasters(array $casters)
177178
{
178179
foreach ($casters as $type => $callback) {
179-
$closure = &$this->casters[strtolower($type)][];
180+
$closure = &$this->casters['' === $type || ':' === $type[0] ? $type : strtolower($type)][];
180181
$closure = $callback instanceof \Closure ? $callback : static function (...$args) use ($callback, &$closure) {
181182
return ($closure = \Closure::fromCallable($callback))(...$args);
182183
};

0 commit comments

Comments
 (0)
0