Monday, May 22, 2006

Setup SSL in Apache

在web連接時加入SSL. 採用載入Apache SSL module 形式.
環境: Debian Testing/Unstable , Apache 1.3, OpenWebMail, 已完成網站設定並可以正常運行於端口80.
目的: 用SSL加密client 與 server的連線.
安裝apache SSL module:
debian:/usr/lib/apache/1.3# apt-get install libapache-mod-ssl
.....
Get:1 http://ftp.hk.debian.org testing/main libapache-mod-ssl 2.8.25-1 [328kB]
....
Unpacking libapache-mod-ssl (from .../libapache-mod-ssl_2.8.25-1_i386.deb) ...
Setting up libapache-mod-ssl (2.8.25-1) ...
./ca-bundle.crt ... Skipped
./snakeoil-dsa.crt ... 5d8360e1.0
./snakeoil-rsa.crt ... 82ab5372.0
./snakeoil-ca-dsa.crt ... 0cf14d7d.0
./snakeoil-ca-rsa.crt ... e52d41d0.0
之後系統提示使用那一方的設置(用戶現行設置/軟件開發者設置), 因選了保留用戶現行設置, 故需自己設定config file. 要自己修改/etc/apache/module.conf, httpd.conf
今次誤打誤撞試用apache-modconf.
debian:/etc/apache# apache-modconf apache-ssl
Creating config file /etc/apache-ssl/httpd.conf with new version
Creating config file /etc/apache-ssl/modules.conf with new version
比較過設置檔, 運行完apache-modconf apache-ssl後在module.conf會加入
LoadModule ssl_module /usr/lib/apache/1.3/mod_ssl.so
但没有在httpd.conf 中作出合適設定.在httpd.conf或者/etc/apache/conf.d/加入
<IfModule mod_ssl.c>
## SSL Global Context
##
## All SSL configuration in this context applies both to
## the main server and all SSL-enabled virtual hosts.
##


Listen 443

#
# Some MIME-types for downloading Certificates and CRLs
#
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl

# Pass Phrase Dialog:
# Configure the pass phrase gathering process.
# The filtering dialog program (`builtin' is a internal
# terminal dialog) has to provide the pass phrase on stdout.
SSLPassPhraseDialog builtin

# Inter-Process Session Cache:
# Configure the SSL Session Cache: First either `none'
# or `dbm:/path/to/file' for the mechanism to use and
# second the expiring timeout (in seconds).
#SSLSessionCache none
#SSLSessionCache shm:logs/ssl_scache(512000)
SSLSessionCache dbm:/var/run/ssl_scache
SSLSessionCacheTimeout 300

# Semaphore:
# Configure the path to the mutual explusion semaphore the
# SSL engine uses internally for inter-process synchronization.
SSLMutex file:/var/run/ssl_mutex

# Pseudo Random Number Generator (PRNG):
# Configure one or more sources to seed the PRNG of the
# SSL library. The seed data should be of good random quality.
# WARNING! On some platforms /dev/random blocks if not enough entropy
# is available. This means you then cannot use the /dev/random device
# because it would lead to very long connection times (as long as
# it requires to make more entropy available). But usually those
# platforms additionally provide a /dev/urandom device which doesn't
# block. So, if available, use this one instead. Read the mod_ssl User
# Manual for more details.
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
#SSLRandomSeed startup file:/dev/random 512
#SSLRandomSeed startup file:/dev/urandom 512
#SSLRandomSeed connect file:/dev/random 512
#SSLRandomSeed connect file:/dev/urandom 512

# Logging:
# The home of the dedicated SSL protocol logfile. Errors are
# additionally duplicated in the general error log file. Put
# this somewhere where it cannot be used for symlink attacks on
# a real server (i.e. somewhere where only root can write).
# Log levels are (ascending order: higher ones include lower ones):
# none, error, warn, info, trace, debug.
#SSLLog /var/log/apache/ssl_engine_log
#SSLLogLevel info

</IfModule>

若用virtual host 則加入:

<VirtualHost newvhost.domain.org:443>
<IfModule mod_ssl.c>
SSLEngine on
SSLCertificateFile /etc/apache/ssl.crt/server.crt
SSLCertificateKeyFile /etc/apache/ssl.key/server.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
</IfModule>

