【武漢肺炎】在家工作使用自建虛擬網絡連接辦公室

在武漢肺炎疫情影響下,不少公司計劃安排員工在家工作(Work From Home),可是還需要解決員工在家存取辦公室的電腦文件檔案。在辦公室安裝 Linux 主機,建立虛擬網絡伺服器是一個可取而廉價的方案。

Ubuntu 是一個較方便快捷安裝的 Linux 系統,在安裝 Linux 之後,就可以安裝虛擬網絡相關的package。為簡化 Windows 及 macOS 系統連接方法,所以本文介紹安裝 L2TP/IPSec 的 256 位元虛擬網絡的方法。

在安裝 Ubuntu 18.04 LTS Server Edition 後,用 APT 安裝 strongSwan IPSec VPN 和 Layer 2 Tunneling Protocol 套件。

$ apt-get install strongswan xl2tpd

編輯 /etc/ipsec.conf,加入以下一段,並把 left 設定為外置 IP 網址。

# ipsec.conf – strongSwan IPsec configuration file
conn L2TP-IPSEC
authby=secret
rekey=no
keyingtries=3
type=transport
esp=aes128-sha1
ike=aes128-sha-modp1024
ikelifetime=8h
keylife=1h
left=XXX.XXX.XXX.XXX # your system’s external IP
leftprotoport=17/1701
right=%any
rightprotoport=17/%any
rightsubnet=0.0.0.0/0
auto=add
dpddelay=30
dpdtimeout=120
dpdaction=clear
#force all to be nat’ed. because of iOS
forceencaps=yes

編輯 /etc/ipsec.secrets,加入以下一段,並把 xxx.xxx.xxx.xxx 設定為外置 IP 網址﹐及用 PSK 設定 private key。

# This file holds shared secrets or RSA private keys for authentication.

# RSA private key for this host, authenticating it to any other host
# which knows the public part.
%any xxx.xxx.xxx.xxx : PSK "Your_Pre-shared_Private_key_here"

編輯 /etc/ppp/options.xl2tpd,加入以下一段。

require-mschap-v2
refuse-mschap
ms-dns 8.8.8.8
ms-dns 8.8.4.4
asyncmap 0
auth
crtscts
idle 1800
mtu 1410
mru 1410
connect-delay 5000
lock
hide-password
local
# debug
modem
name l2tpd
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4

編輯 /etc/xl2tpd/xl2tpd.conf,加入以下一段。

[global]
ipsec saref = no
debug tunnel = no
debug avp = no
debug network = no
debug state = no
access control = no
rand source = dev
port = 1701
auth file = /etc/ppp/chap-secrets

[lns default]
ip range = 192.168.2.10-192.168.2.99
local ip = 192.168.2.1
require authentication = yes
name = l2tp
pass peer = yes
ppp debug = no
length bit = yes
refuse pap = yes
refuse chap = yes
pppoptfile = /etc/ppp/options.xl2tpd

編輯 /etc/ppp/chap-secrets,加入以下一段作為 VPN 登入用戶帳號和密碼。

# Secrets for authentication using CHAP
# client server secret IP addresses
testuser * testpassword *

編輯 /etc/sysctl.conf,加入以下一段來啟動 IPv4 的 IP forwarding。

net.ipv4.ip_forward=1

然後重新載入 sysctl.conf 便可。

$ sysctl -p /etc/sysctl.conf

使用 iptables 來做 NAT masquerade 讓 VPN 用戶能連接外部網絡及互聯網。

$ iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE

最後重啟 strongSwan IPSec VPN 和 Layer 2 Tunneling Protocol 套件便可。

$ /etc/init.d/ipsec restart
$ /etc/init.d/xl2tpd restart

如果外部網絡有防火牆或 Router,需要在防火牆或 Router 設定 Virtual IP 或 Port Forwarding,讓外部 UDP 500, 1701, 4500 的 request 能進入 Linux 伺服器。

VPN 用戶電腦設定和連接

Click Wifi > Open Network Preferences… 出現 Network 設定。

Click + 加入 Interface: VPN (L2TP Over IPSec),Click Create。

Server Address: 輸入主機網址或名稱。
Account Name: 輸入 VPN 用戶名稱。

Click Authentication Settings…

User Authentication: 的 Password: 輸入用戶密碼。
Machine Authentication: 的 Shared Secret: 輸入Pre-shared private key。

Click OK。

Click Advanced,在 Options 的 Session Options: click Send all traffic over VPN connection。

Click OK。
Click Apply。

Click Connect 就可以試試連接 VPN 了。

Click Show VPN status in menu bar 可以在 Menu Bar 看見狀態,也可用來 connect 或 disconnect VPN。

如果你喜歡本文,歡迎你透過 Patreon 定期支持開源人網誌工作。

Linux Harbour 提供商業 Linux 顧問服務。

香港開源區塊鏈活動 Hyperledger BootCamp 2019

3月7-8日 Linux 基金會在香港數碼港舉行開源區塊鏈活動 Hyperledger BootCamp 2019,為 Hyperledger 旗下不同開源區塊鏈專案「開坑」,讓新開發者加速了解不同專案的入門方法,速成教導新開發者貢獻專案的程序。

BootCamp形式像BarCamp那像Unconfernce形式,由參加者設定每節題目。而不同之處是每節都需要參加者自備手提電腦,按不同專案和類型,分作12個10人大圓桌小組,跟主持(Session Leader)做一些習作和互動。主持按照該節目的,或多或少指導參加者作業,甚至交由參加者主導作業。另設三間10-20人培訓室,多作入門教學。

源自 IBM 釋出源碼的Hyperledger Fabric自然有不少人棒場,而筆者在兩日活動主要參加Hyperledger Iroha和Hyperledger Indy相關環節。

