These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Create certification request. |
||
4 | * |
||
5 | * php create-csr.php |
||
6 | */ |
||
7 | |||
8 | use Sop\CryptoEncoding\PEM; |
||
9 | use Sop\CryptoTypes\AlgorithmIdentifier\Hash\SHA256AlgorithmIdentifier; |
||
10 | use Sop\CryptoTypes\AlgorithmIdentifier\Signature\SignatureAlgorithmIdentifierFactory; |
||
11 | use Sop\CryptoTypes\Asymmetric\PrivateKeyInfo; |
||
12 | use X501\ASN1\Name; |
||
13 | use X509\CertificationRequest\CertificationRequestInfo; |
||
14 | |||
15 | require dirname(__DIR__) . "/vendor/autoload.php"; |
||
16 | |||
17 | // load EC private key from PEM |
||
18 | $private_key_info = PrivateKeyInfo::fromPEM( |
||
19 | PEM::fromFile(dirname(__DIR__) . "/test/assets/ec/private_key.pem")); |
||
20 | // extract public key from private key |
||
21 | $public_key_info = $private_key_info->publicKeyInfo(); |
||
22 | // DN of the subject |
||
23 | $subject = Name::fromString("cn=example.com, O=Example\, Inc., C=US"); |
||
24 | // create certification request info |
||
25 | $cri = new CertificationRequestInfo($subject, $public_key_info); |
||
26 | // sign certificate request with private key |
||
27 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
||
28 | $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
||
0 ignored issues
–
show
|
|||
29 | $csr = $cri->sign($algo, $private_key_info); |
||
30 | echo $csr; |
||
31 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.