ssl_certs: add Haiku support (#13761)

This commit is contained in:
alaviss 2020-03-26 13:47:15 +00:00 • committed by GitHub
commit 6162da812a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,6 +49,18 @@ const certificate_paths = [
"/etc/openssl/certs", "/etc/openssl/certs",
] ]
when defined(haiku):
const
B_FIND_PATH_EXISTING_ONLY = 0x4
B_FIND_PATH_DATA_DIRECTORY = 6
proc find_paths_etc(architecture: cstring, baseDirectory: cint,
subPath: cstring, flags: uint32,
paths: var ptr UncheckedArray[cstring],
pathCount: var csize): int32
{.importc, header: "<FindDirectory.h>".}
proc free(p: pointer) {.importc, header: "<stdlib.h>".}
iterator scanSSLCertificates*(useEnvVars = false): string = iterator scanSSLCertificates*(useEnvVars = false): string =
## Scan for SSL/TLS CA certificates on disk. ## Scan for SSL/TLS CA certificates on disk.
## ##
@ -64,13 +76,26 @@ iterator scanSSLCertificates*(useEnvVars = false): string =
yield fn yield fn
else: else:
for p in certificate_paths: when not defined(haiku):
if p.endsWith(".pem") or p.endsWith(".crt"): for p in certificate_paths:
if existsFile(p): if p.endsWith(".pem") or p.endsWith(".crt"):
yield p if existsFile(p):
elif existsDir(p): yield p
for fn in joinPath(p, "*").walkFiles(): elif existsDir(p):
yield fn for fn in joinPath(p, "*").walkFiles():
yield fn
else:
var
paths: ptr UncheckedArray[cstring]
size: csize
let err = find_paths_etc(
nil, B_FIND_PATH_DATA_DIRECTORY, "ssl/CARootCertificates.pem",
B_FIND_PATH_EXISTING_ONLY, paths, size
)
if err == 0:
defer: free(paths)
for i in 0 ..< size:
yield $paths[i]
# Certificates management on windows # Certificates management on windows
# when defined(windows) or defined(nimdoc): # when defined(windows) or defined(nimdoc):