Openssl 编译: http://www.linuxidc.com/Linux/2014-10/108502.htm
OpenSSL 在 Windows7 64bit + vs2010 中 win32 的编译步骤:
1.
从 https://www.openssl.org/source/下载 OpenSSL 源代码 openssl-1.0.1g 版本;
2.
x64(ActivePerl 为 perl 的一个脚本解释器);
从 http://www.activestate.com/activeperl/downloads 下 载 ActivePerl5.16.3
将 ActivePerl 安装到 D:\ProgramFiles\Perl64 目录下,打开命令提示符,将其定位
3.
到 D:\ProgramFiles\Perl64\eg 目录下,执行 perl example.pl ,若提示 Hello fromActivePerl!
则说明 Perl 安装成功,可以开始使用 Perl 的相关命令来进行 OpenSSL 的安装了;
4.
将 openssl-1.0.1g 解压缩到 E:\OpenSSL\openssl-1.0.1g 目录下;
5.
D:\ProgramFiles\NASM 中,并将 D:\ProgramFiles\NASM 添加到系统环境变量 Path 中;
从 http://sourceforge.net/projects/nasm/ 下 载 nasm 2.07 , 将 其 安 装 到
6.
将命令提示符定位到 E:\OpenSSL\openssl-1.0.1g;
7.
E:\OpenSSL\openssl);
输 入 perl Configure VC-WIN32 --perfix=E:\OpenSSL\openssl ( 将 其 安 装 到
8.
输入 ms\do_nasm ;
将 命 令 提 示 符 定 位 到 C:\Program Files (x86)\Microsoft Visual Studio
9.
10.0\VC\bin , 然后输入 vcvars32.bat,会显示 Settingenvironment for using Microsoft
Visual Studio 2010 x86 tools. 如果没有这一步,会提示 nmake 不是内部或外部命令;
10. 再次将命令提示符定位到 E:\OpenSSL\openssl-1.0.1g;
11. 输入 nmake –f ms\ntdll.mak ;执行完后会在 openssl-1.0.1g 目录下生成一个
out32dll 文件夹,里面包含了一些静态库、动态库和.exe 文件;
12. 输入 nmake -f ms\ntdll.mak test ;若最终显示 passed all
正确;
tests 说明生成的库
13. 输入 nmake -f ms\ntdll.mak install ;则会在 E:\OpenSSL\openssl 目录下生成 bin、
include、lib、ssl 四个文件夹;
14. 以上编译的是 release 库,若编译 debug 库,则将以上第 7 步中的 VC-WIN32 改成
debug-VC-WIN32 即可;
15. 若编译静态库则用 ms\nt.mak 替换掉上面用到的 ms\ntdll.mak 即可;
16. 若生成不带汇编支持的库,则需将以上第 7、8 步用 perl Configure VC-WIN32
no-asm --prefix=E:\OpenSSL\openssl 和 ms\do_ms 替换即可;
17. 在 E:\OpenSSL\openssl-1.0.1g\tmp32dll 文件夹下包含相应的汇编文件。
在 win64 下生成相应的库和汇编文件的编译步骤:
1.
2.
3.
4.
将命令提示符定位到 E:\OpenSSL\openssl-1.0.1g;
输入 perl Configure VC-WIN64A --perfix=E:\OpenSSL\openssl\win64 ;
输入 ms\do_nasm ;
输入 ms\do_win64a ;
5.
将 命 令 提 示 符 定 位 到 C:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\bin\amd64 , 然 后 输 入 vcvars64.bat , 会 显 示 Settingenvironment for using
Microsoft Visual Studio 2010 x64 tools. 如果没有这一步,会提示 nmake 不是内部或外部
命令;
6.
再次将命令提示符定位到 E:\OpenSSL\openssl-1.0.1g;
7.
输入 nmake -f ms\nt.mak ;执行完后会在 openssl-1.0.1g 目录下生成 out32
和 tmp32 两个文件夹,out32 文件夹中会生成两个静态库和一些执行文件,tmp32 文件夹
中会生成相应的汇编文件;
8.
正确;
输入 nmake -f ms\nt.mak test ;若最终显示 passed all
tests 说明生成的库
输入 nmake -f ms\nt.mak install ;则会在 E:\OpenSSL\openssl\win64 目录下
9.
生成 bin、include、lib、ssl 四个文件夹;
10. 以上编译的是 release 库,若编译 debug 库,则将以上第 2 步中的 VC-WIN64A 改成
debug-VC-WIN64A 即可;
11. 若编译动态库则用 ms\ntdll.mak 替换掉上面用到的 ms\nt.mak 即可;
12. 若生成不带汇编支持 的库,则需将以上第 2 步用 perl Configure VC-WIN64A
no-asm --prefix=E:\OpenSSL\openssl\win64 替换即可;
13. 在 E:\OpenSSL\openssl-1.0.1g\tmp32 文件夹下包含相应的汇编文件。
使用 openssl 自签证书:
http://www.linuxidc.com/Linux/2015-01/112071.htm
http://blog.csdn.net/jinhill/article/details/2573777
Windows: http://blog.csdn.net/jun55xiu/article/details/8980812
http://www.cnblogs.com/littleatp/p/5878763.html
使用到 openssl.cnf 的改为/etc/ssl/openssl.cnf
使用 OpenSSL 生成证书
下载安装 OpenSSL,进入/bin/下面,执行命令(把 ssl 目录下的 openssl.cnf 拷贝到 bin 目
录下)
1.首先要生成服务器端的私钥(key 文件):
openssl genrsa -des3 -out server.key 1024
[root@airwaySSL openssl]# cd ssl/
[root@airwaySSL ssl]# pwd
/home/openssl/ssl
[root@airwaySSL ssl]# ls
certs man misc openssl.cnf private server.csr server.key
运行时会提示输入密码,此密码用于加密 key 文件(参数 des3 便是指加密算法,当然也可以选
用其他你认为安全的算法.),以后每当需读取此文件(通过 openssl 提供的命令或 API)都需输
入口令.如果觉得不方便,也可以去除这个口令,但一定要采取其他的保护措施!
去除 key 文件口令的命令:
openssl rsa -in server.key -out server.key
2.openssl req -new -key server.key -out server.csr -config openssl.cnf
[root@airwaySSL bin]# openssl
openssl.cnf
req -new -key server.key -out server.csr
-config
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) []:wuhan
Organization Name (eg, company) [Internet Widgits Pty Ltd]:airway
Organizational Unit Name (eg, section) []:airway
Common Name (eg, YOUR name) []:airway
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
生成 Certificate Signing Request(CSR),生成的 csr 文件交给 CA 签名后形成服务端自己的
证书.屏幕上将有提示,依照其指示一步一步输入要求的个人信息即可.
3.对客户端也作同样的命令生成 key 及 csr 文件:
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
openssl req -new -key client.key -out client.csr -config openssl.cnf
[root@airwaySSL bin]# openssl req -new -key client.key -out client.csr -config openssl.cnf
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) []:wuhan
Organization Name (eg, company) [Internet Widgits Pty Ltd]:airway
Organizational Unit Name (eg, section) []:airway
Common Name (eg, YOUR name) []:airway
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
4.CSR 文件必须有 CA 的签名才可形成证书.可将此文件发送到 verisign 等地方由它验证,要
交一大笔钱,何不自己做 CA 呢.
openssl req -new -x509 -keyout ca.key -out ca.crt -config openssl.cnf
[root@airwaySSL bin]# openssl req -new -x509 -keyout ca.key -out ca.crt -config
openssl.cnf
Generating a 1024 bit RSA private key
...++++++
...................++++++
writing new private key to 'ca.key'
Enter PEM pass phrase:12345
Verifying - Enter PEM pass phrase:
-----
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) []:wuhan
Organization Name (eg, company) [Internet Widgits Pty Ltd]:airway
Organizational Unit Name (eg, section) []:airway
Common Name (eg, YOUR name) []:airway
Email Address []:
在 继 续 下 面 操 作 前 , 将 openssl.conf 文 件 打 开 , 查 看 其 dir 路 径 将 其 修 改 为 dir =
/home/openssl/bin/demoCA /,否则下面的步骤会提示路径无法找到。
自己手动创建一个 CA 目录结构:
[weigw@TEST bin]$ mkdir ./demoCA
[weigw@TEST bin]$ mkdir demoCA/newcerts
创建个空文件:
[weigw@TEST bin]$ vi demoCA/index.txt
向文件中写入 01:
[weigw@TEST bin]$ vi demoCA/serial
5.用生成的 CA 的证书为刚才生成的 server.csr,client.csr 文件签名:
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
[root@airwaySSL bin]# openssl ca -in server.csr -out server.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
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Feb 26 04:15:02 2009 GMT
Not After : Feb 26 04:15:02 2010 GMT
Subject:
countryName
= CN
stateOrProvinceName
= china
organizationName
= airway
organizationalUnitName
= airway
commonName
= airway
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier: