Posts

Chrome Extension: 使用 Native Messaging 的方式串接讀卡機

Image
前提 由於需用 NFC 登入系統 評估後使用 新錼 CL-2100R 來實作 構想是用 Chrome Extension 串接讀卡機可快速登入系統 因 NPAPI 已經被淘汰了 所以用 Native Messaging 來開發 網路上有關 winscard.dll 跟 native messaging 的資料不多 一開始一直被誤導 以為可以直接呼叫 winscard.dll 今天看到 這篇文章 才晃然大悟 直接在 path 中帶入 winscard.dll 是 NPAPI 的做法 (因為直接 call .dll 不安全,所以才捨棄 NPAPI 的啊 XD) 如何在 Mac 上測試是否有抓到讀卡機 可以輸入以下指令 如果有出現讀卡機的型號就代表有抓到 $ pcsctest MUSCLE PC/SC Lite Test Program Testing SCardEstablishContext : Command successful. Testing SCardGetStatusChange Please insert a working reader :(我在這邊就卡住了) 如何執行 Chrome Extension 這邊不講解要如何載入開發的程式 只提該怎麼把 Chrome Extension 程式呼叫出來 可在 Chrome 網址列輸入 chrome://apps 就會出現安裝好的 Extension 如果沒出現請確認 Extensions 頁面有開啟該程式 註 winscard.dll 是 Microsoft Windows 內建的動態連結函式庫 基本上讀卡機都是用 winscard.dll 來提供服務 Linux/Mac 上則是使用 PC/SC lite 通常讀卡機廠商都不是自己寫 driver 都用公版程式 Mac 上早在 10.9 版以後就不支援了(10.8 還支援) 我用過兩個牌子都一樣 問過讀卡機廠商也是不了了之 所以目前要在 Mac 上面支援是有困難的(目前的 Mac 版本是 10.14) Reference Chrome Native Messaging Exampl Calling a C dll through chrome browser exten...

使用 certbot 讓 wildcard certificate 可自動更新憑證

Image
由於 Let’s Encrypt Wildcard Certificate 使用 DNS 認證 所以無法用傳統的方式自動更新 ./certbot renew 如果你剛好使用 Cloudflare 的話就有福了! Cloudflare 支援 API key 認證 可以透過一些第三方的模組來自動認證 這樣就不用每三個月都要手動認證了 以下教學參考此篇文章 前情提要 下方使用 CentOS7 當作示範環境 如果你還沒裝 certbot,請先執行 $ yum install certbot 1. 首先要先登入 Cloudflare,右上角 My Profile 那就可找到 Global API Key 請點選 View 輸入密碼就會出現,這把 Key 很重要請小心保管 2. 由於這把 Key 很重要,所以要放在一個安全的地方 原作者把它放在 /root/.secrets 裡面(你要改地方也行,最後的參數路徑記得改就好) 但系統預設沒有 /root/.secrets 這個目錄 所以要先建立這個目錄 $ mkdir /root/.secrets 然後把下面這兩行填好後放到 /root/.secrets/cloudflare.ini 裡面 dns_cloudflare_email = "請填你的cloudflare帳號,也就是email" dns_cloudflare_api_key = "請輸入上述的 Global API Key" 3. 修改 /root/.secrets/cloudflare.ini 權限 $ sudo chmod 0700 /root/.secrets/ $ sudo chmod 0400 /root/.secrets/cloudflare.ini 4. 安裝 Certbot 及 CloudFlare DNS 認證套件 $ sudo yum install python-pip $ sudo pip install certbot-dns-cloudflare 5. 申請 Wildcard SSL 憑證 example.com 請帶入自己的 domain $ sudo /usr/local/bin/certbot certonly --dns...

cordova-plugin-googleplus 無法在 android 上使用 google sign in

Image
我遇到的問題是 在 Android 手機上點選 Google sign-in 會沒有反應 正常會跳出視窗讓你選擇用哪個帳號登入 我們是使用這個套件  cordova-plugin-googleplus 在 iOS 上都是正常的 原本以為是 UI 被遮到 還特別把他將 Fb 的位置對調 而且奇怪的點是,在 console 沒有看到任何的錯誤訊息 這問題困擾了我好幾天 後來嘗試將 cordova-plugin-googleplus 版本一個一個降版 從 5.2.2 到 5.3.2 中每一個版本都試過 後來才發現 5.2.1 是可以 work 的! 不過遇到了 error 16 感謝 這個討論串 讓我很快就找到問題了 最主要是說 webClientId 要用 OAuth 2.0 Client ID 裡面的 Web client 這個才行 iOS 用其他的都可以執行 唯獨 Android 一定要用這一個 後來才知道裡面一堆人說 5.2.1 可以 work 為什麼不讓我早點看到這篇呢 orz... My Environment meteor : 1.7.0.5 cordova cli : 8.1.0 cordova-plugin-googleplus : 5.3.2

