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

LibreSign / libresign / 20133792614

11 Dec 2025 12:54PM UTC coverage: 43.837%. First build
20133792614

Pull #6095

github

web-flow
Merge d3fde8032 into a8bb48e02
Pull Request #6095: fix: correct parameter order in getUserConfigByKey method

0 of 3 new or added lines in 1 file covered. (0.0%)

5758 of 13135 relevant lines covered (43.84%)

5.12 hits per line

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

18.29
/lib/Service/AccountService.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Service;
10

11
use InvalidArgumentException;
12
use OC\Files\Filesystem;
13
use OCA\Libresign\AppInfo\Application;
14
use OCA\Libresign\Db\File as FileEntity;
15
use OCA\Libresign\Db\FileMapper;
16
use OCA\Libresign\Db\FileTypeMapper;
17
use OCA\Libresign\Db\IdentifyMethodMapper;
18
use OCA\Libresign\Db\SignRequest;
19
use OCA\Libresign\Db\SignRequestMapper;
20
use OCA\Libresign\Db\UserElement;
21
use OCA\Libresign\Db\UserElementMapper;
22
use OCA\Libresign\Exception\InvalidPasswordException;
23
use OCA\Libresign\Exception\LibresignException;
24
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
25
use OCA\Libresign\Handler\SignEngine\Pkcs12Handler;
26
use OCA\Libresign\Helper\ValidateHelper;
27
use OCA\Settings\Mailer\NewUserMailHelper;
28
use OCP\Accounts\IAccountManager;
29
use OCP\AppFramework\Db\DoesNotExistException;
30
use OCP\AppFramework\Utility\ITimeFactory;
31
use OCP\Files\Config\IMountProviderCollection;
32
use OCP\Files\File;
33
use OCP\Files\IMimeTypeDetector;
34
use OCP\Files\IRootFolder;
35
use OCP\Files\NotFoundException;
36
use OCP\Http\Client\IClientService;
37
use OCP\IAppConfig;
38
use OCP\IConfig;
39
use OCP\IGroupManager;
40
use OCP\IL10N;
41
use OCP\IURLGenerator;
42
use OCP\IUser;
43
use OCP\IUserManager;
44
use Sabre\DAV\UUIDUtil;
45
use Throwable;
46

47
class AccountService {
48
        private ?SignRequest $signRequest = null;
49
        private ?\OCA\Libresign\Db\File $fileData = null;
50
        private \OCP\Files\File $fileToSign;
51

52
        public function __construct(
53
                private IL10N $l10n,
54
                private SignRequestMapper $signRequestMapper,
55
                private IUserManager $userManager,
56
                private IAccountManager $accountManager,
57
                private IRootFolder $root,
58
                private IMimeTypeDetector $mimeTypeDetector,
59
                private FileMapper $fileMapper,
60
                private FileTypeMapper $fileTypeMapper,
61
                private SignFileService $signFileService,
62
                private RequestSignatureService $requestSignatureService,
63
                private CertificateEngineFactory $certificateEngineFactory,
64
                private IConfig $config,
65
                private IAppConfig $appConfig,
66
                private IMountProviderCollection $mountProviderCollection,
67
                private NewUserMailHelper $newUserMail,
68
                private IdentifyMethodService $identifyMethodService,
69
                private IdentifyMethodMapper $identifyMethodMapper,
70
                private ValidateHelper $validateHelper,
71
                private IURLGenerator $urlGenerator,
72
                private Pkcs12Handler $pkcs12Handler,
73
                private IGroupManager $groupManager,
74
                private IdDocsService $idDocsService,
75
                private SignerElementsService $signerElementsService,
76
                private UserElementMapper $userElementMapper,
77
                private FolderService $folderService,
78
                private IClientService $clientService,
79
                private ITimeFactory $timeFactory,
80
        ) {
81
        }
48✔
82

83
        public function validateCreateToSign(array $data): void {
84
                if (!UUIDUtil::validateUUID($data['uuid'])) {
1✔
85
                        throw new LibresignException($this->l10n->t('Invalid UUID'), 1);
1✔
86
                }
87
                try {
88
                        $signRequest = $this->getSignRequestByUuid($data['uuid']);
×
89
                } catch (\Throwable) {
×
90
                        throw new LibresignException($this->l10n->t('UUID not found'), 1);
×
91
                }
92
                $identifyMethods = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signRequest->getId());
×
93
                if (!array_key_exists('identify', $data['user'])) {
×
94
                        throw new LibresignException($this->l10n->t('Invalid identification method'), 1);
×
95
                }
96
                foreach ($data['user']['identify'] as $method => $value) {
×
97
                        if (!array_key_exists($method, $identifyMethods)) {
×
98
                                throw new LibresignException($this->l10n->t('Invalid identification method'), 1);
×
99
                        }
100
                        foreach ($identifyMethods[$method] as $identifyMethod) {
×
101
                                $identifyMethod->validateToCreateAccount($value);
×
102
                        }
103
                }
104
                if (empty($data['password'])) {
×
105
                        throw new LibresignException($this->l10n->t('Password is mandatory'), 1);
×
106
                }
107
                $file = $this->getFileByUuid($data['uuid']);
×
108
                if (empty($file['fileToSign'])) {
×
109
                        throw new LibresignException($this->l10n->t('File not found'));
×
110
                }
111
        }
