【发布时间】:2010-11-25 21:47:20
【问题描述】:
一个简单的问题,一个相当复杂的答案:
如何对 Java Midlet 进行签名,以便将其加载到安全提示较少的手机上?
【问题讨论】:
-
+1: 我在找这样的东西(+: N00b to J2ME
一个简单的问题,一个相当复杂的答案:
如何对 Java Midlet 进行签名,以便将其加载到安全提示较少的手机上?
【问题讨论】:
获取所需软件
导入现有证书(如果有)
keytool -import -alias {myalias} -file {mycertificate}(由于我没有适当的证书,因此无法测试)keytool -list 以查看您的新证书keytool -export -alias {myalias} -file mycertificate.crt
创建并导入新的(测试)证书
keytool -genkey -alias {myalias} -keyalg RSA -validity 365
keytool -list 以查看您的新证书keytool -export -alias {myalias} -file mycertificate.crt
C:\j2sdk1.4.2_08\bin>keytool -genkey -alias company -keyalg RSA -validity 365
Enter keystore password: password
What is your first and last name? [Unknown]: My Name
What is the name of your organizational unit? [Unknown]: company
What is the name of your organization? [Unknown]: company
What is the name of your City or Locality? [Unknown]: location
What is the name of your State or Province? [Unknown]: location2
What is the two-letter country code for this unit? [Unknown]: GB
Is CN=My Name, OU=company, O=company, L=location, ST=location2, C=GB correct? [no]: yes
Enter key password for (RETURN if same as keystore password):
构建并打包应用程序
javac 构建您的MIDlet,特别注意您的类路径和引导类路径选项(否则预验证将失败)。我还将目标设置为 1.1,源设置为 1.3MIDlet-Jar-URL
签署申请
jarsigner 签署应用程序
jarsigner -keystore {mykeystore} -storepass (mypassword} {myjar} {myalias}
MIDlet-Jar-Size
JadTool.jar 将证书添加到 JADjava -jar JadTool.jar -addcert -alias {myalias} -storepass {mypassword} -keystore {mykeystore} -inputjad {myinputjad} -outputjad {myoutputjad}
JadTool.jar 再次将签名添加到 JAD
java -jar JadTool.jar -addjarsig -alias {myalias} -jarfile {myjar} -storepass {mypassword} -keypass {mypassword} -keystore {mykeystore} -inputjad {myinputjad} -outputjad {myoutputjad}
部署
在手机上安装证书
常见问题
MIDlet-Permissions 中的换行符会导致问题,但在诺基亚 6680/6630/6230i 上对我来说似乎没问题(可能取决于固件?)MIDlet-Permissions 属性是导致很多问题的原因(尤其是因为文档经常错误/缺失或因手机而异),请尝试先将其保留,然后一次添加一个权限。有些手机会抱怨他们不支持的权限,有些会忽略它们信任域
未解决的问题
JAD 示例
MIDlet-Jar-URL: MyApp.jar
MIDlet-Jar-Size: 201365
MIDlet-Name: MyApp
MIDlet-Vendor: EC1M
MicroEdition-Profile: MIDP-2.0
MicroEdition-Configuration: CLDC-1.1
MIDlet-Icon: logo.png
MIDlet-Push-1: sms://:6553,net.ec1m.MyApp.midp.MyAppMIDlet,*
MIDlet-Description: MyApp MIDlet
MIDlet-Permissions: javax.microedition.io.PushRegistry,javax.microedition.io.Connector.sms...
MIDlet-Version: 1.0.67 MIDlet-1: MyApp, logo.png,net.ec1m.MyApp.midp.MyAppMIDlet
MIDlet-Certificate-1-1: MIICODCCAaECBEKqpfswDQYJKoZIhvcNAQEEBQAwYz...=
MIDlet-Jar-RSA-SHA1: EUsAch/.../hEZOsJsiCjBOhNs/3FSw4=
样品清单
清单版本:1.0 MIDlet 名称:MyApp 创建者:1.4.2_05-b04(Sun Microsystems Inc.) MIDlet-Push-1: sms://:6553,net.ec1m.MyApp.midp.MyAppMIDlet,* MIDlet-1:MyApp、logo.png、net.ec1m.MyApp.midp.MyAppMIDlet MicroEdition-配置:CLDC-1.1 Ant 版本:Apache Ant 1.6.2 MIDlet 图标:logo.png MIDlet-供应商:EC1M MIDlet 权限:javax.microedition... MIDlet 版本:1.0.67 微版配置文件:MIDP-2.0 MIDlet 描述:MyApp MIDlet
示例 Ant 构建文件 我已经把我们的EC1Mant build file 放在我们的网站上,以(希望)让这一切对你来说更容易一些。 其他资源 这个FAQ on the Nokia Forum 值得一读。
【讨论】:
Nokia Asha 302) 上安装了证书,但是当我转到 Certificate Management 时,Applications Signing 选项是灰色的,所以当我尝试打开时收到错误 Certificate not on device or SIM它。我该如何启用它?我很绝望!我正在尝试签署一个自制的应用程序 2 天,但我无法让它工作! :(
第一步: 创建可能由
提出的 CSR 请求1) Creating keystore and using that generate CSR file.
2) Perform steps given by certificate authority and download CSR and private key files.
第二步: 将您的信息提供给证书颁发机构进行验证。
第三步: 将为您提供代码签名证书。
第四步: 您需要下载中间证书和根证书。
第五步: 现在您将拥有 your_domain_name.crt、IntCertCA.crt、TrustedRoot.crt
Now you need to create a chained certificate by combining all above certificates.
1) Open a text editor (such as wordpad) and paste the entire body of each certificate into one text file in the following order:
The Primary Certificate - your_domain_name.crt
The Intermediate Certificate - IntCertCA.crt
The Root Certificate - TrustedRoot.crt
Make sure to include the beginning and end tags on each certificate. The result should look like this:
-----BEGIN CERTIFICATE-----
(Your Primary SSL certificate: your_domain_name.crt)
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
(Your Intermediate certificate: IntCertCA.crt)
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
(Your Root certificate: TrustedRoot.crt)
-----END CERTIFICATE-----
Save the combined file as your_domain_name.pem. The .pem file is now ready to use.
第六步: 将私钥导入 your_domain_name.pem
openssl pkcs12 -export -in your_domain_name.pem -inkey your_private_key.key -out output_file_name.p12 -name your_alias
NOTE: PLEASE REMOVE \ FROM FOLLOWING COMMANDS AND EXECUTE ( \ IS BASICALLY COMMAND CONTINUETY )
第七步: 从 output_file_name.p12 创建密钥库
keytool -importkeystore \
-deststorepass changeit -destkeypass changeit -destkeystore your_domain_keystore.ks \
-srckeystore output_file_name.p12 -srcstoretype PKCS12 -srcstorepass your_store_password \
-alias your_alias
第8步: 注意:请在触发以下命令之前备份您的 JAD 文件。
Add your certificates to your your_midlet_name.jad file.
java -jar JadTool.jar -addcert -alias your_alias \
-storepass your_store_password \
-keystore your_domain_keystore.ks \
-inputjad your_midlet_name.jad -outputjad your_midlet_name.jad
第九步: 注意:请在触发以下命令之前备份您的 JAD 文件。
Sign your midlet, also use your_midlet_name.jad file generated from Step8.
java -jar JadTool.jar -addjarsig \
-alias your_store_password \
-storepass your_store_password \
-keypass your_store_password \
-keystore your_domain_keystore.ks \
-inputjad your_midlet_name.jad -outputjad your_midlet_name.jad
【讨论】: