SVN+Apache+SSL的配置說明

SVN+Apache+SSL的配置說明

clip_image002

夏妙

二零一零年十月

目 錄

第 1 章 前言.... 1

第 2 章 CollabNetSubversion.. 1

第 3 章 SSL的個人淺見.... 2

第 4 章 SVN+Apache+SSL環境搭建過程.... 5

4.1 第一步:安裝CollabNetSubversion服務端... 5

4.2 第二步:安裝Subversion客戶端... 8

4.3 第三步:創建測試用的版本庫(repository)... 11

4.4 第四步:配置Apache服務... 11

4.4.1 配置Apache 和 Subversion的集成... 11

4.4.2 配置Apache響應客戶端提交的svn訪問請求... 12

4.4.3 創建Apache服務要求的基本認證密碼文件“passwd”. 13

4.5 第五步:測試Apache服務... 14

4.6 第六步:使用SVN客戶端在測試版本庫TestRepository1中創建若干測試項目文件夾... 26

4.7 第七步:配置版本庫目錄精確授權訪問... 28

4.8 第八步:使用SVN客戶端在測試版版本庫精確目錄授權訪問功能... 31

4.9 第九步:爲Apache服務配置SSL功能(不進行客戶端身份鑑別)... 36

4.9.1 虛擬一個CA認證中心... 38

4.9.2 SVN服務器端向CA中心申請數字證書... 39

4.9.3 CA中心爲SVN服務器端頒發數字證書... 42

4.9.4 啓用Apache的SSL功能... 46

4.9.5 配置SSL功能模塊... 47

4.9.6 測試SSL功能... 59

4.9.6.1 測試啓用了SSL的Apache服務... 59

4.9.6.2 測試啓用了SSL的版本庫訪問... 61

4.9.6.3 採用TortoiseSVN客戶端測試基於SSL的版本庫訪問... 63

4.9.7 在客戶端安裝CA根證書... 67

4.9.7.1 在客戶端瀏覽器中安裝數字證書... 69

4.9.7.2 在TortoiseSVN客戶端中安裝CA根證書... 73

4.9.8 再次測試SSL功能(在客戶端安裝了CA根證書後)... 78

4.9.8.1 測試啓用了SSL的Apache服務... 78

4.9.8.2 測試啓用了SSL的版本庫訪問... 80

4.9.8.3 採用TortoiseSVN客戶端測試基於SSL的版本庫訪問... 81

4.10 第十步:爲Apache服務配置SSL功能(要求進行客戶端身份鑑別)... 85

4.10.1 客戶端向CA中心申請數字證書... 86

4.10.2 CA中心爲客戶端頒發數字證書... 88

4.10.3 配置SSL啓用客戶端身份鑑別功能... 90

4.10.4 在客戶端安裝個人專用的客戶端數字證書... 102

4.10.4.1 在客戶端瀏覽器中安裝個人客戶端數字證書... 103

4.10.4.2 在TortoiseSVN客戶端中安裝個人數字證書... 107

4.10.5 測試要求進行客戶端身份鑑別的SSL功能(在客戶端安裝了CA根證書以及個人客戶端證書後) 111

4.10.5.1 測試啓用了SSL的Apache服務... 111

4.10.5.2 測試啓用了SSL的版本庫訪問... 113

4.10.5.3 採用TortoiseSVN客戶端測試基於SSL的版本庫訪問... 114

第 1 章 前言

花了3天的時間終於搞定了SVN+Apache+SSL的環境搭建,網上瘋狂的搜索大部分都是針對SVN+svnserve或者SVN+Apache的配置(都比較簡單,照着網上的文章配置成功率很高),但是針對SVN+Apache+SSL的配置都講得太過簡單,可操作性不強,下面把自己的辛苦經歷歸納整理成文,希望能夠幫助到新手少走彎路。

第 2 章 CollabNetSubversion

SVN(Subversion)是一個開源項目,有很多贊助商提供免費的維護升級,我這裏選擇的是CollabNet提供的版本,目前該公司提供了一個集成了SVN+Apache+ViewVC的集成安裝版本,叫:CollabNetSubversionEdge,於是下載了最新版:CollabNetSubversionEdge-1.2.2,安裝後試用後各項功能都比較方便(基本上不用進行配置),提供了基於瀏覽器的管理平臺,所有的版本庫、用戶、目錄授權等都可以基於該管理平臺實現,並且給客戶端提供了ViewVC應用(客戶端可以直接使用瀏覽器查看版本庫內容)。但是唯一不好使的是啓用SSL後就不能夠正常訪問了,並且其安裝目錄下的各配置文件目錄結構,包括配置內容都與早期SVN+Apache版本大相徑庭,相去甚遠,從網絡上搜索的資料都沒法實驗(這個集成安裝版本出來還沒有幾天,資料匱乏)。

最終也沒有能夠使用這個集成安裝版本(CollabNetSubversionEdge-1.2.2)實現基於SSL的安全訪問(https://),當時就想怎麼給配起來能夠正常運轉,也沒有弄清楚SSL的真實含義和應用機制以及驗證流程(只知道是比http安全,數據內容都是加密傳輸),結果是囫圇了大半天也未果,對於出現的錯誤沒有辦法發揮主觀能動性進行積極的思考。痛定思痛後,決定先搞清楚SSL是個啥,經過多方查閱後,從應用層面上對SSL算是基本搞清楚了。

第 3 章 SSL的個人淺見

SSL(Secure Sockets Layer 安全套接層)主要用於實現http請求會話的客戶端和服務器端的雙向身份認證,並對會話過程中的數據進行加密傳輸,從而保證網絡訪問的安全性。這些安全功能都是由客戶端瀏覽器和服務器端http服務之間協作自動完成的,對使用者完全透明,使用者只是看見了一個https而已。但是現在是要自己來配置實現就不得不搞清楚其驗證機制了,網上有較多文章對該驗證過程進行了詳細的描述,摘抄部分如下:

----------以下來自百度百科--------------------------------------------

服務器認證階段:

1)客戶端向服務器發送一個開始信息“Hello”以便開始一個新的會話連接;

2)服務器根據客戶的信息確定是否需要生成新的主密鑰,如需要則服務器在響應客戶的“Hello”信息時將包含生成主密鑰所需的信息;

3)客戶根據收到的服務器響應信息,產生一個主密鑰,並用服務器的公開密鑰加密後傳給服務器;

4)服務器恢復該主密鑰,並返回給客戶一個用主密鑰認證的信息,以此讓客戶認證服務器。

用戶認證階段:

在此之前,服務器已經通過了客戶認證,這一階段主要完成對客戶的認證。經認證的服務器發送一個提問給客戶,客戶則返回(數字)簽名後的提問和其公開密鑰,從而向服務器提供認證。

------------------以下來自:http://blog.csdn.net/ast_224/archive/2009/01/19/3837155.aspx,這裏面還有詳盡的圖示,值的一看------------------------

SSL握手過程:
摘錄自《SSL與TLS》
目的:
1. 客戶端與服務器需要就一組用於保護數據的算法達成一致;
2. 它們需要確立一組由那些算法所使用的加密密鑰;
3. 握手還可以選擇對客戶端進行認證。

過程:
1. 客戶端將它所支持的算法列表和一個用作產生密鑰的隨機數發送給服務器;
2. 服務器從算法列表中選擇一種加密算法,並將它和一份包含服務器公用密鑰的證書發送給客戶端;該證書還包含了用於認證目的的服務器標識,服務器同時還提供了一個用作產生密鑰的隨機數;
3. 客戶端對服務器的證書進行驗證(有關驗證證書,可以參考數字簽名),並抽取服務器的公用密鑰;然後,再產生一個稱作pre_master_secret的隨機密碼串,並使用服務器的公用密鑰對其進行加密(參考非對稱加/解密),並將加密後的信息發送給服務器;
4. 客戶端與服務器端根據pre_master_secret以及客戶端與服務器的隨機數值獨立計算出加密和MAC密鑰(參考DH密鑰交換算法)。
5. 客戶端將所有握手消息的MAC值發送給服務器;
6. 服務器將所有握手消息的MAC值發送給客戶端。

上述SSL驗證流程的說明都沒有結合CA(認證中心)講解數字證書在整個驗證過程的應用模式,在此將個人理解補充如下。

下面會涉及到公鑰和私鑰的概念,個人簡單理解就是:他們是成對出現的,如果有這麼一對公鑰/私鑰(公鑰是P,私鑰是S),那麼用P加密後的數據必須用S才能夠正確解密,反過來也是一樣的,用S加密的數據只有用P才能解密。至於他們到底幹啥用的,舉個形象的例子來說明。財務室有個上鎖的保險櫃(比擬服務器端),xm是財務出納並且分配擁有一把鑰匙,保險櫃知道目前公司只有xm具備鑰匙(xm比擬爲客戶端,鎖比擬爲公鑰P,鑰匙比擬爲私鑰S,保險櫃裏面的錢比擬爲用公鑰P加密後的數據),而鎖和鑰匙是成對出現的,如果現在有人用鑰匙把鎖打開了並拿到了錢(比擬爲通過用私鑰S對公鑰P加密的數據進行了正確解密,並得到了解密後數據--錢!),保險櫃當即就認爲開鎖從保險櫃拿錢的人是xm,因爲他知道只有公司出納xm才擁有鑰匙,當初是因爲信任xm纔會分發鑰匙給他的,現在鎖開了就認定這個拿錢人一定是xm,從而實現了拿錢人(數據訪問者/客戶端)身份的鑑別,總之就是可以用於在網絡會話中鑑別對方的身份。

數字證書在整個SSL會話驗證過程中的完整應用機制如下圖所示:

clip_image004

經過後面的摸索過程才知道上圖中的SSL只進行了服務器端身份的鑑別,並沒有進行客戶端身份的鑑別。SSL可以配置是否要求鑑別客戶端身份,這個在後面詳述。下面就先針對這種不鑑別客戶端身份的SVN+Apache+SSL應用環境闡述其在Windows下的搭建過程。

第 4 章 SVN+Apache+SSL環境搭建過程

4.1 第一步:安裝CollabNetSubversion服務端

可以從官網http://www.open.collab.net/downloads/subversion/svn1.5.html下載最新版的CollabNet Subversion Server and Client,目前最新版本是 v1.6.13 (for Windows),注意不要下載CollabNetSubversionEdge集成安裝包,下面的搭建過程對其不適用。

這裏我採用了默認的安裝目錄 C:\Program Files\CollabNet\Subversion Server

安裝過程中的下面這個步驟要特別注意,下圖中的Apache(MOD_DAV_SVN)一定要勾上,表示安裝Apache http服務,並且集成對SVN的訪問處理。

附帶說明一下圖中的SVNSERVE是適用於局域網的SVN服務,支持svn:的訪問處理,安裝Apache後可以支持svn服務的http:訪問處理,後面我們再爲Apache配置上SSL,那麼就可以支持svn服務的https:訪問處理了。

clip_image005

clip_image006

安裝嚮導要求輸入服務的端口號,SVNSERVE的端口缺省填入的是3690,Apache服務的端口缺省填入的是80,因爲我有安裝IIS(80已被佔用),故調整爲8080。

然後還要求輸入SVN版本庫的安裝目錄,我選擇:e:\svn_repository

