2009年7月2日 星期四

Squid 使用者認證

fedora core 10
STEP 1: 建立使用者及密碼檔
[ 建立第一個使用者及設定密碼 ]
# htpasswd -cb /etc/squid/allowuser username passwd


[ 增加第二個使用者 ]
# htpasswd -b /etc/squid/allowuser username2 passwd2

[ 將檔案權限設為755 ]
# chmod 755 /etc/squid/allowuser
STEP 2: 設定squid.conf
[ 編輯squid.conf組態檔 ]
# vi /etc/squid/squid.conf

[ 在auth_param區加入 ]
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/allowuser
(check ncsa_auth所在位置)
(allowuser 是用htpasswd所產生出來, 用來check user/passwd)

[ 在acl區的第一行加入 ]
acl need_auth proxy_auth REQUIRED

[ 在http_access區的第一行加入 ]
http_access allow need_auth

STEP 3: 重新啟動squid
#service squid restart

2009年7月1日 星期三

stunnel 設定

想要跑stunnel.
首先當然先要有一台主機讓你跑stunnel server端.

server端的 stunnel.conf 設定
----------------------------------------------------------------------
cert=stunnel.crt
key = stunnel.key
;這兩個參數可以用ssl 產生, 要高級認證就很麻煩.
;想知道更多可以google一下吧!
taskbar=no
;這個參數可以隱藏STUNELL的圖示,如果做壞事就用$%#%#
client=no
;這個不一定要設定, 預設是server
[socks2ssl]
accept = 80
;在80 port listen.. 接外部連接, 可設定鎖固定ip.
connect = 127.0.0.1:1080 ;
;連到local proxy, 記得架好proxy開啟user login mode.
;如果上面沒鎖ip
----------------------------------------------------------------------
client端的stunnel.conf設定

client = yes

[ssl2SOCKS]
accept = 127.0.0.1:8282
;讓你想連到local stunnel的程式然後轉出去.
connect = xxx.xxx.xxx.xxx:80
;連接到你的Server端ip xxx.xxx.xxx.xxx:80, 透過80轉到server端
----------------------------------------------------------------------
以上設定大概ok.
產生cert 跟key 透過下面指令(linux下有ssl)

# 建立 server.key 使用 1024-bit key 加密
openssl genrsa -out server.key 1024
# 建立 server.crt 憑證,有效時間為 3650 天,使用 X.509 憑證格式
# 一次生10年 :p
openssl req -new -key server.key -out server.crt -x509 -days 3650
如此一來就產生 server.key and server.crt 兩個憑證檔(apache格式)
不過有些軟體是用 pem 格式 (e.x. stunnel, dovecot...ect)
經測試, 只要一行命令就可以產生 pem 了:
cat server.key > stunnel.pem
記得權限改一下:
chmod go-rwx server.key stunnel.pem
stunnel官網 有windows binary file