隨筆-10  評論-36  文章-6  trackbacks-0

          Apache服務器SSL配置

          筆者不久前參與了某系統代理服務器配置的研究,查閱了大量關于Apache的SSL配置的資料。本文即是筆者學習這些資料后的經驗總結,以Win32版Apache與OpenSSL為例,介紹從創建數字證書到Apache配置的整個過程,希望對讀者有所幫助。

          Apache是目前最流行的WEB服務器之一,借助OpenSSL庫,我們可以在Apache上建立SSL通道,提供SSL連接服務。OpenSSL庫除提供Apache的SSL模塊外,還提供了一套數字證書工具,可以創建、轉換數字證書。

          1       環境準備

          軟件下載

          l       Apache:apache_2.2.4-win32-x86-openssl-0.9.8d.msi

          l       openSSL:Win32 OpenSSL v0.9.8e

          apache_2.2.4-win32-x86-openssl-0.9.8d.msi是一個捆綁的軟件包,包含了apache與openssl必選組件,apache的版本是2.2.4,OpenSSL版本是0.9.8d。如不必使用最新的openssl,則僅下載此軟件包即可。

          軟件安裝

          (1)   運行Win32OpenSSL-0_9_8e.exe安裝OpenSSL;

          (2)   運行apache_2.2.4-win32-x86-openssl-0.9.8d.msi安裝apache。

          如果想使用最新版的OpenSSL,則應刪除apache安裝目錄下的libeay32.dll與ssleay32.dll兩個文件,迫使Apache使用OpenSSL安裝在c:"windows"system32下的兩個最新文件。

          軟件配置

          1.3.1            Apache配置

          編輯apache的conf目錄下的httpd.conf文件,將#LoadModule ssl_module modules/mod_ssl.so前的#刪除,使得Apache啟動時加載mod_ssl.so模塊。重新啟動apache,如果看到下列畫面,說明mod_ssl.so已經加載成功。

          1.3.2            OpenSSL配置

          (1)創建證書管理目錄與文件;

          l       創建C:"CA作為證書管理主目錄;

          l       C:"CA下創建certs與keys兩個目錄,存儲證書與私鑰;

          l       C:"CA下創建crl目錄,存儲證書注銷列表文件;

          l       C:"CA下創建一個空文件index.txt,存儲證書清單;

          l       C:"CA下創建一個index.txt.attr文件,內容為unique_subject = no

          l       C:"CA下創建證書序列號文件serial,內容為01;

          l       C:"CA下創建證書注銷列表序號文件crlnumber,內容為01。

          (2)編輯OpenSSL的bin/openssl.cnf文件,修改下列內容:

          #

          # OpenSSL example configuration file.

          # This is mostly being used for generation of certificate requests.

          #

          # This definition stops the following lines choking if HOME isn't

          # defined.

          HOME          = .

          RANDFILE      = $ENV::HOME/.rnd

          # Extra OBJECT IDENTIFIER info:

          #oid_file     = $ENV::HOME/.oid

          oid_section        = new_oids

          # To use this configuration file with the "-extfile" option of the

          # "openssl x509" utility, name here the section containing the

          # X.509v3 extensions to use:

          # extensions       =

          # (Alternatively, use a configuration file that has only

          # X.509v3 extensions in its main [= default] section.)

          [ new_oids ]

          # We can add new OIDs in here for use by 'ca' and 'req'.

          # Add a simple OID like this:

          # testoid1=1.2.3.4

          # Or use config file substitution like this:

          # testoid2=${testoid1}.5.6

          ####################################################################

          [ ca ]

          default_ca    = CA_default       # The default ca section

          ####################################################################

          [ CA_default ]

          dir      = C:/CA       # Where everything is kept

          certs         = $dir/certs       # Where the issued certs are kept

          crl_dir       = $dir/crl         # Where the issued crl are kept

          database= $dir/index.txt   # database index file.

          #unique_subject    = no          # Set to 'no' to allow creation of

                                 # several ctificates with same subject.

          new_certs_dir= $dir/certs       # default place for new certs.

          certificate   = $dir/certs/CA.YOUR.COM.crt     # The CA certificate

          serial        = $dir/serial          # The current serial number

          crlnumber= $dir/crlnumber   # the current crl number

                                 # must be commented out to leave a V1 CRL

          crl      = $dir/crl.pem         # The current CRL

          private_key   = $dir/keys/CA.YOUR.COM.key    # The private key

          RANDFILE= $dir/keys/.rand       # private random number file

          x509_extensions    = usr_cert         # The extentions to add to the cert

          # Comment out the following two lines for the "traditional"

          # (and highly broken) format.

          name_opt = ca_default       # Subject Name options

          cert_opt = ca_default       # Certificate field options

          # Extension copying option: use with caution.

          # copy_extensions = copy

          # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs

          # so this is commented out by default to leave a V1 CRL.

          # crlnumber must also be commented out to leave a V1 CRL.

          # crl_extensions   = crl_ext

          default_days = 365              # how long to certify for

          default_crl_days= 30             # how long before next CRL

          default_md    = sha1             # which md to use.

          preserve= no          # keep passed DN ordering

          # A few difference way of specifying how similar the request should look

          # For type CA, the listed attributes must be the same, and the optional

          # and supplied fields are just that :-)

          policy        = policy_match

          # For the CA policy

          [ policy_match ]

          countryName        = match

          stateOrProvinceName    = match

          organizationName   = match

          organizationalUnitName= optional

          commonName         = supplied

          emailAddress       = optional

          # For the 'anything' policy

          # At this point in time, you must list all acceptable 'object'

          # types.

          [ policy_anything ]

          countryName        = optional

          stateOrProvinceName    = optional

          localityName       = optional

          organizationName   = optional

          organizationalUnitName= optional

          commonName         = supplied

          emailAddress       = optional

          ####################################################################

          [ req ]

          default_bits       = 1024

          default_keyfile    = privkey.pem

          distinguished_name= req_distinguished_name

          attributes         = req_attributes

          x509_extensions    = v3_ca # The extentions to add to the self signed cert

          # Passwords for private keys if not present they will be prompted for

          # input_password = secret

          # output_password = secret

          # This sets a mask for permitted string types. There are several options.

          # default: PrintableString, T61String, BMPString.

          # pkix   : PrintableString, BMPString.

          # utf8only: only UTF8Strings.

          # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).

          # MASK:XXXX a literal mask value.

          # WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings

          # so use this option with caution!

          string_mask = nombstr

          # req_extensions = v3_req # The extensions to add to a certificate request

          [ req_distinguished_name ]

          countryName            = Country Name (2 letter code)

          countryName_default         = CN

          countryName_min             = 2

          countryName_max             = 2

          stateOrProvinceName         = State or Province Name (full name)

          stateOrProvinceName_default= BeiJing

          localityName           = Locality Name (eg, city)

          0.organizationName     = Organization Name (eg, company)

          0.organizationName_default = COM

          # we can do this but it is not needed normally :-)

          #1.organizationName         = Second Organization Name (eg, company)

          #1.organizationName_default= World Wide Web Pty Ltd

          organizationalUnitName      = Organizational Unit Name (eg, section)

          organizationalUnitName_default   = YOUR

          commonName             = Common Name (eg, YOUR name)

          commonName_max              = 64

          emailAddress           = Email Address

          emailAddress_max       = 64

          # SET-ex3          = SET extension number 3

          [ req_attributes ]

          challengePassword      = A challenge password

          challengePassword_min       = 4

          challengePassword_max       = 20

          unstructuredName       = An optional company name

          [ usr_cert ]

          # These extensions are added when 'ca' signs a request.

          # This goes against PKIX guidelines but some CAs do it and some software

          # requires this to avoid interpreting an end user certificate as a CA.

          basicConstraints=CA:FALSE

          # Here are some examples of the usage of nsCertType. If it is omitted

          # the certificate can be used for anything *except* object signing.

          # This is OK for an SSL server.

          # nsCertType           = server

          # For an object signing certificate this would be used.

          # nsCertType = objsign

          # For normal client use this is typical

          # nsCertType = client, email

          # and for everything including object signing:

          # nsCertType = client, email, objsign

          # This is typical in keyUsage for a client certificate.

          # keyUsage = nonRepudiation, digitalSignature, keyEncipherment

          # This will be displayed in Netscape's comment listbox.

          nsComment          = "OpenSSL Generated Certificate"

          # PKIX recommendations harmless if included in all certificates.

          subjectKeyIdentifier=hash

          authorityKeyIdentifier=keyid,issuer

          # This stuff is for subjectAltName and issuerAltname.

          # Import the email address.

          # subjectAltName=email:copy

          # An alternative to produce certificates that aren't

          # deprecated according to PKIX.

          # subjectAltName=email:move

          # Copy subject details

          # issuerAltName=issuer:copy

          #nsCaRevocationUrl     = http://www.domain.dom/ca-crl.pem

          #nsBaseUrl

          #nsRevocationUrl

          #nsRenewalUrl

          #nsCaPolicyUrl

          #nsSslServerName

          [ v3_req ]

          # Extensions to add to a certificate request

          basicConstraints = CA:FALSE

          keyUsage = nonRepudiation, digitalSignature, keyEncipherment

          [ v3_ca ]

          # Extensions for a typical CA

          # PKIX recommendation.

          subjectKeyIdentifier=hash

          authorityKeyIdentifier=keyid:always,issuer:always

          # This is what PKIX recommends but some broken software chokes on critical

          # extensions.

          #basicConstraints = critical,CA:true

          # So we do this instead.

          basicConstraints = CA:true

          # Key usage: this is typical for a CA certificate. However since it will

          # prevent it being used as an test self-signed certificate it is best

          # left out by default.

          # keyUsage = cRLSign, keyCertSign

          # Some might want this also

          # nsCertType = sslCA, emailCA

          # Include email address in subject alt name: another PKIX recommendation

          # subjectAltName=email:copy

          # Copy issuer details

          # issuerAltName=issuer:copy

          # DER hex encoding of an extension: beware experts only!

          # obj=DER:02:03

          # Where 'obj' is a standard or added object

          # You can even override a supported extension:

          # basicConstraints= critical, DER:30:03:01:01:FF

          [ crl_ext ]

          # CRL extensions.

          # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.

          # issuerAltName=issuer:copy

          authorityKeyIdentifier=keyid:always,issuer:always

          [ proxy_cert_ext ]

          # These extensions should be added when creating a proxy certificate

          # This goes against PKIX guidelines but some CAs do it and some software

          # requires this to avoid interpreting an end user certificate as a CA.

          basicConstraints=CA:FALSE

          # Here are some examples of the usage of nsCertType. If it is omitted

          # the certificate can be used for anything *except* object signing.

          # This is OK for an SSL server.

          # nsCertType           = server

          # For an object signing certificate this would be used.

          # nsCertType = objsign

          # For normal client use this is typical

          # nsCertType = client, email

          # and for everything including object signing:

          # nsCertType = client, email, objsign

          # This is typical in keyUsage for a client certificate.

          # keyUsage = nonRepudiation, digitalSignature, keyEncipherment

          # This will be displayed in Netscape's comment listbox.

          nsComment          = "OpenSSL Generated Certificate"

          # PKIX recommendations harmless if included in all certificates.

          subjectKeyIdentifier=hash

          authorityKeyIdentifier=keyid,issuer:always

          # This stuff is for subjectAltName and issuerAltname.

          # Import the email address.

          # subjectAltName=email:copy

          # An alternative to produce certificates that aren't

          # deprecated according to PKIX.

          # subjectAltName=email:move

          # Copy subject details

          # issuerAltName=issuer:copy

          #nsCaRevocationUrl     = http://www.domain.dom/ca-crl.pem

          #nsBaseUrl

          #nsRevocationUrl

          #nsRenewalUrl

          #nsCaPolicyUrl

          #nsSslServerName

          # This really needs to be in place for it to be a proxy certificate.

          proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo

          (3)創建隨機數種子rand文件:

          cd c:"openssl"bin

          openssl rand -out c:/ca/keys/.rand 1024

          2       創建數字證書

          創建根證書(CA.COM

          (1)創建根證書的私鑰與證書申請;

          openssl genrsa -des3 -out c:/ca/keys/CA.COM.key 2048

          ** 創建時需要指定根私鑰保護密碼,請牢記此密碼。

          openssl req -new -out CA.COM.csr -key c:/ca/keys/CA.COM.key -config openssl.cnf

          ** 創建時需要指定下列內容,其他內容使用默認值。

          Country Name : CN

          State or Province Name: BeiJing

          Organization Name:COM

          Organizational Unit Name:COM

          Common Name:CA.COM

          或:

          openssl req -newkey rsa:2048 -keyout c:/ca/Keys/CA.COM.key -out CA.COM.csr -config openssl.cnf

          ** 創建時需要指定下列內容,其他內容使用默認值。

          Country Name : CN

          State or Province Name: BeiJing

          Organization Name:COM

          Organizational Unit Name:COM

          Common Name:CA.COM

          (2)使用根私鑰對根證書自簽名;

          openssl ca -in CA.COM.csr -out c:/ca/certs/CA.COM.crt -selfsign -keyfile c:/ca/keys/CA.COM.key -days 7305 -extensions v3_ca -config openssl.cnf

          ** 確認證書主題是:

                      countryName               = CN

                      stateOrProvinceName       = BeiJing

                      organizationName          = COM

                      organizationalUnitName    = COM

                      commonName                = CA.COM

          或:

          openssl x509 -in CA.COM.csr -out c:/ca/certs/CA.COM.crt -req -signkey c:/ca/keys/CA.COM.key -days 7305 -extensions v3_ca -config openssl.cnf

          ** 確認證書主題是:

                      countryName               = CN

                      stateOrProvinceName       = BeiJing

                      organizationName          = COM

                      organizationalUnitName    = COM

                      commonName                = CA.COM

          (3)刪除根證書申請文件CA.COM.csr。

          創建二級根證書(CA.YOUR.COM

          創建完根證書后,我們可以使用根證書創建二級根證書。

          (1)創建二級根證書的證書申請;

          openssl req -newkey rsa:2048 -keyout c:/ca/keys/CA.YOUR.COM.key -out CA.YOUR.COM.csr -config openssl.cnf

          ** 創建時需要指定二級證書私鑰的保護密碼,請牢記此密碼;

          ** 創建時需要指定下列內容,其他內容使用默認值。

          Country Name : CN

          State or Province Name: BeiJing

          Organization Name:COM

          Organizational Unit Name:YOUR

          Common Name:CA.YOUR.COM

          (2)使用根證書對二級根證書進行簽名;

          openssl ca -in CA.YOUR.COM.csr -out c:/ca/certs/CA.YOUR.COM.crt -keyfile c:/ca/keys/CA.COM.key -cert c:/ca/certs/CA.COM.crt -days 7305 -extensions v3_ca -config openssl.cnf

          ** 輸入根私鑰的保護密碼;

          ** 確認證書主題是:

                     countryName               = CN

                      stateOrProvinceName       = BeiJing

                      organizationName          = COM

                      organizationalUnitName    = YOUR

                      commonName                = CA.YOUR.COM

          (3)刪除二級根證書申請文件CA.YOUR.COM.csr。

          至此我們創建完二級根證書,后續的服務器證書與個人證書,我們都使用二級根證書做簽名。當然,我們也可以使用根證書簽名,但為模擬更現實的情況,我們使用二級根證書做主要的簽名證書。

          創建服務器證書

          (1)創建服務器證書的證書申請;

          openssl req -newkey rsa:1024 -keyout c:/ca/keys/www.your.com.key -out www.your.com.csr -config openssl.cnf

          ** 創建時需要指定服務器證書私鑰的保護密碼,請牢記此密碼;

          ** 創建時需要指定下列內容,其他內容使用默認值。

          Country Name : CN

          State or Province Name: BeiJing

          Organization Name:COM

          Organizational Unit Name:YOUR

          Common Name:www.your.com

          (2)使用二級根證書對服務器證書簽名;

          openssl ca -in www.your.com.csr -out c:/ca/certs/www.your.com.crt -config openssl.cnf

          ** 輸入二級證書的私鑰保護密碼;

          ** 確認證書主題是:

           countryName               = CN

           stateOrProvinceName       = BeiJing

           organizationName          = COM

           organizationalUnitName    = YOUR

           commonName                = www.your.com

          注意:本步驟中我們使用了配置文件openssl.cnf中指定的簽名證書ca.your.com.crt與簽名證書私鑰ca.your.com.key以及有效期365,因而命令比2.2節命令要簡潔許多。

          (3)刪除服務器證書申請文件www.your.com.csr。

          創建個人證書

          (1)創建個人證書的證書申請;

          openssl req -newkey rsa:1024 -keyout my.key -out my.csr -config openssl.cnf

          ** 創建時需要指定個人證書私鑰的保護密碼,請牢記此密碼;

          ** 創建時需要指定下列內容,其他內容使用默認值。

          Country Name : CN

          State or Province Name: BeiJing

          Organization Name:COM

          Organizational Unit Name:YOUR

          Common Name:my@your.com

          (2)使用二級根證書對個人證書簽名;

          openssl ca -in my.csr -out my.crt -config openssl.cnf

          ** 輸入二級證書的私鑰保護密碼;

          ** 確認證書主題是:

           countryName               = CN

           stateOrProvinceName       = BeiJing

           organizationName          = COM

           organizationalUnitName    = YOUR

           commonName                = my@your.com

          (3)添加證書鏈到個人證書。編輯my.crt文件,將CA.YOUR.COM.crt和CA.COM.crt文件從BEGIN CERTIFICATE開始的內容按序復制到my.crt文件中;

          (4)合并編輯后的my.crt與my.key為個人證書文件my.pfx;

          openssl pkcs12 -export -in my.crt -inkey my.key -out c:/ca/certs/my.pfx

          ** 輸入my的證書私鑰保護密碼;

          ** 重新指定個人證書的保護密碼,請牢記此密碼;

          (5)刪除個人證書申請文件my.csr、私鑰文件my.key、證書文件my.crt。

          注意:第3、4兩步可以使用下列命令一步完成:

          openssl pkcs12 -export -in my.crt -inkey my.key -out c:/ca/certs/my.pfx -certfile c:/ca/certs/ca.your.com.crt -certfile c:/ca/certs/ca.com.crt

          再按以上步驟,創建另外一張個人證書my1.pfx,Common Name為my1。后面我們將注銷這張證書,演示證書注銷列表的使用。

          創建證書鏈文件

          Web服務器與客戶端建立SSL通信通道前,要交換雙方的證書,并使用本方的證書鏈文件(P7B-PKCS7)與證書注銷列表文件(CRL)驗證對方證書的合法性。

          證書鏈文件,實際上就是多個CA的證書(公鑰),有兩種格式:一是文本格式(Privacy Enhanced Mail,PEM),即使用BASE64轉碼后的格式;二是二進制格式(Distinguished Encoding Rules,DER),即P7B文件。其中,PEM格式僅需將各CA的證書從枝到根的順序合并在一起即可。而P7B格式的證書鏈文件,則需要特殊處理。

          使用OpenSSL創建P7B格式的證書鏈文件的命令如下:

          openssl crl2pkcs7 -out c:/ca/your.p7b -nocrl -certfile c:/ca/certs/CA.YOUR.COM.crt -certfile c:/ca/certs/CA.COM.crt

          創建證書注銷列表文件

          (1)注銷證書my1.pfx;

          編輯c:/ca/index.txt文件,查閱/C=CN /ST=BeiJing /O=COM /OU=YOUR /CN=lny對應的證書序號為05。創建證書時,openssl自動將新創建的證書存儲在certs目錄下,文件名為<證書序號>.pem,因此05.pem即為my1.pfx對應的證書。使用下列命令可以顯示證書的主題信息進行確認:

          openssl x509 -in c:/ca/certs/05.pem -text

          ** 確認主題是:Subject: C=CN, ST=BeiJing, O=COM, OU=YOUR, CN=my1

          然后,使用下列命令注銷此證書:

          openssl ca -revoke c:/ca/certs/05.pem

          ** 輸入二級根證書的私鑰保護密碼。

          再次編輯c:/ca/index.txt,可以看到05號證書的狀態已經修改為R,即注銷了。

          (2)生成證書注銷列表文件;

          openssl ca -gencrl -crldays 7 -crlexts crl_ext -out c:/ca/crl/your.crl -config openssl.cnf

          ** 輸入二級證書的私鑰保護密碼;

          (3)轉換PEM格式證書列表文件為DER格式;

          本步驟是可選的。如果客戶端或服務器需要DER格式的證書注銷列表文件,則可以使用下列命令進行格式轉換:

          openssl crl -inform PEM -outform DER -in c:/ca/crl/your.crl -out c:/ca/crl/your_bin.crl

          注意:上述操作中,我們可以注銷多個證書后再生成證書注銷列表。生成證書注銷列表時,我們指定了下次發布證書注銷列表的日期為7日后(-crldays 7)。

          3       配置Apache

          準備好需要的各種證書及配套的文件后,我們可以配置Apache,啟用SSL連接服務。

          (1)編輯apache/conf/httpd.conf,刪除#Include conf/extra/ httpd-ssl.conf前的#,激活httpd-ssl.conf;

          (2)編輯apache/conf/extra/httpd-ssl.conf,將全部包含C:/Program Files/Apache Software Foundation/Apache2.2的項編輯為使用""括(蘭色字體部分),修改如下:

          #

          # 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/Apache Software Foundation/Apache2.2/logs/ssl_scache

          SSLSessionCache        "shmcb:C:/Program Files/Apache Software Foundation/Apache2.2/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/Apache Software Foundation/Apache2.2/htdocs"

          ServerName lny.your.com:443

          ServerAdmin nyli@your.cn

          ErrorLog "C:/Program Files/Apache Software Foundation/Apache2.2/logs/error_log"

          TransferLog "C:/Program Files/Apache Software Foundation/Apache2.2/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/Apache Software Foundation/Apache2.2/conf/server.crt"

          #SSLCertificateFile C:/Program Files/Apache Software Foundation/Apache2.2/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/Apache Software Foundation/Apache2.2/conf/server.key"

          #SSLCertificateKeyFile C:/Program Files/Apache Software Foundation/Apache2.2/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/Apache Software Foundation/Apache2.2/conf/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/Apache Software Foundation/Apache2.2/conf"

          SSLCACertificateFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/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/Apache Software Foundation/Apache2.2/conf"

          SSLCARevocationFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/ca.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/Apache Software Foundation/Apache2.2/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/Apache Software Foundation/Apache2.2/logs/ssl_request_log" "

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

          </VirtualHost>                                 

          (3)取消www.your.com.key的私鑰保護密碼;

          此操作僅Win32的Apache需要。

          Linux的Apache啟動時自動提示要求輸入服務器證書私鑰的保護密碼,而Win32的Apache沒有此功能,因此必須取消證書私鑰的保護密碼。

          openssl rsa -in c:/ca/keys/www.your.com.key -out c:/ca/keys/www.your.com1.key

          ** 輸入lny.your.com的私鑰保護密碼。

          (4)復制證書文件;

          移動c:/ca/keys/www.your.com1.key到conf/server.key;

          復制c:/ca/certs/www.your.com.crt到conf/server.crt;

          合并c:/ca/certs/CA.YOUR.COM.crt和c:/ca/certs/CA.COM. crt證書從BEGIN CERTIFICATE開始的內容到PEM格式的證書鏈文件中,復制該證書鏈文件到conf/ca.crt。如果有P7B格式的證書鏈文件,可以使用下列命名轉換成PEM格式的證書鏈文件。

          openssl pkcs7 -in c:/ca/your.p7b -out ca.crt -print_certs

          復制c:/ca/crl/your.crl到conf/ca.crl。

          4       測試

          (1)編輯客戶端hosts文件,增加服務器的域名;

          192.168.100.1   www.your.com

          (2)復制并安裝個人證書lny.pfx和lny1.pfx;

          (3)使用ie瀏覽器訪問服務器https://www.your.com,在彈出的證書選擇窗口中選擇my@your.cn證書,應能連接到服務器,輸出如下內容。


          (4)使用ie瀏覽器訪問服務器https://www.your.com,在彈出的證書選擇窗口中選擇my1證書,應彈出下列錯誤窗口。


          5       其他證書管理

          從個人證書中獲取私鑰

          openssl pkcs12 -in c:/ca/certs/my.pfx -out my.key –nocerts

          ** 輸入個人證書的保護密碼;

          ** 指定個人證書私鑰的保護密碼。

          從個人證書中獲取證書

          openssl pkcs12 -in c:/ca/certs/my.pfx -out my.crt -nokeys

          ** 輸入個人證書的保護密碼。

          posted on 2007-11-29 14:34 飛鷹 閱讀(16046) 評論(12)  編輯  收藏

          評論:
          # re: Apache服務器SSL配置 2008-01-03 10:54 | xiaosun
          你好.我按照你的帖子去配置的apache+ssl.成功了.十分感謝.不過最近出了個問題,希望您能再給予幫助.2008-1-1號以后我的應用都提示客戶端的證書過期,可期限明明還有接近1年,然后我又重新制作了幾個新的客戶證書,結果還是提示過期,您知道是什么原因嗎?  回復  更多評論
            
          # re: Apache服務器SSL配置 2008-01-03 14:28 | sham2k
          @xiaosun
          這種情況我沒有遇到過,按理應該不會這樣的。
          你使用window打開你的證書,確認下有效期。如果有效期沒有問題,你可以考慮更換下openssl庫。另外機器的日期也確認下。  回復  更多評論
            
          # re: Apache服務器SSL配置 2008-02-21 16:21 | com
          你好,我想問下如果要配多個ca的話,應該如何配置?  回復  更多評論
            
          # re: Apache服務器SSL配置 2008-02-21 17:06 | sham2k
          @com
          你可以試試將多個CA的證書文件添加到一個證書鏈文件中試試,具體操作在2.5 創建證書鏈文件,不過我沒有測試過。  回復  更多評論
            
          # re: Apache服務器SSL配置 2009-01-11 21:45 | yj98
          你好,,請教個問題..

          不知道我理解的對不對. ?

          如果你的證書沒到專門受信任的第三方證書頒發機構的確認. 那么在客戶使用瀏覽器打開時就會始終提示"尚未驗證網站身份"..

          而像支付寶這樣的網站已經購買申請了受信任的證書頒發機構的認證, 所以客戶打開其站點從而不會提示"尚未驗證"

          至于我們這樣的個人站點,如果你不花錢申請認證, 那做不做上面的:"自簽名證書,自己給自己簽的server、client證書,自簽名,自己作CA" 都無所謂. ???

          理解的對否?  回復  更多評論
            
          # re: Apache服務器SSL配置 2009-06-05 18:46 | zhengwenkan
          請問,我用的是apache2.2.11自帶openssl-0.9.8i的,按照上面所說的配置完成以后還是不行,請問,可能的問題出在哪里,證書什么的都可以正常生成,就是最后一步,網頁鏈接沒有反應,請指教,不勝感激
          qq:32651238
          msn:zwkatxiamen@hotmail.com
          email:zhengwenkan@sina.com  回復  更多評論
            
          # re: Apache服務器SSL配置 2009-06-23 17:06 | wangqs
          你好, 您的手順很詳細, 我們按照您的手順成功得完成了apache ssl的配置,

          我想請問一下, 在調查的過程中,您主要參考了哪些資料? :) 謝謝~~~  回復  更多評論
            
          # re: Apache服務器SSL配置 2009-06-23 17:19 | sham
          我不記得查閱過哪些資料了,都是邊學習邊實踐總結出來的。  回復  更多評論
            
          # re: Apache服務器SSL配置[未登錄] 2011-04-12 10:48 | 大鵬
          請問這種安裝會彈窗嗎? 提示可信任機構的問題?  回復  更多評論
            
          # re: Apache服務器SSL配置 2013-01-13 19:44 | 酷酷蟲
          博主我請教一個問題,我在windows下的apache 是no_ssl的,請問,我的設置該怎么處理。
          還有在mac系統,自帶的apache,怎么設置ssl  回復  更多評論
            
          # re: Apache服務器SSL配置 2013-07-29 10:48 | Heran
          能用。謝謝。  回復  更多評論
            
          # re: Apache服務器SSL配置 2013-10-02 17:03 | 閆麗霞
          我的電腦是2013,1月23日買的我是一個老太太現在我發現電腦里有,c;\documentsandsettings\administrator,,pkcs7,有黑帳號,有人控制我的電腦,我現在干什么他知道,我的電腦里有那么多國外的證書,這是怎么回事  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 梁山县| 丹江口市| 尼木县| 宁津县| 宁安市| 淮安市| 张家港市| 萝北县| 靖远县| 彭山县| 收藏| 怀安县| 夏津县| 绥宁县| 盈江县| 孝义市| 应用必备| 丰城市| 乌拉特前旗| 宁化县| 府谷县| 永靖县| 海门市| 潜山县| 鹿邑县| 安徽省| 大连市| 兖州市| 调兵山市| 五寨县| 白河县| 淮阳县| 区。| 滁州市| 体育| 石台县| 恩施市| 涞源县| 讷河市| 萝北县| 华容县|