java JDK/JRE 源代码与匹配的 JSSE (SSL) 源代码和匹配的可运行 JDK/JRE?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/163552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 11:15:22  来源:igfitidea点击:

JDK/JRE source code with matching JSSE (SSL) source code and matching runnable JDK / JRE?

javassljsse

提问by Chris Markle

I have seen Where to find Java 6 JSSE/JCE Source Code?and asked the question myself How to get JRE/JDK with matching source?but I don't either of these was specific enough to get the answer I was really after, so I'm going to try a way more specific version of the question.

我已经看到在哪里可以找到 Java 6 JSSE/JCE 源代码?并自己问了一个问题 如何使用匹配的源获取 JRE/JDK?但我认为这些都不够具体,无法得到我真正想要的答案,所以我将尝试更具体的问题版本。

Basically the problem that I am trying to solve is that I would like to be able to use my Eclipse debugger on Windows and step into the Java SSL classes (JSSE) to help me debug SSL issues as well as to just understand the SSL process better. BTW I am familiar with (and use) the javax.net.debug=ssl|all system property to get SSL tracing and, while this is very helpful, I'd still like to be able to step through that pesky code.

基本上,我试图解决的问题是我希望能够在 Windows 上使用我的 Eclipse 调试器并进入 Java SSL 类 (JSSE) 以帮助我调试 SSL 问题以及更好地理解 SSL 过程. 顺便说一句,我熟悉(并使用) javax.net.debug=ssl|all 系统属性来获取 SSL 跟踪,虽然这非常有帮助,但我仍然希望能够逐步完成那些讨厌的代码。

So what I think I specifically need is:

所以我认为我特别需要的是:

  1. An executable JRE / JDK implementation (not wanting to build one)...
  2. That runs on my Windows platform (XP)...
  3. That includes source...
  4. And that source includes the SSL "bits" (JSSE, etc.)...
  5. And ideally the SSL implementation is Sun's or the OpenJDK version.
  1. 一个可执行的 JRE/JDK 实现(不想构建)...
  2. 在我的 Windows 平台 (XP) 上运行...
  3. 这包括源...
  4. 该来源包括 SSL“位”(JSSE 等)...
  5. 理想情况下,SSL 实现是 Sun 或 OpenJDK 版本。

