java - Jar 文件在签名之前一直有效(在 Windows 中)

标签 java jar code-signing jar-signing jarsigner

首先我要声明我不是 Java 程序员,我是 PHP 程序员。

我遇到了 websockets 无法解决问题的情况,我发现这个网站提供了解决方案:

http://stephengware.com/proj/javasocketbridge/

它基本上是一个 Jar,您可以将其加载并使用 JavaScript 进行控制。它工作得很好,我强烈推荐给任何需要类似功能的人。但是,由于 Jar 未签名,每次加载页面时,它都会显示安全警告。这有点烦人,我认为如果我对 Jar 进行 self 签名,它将启用“不再向我展示”/“永远允许”复选框。这将在我们的组织内部部署,因此似乎没有必要使用付费证书对其进行签名。

问题是,一旦我对 Jar 进行签名,它就不起作用了。我收到一个找不到类的错误。我查看了数十个向您展示如何签署 Jar 文件的网站,并用谷歌搜索到第 10 页,但我找不到任何遇到此类问题的网站。

我将包括我认为需要的部分,如果您需要其他东西,请告诉我,我会得到它。

小程序代码:

<applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="400" height="30"></applet>

我是如何签署 Jar 的(在管理员命令提示符下):

C:\Program Files\Java\jdk1.7.0_07\bin>keytool -genkey -keyalg rsa -alias crtlive
Enter keystore password:
What is your first and last name?
  [Unknown]:  first last
What is the name of your organizational unit?
  [Unknown]:  Tech
What is the name of your organization?
  [Unknown]:  ourorg
What is the name of your City or Locality?
  [Unknown]:  city
What is the name of your State or Province?
  [Unknown]:  ST
What is the two-letter country code for this unit?
  [Unknown]:  US
Is CN=first last, OU=Tech, O=ourorg, L=city, ST=ST, C=US correct?
  [no]:  yes

Enter key password for <crtlive>
        (RETURN if same as keystore password):

C:\Program Files\Java\jdk1.7.0_07\bin>keytool -export -alias crtlive -file crtlive
.crt
Enter keystore password:
Certificate stored in file <crtlive.crt>

C:\Program Files\Java\jdk1.7.0_07\bin>jarsigner JavaSocketBridge.jar crtlive
Enter Passphrase for keystore:

Warning:
The signer certificate will expire within six months.

C:\Program Files\Java\jdk1.7.0_07\bin>keytool -export -alias crtlive -rfc -file s
ig.x509
Enter keystore password:
Certificate stored in file <sig.x509>

C:\Program Files\Java\jdk1.7.0_07\bin>

我打开了未签名和已签名的 Jar,源文件是相同的,在已签名的 Jar 的 META-INF 文件夹中只有两个附加文件:CRTLIVE.RSA 和 CRTLIVE.SF。

这是线程转储:

Dump thread list ...
Group main,ac=18,agc=4,pri=10
    main,5,alive
    traceMsgQueueThread,5,alive,daemon
    Timer-0,5,alive
    Java Plug-In Pipe Worker Thread (Client-Side),5,alive,daemon
    AWT-Windows,6,alive,daemon
    SysExecutionTheadCreator,5,alive,daemon
    CacheMemoryCleanUpThread,5,alive,daemon
    CacheCleanUpThread,5,alive,daemon
    Browser Side Object Cleanup Thread,5,alive
    JVM[id=4]-Heartbeat,5,alive,daemon
    AWT-Shutdown,5,alive
    AWT-EventQueue-0,6,alive
Group Plugin Thread Group,ac=2,agc=0,pri=10
    AWT-EventQueue-1,6,alive
    TimerQueue,5,alive,daemon
Group http://www.example.com/admin/-threadGroup,ac=0,agc=0,pri=4,destoyed
Group http://www.example.com/admin/-threadGroup,ac=0,agc=0,pri=4,destoyed
Group http://www.example.com/admin/-threadGroup,ac=4,agc=0,pri=4
    Applet 49 LiveConnect Worker Thread,4,alive
    AWT-EventQueue-23,4,alive
    TimerQueue,4,alive,daemon
    ConsoleTraceListener,4,alive,daemon
