Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit c913545

Browse files
authored
Fix another bug
1 parent 97871e2 commit c913545

1 file changed

Lines changed: 12 additions & 20 deletions

File tree

Sources/prostore/install/GenerateCert.swift

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -319,34 +319,26 @@ public final class GenerateCert {
319319

320320
// Simpler version that doesn't use deprecated stack functions
321321
private static func addSubjectAltName_IP(cert: OpaquePointer, ip: String) throws {
322-
guard let conf = NCONF_new(nil) else {
323-
throw CertGenError.sanCreationFailed("NCONF_new failed")
324-
}
325-
defer { NCONF_free(conf) }
326-
327-
// Create a minimal conf with just the SAN section
328-
let confString = """
329-
[san]
330-
IP.1 = \(ip)
331-
"""
332-
if NCONF_load_bio(conf, BIO_new_mem_buf(confString, -1), nil) <= 0 {
333-
throw CertGenError.sanCreationFailed("NCONF_load_bio failed")
334-
}
335-
336-
var ctx: OpaquePointer?
322+
let sanString = "IP:\(ip)"
323+
let cSanString = sanString.cString(using: .utf8)!
324+
325+
var ctx = X509V3_CTX()
337326
X509V3_set_ctx(&ctx, cert, cert, nil, nil, 0)
338-
X509V3_set_nconf(ctx, conf)
339-
340-
guard let ext = X509V3_EXT_nconf_nid(nil, ctx, NID_subject_alt_name, "san") else {
327+
X509V3_set_nconf(&ctx, nil)
328+
329+
guard let ext = X509V3_EXT_nconf_nid(nil, &ctx, NID_subject_alt_name, cSanString) else {
341330
let err = ERR_get_error()
342331
let reason = ERR_reason_error_string(err)
343-
throw CertGenError.sanCreationFailed("X509V3_EXT_nconf_nid failed: \(reason ?? "unknown")")
332+
let reasonStr = reason != nil ? String(cString: reason!) : "unknown"
333+
throw CertGenError.sanCreationFailed("SAN failed: \(reasonStr)")
344334
}
345335
defer { X509_EXTENSION_free(ext) }
346-
336+
347337
guard X509_add_ext(cert, ext, -1) != 0 else {
348338
throw CertGenError.sanCreationFailed("X509_add_ext failed")
349339
}
340+
341+
InstallLogger.shared.logSuccess("SAN extension added: IP:\(ip)")
350342
}
351343

352344
private static func writePrivateKeyPEM(pkey: OpaquePointer?, to path: String) throws {

0 commit comments

Comments
 (0)