112

113
        public function getFileByUuid(string $uuid): array {
114
                $signRequest = $this->getSignRequestByUuid($uuid);
×
115
                if (!$this->fileData instanceof \OCA\Libresign\Db\File) {
×
116
                        $this->fileData = $this->fileMapper->getById($signRequest->getFileId());
×
117

118
                        $nodeId = $this->fileData->getNodeId();
×
119

120
                        $fileToSign = $this->root->getUserFolder($this->fileData->getUserId())->getFirstNodeById($nodeId);
×
121
                        if ($fileToSign) {
×
122
                                $this->fileToSign = $fileToSign;
×
123
                        }
124
                }
125
                return [
×
126
                        'fileData' => $this->fileData,
×
127
                        'fileToSign' => $this->fileToSign
×
128
                ];
×
129
        }
130

131
        public function validateCertificateData(array $data): void {
132
                if (array_key_exists('email', $data['user']) && empty($data['user']['email'])) {
7✔
133
                        throw new LibresignException($this->l10n->t('You must have an email. You can define the email in your profile.'), 1);
2✔
134
                }
135
                if (!empty($data['user']['email']) && !filter_var($data['user']['email'], FILTER_VALIDATE_EMAIL)) {
5✔
136
                        throw new LibresignException($this->l10n->t('Invalid email'), 1);
2✔
137
                }
138
                if (empty($data['signPassword'])) {
3✔
139
                        throw new LibresignException($this->l10n->t('Password to sign is mandatory'), 1);
1✔
140
                }
141
        }
142

143
        /**
144
         * Get signRequest by Uuid
145
         */
146
        public function getSignRequestByUuid(string $uuid): SignRequest {
147
                if (!$this->signRequest instanceof SignRequest) {
2✔
148
                        $this->signRequest = $this->signRequestMapper->getByUuid($uuid);
2✔
149
                }
150
                return $this->signRequest;
2✔
151
        }
152

153
        public function createToSign(string $uuid, string $email, string $password, ?string $signPassword): void {
154
                $signRequest = $this->getSignRequestByUuid($uuid);
2✔
155

156
                $newUser = $this->userManager->createUser($email, $password);
2✔
157
                $newUser->setDisplayName($signRequest->getDisplayName());
2✔
158
                $newUser->setSystemEMailAddress($email);
2✔
159

160
                $this->updateIdentifyMethodToAccount($signRequest->getId(), $email, $newUser->getUID());
2✔
161

162
                if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
2✔
163
                        try {
164
                                $emailTemplate = $this->newUserMail->generateTemplate($newUser, false);
2✔
165
                                $this->newUserMail->sendMail($newUser, $emailTemplate);
2✔
166
                        } catch (\Exception) {
2✔
167
                                throw new LibresignException('Unable to send the invitation', 1);
2✔
168
                        }
169
                }
170

171
                if ($signPassword) {
×
172
                        $certificate = $this->pkcs12Handler->generateCertificate(
×
173
                                [
×
174
                                        'host' => $newUser->getPrimaryEMailAddress(),
×
175
                                        'uid' => 'account:' . $newUser->getUID(),
×
176
                                        'name' => $newUser->getDisplayName()
×
177
                                ],
×
178
                                $signPassword,
×
179
                                $newUser->getDisplayName()
×
180
                        );
×
181
                        $this->pkcs12Handler->savePfx($newUser->getPrimaryEMailAddress(), $certificate);
×
182
                }
