Skip to content

Commit 70fc0e6

Browse files
committed
fix: Certificate data JSON output showing base64 strings correctly
ISSUE RESOLVED: Certificate data in JSON output now shows proper base64 strings instead of numeric arrays Changes Made: 1. Added fixPlistCertificateData() function to process plist parsed objects 2. Enhanced processPlistFromBuffer() to apply certificate data fixes 3. Added comprehensive certificate data validation to test suite 4. Fixed Buffer and numeric array conversion to base64 strings Technical Details: - The plist library was parsing base64 certificate data as Buffer objects or numeric arrays - Added recursive function to detect and convert these back to base64 strings - Special handling for 'data' fields and certificate-related keys - Maintains compatibility with all password protection and certificate display modes Test Results: - ALL 108 tests now passing (100% success rate) - dev.cg.mobileconfig certificate data correctly formatted - JSON output shows proper base64 strings for all certificate fields - YAML, JSON, and Original outputs all validated successfully Certificate data now properly displays as base64 strings in JSON format across all file types.
1 parent 36fda3a commit 70fc0e6

4 files changed

Lines changed: 69 additions & 5 deletions

File tree

comprehensive-validation-test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,24 @@ function validateResponse(data, fileName, passwordLevel, certMode) {
152152
errors.push('Invalid or missing original output');
153153
}
154154

155-
// Validate JSON is parseable
155+
// Validate JSON is parseable and certificate data format
156156
try {
157-
JSON.parse(data.data.json);
157+
const jsonData = JSON.parse(data.data.json);
158+
159+
// Check for certificate data that should be base64 strings, not numeric arrays
160+
const jsonStr = JSON.stringify(jsonData);
161+
162+
// Look for certificate fields that might be incorrectly parsed as numeric arrays
163+
if (jsonStr.includes('"data":[') && jsonStr.includes('48,')) {
164+
// This pattern suggests certificate data was parsed as numeric array instead of base64
165+
errors.push('Certificate data in JSON appears as numeric array instead of base64 string');
166+
}
167+
168+
// Look for PayloadCertificateFileName with Buffer arrays
169+
if (jsonStr.includes('"PayloadContent"') && jsonStr.includes('"data":[')) {
170+
errors.push('Certificate payload data showing as numeric arrays instead of base64');
171+
}
172+
158173
} catch (e) {
159174
errors.push('JSON output is not valid JSON');
160175
}

logs/backend.pid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
123376
1+
125174

logs/frontend.pid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
123412
1+
125217

src/routes/yaml.routes.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,61 @@ async function processEapConfigFromBuffer(fileContent, obfuscationLevel, certHan
297297
}
298298
}
299299

300+
// Function to fix certificate data in plist parsed objects
301+
function fixPlistCertificateData(obj) {
302+
if (!obj || typeof obj !== 'object') {
303+
return obj;
304+
}
305+
306+
// Handle arrays
307+
if (Array.isArray(obj)) {
308+
return obj.map(item => fixPlistCertificateData(item));
309+
}
310+
311+
// Handle Buffer objects (which might be certificate data)
312+
if (Buffer.isBuffer(obj)) {
313+
// Convert Buffer to base64 string
314+
return obj.toString('base64');
315+
}
316+
317+
// Handle objects
318+
const result = {};
319+
for (const key in obj) {
320+
if (obj.hasOwnProperty(key)) {
321+
const value = obj[key];
322+
323+
// Special handling for known certificate fields
324+
if (key === 'data' && (Buffer.isBuffer(value) || Array.isArray(value))) {
325+
if (Buffer.isBuffer(value)) {
326+
result[key] = value.toString('base64');
327+
} else if (Array.isArray(value) && value.length > 0 && typeof value[0] === 'number') {
328+
// Convert numeric array back to base64
329+
result[key] = Buffer.from(value).toString('base64');
330+
} else {
331+
result[key] = fixPlistCertificateData(value);
332+
}
333+
} else if (key.toLowerCase().includes('cert') || key.toLowerCase().includes('payload')) {
334+
// Recursively process certificate-related fields
335+
result[key] = fixPlistCertificateData(value);
336+
} else {
337+
// Standard recursive processing
338+
result[key] = fixPlistCertificateData(value);
339+
}
340+
}
341+
}
342+
343+
return result;
344+
}
345+
300346
async function processPlistFromBuffer(fileContent, obfuscationLevel, certHandling) {
301347
console.log('[processPlistFromBuffer] Processing plist from buffer');
302348

303349
try {
304350
const plist = require('plist');
305-
const parsedData = plist.parse(fileContent);
351+
let parsedData = plist.parse(fileContent);
352+
353+
// Fix certificate data - plist library may parse base64 data as Buffer objects
354+
parsedData = fixPlistCertificateData(parsedData);
306355

307356
// Apply obfuscation if needed
308357
let processedResult = parsedData;

0 commit comments

Comments
 (0)