meteor build error & apk path

$ meteor build ../build --server localhost:3000 => Errors executing Cordova commands:    While removing plugins    cordova-plugin-app-version,cordova-plugin-badge,cordova-plugin-call-number,cordova-plugin-camera,cordova-plugin-device,cordova-plugin-dialogs,cordova-plugin-file,cordova-plugin-file-transfer,cordova-plugin-googleplus,cordova-plugin-local-notification,cordova-plugin-meteor-webapp,cordova-plugin-splashscreen,cordova-plugin-statusbar,cordova-plugin-whitelist,cordova-plugin-wkwebview-engine,cordova-save-image-gallery    from Cordova project:    Cordova error: Cannot find plugin.xml for plugin "cordova-plugin-facebook4". Please try adding it again.    (If the error message contains suggestions for a fix, note that this may not apply to the Meteor integration. You can try running again with the --verbose option to help diagnose the issue.) 如果遇到 meteor build 時候遇到上述問題 請先執行 meteor reset 再執行以上指令即可 另外紀錄一下 meteor 產生的 ap...

Lumen 5.5 TimeZone

Lumen 的 timezone 設定於 .env 有兩個參數就要設定 APP_TIMEZONE=Asia/Taipei DB_TIMEZONE=+08:00 如果只設定 APP_TIMEZONE 的話 部分寫入資料庫的資料會有問題

如何申請 iOS 推播憑證

Image
大致上申請流程可以參考 Collyn Chen 的文章 iOS推播通知憑證申請流程 有一點要補充的是 最後產生 .pem 那段 我在 macOS High Sierra 10.13.6 上無法正常運作 查了一下我的 openssl 是 LibreSSL 2.2.7 居然不是 openssl ? 在執行這段指令時會發生以下錯誤 後來改了參數後就可以 work 囉! $ openssl pkcs12 -in filename.p12 -out filename.pem -nocerts -nodes 另外這邊要補充一個測試憑證的工具 叫做 Easy APNs Provider 取得 Device Token 後直接把憑證餵進去 就可以馬上收到推播囉! 請注意,這個工具是使用 .cer 檔,不是 .pem 檔喔! 2018.08.10 補充 後來用上述指令產生出來的 pem 無法用程式發推播 將 -nocerts 參數改成 -clcerts 才行 $ openssl pkcs12 -in filename.p12 -out filename.pem -clcerts -nodes 這時候系統卻不會出現上面的錯誤 中間做了什麼已經不可考了

如何在 apache2 上面啟用 http/2 on CentOS7

CentOS 的 repo 某些套件更新相當的保守 例如 apache 跟 php 就是很實在的例子 目前我使用的 CentOS7 是 印象中 apache 的版本在 CentOS7 上始終停留在 2.4.6 由於 apache 支援的 http/2 功能在 2.4.17 才會出現 (不過 2.4.26 版本不安全,請升級到後續的版本) 所以要先想辦法將 apache 升級 如果不想自己 compile 的話 可以參考這篇的做法 1. 先查詢 apache 的版本 可以用 httpd -v 或是 yum info httpd 查詢 2. 先確認是否安裝 epel-release $ sudo yum install -y epel-release 3. 下載並安裝 CodeIT repo $ cd /etc/yum.repos.d && wget https://repo.codeit.guru/codeit.el`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)`.repo 4. 使用 yum info httpd 查詢是否可抓到目前最新版的 httpd 5. 如果還沒安裝 apache 可以輸入 $ yum install httpd 6. 如果要升級 apache 的話 $ yum update httpd-* 7. 重啟 apache $ systemctl restart httpd 接下來要設定讓 site 支援 http/2 1. 要把下面這行 Protocols h2 http/1.1 2. 加入 ssl.conf 或是 httpd.conf < VirtualHost *:443 > Protocols h2 http/1.1 ServerAdmin you@your-awesome-site.com ServerName your-awesome-site.com < /VirtualHost > 3. 重啟 apache $ systemctl restart httpd 如果想要測試可以用 ...