Tag Archives: SSL

Apache SSL配置

场景:

基于Apache服务器配置www.test.com.cn站点SSL证书。

证书链:
根证书:AddTrustExternalCARoot.crt中间证书:COMODORSAAddTrustCA.crt
中间证书:COMODORSADomainValidationSecureServerCA.crt
站点证书:www_test_com_cn.crt
私钥:www_test_com_cn.key

 

配置如下:

Apache 配置文件ssl.conf(apache安装目录下conf.d里)

#
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
#
Listen 443 https

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

#   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 exec:/usr/libexec/httpd-ssl-pass-dialog

#   Inter-Process Session Cache:
#   Configure the SSL Session Cache: First the mechanism
#   to use and second the expiring timeout (in seconds).
# shimizu: Change SSLSessionCache to capture and decrypt contents
#SSLSessionCache         shmcb:/run/httpd/sslcache(512000)
SSLSessionCache none
SSLSessionCacheTimeout  300

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

#
# Use “SSLCryptoDevice” to enable any supported hardware
# accelerators. Use “openssl engine -v” to list supported
# engine names.  NOTE: If you enable an accelerator and the
# server does not start, consult the error logs and ensure
# your accelerator is functioning properly.
#
SSLCryptoDevice builtin
#SSLCryptoDevice ubsec

##
## SSL Virtual Host Context
##

<VirtualHost _default_:443>

# General setup for the virtual host, inherited from global configuration
#DocumentRoot “/var/www/html”
#ServerName www.example.com:443
ServerName api.cpustest.com.cn:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

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

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol all -SSLv2

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
#SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCipherSuite MEDIUM:!aNULL:!MD5

#   Speed-optimized SSL Cipher configuration:
#   If speed is your main concern (on busy HTTPS servers e.g.),
#   you might want to force clients to specific, performance
#   optimized ciphers. In this case, prepend those ciphers
#   to the SSLCipherSuite list, and enable SSLHonorCipherOrder.
#   Caveat: by giving precedence to RC4-SHA and AES128-SHA
#   (as in the example below), most connections will no longer
#   have perfect forward secrecy – if the server’s key is
#   compromised, captures of past or future traffic must be
#   considered compromised, too.
#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5
#SSLHonorCipherOrder on

#   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.  A new
# certificate can be generated using the genkey(1) command.
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/httpd/www_test_com_cn.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 /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/httpd/www_test_com_cn.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 /etc/pki/tls/certs/server-chain.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)
#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
SSLCACertificateFile /etc/httpd/COMODORSADomainValidationSecureServerCA.crt

#   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
<Files ~ “\.(cgi|shtml|phtml|php3?)$”>
SSLOptions +StdEnvVars
</Files>
<Directory “/var/www/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 [2-5]” \
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 logs/ssl_request_log \
“%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \”%r\” %b”

</VirtualHost>

如何理解谷歌浏览器的安全警告信息

最近如果使用Chrome访问国内的很多网站的时候,比如exmail.qq.com, 你可能会注意到这样一个对话框,这个是什么意思?访问链接没有私密性吗? 等等,这里好像有点不对, 网页私密性到底是个啥,为啥会提醒我这个问题,我不是已经输了密码登录了嘛?事情要从头说起。

10081946_iTuw

我上个邮箱,连私密性都没有了,那里面的照片应该怎么办,以前修电脑没有私密性,现在连上网都没有私密性,难道我又要红了?

一、HTTPS (安全超文本协议)怎么来的?

1997 年 CERN发明HTTP 协议并用于万维网的时候,仅仅是为了在学术界内部做一个共享数据的平台, 并没有想到太多传输中的安全性。毕竟当年网络规模非常小,而计算机以及昂贵的网络设备并不是每个人都可以买得起的。

他们当然没有料到之后万维网居然成了一个信息传递的通用平台,一帮人甚至丧心病狂地在上面做起了Web电子邮箱、网络银行一类的服务。这类服务对安全性和私密性的要求都非常严格, 因为基本上没有人希望自己的银行密码,私人的邮件在传输中被第三方看到。

所以问题就来了, HTTP 是明文传输的。 HTTP倒是支持密码认证,只是不巧的是,密码也是明文传的。

