简体   繁体   English

如何为嵌入式证书指定JVM SSL参数?

[英]How to specify JVM SSL arguments for embedded certs?

Let's say I have the following JAR: 假设我有以下JAR:

myapp-1.0.jar/
    META-INF/
        MANIFEST
    classes/
        com/
            <All my .class files>
        mycert1.cer
        mycert2.cer
        mycert3.cer

I need a way to run the JAR from the command line like so: 我需要一种从命令行运行JAR的方法,如下所示:

java -jar myapp-1.0.jar -Djavax.net.ssl.keyStore=myapp-1.0.jar/classes/mycert1.cer

or: 要么:

java -jar myapp-1.0.jar -Djavax.net.ssl.keyStore=myapp-1.0.jar/classes/mycert2.cer

But since the JAR is a ZIP file I can't seem to access the "embedded" SSL cert from the command line. 但是由于JAR是ZIP文件,因此我似乎无法从命令行访问“嵌入式” SSL证书。 This solution needs to work on both Windows and Linux. 该解决方案需要在Windows和Linux上都可以使用。 Ideas? 想法?

The value of 'javax.net.ssl.keyStore' is a filename. “ javax.net.ssl.keyStore”的值是一个文件名。

Resources in JAR files aren't files. JAR文件中的资源不是文件。

You can't do this via system properties. 您无法通过系统属性来执行此操作。

You will have to get an InputStream for the resource, and load a KeyStore from it, and initialize a KeyManager with that, and initialize an SSLContext with that, and get an SSLSocketFactory from that, and create your SSLSockets with that, as described in the JSSE Reference Guide. 您将必须获取资源的InputStream,并从中加载KeyStore,并使用该资源初始化KeyManager,然后使用该资源初始化SSLContext,并从中获取SSLSocketFactory,并使用该资源创建SSLSocket,如JSSE参考指南。

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

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