</VirtualHost>

若没有用virtual host則將上斜體字 部份加入之前的中.

建立SSL Cert:
debian:/etc/apache# mod-ssl-makecert
/etc/apache/ssl.crt/server.crt: already present
/etc/apache/ssl.csr/server.csr: already present
/etc/apache/ssl.key/server.key: already present

Do you really want to overwrite the existing certificate ? [y/N]: y (因第一次設置時誤輸入pass phrase)

What type of certificate do you want to create?
1. dummy (dummy self-signed Snake Oil cert)
2. test (test cert signed by Snake Oil CA)
3. custom (custom cert signed by own CA)
4. existing (existing cert)


Use dummy when you are a vendor package maintainer,
test when you are an admin but want to do tests only,
custom when you are an admin willing to run a real server
existing when you are an admin who upgrades a server.

Normally you would choose 2.

your choice: 2 (測試用)
Which algorithm should be used to generate required key(s)?

1. RSA
2. DSA

Normally you would choose 1.

your choice: 1
SSL Certificate Generation Utility (mkcert.sh)
Copyright (c) 1998-2000 Ralf S. Engelschall, All Rights Reserved.

Generating test certificate signed by Snake Oil CA [TEST]
WARNING: Do not use this for real-life/production systems
______________________________________________________________________

STEP 1: Generating RSA private key (1024 bit) [server.key]
1376666 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
.++++++
................................................++++++
e is 65537 (0x10001)
______________________________________________________________________

STEP 2: Generating X.509 certificate signing request [server.csr]
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
1. Country Name (2 letter code) [XY]:mo(輸入與自己服務器有關資料)
2. State or Province Name (full name) [Snake Desert]:macau
3. Locality Name (eg, city) [Snake Town]:macau
4. Organization Name (eg, company) [Snake Oil, Ltd]:asum
5. Organizational Unit Name (eg, section) [Webserver Team]:asum it
6. Common Name (eg, FQDN) [www.snakeoil.dom]:debsrv.asum.edu.mo
7. Email Address (eg, name@FQDN) [www@snakeoil.dom]:netadm@asum.edu.mo
8. Certificate Validity (days) [365]:(有效期自定)
______________________________________________________________________

STEP 3: Generating X.509 certificate signed by Snake Oil CA [server.crt]
Certificate Version (1 or 3) [3]:
Signature ok
subject=/C=mo/ST=macau/L=macau/O=asum/OU=asum it/CN=debsrv.asum.edu.mo/emailAddress=netadm@asum.edu.mo
Getting CA Private Key
Verify: matching certificate & key modulus
Verify: matching certificate signature
/etc/apache/ssl.crt/server.crt: OK
______________________________________________________________________

STEP 4: Encrypting RSA private key with a pass phrase for security [server.key]
The contents of the server.key file (the generated private key) has to be
kept secret. So we strongly recommend you to encrypt the server.key file
with a Triple-DES cipher and a Pass Phrase.
Encrypt the private key now? [Y/n]: y
writing RSA key
Enter PEM pass phrase: (輸入加密密碼, 此密碼會在啟動apahce 發問)
Verifying - Enter PEM pass phrase: (兩次必需相同)
Fine, you're using an encrypted RSA private key.
______________________________________________________________________

RESULT: Server Certification Files

o /etc/apache/ssl.key/server.key
The PEM-encoded RSA private key file which you configure
with the 'SSLCertificateKeyFile' directive (automatically done
when you install via APACI). KEEP THIS FILE PRIVATE!

o /etc/apache/ssl.crt/server.crt
The PEM-encoded X.509 certificate file which you configure
with the 'SSLCertificateFile' directive (automatically done
when you install via APACI).

o /etc/apache/ssl.csr/server.csr
The PEM-encoded X.509 certificate signing request file which
you can send to an official Certificate Authority (CA) in order
to request a real server certificate (signed by this CA instead
of our demonstration-only Snake Oil CA) which later can replace
the /etc/apache/ssl.crt/server.crt file.

WARNING: Do not use this for real-life/production systems

debian:/etc/apache# apachectl start (重新啟動apache)
Apache/1.3.34 mod_ssl/2.8.25 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide us with the pass phrases.

Server localhost:443 (RSA)
Enter pass phrase: (輸入建立cert時用的密碼)

Ok: Pass Phrase Dialog successful.
/usr/sbin/apachectl start: httpd started

之後在瀏覽器中輸入https://name_or_ip
第一次連接會提示是否接納該cert.

未完成:
1.使啟動apache 免輸入pass phrase,以免令啟動Script出現等候.
2.squrriel web mail 未能接IMAP server, 未知是否與轉用SSL連線有關.

參考:
http://www.debian-administration.org/articles/31

Monday, May 15, 2006

teleline dial-in server

建立經電話線撥入登錄服務器,用modem透過電話線撥入.
server 先安裝好modem, 用外置56k modem 接入com port, 接上電源和電話線.
外置modem安裝較簡單,尤其舊式com port, 在linux下不需要安任何driver, 只要選對相應的端口.而且外且式modem有燈號可查看工作狀態.
安裝mgetty
shell# apt-get install mgetty
修改 /etc/inittab 加入或移除# "T3:23:respawn:/sbin/mgetty -x0 -n8 -s 38400 ttyS1" 其中-n8 為8下鈴聲後由modem接聴. -s 38400 為連線速度.(PSTN 一般為38400)
重新開機或行telinit 再行一次運行相應的級別.
shell# telinit q
由另外一個modem 經電話線撥入即可.

TIPS:
ttyS0 為com 0, 在接入modem到com port 後,若不知所接的為那個com口, 可留意modem 燈號, TT , 若在/etc/inittab 中設置正確並telinit q後, TT燈會亮, 可由ttyS0,ttyS1...逐個試.

Sunday, May 07, 2006

RSS test in blogger.com

I found that the blogger.com seem supports RSS on my blog and bookmark it, i post this article to test the bookmark will update my new post or not.
it will update the blog titles every time start up firefox,
i install the infoRSS.xpi and set it to get update from my blog, but no luck, coz the RSS support in blogger.com olny support blogger-pro version.

network design [::] wireless subnet+firewall+vpn

前言:
剛買了手提電腦,家中的無線設備終於有用武之地,設定AP(NOKIA) 用WI-FI WEP連線.完成後出現一些問題,都是與防火墻(Bering & Shorewall)的設置有關--不同subnet間的連線限制所致.後來用VPN撥接,不但解決了其中問題,亦意外地發現利用這種方式,可以實現一些想了很久的存取管理.證明了OpenSource的力量.

系統環境:(亦即是現在家中的網絡,但免日後有混淆,還是說明一下.)
核心是一部Pentium100建成的防火墻及ADSL寛頻路由器(機名firewall),有多個網卡,用意為建立不同的子網(subnet),以實現不同的需求和管理.使用C 類私有IP::192.168.x.x/24; 分別為192.168.0.0/24(名為loc)和192.168.1.0/24(名為wlan). subnet 0 有部實驗用的Debian Linux Server(機名debsrv), ip:192.168.1.253/24 運行服務有ssh, dns (解析本地域,一個私有自設名為lab.的域), apache web server(兩個virturl host: www.debsrv.lab 和 mail.debsrv.lab)以及其它一些服務,詳細設定略去. subnet 0 還有一部windows xp 的機(winxpc), 有數個文件共享. 而Subnet 1 則為接有一部無線AP. 供無線網絡客戶接入.整個系統的IP及網絡設定由firewall負責.同時作為dns forwader接Internet和lab. 域的Secondary DNS (均由DNSMasq實現).

對wlan中的電腦的網絡連線管理,可以由firewall 依 IP來管理,但對於像無線網絡這種存在風險的環境,若一視同仁地開放網絡是不智.若要讓個別user能存取又不影響安全性, 又不會影響一般用戶,VPN可以提供合宜的方案.以本例,在wlan的電腦可以使用Internet,對於在loc的提供的服務則不開放,但容許個別用戶使用.

