| 80 | }; |
| 81 | |
| 82 | function assertCertPaths(key, cert, ca, basePath) { |
| 83 | const certObj = {}; |
| 84 | certObj.paths = {}; |
| 85 | certObj.certs = {}; |
| 86 | if (key) { |
| 87 | const keypath = key.startsWith('/') ? key : `${basePath}/${key}`; |
| 88 | assert.doesNotThrow(() => |
| 89 | fs.accessSync(keypath, fs.F_OK | fs.R_OK), |
| 90 | `File not found or unreachable: ${keypath}`); |
| 91 | certObj.paths.key = keypath; |
| 92 | certObj.certs.key = fs.readFileSync(keypath, 'ascii'); |
| 93 | } |
| 94 | if (cert) { |
| 95 | const certpath = cert.startsWith('/') ? cert : `${basePath}/${cert}`; |
| 96 | assert.doesNotThrow(() => |
| 97 | fs.accessSync(certpath, fs.F_OK | fs.R_OK), |
| 98 | `File not found or unreachable: ${certpath}`); |
| 99 | certObj.paths.cert = certpath; |
| 100 | certObj.certs.cert = fs.readFileSync(certpath, 'ascii'); |
| 101 | } |
| 102 | |
| 103 | if (ca) { |
| 104 | const capath = ca.startsWith('/') ? ca : `${basePath}/${ca}`; |
| 105 | assert.doesNotThrow(() => |
| 106 | fs.accessSync(capath, fs.F_OK | fs.R_OK), |
| 107 | `File not found or unreachable: ${capath}`); |
| 108 | certObj.paths.ca = capath; |
| 109 | certObj.certs.ca = fs.readFileSync(capath, 'ascii'); |
| 110 | } |
| 111 | return certObj; |
| 112 | } |
| 113 | |
| 114 | function parseSproxydConfig(configSproxyd) { |
| 115 | const joiSchema = joi.object({ |