183
        }
184

185
        public function getCertificateEngineName(): string {
186
                return $this->certificateEngineFactory->getEngine()->getName();
×
187
        }
188

189
        /**
190
         * @return array<string, mixed>
191
         */
192
        public function getConfig(?IUser $user = null): array {
193
                $info['identificationDocumentsFlow'] = $this->appConfig->getValueBool(Application::APP_ID, 'identification_documents', false);
×
194
                $info['hasSignatureFile'] = $this->hasSignatureFile($user);
×
195
                $info['phoneNumber'] = $this->getPhoneNumber($user);
×
196
                $info['isApprover'] = $this->validateHelper->userCanApproveValidationDocuments($user, false);
×
197
                $info['id_docs_filters'] = $this->getUserConfigIdDocsFilters($user);
×
198
                $info['id_docs_sort'] = $this->getUserConfigIdDocsSort($user);
×
199
                $info['crl_filters'] = $this->getUserConfigCrlFilters($user);
×
200
                $info['crl_sort'] = $this->getUserConfigCrlSort($user);
×
NEW
201
                $info['grid_view'] = $this->getUserConfigByKey('grid_view', $user) === '1';
×
202

203
                return array_filter($info);
×
204
        }
205

206
        public function getConfigFilters(?IUser $user = null): array {
NEW
207
                $info['filter_modified'] = $this->getUserConfigByKey('filter_modified', $user);
×
NEW
208
                $info['filter_status'] = $this->getUserConfigByKey('filter_status', $user);
×
209

210
                return $info;
×
211
        }
212

213
        private function updateIdentifyMethodToAccount(int $signRequestId, string $email, string $uid): void {
214
                $identifyMethods = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signRequestId);
2✔
215
                foreach ($identifyMethods as $name => $methods) {
2✔
216
                        if ($name === IdentifyMethodService::IDENTIFY_EMAIL) {
×
217
                                foreach ($methods as $identifyMethod) {
×
218
                                        $entity = $identifyMethod->getEntity();
×
219
                                        if ($entity->getIdentifierValue() === $email) {
×
220
                                                $entity->setIdentifierKey(IdentifyMethodService::IDENTIFY_ACCOUNT);
×
221
                                                $entity->setIdentifierValue($uid);
×
222
                                                $this->identifyMethodMapper->update($entity);
×
223
                                        }
224
                                }
225
                        }
226
                }
227
        }
228

229
        private function getPhoneNumber(?IUser $user): string {
230
                if (!$user) {
×
231
                        return '';
×
232
                }
233
                $userAccount = $this->accountManager->getAccount($user);
×
234
                return $userAccount->getProperty(IAccountManager::PROPERTY_PHONE)->getValue();
×
235
        }
236

237
        public function hasSignatureFile(?IUser $user = null): bool {
238
                if (!$user) {
4✔
239
                        return false;
×
240
                }
241
                try {
242
                        $this->pkcs12Handler->getPfxOfCurrentSigner($user->getUID());
4✔
243
                        return true;
×
244
                } catch (LibresignException) {
4✔
245
                        return false;
4✔
246
                }
247
        }
248

249
        private function getUserConfigByKey(string $key, ?IUser $user = null): string {
250
                if (!$user) {
×
251
                        return '';
×
252
                }
253

254
                return $this->config->getUserValue($user->getUID(), Application::APP_ID, $key);
×
255
        }
256

257
        private function getUserConfigIdDocsFilters(?IUser $user = null): array {
258
                if (!$user) {
×
259
                        return [];
×
260
                }
261

262
                $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'id_docs_filters', '');
×
263
                if (empty($value)) {
×
264
                        return [];
×
265
                }
266

267
                $decoded = json_decode($value, true);
×
268
                return is_array($decoded) ? $decoded : [];
×
269
        }
270

271
        private function getUserConfigCrlFilters(?IUser $user = null): array {
272
                if (!$user || !$this->groupManager->isAdmin($user->getUID())) {
×
273
                        return [];
×
274
                }
275

276
                $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'crl_filters', '');
×
277
                if (empty($value)) {
×
278
                        return [];
×
279
                }
280

281
                $decoded = json_decode($value, true);
×
282
                return is_array($decoded) ? $decoded : [];
×
283
        }
284

