8000 [VarDumper] add caster for OpenSSL X.509 resources by nicolas-grekas · Pull Request #29821 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] add caster for OpenSSL X.509 resources #29821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/VarDumper/Caster/ConstStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*/
class ConstStub extends Stub
{
public function __construct(string $name, $value)
public function __construct(string $name, $value = null)
{
$this->class = $name;
$this->value = $value;
$this->value = 1 < \func_num_args() ? $value : $name;
}

public function __toString()
Expand Down
26 changes: 26 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/ResourceCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,30 @@ public static function castMysqlLink($h, array $a, Stub $stub, $isNested)

return $a;
}

public static function castOpensslX509($h, array $a, Stub $stub, $isNested)
{
$stub->cut = -1;
$info = openssl_x509_parse($h, false);

$pin = openssl_pkey_get_public($h);
$pin = openssl_pkey_get_details($pin)['key'];
$pin = \array_slice(explode("\n", $pin), 1, -2);
$pin = base64_decode(implode('', $pin));
$pin = base64_encode(hash('sha256', $pin, true));

$a += array(
'subject' => new EnumStub(array_intersect_key($info['subject'], array('organizationName' => true, 'commonName' => true))),
'issuer' => new EnumStub(array_intersect_key($info['issuer'], array('organizationName' => true, 'commonName' => true))),
'expiry' => new ConstStub(date(\DateTime::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
'fingerprint' => new EnumStub(array(
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
'pin-sha256' => new ConstStub($pin),
)),
);

return $a;
}
}
3 changes: 2 additions & 1 deletion src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ abstract class AbstractCloner implements ClonerInterface
':pgsql result' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'),
':process' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'),
':stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'),
':OpenSSL X.509' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'),
':persistent stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'),
':stream-context' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'),
':xml' => array('Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'),
Expand Down Expand Up @@ -176,7 +177,7 @@ public function __construct(array $casters = null)
public function addCasters(array $casters)
{
foreach ($casters as $type => $callback) {
$closure = &$this->casters[strtolower($type)][];
$closure = &$this->casters['' === $type || ':' === $type[0] ? $type : strtolower($type)][];
$closure = $callback instanceof \Closure ? $callback : static function (...$args) use ($callback, &$closure) {
return ($closure = \Closure::fromCallable($callback))(...$args);
};
Expand Down
0