Generating a KeyStore and TrustStore

Generating a KeyStore and TrustStore

The following sections explain how to create both a KeyStore and a TrustStore (or import a certificate into an existing TrustStore such as the default Logical Host TrustStore in the location:

<c:\JavaCAPS>\appserver\domains\<MyDomain>\config\cacerts.jks

where <c:\JavaCAPS> is the directory where Java CAPS is installed and <MyDomain> is the name of your domain. The primary tool used iskeytool, but openssl is also used as a reference for generating pkcs12 KeyStores.

For more information on openssl and available downloads, visit the following web site:

http://www.openssl.org.

Creating a KeyStore in JKS Format

This section explains how to create a KeyStore using the JKS format as the database format for both the private key, and the associated certificate or certificate chain. By default, as specified in the java.security file, keytool uses JKS as the format of the key and certificate databases (KeyStore and TrustStores). A CA must sign the certificate signing request (CSR). The CA is therefore trusted by the server-side application to which the Adapter is connected.


Note –

It is recommended to use the default KeyStore

<c:\JavaCAPS>\appserver\domains\<MyDomain>\config\keystore.jks

where <c:\JavaCAPS> is the directory where Java CAPS is installed and <MyDomain> is the name of your domain.


To Generate a KeyStore

  1. Perform the following command.

    keytool -keystore clientkeystore -genkey -alias client
  2. Once prompted, enter the information required to generate a CSR. A sample key generation section follows.
    Enter keystore password: javacaps
    What is your first and last name?
    [Unknown]: development.sun.com
    What is the name of your organizational unit?
    [Unknown]: Development
    what is the name of your organization?
    [Unknown]: Sun
    What is the name of your City or Locality?
    [Unknown]: Monrovia
    What is the name of your State or Province?
    [Unknown]: California
    What is the two-letter country code for this unit?
    [Unknown]: US
    Is<CN=development.sun.com, OU=Development, O=Sun, L=Monrovia, ST=California,
    C=US> correct?
    [no]: yes
    
    Enter key password for <client>
        (RETURN if same as keystore password):

    If the KeyStore password is specified, then the password must be provided for the adapter.

  3. Press RETURN when prompted for the key password (this action makes the key password the same as the KeyStore password).

    This operation creates a KeyStore file clientkeystore in the current working directory. You must specify a fully qualified domain for the “first and last name” question. The reason for this use is that some CAs such as VeriSign expect this properties to be a fully qualified domain name.

    There are CAs that do not require the fully qualified domain, but it is recommended to use the fully qualified domain name for the sake of portability. All the other information given must be valid. If the information cannot be validated, a CA such as VeriSign does not sign a generated CSR for this entry.

    This KeyStore contains an entry with an alias of client. This entry consists of the generated private key and information needed for generating a CSR as follows:

    keytool -keystore clientkeystore -certreq -alias client -keyalg rsa -file client.csr

    This command generates a certificate signing request which can be provided to a CA for a certificate request. The file client.csr contains the CSR in PEM format.

    Some CA (one trusted by the web server to which the adapter is connecting) must sign the CSR. The CA generates a certificate for the corresponding CSR and signs the certificate with its private key. For more information, visit the following web sites:

    http://www.thawte.com

    or

    http://www.verisign.com

    If the certificate is chained with the CA’s certificate, perform step 4; otherwise, perform step 5 in the following list:

  4. Perform the following command.
    keytool -import -keystore clientkeystore -file client.cer -alias client

    The command imports the certificate and assumes the client certificate is in the file client.cer and the CA’s certificate is in the fileCARoot.cer.

  5. Perform the following command to import the CA’s certificate into the KeyStore for chaining with the client’s certificate.
    keytool -import -keystore clientkeystore -file CARoot.cer -alias theCARoot
  6. Perform the following command to import the client’s certificate signed by the CA whose certificate was imported in the preceding step.
    keytool -import -keystore clientkeystore -file client.cer -alias client

    The generated file clientkeystore contains the client’s private key and the associated certificate chain used for client authentication and signing. The KeyStore and/or clientkeystore, can then be used as the adapter’s KeyStore.

Creating a KeyStore in PKCS12 Format

This section explains how to create a PKCS12 KeyStore to work with JSSE. In a real working environment, a customer could already have an existing private key and certificate (signed by a known CA). In this case, JKS format cannot be used, because it does not allow the user to import/export the private key through keytool. It is necessary to generate a PKCS12 database consisting of the private key and its certificate.

The generated PKCS12 database can then be used as the Adapter’s KeyStore. The keytool utility is currently lacking the ability to write to a PKCS12 database. However, it can read from a PKCS12 database.


Note –

There are additional third-party tools available for generating PKCS12 certificates, if you want to use a different tool.



For the following example, openssl is used to generate the PKCS12 KeyStore:

cat mykey.pem.txt mycertificate.pem.txt>mykeycertificate.pem.txt

The existing key is in the file mykey.pem.txt in PEM format. The certificate is in mycertificate.pem.txt, which is also in PEM format. A text file must be created which contains the key followed by the certificate as follows:

openssl pkcs12 -export -in mykeycertificate.pem.txt -out mykeystore.pkcs12
-name myAlias -noiter -nomaciter

This command prompts the user for a password. The password is required. The KeyStore fails to work with JSSE without a password. This password must also be supplied as the password for the Adapter’s KeyStore password.

This command also uses the openssl pkcs12 command to generate a PKCS12 KeyStore with the private key and certificate. The generated KeyStore is mykeystore.pkcs12 with an entry specified by the myAlias alias. This entry contains the private key and the certificate provided by the -in argument. The noiter and nomaciter options must be specified to allow the generated KeyStore to be recognized properly by JSSE.

Creating a TrustStore

For demonstration purposes, suppose you have the following CAs that you trust: firstCA.cert, secondCA.cert, thirdCA.cert, located in the directory C:\cascerts. You can create a new TrustStore consisting of these three trusted certificates.

To Create a New TrustStore

  1. Perform the following command.

    keytool -import -file C:\cascerts\firstCA.cert -alias firstCA -keystore myTrustStore
  2. Enter this command two more times, but for the second and third entries, substitute secondCA and thirdCA for firstCA. Each of these command entries has the following purposes:
    • The first entry creates a KeyStore file named myTrustStore in the current working directory and imports the firstCA certificate into the TrustStore with an alias of firstCA. The format of myTrustStore is JKS.
    • For the second entry, substitute secondCA to import the secondCA certificate into the TrustStore, myTrustStore.
    • For the third entry, substitute thirdCA to import the thirdCA certificate into the TrustStore.

    Once completed, myTrustStore is available to be used as the TrustStore for the adapter.

  • © 2010, Oracle Corporation and/or its affiliates
时间: 2024-10-13 17:01:49

Generating a KeyStore and TrustStore的相关文章

使用keytool生成ssl密钥文件keystore和truststore

最近在研究Mina的开发,通信的时候需要数据加密,而且mina本身支持SSLFilter过滤器,所以可以采用SSL加密的方式对数据进行加密. 在进行加密之前,我们需要使用keytool(这个存在于C:\Program Files\Java\jdk1.7.0_65\bin目录下)产生创建keystore和truststore文件.接下来我会为你介绍生成密钥的方法. 1.打开cmd命令提示符(一定要以管理员身份运行,否则会出现keytool 错误:java.io.FileNotFoundExcept

KeyStore和TrustStore

笔者的这篇文章参考了http://docs.oracle.com/cd/E19509-01/820-3503/ggfgo/index.html KeyStore和TrustStore在很多HTTPS双向配置的文章中基本没有明白的,可能是因为当前的HTTPS网站太少,得不到重视,都是照着别人的抄一遍,然后运行一下. KeyStore是服务器的密钥存储库,存服务器的公钥私钥证书 TrustStore是服务器的信任密钥存储库,存CA公钥,但有一部分人存的是客户端证书集合,这样并不合适 下面是几个常见的

转/keystore和truststore的区别

keytool是java自带的工具用于产生密钥 keystore可以看成一个放key的库,key就是公钥,私钥,数字签名等组成的一个信息. truststore是放信任的证书的一个store. 那他们之间有啥关系和联系呢?在一个安全链接的模型中又各自起到什么作用呢? 其实我也没搞太清楚-_-b 我先把目前的理解记下来,以后再慢慢修正 这篇主要针对的是web应用,web应用一般是通过https,ssl来做客户端和server端的链接 就以单向验证为例,服务器端的app server是tomcat

Https:证书生成 .p12 .keyStore 和 .truststore文件理解

当我们需要SSL证书时,可以自动生成SSL证书,但是每个系统都申请一次证书会比较麻烦,所以用到了如下几个文件格式:   .p12(PKCS #12) 我们的每一个证书都可以生成一个.p12文件,这个文件是一个加密的文件,只要知道其密码,就可以供给所有的系统设备使用,使设备不需要在重新申请开发和发布证书,就能使用. 注意:一般.p12文件是给与别人使用的,本机必须已经有一个带秘钥的证书才可以生成.p12文件 .keyStore(密钥库) keystore中一般保存的是我们的私钥,用来加解密或者为别

keyStore vs trustStore--转载

原文:http://lukejin.iteye.com/blog/605634 今天有同事向我问起这两个概念,所以我就记录下.首先我们得澄清一些概念.一个web应用如果需要提供以https的方式访问的服务的话,我们需要一个数字证书,这个证书的配置是在apache的配置文件或者其他web容器的配置文件中进行配置的.当然这个可以保存在keystore中. 我们自己的应用中通常所说的keystore或者truststore主要是针对于应用本身的需求来的.keystore和truststore从其文件格

杂谈X509证书, Java Keystore与Jetty

很多人对JSSE组成部分的Key Tool 工具不太明白,希望本文能有帮助 科班出身的同学应该学过课程“密码学”, 这门课详细解释了现代对称加密的算法原理, 当时学的我云里雾里. 直到现在使用过SSL加密才知道工程上用法是这样的, 老师讲的时候就不能带一点工程实践吗? 简单来说,对称加密体系就是我有一段需要加密的字符, 我用私钥加密之后变成了无意义的密文, 只有用配对的公钥才能对这个密文进行解密还原回来. 下图是个简单的示意,注意由于公私钥是配对的,一般给信息加密的人持有此密钥对. 这套机制可以

Java Secure Socket Extension (JSSE) Reference Guide

Skip to Content Oracle Technology Network Software Downloads Documentation Search Java Secure Socket Extension (JSSE) Reference Guide This guide covers the following topics: Skip Navigation Links Introduction Features and Benefits JSSE Standard API S

深入浅出Zabbix 3.0 -- 第三章 Zabbix 监控方式

第三章  Zabbix 监控方式 有人说通过Zabbix可以完成任何监控任务,只有你想不到的,但没有监控不了的,真是这样吗?当你通过本章了解了Zabbix提供的多种监控方式后,你就会发现此言非虚. 这里所说的监控方式,实际上就是Zabbix中的配置监控项时选择的监控项类型.为了适应各种应用场景的需要,Zabbix提供了多种方法帮助你更好的完成监控任务. Zabbix 3.0中提供的监控方式包括: Active agents Passive agents Extending agents Simp

Java安全套接字扩展——JSSE

上节已经介绍了SSL/TLS协议的通信模式,而对于这些底层协议,如果要每个开发者都自己去实现显然会带来不必要的麻烦,正是为了解决这个问题Java为广大开发者提供了Java安全套接字扩展--JSSE,它包含了实现Internet安全通信的一系列包的集合,是SSL和TLS的纯Java实现,同时它是一个开放的标准,每个公司都可以自己实现JSSE,通过它可以透明地提供数据加密.服务器认证.信息完整性等功能,就像使用普通的套接字一样使用安全套接字,大大减轻了开发者的负担,使开发者可以很轻松将SSL协议整合