clip_image007

嚮導界面上的其他選項保持缺省值不變,然後下一步直至安裝完成,安裝完畢後會在windows服務中註冊兩個服務程序。

clip_image008

注意:如果是XP等具備Windows防火牆的操作系統,需要將上述TCP端口號3690和8080添加至正常訪問列表中,可通過防火牆設置程序來添加例外通過的端口號,也可以通過以下命令行腳本來添加(在運行框或DOS窗口中執行即可)。

執行下面這行表示添加TCP 3690端口號至防火牆例外通過的端口列表中

netsh firewall set portopening protocol = TCP port = 3690 name = SvnservePort mode = ENABLE scope = SUBNET profile = CURRENT

執行下面這行表示添加TCP 8080端口號至防火牆例外通過的端口列表中

netsh firewall set portopening protocol = TCP port = 8080 name = ApachePort mode = ENABLE scope = SUBNET profile = CURRENT

關於SVNSERVE的配置比較簡單(略過),如果只允許通過http:訪問SVN,那麼可以不用安裝SVNSERVE服務,下面針對Apache進行配置說明。

4.2 第二步:安裝Subversion客戶端

實際上在SVN服務端是不需要安裝Subversion客戶端的,但是如果安裝了那麼我們在創建版本庫的時候會很便捷,可以拋棄比較繁瑣的命令行方式。

這裏我選擇的Subversion客戶端是赫赫有名的TortoiseSVN,他很好的與Windows資源管理器進行了集成,並且最有價值的是提供了非常有用的幫助文檔,可以對SVN服務的配置有個全面的認識,但是裏面對Apache的SSL配置太模糊,使我走了很多彎路。

可以從官網(http://tortoisesvn.net/downloads)下載最新版本,目前是1.6.11,記得同時下載簡體中文語言安裝包(在同一個下載頁面的底部)。

TortoiseSVN安裝界面如下:

clip_image009

簡體中文語言包安裝界面如下:

clip_image010

接着需要設置客戶端語言環境爲中文:

在Windows資源管理器任意地方點擊右鍵選擇TortoiseSVN菜單中的Settings

clip_image011

在設置界面上的Language選項中選擇:中文(簡體)即可。

clip_image012

4.3 第三步:創建測試用的版本庫(repository

在windows資源管理器中打開我選擇的版本庫目錄:e:\svn_repository,新建文件夾TestRepository1,然後再新建的TestRepository1文件夾上點擊鼠標右鍵,選擇TortoiseSVN菜單”在此創建版本庫”,該測試版本庫留待後面的Apache服務配置完成後進行測試使用。

clip_image013

4.4 第四步:配置Apache服務

4.4.1 配置Apache Subversion的集成

如果採用上述安裝包進行Subversion和Apache的集成安裝,那麼安裝嚮導會自動完成了大部分在Apache服務中集成SVN的配置,例如完成了mod_dav_svn.so和mod_authz_svn.so文件的拷貝處理,但仍有小量的配置工作要做。用UltraEdit之類的文本編輯器打開Apache服務的配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\httpd.conf)進行如下配置:

搜索到下面這行配置內容,去掉首字符#(帶#表示註釋信息,去掉#表示生效的配置信息)

#LoadModule dav_fs_module modules/mod_dav_fs.so

將以下配置內容添加到 LoadModule 節的末尾

LoadModule authz_svn_module modules/mod_authz_svn.so

從D:\Program Files\CollabNet\Subversion Server目錄下拷貝以下文件至Apache的bin目錄(D:\Program Files\CollabNet\Subversion Server\httpd\bin):

libdb41.dll
libapr-1.dll
libaprutil-1.dll
libsvn_delta-1.dll
libsvn_fs-1.dll
libsvn_repos-1.dll
libsvn_subr-1.dll

拷貝過程中如果提示目標文件已經存在,可以選擇否(不覆蓋)。

注意:上述這些文件必須確保都存在於Apache的bin目錄,否則Apache服務將無法啓動,報cannot load mod_dav_svn.so的錯誤信息。

4.4.2 配置Apache響應客戶端提交的svn訪問請求

在Apache服務的配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\httpd.conf)末尾將<Location /svn>節的配置內容替換爲如下內容:

#<Location /svn>的意思是Subversion版本庫的URL是http://servername/svn
<Location /svn>
   #告訴Apache是哪個模塊響應那個URL的請求-此刻是Subversion模塊。
   DAV svn
   #對於 Subversion 1.3 或者更高版本,這個指示會列出所有 SVNParentPath 中的版本庫。
   SVNListParentPath on
   #告訴Subversion需要查看的版本庫位於e:\svn_repository之下
   SVNParentPath e:\svn_repository
   #激活基本認證,就是用戶名/密碼
   AuthType Basic
   #指定當客戶端在訪問版本庫時彈出要求用戶輸入認證信息的認證對話框上顯示的信息
   AuthName "Subversion repositories login:"
   #指定使用的認證密碼文件,passwd是用戶密碼驗證文件,要求放置在httpd子目錄下
   AuthUserFile passwd
   #指定精確的控制版本庫目錄訪問的授權文件路徑,
   #svnaccessfile是目錄授權文件(可對訪問用戶進行版本庫中任意目錄的授權),要求放置在httpd目錄下
   #如果不需要進行細粒度的目錄授權控制,則可以把下面這行配置內容用#註釋掉
   #AuthzSVNAccessFile svnaccessfile
   #指定只有輸入了正確的用戶/密碼的用戶可以訪問URL
   Require valid-user
</Location>

4.4.3 創建Apache服務要求的基本認證密碼文件“passwd”

這個密碼文件的文件名在前面的配置文件中由下面這句話指定了:

   #指定使用的認證密碼文件,passwd是用戶密碼驗證文件,要求放置在httpd子目錄下
   AuthUserFile passwd

打開命令行提示符(DOS 窗口),進入 D:\Program Files\CollabNet\Subversion Server\httpd\bin 目錄,通過輸入下面的命令創建密碼文件passwd,並添加一個訪問用戶xm,後續會要求輸入用戶的密碼。

htpasswd –c ..\passwd xm

clip_image014

用下面的命令增加其它用戶:

htpasswd ..\passwd otherusername

至此,Apache集成Subversion服務的配置基本完成(不開啓SSL),下面進行測試。

4.5 第五步:測試Apache服務

在Windows服務管理界面找到CollabNet Subversion Apache服務,並啓動/重新啓動它,如果前面的配置都沒有遺漏的話應該就可以順序啓動Apache服務了。

注意:下面的圖示都是直接在Apache服務端進行測試,如果在另一臺客戶端機器上做測試,需要將地址欄中的localhost替換爲該Apache服務器的計算機名稱或IP地址。

在IE瀏覽器中輸入地址http://localhost:8080,顯示It works!,表示Apache服務已經在工作了。

clip_image015

下面進一步測試Apache對Subversion請求的處理是否正常。

在IE瀏覽器中輸入地址:http://localhost:8080/svn/,並且輸入我們之前創建的版本庫用戶名和密碼後,瀏覽器顯示出了我們之前創建的測試版本庫TestRepository1,表示Apache與Subversion已經正確集成,可以處理客戶端提交的svn訪問請求。

clip_image016

clip_image017

Apache服務配置文件內容實例

此時,整個Apache服務配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\httpd.conf)的內容如下:

#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned. 
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "C:\Program Files\CollabNet\Subversion Server/httpd" will be interpreted by the
# server as "C:\Program Files\CollabNet\Subversion Server/httpd/logs/foo.log".
#
# NOTE: Where filenames are specified, you must use forward slashes
# instead of backslashes (e.g., "c:/apache" instead of "c:\apache").
# If a drive letter is omitted, the drive on which Apache.exe is located
# will be used by default.  It is recommended that you always supply
# an explicit drive letter in absolute paths, however, to avoid
# confusion.
#

# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum  number of requests a server process serves
ThreadsPerChild 250
MaxRequestsPerChild  0

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk.  If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "C:\Program Files\CollabNet\Subversion Server/httpd"

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen 8080

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule cgi_module modules/mod_cgi.so
#LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule headers_module modules/mod_headers.so
LoadModule imagemap_module modules/mod_imagemap.so
LoadModule include_module modules/mod_include.so
#LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule negotiation_module modules/mod_negotiation.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule status_module modules/mod_status.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule ssl_module modules/mod_ssl.so
LoadModule dav_module         modules/mod_dav.so
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. [email protected]
#
ServerSignature On
ServerAdmin localhost@localdomain

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:8080

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:\Program Files\CollabNet\Subversion Server/httpd/htdocs"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features. 
#
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Satisfy all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "C:\Program Files\CollabNet\Subversion Server/httpd/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
</FilesMatch>

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog logs/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog logs/access.log common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog logs/access.log combined
</IfModule>

<IfModule alias_module>
    #
    # Redirect: Allows you to tell clients about documents that used to
    # exist in your server's namespace, but do not anymore. The client
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://www.example.com/bar

    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

    #
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client.  The same rules about trailing "/" apply to ScriptAlias
    # directives as to Alias.
    #
    ScriptAlias /cgi-bin/ "C:\Program Files\CollabNet\Subversion Server/httpd/cgi-bin/"

</IfModule>

#
# "C:\Program Files\CollabNet\Subversion Server/httpd/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "C:\Program Files\CollabNet\Subversion Server/httpd/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

#
# Apache parses all CGI scripts for the shebang line by default.
# This comment line, the first line of the script, consists of the symbols
# pound (#) and exclamation (!) followed by the path of the program that
# can execute this specific script.  For a perl script, with perl.exe in
# the C:\Program Files\Perl directory, the shebang line should be:

   #!c:/program files/perl/perl

# Note you _must_not_ indent the actual shebang line, and it must be the
# first line of the file.  Of course, CGI processing must be enabled by
# the appropriate ScriptAlias or Options ExecCGI directives for the files
# or directory in question.
#
# However, Apache on Windows allows either the Unix behavior above, or can
# use the Registry to match files by extention.  The command to execute
# a file of this type is retrieved from the registry by the same method as
# the Windows Explorer would use to handle double-clicking on a file.
# These script actions can be configured from the Windows Explorer View menu,
# 'Folder Options', and reviewing the 'File Types' tab.  Clicking the Edit
# button allows you to modify the Actions, of which Apache 1.3 attempts to
# perform the 'Open' Action, and failing that it will try the shebang line.
# This behavior is subject to change in Apache release 2.0.
#
# Each mechanism has it's own specific security weaknesses, from the means
# to run a program you didn't intend the website owner to invoke, and the
# best method is a matter of great debate.
#
# To enable the this Windows specific behavior (and therefore -disable- the
# equivilant Unix behavior), uncomment the following directive:
#
#ScriptInterpreterSource registry
#
# The directive above can be placed in individual <Directory> blocks or the
# .htaccess file, with either the 'registry' (Windows behavior) or 'script'
# (Unix behavior) option, and will override this server default option.
#

#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #AddHandler cgi-script .cgi

    # For type maps (negotiated resources):
    #AddHandler type-map var

    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml
</IfModule>

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type.  The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile conf/magic

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#

#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall is used to deliver
# files.  This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
#
#EnableMMAP off
#EnableSendfile off

# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
#Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
#Include conf/extra/httpd-default.conf

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

#<Location /svn>的意思是Subversion版本庫的URL是http://servername/svn
<Location /svn>
   #告訴Apache是哪個模塊響應那個URL的請求-此刻是Subversion模塊。
   DAV svn
   #對於 Subversion 1.3 或者更高版本,這個指示會列出所有 SVNParentPath 中的版本庫。
   SVNListParentPath on
   #告訴Subversion需要查看的版本庫位於e:\svn_repository之下
   SVNParentPath e:\svn_repository
   #激活基本認證,就是用戶名/密碼
   AuthType Basic
   #指定當客戶端在訪問版本庫時彈出要求用戶輸入認證信息的認證對話框上顯示的信息
   AuthName "Subversion repositories login:"
   #指定使用的認證密碼文件,passwd是用戶密碼驗證文件,要求放置在httpd子目錄下
   AuthUserFile passwd
   #指定精確的控制版本庫目錄訪問的授權文件路徑,
   #svnaccessfile是目錄授權文件(可對訪問用戶進行版本庫中任意目錄的授權),要求放置在httpd目錄下
   #如果不需要進行細粒度的目錄授權控制,則可以把下面這行配置內容用#註釋掉
   #AuthzSVNAccessFile svnaccessfile
   #指定只有輸入了正確的用戶/密碼的用戶可以訪問URL
   Require valid-user
</Location>

4.6 第六步:使用SVN客戶端在測試版本庫TestRepository1中創建若干測試項目文件夾

下面我將在測試版本庫TestRepository1中創建如下測試項目文件夾,我們採用之前安裝的TortoiseSVN客戶端來完成。

clip_image018

選擇TortoiseSVN菜單“版本庫瀏覽器”,要求輸入版本庫地址。

clip_image019

輸入TestRepository1測試版本庫的訪問地址:http://localhost:8080/svn/TestRepository1,確定後需要繼續進行身份認證。

clip_image020

輸入我們之前創建的版本庫用戶名和密碼後,版本庫瀏覽器將顯示TestRepository1版本庫下面的目錄結構,目前是空白的,沒有任何子目錄,下面通過右鍵菜單“創建文件夾”來分別創建project1、project2、project3三個測試項目文件夾。

clip_image021

這裏創建的TestRepository1測試版本庫中的3個項目子目錄(project1-3)留待備用,下面在闡述對版本庫目錄精確授權訪問的配置過程時將要使用它們。

4.7 第七步:配置版本庫目錄精確授權訪問

作爲源代碼管理,一般都是應該實現版本庫目錄的精確授權訪問,否則隱患很大!很有可能團隊中的某個人誤操作或主觀上有意無意的給你吧整個版本庫下的所有項目源代碼都刪除了,雖然之前的代碼不會丟,但會給正在工作的各個項目團隊帶來不小的麻煩。

首先要啓用目錄精確授權訪問功能,可以通過修改前面配置完畢的Apache服務配置文件(C:\Program Files\CollabNet\Subversion Server\httpd\conf\httpd.conf)來啓用該功能。

搜索到下面這行配置內容,去掉首字符#(帶#表示註釋信息,去掉#表示生效的配置信息)

#AuthzSVNAccessFile svnaccessfile

該配置項表示要求根據指定的svnaccessfile文件進行精確的版本庫目錄訪問權限檢查,未授權的目錄不允許訪問。svnaccessfile是目錄授權文件(可對訪問用戶進行版本庫中任意目錄的授權)。

注意:該svnaccessfile文件要求放置在httpd目錄下,這個文件的配置有格式要求,不過我們在創建版本庫目錄時程序會自動生成該配置文件樣例,直接拷貝過來即可,然後在其基礎上進行修改配置。

該樣例配置文件在版本庫目錄中的具體存放位置,以之前創建的TestRepository1測試版本庫目錄爲例,路徑爲:e:\svn_repository\TestRepository1\conf\authz,現在需要把這個authz文件拷貝至C:\Program Files\CollabNet\Subversion Server\httpd\conf目錄下,重命名爲svnaccessfile,然後用記事本或UltraEdit之類的文本編輯器打開它進行如下修改(下面是svnaccessfile文件直接配置完畢的結果),該配置文件各節含義比較簡單,話不多說,直接看配置文件中的註釋。

### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

#[groups]下配置的是用戶組及其成員信息
[groups]
# 定義一個名爲project1Group的用戶組,代表project1項目組的研發人員,目前包括 dxt 和 tby 兩個用戶成員
project1Group = dxt,tyb
# harry_sally_and_joe = harry,sally,&joe

# [/foo/bar]
# harry = rw
# &joe = r
# * =

# 精確指定具體版本庫下面的某個子目錄,然後配置那些用戶或用戶組具備哪些訪問權限(其下所有子目錄都繼承該權限),未配置的用戶無權訪問該目錄
# 訪問權限標識符說明:r表示只讀,w表示可寫,rw表示可讀寫,空格表示無權訪問
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

# 配置版本庫TestRepository1的根目錄的訪問授權(其下所有子目錄都繼承該權限)
[TestRepository1:/]
# xm可以讀寫
xm = rw

# 配置版本庫TestRepository1下的project1子目錄的訪問授權(其下所有子目錄都繼承該權限)
[TestRepository1:/project1]
# dxt可以讀寫
dxt = rw
# tyb可以讀寫
tyb = rw
# project1Group的用戶組可以讀寫
project1Group = rw

此時,整個Apache服務配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\httpd.conf)底部的內容如下:

#<Location /svn>的意思是Subversion版本庫的URL是http://servername/svn
<Location /svn>
   #告訴Apache是哪個模塊響應那個URL的請求-此刻是Subversion模塊。
   DAV svn
   #對於 Subversion 1.3 或者更高版本,這個指示會列出所有 SVNParentPath 中的版本庫。
   SVNListParentPath on
   #告訴Subversion需要查看的版本庫位於e:\svn_repository之下
   SVNParentPath e:\svn_repository
   #激活基本認證,就是用戶名/密碼
   AuthType Basic
   #指定當客戶端在訪問版本庫時彈出要求用戶輸入認證信息的認證對話框上顯示的信息
   AuthName "Subversion repositories login:"
   #指定使用的認證密碼文件,passwd是用戶密碼驗證文件,要求放置在httpd子目錄下
   AuthUserFile passwd
   #指定精確的控制版本庫目錄訪問的授權文件路徑,
   #svnaccessfile是目錄授權文件(可對訪問用戶進行版本庫中任意目錄的授權),要求放置在httpd目錄下
#如果不需要進行細粒度的目錄授權控制,則可以把下面這行配置內容用#註釋掉
AuthzSVNAccessFile svnaccessfile
   #指定只有輸入了正確的用戶/密碼的用戶可以訪問URL
   Require valid-user
</Location>

4.8 第八步:使用SVN客戶端在測試版版本庫精確目錄授權訪問功能

在Windows服務管理界面找到CollabNet Subversion Apache服務,並啓動/重新啓動它。

注意:下面的圖示都是直接在Apache服務端進行測試,如果在另一臺客戶端機器上做測試,需要將地址欄中的localhost替換爲該Apache服務器的計算機名稱或IP地址。

下面我將在測試版本庫TestRepository1中創建如下測試項目文件夾,我們採用之前安裝的TortoiseSVN客戶端來完成。

clip_image018[1]

選擇TortoiseSVN菜單“版本庫瀏覽器”,要求輸入版本庫地址。

clip_image019[1]

輸入TestRepository1測試版本庫的訪問地址:http://localhost:8080/svn/TestRepository1,確定後需要繼續進行身份認證。

clip_image022

這裏我們使用dxt用戶進行登錄,結果顯示禁止訪問的錯誤信息(在前面的目錄授權中沒有對dxt授予該目錄的訪問權限),這就證明我們配置的目錄精確授權控制起作用了。

clip_image023

然後重新用xm進行登錄(在前面的目錄授權中對xm授予了該目錄的讀寫訪問權限),結果正確顯示出了該目錄下的子目錄信息),這就再次證明我們配置的目錄精確授權控制確實起作用了。

clip_image024

clip_image025

至此,我們實現了SVN版本庫的http:方式的精確目錄授權訪問,如果再配置一個花生殼動態域名,就可以把我們的SVN服務放置在外網上了,從而實現異地多支項目團隊的協作開發。

但是http對身份驗證等會話信息都是以明文方式進行網絡傳輸,總歸是不太安全,我們可以進一步爲Apache配置SSL來加強網絡傳輸安全。

4.9 第九步:爲Apache服務配置SSL功能(不進行客戶端身份鑑別)

SSL這個東西的出現就是爲了進行網絡兩端身份的鑑別,並且對傳輸數據進行加密處理。網絡上針對Apache的SSL配置有很多文章,但是最麻煩的數字證書製作與配置這個環節基本上講得都比較模糊,個人經過艱難的摸索驗證,基本上理解了SSL這個應用環境的運作機制,數字證書在整個SSL會話驗證過程中的應用機制如下圖所示:

clip_image026

經過後面的摸索過程才知道上圖中的SSL只進行了服務器端身份的鑑別,並沒有進行客戶端身份的鑑別。SSL可以配置是否要求鑑別客戶端身份,這個在後面詳述。

下面就針對這種不鑑別客戶端身份的SSL應用環境,根據上圖中的應用流程闡述其配置過程,包括各種數字證書的製作過程。

4.9.1 虛擬一個CA認證中心

商業用的CA認證中心不是誰都能幹的,有很多嚴格的資格審查,如果是自己內部用完全可以自己來虛擬一個CA認證中心,下面就來生成CA認證中心必備的私鑰和自簽名的根證書。

打開命令行提示符(DOS 窗口),進入 Apache的bin目錄(C:\Program Files\CollabNet\Subversion Server\httpd\bin),通過輸入下面的命令創建ca_cert子目錄,用於存放CA中心的相關數字證書和密鑰等文件。

md ca_cert

接着用下面的命令生成CA中心的私鑰文件 ca_privkey.key(保存在ca_cert目錄下)

openssl genrsa -out ca_cert\ca_privkey.key 1024

DOS窗口截圖如下:

clip_image027

然後用下面的命令生成CA中心的自簽名數字證書文件ca.crt(保存在ca_cert目錄下)

openssl req -new -x509 -days 4000 -key ca_cert\ca_privkey.key -out ca_cert\ca.crt -config ..\conf\openssl.cnf

該命令會要求輸入以下身份信息,表示CA中心的身份:

Country Name (2 letter code) [AU]:CN                                               --國家代碼,中國用CN
State or Province Name (full name) [Some-State]:BeiJing                     --國家或所在省份
Locality Name (eg, city) []:BeiJing                                                      --城市名稱
Organization Name (eg, company) [Internet Widgits Pty Ltd]:orifound   --組織名稱
Organizational Unit Name (eg, section) []:orifound_ca                          --組織單位名稱
Common Name (eg, YOUR name) []:orifound_ca                                 --你的名稱或網站域名
Email Address []:[email protected]                                            --郵件地址

DOS窗口截圖如下:

clip_image028

4.9.2 SVN服務器端向CA中心申請數字證書

要實現SSL驗證,服務器端必須具備數字證書,故SVN服務器端需要向CA中心申請一個數字證書。