285
        private function getUserConfigCrlSort(?IUser $user): array {
286
                if (!$user || !$this->groupManager->isAdmin($user->getUID())) {
×
287
                        return ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC'];
×
288
                }
289

290
                $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'crl_sort', '');
×
291
                if (empty($value)) {
×
292
                        return ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC'];
×
293
                }
294

295
                $decoded = json_decode($value, true);
×
296
                return is_array($decoded) ? $decoded : ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC'];
×
297
        }
298

299
        private function getUserConfigIdDocsSort(?IUser $user): array {
300
                if (!$user || !$this->validateHelper->userCanApproveValidationDocuments($user, false)) {
×
301
                        return ['sortBy' => null, 'sortOrder' => null];
×
302
                }
303

304
                $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'id_docs_sort', '');
×
305
                if (empty($value)) {
×
306
                        return ['sortBy' => null, 'sortOrder' => null];
×
307
                }
308

309
                $decoded = json_decode($value, true);
×
310
                return is_array($decoded) ? $decoded : ['sortBy' => null, 'sortOrder' => null];
×
311
        }
312

313
        /**
314
         * Get PDF node by UUID
315
         *
316
         * @psalm-suppress MixedReturnStatement
317
         * @throws Throwable
318
         * @return \OCP\Files\File
319
         */
320
        public function getPdfByUuid(string $uuid): File {
321
                $fileData = $this->fileMapper->getByUuid($uuid);
4✔
322

323
                if (in_array($fileData->getStatus(), [FileEntity::STATUS_PARTIAL_SIGNED, FileEntity::STATUS_SIGNED])) {
4✔
324
                        $nodeId = $fileData->getSignedNodeId();
3✔
325
                } else {
326
                        $nodeId = $fileData->getNodeId();
1✔
327
                }
328
                $file = $this->root->getUserFolder($fileData->getUserId())->getFirstNodeById($nodeId);
4✔
329
                if (!$file instanceof File) {
4✔
330
                        throw new DoesNotExistException('Not found');
×
331
                }
332
                return $file;
4✔
333
        }
334

335
        public function getFileByNodeId(int $nodeId): File {
336
                try {
337
                        return $this->folderService->getFileById($nodeId);
×
338
                } catch (NotFoundException) {
×
339
                        throw new DoesNotExistException('Not found');
×
340
                }
341
        }
342

343
        public function canRequestSign(?IUser $user = null): bool {
344
                if (!$user) {
12✔
345
                        return false;
2✔
346
                }
347
                $authorized = $this->appConfig->getValueArray(Application::APP_ID, 'groups_request_sign', ['admin']);
10✔
348
                if (empty($authorized)) {
10✔
349
                        return false;
2✔
350
                }
351
                $userGroups = $this->groupManager->getUserGroupIds($user);
8✔
352
                if (!array_intersect($userGroups, $authorized)) {
8✔
353
                        return false;
4✔
354
                }
355
                return true;
4✔
356
        }
357

358
        public function getSettings(?IUser $user = null): array {
359
                $return['canRequestSign'] = $this->canRequestSign($user);
4✔
360
                $return['hasSignatureFile'] = $this->hasSignatureFile($user);
4✔
361
                return $return;
4✔
362
        }
363

364
        public function addFilesToAccount(array $files, IUser $user): void {
365
                $this->idDocsService->addIdDocs($files, $user);
×
366
        }
367

368
        public function deleteFileFromAccount(int $nodeId, IUser $user): void {
369
                $this->idDocsService->deleteIdDoc($nodeId, $user);
×
370
        }
371

372
        public function saveVisibleElements(array $elements, string $sessionId, ?IUser $user): void {
373
                foreach ($elements as $element) {
×
374
                        $this->saveVisibleElement($element, $sessionId, $user);
×
375
                }
376
        }
377

378
        public function saveVisibleElement(array $data, string $sessionId, ?IUser $user): void {
379
                if (isset($data['elementId'])) {
×
380
                        $this->updateFileOfVisibleElement($data);
×
381
                        $this->updateDataOfVisibleElement($data);
×
382
                } elseif ($user instanceof IUser) {
×
383
                        $file = $this->saveFileOfVisibleElementUsingUser($data, $user);
×
384
                        $this->insertVisibleElement($data, $user, $file);
×
385
                } else {
386
                        $file = $this->saveFileOfVisibleElementUsingSession($data, $sessionId);
×
387
                }
388
        }
