GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (92)

Security Analysis    no vulnerabilities found

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.

src/CA/EasyRsaCa.php (3 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
/**
4
 * eduVPN - End-user friendly VPN.
5
 *
6
 * Copyright: 2016-2017, The Commons Conservancy eduVPN Programme
7
 * SPDX-License-Identifier: AGPL-3.0+
8
 */
9
10
namespace SURFnet\VPN\Server\CA;
11
12
use RuntimeException;
13
use SURFnet\VPN\Common\Config;
14
use SURFnet\VPN\Common\FileIO;
15
use SURFnet\VPN\Server\CA\Exception\CaException;
16
17
class EasyRsaCa implements CaInterface
18
{
19
    /** @var string */
20
    private $easyRsaDir;
21
22
    /** @var string */
23
    private $easyRsaDataDir;
24
25
    public function __construct($easyRsaDir, $easyRsaDataDir)
26
    {
27
        $this->easyRsaDir = $easyRsaDir;
28
        $this->easyRsaDataDir = $easyRsaDataDir;
29
        FileIO::createDir($this->easyRsaDataDir, 0700);
30
    }
31
32
    /**
33
     * Initialize the CA.
34
     *
35
     * @param \SURFnet\VPN\Common\Config $config the CA configuration
36
     */
37
    public function init(Config $config)
38
    {
39
        // only initialize when unitialized, prevent destroying existing CA
40
        if (!@file_exists(sprintf('%s/vars', $this->easyRsaDataDir))) {
41
            $configData = [
42
                sprintf('set_var EASYRSA "%s"', $this->easyRsaDir),
43
                sprintf('set_var EASYRSA_PKI "%s/pki"', $this->easyRsaDataDir),
44
                sprintf('set_var EASYRSA_KEY_SIZE %d', $config->getSection('CA')->getItem('key_size')),
45
                sprintf('set_var EASYRSA_CA_EXPIRE %d', $config->getSection('CA')->getItem('ca_expire')),
46
                sprintf('set_var EASYRSA_CERT_EXPIRE %d', $config->getSection('CA')->getItem('cert_expire')),
47
                sprintf('set_var EASYRSA_REQ_CN	"%s"', $config->getSection('CA')->getItem('ca_cn')),
48
                'set_var EASYRSA_BATCH "1"',
49
            ];
50
51
            FileIO::writeFile(
52
                sprintf('%s/vars', $this->easyRsaDataDir),
53
                implode(PHP_EOL, $configData).PHP_EOL,
54
                0600
55
            );
56
57
            $this->execEasyRsa(['init-pki']);
58
            $this->execEasyRsa(['build-ca', 'nopass']);
59
        }
60
    }
61
62
    /**
63
     * Get the CA root certificate.
64
     *
65
     * @return string the CA certificate in PEM format
66
     */
67
    public function caCert()
68
    {
69
        $certFile = sprintf('%s/pki/ca.crt', $this->easyRsaDataDir);
70
71
        return $this->readCertificate($certFile);
72
    }
73
74
    /**
75
     * Generate a certificate for the VPN server.
76
     *
77
     * @param string $commonName
78
     *
79
     * @return array the certificate, key in array with keys
80
     *               'cert', 'key', 'valid_from' and 'valid_to'
81
     */
82 View Code Duplication
    public function serverCert($commonName)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        if ($this->hasCert($commonName)) {
85
            throw new CaException(sprintf('certificate with commonName "%s" already exists', $commonName));
86
        }
87
88
        $this->execEasyRsa(['build-server-full', $commonName, 'nopass']);
89
90
        return $this->certInfo($commonName);
91
    }
92
93
    /**
94
     * Generate a certificate for a VPN client.
95
     *
96
     * @param string $commonName
97
     *
98
     * @return array the certificate and key in array with keys 'cert', 'key',
99
     *               'valid_from' and 'valid_to'
100
     */
101 View Code Duplication
    public function clientCert($commonName)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103
        if ($this->hasCert($commonName)) {
104
            throw new CaException(sprintf('certificate with commonName "%s" already exists', $commonName));
105
        }
106
107
        $this->execEasyRsa(['build-client-full', $commonName, 'nopass']);
108
109
        return $this->certInfo($commonName);
110
    }
111
112
    private function certInfo($commonName)
113
    {
114
        $certData = $this->readCertificate(sprintf('%s/pki/issued/%s.crt', $this->easyRsaDataDir, $commonName));
115
        $keyData = $this->readKey(sprintf('%s/pki/private/%s.key', $this->easyRsaDataDir, $commonName));
116
117
        $parsedCert = openssl_x509_parse($certData);
118
119
        return [
120
            'certificate' => $certData,
121
            'private_key' => $keyData,
122
            'valid_from' => $parsedCert['validFrom_time_t'],
123
            'valid_to' => $parsedCert['validTo_time_t'],
124
        ];
125
    }
126
127
    private function readCertificate($certFile)
128
    {
129
        // strip junk before and after actual certificate
130
        $pattern = '/(-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----)/msU';
131
        if (1 !== preg_match($pattern, FileIO::readFile($certFile), $matches)) {
132
            throw new CaException('unable to extract certificate');
133
        }
134
135
        return $matches[1];
136
    }
137
138
    private function readKey($keyFile)
139
    {
140
        // strip whitespace before and after actual key
141
        return trim(
142
            FileIO::readFile($keyFile)
143
        );
144
    }
145
146
    private function hasCert($commonName)
147
    {
148
        return @file_exists(
149
            sprintf(
150
                '%s/pki/issued/%s.crt',
151
                $this->easyRsaDataDir,
152
                $commonName
153
            )
154
        );
155
    }
156
157 View Code Duplication
    private function execEasyRsa(array $argv)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $command = sprintf(
160
            '%s/easyrsa --vars=%s/vars %s >/dev/null 2>/dev/null',
161
            $this->easyRsaDir,
162
            $this->easyRsaDataDir,
163
            implode(' ', $argv)
164
        );
165
166
        exec(
167
            $command,
168
            $commandOutput,
169
            $returnValue
170
        );
171
172
        if (0 !== $returnValue) {
173
            throw new RuntimeException(
174
                sprintf('command "%s" did not complete successfully: "%s"', $command, $commandOutput)
175
            );
176
        }
177
    }
178
}
179