Issues (19)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

examples/ac-example.php (4 issues)

Upgrade to new PHP Analysis Engine

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
$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.

Loading history...
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.

Loading history...
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.

Loading history...
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.

Loading history...
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