Vincent.Chan‘s Blog

常用链接

统计

积分与排名

网站

最新评论

https相关

什么是HTTPS?
当使用 基于SSL/TLS(通常使用 https:// URL)向站点进行HTTP请求时,从服务器向客户机发送一个证书。客户机使用已安装的公共证书通过这个证书验证服务器的身份,然后检查 IP 名称(机器名)与客户机连接的机器是否匹配。客户机生成一些可以用来生成对话的私钥(称为会话密钥)的随机信息,然后用服务器的公钥对它加密并将它发送到 服务器。服务器用自己的私钥解密消息,然后用该随机信息派生出和客户机一样的私有会话密钥。通常在这个阶段使用 RSA 公钥算法。然后,客户机和服务器使用私有会话密钥和私钥算法(通常是 RC4)进行通信。使用另一个密钥的消息认证码来确保消息的完整性。

什么是数字签名?
所 谓数字签名就是信息发送者用其私有密钥对从所传报文中提取出的特征数据(或称数字指纹)进行RSA算法操作,以保证发信人无法抵赖曾发过该信息(即不可抵 赖性),同时也确保信息报文在经签名后末被篡改(即完整性)。当信息接收者收到报文后,就可以用发送者的公钥对数字签名进行验证。
Overview of SSL?
     SSL, or Secure Socket Layer, is a technology which allows web browsers and web servers to communicate over a secured connection. This means that the data being sent is encrypted by one side, transmitted, then decrypted by the other side before processing. This is a two-way process, meaning that both the server AND the browser encrypt all traffic before sending out data.
     Another important aspect of the SSL protocol is Authentication. This means that during your initial attempt to communicate with a web server over a secure connection, that server will present your web browser with a set of credentials, in the form of a "Certificate", as proof the site is who and what it claims to be. In certain cases, the server may also request a Certificate from your web browser, asking for proof that you are who you claim to be. This is known as "Client Authentication," although in practice this is used more for business-to-business (B2B) transactions than with individual users. Most SSL-enabled web servers do not request Client Authentication.
https与Tomcat
   The Apache Jakarta Tomcat 5 Servlet/JSP Container SSL Configuration HOW-TO?
利用快速配置:
  1,用jdk中的keytool生成一个tomcat keystore
    在命令行敲入:%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA
    会提示你输入keypassword 和 keystorepassword 以及其它相关信息。按提示确认完成。
  2, 在conf/server.xml中加入:
    

               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" disableUploadTimeout="true"
               acceptCount="100" debug="0" scheme="https" secure="true"
               clientAuth="false" keystorePass="password" sslProtocol="TLS" />
 
3,启动tomcat,打开浏览器输入https://localhost:8443 就OK了。
注意:用此方法生成的keystore文件置于C:\Documents and Settings\user下
注释:
Attribute Description
clientAuth Set this value to true if you want Tomcat to require all SSL clients to present a client Certificate in order to use this socket. Set this value to want if you want Tomcat to request a client Certificate, but not fail if one isn't presented.
keystoreFile Add this attribute if the keystore file you created is not in the default place that Tomcat expects (a file named .keystore in the user home directory under which Tomcat is running). You can specify an absolute pathname, or a relative pathname that is resolved against the $CATALINA_BASE environment variable.
keystorePass Add this element if you used a different keystore (and Certificate) password than the one Tomcat expects (changeit).
keystoreType Add this element if using a PKCS12 keystore. The valid values are JKS and PKCS12.
sslProtocol The encryption/decryption protocol to be used on this socket. It is not recommended to change this value if you are using Sun's JVM. It is reported that IBM's 1.4.1 implementation of the TLS protocol is not compatible with some popular browsers. In this case, use the value SSL.
ciphers The comma separated list of encryption ciphers that this socket is allowed to use. By default, any available cipher is allowed.
algorithm The X509 algorithm to use. This defaults to the Sun implementation (SunX509). For IBM JVMs you should use the value IbmX509. For other vendors, consult the JVM documentation for the correct value.
truststoreFile The TrustStore file to use to validate client certificates.
truststorePass The password to access the TrustStore. This defaults to the value of keystorePass.
truststoreType Add this element if your are using a different format for the TrustStore then you are using for the KeyStore. The valid values are JKS and PKCS12.

Java keytool工具的作用及使用方法?
Keytool 是安全钥匙与证书的管理工具。它管理一个存储了私有钥匙和验证相应公共钥匙的与它们相关联的X.509 证书链的keystore(相当一个数据库)。
Keytool 是一个有效的安全钥匙和证书的管理工具。它能够使用户使用数字签名来管理他们自己的私有/公共钥匙对,管理用来作自我鉴定的相关的证书,管理数据完整性和鉴定服务。它还能使用户在通信时缓存它们的公共钥匙.
一个证书是某一实体(个人,公司等)的数字签名,指出其他实体的公共钥匙(或其他信息)的详细的值.当数据被签名后,这个签名信息被用来检验数据的完整性和真实性.完整性指数据没有被修改和篡改,真实性指数据从任何产生和签名的一方真正的传输到达。
Keytool 把钥匙和证书储存到一个keystore.默任的实现keystore的是一个文件。它用一个密码保护钥匙。而另外的一个工具jarsigner用keystore中的信息产生或检验Java aRchive(jar文件)中的数字签名。
Keystore有两个不同的入口:
1.       钥匙入口:保存了非常敏感的加密的钥匙信息,并且是用一个保护的格式存储以防止未被授权的访问.以这种形式存储的钥匙是秘密钥匙,或是一个对应证书链中公有钥匙的私有钥匙.
2.    信任证书入口:包含一个属于其他部分的单一公共钥匙证书.它之所以被称为"信任证书",是因为keystore信任的证书中的公共钥匙真正属于证书所有者的身份识别.
 
Keystore的别名:
所有的keystore入口(钥匙和信任证书入口)是通过唯一的别名访问.别名是不区分大小写的。如别名Hugo和hugo指向同一个keystore入口.
可以在加一个入口到keystore的时候使用-genkey参数来产生一个钥匙对(公共钥匙和私有钥匙)时指定别名.也可以用-import参数加一个证书或证书链到信任证书。
 
如:keytool -genkey -alias duke -keypass dukekeypasswd
 
其中duke为别名,dukekeypasswd为duke别名的密码。这行命令的作用是产生一个新的公共/私有钥匙对. 其中duke为别名,dukekeypasswd为duke别名的密码.这行命令的作用是产生一个新的公共/私有钥匙对.
假如你想修改密码,可以用:
keytool -keypasswd -alias duke -keypass dukekeypasswd -new newpass
将旧密码dukekeypasswd改为newpass.
 
Keystore的产生:
1.       当使用-genkey 或-import或-identitydb命令添加数据到一个keystore,而当这个keystore不存在时,产生一个keystore.默认名是.keystore,存放到user-home目录.
2.    当用-keystore指定时,将产生指定的keystore.
 
Keystore的实现:
Keytool 类位于java.security包下,提供一个非常好的接口去取得和修改一个keystore中的信息. 目前有两个命令行:keytool和jarsinger,一个GUI工具Policy 可以实现keystore.由于keystore是公开的,用户可以用它写一些额外的安全应用程序。
Keystore还有一个sun公司提供的內在实现.它把keystore作为一个文件来实现.利用了一个keystore类型(格式)"JKS".它用单独的密码保护每一个私有钥匙.也用可能不同的密码保护整个keystore的完整性.
 
支持的算法和钥匙大小:
keytool允许用户指定钥匙对和注册密码服务供应者所提供的签名算法.缺省的钥匙对产生算法是"DSA"。假如私有钥匙是"DSA"类型,缺省签名算法是"SHA1withDSA",假如私有钥匙是"RSA"类型,缺省算法是"MD5withRSA".
当产生一个DSA钥匙对,钥匙必须在512-1024位之间.对任何算法的缺省钥匙大小是1024位.
 
1.       证书:一个证书是一个实体的数字签名,指出其他实体的公共钥匙有明确的值。
2.       公共钥匙:是同一个详细的实体的数字关联,并有意让所有想同这个实体发生信任关系的其他实体知道,公共钥匙用来检验签名;
3.    数字签名:假如数据已被签名,并用身份存储在一个实体中,一个签名能够证明这个实体知道这个数据.这个数据用实体私有钥匙签名并递交;
4.    身份:知道实体的方法.在一些系统中身份是公共钥匙,其他系统中可以是从一个X.509名字的邮件地址的Unix UID来的任何东西;
5.    签名:一个签名用实体私有钥匙来计算某些加密数据;
6.    私有钥匙:是一些数字,每一个私有钥匙只能被特定的拥有该私有钥匙的实体知道.私有和公共钥匙存在所有用公共钥匙加密的系统的钥匙对中.一个公共钥匙加密(如DSA),一个私有钥匙与一个正确的公共钥匙通信.私有钥匙用来计算签名。
7.    实体:一个实体可以是一个人,一个组织,一个程序,一台计算机,一个商业,一个银行,或其他你想信任的东西.
 
Keytool应用实例:
 
1.产生一个keystore:
 
keytool -genkey -alias User(keystore的别名) -keyalg RSA -validity 7 -keystore keystore(指定keystore).
 
运行这个命令,系统提示:
Enter keystore password:yourpassword(输入密码)
 
What is your first and last name?
[Unknown]: your name(输入你的名字)
 
What is the name of your organizational unit?
[Unknown]:your organizational(输入你所在组织单位的名字)
 
What is the name of your organization?
[Unknown]:your organization name (输入你所在组织的名字)
 
What is the name of your City or Locality?
[Unknown]:your city name(输入所在城市的名字)
 
What is the name of your State or Province?
[Unknown]:your provice name(输入所在省份名字)
 
What is the two-letter country code for this unit?
[Unknown]:cn(输入国家名字)
Is CN=your name, OU=your organizaion, O="your organization name",L=your city name, ST=your province name, C=cn correct?
[no]: yes
 
3.    检查一个keystore:
keytool -list -v -keystore keystore
Enter keystore password:your password(输入密码)
 
将显示keystore內容如:
Keystore type: jks
Keystore provider: SUN
 
Your keystore contains 1 entry
Alias name: yourname
Creation date: Dec 20, 2001
Entry type: keyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=yourname, OU=your organization, O="your organization name",
L=your city name, ST=your province name, C=CN
Issuer: CN=Duke, OU=Java Software, O="Sun Microsystems, Inc.", L=Palo Alto, ST=CA, C=US
Serial number: 3c22adc1
Valid from: Thu Dec 20 19:34:25 PST 2001 until: Thu Dec 27 19:34:25 PST 2001
Certificate fingerprints:
MD5: F1:5B:9B:A1:F7:16:CF:25:CF:F4:FF:35:3F:4C:9C:F0
SHA1: B2:00:50:DD:B6:CC:35:66:21:45:0F:96:AA:AF:6A:3D:E4:03:7C:74
 
3.输出keystore到一个文件:testkey:
keytool -export -alias duke -keystore keystore -rfc -file testkey
系统输出:Enter keystore password:your password(输入密码)
Certificate stored in file < td>
 
4.输入证书到一个新的truststore:
keytool -import -alias dukecert -file testkey -keystore truststore
Enter keystore password:your new password.(输入truststore新密码)
 
 
5.检查truststore:
keytool -list -v -keystore truststore
系统将显示truststore的信息.
 
现在可以用适当的keystore运行你的应用程序.如:
java -Djavax.net.ssl.keyStore = keystore
-Djavax.net.ssl.keyStorePassword=password Server
 
和:
 java -Djavax.net.ssl.trustStore=truststore
-Djavax.net.ssl.trustStorePassword=trustword Client

posted on 2006-02-14 21:00 Vincent.Chen 阅读(1595) 评论(0)  编辑  收藏 所属分类: 杂文


只有注册用户登录后才能发表评论。


网站导航: