]> git.joonet.de Git - adminer.git/commitdiff
Verify if adminer.version was created on www.adminer.org
authorJakub Vrana <jakub@vrana.cz>
Wed, 24 Jan 2018 14:10:44 +0000 (15:10 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 24 Jan 2018 14:10:44 +0000 (15:10 +0100)
adminer/include/design.inc.php
adminer/script.inc.php
adminer/static/functions.js

index 8d8106e0427e8538dbcc75d1c155107d49a99042..28b159c6b11c392f2e1e3d9b76171c2cad78deaa 100644 (file)
@@ -35,8 +35,21 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
 <body class="<?php echo lang('ltr'); ?> nojs">
 <?php
        $filename = get_temp_dir() . "/adminer.version";
-       if (!$_COOKIE["adminer_version"] && file_exists($filename) && filemtime($filename) + 86400 > time()) { // 86400 - 1 day in seconds
-               $_COOKIE["adminer_version"] = file_get_contents($filename); // doesn't need to send to the browser
+       if (!$_COOKIE["adminer_version"] && function_exists('openssl_verify') && file_exists($filename) && filemtime($filename) + 86400 > time()) { // 86400 - 1 day in seconds
+               $version = unserialize(file_get_contents($filename));
+               $public = "-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwqWOVuF5uw7/+Z70djoK
+RlHIZFZPO0uYRezq90+7Amk+FDNd7KkL5eDve+vHRJBLAszF/7XKXe11xwliIsFs
+DFWQlsABVZB3oisKCBEuI71J4kPH8dKGEWR9jDHFw3cWmoH3PmqImX6FISWbG3B8
+h7FIx3jEaw5ckVPVTeo5JRm/1DZzJxjyDenXvBQ/6o9DgZKeNDgxwKzH+sw9/YCO
+jHnq1cFpOIISzARlrHMa/43YfeNRAm/tsBXjSxembBPo7aQZLAWHmaj5+K19H10B
+nCpz9Y++cipkVEiKRGih4ZEvjoFysEOdRLj6WiD/uUNky4xGeA6LaJqh5XpkFkcQ
+fQIDAQAB
+-----END PUBLIC KEY-----
+";
+               if (openssl_verify($version["version"], base64_decode($version["signature"]), $public) == 1) {
+                       $_COOKIE["adminer_version"] = $version["version"]; // doesn't need to send to the browser
+               }
        }
        ?>
 <script<?php echo nonce(); ?>>
index 0f896b436be64de640fb2aa7330b02d928f1bd67..51f0534d6d65063eebdc82842d5fb53e96442d2c 100644 (file)
@@ -37,7 +37,7 @@ if ($_GET["script"] == "db") {
 } elseif ($_GET["script"] == "version") {
        $fp = file_open_lock(get_temp_dir() . "/adminer.version");
        if ($fp) {
-               file_write_unlock($fp, $_POST["version"]);
+               file_write_unlock($fp, serialize(array("signature" => $_POST["signature"], "version" => $_POST["version"])));
        }
 
 } else { // connect
index b2f39cceae82b9622e46b058ed05300842d0944e..05b62fcd4bb006a6ac50fb48677604a3c0b75ffd 100644 (file)
@@ -115,7 +115,7 @@ function verifyVersion(current, url, token) {
                                if (match) {
                                        cookie('adminer_version=' + match[1], 1);
                                        ajax(url + 'script=version', function () {
-                                       }, 'version=' + match[1] + '&token=' + token);
+                                       }, event.data + '&token=' + token);
                                }
                        }
                }, false);