@@ -319,34 +319,26 @@ public final class GenerateCert {
319319
320320 // Simpler version that doesn't use deprecated stack functions
321321private 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