I think the closest thing (as noted in PW's answer StackOverflow: 87106) is the OpenJDK source openjdk-6-src-b12-28_aug_2008.tar.gz found at OpenJDK 6 Source Release, but I'm not sure there's a matching executable JDK / JRE for that that would run on Windows.

我认为最接近的事情(如 PW 的回答StackOverflow: 87106 中所述)是在OpenJDK 6 Source Release 中找到的 OpenJDK 源 openjdk-6-src-b12-28_aug_2008.tar.gz ,但我不确定是否有匹配的可执行 JDK / JRE 用于在 Windows 上运行。

回答by Ayaskant

You can get the source code of JSSE lib (Open JDK implementation) here - http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/file/4d6c03fb1039/src/share/classes/sun/security/ssl

您可以在此处获取 JSSE lib(Open JDK 实现)的源代码 - http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/file/4d6c03fb1039/src/share/classes/sun/security/ ssl

Steps to create a source jar file for attaching to an IDE for debugging.

创建源 jar 文件以附加到 IDE 以进行调试的步骤。

  1. Go a little above in the directory structure i.e. to http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/file/4d6c03fb1039/src/share/classes/repo.
  2. Download the source package by clicking on the "zip" or "gz" links that you see at the left pane.
  3. But this package is huge and contains thousands of *.java files. You do not normally want all of these to just debug jsse.jar code.
  4. So better copy only the sun.security.rsa, sun.security.ssl, sun.security.provider& com.sun.net.sslpackages to a new folder (lets say jsse-code) on your computer.
  5. Go to that folder from command line & create the source jar on your own.
    e.g. jar -cvf jsse-src.jar *
  6. You are done. You now have your jsse source lib that you can attach to your preferred IDE (e.g. - Eclipse) to debug the JSSE code.
  1. 转到目录结构的上方,即http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/file/4d6c03fb1039/src/share/classes/repo
  2. 单击左窗格中显示的“zip”或“gz”链接下载源包。
  3. 但是这个包很大,包含数千个 *.java 文件。您通常不希望所有这些只是调试 jsse.jar 代码。
  4. 因此,最好只将sun.security.rsasun.security.sslsun.security.providercom.sun.net.ssl包复制到您计算机上的新文件夹(比如 jsse-code)中。
  5. 从命令行转到该文件夹​​并自行创建源 jar。
    例如 jar -cvf jsse-src.jar *
  6. 你完成了。您现在拥有了 jsse 源库,您可以将其附加到首选 IDE(例如 - Eclipse)以调试 JSSE 代码。

Thanks
Ayas

由于
阿亚斯

回答by Peter

I used the OpenJDK download for Java 6:

我使用了 Java 6 的 OpenJDK 下载:

http://download.java.net/openjdk/jdk6/

http://download.java.net/openjdk/jdk6/

To debug the JSSE/SSL code, I used the classes found in the sun.security.ssland sun.security.ecpackages and created a new library. Unfortunately, just having a library with all the source wasn't enough for me. I couldn't figure out how to get my IDE (Netbeans) to step into the JSSE code. Instead, it was calling the JSSE bundled with my JDK.

为了调试 JSSE/SSL 代码,我使用了sun.security.sslsun.security.ec包中的类并创建了一个新库。不幸的是,仅仅拥有一个包含所有源代码的库对我来说是不够的。我不知道如何让我的 IDE (Netbeans) 进入 JSSE 代码。相反,它正在调用与我的 JDK 捆绑在一起的 JSSE。

As a workaround, I ended up refactoring the ssl and ec packages into a new "Provider". Here's what I did:

作为一种解决方法,我最终将 ssl 和 ec 包重构为一个新的“提供者”。这是我所做的:

  1. Renamed the SunJSSEclass to SSLProviderand replaced all references to "SunJSSE" in the code.
  2. Refactored sun.security.ssland sun.security.ecinto 2 new packages: javaxt.ssland javaxt.ec
  3. Find/Replace all references to the original package names in the code. For example, in the SSLProvider.java class, replace "sun.security.ssl.SSLContextImpl" with "javaxt.ssl.SSLContextImpl".
  1. SunJSSE类重命名为SSLProvider并替换代码中对“SunJSSE”的所有引用。
  2. sun.security.sslsun.security.ec重构为 2 个新包:javaxt.ssljavaxt.ec
  3. 在代码中查找/替换对原始包名称的所有引用。例如,在 SSLProvider.java 类中,将“sun.security.ssl.SSLContextImpl”替换为“javaxt.ssl.SSLContextImpl”。

Once I had a new security provider, I could reference it explicitly in my code. Example:

一旦我有了一个新的安全提供者,我就可以在我的代码中明确地引用它。例子:

  java.security.Provider provider = new javaxt.ssl.SSLProvider();
  java.security.Security.addProvider(provider);
  SSLContext sslc = SSLContext.getInstance("TLS", "SSLProvider");

By explicitly setting the security provider, I can now drop breakpoints and throw out print statements to my heart's content :-)

通过显式设置安全提供程序,我现在可以删除断点并将打印语句扔到我的心目中:-)

If anyone is interested, I have posted a zip archive of the "SSLProvider" source here:

如果有人感兴趣,我已经在此处发布了“SSLProvider”源的 zip 存档:

http://www.javaxt.com/download/?/jsse/SSLProvider.zip

http://www.javaxt.com/download/?/jsse/SSLProvider.zip

回答by Teocci

You can get the source code of JSSE lib (Open JDK implementation) from its mercurial repository following these steps to create a source zip file for attaching to an IDE for debugging.

