• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 3717593689

pending completion
3717593689

Pull #1287

github

GitHub
Merge 42fe701e4 into ff8c1edaf
Pull Request #1287: [stable25] Bump packages

2548 of 4384 relevant lines covered (58.12%)

4.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/lib/Handler/CfsslServerHandler.php
1
<?php
2

3
namespace OCA\Libresign\Handler;
4

5
use OCA\Libresign\Exception\LibresignException;
6

7
class CfsslServerHandler {
8
        public const CSR_FILE = 'csr_server.json';
9
        public const CONFIG_FILE = 'config_server.json';
10

11
        public function createConfigServer(
12
                string $commonName,
13
                array $names,
14
                string $key,
15
                string $configPath
16
        ): void {
17
                $this->putCsrServer(
2✔
18
                        $commonName,
2✔
19
                        $names,
2✔
20
                        $configPath
2✔
21
                );
2✔
22
                $this->putConfigServer($key, $configPath);
2✔
23
        }
24

25
        private function putCsrServer(
26
                string $commonName,
27
                array $names,
28
                string $configPath
29
        ): void {
30
                $filename = $configPath . self::CSR_FILE;
2✔
31
                $content = [
2✔
32
                        'CN' => $commonName,
2✔
33
                        'key' => [
2✔
34
                                'algo' => 'rsa',
2✔
35
                                'size' => 2048,
2✔
36
                        ],
2✔
37
                ];
2✔
38
                foreach ($names as $name) {
2✔
39
                        $content['names'][0][$name['id']] = $name['value'];
2✔
40
                }
41
                
42
                $response = file_put_contents($filename, json_encode($content));
2✔
43
                if ($response === false) {
2✔
44
                        throw new LibresignException(
×
45
                                "Error while writing CSR server file.\n" .
×
46
                                "Remove the CFSSL API URI and Config path to use the default values.",
×
47
                                500
×
48
                        );
×
49
                }
50
        }
51

52
        private function putConfigServer(string $key, string $configPath): void {
53
                $filename = $configPath . self::CONFIG_FILE;
2✔
54
                $content = [
2✔
55
                        'signing' => [
2✔
56
                                'profiles' => [
2✔
57
                                        'CA' => [
2✔
58
                                                'auth_key' => 'key1',
2✔
59
                                                'expiry' => '8760h',
2✔
60
                                                'usages' => [
2✔
61
                                                        "signing",
2✔
62
                                                        "digital signature",
2✔
63
                                                        "cert sign"
2✔
64
                                                ],
2✔
65
                                        ],
2✔
66
                                ],
2✔
67
                        ],
2✔
68
                        'auth_keys' => [
2✔
69
                                'key1' => [
2✔
70
                                        'key' => $key,
2✔
71
                                        'type' => 'standard',
2✔
72
                                ],
2✔
73
                        ],
2✔
74
                ];
2✔
75

76
                $response = file_put_contents($filename, json_encode($content));
2✔
77
                if ($response === false) {
2✔
78
                        throw new LibresignException("Error while writing config server file!", 500);
×
79
                }
80
        }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc