2024年6月14日 星期五
2024年6月3日 星期一
2024年6月1日 星期六
殺人者死, 傷人者刑. 反廢死
殺人者死, 傷人者刑. 反對廢死.
這跟跟自由一樣, 所謂自由是不影響他人. 犯案者都不尊重別人人權了, 為什麼要考慮他的人權. 在我們國家死刑都是重大惡極之人, 有需要與社會隔絕. 犯後有悔意, 為何不在犯前有悔意. 尤其是故意殺人或凌虐他人致死者.
處終身無期徒刑更不可行, 我一年十几廿萬納的稅, 不養這些人.
2024年5月9日 星期四
2024年3月21日 星期四
2024年2月20日 星期二
2024年1月23日 星期二
2024年1月10日 星期三
安裝 ikev2 VPN on Ubuntu 20.04
一、前言:
VPN 主要目的不是要做違法之事, 而是要連往某些有限制拜訪來源或是有安全性限制網域時的橋樑,既然是要連往具有嚴格安全性管制網域自然在 VPN 的通訊協定上必須要使用一種安全性較高的 VPN 協定,傳統的 PPTP/L2TP 雖有安全性,但並不足夠安全。近幾年屬於
IPSec[1] 的 ikev2 (Internet Key Exchange version 2) [2] 是一個較為普及通用的加密的VPN 通訊協定。至於 ikev2 是如何運作, 可以參考 ARAVIND .S 這篇 blog 的介紹[3]。
二、安裝 ikev2 VPN server @ Ubuntu 20.04
目前許多作業系統都可以安裝 ikev2 VPN server (包含 windows server [4]), 在此我參考 cloud infrastructure service 這篇文章進行安裝[5]。
1. 先更新系統上的 packages 保持在最新的版本
sudo apt-get update
sudo apt-get upgrade
2. 修改 /etc/sysctl.conf 讓 IP 能夠做 forward (因為做VPN 就想像是多一張虛擬網卡),editor 用 vi 或 nano 都可以。
sudo nano /etc/sysctl.conf
上面白色字的3行原來是有 mark 註解的,將它們拿掉。
3. 重新啟動 sysctl
sudo sysctl -f
4. 安裝 StrongSwan VPN
支援 ikev2 的服務有很多[2],但目前用的較多的為StrongSwan[6],我們透過 apt-get 安裝它及相關套件。
sudo apt-get install strongswan strongswan-pki libcharon-extra-plugins
libcharon-extauth-plugins libstrongswan-extra-plugins libtss2-tcti-tabrmd-dev
5. 安裝憑證授權機構(Certificate Authority, CA)與證書(Certificate)
(1). 產生所需目錄與儲存CA與證書
sudo mkdir -p /root/pki/{cacerts,certs,private}
(2). 產生 root 金鑰以便等會簽署CA
sudo pki --gen --type rsa --size 4096 --outform pem >
/root/pki/private/ca-key.pem
(3). 使用上面金鑰產生 root CA
sudo pki --self --ca --lifetime 3650 --in /root/pki/private/ca-key.pem --type
rsa --dn "CN=VPN root CA" --outform pem >
/root/pki/cacerts/ca-cert.pem
(4). 簽署給 VPN server 用的證書與金鑰
sudo pki --gen --type rsa --size 4096 --outform pem >
/root/pki/private/server-key.pem
(5). 使用之前 CA key 簽署 VPN server 證書, IP 用你 VPN server 的IP(這裏用xxx.xxx.xxx.xxx 取代。
sudo pki --pub --in /root/pki/private/server-key.pem --type rsa | pki --issue
--lifetime 1825 --cacert /root/pki/cacerts/ca-cert.pem --cakey
/root/pki/private/ca-key.pem --dn "CN=xxx.xxx.xxx.xxx" --san xxx.xxx.xxx.xxx
--flag serverAuth --flag ikeIntermediate --outform pem >
/root/pki/certs/server-cert.pem
(6). 拷貝所有證書到 /etc/ipsec.d 資料夾
sudo cp -r /root/pki/* /etc/ipsec.d/
6. 設定 StrongSwan VPN server
(1). 將原舊 ipsec.conf 備份
sudo mv /etc/ipsec.conf /etc/ipsec.conf.bak
(2). 新編寫一個 ipsec.conf 檔
sudo nano /etc/ipsec.conf
(3). 編寫 /etc/ipsec.secrets 檔案
sudo nano /etc/ipsec.secrets
(4).
(5). 重新啟動StrongSwan 服務
sudo systemctl restart strongswan-starter
(6). 檢測 strongswan 的狀態
sudo systemctl status strongswan-starter
7. Client 端的使用
在此使用Android 的StrongSwan
做範例
(1). 先下載你的 VPN 憑證證書到你的手機並導入
/etc/ipsec.d/cacerts 中的 ca-cert.pem 檔案
(2). StrongSwan 做設定時輸入你的IP/帳號/密碼外,最重要的是要導入你的VPN 憑證後方可使用
====================================
References
1. https://en.wikipedia.org/wiki/IPsec
, Access on 2024-01-08.
2. https://en.wikipedia.org/wiki/Internet_Key_Exchange
, Access on 2024-01-08.
3. https://www.linkedin.com/pulse/ikev2-vpn-protocol-explained-what-how-works-aravind-s/
, Access on 2024-01-08.
4. https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh831807(v=ws.11)
, Access on 2024-01-08.
5. https://cloudinfrastructureservices.co.uk/setup-ikev2-vpn-server-on-ubuntu-20-04/
, Access on 2024-01-08.
6. https://strongswan.org/ , Access
on 2024-01-08.
2024年1月5日 星期五
Centos 7 上的 apache 升級 SSL + Cert
一、前言:
現在的 browser 都對沒有使用 SSL 與憑證的 web 提出不安全連線的警告, 為了不要讓我的智慧門牌一直出現這問題, 打算對 Centos 上的 apache2 web daemon 升級.
二、 Steps
1. 安裝 mod_ssl 模組,更改設定檔與重新啟動
基本上參考 [1] 中的方法, 依自己的設定做修改即可, 摘要如下:
(1) 安裝 SSL module
sudo yum install mod_ssl
(2) 產生給 TLS/SSL 用的憑證
請注意, 這裏產生的是給https 通訊協定的 TLS/SSL 用的私有加密憑證, 跟你去外面申請的公開憑證不同, 這個即使安裝了, 你在連線時是使用 https 了, 但仍然會說你不安全, 因為伙沒有去申請一個公開憑證去證明你網站的身份.
(3) SSL module 安裝好了之後, 在 /etc/ssl 下會有一個 certs 資料夾. 你需要自己再建一個 private 資料夾.
sudo mkdir /etc/ssl/private
(4) 修改 private 權限
sudo chmod 700 /etc/ssl/private
(5) 使用 OpenSSL 產生自己簽署的 key 與certificate pair
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt|
執行過程會要你回答一些問題:
<1> 國碼: 我寫 TW
<2> 城市名: 我寫 New Taipei City
<3> 地名: 我寫 Xin Zuang
<4> 公司或組織名: 我寫 FJCU
<5> 單位: 我寫 HEC
<6> 伺服器 domain: 我寫 macgyver.fjcu.org (沒有 domain 就寫 static public IP)
<7> 連絡人 email; 這就留你的 email 即可
(6) 設定私有憑證
<1> 移到你 apache 設定資料夾 /etc/httpd/conf.d
cd /etc/httpd/conf.d
<2> 產生編輯一個你 domain (或IP) 的設定檔, 在此我用我的domain , 在此編輯器你用 vi 或 nano 都可以.
sudo vi /etc/httpd/conf.d/macgyver.fjcu.org.conf
將下列資料寫到該檔案中 (ServerName 用自己的 domain)
sudo vi /etc/httpd/conf.d/non-ssl.conf
將下列檔案寫到檔案內 (ServerName用自己的 domain)
(7) 修改 apache 啟動 service
<1> 先檢查語法有沒有問題
sudo apachectl configtest
<2> 重新啟動 apache service
sudo systemctl restart httpd.service
<3> 防火牆要打開 443 port (看你用那套防火牆)
<i> 用 iptables 的
sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
<ii> 用 firewalld 的
sudo firewall-cmd --add-service=http
2. 使用免費憑證
你在安裝 OpenSSL 之後所安裝的是私人憑證(可想像是私人信用), 在網路上沒有人要相信你, 所以你必須找到一個可以發公開憑證的單位給你發憑證去認可你. 但憑什麼要免費幫你做公開認可呢? 所以多數出來幫你擔保的都要收費.
在此我們介紹一個免費的發公開憑證的服務, 但一次效期 3 個月, 期限到再去請. 相關文件可先去 Let's Encrypt[2] 網站上先閱讀文件, 在此直接以 Centos 7 的 apache 做範例. 我選用的是 certbot [3].
(1) 選擇使用的 web daemon 與 OS
https://certbot.eff.org/instructions
(2) 安裝 snap[4], 我以Centos 為例
依據你的 Centos 版本先選擇安裝 EPEL (我是 Centos 7)
<1> sudo yum install epel-release
<2> 透過 EPEL repo 安裝 snapd
sudo yum install snapd
<3> 透過 systemd enable snapd socket
sudo systemctl enable --now snapd.socket
<4> 產生 snapd library 連結
sudo ln -s /var/lib/snapd/snap /snap
(3) 移除你系統先前安裝過的 certbot
sudo yum remove certbot
(4) 安裝 certbot
sudo snap install --classic certbot
(5) 做指令連結
sudo ln -s /snap/bin/certbot /usr/bin/certbot
(6) 取得公開憑證
sudo certbot certonly --apache
(7) 測試是否可自動取得新憑證
sudo certbot renew --dry-run
(8) 將上述寫到你的 crontab 中, 每 3 個月自己 renew 一次
3. 完工
=============================
References
1. https://www.digitalocean.com/community/tutorials/how-to-create-an-ssl-certificate-on-apache-for-centos-7
2. https://letsencrypt.org/zh-tw/docs/
3. https://certbot.eff.org/
4. https://snapcraft.io/docs/installing-snapd






