热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Centos7环境下,如何使用Apache实现SSL虚拟主机双向认证的详细教程:

1.testing!11原文参考链接:http:showerlee.blog.51cto.com20470051266712很久没有更新LAMP的相关文档了&#

1.

testing ! ...

1

 

1 原文参考链接: http://showerlee.blog.51cto.com/2047005/1266712

很久没有更新LAMP的相关文档了,刚好最近单位做项目需要用到apache的SSL虚拟主机双向认证,刚好之前在做LAMP的时候顺带做过SSL模块加载,SO参考了google大量文档,用了半天时间搞定,这里总结出来给大家分享一下。

 

     该方案是为了实现apache下实现SSL虚拟主机双向认证,从而实现可信任用户才能访问具体虚拟站点,实现了数据加密以及双向可靠认证。

 

我的博客新站已经建好,更多新的内容即将在新站更新。。

欢迎访问     http://www.showerlee.com

 

LINUX操作系统:  centOS6.3 64bit(安装系统默认开发包)

APACHE:         httpd-2.4.4

SSL:            ssl.ca-0.1

 

解决方案:

 

一.关闭iptables和SELINUX

# service iptables stop

# setenforce 0

# vi /etc/sysconfig/selinux

---------------

SELINUX=disabled

---------------

 

二.编译安装apache

 

1.安装pcre依赖包

# wget http://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.gz/download

# tar -xzvf pcre-8.32.tar.gz

# cd pcre-8.32

# ./configure --prefix=/usr/local/pcre

# make && make install

 

2.apache配置:

1).下载apache与apr编译包

# wget http://archive.apache.org/dist/httpd/httpd-2.4.3-deps.tar.bz2

# wget http://archive.apache.org/dist/httpd/httpd-2.4.4.tar.bz2

 

2).将apache与apr编译包整合

注:httpd-2.4.3-deps.tar.bz2已集成APR,安装apache前检查pcre是否安装成功.

# tar jxvf httpd-2.4.4.tar.bz2

# tar jxvf httpd-2.4.3-deps.tar.bz2

# cp -rf httpd-2.4.3/* httpd-2.4.4

 

3).编译安装(加载mod_ssl模块)

# cd httpd-2.4.4

# ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite  -enable-ssl=static -with-ssl=/usr/local/ssl -enable-mods-shared=all --with-pcre=/usr/local/pcre/bin/pcre-config

# make && make install

注:编译过程中如果报错:

----------------------------------

checking for OpenSSL version >= 0.9.7… FAILED

configure: WARNING:  OpenSSL version is too old

no

checking whether to enable mod_ssl…  configure: error: mod_ssl has been requested but can not be built due to  prerequisite failures

-----------------------------------

解决办法

# yum install openssl-devel -y

# yum update openssl -y

 

三.SSL单向认证配置

 

1.加载ssl配置文件:

# vi /usr/local/apache2/conf/httpd.conf

搜索"Include conf/extra/httpd-ssl.conf", 并将这行前面的"#"去掉

 

2.配置ssl:

# vi /usr/local/apache2/conf/extra/httpd-ssl.conf

搜索"shmcb:/usr/local/apache2/logs/ssl_scache(512000)",并将这行加"#"注释掉

确认以下几行配置无误:

----------------------------

Listen 443

SSLEngine on

SSLCertificateFile "/usr/local/apache2/conf/server.crt"

SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"

SSLCACertificateFile "/usr/local/apache2/conf/ca.crt"

----------------------------

 

3.证书配置:

1).下载并解压ssl证书生成压缩包:

# cd /usr/local/apache2/conf

# wget http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz

# tar zxvf ssl.ca-0.1.tar.gz

# cd ssl.ca-0.1

 

2).利用ssl内脚本生成根证书:

# ./new-root-ca.sh  

---------------------------------------------------

No Root CA key round. Generating one

Generating RSA private key, 1024 bit  long modulus

………………………++++++

….++++++

e is 65537 (0×10001)

Enter  pass phrase for ca.key: (输入一个密码)

Verifying – Enter pass phrase for ca.key:  (再输入一次密码)

……

Self-sign the root CA… (签署根证书)

Enter pass phrase for  ca.key: (输入刚刚设置的密码)

……..

…….. (下面开始签署)

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

State or Province Name (full name) [Perak]:JiangSu

Locality Name  (eg, city) [Sitiawan]:NanJing

Organization Name (eg, company) [My Directory  Sdn Bhd]:example Co.,Ltd

Organizational Unit Name (eg, section)  [Certification Services Division]:example

Common Name (eg, MD Root CA)  []:example

Email Address []:info@example.com

--------------------------------------------------

这样就生成了ca.key和ca.crt两个文件

 

3).生成服务端证书:

# ./new-server-cert.sh server  

注:证书名为server

----------------------------------------------------

……

……

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

State or  Province Name (full name) [Perak]:JiangSu

Locality Name (eg, city)  [Sitiawan]:NanJing

Organization Name (eg, company) [My Directory Sdn  Bhd]:example Co.,Ltd

Organizational Unit Name (eg, section) [Secure Web  Server]:example

Common Name (eg, www.domain.com)  []:www.example.com

Email Address  []:info@example.com

-----------------------------------------------------

这样就生成了server.csr和server.key这两个文件。

 

4).签署服务端证书:

#  ./sign-server-cert.sh server

-------------------------------------------------

CA signing: server.csr ->  server.crt:

Using configuration from ca.config

Enter pass phrase for  ./ca.key: (输入上面设置的根证书密码)

Check that the request matches the  signature

Signature ok

The Subject’s Distinguished Name is as  follows

countryName   RINTABLE:’CN’

stateOrProvinceName   RINTABLE:’JiangSu’

localityName   RINTABLE:’NanJing’

organizationName   RINTABLE:’example Co.,Ltd’

organizationalUnitName:PRINTABLE:’example’

commonName   RINTABLE:’www.example.com’

emailAddress  :IA5STRING:’info@example.com’

Certificate is to be certified until Jul 16  12:55:34 2005 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

CA verifying: server.crt <-> CA  cert

server.crt: OK

-------------------------------------------

注:如果这里出现错误&#xff0c;最好重新来过&#xff0c;删除ssl.ca-0.1这个目录&#xff0c;从解压缩处重新开始。

下面要按照httpd-ssl.conf的设置&#xff0c;将证书放在适当的位置。

 

5).配置证书相关权限和路径:

# cd /usr/local/apache2/conf/ssl.ca-0.1

# chmod 644 server.key server.crt ca.crt

# mv server.key ..

# mv server.crt ..

# mv ca.crt ..

 

4.配置https实现SSL虚拟主机单向加密

1).加载虚拟主机配置文件&#xff1a;

# vi /usr/local/apache2/conf/httpd.conf

搜索"Include conf/extra/httpd-vhosts.conf", 并将这行前面的"#"去掉

 

2).让www.example.com虚拟主机实现https访问

# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

添加如下内容&#xff1a;

---------------------------

  DocumentRoot "/usr/local/apache2/htdocs/www.example.com/"

  ServerAlias www.example.com

  SSLEngine on

  SSLCertificateFile "/usr/local/apache2/conf/server.crt"

  SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"

  SSLCACertificateFile "/usr/local/apache2/conf/ca.crt"

----------------------------

# cd /usr/local/apache2/htdocs

# mkdir www.example.com

# cd www.example.com/

# echo "this is a test SSL web page" > index.html

 

3).启动服务:

# /usr/local/apache2/bin/apachectl start

 

4).查看SSL端口是否打开:

# lsof -i:443

---------------------------------

COMMAND    PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME

httpd   125366   root    6u  IPv6 6351523      0t0  TCP *:https (LISTEN)

httpd   125885 daemon    6u  IPv6 6351523      0t0  TCP *:https (LISTEN)

httpd   125886 daemon    6u  IPv6 6351523      0t0  TCP *:https (LISTEN)

httpd   125887 daemon    6u  IPv6 6351523      0t0  TCP *:https (LISTEN)

httpd   125946 daemon    6u  IPv6 6351523      0t0  TCP *:https (LISTEN)

---------------------------------

 

5).浏览器输入 https://www.example.com

注:需配置本机HOST文件

如图:

 

 

 

四.SSL双向认证配置:

 

1.为客户端生成一个证书:

# /usr/local/apache2/conf/ssl.ca-0.1

# ./new-user-cert.sh client1

-----------------------------------------

No client1.key round. Generating one

Generating RSA private key, 1024 bit long modulus

...........&#43;&#43;&#43;&#43;&#43;&#43;

...&#43;&#43;&#43;&#43;&#43;&#43;

e is 65537 (0x10001)

 

Fill in certificate data

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 &#39;.&#39;, the field will be left blank.

-----

Common Name (eg, John Doe) []:client1

Email Address []:info&#64;example.com

 

You may now run ./sign-user-cert.sh to get it signed

-------------------------------------------

 

2.签署该证书:

# ./sign-user-cert.sh client1

--------------------------------------

CA signing: client1.csr -> client1.crt:

Using configuration from ca.config

Enter pass phrase for ./ca.key: &#xff08;输入ca根认证密码&#xff09;

Check that the request matches the signature

Signature ok

The Subject&#39;s Distinguished Name is as follows

commonName            :PRINTABLE:&#39;client1&#39;

emailAddress          :IA5STRING:&#39;info&#64;example.com&#39;

Certificate is to be certified until Aug  8 08:41:51 2014 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

CA verifying: client1.crt <-> CA cert

client1.crt: OK

------------------------------------

 

3.将该客户端证书转换成浏览器可识别的.p12格式

# ./p12.sh client1

-------------------------------------

Enter Export Password: &#xff08;输入ca根认证密码&#xff09;

Verifying - Enter Export Password: (确认)

 

The certificate for client1 has been collected into a pkcs12 file.

You can download to your browser and import it.

--------------------------------------

# ll client1.p12

--------------------------------------

-rw-r--r-- 1 root root 2601 8月   8 16:44 client1.p12

--------------------------------------

 

4.将该p12文件分发给可信任的客户端&#xff0c;实现双向证书加密功能

注:此处将该文件传送到本机作为示例&#xff0c;实际线上可以利用程序实现证书认证下载

# sz client1.p12

 

5.配置https实现SSL虚拟主机双向加密

# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

添加如下内容&#xff1a;

----------------------------

   DocumentRoot "/usr/local/apache2/htdocs/www.example.com/"

   ServerAlias www.example.com

   SSLEngine on

   SSLCertificateFile "/usr/local/apache2/conf/server.crt"

   SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"

   SSLCACertificateFile  "/usr/local/apache2/conf/ca.crt"

   SSLVerifyClient require

   SSLVerifyDepth 10

----------------------------

 

6.测试结果

1).使用Chrome浏览器输入 https://www.example.com

未导入客户端证书&#xff0c;提示SSL连接出错

 

2).SO导入证书:

a.windows下运行该证书文件

b.进入证书导入向导&#xff0c;一路下一步即可完成操作

这里输入ca根证书密码

 

 

重新使用Chrome浏览器输入 https://www.example.com

提示

 

 

大功告成...

本文出自 “一路向北” 博客&#xff0c;请务必保留此出处http://showerlee.blog.51cto.com/2047005/1266712

 

1

 

 

 

 

 

 

 

    2 .基于apache双向ssl虚拟主机服务配置: http://881955.blog.51cto.com/871955/1652747

 


因为公司需要最近一直研究apache双向认证的问题&#xff0c;公司只有一台服务器&#xff0c;这台服务器上部署着wiki知识库&#xff0c;owncloud私有云&#xff0c;phpmyadmin&#xff0c;zendaopms。现在想实现owncloud需要证书认证的方式才能访问&#xff0c;其他三个可以通过http访问。想要实现这样的环境需要用到apache双向ssl的配置还有apache虚拟主机的知识。

 

软件环境 
Apache Httpd 2.2.16  
openssl-1.0.0e.tar.gz
SSL-Tools(http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz ) 

 

1、  安装openssl

#tar zxvf openssl-1.0.0e.tar.gz
#cd openssl-1.0.0e.tar.gz
#./config –prefix&#61;/usr/local/openssl
#make 
#make install 

 

2、  Httpd的安装

#tar zxvf httpd-2.2.16.tar.gz 
#cd httpd-2.2.16 
#./configure --prefix&#61;/usr/local/apache2 --with-included-apr  --enable-mods-shared&#61;most  --enable-ssl  --enable-rewrite  --enable-so --with-ssl&#61;/usr/local/openssl
#make 
#make install 

此步骤在/apache/httpd目录中安装httpd服务(通过参数--prefix指定)&#xff0c;同时使用--with-ssl指定刚才所安装OpenSSL的路径&#xff0c;用于将mod_ssl静态的编译到httpd服务中。 

 

3.制作证书

我们必须手工来生成SSL用到的证书&#xff0c;对证书不熟悉的人&#xff0c;有一个工具可以使用&#xff1a;http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz 。下面是如何通过这个工具来生成证书的过程&#xff1a; 

