Skip to content

Commit c5b090f

Browse files
authored
Revert "improve ssh key validation (#163)"
This reverts commit cf60e7a.
1 parent cf60e7a commit c5b090f

File tree

7 files changed

+13
-67
lines changed

7 files changed

+13
-67
lines changed

.github/workflows/phpunit.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,5 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
10-
- name: setup PHP
11-
uses: shivammathur/setup-php@v2
12-
with:
13-
php-version: "8.3"
14-
# php extensions also listed in tools/docker-dev/web/Dockerfile
15-
extensions: curl,mysql,ldap,pdo,redis
16-
tools: composer:v2
17-
- name: Install dependencies
18-
run: composer install --prefer-dist --no-progress
19-
- name: Run PHPUnit tests
20-
run: vendor/bin/phpunit
10+
- uses: php-actions/composer@v6
11+
- uses: php-actions/phpunit@v3

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
"phpseclib/phpseclib": "3.0.43",
55
"phpmailer/phpmailer": "6.6.4",
66
"hakasapl/phpopenldaper": "1.0.5"
7-
},
8-
"require-dev": {
9-
"phpunit/phpunit": "<12.1"
107
}
118
}

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<!-- restrictWarnings="true" -->
21
<phpunit
32
bootstrap="test/unit/bootstrap.php"
43
failOnWarning="true"
54
failOnDeprecation="true"
65
failOnNotice="true"
6+
restrictWarnings="true"
77
>
88
<testsuites>
99
<testsuite name="unit">

resources/lib/UnitySite.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ public static function getGithubKeys($username)
5252

5353
public static function testValidSSHKey($key_str)
5454
{
55-
$key_str = trim($key_str);
56-
if ($key_str == "") {
57-
return false;
58-
}
59-
// PHP warning when key_str is digits: Attempt to read property "keys" on int
60-
if (preg_match("/^[0-9]+$/", $key_str)) {
61-
return false;
62-
}
63-
// PHP warning when key_str is JSON: Undefined property: stdClass::$keys
64-
if (!is_null(@json_decode($key_str))) {
65-
return false;
66-
}
6755
try {
6856
PublicKeyLoader::load($key_str);
6957
return true;

test/unit/AjaxSshValidateTest.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

tools/docker-dev/web/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ FROM ubuntu:20.04
22

33
# Web Server Setup
44
ARG DEBIAN_FRONTEND=noninteractive
5-
# php extensions also listed in .github/workflows/phpunit.yml
65
RUN apt-get update && apt-get install -y \
76
apache2 \
87
apache2-utils \
@@ -24,4 +23,4 @@ RUN sed -i '/display_errors/c\display_errors = on' /etc/php/7.4/apache2/php.ini
2423
# Start apache2 server
2524
EXPOSE 80
2625

27-
CMD ["apache2ctl", "-D", "FOREGROUND"]
26+
CMD ["apache2ctl", "-D", "FOREGROUND"]

webroot/js/ajax/ssh_validate.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22

3-
require_once __DIR__ . "/../../../resources/lib/UnitySite.php";
4-
use UnityWebPortal\lib\UnitySite;
3+
require "../../../resources/autoload.php";
54

6-
echo UnitySite::testValidSSHKey($_POST["key"]) ? "true" : "false";
5+
use phpseclib3\Crypt\PublicKeyLoader;
6+
7+
try {
8+
PublicKeyLoader::load($_POST['key'], $password = false);
9+
echo "true";
10+
} catch (Exception $e) {
11+
echo "false";
12+
}

0 commit comments

Comments
 (0)