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

LibreSign / libresign / 20606755727

30 Dec 2025 09:57PM UTC coverage: 44.923%. First build
20606755727

Pull #6277

github

web-flow
Merge 66a21dab7 into 1098b4452
Pull Request #6277: fix: use nodeId for user element

21 of 56 new or added lines in 9 files covered. (37.5%)

6618 of 14732 relevant lines covered (44.92%)

5.09 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 OCA\Libresign\AppInfo\Application;
13
use OCA\Libresign\Db\File as FileEntity;
14
use OCA\Libresign\Db\FileMapper;
15
use OCA\Libresign\Db\FileTypeMapper;
16
use OCA\Libresign\Db\IdentifyMethodMapper;
17
use OCA\Libresign\Db\SignRequest;
18
use OCA\Libresign\Db\SignRequestMapper;
19
use OCA\Libresign\Db\UserElement;
20
use OCA\Libresign\Db\UserElementMapper;
21
use OCA\Libresign\Exception\InvalidPasswordException;
22
use OCA\Libresign\Exception\LibresignException;
23
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
24
use OCA\Libresign\Handler\SignEngine\Pkcs12Handler;
25
use OCA\Libresign\Helper\FileUploadHelper;
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
                private FileUploadHelper $uploadHelper,
81
        ) {
82
        }
41✔
83

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

212
                return $info;
×
213
        }
214

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

508
        /**
509
         * @throws LibresignException at savePfx
510
         * @throws InvalidArgumentException
511
         */
512
        public function uploadPfx(array $file, IUser $user): void {
513
                try {
514
                        $this->uploadHelper->validateUploadedFile($file);
×
515
                } catch (InvalidArgumentException) {
×
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

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