#cpssl.ca-0.1.tar.gz /usr/local/apache/httpd/conf 
#cd/usr/local/apache/conf 
#tar zxvfssl.ca-0.1.tar.gz 
#cd ssl.ca-0.1 
#./new-root-ca.sh (生成根证书
No Root CA keyround. Generating one 
Generating RSAprivate key, 1024 bit long modulus 
...........................&#43;&#43;&#43;&#43;&#43;&#43; 
....&#43;&#43;&#43;&#43;&#43;&#43; 
e is 65537(0x10001) 
Enter pass phrasefor ca.key: (输入一个密码
Verifying - Enterpass phrase for ca.key: (再输入一次密码
...... 
Self-sign the rootCA... (签署根证书
Enter pass phrasefor ca.key: (输入刚刚设置的密码
........ 
........ (下面开始签署
Country Name (2letter code) [MY]:CN 
State or ProvinceName (full name) [Perak]:Beijing//随你喜欢 
Locality Name (eg,city) [Sitiawan]:Beijing//随你喜欢 
Organization Name(eg, company) [My Directory Sdn Bhd]:chosen//随你喜欢 
Organizational UnitName (eg, section) [Certification Services Division]:tech//随你喜欢 
Common Name (eg, MDRoot CA) []:tech//随你喜欢 
Email Address []:di.wang&#64;chosenglobal.com//随你喜欢 
这样就生成了ca.key和ca.crt两个文件&#xff0c;下面还要为我们的服务器生成一个证书&#xff1a; 
#./new-server-cert.sh server (这个证书的名字是server) 
...... 
...... 
Country Name (2letter code) [MY]:CN 
State or ProvinceName (full name) [Perak]:Beijing 
Locality Name (eg,city) [Sitiawan]: Beijing
Organization Name(eg, company) [My Directory Sdn Bhd]:chosen 
Organizational UnitName (eg, section) [Secure Web Server]:tech
Common Name (eg,www.domain.com) []:tech
Email Address []:di.wang&#64;chosenglobal.com
这样就生成了server.csr和server.key这两个文件。 
还需要签署一下才能使用的&#xff1a; 
#./sign-server-cert.sh server 
CA signing:server.csr -> server.crt: 
Using configurationfrom ca.config 
Enter pass phrasefor ./ca.key: (输入上面设置的根证书密码
Check that therequest matches the signature 
Signature ok 
The Subject&#39;sDistinguished Name is as follows 
countryName:PRINTABLE:&#39;CN&#39; 
stateOrProvinceName:PRINTABLE:&#39;Beijing&#39; 
localityName:PRINTABLE:’Beijing’ 
organizationName:PRINTABLE:&#39;chosen&#39; 
organizationalUnitName:PRINTABLE:&#39;chosen&#39; 
commonName:PRINTABLE:&#39;tech&#39; 
emailAddress:IA5STRING:&#39; di.wang&#64;chosenglobal.com &#39; 
Certificate is tobe certified until Jan 19 21:59:46 2011 GMT (365 days) 
Sign thecertificate? [y/n]:y 
1 out of 1certificate requests certified, commit? [y/n]y 
Write out databasewith 1 new entries 
Data Base Updated 
CA verifying:server.crt <-> CA cert 
server.crt: OK

 

4、配置证书相关权限和路径:

# cd /usr/local/apache2/conf/ssl.ca-0.1

# chmod 644 server.key  server.crt  ca.crt

 

5SSL双向认证配置

为客户端生成一个证书:

# /usr/local/apache2/conf/ssl.ca-0.1

# ./new-user-cert.sh client1

-----------------------------------------

No client1.key round. Generating one

Generating RSA private key, 1024 bit long modulus

...........&#43;&#43;&#43;&#43;&#43;&#43;

...&#43;&#43;&#43;&#43;&#43;&#43;

e is 65537 (0x10001)

Fill in certificate data

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

into your certificate request.

What you are about to enter is what is called a DistinguishedName 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 &#39;.&#39;, the field will be left blank.

-----

Common Name (eg, John Doe) []:client1

Email Address []:di.wang&#64;chosenglobal.com

You may now run ./sign-user-cert.sh to get it signed

-------------------------------------------

签署该证书:

# ./sign-user-cert.sh client1

--------------------------------------

CA signing: client1.csr -> client1.crt:

Using configuration from ca.config

Enter pass phrase for ./ca.key: &#xff08;输入ca根认证密码&#xff09;

Check that the request matches the signature

Signature ok

The Subject&#39;s Distinguished Name is as follows

commonName           :PRINTABLE:&#39;client1&#39;

emailAddress         :IA5STRING:&#39;info&#64;example.com&#39;

Certificate is to be certified until Aug  8 08:41:512014 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

CA verifying: client1.crt <-> CA cert

client1.crt: OK

------------------------------------

将该客户端证书转换成浏览器可识别的.p12格式

# ./p12.sh client1

-------------------------------------

Enter Export Password: &#xff08;输入ca根认证密码&#xff09;

Verifying - Enter Export Password: (确认)

The certificate for client1 has been collected into a pkcs12file.

You can download to your browser and import it.

--------------------------------------

# ll client1.p12

--------------------------------------

-rw-r--r-- 1 root root 2601 8   8 16:44 client1.p12

--------------------------------------

将该p12文件分发给可信任的客户端&#xff0c;实现双向证书加密功能

注:此处将该文件传送到本机作为示例&#xff0c;实际线上可以利用程序实现证书认证下载

配置https实现SSL虚拟主机双向加密

# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

添加如下内容&#xff1a;

----------------------------

   DocumentRoot"/usr/local/apache2/htdocs"

   ServerAliashttps://10.10.10.1

   SSLEngine on

   SSLCertificateFile"/usr/local/ssl.ca/server.crt"

  SSLCertificateKeyFile "/usr/local/ssl.ca/server.key"

  SSLCACertificateFile "/usr/local/ssl.ca/ca.crt"

   SSLVerifyClient require

   SSLVerifyDepth 10

----------------------------

 

6、测试结果

1).使用Chrome浏览器输入 https://10.10.10.1/owncloud

未导入客户端证书&#xff0c;提示SSL连接出错

                            wKiom1Vay5rRMLxDAAEiP2jONvI982.jpg

2).SO导入证书:

a.windows下运行该证书文件

 

b.进入证书导入向导&#xff0c;一路下一步即可完成操作

 

 

重新使用Chrome浏览器输入 http://10.10.10.1/owncloud

提示


wKioL1VazY6zP821AACU8kD44tY951.jpg

wKiom1VazN7wtR_7AADpo0K5WRU985.jpgwKioL1VazmazCzxgAAG1_-vAJ-k272.jpg

 

参考资料&#xff1a;

http://blog.csdn.net/passwordport/article/details/8005292  apache2 ssl 双向认证

http://www.showerlee.com/archives/1211  Centos6.3apache实现SSL虚拟主机双向认证

http://honghuihun.iteye.com/blog/1137204  linux下apache-ssl配置

 

1

 

1

1

1

 

1

基于apache双向ssl虚拟主机服务配置: http://881955.blog.51cto.com/871955/1652747

因为公司需要最近一直研究apache双向认证的问题&#xff0c;公司只有一台服务器&#xff0c;这台服务器上部署着wiki知识库&#xff0c;owncloud私有云&#xff0c;phpmyadmin&#xff0c;zendaopms。现在想实现owncloud需要证书认证的方式才能访问&#xff0c;其他三个可以通过http访问。想要实现这样的环境需要用到apache双向ssl的配置还有apache虚拟主机的知识。

 

软件环境 
Apache Httpd 2.2.16  
openssl-1.0.0e.tar.gz
SSL-Tools(http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz ) 

 

1、  安装openssl

#tar zxvf openssl-1.0.0e.tar.gz
#cd openssl-1.0.0e.tar.gz
#./config –prefix&#61;/usr/local/openssl
#make 
#make install 

 

2、  Httpd的安装

#tar zxvf httpd-2.2.16.tar.gz 
#cd httpd-2.2.16 
#./configure --prefix&#61;/usr/local/apache2 --with-included-apr  --enable-mods-shared&#61;most  --enable-ssl  --enable-rewrite  --enable-so --with-ssl&#61;/usr/local/openssl
#make 
#make install 

此步骤在/apache/httpd目录中安装httpd服务(通过参数--prefix指定)&#xff0c;同时使用--with-ssl指定刚才所安装OpenSSL的路径&#xff0c;用于将mod_ssl静态的编译到httpd服务中。 

 

3.制作证书

我们必须手工来生成SSL用到的证书&#xff0c;对证书不熟悉的人&#xff0c;有一个工具可以使用&#xff1a;http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz 。下面是如何通过这个工具来生成证书的过程&#xff1a; 

#cpssl.ca-0.1.tar.gz /usr/local/apache/httpd/conf 
#cd/usr/local/apache/conf 
#tar zxvfssl.ca-0.1.tar.gz 
#cd ssl.ca-0.1 
#./new-root-ca.sh (生成根证书
No Root CA keyround. Generating one 
Generating RSAprivate key, 1024 bit long modulus 
...........................&#43;&#43;&#43;&#43;&#43;&#43; 
....&#43;&#43;&#43;&#43;&#43;&#43; 
e is 65537(0x10001) 
Enter pass phrasefor ca.key: (输入一个密码
Verifying - Enterpass phrase for ca.key: (再输入一次密码
...... 
Self-sign the rootCA... (签署根证书
Enter pass phrasefor ca.key: (输入刚刚设置的密码
........ 
........ (下面开始签署
Country Name (2letter code) [MY]:CN 
State or ProvinceName (full name) [Perak]:Beijing//随你喜欢 
Locality Name (eg,city) [Sitiawan]:Beijing//随你喜欢 
Organization Name(eg, company) [My Directory Sdn Bhd]:chosen//随你喜欢 
Organizational UnitName (eg, section) [Certification Services Division]:tech//随你喜欢 
Common Name (eg, MDRoot CA) []:tech//随你喜欢 
Email Address []:di.wang&#64;chosenglobal.com//随你喜欢 
这样就生成了ca.key和ca.crt两个文件&#xff0c;下面还要为我们的服务器生成一个证书&#xff1a; 
#./new-server-cert.sh server (这个证书的名字是server) 
...... 
...... 
Country Name (2letter code) [MY]:CN 
State or ProvinceName (full name) [Perak]:Beijing 
Locality Name (eg,city) [Sitiawan]: Beijing
Organization Name(eg, company) [My Directory Sdn Bhd]:chosen 
Organizational UnitName (eg, section) [Secure Web Server]:tech
Common Name (eg,www.domain.com) []:tech
Email Address []:di.wang&#64;chosenglobal.com
这样就生成了server.csr和server.key这两个文件。 
还需要签署一下才能使用的&#xff1a; 
#./sign-server-cert.sh server 
CA signing:server.csr -> server.crt: 
Using configurationfrom ca.config 
Enter pass phrasefor ./ca.key: (输入上面设置的根证书密码
Check that therequest matches the signature 
Signature ok 
The Subject&#39;sDistinguished Name is as follows 
countryName:PRINTABLE:&#39;CN&#39; 
stateOrProvinceName:PRINTABLE:&#39;Beijing&#39; 
localityName:PRINTABLE:’Beijing’ 
organizationName:PRINTABLE:&#39;chosen&#39; 
organizationalUnitName:PRINTABLE:&#39;chosen&#39; 
commonName:PRINTABLE:&#39;tech&#39; 
emailAddress:IA5STRING:&#39; di.wang&#64;chosenglobal.com &#39; 
Certificate is tobe certified until Jan 19 21:59:46 2011 GMT (365 days) 
Sign thecertificate? [y/n]:y 
1 out of 1certificate requests certified, commit? [y/n]y 
Write out databasewith 1 new entries 
Data Base Updated 
CA verifying:server.crt <-> CA cert 
server.crt: OK

 

4、配置证书相关权限和路径:

# cd /usr/local/apache2/conf/ssl.ca-0.1

# chmod 644 server.key  server.crt  ca.crt

 

5SSL双向认证配置

为客户端生成一个证书:

# /usr/local/apache2/conf/ssl.ca-0.1

# ./new-user-cert.sh client1

-----------------------------------------

No client1.key round. Generating one

Generating RSA private key, 1024 bit long modulus

...........&#43;&#43;&#43;&#43;&#43;&#43;

...&#43;&#43;&#43;&#43;&#43;&#43;

e is 65537 (0x10001)

Fill in certificate data

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

into your certificate request.

What you are about to enter is what is called a DistinguishedName 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 &#39;.&#39;, the field will be left blank.

-----

Common Name (eg, John Doe) []:client1

Email Address []:di.wang&#64;chosenglobal.com

You may now run ./sign-user-cert.sh to get it signed

-------------------------------------------

签署该证书:

# ./sign-user-cert.sh client1

--------------------------------------

CA signing: client1.csr -> client1.crt:

Using configuration from ca.config

Enter pass phrase for ./ca.key: &#xff08;输入ca根认证密码&#xff09;

Check that the request matches the signature

Signature ok

The Subject&#39;s Distinguished Name is as follows

commonName           :PRINTABLE:&#39;client1&#39;

emailAddress         :IA5STRING:&#39;info&#64;example.com&#39;

Certificate is to be certified until Aug  8 08:41:512014 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

CA verifying: client1.crt <-> CA cert

client1.crt: OK

------------------------------------

将该客户端证书转换成浏览器可识别的.p12格式

# ./p12.sh client1

-------------------------------------

Enter Export Password: &#xff08;输入ca根认证密码&#xff09;

Verifying - Enter Export Password: (确认)

The certificate for client1 has been collected into a pkcs12file.

You can download to your browser and import it.

--------------------------------------

# ll client1.p12

--------------------------------------

-rw-r--r-- 1 root root 2601 8   8 16:44 client1.p12

--------------------------------------

将该p12文件分发给可信任的客户端&#xff0c;实现双向证书加密功能

注:此处将该文件传送到本机作为示例&#xff0c;实际线上可以利用程序实现证书认证下载

配置https实现SSL虚拟主机双向加密

# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

添加如下内容&#xff1a;

----------------------------

   DocumentRoot"/usr/local/apache2/htdocs"

   ServerAliashttps://10.10.10.1

   SSLEngine on

   SSLCertificateFile"/usr/local/ssl.ca/server.crt"

  SSLCertificateKeyFile "/usr/local/ssl.ca/server.key"

  SSLCACertificateFile "/usr/local/ssl.ca/ca.crt"

   SSLVerifyClient require

   SSLVerifyDepth 10

----------------------------

 

6、测试结果

1).使用Chrome浏览器输入 https://10.10.10.1/owncloud

未导入客户端证书&#xff0c;提示SSL连接出错

                            wKiom1Vay5rRMLxDAAEiP2jONvI982.jpg

2).SO导入证书:

a.windows下运行该证书文件

 

b.进入证书导入向导&#xff0c;一路下一步即可完成操作

 

 

重新使用Chrome浏览器输入 http://10.10.10.1/owncloud

提示


wKioL1VazY6zP821AACU8kD44tY951.jpg

wKiom1VazN7wtR_7AADpo0K5WRU985.jpgwKioL1VazmazCzxgAAG1_-vAJ-k272.jpg

 

参考资料&#xff1a;

http://blog.csdn.net/passwordport/article/details/8005292  apache2 ssl 双向认证

http://www.showerlee.com/archives/1211  Centos6.3apache实现SSL虚拟主机双向认证

http://honghuihun.iteye.com/blog/1137204  linux下apache-ssl配置

1

 

 

 

 

 

1

 

1

 

1

 

1

1

 

1

 


转载于:https://www.cnblogs.com/xgqfrms/p/5347540.html


推荐阅读
  • 本文介绍了在Linux下安装和配置Kafka的方法,包括安装JDK、下载和解压Kafka、配置Kafka的参数,以及配置Kafka的日志目录、服务器IP和日志存放路径等。同时还提供了单机配置部署的方法和zookeeper地址和端口的配置。通过实操成功的案例,帮助读者快速完成Kafka的安装和配置。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • Skywalking系列博客1安装单机版 Skywalking的快速安装方法
    本文介绍了如何快速安装单机版的Skywalking,包括下载、环境需求和端口检查等步骤。同时提供了百度盘下载地址和查询端口是否被占用的命令。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • mac php错误日志配置方法及错误级别修改
    本文介绍了在mac环境下配置php错误日志的方法,包括修改php.ini文件和httpd.conf文件的操作步骤。同时还介绍了如何修改错误级别,以及相应的错误级别参考链接。 ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • 本文介绍了Perl的测试框架Test::Base,它是一个数据驱动的测试框架,可以自动进行单元测试,省去手工编写测试程序的麻烦。与Test::More完全兼容,使用方法简单。以plural函数为例,展示了Test::Base的使用方法。 ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • 拥抱Android Design Support Library新变化(导航视图、悬浮ActionBar)
    转载请注明明桑AndroidAndroid5.0Loollipop作为Android最重要的版本之一,为我们带来了全新的界面风格和设计语言。看起来很受欢迎࿰ ... [详细]
  • 本文介绍了作者在开发过程中遇到的问题,即播放框架内容安全策略设置不起作用的错误。作者通过使用编译时依赖注入的方式解决了这个问题,并分享了解决方案。文章详细描述了问题的出现情况、错误输出内容以及解决方案的具体步骤。如果你也遇到了类似的问题,本文可能对你有一定的参考价值。 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • Ubuntu 9.04中安装谷歌Chromium浏览器及使用体验[图文]
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
author-avatar
傻丫丫69_678
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有