简体   繁体   English

如何创建X509自签名证书以在Apache Tomcat中使用

[英]How to create X509 self signed certificate for use in Apache Tomcat

I have a Java application that runs on Windows Mobile devices using a 3rd Party JVM. 我有一个使用第三方JVM在Windows Mobile设备上运行的Java应用程序。 The application communicates with an Apache Tomcat server over HTTP. 该应用程序通过HTTP与Apache Tomcat服务器通信。 We have also used HTTPS for some connections and the certificates were created using the Sun keytool utility. 我们还对某些连接使用了HTTPS,并且使用Sun keytool实用程序创建了证书。 First a keystore was created using genkey, then the certificate exported using export and finally that was imported into another keystore using import. 首先使用genkey创建密钥库,然后使用export导出证书,最后使用import将其导入另一个密钥库。 The file created by genkey was loaded into the Apache server and the keystore created using import was loaded into the JVM on the PDA. genkey创建的文件已加载到Apache服务器中,而使用import创建的密钥库已加载到PDA上的JVM中。 Everything works as expected. 一切正常。

I am now working with a new JVM on the PDA and (for whatever reason) I have established that this JVM requires the keystore to be in X509 (DER) format. 我现在正在PDA上使用新的JVM,并且(无论出于何种原因)我已经确定该JVM需要密钥存储区为X509(DER)格式。 I started working on this about a month ago and had it working, but stupidly never wrote down the steps I took, and now I can't for the life of me remember what I did. 我大约一个月前就开始进行这项工作,并且一直有效,但愚蠢的是从来没有写下我所采取的步骤,而现在我一辈子都记不住自己做了什么。 I seem to remember using openssl but other than that I am totally lost. 我似乎记得使用openssl,但除此之外,我完全迷失了。 Anything I create now using openssl and try to load into Apache causes an error at startup (Invalid Keystore Format) so I am probably missing something out entirely. 我现在使用openssl创建的任何内容,尝试加载到Apache中都会在启动时导致错误(无效的密钥库格式),因此我可能会完全丢失某些内容。

Does anyone have any ideas how I should be going about creating this self-signed X509 certificate that can be loaded into Apache server and JVM running on a PDA? 有人对我如何创建可加载到PDA上运行的Apache服务器和JVM的自签名X509证书有什么想法吗?

UPDATE UPDATE

I followed the instructions from Apache on creating the self-signed certificate: 我遵循了Apache关于创建自签名证书的说明:

openssl req -new -x509 -nodes -out server.crt -keyout server.key

But when I copy the key to the Apache conf directory and start up I get an exception: 但是,当我将密钥复制到Apache conf目录并启动时,出现异常:

java.io.IOException: invalid keystore format
    at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:633)
...

The server.xml file contains the following entry for HTTPS: server.xml文件包含HTTPS的以下条目:

<Connector port="6969"
        protocol="HTTP/1.1"
            SSLEnabled="true"
                maxThreads="150"

                scheme="https"
                sslProtocol="TLS"
                secure="true"

                clientAuth="false"

                keystoreFile="./conf/server.key"
                keystorePass="password"

        ciphers="SSL_RSA_WITH_RC4_128_MD5"
    />

I guess the keystore needs to be a Java Keystore format?? 我猜密钥库需要是Java密钥库格式? But I need the certificate to be x509 format for the device, so I am not sure how to go about doing this? 但是我需要设备的证书为x509格式,所以我不确定该怎么做?

如果您已经按照apache说明进行操作 ,则需要提供有关无效密钥库格式的更多详细信息。

The KeyStoreBuilder utility in not-yet-commons-ssl-0.3.11.jar can convert between Apache/OpenSSL style PEM certificates and Java keystore files: not-yet-commons-ssl-0.3.11.jar中的KeyStoreBuilder实用程序可以在Apache / OpenSSL样式的PEM证书和Java密钥库文件之间进行转换:

http://juliusdavies.ca/commons-ssl/utilities.html#ksb http://juliusdavies.ca/commons-ssl/utilities.html#ksb

Try running this to see the command-line option: 尝试运行此命令以查看命令行选项:

java -cp not-yet-commons-ssl-0.3.11.jar org.apache.commons.ssl.KeyStoreBuilder java -cp not-yet-commons-ssl-0.3.11.jar org.apache.commons.ssl.KeyStoreBuilder

You write that the new JVM on the PDA requires the DER format. 您写道,PDA上的新JVM需要DER格式。 The openssl command line you are using will create PEM files by default. 默认情况下,您使用的openssl命令行将创建PEM文件。 You can convert those server.crt and server.key PEM files to DER format using these openssl commands: 您可以使用以下openssl命令将这些server.crt和server.key PEM文件转换为DER格式:

$ openssl x509 -in server.crt -outform DER -out server.crt2
$ openssl rsa -in server.key -outform DER -out server.key2

PEM files will be readable as text files, and DER files will be binary. PEM文件将被视为文本文件,而DER文件将为二进制文件。 If it's really just a difference of PEM vs. DER format, this should do the trick. 如果确实只是PEM与DER格式的区别,那应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM