|
14 | 14 | use OCA\Libresign\Handler\CertificateEngine\IEngineHandler; |
15 | 15 | use OCA\Libresign\Helper\ConfigureCheckHelper; |
16 | 16 | use OCA\Libresign\ResponseDefinitions; |
| 17 | +use OCA\Libresign\Service\Certificate\ValidateService; |
17 | 18 | use OCA\Libresign\Service\CertificatePolicyService; |
18 | 19 | use OCA\Libresign\Service\Install\ConfigureCheckService; |
19 | 20 | use OCA\Libresign\Service\Install\InstallService; |
@@ -54,6 +55,7 @@ public function __construct( |
54 | 55 | protected ISession $session, |
55 | 56 | private SignatureBackgroundService $signatureBackgroundService, |
56 | 57 | private CertificatePolicyService $certificatePolicyService, |
| 58 | + private ValidateService $validateService, |
57 | 59 | ) { |
58 | 60 | parent::__construct(Application::APP_ID, $request); |
59 | 61 | $this->eventSource = $this->eventSourceFactory->create(); |
@@ -136,15 +138,14 @@ private function generateCertificate( |
136 | 138 | ): IEngineHandler { |
137 | 139 | $names = []; |
138 | 140 | if (isset($rootCert['names'])) { |
| 141 | + $this->validateService->validateNames($rootCert['names']); |
139 | 142 | foreach ($rootCert['names'] as $item) { |
140 | | - if (empty($item['id'])) { |
141 | | - throw new LibresignException('Parameter id is required!', 400); |
142 | | - } |
143 | | - $names[$item['id']]['value'] = $this->trimAndThrowIfEmpty($item['id'], $item['value']); |
| 143 | + $names[$item['id']]['value'] = trim((string)$item['value']); |
144 | 144 | } |
145 | 145 | } |
| 146 | + $this->validateService->validate('CN', $rootCert['commonName']); |
146 | 147 | $this->installService->generate( |
147 | | - $this->trimAndThrowIfEmpty('commonName', $rootCert['commonName']), |
| 148 | + trim((string)$rootCert['commonName']), |
148 | 149 | $names, |
149 | 150 | $properties, |
150 | 151 | ); |
@@ -177,13 +178,6 @@ public function loadCertificate(): DataResponse { |
177 | 178 | return new DataResponse($certificate); |
178 | 179 | } |
179 | 180 |
|
180 | | - private function trimAndThrowIfEmpty(string $key, $value): string { |
181 | | - if (empty($value)) { |
182 | | - throw new LibresignException("parameter '{$key}' is required!", 400); |
183 | | - } |
184 | | - return trim((string)$value); |
185 | | - } |
186 | | - |
187 | 181 | /** |
188 | 182 | * Check the configuration of LibreSign |
189 | 183 | * |
|
0 commit comments