Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 29b151b

Browse filesBrowse files
committed
feature #29821 [VarDumper] add caster for OpenSSL X.509 resources (nicolas-grekas)
This PR was merged into the 4.3-dev branch. Discussion ---------- [VarDumper] add caster for OpenSSL X.509 resources | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - I needed that today, so here we are: ![image](https://user-images.githubusercontent.com/243674/50846515-a0b49e80-136f-11e9-9ebd-5d570c01df26.png) Commits ------- 5e88dc6 [VarDumper] add caster for OpenSSL X.509 resources
2 parents 006dacd + 5e88dc6 commit 29b151b
Copy full SHA for 29b151b

File tree

3 files changed

+30
-3
lines changed
Filter options

3 files changed

+30
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ConstStub.php
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ResourceCaster.php
+26Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
+2-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.