针对这种情况,在网景一帮科学家,特别是 Dr. Taher Elgamal (号称SSL 之父)的努力下, HTTPS 横空出世了。

HTTPS 里面,所有传输的数据都是加密过的,于是第三方无法在数据的传输过程中获得任何有用的数据,数据传输中的私密性自然得到了保证。

至少当初设计的目的是这样子。

HTTPS 并非是一个全新的协议,其实是在 HTTP的 基础上,加了 SSL (安全套接字)或者是后来的 TLS (传输安全协议)。 SSL/TLS 工作在 HTTP 之下, 负责加密所有传输的数据。

说个题外话,当时不仅仅是 HTTP,众多的互联网上层协议,即应用层协议,STMP 电子邮件协议 一类,大多都是明文传输的。而移动互联网或
者其他网络,都是基于一些标准的协议,就是TCP/IP协议簇。早期时候,这些协议是由互联网领域专家联合制定的,就像现在制定法律的过程一样。而经过实
际的验证,其不严谨性渐渐被发现,于是人们在此前的基础上进行不断更新,SSL/TLS就是这样出来的。 SSL/TLS
由于是工作在TCP层和应用层之间,它可以加密任何应用层协议,包括STMP一类。 从这个角度说来,网景对互联网的贡献其实是非常深远的。

HTTPS 使用非对称算法交换密钥,这个也是一个非常精巧的算法,有兴趣的同学可以点击这里了解下,号称是20世纪最重要的算法之一。

HTTPS 除了解决加密问题以外,还需要还解决另外一个问题: 网站真实身份鉴别

比如,如果你上招行网站,你怎么知道你上的就是招商银行网站而不是一个做得和招商银行一模一样的钓鱼网站呢?

这个其实和现实生活中如何鉴定一个长的像警察并且突然站到你面前要你交罚款的人是否是真正的人民警察是一个场景。

”警官证可以给我看看吗,谢谢!“

HTTPS 用的是同一种方法,它要求每一个使用这个协议的网站从专业的第三方机构申请一个数字证书,数字证书中包括网站的域名,所有者等等 (当然也包括公钥,这里不详细展开协议细节了)。

这个数字证书其实就相当于现实中的警官证。

在访问这个网站的时候浏览器会对证书做一次检查,而这个对话框,就是检查的结果。

我们来看看这个对话框内容是个什么鬼。

二、如何鉴别你是警察?因为警官证也有可能是假的。

第一个:

该网站的身份验证已经通过GeoTrust SSL CA–G2的验证,但没有公开审核记录。该网站的安全设置已过期,可能导致日后的Chrome 版本无法安全访问该网站。

刚才有提到证书是由专业机构颁发的,不过,

- 专业机构就没有坏人了嘛。

- 证书就不会被人偷吗。

- 专业机构被骗了怎么办。

事实上,荷兰专业机构(DigiNotar)甚至被入侵过一次, 丢了好几百个证书,你可以自行脑补一下有人潜入公安部自己办了几百个警官证是一个多么壮观的场景。


是,IETF在2013年启动了一个叫做certificate-transparency的开源项目,把所有已知的合法证书做了一个白名单,浏览器在验
证证书的时候同时也会去查看这个证书是不是在白名单里面。 如果不在的话,就会告知用户这个证书找不到记录,于是,有可能是假或者是被盗的证书。

但是,这里有一个致命的问题:

到目前为止,这个还只是一个试验性项目,而这个世界上那么多的网站, 你白名单得过来嘛。

10081946_alMV

(注意:已经没有警示标志)

比如上图所显示的,其实也没有审核纪录,不过警告的标示去掉了。说明谷歌其实自己也知道目前白名单的覆盖很差,一般找不到记录,并不会加上确切的警告标示。所以,目前你可以忽略它。

关键在第二个:

本网站采用较弱的安全配置(SHA-1签名),所以你的连接可能不是私人的。

这个就比较有意思了。

还是那个警官证的问题。 要搞一个警官证除了去偷/骗/潜入公安部自己做一个真的以外, 你还可以做个假的嘛。

对于数字证书来说,最重要的鉴别真假的部分是数字签名,而鉴于数字证书一般不小,不可能对每个字节都签一次名,一般来说是对数字证书的一个哈希值进行签名。