您可以按照以下步骤从其 mercurial 存储库中获取 JSSE lib(Open JDK 实现)的源代码,以创建源 zip 文件以附加到 IDE 进行调试。

  1. Get your java build version (in my case the build is 1.8.0_181-b13)

    java -version
    

    Probably you will get a result like this:

    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
    
  2. Now we can find the node for our version in this the repository. In my case my tag will be jdk8u181-b13because my build is 1.8.0_181-b13and its node will be 0cb452d66676remember that the java version is jdk8u. We can download the source package by clicking on the "zip" or "gz" links that you see at the left pane and manually repack it as a zip. Or select only the packages you need.

  3. In this example I will download all the packages under the directory classes. To this end, replace the version jdk8uand node 0cb452d66676in this script to download the source code, and repack it as a srczip file.

    version=jdk8u
    node=0cb452d66676
    mkdir ~/temp
    cd ~/temp
    wget http://hg.openjdk.java.net/$version/$version/jdk/archive/$node.zip/src/share/classes/
    unzip $node.zip -d $version-$node
    cd jdk-$node/src/share/classes/
    zip -r $version-$node-src.zip .
    
  4. Add the source to your IDE and happy coding.

  1. 获取您的 Java 构建版本(在我的情况下,构建版本为 1.8.0_181-b13)

    java -version
    

    可能你会得到这样的结果:

    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
    
  2. 现在我们可以在这个存储库中找到我们版本的节点。在我的例子中,我的标签将是jdk8u181-b13因为我的构建是1.8.0_181-b13并且它的节点将是0cb452d66676记住 java 版本是jdk8u。我们可以通过单击您在左侧窗格中看到的“zip”或“gz”链接下载源包,然后手动将其重新打包为 zip。或者仅选择您需要的包。

  3. 在这个例子中,我将下载目录下的所有包classes。为此,替换本脚本中的版本jdk8u和节点 0cb452d66676下载源码,并重新打包为srczip文件。

    version=jdk8u
    node=0cb452d66676
    mkdir ~/temp
    cd ~/temp
    wget http://hg.openjdk.java.net/$version/$version/jdk/archive/$node.zip/src/share/classes/
    unzip $node.zip -d $version-$node
    cd jdk-$node/src/share/classes/
    zip -r $version-$node-src.zip .
    
  4. 将源代码添加到您的 IDE 并愉快地编码。

Notice:In this repository, the available versions are:

注意:在这个存储库中,可用的版本是:

回答by Jonathan

The Sun implementation is not open source as far as I know. You can download an open source JCE here:

据我所知,Sun 的实现不是开源的。您可以在此处下载开源 JCE:

http://www.bouncycastle.org/java.html

http://www.bouncycastle.org/java.html

回答by Dolda2000

As a matter of fact, the SSL implementation is included in the OpenJDK sources, but for some reason not in the standard source Zip file. I have no clue why.

事实上,SSL 实现包含在 OpenJDK 源代码中,但由于某种原因没有包含在标准源代码 Zip 文件中。我不知道为什么。

I don't know where one would normally fetch the OpenJDK sources; I got them on Debian via apt-get source openjdk-6. The SSL implementation sources are in jdk/src/share/classes/javax/net/ssl.

我不知道通常从哪里获取 OpenJDK 源代码;我通过apt-get source openjdk-6. SSL 实现源位于jdk/src/share/classes/javax/net/ssl.

回答by user207421

The JSSE source code for the Sun Java releases was formerly available via the Sun Community Source License Program. Since the Oracle takeover it appears to have disappeared, but I hope I'm wrong about that.

Sun Java 发行版的 JSSE 源代码以前可通过Sun Community Source License Program 获得。自从 Oracle 接管它似乎已经消失了,但我希望我错了。

回答by tkr

I ended up doing the following on Mac OS X High Sierra 10.13.4 running eclipse luna and javac 1.8.0_171

我最终在运行 eclipse luna 和 javac 1.8.0_171 的 Mac OS X High Sierra 10.13.4 上执行以下操作

On a ubuntu machine also running open jdk and javac 1.8.0_171

在同样运行 open jdk 和 javac 1.8.0_171 的 ubuntu 机器上

apt-get install openjdk-8-source

cd tmp

unzip /usr/lib/jvm/openjdk-8/src.zip "sun/security/*"

zip -r jsse-src sun 

I didn't include the com/sun/net/ssl stuff but was good enough in my case.

我没有包括 com/sun/net/ssl 的东西,但对我来说已经足够了。

I then copied jsse-src.zipto the mac at /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/and pointed eclipse to that.

然后我复制jsse-src.zip到 mac/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/并将 eclipse 指向那个。

回答by Will Sargent

Following up on this, you can download OpenJDK:

在此之后,您可以下载 OpenJDK:

https://adoptopenjdk.net/

https://adoptopenjdk.net/

and match it up exactly to the source code from

并将其与源代码完全匹配

https://github.com/AdoptOpenJDK/openjdk-jdk8u

https://github.com/AdoptOpenJDK/openjdk-jdk8u

Currently u172-b11 is the latest version, but they are in sync and will work on all platforms.

目前 u172-b11 是最新版本,但它们是同步的,适用于所有平台。