Post

Replies

Boosts

Views

Activity

Reply to Issue implementing the Connection with TLS/SSL method from TCP method using swift5.
I also try to use OpenSSL to get the Certificate from client but is is nothing to show: macos@ESB-Dev-MacBook ~ % openssl s_client -starttls postgres -showcerts -connect 10.1.141.91:1515 </dev/null -debug CONNECTED(00000003) write to 0x600003015480 [0x1049b1fb8] (8 bytes => 8 (0x8)) 0000 - 00 00 00 08 04 d2 16 2f- ......./ read from 0x600003015480 [0x159810800] (8192 bytes => 15 (0xF)) 0000 - 4d 44 43 53 54 41 52 54-3c 3c 54 4c 53 3e 3e MDCSTART<<TLS>> --- no peer certificate available --- No client certificate CA names sent --- SSL handshake has read 15 bytes and written 8 bytes Verification: OK --- New, (NONE), Cipher is (NONE) Secure Renegotiation IS NOT supported Compression: NONE Expansion: NONE No ALPN negotiated Early data was not sent Verify return code: 0 (ok) --- read from 0x600003015480 [0x159810800] (8192 bytes => -1 (0xFFFFFFFFFFFFFFFF))
Jun ’23
Reply to Issue implementing the Connection with TLS/SSL method from TCP method using swift5.
Thanks for your quick response Just so I'm clear also, you don't want to upgrade the connection to use TLS midstream, you are looking to perform either server side or client side verification using TLS from the start, correct? I finally found that is STARTTLS connection protocol. It didn't make a TLS connection from the beginning, it follow this flow: Connect via TCP protocol. Get SSL context. Verify the Certificate using the context above. Send encrypt data I have found some example as: // Create the SSL/TLS context var context: SSLContext? = nil let status = SSLCreateContext(nil, SSLProtocolSide.clientSide, SSLConnectionType.streamType, &context) guard status == errSecSuccess else { // Handle the error return } But it seems to be deprecated in MacOS 13.0. Did you have any clue about this case? Thanks a lot.
Jun ’23
Reply to How to get the current connected Network Interface in MacOS
Thanks for your quick response. The key purpose is finding out the current connected Network Interface. Ex: The Wi-Fi connection is en0 (default). I used an adapter USB-C to RJ45 to connect a LAN connection → I could not find out which Network Interface is used for it programmatically. (sometime is en8, sometime is en15 and it depending on each different adapters I connected). I used this function to get the current available Network Interface. Is there any newer supported function ? Can we use these lines of code for future? public class EnumerateNetworkInterfaces { public struct NetworkInterfaceInfo { let name: String let ip: String let netmask: String } public static func enumerate() -> [NetworkInterfaceInfo] { var interfaces = [NetworkInterfaceInfo]() // Get list of all interfaces on the local machine: var ifaddr : UnsafeMutablePointer<ifaddrs>? = nil if getifaddrs(&ifaddr) == 0 { // For each interface ... var ptr = ifaddr while( ptr != nil) { let flags = Int32(ptr!.pointee.ifa_flags) var addr = ptr!.pointee.ifa_addr.pointee // Check for running IPv4, IPv6 interfaces. Skip the loopback interface. if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) { if addr.sa_family == UInt8(AF_INET) || addr.sa_family == UInt8(AF_INET6) { var mask = ptr!.pointee.ifa_netmask.pointee // Convert interface address to a human readable string: let zero = CChar(0) var hostname = [CChar](repeating: zero, count: Int(NI_MAXHOST)) var netmask = [CChar](repeating: zero, count: Int(NI_MAXHOST)) if (getnameinfo(&addr, socklen_t(addr.sa_len), &hostname, socklen_t(hostname.count), nil, socklen_t(0), NI_NUMERICHOST) == 0) { let address = String(cString: hostname) let name = ptr!.pointee.ifa_name! let ifname = String(cString: name) if (getnameinfo(&mask, socklen_t(mask.sa_len), &netmask, socklen_t(netmask.count), nil, socklen_t(0), NI_NUMERICHOST) == 0) { let netmaskIP = String(cString: netmask) let info = NetworkInterfaceInfo(name: ifname, ip: address, netmask: netmaskIP) interfaces.append(info) } } } } ptr = ptr!.pointee.ifa_next } freeifaddrs(ifaddr) } return interfaces } } Best regards,
Jul ’23
Reply to How to get the current connected Network Interface in MacOS
Sorry about that, my intentions are: I want to get the current connected network interface (in case I don't use Wi-Fi (en0) any more, and use adapter instead) I want to use Simple Ping lib to ping to IPv6 local-link which need the exact network interface (the same with $sudo ping6 [IPv6 Local-Link]%[Network Interface]) Is there any way to ping to ipv6 to ensure that my connection is still alive without using this method above? By the way, I still seek for the method to get MAC Address from IPv6 actually... Best regards,
Jul ’23
Reply to How to get the current connected Network Interface in MacOS
Thanks for your response. About this So you’re end goal is to get the device’s MAC address? Yes, that's it! We actually work on the TV devices using Wi-Fi. Are you trying to do that entirely on device? Yes, sure. NDP protocol is a good deal, but I can not find its base code as ARP in Apple code. (In the window version of my app, I can use Win API : netioapi.h, and It works) Or with the cooperation of some external hardware? We have to do that in App, maybe there aren't any external devices to cooperate. The TV will support us to give back a Mac Address when I request on them in a few years later. But we want to get it programmatically.
Jul ’23
Reply to com.apple.dock.plist is changed in macOS14.0 and later
Dear @eskimo, I got your point, and I'm going to change my mindset with the alternative solution below: I have tried to use the UserDefault to get its information (dock orientation) : if let defaults = UserDefaults(suiteName: "com.apple.dock"), let orientation = defaults.string(forKey: "orientation") But It is not reliable. Sometimes It got, sometime it didn't. I have double-checked with the Terminal: [Restored 1 Mar 2024 at 09:06:03] (base) macos ~ % defaults read com.apple.dock { "mod-count" = 1035; } (base) macos ~ % defaults read com.apple.dock autohide 2024-03-01 09:07:28.641 defaults[24181:525841] The domain/default pair of (com.apple.dock, autohide) does not exist (base) macos ~ % defaults read com.apple.dock { mineffect = genie; "mod-count" = 1040; orientation = bottom; } (base) macos ~ % defaults read com.apple.dock autohide 2024-03-04 10:13:44.931 defaults[38656:1061252] The domain/default pair of (com.apple.dock, autohide) does not exist I expect not to use scripts as little as possible.
Mar ’24