申請數字證書需要提交一個採用私鑰簽名了的申請文件(.csr),下面就來爲SVN服務器端生成其私鑰和證書製作申請文件。

打開命令行提示符(DOS 窗口),進入 Apache的bin目錄(C:\Program Files\CollabNet\Subversion Server\httpd\bin),通過輸入下面的命令創建svn_server_cert子目錄,用於存放SVN服務器端的相關數字證書和密鑰等文件。

md svn_server_cert

接着用下面的命令生成svn服務器端的密鑰文件 svn_server_privkey.key(保存在svn_server_cert目錄下)

openssl genrsa -out svn_server_cert\svn_server_privkey.key 1024

然後用下面的命令生成svn服務器端準備提交給CA中心的數字證書製作申請文件 svn_server.csr(保存在svn_server_cert目錄下)

openssl req -new -out svn_server_cert\svn_server.csr -key svn_server_cert\svn_server_privkey.key -config ..\conf\openssl.cnf

該命令會要求輸入以下身份信息,表示SVN服務器端的身份:

Country Name (2 letter code) [AU]:CN                               --國家代碼,中國用CN(建議與CA根證書一致)
State or Province Name (full name) [Some-State]:BeiJing            --國家或所在省份(建議與CA根證書一致)
Locality Name (eg, city) []:BeiJing                                                      --城市名稱
Organization Name (eg, company) [Internet Widgits Pty Ltd]:orifound   --組織名稱(建議與CA根證書一致)
Organizational Unit Name (eg, section) []:orifound_svn_server              --組織單位名稱
Common Name (eg, YOUR name) []:xp                                               --你的名稱或網站域名
Email Address []:[email protected]                                            --郵件地址

特別注意:

這裏的Common Name 在輸入時一定要仔細考慮,如果你的SVN服務器部署在局域網內,那麼該名稱一定要和客戶端訪問該SVN服務器的地址中的“https://xp:8080/svn/” xp完全一致,實際上就是你的SVN服務器主機名或IP地址,因爲SSL會檢查客戶端https請求的域名是否與服務器身份完全一致(通過檢查這個Common Name來判斷是否一致),否則無法正確訪問,提示SSL驗證失敗的錯誤信息。

如果這裏的Common Name 設置爲主機名xp,那麼日後就只能夠用“https://xp:8080/svn/”來訪問版本庫;

如果這裏的Common Name 設置爲主機IP地址192.168.0.22,那麼日後就只能夠用“https://192.168.0.22:8080/svn/”來訪問版本庫;

如果SVN服務器部署在外網上,並且域名是www.yourdomain.com,那麼這裏的Common Name 必須設置爲www.yourdomain.com

另外,這裏輸入的Country Name、State or Province Name和Organization Name都強烈建議與CA證書的完全一致,因爲我們後面基於缺省的openssl.cnf配置文件頒發證書時要求證書使用者的上述信息與CA證書的完全一致,否則報錯無法生成數字證書,除非修改openssl.cnf配置文件。

openssl.cnf配置文件的存放路徑爲:

C:\Program Files\CollabNet\Subversion Server\httpd\conf\openssl.cnf

其內容如下圖所示,圖中黃色標記部分就是在生成數字證書時對上述三項內容的匹配要求。

clip_image030

DOS窗口截圖如下:

clip_image031

4.9.3 CA中心爲SVN服務器端頒發數字證書

CA中心拿到SVN服務器端提交過來的證書製作申請文件(.csr)後,下面就可以爲SVN服務器端其生成數字證書了。

在生成數字證書時要用到openssl配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\openssl.cnf),該配置文件中配置了幾個目錄和文件,我們必須事先創建好,否則在生成數字證書的時候會出現一系列的錯誤,具體要創建的目錄和文件如下:

  • 在Apache的bin目錄(C:\Program Files\CollabNet\Subversion Server\httpd\bin)下,創建DemoCA子目錄,然後再DemoCA子目錄下再創建newcerts子目錄。
  • 在Apache的bin目錄(C:\Program Files\CollabNet\Subversion Server\httpd\bin)下,先創建一個空白內容的index.txt文件(0字節),然後再創建一個temp.txt文件,雙擊temp.txt文件打開後輸入01兩個字符保存關閉,最後將temp.txt文件重命名爲serial。

接下來就可以用下面的DOS命令生成由CA中心向svn服務器端頒發的數字證書 svn_server.crt(保存在svn_server_cert目錄下),CA中心必須用自己的私鑰和根證書對最終頒發的svn服務器端數字證書文件進行簽名處理。

打開命令行提示符(DOS 窗口),進入 Apache的bin目錄(C:\Program Files\CollabNet\Subversion Server\httpd\bin),輸入以下命令:

openssl ca -in svn_server_cert\svn_server.csr -out svn_server_cert\svn_server.crt -cert ca_cert\ca.crt -keyfile ca_cert\ca_privkey.key -config ..\conf\openssl.cnf -days 4000

注意:

該命令會詢問是否要簽名等兩個問題,都輸入y回車,證書才能夠正確生成,否則證書文件雖然生成了但卻是0字節,我當時摸索研究時沒有細看,把這個空文件直接配置到服務器端,結果在啓動服務時失敗,日誌記錄了證書文件內容爲空的錯誤信息。

DOS窗口截圖如下:

clip_image032

如果前面沒有按要求事先創建好openssl配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\openssl.cnf)所需的目錄和文件,在生成證書時會出現下面一系列的錯誤。

clip_image033

clip_image034

至此,我們已經制作了SSL(不鑑別客戶端身份)驗證過程所需的各種數字證書,下面需要來配置Apache以啓用SSL功能。

4.9.4 啓用ApacheSSL功能

可以通過修改前面配置完畢的Apache服務配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\httpd.conf)來啓用該功能,具體修改如下。

搜索到下面兩行配置內容,分別刪除首部的#(帶#表示註釋信息,去掉#表示生效的配置信息)

#LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-ssl.conf

如果希望關閉非SSL的普通http訪問請求,強制要求客戶端採用https的SSL方式來訪問版本庫,那麼可以對上述配置文件進一步做如下修改。

在配置文件底部的<Location>節 增加如下配置內容,指示客戶端必須採用SSL方式來訪問版本庫。

SSLRequireSSL

此時,整個Apache服務配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\httpd.conf)底部的內容如下:

#<Location /svn>的意思是Subversion版本庫的URL是http://servername/svn
<Location /svn>
   #告訴Apache是哪個模塊響應那個URL的請求-此刻是Subversion模塊。
   DAV svn
   #對於 Subversion 1.3 或者更高版本,這個指示會列出所有 SVNParentPath 中的版本庫。
   SVNListParentPath on
   #告訴Subversion需要查看的版本庫位於e:\svn_repository之下
   SVNParentPath e:\svn_repository
   #強制要求SSL認證,不響應非SSL方式的http請求
   SSLRequireSSL
   #激活基本認證,就是用戶名/密碼
   AuthType Basic
   #指定當客戶端在訪問版本庫時彈出要求用戶輸入認證信息的認證對話框上顯示的信息
   AuthName "Subversion repositories login:"
   #指定使用的認證密碼文件,passwd是用戶密碼驗證文件,要求放置在httpd子目錄下
   AuthUserFile passwd
   #指定精確的控制版本庫目錄訪問的授權文件路徑,
   #svnaccessfile是目錄授權文件(可對訪問用戶進行版本庫中任意目錄的授權),要求放置在httpd目錄下
   #如果不需要進行細粒度的目錄授權控制,則可以把下面這行配置內容用#註釋掉
   AuthzSVNAccessFile svnaccessfile
   #指定只有輸入了正確的用戶/密碼的用戶可以訪問URL
   Require valid-user
</Location>

至此,我們已經啓用了Apache的SSL功能模塊,但尚無法正確使用SSL,因爲還需要進一步對SSL功能模塊進行配置。

4.9.5 配置SSL功能模塊

SSL功能模塊的配置文件路徑爲:

C:\Program Files\CollabNet\Subversion Server\httpd\conf\extra\httpd-ssl.conf

用UltraEdit或記事本之類的編輯器打開這個配置文件,做如下修改。

該配置文件中有很多文件路徑,需要把這些路徑中的相對父目錄都配置爲我們的Apache服務的安裝路徑(D:\Program Files\CollabNet\Subversion Server\httpd),需要修改的地方是下面圖中的黃色標記部分,比較快捷的做法如下。

使用文本編輯器的搜索替換功能,直接將配置文件中的

E:/1.6.9/subversion/../httpd/tmp/httpd/Apache

全部替換爲:

C:/Program Files/CollabNet/Subversion Server/httpd

注意:並注意路徑分隔符要用/

clip_image036

clip_image038

clip_image040

clip_image042

clip_image044

將上圖中的路徑修全部改完畢後,接着需要配置SVN服務器端的數字證書和私鑰文件路徑。

在當前SSL配置文件中搜索 “SSLCertificateFile” 和 “SSLCertificateKeyFile” 配置項,如下圖所示:

clip_image046

SSLCertificateFile配置項用來指定SVN服務器端的數字證書文件路徑。在SSL驗證過程中,SVN服務器會將該數字證書傳輸給客戶端,客戶端通過讀取證書中的身份信息和證書頒發機構來完成對SVN服務器的身份鑑別。

SSLCertificateKeyFile配置項用來指定SVN服務器端的私鑰文件路徑。在SSL驗證過程中,客戶端會生成一個隨機的明文密碼串,然後從SVN服務器端數字證書中獲取服務器端的公鑰信息,並用該公鑰加密這個密文密碼串後發給SVN服務器,SVN服務器則會採用該配置項指定的私鑰來解密接收到的密碼串,得到真正的明文密碼串,此後客戶端和服務器端都採用該明文密碼串進行數據加密傳輸,從而保證SSL會話通道內數據傳輸的安全性。

我們在前面的數字證書製作部分已經將SVN服務器端的數字證書和密鑰文件都生成好了,並且存放路徑如下。

SVN服務器數字證書文件路徑:

C:\Program Files\CollabNet\Subversion Server\httpd\bin\svn_server_cert\svn_server.crt

SVN服務器私鑰文件路徑:

C:\Program Files\CollabNet\Subversion Server\httpd\bin\svn_server_cert\svn_server_privkey.key

如下圖所示:

clip_image047

根據上述數字證書和私鑰文件路徑,將SSLCertificateFile配置項修改爲(注意路徑分隔符用/):

SSLCertificateFile "C:/Program Files/CollabNet/Subversion Server/httpd/bin/svn_server_cert/svn_server.crt"

將SSLCertificateKeyFile配置項修改爲(注意路徑分隔符用/):

SSLCertificateKeyFile "C:/Program Files/CollabNet/Subversion Server/httpd/bin/svn_server_cert/svn_server_privkey.key"

上面這個配置可以理解爲安裝SVN服務器端數字證書和私鑰,數字證書和私鑰文件其實可以放在服務器端任意位置,然後在這裏配置其正確的存放路徑即可。

從這個配置文件中我們可以看到下面這句配置內容:

<VirtualHost _default_:443>