首先為wlan用戶提供基本上網服務,這包括對Internet DNS查詢, 對firewall的ssh連線. 網絡設置由DHCP提供.
DNSMasq 完成對兩個subnet提供DHCP和dns 查詢緩存功能.會根據客戶所在subnet而提供合適IP設置如下:
Windows IP Configuration
Host Name . . . . . . . . . . . . : D2N2L2BX
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : lab

Ethernet adapter Wireless Network Connection:
Connection-specific DNS Suffix . : lab
Description . . . . . . . . . . . : Intel(R) PRO/Wireless 2200BG Network Connection
Physical Address. . . . . . . . . : 00-16-6F-71-6F-93
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes

IP Address. . . . . . . . . . . . : 192.168.1.200
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.254
DHCP Server . . . . . . . . . . . : 192.168.1.254
DNS Servers . . . . . . . . . . . : 192.168.0.253 192.168.0.254

Lease Obtained. . . . . . . . . . : Sunday, May 07, 2006 3:09:35 PM
Lease Expires . . . . . . . . . . : Monday, May 08, 2006 3:09:35 AM
特別注意是default gateway 及 dns server, 1.254和0.254都是firewall的兩個網卡ip, 而0.253則是lab域的Primary DNS.

Shorewall 提供firewall iptable 管理和設定.
/etc/shorewall/interfaces
#ZONE INTERFACE BROADCAST OPTIONS
#net eth0 detect dhcp,routefilter,norfc1918
net ppp0 -
wlan eth1 detect
loc eth0 detect
loc ppp+
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE

/etc/shorewall/zones
#ZONE DISPLAY COMMENTS
net Net Internet
loc Local Local networks
wlan Wireless Wireless networks
#LAST LINE - ADD YOUR ENTRIES ABOVE THIS ONE - DO NOT REMOVE

/etc/shorewall/policy
#SOURCE DEST POLICY LOG LIMIT:BURST
# LEVEL
loc net ACCEPT
wlan net ACCEPT
net all DROP ULOG
fw loc ACCEPT
fw wlan ACCEPT
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE

/etc/shorewall/rules
因設定檔太長,相關扼述如下:
allow loc -> fw tcp22 udp53 udp67,68 tcp80
allow wlan -> fw tcp22 udp53 udp67,68 tcp80
ssh/22 dns/53 dhcp/67,68 weblet/80
allow loc -> fw tcp47,1723
allow wlan ->fw tcp47,1723
VPN pptpd/47,1723

由interfaces, ppp0為adsl接入Internet的介面卡, 而ppp+ 則視為與loc在同一個子網的介面卡,據測試,ppp+不包括ppp0.在vpn 連接時, server會建立ppp虛擬介面卡,若此時不存在ppp0則會使用了ppp0,將該vpn 連接視為net zone 限制連入loc.而使用ppp1則不會.

/etc/pptpd.conf
localip 192.168.0.254
remoteip 192.168.0.100-110

/etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client server secret IP addresses
username pptpd "vpnpassword" *

設置後,在wlan的用戶,可連上Internet,(無線網則先建立無線連接),正常使用各類Internet服務,但對於在loc的所有訪問則禁止,此時,個別用戶若要連入loc,則先進行VPN 連線,成為loc的一部份,wlan 電腦取得ip 設置如下:
PPP adapter 254:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
Physical Address. . . . . . . . . : 00-53-45-00-00-00
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.0.100
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 192.168.0.100
此時,該機就可以使用在loc中debsrv 的DNS services 找www.debsrv.lab 和 mail.debsrv.lab 以及 winxpc 中網上鄰居的共享. 同時亦可連上Internet.

以下是VPN 連線前後wlan中電腦網絡狀態一些比較:
連接前:
netstat -nr
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...00 16 6f 71 6f 93 ...... Intel(R) PRO/Wireless 2200BG Network Connection - Packet Scheduler Miniport
===========================================================================
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.254 192.168.1.200 30
65.54.179.192 255.255.255.255 192.168.1.254 192.168.1.200 30
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.1.0 255.255.255.0 192.168.1.200 192.168.1.200 30
192.168.1.200 255.255.255.255 127.0.0.1 127.0.0.1 30
192.168.1.255 255.255.255.255 192.168.1.200 192.168.1.200 30
207.46.219.62 255.255.255.255 192.168.1.254 192.168.1.200 30
224.0.0.0 240.0.0.0 192.168.1.200 192.168.1.200 30
255.255.255.255 255.255.255.255 192.168.1.200 192.168.1.200 1
Default Gateway: 192.168.1.254
===========================================================================
Persistent Routes:
None