10081946_6Jdd

如果你不知道哈希值是什么,我给你打个比方。如果你是一个数字证书, 那你的照片就是你的哈希值。

它包含下面2个条件:

- 通过合适的手段,可以从你产生你的照片, 但是没法从照片产生你 。意思是,先有你,才能有照片。

- 只有你可以精确的产生你的照片,别人都不行。你就是唯一的,你的特征是别人没有的。

所以如果想检查一个人的警官证,只需要看看照片能不能对上人(哈希值符合),照片上面的骑缝章对不对(数字签名)。但是这个骑缝章只需要盖在照片上,而不需要盖在警官兄的脸上。当然我知道这个比喻有非常多学术上的不严谨性,不过这个是我目前能找到最容易理解的比喻之一了。

数字证书中, SHA-1就是一种常见的哈希算法。 可以像照相机一样,给你的数字证书生成一个唯一值(照片)。

只是这个算法有一个问题。 这个算法这个函数由于设计时间早,强度太差,导致有可能用两个不同的数字证书可能会生成同样一个值。

这个就像如果你有一个照身份照的照相机,不过这个神奇的照相机拍的太模糊,以致于通过特殊的设定,可以用另外一个人照出和真实警官一模一样的照片。恭喜你,如果你发现了这个设定,你就可以大规模的制作套牌警官证了。

这种现象在哈希函数中被称为是“碰撞”。

对于SHA-1 算法 如果要找到这个“特殊的设定”大概需要2的74次方个操作,(也有论文指出,只需要2的61次方个操作即可完成)  这个在SHA-1发明的时候是不可想象,不过其实在现在也是不可行的。只是按照现在计算机的发展速度 2018 年左右使用价格合适服务器集群理论上就可以破解(可以参考这里):

”A
collision attack is therefore well within the range of what an
organized crime syndicate can practically budget by 2018, and a
university research project by 2021。“

(”因此,在一个有组织犯罪集团的范围内,一次碰撞攻击的实际预算是2018,而一个大学的研究项目是2021“)

于是,Chrome 认为使用SHA-1的哈希函数都是潜在不安全的,于是会对所有使用SHA-1的网站证书提出警告,督促所有使用SHA-1的网站换为SHA-2。

不过注意,仅仅是潜在不安全, 目前还没有可行可靠的SHA-1碰撞算法出现。

所以,这些网站暂时是安全的,不过也希望站长们多多提高安全意识,因为SHA-1已经非常接近可以被“破解”边缘。很有可能会出现以上情况:被人找到碰撞算法或者说被破解,从而制作虚假警官证。

如果要详细的证书设置以去除这个警告的步骤,可以参考这里(点击进入链接)

因为工作原因——欧朋Opera是Chromium安全组成员,所以我对这个内情比较了解。有兴趣可以去看看讨论组里面的撕逼贴, 截个屏放在这里:

10081946_c1fF

from:   http://www.techug.com/google-browser

Install SSL Certificate on Tomcat

Apache服务器SSL配置

服务器证书安装配置指南(tomcat) – SSL证书配置指南http://blog.csdn.net/defonds/article/details/44410359

StartSSL 免费证书申请步骤以及Tomcat和Apache下的安装

http://www.chinaunix.net/old_jh/13/456376.html

Tomcat更换SSL证书方法-key和crt文件转换为jks

在Jboss中添加Godaddy的SSL域名证书的方法

数字证书的格式

How to add ssl certificate for a domain in Tomcat 8 server

服务器证书安装配置指南(tomcat) – SSL证书配置指南

数字证书及CA的扫盲介绍

电子证书 DER vs. CRT vs. CER vs. PEM

http://www.instantssl.cn/ssl-certificate-products/all-ssl-certificates.html

https://support.comodo.com/index.php?/Default/Knowledgebase/Article/View/968/108/intermediate-ca-2-comodo-rsa-organization-validation-secure-server-ca-sha-2

不同格式证书导入keystore方法

 

问题:相机上使用tomcat设置证书的方式,无法工作。

需要改为Apache上设置证书。

from:http://www.alphassl.com/support/install-ssl/tomcat.html