Commit ad942f0
committed
chore: Refactor certificate chain processing with robust ordering algorithm and validation
- **Certificate Ordering (OrderCertificatesTrait):**
- Implement new leaf-first ordering algorithm with proper chain building
- Add Distinguished Name normalization for reliable certificate comparison
- Introduce comprehensive chain validation with `validateCertificateChain()`
- Handle complex multi-level certificate hierarchies and edge cases
- Improve error handling with detailed validation messages
- **PDF Signature Processing (Pkcs12Handler):**
- Refactor `getCertificateChain()` method with extracted helper functions
- Improve TSA timestamp processing and certificate chain extraction
- Clean up code organization and remove unnecessary comments
- Enhance certificate data enrichment from Poppler utilities
- **Test Coverage Improvements:**
- Add 300+ lines of comprehensive test cases covering real-world scenarios
- Include banking, corporate, and e-commerce certificate chain examples
- Add validation tests for complete, incomplete, and invalid chains
- Refactor Pkcs12Handler tests to focus on public interface without reflection
- Remove excessive mocking in favor of behavioral testing
- **Code Quality:**
- Follow best practices by testing only public methods
- Eliminate reflection-based testing for better maintainability
- Improve test reliability and reduce brittleness to internal changes
- Clean up code structure and remove redundant documentation
This enhancement significantly improves certificate chain handling reliability
for digital signature validation in LibreSign, with comprehensive test
coverage ensuring robustness across various PKI scenarios.
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>1 parent 24c45fa commit ad942f0
4 files changed
Lines changed: 795 additions & 166 deletions
File tree
- lib/Handler
- CertificateEngine
- SignEngine
- tests/php/Unit/Handler
- CertificateEngine
- SignEngine
Lines changed: 121 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
17 | 32 | | |
18 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
19 | 48 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
23 | 52 | | |
24 | | - | |
25 | 53 | | |
26 | 54 | | |
27 | | - | |
28 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
29 | 58 | | |
| 59 | + | |
30 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
31 | 68 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
42 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
43 | 81 | | |
44 | | - | |
45 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
46 | 87 | | |
47 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
48 | 114 | | |
49 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
50 | 122 | | |
51 | 123 | | |
52 | | - | |
| 124 | + | |
53 | 125 | | |
54 | | - | |
| 126 | + | |
55 | 127 | | |
56 | 128 | | |
57 | 129 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
62 | 134 | | |
63 | 135 | | |
64 | 136 | | |
65 | | - | |
66 | | - | |
67 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
68 | 145 | | |
| 146 | + | |
69 | 147 | | |
70 | 148 | | |
71 | | - | |
72 | | - | |
73 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
74 | 160 | | |
75 | | - | |
| 161 | + | |
76 | 162 | | |
77 | 163 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 29 | | |
33 | 30 | | |
34 | 31 | | |
| |||
58 | 55 | | |
59 | 56 | | |
60 | 57 | | |
61 | | - | |
62 | 58 | | |
63 | | - | |
64 | 59 | | |
65 | | - | |
66 | 60 | | |
67 | 61 | | |
68 | 62 | | |
| |||
85 | 79 | | |
86 | 80 | | |
87 | 81 | | |
88 | | - | |
89 | 82 | | |
| 83 | + | |
| 84 | + | |
90 | 85 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
100 | 119 | | |
| 120 | + | |
| 121 | + | |
101 | 122 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
110 | 146 | | |
| 147 | + | |
111 | 148 | | |
112 | | - | |
113 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
114 | 164 | | |
| 165 | + | |
115 | 166 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 167 | + | |
| 168 | + | |
139 | 169 | | |
140 | | - | |
141 | 170 | | |
142 | 171 | | |
143 | 172 | | |
| |||
167 | 196 | | |
168 | 197 | | |
169 | 198 | | |
170 | | - | |
171 | 199 | | |
172 | 200 | | |
173 | 201 | | |
| |||
0 commit comments