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

LibreSign / libresign / 19892877141

03 Dec 2025 11:52AM UTC coverage: 41.414%. First build
19892877141

Pull #5965

github

web-flow
Merge 33d171749 into 6ee4c16d1
Pull Request #5965: feat: id docs sorting

9 of 29 new or added lines in 4 files covered. (31.03%)

5137 of 12404 relevant lines covered (41.41%)

4.15 hits per line

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

18.5
/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['grid_view'] = $this->getUserConfigGridView($user);
×
198
                $info['id_docs_filters'] = $this->getUserConfigIdDocsFilters($user);
×
NEW
199
                $info['id_docs_sort'] = $this->getUserConfigIdDocsSort($user);
×
200
                $info['crl_filters'] = $this->getUserConfigCrlFilters($user);
×
201
                $info['crl_sort'] = $this->getUserConfigCrlSort($user);
×
202

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

206

207

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

224
        private function getPhoneNumber(?IUser $user): string {
225
                if (!$user) {
×
226
                        return '';
×
227
                }
228
                $userAccount = $this->accountManager->getAccount($user);
×
229
                return $userAccount->getProperty(IAccountManager::PROPERTY_PHONE)->getValue();
×
230
        }
231

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

244
        private function getUserConfigGridView(?IUser $user = null): bool {
245
                if (!$user) {
×
246
                        return false;
×
247
                }
248

249
                return $this->config->getUserValue($user->getUID(), Application::APP_ID, 'grid_view', false) === '1';
×
250
        }
251

252
        private function getUserConfigIdDocsFilters(?IUser $user = null): array {
253
                if (!$user) {
×
254
                        return [];
×
255
                }
256

257
                $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'id_docs_filters', '');
×
258
                if (empty($value)) {
×
259
                        return [];
×
260
                }
261

262
                $decoded = json_decode($value, true);
×
263
                return is_array($decoded) ? $decoded : [];
×
264
        }
265

266
        private function getUserConfigCrlFilters(?IUser $user = null): array {
267
                if (!$user || !$this->groupManager->isAdmin($user->getUID())) {
×
268
                        return [];
×
269
                }
270

271
                $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'crl_filters', '');
×
272
                if (empty($value)) {
×
273
                        return [];
×
274
                }
275

276
                $decoded = json_decode($value, true);
×
277
                return is_array($decoded) ? $decoded : [];
×
278
        }
279

280
        private function getUserConfigCrlSort(?IUser $user): array {
281
                if (!$user || !$this->groupManager->isAdmin($user->getUID())) {
×
282
                        return ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC'];
×
283
                }
284

285
                $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'crl_sort', '');
×
286
                if (empty($value)) {
×
287
                        return ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC'];
×
288
                }
289

290
                $decoded = json_decode($value, true);
×
291
                return is_array($decoded) ? $decoded : ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC'];
×
292
        }
293

294
        private function getUserConfigIdDocsSort(?IUser $user): array {
NEW
295
                if (!$user || !$this->validateHelper->userCanApproveValidationDocuments($user, false)) {
×
NEW
296
                        return ['sortBy' => null, 'sortOrder' => null];
×
297
                }
298

NEW
299
                $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'id_docs_sort', '');
×
NEW
300
                if (empty($value)) {
×
NEW
301
                        return ['sortBy' => null, 'sortOrder' => null];
×
302
                }
303

NEW
304
                $decoded = json_decode($value, true);
×
NEW
305
                return is_array($decoded) ? $decoded : ['sortBy' => null, 'sortOrder' => null];
×
306
        }
307

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

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

330
        public function getFileByNodeId(int $nodeId): File {
331
                try {
332
                        return $this->folderService->getFileById($nodeId);
×
333
                } catch (NotFoundException) {
×
334
                        throw new DoesNotExistException('Not found');
×
335
                }
336
        }
337

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

353
        public function getSettings(?IUser $user = null): array {
354
                $return['canRequestSign'] = $this->canRequestSign($user);
4✔
355
                $return['hasSignatureFile'] = $this->hasSignatureFile($user);
4✔
356
                return $return;
4✔
357
        }
358

359
        public function addFilesToAccount(array $files, IUser $user): void {
360
                $this->idDocsService->addIdDocs($files, $user);
×
361
        }
362

363
        public function deleteFileFromAccount(int $nodeId, IUser $user): void {
364
                $this->idDocsService->deleteIdDoc($nodeId, $user);
×
365
        }
366

367
        public function saveVisibleElements(array $elements, string $sessionId, ?IUser $user): void {
368
                foreach ($elements as $element) {
×
369
                        $this->saveVisibleElement($element, $sessionId, $user);
×
370
                }
371
        }
372

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

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

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

403
        private function saveFileOfVisibleElementUsingUser(array $data, IUser $user): File {
404
                $rootSignatureFolder = $this->folderService->getFolder();
×
405
                $folderName = $this->folderService->getFolderName($data, $user);
×
406
                $folderToFile = $rootSignatureFolder->newFolder($folderName);
×
407
                return $folderToFile->newFile(UUIDUtil::getUUID() . '.png', $this->getFileRaw($data));
×
408
        }
409

410
        private function saveFileOfVisibleElementUsingSession(array $data, string $sessionId): File {
411
                if (!empty($data['nodeId'])) {
×
412
                        return $this->updateFileOfVisibleElementUsingSession($data, $sessionId);
×
413
                }
414
                return $this->createFileOfVisibleElementUsingSession($data, $sessionId);
×
415
        }
416

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

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

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

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

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

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

533
        public function deletePfx(IUser $user): void {
534
                $this->pkcs12Handler->deletePfx($user->getUID());
×
535
        }
536

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

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