-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlePfx.js
46 lines (38 loc) · 2.27 KB
/
handlePfx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
try {
// Extract form data from context variables
var pfxBase64 = context.getVariable('formdata.pfxFile');
var pfxPassword = context.getVariable('formdata.pfxPassword');
var targetUrl = context.getVariable('formdata.targetUrl');
var targetPath = context.getVariable('formdata.targetPath') || '/'; // Default to '/' if not provided
var targetMethod = context.getVariable('formdata.targetMethod') || 'GET'; // Default to 'GET' if not provided
var tlsVersion = context.getVariable('formdata.tlsVersion') || 'TLSv1_2_method'; // Default to TLS 1.2
// Simulate Base64 decoding (replace with actual logic if needed)
var pfxFile = "decoded pfx content"; // Replace with actual Base64 decoding logic
// Simulate PFX file parsing
var keyObj = "dummyPrivateKey"; // Replace with actual key parsing logic
var certObj = "dummyCertificate"; // Replace with actual cert parsing logic
// Validate that both key and certificate are extracted
if (!keyObj || !certObj) {
throw new Error("Invalid PFX file or password. Could not extract key and certificate.");
}
// Dummy DNS Resolution Test (since real DNS lookup is not supported in Apigee JavaScript)
var dnsResolution = "Success: Dummy IP"; // Replace with actual resolution logic if possible
// Dummy Connectivity Test (since real connectivity test is not supported in Apigee JavaScript)
var connectivityTest = "Success"; // Replace with actual connectivity test logic if possible
// Assume TLS handshake success (since real TLS handshake is not supported in Apigee JavaScript)
var tlsHandshake = "Success";
// Set context variables
context.setVariable('dnsResolution', dnsResolution);
context.setVariable('connectivityTest', connectivityTest);
context.setVariable('tlsHandshake', tlsHandshake);
context.setVariable('tlsResponseCode', '200'); // Make sure the code is a string
context.setVariable('tlsResponseMessage', 'OK');
} catch (e) {
// Handle errors
context.setVariable('error', e.message);
context.setVariable('dnsResolution', 'N/A');
context.setVariable('connectivityTest', 'Failed');
context.setVariable('tlsHandshake', 'Failed');
context.setVariable('tlsResponseCode', 'N/A');
context.setVariable('tlsResponseMessage', 'N/A');
}