389

390
        private function updateFileOfVisibleElement(array $data): void {
391
                if (!isset($data['file'])) {
×
392
                        return;
×
393
                }
394
                $userElement = $this->userElementMapper->findOne(['id' => $data['elementId']]);
×
395
                $file = $this->folderService->getFileById($userElement->getFileId());
×
396
                $file->putContent($this->getFileRaw($data));
×
397
        }
398

399
        private function updateDataOfVisibleElement(array $data): void {
400
                if (!isset($data['starred'])) {
×
401
                        return;
×
402
                }
403
                $userElement = $this->userElementMapper->findOne(['id' => $data['elementId']]);
×
404
                $userElement->setStarred($data['starred'] ? 1 : 0);
×
405
                $this->userElementMapper->update($userElement);
×
406
        }
407

408
        private function saveFileOfVisibleElementUsingUser(array $data, IUser $user): File {
409
                $rootSignatureFolder = $this->folderService->getFolder();
×
410
                $folderName = $this->folderService->getFolderName($data, $user);
×
411
                $folderToFile = $rootSignatureFolder->newFolder($folderName);
×
412
                return $folderToFile->newFile(UUIDUtil::getUUID() . '.png', $this->getFileRaw($data));
×
413
        }
414

415
        private function saveFileOfVisibleElementUsingSession(array $data, string $sessionId): File {
416
                if (!empty($data['nodeId'])) {
×
417
                        return $this->updateFileOfVisibleElementUsingSession($data, $sessionId);
×
418
                }
419
                return $this->createFileOfVisibleElementUsingSession($data, $sessionId);
×
420
        }
421

422
        private function updateFileOfVisibleElementUsingSession(array $data, string $sessionId): File {
423
                $fileList = $this->signerElementsService->getElementsFromSession();
×
424
                $element = array_filter($fileList, fn (File $element) => $element->getId() === $data['nodeId']);
×
425
                $element = current($element);
×
426
                if (!$element instanceof File) {
×
427
                        throw new \Exception($this->l10n->t('File not found'));
×
428
                }
429
                $element->putContent($this->getFileRaw($data));
×
430
                return $element;
×
431
        }
432

433
        private function createFileOfVisibleElementUsingSession(array $data, string $sessionId): File {
434
                $rootSignatureFolder = $this->folderService->getFolder();
×
435
                $folderName = $sessionId;
×
436
                $folderToFile = $rootSignatureFolder->newFolder($folderName);
×
437
                $filename = implode(
×
438
                        '_',
×
439
                        [
×
440
                                $data['type'],
×
441
                                $this->timeFactory->getDateTime()->getTimestamp(),
×
442
                        ]
×
443
                ) . '.png';
×
444
                return $folderToFile->newFile($filename, $this->getFileRaw($data));
×
445
        }
446

447
        private function insertVisibleElement(array $data, IUser $user, File $file): void {
448
                $userElement = new UserElement();
×
449
                $userElement->setType($data['type']);
×
450
                $userElement->setFileId($file->getId());
×
451
                $userElement->setUserId($user->getUID());
×
452
                $userElement->setStarred(isset($data['starred']) && $data['starred'] ? 1 : 0);
×
453
                $userElement->setCreatedAt($this->timeFactory->getDateTime());
×
454
                $this->userElementMapper->insert($userElement);
×
455
        }
456

457
        private function getFileRaw(array $data): string {
458
                if (!empty($data['file']['url'])) {
×
459
                        if (!filter_var($data['file']['url'], FILTER_VALIDATE_URL)) {
×
460
                                throw new \Exception($this->l10n->t('Invalid URL file'));
×
461
                        }
462
                        $response = $this->clientService->newClient()->get($data['file']['url']);
×
463
                        $contentType = $response->getHeader('Content-Type');
×
464
                        if ($contentType !== 'image/png') {
×
465
                                throw new \Exception($this->l10n->t('Visible element file must be png.'));
×
466
                        }
467
                        $content = (string)$response->getBody();
×
468
                        if (empty($content)) {
×
469
                                throw new \Exception($this->l10n->t('Empty file'));
×
470
                        }
471
                        $this->validateHelper->validateBase64($content, ValidateHelper::TYPE_VISIBLE_ELEMENT_USER);
×
472
                        return $content;
×
473
                }
474
                $this->validateHelper->validateBase64($data['file']['base64'], ValidateHelper::TYPE_VISIBLE_ELEMENT_USER);
×
475
                $withMime = explode(',', (string)$data['file']['base64']);
×
476
                if (count($withMime) === 2) {
×
477
                        $content = base64_decode($withMime[1]);
×
478
                } else {
479
                        $content = base64_decode((string)$data['file']['base64']);
×
480
                }
481
                if (!$content) {
×
482
                        return '';
×
483
                }
484
                return $content;
×
485
        }
