This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 attribute certificate. |
||
4 | * |
||
5 | * php ac-example.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\Attribute; |
||
13 | use X501\ASN1\Name; |
||
14 | use X509\AttributeCertificate\AttCertIssuer; |
||
15 | use X509\AttributeCertificate\AttCertValidityPeriod; |
||
16 | use X509\AttributeCertificate\AttributeCertificateInfo; |
||
17 | use X509\AttributeCertificate\Attributes; |
||
18 | use X509\AttributeCertificate\Holder; |
||
19 | use X509\AttributeCertificate\IssuerSerial; |
||
20 | use X509\AttributeCertificate\Attribute\RoleAttributeValue; |
||
21 | use X509\AttributeCertificate\Validation\ACValidationConfig; |
||
22 | use X509\AttributeCertificate\Validation\ACValidator; |
||
23 | use X509\Certificate\TBSCertificate; |
||
24 | use X509\Certificate\Validity; |
||
25 | use X509\Certificate\Extension\AuthorityKeyIdentifierExtension; |
||
26 | use X509\Certificate\Extension\BasicConstraintsExtension; |
||
27 | use X509\Certificate\Extension\KeyUsageExtension; |
||
28 | use X509\Certificate\Extension\SubjectKeyIdentifierExtension; |
||
29 | use X509\Certificate\Extension\TargetInformationExtension; |
||
30 | use X509\Certificate\Extension\Target\TargetName; |
||
31 | use X509\CertificationPath\CertificationPath; |
||
32 | use X509\GeneralName\GeneralNames; |
||
33 | use X509\GeneralName\UniformResourceIdentifier; |
||
34 | |||
35 | require dirname(__DIR__) . "/vendor/autoload.php"; |
||
36 | |||
37 | // CA private key |
||
38 | openssl_pkey_export( |
||
39 | openssl_pkey_new( |
||
40 | ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
||
41 | "private_key_bits" => 2048]), $pkey); |
||
42 | $ca_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
||
43 | |||
44 | // Issuer private key |
||
45 | openssl_pkey_export( |
||
46 | openssl_pkey_new( |
||
47 | ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
||
48 | "private_key_bits" => 2048]), $pkey); |
||
49 | $issuer_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
||
50 | |||
51 | // Holder private key |
||
52 | openssl_pkey_export( |
||
53 | openssl_pkey_new( |
||
54 | ["private_key_type" => OPENSSL_KEYTYPE_RSA, |
||
55 | "private_key_bits" => 2048]), $pkey); |
||
56 | $holder_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey)); |
||
57 | |||
58 | // create trust anchor certificate (self signed) |
||
59 | $tbs_cert = new TBSCertificate( |
||
60 | Name::fromString("cn=CA"), |
||
61 | $ca_private_key->publicKeyInfo(), |
||
62 | Name::fromString("cn=CA"), |
||
63 | Validity::fromStrings("now", "now + 1 year")); |
||
64 | |||
65 | $tbs_cert = $tbs_cert->withRandomSerialNumber() |
||
66 | ->withAdditionalExtensions( |
||
67 | new BasicConstraintsExtension(true, true), |
||
68 | new SubjectKeyIdentifierExtension(false, |
||
69 | $ca_private_key->publicKeyInfo()->keyIdentifier()), |
||
70 | new KeyUsageExtension(true, |
||
71 | KeyUsageExtension::DIGITAL_SIGNATURE | |
||
72 | KeyUsageExtension::KEY_CERT_SIGN)); |
||
73 | |||
74 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
||
75 | $ca_private_key->algorithmIdentifier(), |
||
0 ignored issues
–
show
|
|||
76 | new SHA256AlgorithmIdentifier()); |
||
77 | |||
78 | $ca_cert = $tbs_cert->sign($algo, $ca_private_key); |
||
79 | |||
80 | // create AC issuer certificate |
||
81 | $tbs_cert = new TBSCertificate( |
||
82 | Name::fromString("cn=Issuer"), |
||
83 | $issuer_private_key->publicKeyInfo(), |
||
84 | new Name(), |
||
85 | Validity::fromStrings("now", "now + 6 months")); |
||
86 | |||
87 | $tbs_cert = $tbs_cert->withIssuerCertificate($ca_cert) |
||
88 | ->withRandomSerialNumber() |
||
89 | ->withAdditionalExtensions( |
||
90 | // issuer must not be a CA |
||
91 | new BasicConstraintsExtension(true, false), |
||
92 | new KeyUsageExtension(true, |
||
93 | KeyUsageExtension::DIGITAL_SIGNATURE | |
||
94 | KeyUsageExtension::KEY_ENCIPHERMENT)); |
||
95 | |||
96 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
||
97 | $ca_private_key->algorithmIdentifier(), |
||
0 ignored issues
–
show
$ca_private_key->algorithmIdentifier() of type object<Sop\CryptoTypes\A...lgorithmIdentifierType> is not a sub-type of object<Sop\CryptoTypes\A...ptoAlgorithmIdentifier> . It seems like you assume a child interface of the interface Sop\CryptoTypes\Algorith...AlgorithmIdentifierType to be always present.
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. ![]() |
|||
98 | new SHA256AlgorithmIdentifier()); |
||
99 | |||
100 | $issuer_cert = $tbs_cert->sign($algo, $ca_private_key); |
||
101 | |||
102 | // create AC holder certificate |
||
103 | $tbs_cert = new TBSCertificate( |
||
104 | Name::fromString("cn=Holder, gn=John, sn=Doe"), |
||
105 | $holder_private_key->publicKeyInfo(), |
||
106 | new Name(), |
||
107 | Validity::fromStrings("now", "now + 6 months")); |
||
108 | |||
109 | $tbs_cert = $tbs_cert->withIssuerCertificate($ca_cert) |
||
110 | ->withRandomSerialNumber() |
||
111 | ->withAdditionalExtensions( |
||
112 | new BasicConstraintsExtension(true, false), |
||
113 | new KeyUsageExtension(true, |
||
114 | KeyUsageExtension::DIGITAL_SIGNATURE | |
||
115 | KeyUsageExtension::KEY_ENCIPHERMENT)); |
||
116 | |||
117 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
||
118 | $ca_private_key->algorithmIdentifier(), |
||
0 ignored issues
–
show
$ca_private_key->algorithmIdentifier() of type object<Sop\CryptoTypes\A...lgorithmIdentifierType> is not a sub-type of object<Sop\CryptoTypes\A...ptoAlgorithmIdentifier> . It seems like you assume a child interface of the interface Sop\CryptoTypes\Algorith...AlgorithmIdentifierType to be always present.
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. ![]() |
|||
119 | new SHA256AlgorithmIdentifier()); |
||
120 | |||
121 | $holder_cert = $tbs_cert->sign($algo, $ca_private_key); |
||
122 | |||
123 | // named authority that grants the attributes |
||
124 | $authority = new GeneralNames( |
||
125 | new UniformResourceIdentifier("uri:trusted_authority")); |
||
126 | // role attribute |
||
127 | $attribs = new Attributes( |
||
128 | Attribute::fromAttributeValues( |
||
129 | RoleAttributeValue::fromString("role-name", $authority))); |
||
130 | $aci = new AttributeCertificateInfo( |
||
131 | // holder is identified by the holder's public key certificate |
||
132 | new Holder(IssuerSerial::fromPKC($holder_cert)), |
||
133 | AttCertIssuer::fromPKC($issuer_cert), |
||
134 | AttCertValidityPeriod::fromStrings("now - 1 hour", "now + 3 months"), |
||
135 | $attribs); |
||
136 | $aci = $aci->withRandomSerialNumber() |
||
137 | ->withAdditionalExtensions( |
||
138 | // named target identifier |
||
139 | TargetInformationExtension::fromTargets( |
||
140 | new TargetName( |
||
141 | new UniformResourceIdentifier("uri:target_identifier"))), |
||
142 | // key identifier of the AC issuer |
||
143 | new AuthorityKeyIdentifierExtension(false, |
||
144 | $issuer_cert->tbsCertificate() |
||
145 | ->subjectPublicKeyInfo() |
||
146 | ->keyIdentifier())); |
||
147 | |||
148 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
||
149 | $issuer_private_key->algorithmIdentifier(), |
||
0 ignored issues
–
show
$issuer_private_key->algorithmIdentifier() of type object<Sop\CryptoTypes\A...lgorithmIdentifierType> is not a sub-type of object<Sop\CryptoTypes\A...ptoAlgorithmIdentifier> . It seems like you assume a child interface of the interface Sop\CryptoTypes\Algorith...AlgorithmIdentifierType to be always present.
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. ![]() |
|||
150 | new SHA256AlgorithmIdentifier()); |
||
151 | |||
152 | $ac = $aci->sign($algo, $issuer_private_key); |
||
153 | |||
154 | // validate AC |
||
155 | $holder_path = new CertificationPath($ca_cert, $holder_cert); |
||
156 | $issuer_path = new CertificationPath($ca_cert, $issuer_cert); |
||
157 | $validator_config = new ACValidationConfig($holder_path, $issuer_path); |
||
158 | |||
159 | // targetting must match |
||
160 | $target = new TargetName(new UniformResourceIdentifier("uri:target_identifier")); |
||
161 | $validator_config = $validator_config->withTargets($target); |
||
162 | $validator = new ACValidator($ac, $validator_config); |
||
163 | |||
164 | if ($validator->validate()) { |
||
165 | fprintf(STDERR, "AC validation succeeded.\n"); |
||
166 | } |
||
167 | |||
168 | fprintf(STDERR, "Root certificate:\n"); |
||
169 | echo "$ca_cert\n"; |
||
170 | |||
171 | fprintf(STDERR, "Issuer certificate:\n"); |
||
172 | echo "$issuer_cert\n"; |
||
173 | |||
174 | fprintf(STDERR, "Holder certificate:\n"); |
||
175 | echo "$holder_cert\n"; |
||
176 | |||
177 | fprintf(STDERR, "Attribute certificate:\n"); |
||
178 | echo "$ac\n"; |
||
179 |
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.