它表示SVN服務器主機的SSL處理功能(https://)將偵聽443端口,這也是SSL訪問方式(https://)的缺省端口號,就像http的缺省端口號是80一樣。如果SVN服務器是帶有Windows防火牆的操作系統(例如XP等等),那麼這裏爲了能夠讓客戶端能夠正確訪問到SSL功能,SVN服務器端必須在防火牆中開啓443端口的正常訪問(如果有其他防火牆軟件同樣也需要開啓該端口)。

對於Windows防火牆,可在運行框或DOS窗口中執行如下命令行腳本來開啓TCP 443端口的正常訪問:

netsh firewall set portopening protocol = TCP port = 443 name = ApacheSSLPort mode = ENABLE scope = SUBNET profile = CURRENT

SSL功能模塊的配置文件內容實例:

上述配置完成後,SSL功能模塊的配置文件(C:\Program Files\CollabNet\Subversion Server\httpd\conf\extra\httpd-ssl.conf)的完整內容實例如下:

#

# This is the Apache server configuration file providing SSL support.

# It contains the configuration directives to instruct the server how to

# serve pages over an https connection. For detailing information about these

# directives see <URL:http://httpd.apache.org/docs/2.2/mod/mod_ssl.html>

#

# Do NOT simply read the instructions in here without understanding

# what they do.  They're here only as hints or reminders.  If you are unsure

# consult the online docs. You have been warned. 

#

#

# 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 file:/dev/random  512

#SSLRandomSeed startup file:/dev/urandom 512

#SSLRandomSeed connect file:/dev/random  512

#SSLRandomSeed connect file:/dev/urandom 512

#

# When we also provide SSL we have to listen to the

# standard HTTP port (see above) and to the HTTPS port

#

# Note: Configurations that use IPv6 but not IPv4-mapped addresses need two

#       Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"

#

Listen 443

##

##  SSL Global Context

##

##  All SSL configuration in this context applies both to

##  the main server and all SSL-enabled virtual hosts.

##

#

#   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 the mechanism

#   to use and second the expiring timeout (in seconds).

#SSLSessionCache         "dbm:C:/Program Files/CollabNet/Subversion Server/httpd/logs/ssl_scache"

SSLSessionCache        "shmcb:C:/Program Files/CollabNet/Subversion Server/httpd/logs/ssl_scache(512000)"

SSLSessionCacheTimeout  300

#   Semaphore:

#   Configure the path to the mutual exclusion semaphore the

#   SSL engine uses internally for inter-process synchronization.

SSLMutex default

##

## SSL Virtual Host Context

##

<VirtualHost _default_:443>

#   General setup for the virtual host

DocumentRoot "C:/Program Files/CollabNet/Subversion Server/httpd/htdocs"

ServerName www.example.com:443

ServerAdmin [email protected]

ErrorLog "C:/Program Files/CollabNet/Subversion Server/httpd/logs/error.log"

TransferLog "C:/Program Files/CollabNet/Subversion Server/httpd/logs/access.log"

#   SSL Engine Switch:

#   Enable/Disable SSL for this virtual host.

SSLEngine on

#   SSL Cipher Suite:

#   List the ciphers that the client is permitted to negotiate.

#   See the mod_ssl documentation for a complete list.

SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

#   Server Certificate:

#   Point SSLCertificateFile at a PEM encoded certificate.  If

#   the certificate is encrypted, then you will be prompted for a

#   pass phrase.  Note that a kill -HUP will prompt again.  Keep

#   in mind that if you have both an RSA and a DSA certificate you

#   can configure both in parallel (to also allow the use of DSA

#   ciphers, etc.)

SSLCertificateFile "C:/Program Files/CollabNet/Subversion Server/httpd/bin/svn_server_cert/svn_server.crt"

#SSLCertificateFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/server-dsa.crt"

#   Server Private Key:

#   If the key is not combined with the certificate, use this

#   directive to point at the key file.  Keep in mind that if

#   you've both a RSA and a DSA private key you can configure

#   both in parallel (to also allow the use of DSA ciphers, etc.)

SSLCertificateKeyFile "C:/Program Files/CollabNet/Subversion Server/httpd/bin/svn_server_cert/svn_server_privkey.key"

#SSLCertificateKeyFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/server-dsa.key"

#   Server Certificate Chain:

#   Point SSLCertificateChainFile at a file containing the

#   concatenation of PEM encoded CA certificates which form the

#   certificate chain for the server certificate. Alternatively

#   the referenced file can be the same as SSLCertificateFile

#   when the CA certificates are directly appended to the server

#   certificate for convinience.

#SSLCertificateChainFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/server-ca.crt"

#   Certificate Authority (CA):

#   Set the CA certificate verification path where to find CA

#   certificates for client authentication or alternatively one

#   huge file containing all of them (file must be PEM encoded)

#   Note: Inside SSLCACertificatePath you need hash symlinks

#         to point to the certificate files. Use the provided

#         Makefile to update the hash symlinks after changes.

#SSLCACertificatePath "C:/Program Files/CollabNet/Subversion Server/httpd/conf/ssl.crt"

#SSLCACertificateFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/ssl.crt/ca-bundle.crt"

#   Certificate Revocation Lists (CRL):

#   Set the CA revocation path where to find CA CRLs for client

#   authentication or alternatively one huge file containing all

#   of them (file must be PEM encoded)

#   Note: Inside SSLCARevocationPath you need hash symlinks

#         to point to the certificate files. Use the provided

#         Makefile to update the hash symlinks after changes.

#SSLCARevocationPath "C:/Program Files/CollabNet/Subversion Server/httpd/conf/ssl.crl"

#SSLCARevocationFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/ssl.crl/ca-bundle.crl"

#   Client Authentication (Type):

#   Client certificate verification type and depth.  Types are

#   none, optional, require and optional_no_ca.  Depth is a

#   number which specifies how deeply to verify the certificate

#   issuer chain before deciding the certificate is not valid.

#SSLVerifyClient require

#SSLVerifyDepth  10

#   Access Control:

#   With SSLRequire you can do per-directory access control based

#   on arbitrary complex boolean expressions containing server

#   variable checks and other lookup directives.  The syntax is a

#   mixture between C and Perl.  See the mod_ssl documentation

#   for more details.

#<Location />

#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \

#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \

#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \

#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \

#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \

#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/

#</Location>

#   SSL Engine Options:

#   Set various options for the SSL engine.

#   o FakeBasicAuth:

#     Translate the client X.509 into a Basic Authorisation.  This means that

#     the standard Auth/DBMAuth methods can be used for access control.  The

#     user name is the `one line' version of the client's X.509 certificate.

#     Note that no password is obtained from the user. Every entry in the user

#     file needs this password: `xxj31ZMTZzkVA'.

#   o ExportCertData:

#     This exports two additional environment variables: SSL_CLIENT_CERT and

#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the

#     server (always existing) and the client (only existing when client

#     authentication is used). This can be used to import the certificates

#     into CGI scripts.

#   o StdEnvVars:

#     This exports the standard SSL/TLS related `SSL_*' environment variables.

#     Per default this exportation is switched off for performance reasons,

#     because the extraction step is an expensive operation and is usually

#     useless for serving static content. So one usually enables the

#     exportation for CGI and SSI requests only.

#   o StrictRequire:

#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even

#     under a "Satisfy any" situation, i.e. when it applies access is denied

#     and no other module can change it.

#   o OptRenegotiate:

#     This enables optimized SSL connection renegotiation handling when SSL

#     directives are used in per-directory context.

#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire

<FilesMatch "\.(cgi|shtml|phtml|php)$">

    SSLOptions +StdEnvVars

</FilesMatch>

<Directory "C:/Program Files/CollabNet/Subversion Server/httpd/cgi-bin">

    SSLOptions +StdEnvVars

</Directory>

#   SSL Protocol Adjustments:

#   The safe and default but still SSL/TLS standard compliant shutdown

#   approach is that mod_ssl sends the close notify alert but doesn't wait for

#   the close notify alert from client. When you need a different shutdown

#   approach you can use one of the following variables:

#   o ssl-unclean-shutdown:

#     This forces an unclean shutdown when the connection is closed, i.e. no

#     SSL close notify alert is send or allowed to received.  This violates

#     the SSL/TLS standard but is needed for some brain-dead browsers. Use

#     this when you receive I/O errors because of the standard approach where

#     mod_ssl sends the close notify alert.

#   o ssl-accurate-shutdown:

#     This forces an accurate shutdown when the connection is closed, i.e. a

#     SSL close notify alert is send and mod_ssl waits for the close notify

#     alert of the client. This is 100% SSL/TLS standard compliant, but in

#     practice often causes hanging connections with brain-dead browsers. Use

#     this only for browsers where you know that their SSL implementation

#     works correctly.

#   Notice: Most problems of broken clients are also related to the HTTP

#   keep-alive facility, so you usually additionally want to disable

#   keep-alive for those clients, too. Use variable "nokeepalive" for this.

#   Similarly, one has to force some clients to use HTTP/1.0 to workaround

#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and

#   "force-response-1.0" for this.

BrowserMatch ".*MSIE.*" \

         nokeepalive ssl-unclean-shutdown \

         downgrade-1.0 force-response-1.0

#   Per-Server Logging:

#   The home of a custom SSL log file. Use this when you want a

#   compact non-error SSL logfile on a virtual host basis.

CustomLog "C:/Program Files/CollabNet/Subversion Server/httpd/logs/ssl_request.log" \

          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>   

4.9.6 測試SSL功能

在Windows服務管理界面找到CollabNet Subversion Apache服務,並啓動/重新啓動它。

注意:下面的圖示都是直接在Apache服務端進行測試,如果在另一臺客戶端機器上做測試,需要將地址欄中的localhost替換爲該Apache服務器的計算機名稱或IP地址。

4.9.6.1 測試啓用了SSL的Apache服務

在IE瀏覽器中輸入如下地址:https://localhosthttps://localhost:443

https缺省就是採用443端口進行訪問。

注意:

客戶端採用https://訪問的時候就不要用端口8080了,我這裏配置的SVN服務器針對http的端口是8080,針對https的端口是443。SVN服務器首先在443端口上響應並處理SSL驗證流程,SSL驗證通過後Apache會將https://裏面封裝的http://請求繼續發送給8080端口進行處理。

測試結果如下圖所示,IE瀏覽器客戶端彈出一個安全警報提示框,表示SVN服務器端證書的頒發機構未在客戶端信任列表中。

clip_image048

點擊是繼續瀏覽我們可以看到更爲詳盡的證書情況說明,如下圖:

clip_image049

點擊是繼續瀏覽可以正確訪問到SVN服務器的Apache服務缺省頁面(http請求返回的結果):

clip_image050

4.9.6.2 測試啓用了SSL的版本庫訪問

如果想測試SVN版本庫的SSL訪問,以我們之前創建的測試版本庫TestRepository1爲例,可以在IE瀏覽器中輸入如下地址:

https://localhost/svn/TestRepository1

同樣的,客戶端會警示服務器端數字證書的頒發機構未在信任列表中等安全性警告,點擊是繼續瀏覽,此時會彈出SVN版本庫的身份認證信息,要求客戶端進行身份認證,這裏使用前面創建的版本庫用戶xm進行登錄。

clip_image051

版本庫用戶身份認證通過後,顯示出了TestRepository1版本庫中的目錄信息(我們之前創建的project1-3子目錄)。

由此說明,客戶端採用https:來訪問SVN服務測試通過!

clip_image052

對於版本庫的SSL訪問方式,還可以用SVN客戶端來進行測試。

4.9.6.3 採用TortoiseSVN客戶端測試基於SSL的版本庫訪問

這裏還是採用之前安裝的TortoiseSVN客戶端來完成該測試,你也可以使用別的SVN客戶端(例如直接在安裝了Subclipse插件的Eclipse IDE中進行測試)。

clip_image018[2]

選擇TortoiseSVN菜單“版本庫瀏覽器”,要求輸入版本庫地址。

clip_image053

輸入TestRepository1測試版本庫的訪問地址:https://localhost/svn/TestRepository1,確定後彈出一個SVN服務器端數字證書頒發人不在客戶端信任列表中的警告信息(與IE瀏覽器的警告大同小異),總的意思就是說客戶端沒法鑑別SVN服務器的身份,因爲在客戶端信任的證書頒發機構列表中沒有該SVN服務器端數字證書的頒發機構。

clip_image054

點擊接受繼續,SVN客戶端彈出版本庫用戶認證框。

clip_image055

使用前面創建的版本庫用戶xm登錄,用戶驗證通過後,可能繼續會彈出服務器端數字證書的警告信息,點擊接受繼續,即可顯示出TestRepository1版本庫下的子目錄信息。

clip_image056

至此,採用SVN客戶端測試基於SSL的版本庫訪問測試通過!

4.9.7 在客戶端安裝CA根證書

前面在測試SSL訪問功能時,不論是IE瀏覽器客戶端還是SVN客戶端程序都會報服務器端身份無法鑑別的警示信息(並詢問是否繼續訪問)。

出現這個警示信息的原因是SVN服務器端將其數字證書傳給客戶端後,客戶端可以從證書中獲取其頒發機構以及相應身份信息,客戶端會預安裝很多商業的證書頒發機構至信任列表中,而這個SVN服務器端證書是由我們自己虛擬的CA中心頒發的,當然不在客戶端證書頒發機構信任列表中。

既然是這個原因造成的,那麼只要把之前創建的CA中心的根證書安裝到客戶端的證書頒發機構信任列表中就可以解決該問題。

前面數字證書製作部分,已經將CA中心的根證書文件生成了,其存放地址爲:

C:\Program Files\CollabNet\Subversion Server\httpd\bin\ca_cert\ca.crt

如下圖:

clip_image057

爲了在客戶端安裝該證書,首先要將該CA根證書文件拷貝至客戶端機器的任意位置,我這裏是拷貝至客戶端機器的 C:\orifound_ca\ca.crt

客戶端主機上CA根證書文件的存放位置截圖:

clip_image058

4.9.7.1 在客戶端瀏覽器中安裝數字證書

把該CA根證書文件(ca.crt)拷貝至客戶端機器上後,用鼠標雙擊可以打開該證書文件。

clip_image059

點擊上圖的安裝證書,將打開證書導入嚮導。

clip_image060

點擊下一步,選擇證書導入後存放的位置。

注意:這裏一定要選擇“受信任的根證書頒發機構”。

clip_image061

clip_image062

點擊完成,此時會再次彈出一個頒發機構證書安裝確認提示框。

clip_image063

點擊是,CA根證書在客戶端安裝完畢!

可以通過IE瀏覽器的“Internet選項”來檢查證書的安裝情況。

clip_image064

點擊上圖中的“證書(C)...”按鈕,然後選擇受信任的根證書頒發機構,從下圖中可以看到我們自己虛擬的CA中心的根證書已經安裝到了客戶端的受信任的根證書頒發機構列表中。

clip_image065

也可以直接通過上圖的“導入(I)…”來進行數字證書的安裝。

對於SVN客戶端,我們同樣也需要安裝CA根證書,否則就像前面測試結果一樣總是彈出警告提示框。

4.9.7.2 在TortoiseSVN客戶端中安裝CA根證書

在Windows資源管理器(或桌面上)任意空白位置,點擊右鍵選擇TortoiseSVN菜單“設置(S)”。

clip_image066

打開TortoiseSVN客戶端的設置界面後,選擇網絡節點,然後點擊下圖中的“編輯”按鈕來對Subversion服務器進行設置。

clip_image067

此時將打開一個配置文件,如下圖所示,我們要對圖中的黃色標記部分進行修改。

clip_image068

該配置文件的存放位置爲:

C:\Documents and Settings\Administrator\Application Data\Subversion\servers

在該配置文件中搜索“ssl-authority-files”,該配置項用於指定客戶端信任的所有CA數字證書文件路徑,用;隔開。

前面已經把CA根證書文件拷貝至客戶端機器的 C:\orifound_ca\ca.crt

客戶端主機上CA根證書文件的存放位置截圖:

clip_image058[1]

根據該CA根證書文件的路徑,在該配置文件中對“ssl-authority-files”配置項做如下配置:

去掉首字符#,並把CA根證書文件路徑配置上去(注意:路徑分隔符爲/)。

ssl-authority-files = C:/orifound_ca/ca.crt

配置完成後的截圖如下(黃色標記部分爲修改內容):

clip_image069

4.9.8 再次測試SSL功能(在客戶端安裝了CA根證書後)
4.9.8.1 測試啓用了SSL的Apache服務

在IE瀏覽器中輸入如下地址:https://localhosthttps://localhost:443

https缺省就是採用443端口進行訪問。

測試結果如下圖所示,IE瀏覽器客戶端仍然彈出一個安全警報提示框,但於未安裝CA根證書之前的提示信息不一樣了。

clip_image070

從警告信息框可以看出,客戶端從SVN服務器端數字證書中識別的頒發機構,已經是可信的(因爲我們已經把其頒發機構--CA的根證書導入到了客戶端的受信任根證書頒發結構列表中),只是SVN服務器端數字證書中登記的名稱(Common Name )與現在請求的主機名稱不匹配。

查看Apache服務器端的錯誤日誌內容如下:

[Sun Oct 10 16:36:35 2010] [warn] RSA server certificate CommonName (CN) `xp' does NOT match server name!?

從錯誤日誌中可以看出,SVN服務器端數字證書中登記的名稱(Common Name )是xp,而我們通過https://localhost請求的主機名是localhost,顯然不匹配,既然SSL驗證過程中要求請求的主機與服務器端數字證書中登記的名稱要一致,那麼我們當初在製作SVN服務器端數字證書的時候就一定要仔細覈對登記的Common Name ,將來就用該Common Name 作爲https://訪問地址中的主機名。

點擊是繼續瀏覽我們可以看到更爲詳盡的證書情況說明,如下圖:

clip_image049[1]

點擊否,然後將瀏覽器中的地址修改爲https://xp 後回車,此時不再出現前面的警示框,而是直接顯示Apache服務的缺省頁面,說明SSL測試通過!

clip_image071

4.9.8.2 測試啓用了SSL的版本庫訪問

如果想測試SVN版本庫的SSL訪問,以我們之前創建的測試版本庫TestRepository1爲例,可以在IE瀏覽器中輸入如下地址:

https://xp/svn/TestRepository1,此時也不再彈出警示框,而是要求客戶端進行版本庫身份認證,這裏使用前面創建的版本庫用戶xm登錄。

版本庫用戶身份認證通過後,顯示出了TestRepository1版本庫中的目錄信息(我們之前創建的project1-3子目錄)。

由此說明,客戶端採用https:來訪問SVN服務測試通過!

clip_image072

對於版本庫的SSL訪問方式,還可以用SVN客戶端來進行測試。

4.9.8.3 採用TortoiseSVN客戶端測試基於SSL的版本庫訪問

這裏還是採用之前安裝的TortoiseSVN客戶端來完成該測試,你也可以使用別的SVN客戶端(例如直接在安裝了Subclipse插件的Eclipse IDE中進行測試)。

clip_image018[3]

選擇TortoiseSVN菜單“版本庫瀏覽器”,要求輸入版本庫地址。

clip_image073

輸入TestRepository1測試版本庫的訪問地址:https://xp/svn/TestRepository1,確定。

此時沒有再彈出之前的服務器憑證檢核錯誤的警示框,而是直接要求進行版本庫身份認證。

點擊接受繼續,SVN客戶端彈出版本庫用戶認證框。

clip_image074

使用前面創建的版本庫用戶xm登錄,用戶驗證通過後,即可顯示出TestRepository1版本庫下的子目錄信息。

clip_image075

至此,採用SVN客戶端測試基於SSL的版本庫訪問測試通過!

到目前爲止,SVN客戶端已經可以使用基於SSL的訪問方式(https://)來訪問SVN版本庫數據了,該SSL並沒有要求鑑別客戶端身份,如果是在局域網中問題不大,但是如果是將該SVN服務器配置中外網上訪問,以支持不同城市甚至國家的團隊協同開發,顯然不合適,存在驗證的安全問題,因爲一旦有團隊成員的身份驗證信息(用戶口令)泄漏了,就等同於它能夠訪問的源代碼資源泄漏了。

爲了解決這個問題,我們可以將SSL功能配置爲要求鑑別客戶端身份,實現SSL的雙向身份鑑別,即客戶端會鑑別服務器端身份,同時服務器端也會鑑別客戶端身份,只有客戶端身份鑑別通過後,SVN服務器端才響應客戶端的請求。

4.10 第十步:爲Apache服務配置SSL功能(要求進行客戶端身份鑑別)

前面已經講解了SSL不要進行客戶端身份鑑別的驗證流程,現在爲了能夠在外網實現SVN的安全訪問,要求SSL驗證流程中必須進行客戶端身份鑑別。其驗證流程相比前面增加了一個驗證環節,具體的SSL會話驗證過程如下圖所示:

clip_image077

下面就針對這種要求鑑別客戶端身份的SSL應用環境,根據上圖中的應用流程闡述其配置過程,包括各種數字證書的製作過程。

現在SSL驗證要求鑑別客戶端身份,那麼客戶端必須具備一個數字證書,在前面製作了CA根證書和SVN服務器端證書的基礎上,還必須爲每個客戶端頒發一個數字證書(與SVN服務器端證書一樣,客戶端證書也是由CA中心來製作頒發)。

每個客戶端都需要提交一個證書製作申請給CA中心,然後由CA中心根據申請內容來製作其數字證書。

對於CA而言,SVN服務器端和客戶端都是同級的,他們的證書製作流程完全相同。

這裏的客戶端從某種程度上可以映射爲研發團隊中的研發人員,現在需要給每個團隊成員製作一個專有的客戶端數字證書。

下面以客戶端用戶xm爲例,詳細講解爲團隊成員xm製作他專有的客戶端數字證書的步驟。

4.10.1 客戶端向CA中心申請數字證書

客戶端需要向CA中心申請一個數字證書,申請數字證書必須提交一個採用私鑰簽名了的申請文件(.csr),下面就來爲客戶端生成其私鑰和證書製作申請文件。

打開命令行提示符(DOS 窗口),進入 Apache的bin目錄(C:\Program Files\CollabNet\Subversion Server\httpd\bin),通過輸入下面的命令創建svn_client_cert子目錄,用於存放客戶端的相關數字證書和密鑰等文件。

md svn_client_cert

接着用下面的命令生成客戶端的密鑰文件 svn_client_privkey_xm.key(保存在svn_client_cert目錄下)

openssl genrsa -out svn_client_cert\svn_client_privkey_xm.key 1024

用下面的命令生成客戶端準備提交給CA中心的數字證書製作申請文件 svn_client_xm.csr(保存在svn_client_cert目錄下)

openssl req -new -out svn_client_cert\svn_client_xm.csr -key svn_client_cert\svn_client_privkey_xm.key -config ..\conf\openssl.cnf

該命令會要求輸入以下身份信息,表示客戶端的身份:

Country Name (2 letter code) [AU]:CN                              --國家代碼,中國用CN(建議與CA根證書一致)
State or Province Name (full name) [Some-State]:BeiJing            --國家或所在省份(建議與CA根證書一致)
Locality Name (eg, city) []:BeiJing                                                      --城市名稱
Organization Name (eg, company) [Internet Widgits Pty Ltd]:orifound   --組織名稱(建議與CA根證書一致)
Organizational Unit Name (eg, section) []:orifound_svn_client              --組織單位名稱
Common Name (eg, YOUR name) []:xm                                             --你的名稱或網站域名
Email Address []:[email protected]                                            --郵件地址

強烈建議:塗銀波

這裏輸入的Country Name、State or Province Name和Organization Name都強烈建議與CA證書的完全一致,因爲我們後面基於缺省的openssl.cnf配置文件頒發證書時要求證書使用者的上述信息與CA證書的完全一致,否則報錯無法生成數字證書,除非修改openssl.cnf配置文件。

openssl.cnf配置文件的存放路徑爲:

C:\Program Files\CollabNet\Subversion Server\httpd\conf\openssl.cnf

其內容如下圖所示,圖中黃色標記部分就是在生成數字證書時對上述三項內容的匹配要求。

clip_image078

DOS窗口截圖如下:

clip_image079

4.10.2 CA中心爲客戶端頒發數字證書

CA中心收到客戶端提交過來的證書製作申請文件(.csr)後,下面就可以爲客戶端生成數字證書了。

在生成數字證書時要用到openssl配置文件(D:\Program Files\CollabNet\Subversion Server\httpd\conf\openssl.cnf),該配置文件中配置了幾個目錄和文件,必須事先創建好,否則在生成數字證書的時候會出現一系列的錯誤,我們已經在前面製作SVN服務器端數字證書的時候就已經創建好了,這裏跳過不講,如果在執行下面步驟中出現錯誤請參考前面製作SVN服務器端數字證書的說明來創建openssl.cnf配置文件中需要的幾個目錄和文件。

接下來就可以用下面的DOS命令生成由CA中心向客戶端頒發的數字證書 svn_client_xm.crt(保存在svn_client_cert目錄下),CA中心必須用自己的私鑰和根證書對最終頒發的客戶端數字證書文件進行簽名處理。

打開命令行提示符(DOS 窗口),進入 Apache的bin目錄(C:\Program Files\CollabNet\Subversion Server\httpd\bin),輸入以下命令:

openssl ca -in svn_client_cert\svn_client_xm.csr -out svn_client_cert\svn_client_xm.crt -cert ca_cert\ca.crt -keyfile ca_cert\ca_privkey.key -config ..\conf\openssl.cnf -days 4000

注意:該命令會詢問是否要簽名等兩個問題,都輸入y回車,證書才能夠正確生成,否則證書文件雖然生成了但卻是0字節。

DOS窗口截圖如下:

clip_image080

到現在爲止,客戶端數字證書尚未製作完成,因爲上面生成的數字證書格式無法安裝到客戶端個人數字證書列表中,而p12格式的數字證書可以正確安裝,故需要再生成一個p12格式的數字證書。

可以用下面的DOS命令從上面的客戶端數字證書svn_client_xm.crt 中導出一個p12格式的客戶端數字證書svn_client_xm.p12,內部已包含私鑰信息(保存在svn_client_cert目錄下):

openssl pkcs12 -export -clcerts -in svn_client_cert\svn_client_xm.crt -inkey svn_client_cert\svn_client_privkey_xm.key -out svn_client_cert\svn_client_xm.p12

該命令要求輸入將用於保護私鑰信息的口令,將來任何程序要讀取該證書中的私鑰,都必須輸入該口令,這裏我將口令設置爲123456,DOS窗口截圖如下:

clip_image081

至此,我們已經制作了用於SSL(鑑別客戶端身份)的客戶端數字證書,下面需要來配置Apache以啓用SSL的客戶端身份鑑別功能。

4.10.3 配置SSL啓用客戶端身份鑑別功能

SSL功能模塊的配置文件路徑爲:

C:\Program Files\CollabNet\Subversion Server\httpd\conf\extra\httpd-ssl.conf

用UltraEdit或記事本之類的編輯器打開這個配置文件,做如下修改。

搜索"<VirtualHost _default_:443>",如下圖黃色標記部分,將其修改爲:

<VirtualHost *:443>

clip_image083

經驗教訓:當初自己做配置時,因爲沒有修改這一項,結果客戶端SSL驗證總是失敗,有網文說修改爲主機域名,結果還是出錯,查閱好多文章後終於找到了上述解決方案。

搜索"SSLCACertificatePath"和"SSLCACertificateFile",如下圖黃色標記部分。

  • SSLCACertificatePath配置項指定CA中心的根證書文件的存放目錄;
  • SSLCACertificateFile配置項指定CA中心的根證書文件路徑;

clip_image084

在前面數字證書製作部分,已經將CA中心的根證書文件生成了,其存放地址爲:

C:\Program Files\CollabNet\Subversion Server\httpd\bin\ca_cert\ca.crt

如下圖:

clip_image057[1]

根據上述CA根證書文件地址,將"SSLCACertificatePath"和"SSLCACertificateFile"兩項配置內容做如下修改。

去掉首字符#,並將路徑設置爲上述地址(注意路徑分隔符爲/),修改結果如下:

SSLCACertificatePath "C:/Program Files/CollabNet/Subversion Server/httpd/bin/ca_cert"
SSLCACertificateFile "C:/Program Files/CollabNet/Subversion Server/httpd/bin/ca_cert/ca.crt"

搜索"SSLVerifyClient"和"SSLVerifyDepth",如下圖黃色標記部分,該配置項表示要求進行客戶端身份鑑別,以及鑑別的深度(身份信息匹配之類的深度),將兩行內容做如下修改:

去掉首字符#

clip_image085

修改完成後內容如下:

SSLVerifyClient require
SSLVerifyDepth  10

搜索"SSLRequire",如下圖黃色標記部分,該配置項指定在訪問相關目錄時客戶端身份鑑別通過的條件。

clip_image086

去掉這段配置項的首字符#,並設置通過條件,修改完成後內容如下:

<Location />
SSLRequire  ( %{SSL_CLIENT_S_DN_O} eq "orifound" \
            and %{SSL_CLIENT_S_DN_OU} eq "orifound_svn_client"  )
</Location>

上述配置表示客戶端在訪問任意版本庫目錄時都必須通過客戶端身份鑑別,鑑別通過的條件是其證書身份信息中Organization Name 爲"orifound" ,並且Organizational Unit Name 爲"orifound_svn_client" 。

在配置上述驗證通過的條件時,如果分多行配置,那麼每行的末尾要以 \ 結束,最後一行末尾不要有 \,也可以將上述多個條件配置在一行,把括號去掉也可以,如下:

<Location />
SSLRequire  ( %{SSL_CLIENT_S_DN_O} eq "orifound" and %{SSL_CLIENT_S_DN_OU} eq "orifound_svn_client"  )
</Location>

注意:這個條件有嚴格的語法格式要求,如果配置不合法,會導致Apache服務啓動失敗。

搜索"</Directory>",如下圖黃色標記部分,在其下方增加如下配置內容(注意:是追加配置內容,不是替換)。

<Directory "/">
    SSLRequire %{SSL_CLIENT_VERIFY} eq "SUCCESS"
</Directory>

追加上述配置內容的作用是要求客戶端在訪問任何服務器端目錄時都必須通過客戶端身份鑑別。

clip_image088

追加上述配置內容後的截圖如下:

clip_image089

至此,SSL啓用客戶端身份鑑別功能配置完畢。

SSL功能模塊的配置文件內容實例

SSL功能模塊的配置文件路徑爲:

C:\Program Files\CollabNet\Subversion Server\httpd\conf\extra\httpd-ssl.conf

上述所有配置完成後,其完整內容如下:

#
# This is the Apache server configuration file providing SSL support.
# It contains the configuration directives to instruct the server how to
# serve pages over an https connection. For detailing information about these
# directives see <URL:http://httpd.apache.org/docs/2.2/mod/mod_ssl.html>
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned. 
#

#
# 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 file:/dev/random  512
#SSLRandomSeed startup file:/dev/urandom 512
#SSLRandomSeed connect file:/dev/random  512
#SSLRandomSeed connect file:/dev/urandom 512

#
# When we also provide SSL we have to listen to the
# standard HTTP port (see above) and to the HTTPS port
#
# Note: Configurations that use IPv6 but not IPv4-mapped addresses need two
#       Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"
#
Listen 443

##
##  SSL Global Context
##
##  All SSL configuration in this context applies both to
##  the main server and all SSL-enabled virtual hosts.
##

#
#   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 the mechanism
#   to use and second the expiring timeout (in seconds).
#SSLSessionCache         "dbm:C:/Program Files/CollabNet/Subversion Server/httpd/logs/ssl_scache"
SSLSessionCache        "shmcb:C:/Program Files/CollabNet/Subversion Server/httpd/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300

#   Semaphore:
#   Configure the path to the mutual exclusion semaphore the
#   SSL engine uses internally for inter-process synchronization.
SSLMutex default

##
## SSL Virtual Host Context
##

<VirtualHost *:443>

#   General setup for the virtual host
DocumentRoot "C:/Program Files/CollabNet/Subversion Server/httpd/htdocs"
ServerName www.example.com:443
ServerAdmin [email protected]
ErrorLog "C:/Program Files/CollabNet/Subversion Server/httpd/logs/error.log"
TransferLog "C:/Program Files/CollabNet/Subversion Server/httpd/logs/access.log"

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

#   Server Certificate:
#   Point SSLCertificateFile at a PEM encoded certificate.  If
#   the certificate is encrypted, then you will be prompted for a
#   pass phrase.  Note that a kill -HUP will prompt again.  Keep
#   in mind that if you have both an RSA and a DSA certificate you
#   can configure both in parallel (to also allow the use of DSA
#   ciphers, etc.)
SSLCertificateFile "C:/Program Files/CollabNet/Subversion Server/httpd/bin/svn_server_cert/svn_server.crt"
#SSLCertificateFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/server-dsa.crt"

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile "C:/Program Files/CollabNet/Subversion Server/httpd/bin/svn_server_cert/svn_server_privkey.key"
#SSLCertificateKeyFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/server-dsa.key"

#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convinience.
#SSLCertificateChainFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/server-ca.crt"

#   Certificate Authority (CA):
#   Set the CA certificate verification path where to find CA
#   certificates for client authentication or alternatively one
#   huge file containing all of them (file must be PEM encoded)
#   Note: Inside SSLCACertificatePath you need hash symlinks
#         to point to the certificate files. Use the provided
#         Makefile to update the hash symlinks after changes.
SSLCACertificatePath "C:/Program Files/CollabNet/Subversion Server/httpd/bin/ca_cert"
SSLCACertificateFile "C:/Program Files/CollabNet/Subversion Server/httpd/bin/ca_cert/ca.crt"

#   Certificate Revocation Lists (CRL):
#   Set the CA revocation path where to find CA CRLs for client
#   authentication or alternatively one huge file containing all
#   of them (file must be PEM encoded)
#   Note: Inside SSLCARevocationPath you need hash symlinks
#         to point to the certificate files. Use the provided
#         Makefile to update the hash symlinks after changes.
#SSLCARevocationPath "C:/Program Files/CollabNet/Subversion Server/httpd/conf/ssl.crl"
#SSLCARevocationFile "C:/Program Files/CollabNet/Subversion Server/httpd/conf/ssl.crl/ca-bundle.crl"

#   Client Authentication (Type):
#   Client certificate verification type and depth.  Types are
#   none, optional, require and optional_no_ca.  Depth is a
#   number which specifies how deeply to verify the certificate
#   issuer chain before deciding the certificate is not valid.
SSLVerifyClient require
SSLVerifyDepth  10

#   Access Control:
#   With SSLRequire you can do per-directory access control based
#   on arbitrary complex boolean expressions containing server
#   variable checks and other lookup directives.  The syntax is a
#   mixture between C and Perl.  See the mod_ssl documentation
#   for more details.
#<Location />
#SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
#            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
#            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
#            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
#            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
#           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>
<Location />
SSLRequire  ( %{SSL_CLIENT_S_DN_O} eq "orifound" \
            and %{SSL_CLIENT_S_DN_OU} eq "orifound_svn_client"  )
</Location>

#   SSL Engine Options:
#   Set various options for the SSL engine.
#   o FakeBasicAuth:
#     Translate the client X.509 into a Basic Authorisation.  This means that
#     the standard Auth/DBMAuth methods can be used for access control.  The
#     user name is the `one line' version of the client's X.509 certificate.
#     Note that no password is obtained from the user. Every entry in the user
#     file needs this password: `xxj31ZMTZzkVA'.
#   o ExportCertData:
#     This exports two additional environment variables: SSL_CLIENT_CERT and
#     SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
#     server (always existing) and the client (only existing when client
#     authentication is used). This can be used to import the certificates
#     into CGI scripts.
#   o StdEnvVars:
#     This exports the standard SSL/TLS related `SSL_*' environment variables.
#     Per default this exportation is switched off for performance reasons,
#     because the extraction step is an expensive operation and is usually
#     useless for serving static content. So one usually enables the
#     exportation for CGI and SSI requests only.
#   o StrictRequire:
#     This denies access when "SSLRequireSSL" or "SSLRequire" applied even
#     under a "Satisfy any" situation, i.e. when it applies access is denied
#     and no other module can change it.
#   o OptRenegotiate:
#     This enables optimized SSL connection renegotiation handling when SSL
#     directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/Program Files/CollabNet/Subversion Server/httpd/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

#要求任何目錄訪問都必須進行客戶端身份鑑別
<Directory "/">
    SSLRequire %{SSL_CLIENT_VERIFY} eq "SUCCESS"
</Directory>

#   SSL Protocol Adjustments:
#   The safe and default but still SSL/TLS standard compliant shutdown
#   approach is that mod_ssl sends the close notify alert but doesn't wait for
#   the close notify alert from client. When you need a different shutdown
#   approach you can use one of the following variables:
#   o ssl-unclean-shutdown:
#     This forces an unclean shutdown when the connection is closed, i.e. no
#     SSL close notify alert is send or allowed to received.  This violates
#     the SSL/TLS standard but is needed for some brain-dead browsers. Use
#     this when you receive I/O errors because of the standard approach where
#     mod_ssl sends the close notify alert.
#   o ssl-accurate-shutdown:
#     This forces an accurate shutdown when the connection is closed, i.e. a
#     SSL close notify alert is send and mod_ssl waits for the close notify
#     alert of the client. This is 100% SSL/TLS standard compliant, but in
#     practice often causes hanging connections with brain-dead browsers. Use
#     this only for browsers where you know that their SSL implementation
#     works correctly.
#   Notice: Most problems of broken clients are also related to the HTTP
#   keep-alive facility, so you usually additionally want to disable
#   keep-alive for those clients, too. Use variable "nokeepalive" for this.
#   Similarly, one has to force some clients to use HTTP/1.0 to workaround
#   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
#   "force-response-1.0" for this.
BrowserMatch ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog "C:/Program Files/CollabNet/Subversion Server/httpd/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

4.10.4 在客戶端安裝個人專用的客戶端數字證書

前面數字證書製作部分,已經將個人專用的客戶端數字證書生成了,其存放地址爲:

C:\Program Files\CollabNet\Subversion Server\httpd\bin\svn_client_cert\svn_client_xm.p12

如下圖:

clip_image090

爲了在客戶端安裝該證書,首先要將該客戶端證書文件拷貝至客戶端機器的任意位置,我這裏是拷貝至客戶端機器的 C:\orifound_ca\svn_client_xm.p12

客戶端主機上的個人專用的客戶端數字證書文件的存放位置截圖:

clip_image091

4.10.4.1 在客戶端瀏覽器中安裝個人客戶端數字證書

把該客戶端證書文件(svn_client_xm.p12)拷貝至客戶端機器上後,用鼠標雙擊可以打開證書導入嚮導。

clip_image060[1]

點擊下一步,選擇要導入的證書文件。

clip_image092

點擊下一步,要求輸入該客戶端數字證書中的密鑰保護口令。

前面在導出該p12格式的個人客戶端數字證書時設置的密鑰保護口令爲123456,這裏當然也輸入123456。

clip_image093

點擊下一步,選擇證書導入後存放的位置,讓嚮導自動選擇即可。

clip_image094

點擊下一步,完成個人客戶端數字證書的安裝。

clip_image095

可以通過IE瀏覽器的“Internet選項”來檢查證書的安裝情況。

clip_image064[1]

點擊上圖中的“證書(C)...”按鈕,然後選擇“個人”標籤頁,從下圖中可以看到xm的個人客戶端證書已經安裝到了客戶端的個人證書列表中。

clip_image096

也可以直接通過上圖的“導入(I)…”來進行個人客戶端數字證書的安裝。

對於SVN客戶端,我們同樣也需要安裝個人客戶端數字證書,否則SSL驗證會失敗。

4.10.4.2 在TortoiseSVN客戶端中安裝個人數字證書

在Windows資源管理器(或桌面上)任意空白位置,點擊右鍵選擇TortoiseSVN菜單“設置(S)”。

clip_image066[1]

打開TortoiseSVN客戶端的設置界面後,選擇網絡節點,然後點擊下圖中的“編輯”按鈕來對Subversion服務器進行設置。

clip_image067[1]

此時將自動打開一個配置文件,在XP下該配置文件的存放位置爲:

C:\Documents and Settings\Administrator\Application Data\Subversion\servers

如果是在Win7下,該配置文件的存放位置爲路徑爲:

C:\Users\EAGLE\AppData\Roaming\Subversion\servers

在該配置文件中搜索“ssl-authority-files”,在其下方追加如下配置內容(注意是追加配置內容,而不是替換)。

ssl-client-cert-file = C:\orifound_ca\svn_client_xm.p12
ssl-client-cert-password = 123456

上述配置項的作用是指定SVN客戶端進行SSL驗證時,要提供的個人客戶端數字證書以及在訪問證書中的密鑰信息時要提供的口令。

爲了在客戶端安裝該證書,前面已經將該客戶端證書文件拷貝至客戶端機器的 C:\orifound_ca\svn_client_xm.p12

客戶端主機上的個人專用的客戶端數字證書文件的存放位置截圖:

clip_image091[1]

根據該客戶機的個人客戶端數字證書文件的路徑以及導出該個人證書時設置的密鑰保護口令,對上述配置項“ssl-client-cert-file”和“ssl-client-cert-password”進行正確配置。

配置完成後的截圖如下(黃色標記部分爲修改內容):

clip_image097

到此爲止,已經完成了要求進行客戶端身份鑑別的SSL配置,下面進行測試,在測試之前,需要重啓Apache服務。

4.10.5 測試要求進行客戶端身份鑑別的SSL功能(在客戶端安裝了CA根證書以及個人客戶端證書後)
4.10.5.1 測試啓用了SSL的Apache服務

在IE瀏覽器中輸入如下地址:https://xphttps://xp:443,https缺省就是採用443端口進行訪問。

測試結果如下圖所示,IE瀏覽器客戶端彈出一個客戶端證書選擇框,在列表中自動列出了最合適的客戶端證書信息,這裏列出了前面導入的用戶xm的個人客戶端證書。

clip_image098

選擇用戶xm的個人客戶端數字證書,確定後顯示出Apache服務缺省頁面

clip_image071[1]

由此證明,要求鑑別客戶端身份的SSL功能測試通過!

4.10.5.2 測試啓用了SSL的版本庫訪問

如果想測試SVN版本庫的SSL訪問,以我們之前創建的測試版本庫TestRepository1爲例,可以在IE瀏覽器中輸入如下地址:

https://xp/svn/TestRepository1,同樣也是要求提供客戶端數字證書,選擇客戶端證書確定後,客戶端要求進行版本庫身份認證,這裏使用前面創建的版本庫用戶xm登錄。

clip_image099

版本庫用戶身份認證通過後,顯示出了TestRepository1版本庫中的目錄信息(我們之前創建的project1-3子目錄)。

由此說明,客戶端採用https:來訪問SVN服務測試通過(SSL進行了客戶端身份的鑑別)!

clip_image072[1]

對於版本庫的SSL訪問方式,還可以用SVN客戶端來進行測試。

4.10.5.3 採用TortoiseSVN客戶端測試基於SSL的版本庫訪問

這裏還是採用之前安裝的TortoiseSVN客戶端來完成該測試,你也可以使用別的SVN客戶端(例如直接在安裝了Subclipse插件的Eclipse IDE中進行測試)。

clip_image018[4]

選擇TortoiseSVN菜單“版本庫瀏覽器”,要求輸入版本庫地址。

clip_image073[1]

輸入TestRepository1測試版本庫的訪問地址:https://xp/svn/TestRepository1,確定後要求進行版本庫身份認證。

點擊接受繼續,SVN客戶端彈出版本庫用戶認證框。

clip_image074[1]

使用前面創建的版本庫用戶xm登錄,用戶驗證通過後,即可顯示出TestRepository1版本庫下的子目錄信息。

clip_image075[1]

至此,採用SVN客戶端測試基於SSL的版本庫訪問測試通過(SSL完成了客戶端身份的鑑別)!

第 5 章 SVN客戶端驗證相關配置文件路徑

NetBeans6.9.1中集成了Subversion客戶端,它的配置文件存放目錄:

C:\Users\EAGLE\.netbeans\6.9\config\svn\config

Eclipse或MyEclipse安裝了Subclipse插件後,其配置文件存放目錄:

C:\Users\EAGLE\AppData\Roaming\Subversion

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章