Commit graph

123 commits

Author SHA1 Message Date
Vitor Mattos
73615a77d4
fix: use correct Nextcloud instanceid in PKI path initialization
The initializePkiConfigPath method was using a variable named
'instanceId' from getSystemValue('instanceid') which could be confused
with LibreSign's instance_id. Changed to 'systemInstanceId' for clarity
and consistency with getConfigPathByParams method.

This ensures the PKI directories are created in the correct appdata path
using Nextcloud's system instance ID, while the directory name itself
contains LibreSign's CA identifier with its own instance ID.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-17 02:36:56 -03:00
Vitor Mattos
3d4bdf0294
fix: filter CA ID from OU only when certificate not generated
The CA ID (libresign-ca-id:...) in OrganizationalUnit should only be
filtered out when the certificate is not generated (isSetupOk() returns
false). When the certificate is successfully generated, the CA ID must
be preserved in the API response.

This ensures:
- Generated certificates: CA ID is visible (expected behavior)
- Failed/not generated: CA ID is filtered to prevent stale data in form

Integration tests validated:
- features/account/signature.feature:2 (OpenSSL)
- features/account/signature.feature:23 (CFSSL)
- features/admin/certificate_openssl.feature:2
- features/admin/certificate_openssl.feature:35

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 17:39:24 -03:00
Vitor Mattos
249f0837b0
fix: prevent stale configPath and CA ID exposure in root certificate API
Filter configPath from API response when certificate is not generated to prevent
form pre-population with outdated generation numbers that cause validation errors.

Filter CA ID (libresign-ca-id:*) from OrganizationalUnit field to prevent users
from submitting stale generation values that conflict with certificate validation.

Refactor toArray() method by extracting logic into dedicated methods:
- getConfigPathForApi(): Returns empty string for non-generated certificates
- removeCaIdFromOrganizationalUnit(): Filters CA IDs from OU arrays

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-15 16:57:17 -03:00
Vitor Mattos
ca05fe55f2
feat: add setEngine method to configure identify methods
Add setEngine() method to IEngineHandler interface and implement
in AEngineHandler to automatically configure identify methods based
on certificate engine selection.

When engine is 'none', only account identification is enabled since
no certificate infrastructure is available for other methods.

