国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
在linux下使用openssl生成證書
userphoto

2011.09.17

關注
  • linux下使用openssl生成證書

[Linux]

post by 后山一根蔥 / 2010-6-12 16:36 Saturday

內容:使用openssl自己生成證書

環(huán)境:ubuntu 9.10

來源:后山一根蔥

 

這兩天在配置一個SSL環(huán)境,也發(fā)了些時間。下面是我自己在配置中的一個流水過程,有需要朋友可以參考,如有不對的地方還望指出。

安裝openssl

sudo apt-get install openssl

按照 OpenSSL 的默認配置建立 一個目錄ssleg. mkdir /home/jecks/ssl ,需要在ssl下建立相應的目錄結構。相關的配置內容一般位于/etc/ssl/openssl.cnf  內。在終端中使用如下命令建立目錄結構:

$ mkdir -p ./demoCA/{private,newcerts}
$ touch ./demoCA/index.txt
$ touch ./demoCA/serial

注:在文件serial中寫入01,index.txt為空文件。

進入/hone/jecks/ssl/下面,執(zhí)行命令

[root@qiujicai.com~/ssl]# pwd

/home/jecks/ssl

[root@qiujicai.com~/ssl]# ls

demoCA

 

1.首先要生成服務器端的私鑰(key文件):

[root@qiujicai.com~/ssl]#openssl genrsa -des3 -out server.key 1024

運行時會提示輸入密碼,此密碼用于加密key文件(參數(shù)des3便是指加密算法,當然也可以選用其他你認為安全的算法.),以后每當需讀取此文件(通過openssl提供的命令或API)都需輸入口令.如果覺得不方便,也可以去除這個口令,但一定要采取其他的保護措施!

去除key文件口令的命令:

[root@qiujicai.com~/ssl]#openssl rsa -in server.key -out server.key



2.
server.key生成一個證書:

[root@qiujicai.com~/ssl]#openssl req -new -key server.key -out server.csr

Enter pass phrase for server.key:12345

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [AU]:CN

State or Province Name (full name) [Some-State]:china

Locality Name (eg, city) []:Zhuhai

Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxxx Ltd....

Organizational Unit Name (eg, section) []:jecks

Common Name (eg, YOUR name) []:www.qiuicai.com

Email Address []:xxx@qiujicai.com

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:12345

An optional company name []:xxx@qiujicai.com 

生成Certificate Signing RequestCSR,生成的csr文件交給CA簽名后形成服務端自己的證書.屏幕上將有提示,依照其指示一步一步輸入要求的個人信息即可.



3.
對客戶端也作同樣的命令生成keycsr文件(在這兩步寫在一起):

    A
[root@qiujicai.com~/ssl]#openssl genrsa -des3 -out client.key 1024
 

Generating RSA private key, 1024 bit long modulus

...........++++++

..++++++

e is 65537 (0x10001)

Enter pass phrase for client.key:12345

Verifying - Enter pass phrase for client.key:12345



    B
[root@qiujicai.com~/ssl]# openssl req -new -key client.key -out client.csr

Enter pass phrase for client.key:12345

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [AU]:CN

State or Province Name (full name) [Some-State]:china

Locality Name (eg, city) []:Zhuhai
Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxxx Ltd....

Organizational Unit Name (eg, section) []:jecks

Common Name (eg, YOUR name) []:www.qiuicai.com

Email Address []:xxx@qiujicai.com

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:12345

An optional company name []:xxx@qiujicai.com

 

4.
生成的CSR證書文件必須有CA的簽名才可形成證書.這時生成一個KEY文件ca.key 和根證書ca.crt

[root@qiujicai.com~/ssl]# openssl req -new -x509 -keyout ca.key -out ca.crt

Generating a 1024 bit RSA private key

...++++++

...................++++++

writing new private key to 'ca.key'

Enter PEM pass phrase:12345

Verifying - Enter PEM pass phrase:

-----

Country Name (2 letter code) [AU]:CN

State or Province Name (full name) [Some-State]:china

Locality Name (eg, city) []:Zhuhai
Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxxx Ltd....

Organizational Unit Name (eg, section) []:jecks

Common Name (eg, YOUR name) []:www.qiuicai.com

Email Address []:xxx@qiujicai.com

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:12345

An optional company name []:xxx@qiujicai.com


5.
用生成的CA的證書為剛才生成的server.csr,client.csr文件簽名(這也是兩寫在一起):

   A
