# 衛福部健保卡元件 on MAC 疑難雜症 (tw.gov.nhi.nhiicc) 健保卡元件是以 launchd 管理的 daemon 的形式存在 可用以下方法檢查 :::info 某一版本之後 (推測是 `0008` 之後),其 daemon 會使用 `root` 於 `system` domain 運行 故沒有使用 `root` 去列出 daemon 清單會找不到 ::: ```bash $ sudo launchctl list | grep --ignore-case nhi - - tw.gov.nhi.nhiicc2023.plist # perviously version # - - tw.gov.nhi.nhiicc.plist # - - tw.gov.nhi.nhiicc2019.plist ``` 如看到第一個 `-` 是數字 (代表 pid) 即表示 daemon 運行中 對應的 daemon configuration 位於 - `/Library/LaunchDaemons/tw.gov.nhi.nhiicc2023.plist` - ~~`/Library/LaunchDaemons/tw.gov.nhi.nhiicc.plist`~~ - ~~`/Library/LaunchDaemons/tw.gov.nhi.nhiicc2019.plist`~~ 另外 NHI 的 daemon 會透過 bind `localhost:7777` 提供健保卡讀取功能 # 功能測試 / 驗證 - file:///usr/local/share/NHIICC/html/ESample.html - https://cloudicweb.nhi.gov.tw/cloudic/system/webtesting/SampleY.aspx - ~~file:///Library/StartupItems/nhiicc/web/test.html~~ # 無法找到 daemon,也無法連接到元件 極有可能是程式沒有正常被運行著 透過以下指令載入 daemon 設定檔 ```bash $ launchctl load /Library/LaunchDaemons/tw.gov.nhi.nhiicc2023.plist ``` # 確認 daemon 正常運行,卻還是無法偵測到元件 很有可能是因為瀏覽器因為憑證信任的關係阻擋其內容 如果你透過以下方式測試發現 API 都正常 ```bash $ nc -zv iccert.nhi.gov.tw 7777 iccert.nhi.gov.tw [127.0.0.1] 7777 (cbt) open $ curl https://iccert.nhi.gov.tw:7777/ # Omit ... $ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" --header "Sec-WebSocket-Version: 13" --max-time 2 https://iccert.nhi.gov.tw:7777/echo HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: qGEgH3En71di5rrssAZTmtRTyFk= = curl: (28) Operation timed out after 2005 milliseconds with 0 bytes received ``` 測試 websocket 的 `curl` 指令會遇到 timeout 是正常的 這是因為 websocket 在完成 protocol 切換後會保持連接 這時候可以開啟瀏覽器連接到 https://iccert.nhi.gov.tw:7777/ 以 chrome 為例,會看到警示畫面 ![](https://i.imgur.com/8L8S5Ew.png) 透過主動提示 chrome 接受在不安全的情況繼續造訪網站 這時看到以下畫面,再回去測試元件功能正常便能成功 ![](https://i.imgur.com/S3Ketfn.png) 補充說明:如果想重現,可以點這邊的 ![](https://i.imgur.com/F3hUvHH.png) # 確認健保卡元件版本 以 2025 報稅為例,要求版本要到 `011` 以上 ![Screen Shot 2025-04-28 at 21.12.37](https://hackmd.io/_uploads/SyAARxT1xx.png) 暫時沒有發現適合方法,必須透過上圖檢測得知 https://med.nhi.gov.tw/ca2/nhi/icc/page/portal.html > 因中央健康保險署新版元件預計於113年7月1日發布並停用舊版本,如無法正常登入請至健保署健保卡驗證服務進行環境檢查更新,如有相關問題,請洽健保署客服人員。 # 參考資料 - https://gist.github.com/wancw/61c629b78bad206816ae4b58913a7cd8 - https://www.puritys.me/docs-blog/article-450-Mac-+-Chrome-%E8%A7%A3%E6%B1%BA%E5%81%A5%E4%BF%9D%E5%8D%A1%E8%AE%80%E4%B8%8D%E5%88%B0%E7%9A%84%E5%95%8F%E9%A1%8C.html - https://gist.github.com/htp/fbce19069187ec1cc486b594104f01d0 - https://cloudicweb.nhi.gov.tw/cloudic/system/SMC/mEventesting.htm