我正在使用maven + grizzly + jersey来启动我自己的服务器。我创建了自签名证书,以便我的服务器可以支持https。我很好奇,以下是我生成证书的方式
keytool -genkey -keystore ./keystore_server -alias serverKey -dname "CN=localhost, OU=Jersey, O=Sun Microsystem, L=Prague, ST=Czech Republic, C=CZ"
keytool -export -alias serverKey -rfc -keystore ./keystore_server > ./server.cert
我在iMac上测试了这个(运行Mavericks)现在,我将server.cert添加到系统keychain中,以便所有用户都可以信任此证书。此外,我将信任级别更改为“始终信任”。
我在Chrome和Firefox中完成了这项工作。他们让我为这个证书添加例外,我做了然后一切都很顺利。但是,我从未让Safari(7.0)感到高兴。我总是得到错误,说Safari无法与我的localhost建立安全连接。
有谁知道为什么会这样?或者有更好的方法来调试这个问题,以便我能够告诉出错的地方。
提前谢谢你。我真的很感激。
答案 0 :(得分:1)
我终于敲了出来。这与我如何生成密钥库有关。 我使用的关键算法是DSA,为了让Safari和curl高兴,我必须使用RSA。否则,在SSL协商期间,将没有通用的密码套件。
答案 1 :(得分:0)
keytool -genkey -keystore ./keystore_server -alias serverKey -dname“CN = localhost,OU = Jersey,O = Sun Microsystem,L = Prague,ST = Czech Republic,C = CZ”
IETF和CA / Browser论坛不推荐使用公共名称中的DNS。相反,您应该在主题备用名称中放置DNS名称。在Common Name中加上一个友好名称,如“Sun Microsystem”。
有谁知道为什么会这样?
当证书在正确的位置具有所需的所有DNS名称时,我认为我没有问题。这包括浏览器和库,如.Net,Cocoa,Java,Python,PERL和Ruby。
我不使用keytool
,但我认为Server Fault中的这篇文章解释了如何使用它在SAN中生成带有DNS名称的证书:Unable to generate certificate with Subject Alternate Name using Java 1.7 keytool utility。
我使用OpenSSL在SAN中生成带有DNS名称的自签名。要使用OpenSSL并调用CONF文件(文件example-com.conf
如下所示):
$ openssl req -config example-com.conf -new -x509 -newkey rsa:2048 \
-nodes -keyout example-com.key.pem -days 365 -out example-com.cert.pem
# Self Signed (note the addition of -x509):
# openssl req -config example-com.conf -new -x509 -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.cert.pem
# Signing Request (note the lack of -x509):
# openssl req -config example-com.conf -new -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.cert.pem
# Print it:
# openssl x509 -in example-com.cert.pem -text -noout
# openssl req -in example-com.req.pem -text -noout
[ req ]
default_bits = 2048
default_keyfile = server-key.pem
distinguished_name = subject
req_extensions = req_ext
x509_extensions = x509_ext
string_mask = utf8only
# The Subject DN can be formed using X501 or RFC 4514 (see RFC 4519 for a description).
# Its sort of a mashup. For example, RFC 4514 does not provide emailAddress.
[ subject ]
countryName = Country Name (2 letter code)
countryName_default = US
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = NY
localityName = Locality Name (eg, city)
localityName_default = New York
organizationName = Organization Name (eg, company)
organizationName_default = Example, LLC
# Use a friendly name here because its presented to the user. The server's DNS
# names are placed in Subject Alternate Names. Plus, DNS names here is deprecated
# by both IETF and CA/Browser Forums.
commonName = Common Name (e.g. server FQDN or YOUR name)
commonName_default = Example Company
emailAddress = Email Address
emailAddress_default = test@example.com
# Section x509_ext is used when generating a self-signed certifcate. I.e., openssl req -x509 ...
[ x509_ext ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alternate_names
nsComment = "OpenSSL Generated Certificate"
# RFC 5280, Section 4.2.1.12 makes EKU optional
# CA/Browser Baseline Requirements, Appendix (B)(3)(F) makes EKU madatory
# extendedKeyUsage = serverAuth
# Section req_ext is used when generating a certifcate signing request. I.e., openssl req ...
[ req_ext ]
subjectKeyIdentifier = hash
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alternate_names
nsComment = "OpenSSL Generated Certificate"
# RFC 5280, Section 4.2.1.12 makes EKU optional
# CA/Browser Baseline Requirements, Appendix (B)(3)(F) makes EKU madatory
# extendedKeyUsage = serverAuth
[ alternate_names ]
DNS.1 = example.com
DNS.2 = www.example.com
DNS.3 = mail.example.com
DNS.4 = ftp.example.com
# Add these if you need them. But usually you don't want them or
# need them in production. You may need them for development.
# DNS.5 = localhost
# DNS.6 = localhost.localdomain
# DNS.7 = 127.0.0.1
# IPv6 localhost
# DNS.8 = ::1
# DNS.9 = fe80::1
答案 2 :(得分:0)
openssl x509 -in server.cert -inform PEM -text -noout
这是我的证书看起来像......
Safari不提供DSS支持(请参阅下面的Wireshark捕获),即使它是RFC 2246所要求的,第9节:
9. Mandatory Cipher Suites
In the absence of an application profile standard specifying
otherwise, a TLS compliant application MUST implement the cipher
suite TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA.
您可能遇到的另一个问题是SecureTransports
实施ECDHE_ECDSA_*
。它破坏了OS X和iOS的某些版本。请参阅OpenSSL开发人员邮件列表中的[openssl.org #3068] [PATCH] Safari broken ECDHE-ECDSA workaround和Apple are, apparently, dicks...。