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

LibreSign / libresign / 20270195274

16 Dec 2025 01:49PM UTC coverage: 43.916%. First build
20270195274

Pull #6213

github

web-flow
Merge f664bd983 into 4f46ee6d4
Pull Request #6213: feat: persist signer identify tab preference

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

5923 of 13487 relevant lines covered (43.92%)

5.18 hits per line

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

18.22
/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);
×
201
                $info['grid_view'] = $this->getUserConfigByKey('grid_view', $user) === '1';
×
NEW
202
                $info['signer_identify_tab'] = $this->getUserConfigByKey('signer_identify_tab', $user);
×
203

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

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

211
                return $info;
×
212
        }
213

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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