Related to #5145

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-09 12:42:00 -03:00
Vitor Mattos
754fc024f0
feat: improve error messages for revoked/expired root certificates
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-02 10:31:48 -03:00
Vitor Mattos
f2b699f8e2
feat: validate root cert validity at config page
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 16:32:51 -03:00
Vitor Mattos
b5074c5086
fix: prevent error when directory does not exsits
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 16:11:45 -03:00
Vitor Mattos
fa79baf0a9
chore: error handler
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 15:47:37 -03:00
Vitor Mattos
1e72bc83b6
chore: remove docblock
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 15:45:32 -03:00
Vitor Mattos
f34df31452
chore: use full FQCN
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 15:44:38 -03:00
Vitor Mattos
d9e0ed2bca
fix: silently skip validation when root certificate is not configured
- Return early without throwing exception if ca.pem doesn't exist
- Return early if certificate file is empty
- Only validate when a proper root certificate is actually configured
- Fixes Pkcs7HandlerTest and Pkcs12HandlerTest that run without CA setup

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 15:41:58 -03:00
Vitor Mattos
5ac4f41118
fix: add Override attribute to validateRootCertificate method
Fixes Psalm static analysis error MissingOverrideAttribute

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 15:04:03 -03:00
Vitor Mattos
b3212d099b
fix: make root certificate validation optional for unconfigured environments
- Return early if configPath is empty (test environments without CA)
- Still throw exception if CA path exists but certificate is missing/empty
- Prevents validation errors in unit tests without breaking production validation
- Fixes Pkcs7HandlerTest and Pkcs12HandlerTest failures

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 14:58:10 -03:00
Vitor Mattos
5db3867990
fix: cs
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 14:53:46 -03:00
Vitor Mattos
33a0289aed
feat: implement root certificate validation logic
- Add validateRootCertificate() method to check certificate health
- Verify certificate is not revoked via CRL
- Verify certificate has not expired
- Check if renewal is needed based on remaining validity
- Calculate renewal timing: remaining_days <= leaf_expiry_days
- Log warnings when renewal is recommended
- Throw LibresignException with clear messages on critical issues

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-12-01 14:46:46 -03:00
Vitor Mattos
1019231caf
Merge pull request #5854 from LibreSign/refactor/remove-pem-fallback-crl-command
refactor: remove PEM fallback from CRL command
2025-11-29 14:10:02 -03:00
Vitor Mattos
c5a2cd959c
refactor: remove PEM fallback from CRL command
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-29 13:53:50 -03:00
Vitor Mattos
c7fee441f2
fix: crl serial number without zeros at left side
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-29 13:51:45 -03:00
Vitor Mattos
c7bdba7718
chore: unify parser
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-25 17:48:47 -03:00
Vitor Mattos
73f784e0db
fix: prevent do not generate crl
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-25 17:04:05 -03:00
Vitor Mattos
9d0c00cf68
fix: prevent issues when valdiate serial number in CRL
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-25 16:42:35 -03:00
Vitor Mattos
83a1aadc8d
fix: serial number format
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 21:29:25 -03:00
Vitor Mattos
2a2632e426
chore: improve error handler
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 21:28:29 -03:00
Vitor Mattos
78a44bdcc9
fix: consider url with index.php
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 21:27:57 -03:00
Vitor Mattos
ae74a735f0
fix: prevent warnings
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 20:50:32 -03:00
Vitor Mattos
c20187cc27
fix: removed unused argument
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 18:46:32 -03:00
Vitor Mattos
cda110a07e
fix: date format
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 18:14:45 -03:00
Vitor Mattos
fbef120cc7
fix: namespace
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 15:05:19 -03:00
Vitor Mattos
d93fe5da36
chore: use phpseclib from main composer
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 14:58:36 -03:00
Vitor Mattos
e2dc0a8d5b
chore: increase perfomance
Only load CRL by URL when is necessary

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 12:28:18 -03:00
Vitor Mattos
d6f95faaa2
fix: cast to prevent error
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 12:28:18 -03:00
Vitor Mattos
cb453afdc4
fix: cs
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 12:28:18 -03:00
Vitor Mattos
7fd2cb184c
fix: make to work with OpenSSL and CFSSL
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 12:28:18 -03:00
Vitor Mattos
d5b7cb39f3
chore: promote method
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 12:28:18 -03:00
Vitor Mattos
2a1d07d5bb
feat: parse crl
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-24 12:28:18 -03:00
Vitor Mattos
2c7e5e7d6b
chore: generate crl by root cert
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-06 01:00:14 -03:00
Vitor Mattos
89ddd6981a
chore: consider instanceId and generation to get CRL
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 21:16:58 -03:00
Vitor Mattos
91afdfaf48
chore: rename method
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 21:14:00 -03:00
Vitor Mattos
adfafab73a
fix: use escapeshellarg
https://github.com/LibreSign/libresign/pull/5754#discussion_r2496304692

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 19:48:16 -03:00
Vitor Mattos
7546a19228
fix: changes from code review
https://github.com/LibreSign/libresign/pull/5754#discussion_r2496241294

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 18:37:18 -03:00
Vitor Mattos
b35f453014
fix: genereate instanceId if does'n exists
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 18:22:48 -03:00
Vitor Mattos
ecd6b76069
fix: add condition to verify if ca_id exists
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 17:21:48 -03:00
Vitor Mattos
09f5bd31b1
fix: prevent psalm issue
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 13:49:44 -03:00
Vitor Mattos
800adf5503
feat: preserve previous root cert
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 13:40:24 -03:00
Vitor Mattos
519b3c7d6b
chore: rename method to prevent misunderstanding with Nextcloud instance id
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-05 13:25:20 -03:00
Vitor Mattos
904f89e48b
chore: replace libresign-ca-uuid by libresign-ca-id
The field is an ID not an UUID

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-04 11:39:27 -03:00
Vitor Mattos
600dc90d98
feat: split all items with comma as array
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-04 10:40:59 -03:00
Vitor Mattos
1335ef2b62
chore: replace pipe by comma
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-04 10:38:17 -03:00
Vitor Mattos
db74665491
fix: convert back to array
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-03 14:56:24 -03:00
Vitor Mattos
66f3d14c8a
fix: typo
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
2025-11-03 14:39:09 -03:00