你如何签署Java Midlet?
一个简单的问题和一个相当复杂的答案:
如何对 Java Midlet 进行签名,以便将其加载到手机上,同时减少安全提示?
一个简单的问题和一个相当复杂的答案:
如何对 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
将证书添加到 JAD.jar来自 WTKjava -jar JadTool.jar -addcert -alias {myalias} -storepass {mypassword} -keystore {mykeystore} -inputjad {myinputjad} -outputjad {myoutputjad}
JAD.jar
java -jar JadTool.jar -addjarsig -alias {myalias} -jarfile {myjar} -storepass {mypassword} -keypass {mypassword} -keystore {mykeystore} -inputjad {myinputjad} -outputjad {myoutputjad}
部署
在手机上安装证书
常见问题
MIDlet-Permissions
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=
示例清单
Manifest-Version: 1.0 MIDlet-Name: MyApp Created-By: 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-Configuration: CLDC-1.1 Ant-Version: Apache Ant 1.6.2 MIDlet-Icon: logo.png MIDlet-Vendor: EC1M MIDlet-Permissions: javax.microedition... MIDlet-Version: 1.0.67 MicroEdition-Profile: MIDP-2.0 MIDlet-Description: MyApp MIDlet
示例蚂蚁构建文件我已经把我们的 EC1M 蚂蚁构建文件放在我们的网站上,(希望)让这一切变得更容易一些。其他资源诺基亚论坛上的此常见问题解答值得一读。
步骤 1:创建 CSR 请求,该请求可能由
1) Creating keystore and using that generate CSR file.
2) Perform steps given by certificate authority and download CSR and private key files.
第 2 步:将您的信息提供给证书颁发机构进行验证。
Step3:您将获得用于代码签名的证书。
Step4:您需要将中间证书与根证书一起下载。
Step5:现在您将拥有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.
步骤6:将私钥导入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 )
步骤 7:从 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
步骤9:注意:在触发以下命令之前,请备份您的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