MCPcopy
hub / github.com/prisma/prisma / getSSLVersion

Function getSSLVersion

packages/get-platform/src/getPlatform.ts:343–403  ·  view source on GitHub ↗
(libsslSpecificPaths: string[])

Source from the content-addressed store, hash-verified

341 * This function never throws.
342 */
343export async function getSSLVersion(libsslSpecificPaths: string[]): Promise<GetOpenSSLVersionResult> {
344 const excludeLibssl0x = 'grep -v "libssl.so.0"'
345 const libsslFilenameFromSpecificPath: string | undefined = await findLibSSLInLocations(libsslSpecificPaths)
346
347 if (libsslFilenameFromSpecificPath) {
348 debug(`Found libssl.so file using platform-specific paths: ${libsslFilenameFromSpecificPath}`)
349 const libsslVersion = parseLibSSLVersion(libsslFilenameFromSpecificPath)
350 debug(`The parsed libssl version is: ${libsslVersion}`)
351 if (libsslVersion) {
352 return { libssl: libsslVersion, strategy: 'libssl-specific-path' }
353 }
354 }
355
356 debug('Falling back to "ldconfig" and other generic paths')
357 let libsslFilename: string | undefined = await getCommandOutput(
358 /**
359 * The `ldconfig -p` returns the dynamic linker cache paths, where libssl.so files are likely to be included.
360 * Each line looks like this:
361 * libssl.so (libc6,hard-float) => /usr/lib/arm-linux-gnueabihf/libssl.so.1.1
362 * But we're only interested in the filename, so we use sed to remove everything before the `=>` separator,
363 * and then we remove the path and keep only the filename.
364 * The second sed commands uses `|` as a separator because the paths may contain `/`, which would result in the
365 * `unknown option to 's'` error (see https://stackoverflow.com/a/9366940/6174476) - which would silently
366 * fail with error code 0.
367 */
368 `ldconfig -p | sed "s/.*=>s*//" | sed "s|.*/||" | grep libssl | sort | ${excludeLibssl0x}`,
369 )
370
371 if (!libsslFilename) {
372 /**
373 * Fall back to the rhel-specific paths (although `familyDistro` isn't detected as rhel) when the `ldconfig` command fails.
374 */
375 libsslFilename = await findLibSSLInLocations(['/lib64', '/usr/lib64', '/lib', '/usr/lib'])
376 }
377
378 if (libsslFilename) {
379 debug(`Found libssl.so file using "ldconfig" or other generic paths: ${libsslFilename}`)
380 const libsslVersion = parseLibSSLVersion(libsslFilename)
381 debug(`The parsed libssl version is: ${libsslVersion}`)
382 if (libsslVersion) {
383 return { libssl: libsslVersion, strategy: 'ldconfig' }
384 }
385 }
386
387 /* Reading the libssl.so version didn't work, fall back to openssl */
388
389 const openSSLVersionLine: string | undefined = await getCommandOutput('openssl version -v')
390
391 if (openSSLVersionLine) {
392 debug(`Found openssl binary with version: ${openSSLVersionLine}`)
393 const openSSLVersion = parseOpenSSLVersion(openSSLVersionLine)
394 debug(`The parsed openssl version is: ${openSSLVersion}`)
395 if (openSSLVersion) {
396 return { libssl: openSSLVersion, strategy: 'openssl-binary' }
397 }
398 }
399
400 /* Reading openssl didn't work */

Callers 2

getosFunction · 0.85

Calls 5

findLibSSLInLocationsFunction · 0.85
debugFunction · 0.85
parseLibSSLVersionFunction · 0.85
getCommandOutputFunction · 0.85
parseOpenSSLVersionFunction · 0.85

Tested by

no test coverage detected