Subversion Repositories oidplus

Rev

Rev 1072 | Rev 1086 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1072 Rev 1073
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
9
 * You may obtain a copy of the License at
10
 *
10
 *
Line 49... Line 49...
49
                'adminPages',
49
                'adminPages',
50
                'objectTypes',
50
                'objectTypes',
51
                'captcha'
51
                'captcha'
52
        );
52
        );
53
 
53
 
-
 
54
        const UUID_NAMEBASED_NS_Base64PubKey = 'fd16965c-8bab-11ed-8744-3c4a92df8582';
-
 
55
 
54
        private function __construct() {
56
        private function __construct() {
55
        }
57
        }
56
 
58
 
57
        private static function insideSetup(): bool {
59
        private static function insideSetup(): bool {
58
                if (PHP_SAPI == 'cli') return false;
60
                if (PHP_SAPI == 'cli') return false;
Line 1284... Line 1286...
1284
                                return $protocol.'://'.$host.$res.'/';
1286
                                return $protocol.'://'.$host.$res.'/';
1285
                        }
1287
                        }
1286
                }
1288
                }
1287
        }
1289
        }
1288
 
1290
 
1289
        private static function getSystemIdFromPubKey($pubKey) {
1291
        private static function pubKeyToRaw($pubKey) {
1290
                $m = array();
1292
                $m = array();
1291
                if (preg_match('@BEGIN PUBLIC KEY\-+(.+)\-+END PUBLIC KEY@ismU', $pubKey, $m)) {
1293
                if (preg_match('@BEGIN PUBLIC KEY\\-+([^\\-]+)\\-+END PUBLIC KEY@ismU', $pubKey, $m)) {
1292
                        return smallhash(base64_decode($m[1]));
1294
                        return base64_decode($m[1], false);
1293
                }
1295
                }
1294
                return false;
1296
                return false;
1295
        }
1297
        }
1296
 
1298
 
-
 
1299
        private static function getSystemIdFromPubKey($pubKey) {
-
 
1300
                $rawData = self::pubKeyToRaw($pubKey);
-
 
1301
                if ($rawData === false) return false;
-
 
1302
                return smallhash($rawData);
-
 
1303
        }
-
 
1304
 
-
 
1305
        private static function getSystemGuidFromPubKey($pubKey) {
-
 
1306
                $rawData = self::pubKeyToRaw($pubKey);
-
 
1307
                if ($rawData === false) return false;
-
 
1308
                $normalizedBase64 = base64_encode($rawData);
-
 
1309
                return gen_uuid_sha1_namebased(self::UUID_NAMEBASED_NS_Base64PubKey, $normalizedBase64);
-
 
1310
        }
-
 
1311
 
1297
        private static $system_id_cache = null;
1312
        private static $system_id_cache = null;
1298
        public static function getSystemId($oid=false) {
1313
        public static function getSystemId($oid=false) {
1299
                if (!is_null(self::$system_id_cache)) {
1314
                if (!is_null(self::$system_id_cache)) {
1300
                        $out = self::$system_id_cache;
1315
                        $out = self::$system_id_cache;
1301
                } else {
1316
                } else {
Line 1309... Line 1324...
1309
                }
1324
                }
1310
                if (!$out) return false;
1325
                if (!$out) return false;
1311
                return ($oid ? '1.3.6.1.4.1.37476.30.9.' : '').$out;
1326
                return ($oid ? '1.3.6.1.4.1.37476.30.9.' : '').$out;
1312
        }
1327
        }
1313
 
1328
 
-
 
1329
        private static $system_guid_cache = null;
-
 
1330
        public static function getSystemGuid() {
-
 
1331
                if (!is_null(self::$system_guid_cache)) {
-
 
1332
                        $out = self::$system_guid_cache;
-
 
1333
                } else {
-
 
1334
                        $out = false;
-
 
1335
 
-
 
1336
                        if (self::getPkiStatus(true)) {
-
 
1337
                                $pubKey = OIDplus::getSystemPublicKey();
-
 
1338
                                $out = self::getSystemGuidFromPubKey($pubKey);
-
 
1339
                        }
-
 
1340
                        self::$system_guid_cache = $out;
-
 
1341
                }
-
 
1342
                if (!$out) return false;
-
 
1343
                return $out;
-
 
1344
        }
-
 
1345
 
1314
        public static function getOpenSslCnf() {
1346
        public static function getOpenSslCnf() {
1315
                // The following functions need a config file, otherway they don't work
1347
                // The following functions need a config file, otherway they don't work
1316
                // - openssl_csr_new
1348
                // - openssl_csr_new
1317
                // - openssl_csr_sign
1349
                // - openssl_csr_sign
1318
                // - openssl_pkey_export
1350
                // - openssl_pkey_export