{"id":304,"date":"2013-09-10T21:39:24","date_gmt":"2013-09-10T13:39:24","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=304"},"modified":"2018-09-04T13:05:03","modified_gmt":"2018-09-04T05:05:03","slug":"self-signing-a-java-applet","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/self-signing-a-java-applet\/","title":{"rendered":"Self-signing a Java applet"},"content":{"rendered":"<p>Part of my role as a system analyst involves performing enhancement works on Java applets. Recently, the company had decided to self sign all the applets in the system so that our system infrastructure colleagues can save some time when we upgrade the Java runtime version on all our client machines.<\/p>\n<p>This post documents my process of self-signing a Java applet.<\/p>\n<h3>Generating the keystore<\/h3>\n<p>The first thing that I did was to generate the keystore. The keystore is a file that contains encryption keys for signing Java applets. I create the keystore and a key with the following command.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkeytool -genkey -keystore techcoil_research.jks -alias techcoil.com -validity 36500\r\n<\/pre>\n<p>The command can be broken down into the following pieces:<\/p>\n<ul>\n<li><strong><code>keytool<\/code><\/strong> is the command line application provided in my Java Development Kit for generating the key and the keystore. <\/li>\n<li><strong><code>-genkey<\/code><\/strong> tells <code>keytool<\/code> to generate an encryption key.<\/li>\n<li><strong><code>-keystore techcoil_research.jks<\/code><\/strong> lets <code>keytool<\/code> know that I want my keystore to be saved as <code>techcoil_research.jks<\/code> in my current working directory. The <code>.jks<\/code> extension is for me to remember that the file is a <strong>j<\/strong>ava <strong>k<\/strong>ey<strong>s<\/strong>tore. It is important to note that the keystore file cannot be renamed by other facilities - if I want a keystore with another name, I will need to use the <code>keytool<\/code> to do it.<\/li>\n<li><strong><code>-alias techcoil.com<\/code><\/strong> names my key as <a href=\"http:\/\/www.techcoil.com\" title=\"Home page for Techcoil.com\">techcoil.com<\/a> so that I can find it later.<\/li>\n<li><strong><code>-validity 36500<\/code><\/strong> allows me to use my key for 36500 days after I generate my key.<\/li>\n<\/ul>\n<p>After entering the command, the keytool asked me a few questions. The following was my interaction trace with the keytool, which was rather self-explanatory:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nEnter keystore password:\r\nRe-enter new password:\r\nWhat is your first and last name?\r\n  &#x5B;Unknown]:  Clivant Yeo\r\nWhat is the name of your organizational unit?\r\n  &#x5B;Unknown]:  Research\r\nWhat is the name of your organization?\r\n  &#x5B;Unknown]:  Techcoil\r\nWhat is the name of your City or Locality?\r\n  &#x5B;Unknown]:  Singapore\r\nWhat is the name of your State or Province?\r\n  &#x5B;Unknown]:  Singapore\r\nWhat is the two-letter country code for this unit?\r\n  &#x5B;Unknown]:  SG\r\nIs CN=Clivant Yeo, OU=Research, O=Techcoil, L=Singapore, ST=Singapore, C=SG corr\r\nect?\r\n  &#x5B;no]:  yes\r\n\r\nEnter key password for &lt;techcoil.com&gt;;\r\n        (RETURN if same as keystore password):\r\n\r\n<\/pre>\n<h2>Signing the Java applet<\/h2>\n<p>With the keystore on hand, I then proceed to sign the <a href=\"http:\/\/www.techcoil.com\/blog\/how-to-send-message-from-java-applet-to-web-page-via-jquery\/\" title=\"How to send message from Java applet to web page via jQuery\" target=\"_blank\">MessageSendingApplet<\/a> with the <code>jarsigner<\/code> tool:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\njarsigner -keystore techcoil_research.jks MessageSendingApplet.jar techcoil.com\r\n<\/pre>\n<p>The command can be broken down into the following pieces:<\/p>\n<ul>\n<li><strong><code>jarsigner<\/code><\/strong> is a tool from the Java Development Kit that I can use for signing a Java archive.<\/li>\n<li><strong><code>-keystore techcoil_research.jks<\/code><\/strong> tells <code>jarsigner<\/code> to use the keystore file that I had generated in the working directory to look for the key to sign the jar file.<\/li>\n<li><strong><code>MessageSendingApplet.jar<\/code><\/strong> is the java archive file that I wish to sign, which in this case, a Java applet from a <a href=\"http:\/\/www.techcoil.com\/proof-of-concepts\" title=\"Listing of proof of concepts at Techcoil.com\">proof of concept<\/a>.<\/li>\n<li><strong><code>techcoil.com<\/code><\/strong> is the key which I want <code>jarsigner<\/code> to use to sign my Java applet.<\/li>\n<\/ul>\n<p>Upon entering the command, the <code>jarsigner<\/code> asked me for the password to the keystore:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nEnter Passphrase for keystore:\r\n<\/pre>\n<p>And since I had earlier indicated that my <a href=\"http:\/\/www.techcoil.com\" title=\"Home page for techcoil.com\">techcoil.com<\/a> key had the same password as the keystore, the <code>jarsigner<\/code> did not ask for the password for the key.<\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-4U\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-4U&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-4U&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F304&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>Part of my role as a system analyst involves performing enhancement works on Java applets. Recently, the company had decided to self sign all the applets in the system so that our system infrastructure colleagues can save some time when we upgrade the Java runtime version on all our client machines.<\/p>\n<p>This post documents my process of self-signing a Java applet.<\/p>\n","protected":false},"author":1,"featured_media":1220,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[164,6,162,165,163],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Java-logo.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-4U","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/304"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=304"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/304\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1220"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}