[root@qiujicai.com~/ssl]# openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key 


Using configuration from openssl.cnf

Enter pass phrase for ca.key:

Check that the request matches the signature

Signature ok

Certificate Details:

        Serial Number: 1 (0x1)

        Validity

            Not Before: Feb 26 04:15:02 2010 GMT

            Not After : Feb 26 04:15:02 2011 GMT

        Subject:

            countryName               = CN

            stateOrProvinceName       = china

            organizationName          = xxx.Ltd.C

            organizationalUnitName    = jecks

            commonName                = www.qiujicai.com

        X509v3 extensions:

            X509v3 Basic Constraints:

            CA:FALSE

            Netscape Comment:

            OpenSSL Generated Certificate

            X509v3 Subject Key Identifier:

            30:70:D2:EB:9B:73:AE:7B:0E:8E:F6:94:33:7C:53:5B:EF:93:FC:38

            X509v3 Authority Key Identifier:

            keyid:DB:D6:83:BB:7F:28:C2:A9:40:6A:D8:32:FC:01:E0:5C:48:27:51:19

 

Certificate is to be certified until Feb 26 04:15:02 2010 GMT (365 days)

Sign the certificate? [y/n]:y

 

 

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

 

   B
   [root@qiujicai.com~/ssl]#openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key

 

[root@airwaySSL bin]# openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key -config openssl.cnf

Using configuration from openssl.cnf

Enter pass phrase for ca.key:

Check that the request matches the signature

Signature ok

The countryName field needed to be the same in the

CA certificate (CN) and the request (cn)

..................

另外,這個certificateBASE64形式的,要轉成PKCS12才能裝到IE,/NETSCAPE.所以還要

[root@qiujicai.com~/ssl]# openssl pkcs12 -export -in client.pem -inkey client.key -out  client.pfx

Enter pass phrase for client.key:

Enter Export Password: # 設置client.pfx密碼

Verifying - Enter Export Password:


現(xiàn)在我們所需的全部文件便生成了.

另:

client
使用的文件有:ca.crt,client.crt,client.key,client.pfx

server
使用的文件有:ca.crt,server.crt,server.key

6.最后

編輯/etc/apache2/sites-enabled/000-default

NameVirtualHost *:443

 

 
<VirtualHost *:443>

 

 
        ServerSignature 

 

 
        OnSSLEngine On 

 

 
        SSLCertificateFile /usr/local/apache/conf/ssl.crt/server.crt  #指定服務器證書位置

 

 
        SSLCertificateKeyFile /usr/local/apache/conf/ssl.crt/server.key #指定服務器證書key位置

 

 
        SSLCACertificatePath /usr/local/apache/conf/ssl.crt #證書目錄

 

 
        SSLCACertificateFile /usr/local/apache/conf/ssl.crt/ca.csr #根證書位置

 

 
        #開啟客戶端SSL請求

 

 
        SSLVerifyClient require

 

 
        SSLVerifyDepth  1

 

 
        ServerAdmin webmaster@localhost

 
        ServerName www.qiujicai.com

 
        DocumentRoot /var/www/test

 
        ErrorDocument 404 http://www.qiujicai.com/err.php

 
        <Directory />

 
                Options FollowSymLinks

 
                AllowOverride None

 
        </Directory>

 
        <Directory /var/www/test/>

 
                Options Indexes FollowSymLinks MultiViews

 
                AllowOverride None

 
                Order allow,deny

 
                allow from all

 
        </Directory>

 

</VirtualHOst>

 

證書安裝及使用

把剛才生成的證書:根證書ca.crt和客戶證書client.crt(client.pfx)安裝到客戶端, ca.crt安裝到信任的機構,client.crt直接在windows安裝或安裝到個人證書位置,然后用IP訪問HTTPhttps服務器。在IE中我們一般導入client.pfx證書,導入時會提示上面設置的密碼。

 

 

 

 

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
linux 下生成ssl自簽證書并配置nginx通過https訪問(好使)
Ubuntu使用OpenSSL生成數(shù)字證書詳解
nginx配置SSL實現(xiàn)服務器/客戶端雙向認證
netty案例,netty4.1中級拓展篇十三《Netty基于SSL實現(xiàn)信息傳輸過程中雙向加密驗證》
使用OpenSSL生成CSR文件,并申請全球通用SSL證書
如何用openssl命令行生成證書
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服