486

487
        public function deleteSignatureElement(?IUser $user, string $sessionId, int $nodeId): void {
488
                if ($user instanceof IUser) {
×
489
                        $element = $this->userElementMapper->findOne([
×
490
                                'file_id' => $nodeId,
×
491
                                'user_id' => $user->getUID(),
×
492
                        ]);
×
493
                        $this->userElementMapper->delete($element);
×
494
                        try {
495
                                $file = $this->folderService->getFileById($element->getFileId());
×
496
                                $file->delete();
×
497
                        } catch (NotFoundException) {
×
498
                        }
499
                } else {
500
                        $rootSignatureFolder = $this->folderService->getFolder();
×
501
                        $folderName = $sessionId;
×
502
                        $rootSignatureFolder->delete($folderName);
×
503
                }
504
        }
505

506
        /**
507
         * @throws LibresignException at savePfx
508
         * @throws InvalidArgumentException
509
         */
510
        public function uploadPfx(array $file, IUser $user): void {
511
                if (
512
                        $file['error'] !== 0
×
513
                        || !is_uploaded_file($file['tmp_name'])
×
514
                        || Filesystem::isFileBlacklisted($file['tmp_name'])
×
515
                ) {
516
                        // TRANSLATORS Error when the uploaded certificate file is not valid
517
                        throw new InvalidArgumentException($this->l10n->t('Invalid file provided. Need to be a .pfx file.'));
×
518
                }
519
                if ($file['size'] > 10 * 1024) {
×
520
                        // TRANSLATORS Error when the certificate file is bigger than normal
521
                        throw new InvalidArgumentException($this->l10n->t('File is too big'));
×
522
                }
523
                $content = file_get_contents($file['tmp_name']);
×
524
                $mimetype = $this->mimeTypeDetector->detectString($content);
×
525
                if ($mimetype !== 'application/octet-stream') {
×
526
                        // TRANSLATORS Error when the mimetype of uploaded file is not valid
527
                        throw new InvalidArgumentException($this->l10n->t('Invalid file provided. Need to be a .pfx file.'));
×
528
                }
529
                $extension = strtolower(pathinfo((string)$file['name'], PATHINFO_EXTENSION));
×
530
                if ($extension !== 'pfx') {
×
531
                        // TRANSLATORS Error when the certificate file is not a pfx file
532
                        throw new InvalidArgumentException($this->l10n->t('Invalid file provided. Need to be a .pfx file.'));
×
533
                }
534
                unlink($file['tmp_name']);
×
535
                $this->pkcs12Handler->savePfx($user->getUID(), $content);
×
536
        }
537

538
        public function deletePfx(IUser $user): void {
539
                $this->pkcs12Handler->deletePfx($user->getUID());
×
540
        }
541

542
        /**
543
         * @throws LibresignException when have not a certificate file
544
         */
545
        public function updatePfxPassword(IUser $user, string $current, string $new): void {
546
                try {
547
                        $pfx = $this->pkcs12Handler->updatePassword($user->getUID(), $current, $new);
×
548
                } catch (InvalidPasswordException) {
×
549
                        throw new LibresignException($this->l10n->t('Invalid user or password'));
×
550
                }
551
        }
552

553
        /**
554
         * @throws LibresignException when have not a certificate file
555
         */
556
        public function readPfxData(IUser $user, string $password): array {
557
                try {
558
                        return $this->pkcs12Handler
×
559
                                ->setCertificate($this->pkcs12Handler->getPfxOfCurrentSigner($user->getUID()))
×
560
                                ->setPassword($password)
×
561
                                ->readCertificate();
×
562
                } catch (InvalidPasswordException) {
×
563
                        throw new LibresignException($this->l10n->t('Invalid user or password'));
×
564
                }
565
        }
566
}
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

© 2026 Coveralls, Inc