區塊鏈入門環節The Forest & the Trees! The unifying foundations of Blockchain,為區塊鏈新手講解區塊鏈技術。

以下是筆者英文速記:

  • DLT = Distributed Ledger Technology
  • Hash and Message Digest
  • Public Key Crypto
  • Merkle Tree
  • Transaction Chain
  • Blockchain
    • Header- contains
    • Chaining-achieved through hashing of previous blocks
    • Merkle Root: Hash based data structure of transactions (here Hash of Block data)
  • Permissioned vs Permissionless
  • Block-Fabric
    • Blockchain
    • Additional items in header and transactions…..
  • Block-Sawtooth
    • additional items in header an batches are to do with permission ledgers.

Hyperledger Indy需要懂Rust的開發者,所以設有入門環節Introduction to Rust and Cargo,讓不認識Rust的開發者快速了解這Rust語言。以下是筆者英文速記:

  • WASM!!
    • Web app server -> middleware -> browser code, all in RUST!
  • cargo init –bin myproject
  • Cargo.toml
    • .toml json file in different layout.
  • cargo build
  • cargo run
    • Finished dev [unoptimized + debuginfo] target(s) in 4.53 secs
  • optimised version
    • cargo build —release
    • Finished release [optimized] target(s) in 0.0 secs
  • https://doc.rust-lang.org/stable/book/
  • https://doc.rust-lang.org/stable/cargo/
  • https://doc.rust-lang.org/stable/rust-by-example/
  • https://crates.io/
    • More packages than Python, Node
    • Most Recommended Package: serde
      • a generice serialisation/deserialization framework
  • IRON extensible web framework for rust
    • ironframework.io
  • enum = data type
  • pub fn fn_name() {… } = public function
  • for i in a {… } = for loop
  • let, let out something = 0;
  • impl

筆者在Hyperledger Iroha入門環節Getting Started with Iroha Session I 的英文速記。

  • Features
    • Command-driven architecture
      • Asset management
      • Identify management
    • Byzantine fault-tolerant ordering service and consensus
    • Role-based access control
    • Mutlo-signature transactions
    • Universal peer role and easy scripted deployment with Docker and Ansible
  • Why Iroha
    • Distributed Ledger platform for simple use-cases of payments and identify storage.
    • Uses fixed set of commands 16 in total (eg. asset creation, transfers, account creation) and ?? queues.
  • Successful Proof of Concept projects: cross-chain exchange, bank settlements, etc.
  • Data structure
    • User account {account_name}@{domain}
    • Each user have some Asset {asset_name}#{domain}
  • Works
    • Run Iroha locally
    • Create simple web service to interact with Iroha
  • Workshop 1

irohad –config ~/config.docker –keypair_name ~/node0

[2019-03-07 10:57:01.576692300] [I] [CLI/ResponseHandler/Query]: [Account Assets]
[2019-03-07 10:57:01.576748700] [I] [CLI/ResponseHandler/Query]: -Account Id:- test@test
[2019-03-07 10:57:01.576762100] [I] [CLI/ResponseHandler/Query]: -Asset Id- coolcoin#test
[2019-03-07 10:57:01.576776500] [I] [CLI/ResponseHandler/Query]: -Balance- 100.5

[2019-03-07 10:57:40.420019600] [I] [CLI/ResponseHandler/Query]: [Account Assets]
[2019-03-07 10:57:40.420044900] [I] [CLI/ResponseHandler/Query]: -Account Id:- admin@test
[2019-03-07 10:57:40.420052900] [I] [CLI/ResponseHandler/Query]: -Asset Id- coolcoin#test
[2019-03-07 10:57:40.420063700] [I] [CLI/ResponseHandler/Query]: -Balance- 100.0

筆者在Hyperledger Indy入門環節Getting Started with Indy的英文速記。

  • Sovrin Foundation, Sovrin Alliance
  • Identity
  • Sovrin donate source code to LF.
  • Most Bottom Layer: Indy-Crypto -> HyperLedger Ursa
  • Client side: Indy-SDK (libIndy & libVCX), Agent (on top SDK) (Python, Node), Sovrin Connector-App
  • Ledger side: Indy Plenum (Communicate with Nodes), Indy-Node (on top of Plenum)(Handling Identity), Sovrin Ledger plugin
  • Look for: Agent Protocol, Schema2.0, DKMS Efforts (Decentrailised Key Management System), Ledger 2.0 (Python?).

然後是Indy Agent的英文速記。

在結束環節最後,Hyperledger 團隊宣佈 David Liu 被選為新的義務宣傳大使(ambassador)。

OpenSSL Heartbleed (CVE-2014-0160) 解決方法

OpenSSL Heartbleed (CVE-2014-0160) 個 bug 都幾大件事下,因為理論上好多 web server 的 SSL certificate 都有機會出問題,所以安全起見都係 upgrade OpenSSL 後,重新 generate 新 SSL certificate。

所以在 Linux Harbour 先寫了篇英文 blog 詳細少少講多兩句,亦好歡迎俾 job 我地幫你做下。

簡單來講,如果 check 到有事,只需要 apt-get 或 yum upgrade 左個 OpenSSL 去,然後 confirm build date 係 2014年4月7日後,就即係你既OpenSSL安全了。

$ apt-get update && apt-get install -y libssl1.0.0 openssl

然後 generate 張新 SSL certificate 俾 Apache HTTP web server 用,然後 restart Apache HTTPD,搞掂!

$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem

上述方法我亦整左個 shell script 放左上 github

睇以上 procedures 就好似好簡單,但做落比平常 fix bug 較複雜,所以睇 Linux Harbour 果邊篇文,或者俾錢我幫你搞。 🙂