Done.

线程堆栈在长边,但这里是:

Full thread dump Java HotSpot(TM) Client VM (23.3-b01 mixed mode, sharing):

"TimerQueue" daemon prio=6 tid=0x04d55800 nid=0x1f28 waiting on condition [0x0ac7f000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x24820770> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(Unknown Source)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
    at java.util.concurrent.DelayQueue.take(Unknown Source)
    at javax.swing.TimerQueue.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

"ConsoleTraceListener" daemon prio=4 tid=0x04e12400 nid=0x2c14 runnable [0x09d7f000]
   java.lang.Thread.State: RUNNABLE
    at java.lang.Object.wait(Native Method)
    at java.lang.Thread.join(Unknown Source)
    - locked <0x244218e0> (a sun.plugin.util.PluginSysUtil$SysExecutionThread)
    at java.lang.Thread.join(Unknown Source)
    at sun.plugin.util.PluginSysUtil.execute(Unknown Source)
    at sun.plugin.util.PluginSysUtil.execute(Unknown Source)
    at sun.plugin.util.PluginSysUtil.delegate(Unknown Source)
    at com.sun.deploy.util.DeploySysRun.execute(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.ui.SwingConsoleWindow.invokeLater(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.ui.SwingConsoleWindow.append(Unknown Source)
    at com.sun.deploy.uitoolkit.ui.ConsoleTraceListener$ConsoleWriterThread.run(Unknown Source)

"AWT-EventQueue-1" prio=6 tid=0x04e37400 nid=0x338 waiting on condition [0x0a10e000]
   java.lang.Thread.State: RUNNABLE
    at com.sun.deploy.uitoolkit.ui.ConsoleHelper.dumpAllStacksImpl(Native Method)
    at com.sun.deploy.uitoolkit.ui.ConsoleHelper.dumpAllStacks(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.ui.SwingConsoleWindow$3.actionPerformed(Unknown Source)
    at javax.swing.JComponent$ActionStandin.actionPerformed(Unknown Source)
    at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    at javax.swing.JComponent.processKeyBinding(Unknown Source)
    at javax.swing.KeyboardManager.fireBinding(Unknown Source)
    at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
    at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
    at javax.swing.JComponent.processKeyBindings(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

"TimerQueue" daemon prio=4 tid=0x04e11c00 nid=0x1f7c waiting on condition [0x0940f000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x24820e00> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(Unknown Source)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
    at java.util.concurrent.DelayQueue.take(Unknown Source)
    at javax.swing.TimerQueue.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

"AWT-EventQueue-23" prio=4 tid=0x04e32c00 nid=0x31d8 waiting on condition [0x09e5f000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x29e3a6b8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(Unknown Source)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
    at java.awt.EventQueue.getNextEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

"Applet 49 LiveConnect Worker Thread" prio=4 tid=0x04de8c00 nid=0x2e88 in Object.wait() [0x09c6f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
    - locked <0x29e3a798> (a java.lang.Object)
    at java.lang.Thread.run(Unknown Source)

"AWT-EventQueue-0" prio=6 tid=0x04de8800 nid=0x1038 waiting on condition [0x0977f000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x2998d388> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(Unknown Source)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
    at java.awt.EventQueue.getNextEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

"AWT-Shutdown" prio=6 tid=0x04d56000 nid=0x37f8 in Object.wait() [0x07cdf000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at sun.awt.AWTAutoShutdown.run(Unknown Source)
    - locked <0x2998d4f0> (a java.lang.Object)
    at java.lang.Thread.run(Unknown Source)

"D3D Screen Updater" daemon prio=8 tid=0x04e35800 nid=0x674 in Object.wait() [0x0963f000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at sun.java2d.d3d.D3DScreenUpdateManager.run(Unknown Source)
    - locked <0x2998cdf0> (a java.lang.Object)
    at java.lang.Thread.run(Unknown Source)

"JVM[id=4]-Heartbeat" daemon prio=6 tid=0x04e33800 nid=0x2578 in Object.wait() [0x054df000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at sun.plugin2.main.server.HeartbeatThread.run(Unknown Source)
    - locked <0x2998d010> (a sun.plugin2.main.client.PluginMain$Heartbeat)

"Browser Side Object Cleanup Thread" prio=6 tid=0x04e32400 nid=0x1834 in Object.wait() [0x07f1f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x2998d180> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    - locked <0x2998d180> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    at sun.plugin2.main.client.LiveConnectSupport$BrowserSideObjectCleanupThread.run(Unknown Source)

"CacheCleanUpThread" daemon prio=6 tid=0x04e28000 nid=0x2208 in Object.wait() [0x07b5f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at com.sun.deploy.cache.CleanupThread.run(Unknown Source)
    - locked <0x2998d1a0> (a com.sun.deploy.cache.CleanupThread)

"CacheMemoryCleanUpThread" daemon prio=6 tid=0x04e21000 nid=0x3484 in Object.wait() [0x0735f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x2998d290> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    - locked <0x2998d290> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    at com.sun.deploy.cache.MemoryCache$LoadedResourceCleanupThread.run(Unknown Source)

"SysExecutionTheadCreator" daemon prio=6 tid=0x04dd8400 nid=0x2f40 in Object.wait() [0x07e8f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at sun.plugin.util.PluginSysUtil$SysExecutionThreadCreator.run(Unknown Source)
    - locked <0x2998d2b0> (a sun.plugin.util.PluginSysUtil$SysExecutionThreadCreator)

"AWT-Windows" daemon prio=6 tid=0x04dabc00 nid=0x1eb4 runnable [0x00daf000]
   java.lang.Thread.State: RUNNABLE
    at sun.awt.windows.WToolkit.eventLoop(Native Method)
    at sun.awt.windows.WToolkit.run(Unknown Source)

"Java2D Disposer" daemon prio=10 tid=0x04da0c00 nid=0x3014 in Object.wait() [0x057cf000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    - locked <0x2998d580> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    at sun.java2d.Disposer.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

"Java Plug-In Pipe Worker Thread (Client-Side)" daemon prio=6 tid=0x04d99000 nid=0x1e74 runnable [0x058df000]
   java.lang.Thread.State: RUNNABLE
    at sun.plugin2.os.windows.Windows.ReadFile0(Native Method)
    at sun.plugin2.os.windows.Windows.ReadFile(Unknown Source)
    at sun.plugin2.ipc.windows.WindowsNamedPipe.read(Unknown Source)
    at sun.plugin2.message.transport.NamedPipeTransport$SerializerImpl.read(Unknown Source)
    at sun.plugin2.message.transport.NamedPipeTransport$SerializerImpl.readByte(Unknown Source)
    at sun.plugin2.message.AbstractSerializer.readInt(Unknown Source)
    at sun.plugin2.message.transport.SerializingTransport.read(Unknown Source)
    at sun.plugin2.message.Pipe$WorkerThread.run(Unknown Source)

"Timer-0" prio=6 tid=0x04d75800 nid=0x1438 in Object.wait() [0x0517f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x2998d8c0> (a java.util.TaskQueue)
    at java.lang.Object.wait(Object.java:503)
    at java.util.TimerThread.mainLoop(Unknown Source)
    - locked <0x2998d8c0> (a java.util.TaskQueue)
    at java.util.TimerThread.run(Unknown Source)

"traceMsgQueueThread" daemon prio=6 tid=0x04cce800 nid=0x2aec in Object.wait() [0x04b0f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at com.sun.deploy.trace.Trace$TraceMsgQueueChecker.run(Unknown Source)
    - locked <0x298b6d28> (a java.util.ArrayList)
    at java.lang.Thread.run(Unknown Source)

"Service Thread" daemon prio=6 tid=0x00b14400 nid=0x2804 runnable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread0" daemon prio=10 tid=0x00b0fc00 nid=0x1ff4 waiting on condition [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Attach Listener" daemon prio=10 tid=0x00b0e800 nid=0x1980 runnable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x00b0b400 nid=0x21bc runnable [0x00000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=8 tid=0x00ae4000 nid=0x2df0 in Object.wait() [0x047df000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    - locked <0x2998db48> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)

"Reference Handler" daemon prio=10 tid=0x00ae2800 nid=0xc0c in Object.wait() [0x0485f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
    - locked <0x2998cd80> (a java.lang.ref.Reference$Lock)

"main" prio=6 tid=0x003ddc00 nid=0x2fa0 in Object.wait() [0x0098f000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at sun.plugin2.message.Queue.waitForMessage(Unknown Source)
    - locked <0x2998dbd0> (a sun.plugin2.message.Queue)
    at sun.plugin2.message.Pipe$1.run(Unknown Source)
    at com.sun.deploy.util.Waiter$1.wait(Unknown Source)
    at com.sun.deploy.util.Waiter.runAndWait(Unknown Source)
    at sun.plugin2.message.Pipe.receive(Unknown Source)
    at sun.plugin2.main.client.PluginMain.mainLoop(Unknown Source)
    at sun.plugin2.main.client.PluginMain.run(Unknown Source)
    at sun.plugin2.main.client.PluginMain.main(Unknown Source)

"VM Thread" prio=10 tid=0x00ae1000 nid=0x23f4 runnable 

"VM Periodic Task Thread" prio=10 tid=0x00b2fc00 nid=0x32b8 waiting on condition 

lugin2.main.client.PluginMain.run(Unknown Source)
    at sun.plugin2.main.client.PluginMain.main(Unknown Source)

"VM Thread" prio=10 tid=0x00ae1000 nid=0x23f4 runnable 

"VM Periodic Task Thread" prio=10 tid=0x00b2fc00 nid=0x32b8 waiting on condition 


----------------------------------------------------
Done.

我已经用谷歌搜索了我能想到的所有内容,我们将不胜感激。

谢谢!

最佳答案

当我们将 java web start 产品从 java 6 迁移到 java 7 时,我们发现 java 7 不会让我们之前自签名的 jar 文件运行。

我们发现 java 7 不接受我们创建的 Root CA。一旦我们使用了受信任的根 CA,问题就消失了。

现在,或许可以找到解决此问题的方法。我建议调查一下(搜索 keytool):http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html

具体来说:

领域:工具 概要:提供了一个新的 keytool 命令 (-gencert) 来生成非自签名证书。提供了一个新选项 (-ext) 来为 -gencert、-genkeypair 和 -certreq 命令生成多个 X.509 v3 扩展。 keytool 和 jarsigner 工具还有其他新命令和选项。有关详细信息,请参阅 keytool 和 jarsigner 工具文档。 RFE: 6780416, 6802846, 6324292, 6890872

RFE 包含指向可能对您有帮助的信息的链接。

关于java - Jar 文件在签名之前一直有效(在 Windows 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12788192/

相关文章:

cmake - 使用 cmake + cpack 构建时如何签署 Windows 二进制文件和 NSIS 安装程序

java - 如何使 Ant 任务对我的所有 JAR 文件进行签名和打包?

android - 备份用于在 Eclipse 中签署 Android 应用程序的签名 key

java - 有什么方法可以检查给定的类类型是属于 Java 对象还是自定义对象

java - 如何执行java应用程序(.exe/.jar/.bat)而不显示弹出控制台?

java - 当我 JAR 我的程序时,Java 将资源文件放在哪里?

java - 我如何知道哪个项目正在从 Maven 请求特定的 jar

java - 读取文件并根据该行的内容执行功能

java - 使用缓冲区将字符串转换为 UTF-8

java - 如何了解在 Mac 上双击 .jar 文件时会发生什么情况?