tracert www.google.com
Tracing route to www.l.google.com [66.249.89.99]

over a maximum of 30 hops:
1 3 ms 3 ms 3 ms 192.168.1.254
2 17 ms 16 ms 16 ms nrp28.macau.ctm.net [202.175.100.28]
3 18 ms 17 ms 19 ms v601a.macau.ctm.net [202.175.95.61]
4 19 ms 19 ms 16 ms gw3-192.macau.ctm.net [202.175.26.203]
5 24 ms 22 ms 24 ms pr3-pos1.macau.ctm.net [202.175.1.42]
6 38 ms 40 ms 42 ms rs1.hkix.net [202.40.161.1]
7 38 ms 43 ms 38 ms 192.168.168.34
8 28 ms 31 ms 28 ms google2-RGE.hkix.net [218.100.16.24]
9 93 ms 97 ms 96 ms 72.14.236.228
10 100 ms 110 ms 101 ms 72.14.236.208
11 105 ms 104 ms 97 ms 66.249.89.99
Trace complete.


VPN連線後:
PPP adapter 254:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
Physical Address. . . . . . . . . : 00-53-45-00-00-00
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.0.100
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 192.168.0.100


netstat -nr
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...00 16 6f 71 6f 93 ...... Intel(R) PRO/Wireless 2200BG Network Connection - Packet Scheduler Miniport
0xe0004 ...00 53 45 00 00 00 ...... WAN (PPP/SLIP) Interface
===========================================================================
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.0.100 192.168.0.100 1
0.0.0.0 0.0.0.0 192.168.1.254 192.168.1.200 31
65.54.179.192 255.255.255.255 192.168.1.254 192.168.1.200 30
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.0.100 255.255.255.255 127.0.0.1 127.0.0.1 50
192.168.0.255 255.255.255.255 192.168.0.100 192.168.0.100 50
192.168.1.0 255.255.255.0 192.168.1.200 192.168.1.200 30
192.168.1.200 255.255.255.255 127.0.0.1 127.0.0.1 30
192.168.1.254 255.255.255.255 192.168.1.200 192.168.1.200 30
192.168.1.255 255.255.255.255 192.168.1.200 192.168.1.200 30
207.46.219.62 255.255.255.255 192.168.1.254 192.168.1.200 30
224.0.0.0 240.0.0.0 192.168.1.200 192.168.1.200 30
224.0.0.0 240.0.0.0 192.168.0.100 192.168.0.100 1
255.255.255.255 255.255.255.255 192.168.0.100 192.168.0.100 1
255.255.255.255 255.255.255.255 192.168.1.200 192.168.1.200 1
Default Gateway: 192.168.0.100
===========================================================================
Persistent Routes:
None

Route Table

tracert www.google.com
Tracing route to www.l.google.com [66.249.89.99]
over a maximum of 30 hops:
1 5 ms 5 ms 5 ms 192.168.0.254
2 20 ms 20 ms 19 ms nrp28.macau.ctm.net [202.175.100.28]
3 19 ms 19 ms 20 ms v601a.macau.ctm.net [202.175.95.61]
4 19 ms 19 ms 19 ms gw3-192.macau.ctm.net [202.175.26.203]
5 25 ms 23 ms 23 ms 202.175.1.42
6 24 ms 28 ms 24 ms rs1.hkix.net [202.40.161.1]
7 27 ms 30 ms 26 ms 192.168.168.34
8 33 ms 29 ms 32 ms google2-RGE.hkix.net [218.100.16.24]
9 97 ms 100 ms 98 ms 72.14.236.228
10 111 ms 102 ms 106 ms 72.14.236.208
11 182 ms 143 ms 99 ms 66.249.89.99

Trace complete.

P.S 存在VPN連線時,暫時發現會造成msn不能連線; 本blog 編輯時不能save as draft, 而一般網頁瀏覽則未發現有問題.