<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>keytool on Digi Hunch</title><link>https://static.digihunch.com/tag/keytool/</link><description>Recent content in keytool on Digi Hunch</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Sat, 20 Jul 2024 18:37:35 -0400</lastBuildDate><atom:link href="https://static.digihunch.com/tag/keytool/index.xml" rel="self" type="application/rss+xml"/><item><title>Public Key Infrastructure (PKI) – Introduction</title><link>https://static.digihunch.com/2021/04/public-key-infrastructure-pki/</link><pubDate>Thu, 08 Apr 2021 22:07:00 -0400</pubDate><guid>https://static.digihunch.com/2021/04/public-key-infrastructure-pki/</guid><description>&lt;p class="wp-block-paragraph"&gt;A public-key infrastructure (PKI) is a set of roles, policies, hardware, software and procedures needed to create, manage, distribute, use, store and revoke digital certificates and manage public-key encryption. The algorithms are based on Publick-key cryptography. The format of the digital certificate is defined in X.509 standard.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Certificate Authority&lt;/strong&gt; &amp;#8211; CA digitally signs and publishes the public key to user. Website requesting certificates start with a key pair. It then converts public key into CSR (certificate signing request), including the identity. Once the identity of requestor is validated, CA will sign the public key of requestor, using its own private key. The output of this is the certificate.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Registration Authority&lt;/strong&gt; &amp;#8211; CA may delegate some roles to registration authority (RA). RA is responsible for accepting requests for certificates and authenticating the entity making the request. However, RAs do not have the signing authority of a CA. Note that Microsoft may have referred to a subordinate CA as an RA, which is incorrect according to X.509 PKI standards.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-validation-types"&gt;Validation types&lt;/h3&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Domain Validation: domain ownerships is usually verified via DNS record.&lt;/li&gt;&#10;&lt;li&gt;Organization Validation: the organization name and address are verified and put into the certificate.&lt;/li&gt;&#10;&lt;li&gt;Extended Validation: verifies existence and location of the legal entity, as well as domain ownership. EV cannot be issued as a wildcard certificate.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 class="wp-block-heading" id="h-private-certificate-authorities"&gt;Private Certificate Authorities&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;You can create private CA and use it to sign certificates. Your user need to manually install and trust your private CA so that all certificates issued from the CA will inherit that trust. For revocation, you will also need to maintain an HTTP server for the certificate revocation list, or an OCSP responder.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-certificate-revocation-list-crl"&gt;Certificate Revocation List (CRL)&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;SSL certificates include information on how to access a certificate revocation list. Client will download and check this list to make sure the certificate has not been revoked. This mechanism has largely been replaced by OCSP responders.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-online-certificate-status-protocol-ocsp"&gt;Online Certificate Status Protocol (OCSP)&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The OCSP protocol is a replacement for CRLs, with the benefit of being more real-time and requiring less bandwidth. The general operation is similar: clients are to query to OCSP responder to check if a certificate has been revoked.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-commercial-vs-non-profit-ca"&gt;Commercial vs non-profit CA&lt;/h3&gt;&#10;&lt;figure class="wp-block-table is-style-stripes"&gt;&lt;table class="has-background" style="background-color:#e7f5fe"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Commercial (e.g. SSLs.com)&lt;/td&gt;&lt;td&gt;Non-profit (e.g. Let&amp;#8217;s Encrypt)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Validation&lt;/td&gt;&lt;td&gt;DV, OV and EV&lt;/td&gt;&lt;td&gt;DV only&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Wildcard&lt;/td&gt;&lt;td&gt;Supported&lt;/td&gt;&lt;td&gt;Supported (using DNS-01 challenge via ACME v2)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Cost&lt;/td&gt;&lt;td&gt;Not Free&lt;/td&gt;&lt;td&gt;Free&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Expiration&lt;/td&gt;&lt;td&gt;1-3 years&lt;/td&gt;&lt;td&gt;90 days&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;&#10;&lt;h3 class="wp-block-heading" id="h-acme-protocol"&gt;ACME protocol&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Traditionally, there are several command-line utilities such as openssl, cfssl, or keytool (Java) to manage certificate related tasks. The process are mostly manual. The Internet Security Research Group (ISRG) developed the ACME (Automated Certificate management Environment) protocol.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In this protocol, there is a certificate management agent (client) on the given web server. The agent generates a key pair and shares it with the CA at the outset of the validation process. Once validation is finished and the agent is verified as the proven owner of the key pair. It can use its key to digitally sign the CSRs it generates and sends to the CA via HTTPS requests. The CA uses the CSR, along with its associated public key, to issue the certificate and send it back to the agent. The agent downloads and installs it, then notifies the designated contact.&amp;nbsp;The agent can be automated to check in with the CA at given intervals to rotate certificates and keys.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Let&amp;#8217;s encrypt adopts ACME protocol by using &lt;a class="rank-math-link" href="https://github.com/letsencrypt/boulder"&gt;Boulder&lt;/a&gt; on the server side, and the most commonly used client is &lt;a class="rank-math-link" href="https://github.com/certbot/certbot"&gt;certbot&lt;/a&gt;. Smallstep also introduced ACME support in step CA in 2019.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading"&gt;Lets Encrypt&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;I have used let&amp;#8217;s encrypt several times because it is free and easy to manage with &lt;strong&gt;certbot&lt;/strong&gt;, which can be installed using &lt;code&gt;brew&lt;/code&gt; on Mac. Here&amp;#8217;s how I quickly generate certificate manually:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;DOMAIN&lt;span style="color:#f92672"&gt;=&lt;/span&gt;orthwebdemo.digihunch.com&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo $DOMAIN&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sudo certbot -d $DOMAIN --manual --preferred-challenges dns certonly&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# get ready to change txt record&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ls /etc/letsencrypt/live/orthwebdemo.digihunch.com/&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p class="wp-block-paragraph"&gt;The &lt;code&gt;--manual&lt;/code&gt; switch starts interactive prompts, which includes configuring TXT record and wait for the update.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-open-source-implementations"&gt;Open source implementations&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Here is a list of open-source implementations of PKI management:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;a href="https://wiki.openssl.org/index.php/Main_Page" class="rank-math-link"&gt;OpenSSL&lt;/a&gt;: classic tool for PKI management. The Mac/BSD implementation and GNU implementation are slightly different.&lt;/li&gt;&#10;&lt;li&gt;Keytool: Java&amp;#8217;s Key and Certificate Management Tool that supports formats used in &lt;a href="https://docs.oracle.com/javase/6/docs/technotes/tools/solaris/keytool.html" class="rank-math-link"&gt;Java&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;Cfssl: introduced by &lt;a href="https://blog.cloudflare.com/introducing-cfssl/" class="rank-math-link"&gt;CloudFlare&lt;/a&gt; to simplify the &lt;a href="https://blog.cloudflare.com/how-to-build-your-own-public-key-infrastructure/" class="rank-math-link"&gt;PKI management&lt;/a&gt; process. On Ubuntu, the apt package name is golang-cfssl&lt;/li&gt;&#10;&lt;li&gt;Hashicorp Vault: CA, secret management and encryption.&lt;/li&gt;&#10;&lt;li&gt;Boulder: implemented in Go based on ACME protocol. Let&amp;#8217;s Encrypt uses Boulder on the server side. &lt;/li&gt;&#10;&lt;li&gt;EJBCA: a full-featured, enterprise-grade implementation in Java, managed by Swedish company PrimeKey Solutions AB.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 class="wp-block-heading" id="h-managed-ca-as-service"&gt;Managed CA as service&lt;/h3&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;AWS Certificate Manager: [Update] as of Sep 2022, the managed CA capability was spun off as a new service called &lt;a href="https://aws.amazon.com/about-aws/whats-new/2022/09/aws-certificate-manager-private-certificate-authority-now-aws-private-ca/"&gt;AWS Private Certificate Authority&lt;/a&gt;, to distinguish from the certificate management capability. &lt;/li&gt;&#10;&lt;li&gt;EJBCA Enterprise, as Azure Market place&lt;/li&gt;&#10;&lt;li&gt;Google Cloud Certificate Authority Service API&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://static.digihunch.com/2021/03/intro-to-data-analytics-platform/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Intro to Data Analytics Platform on Azure&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://static.digihunch.com/2021/04/preparing-certified-kubernetes-administrator-exam/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Certified Kubernetes Administrator (CKA) Exam&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Cryptography basics 2 of 2</title><link>https://static.digihunch.com/2019/09/cryptographic-concepts-for-busy-it-professionals-2-of-2/</link><pubDate>Sun, 08 Sep 2019 21:21:41 -0400</pubDate><guid>https://static.digihunch.com/2019/09/cryptographic-concepts-for-busy-it-professionals-2-of-2/</guid><description>&lt;p class="wp-block-paragraph"&gt;My previous &lt;a href="https://static.digihunch.com/2019/07/practical-cryptography-for-it-professional/"&gt;post&lt;/a&gt; outlines several core concepts around cryptography, such as asymmetric key encryption, digital certificate, the encoding formats and relevant file extensions. In this article, we continue to explore cryptography use cases, where these concepts are connected and put into application.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The most important use case is TLS handshake. I cannot stress enough how paramount this scenario is. This use case and its variation can be found in almost every situation where connection needs to be secured.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;TLS handshake&lt;/strong&gt;: the process in which client and server establish secure connection. During the handshake, two parties agree on TLS version, decide on cipher suite, authenticate the identity of each other (although client identity authentication is less common), and generate session key for symmetric encryption after the handshake. Details steps are very important. &lt;a href="https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.1.0/com.ibm.mq.doc/sy10660_.htm"&gt;Here&lt;/a&gt; is a fairly thorough reference, and here is a great diagram:&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img loading="lazy" decoding="async" width="1496" height="792" src="https://static.digihunch.com/wp-content/uploads/2019/10/TLS.png" alt="" class="wp-image-152"/&gt;&lt;figcaption class="wp-element-caption"&gt;TLS handshake&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Secure browser connection&lt;/strong&gt;: The most widespread use of TLS handshake is to secure browser connection with HTTPS:&lt;/p&gt;&#10;&lt;ol class="wp-block-list"&gt;&#10;&lt;li&gt;Browser initiates connection to the server;&lt;/li&gt;&#10;&lt;li&gt;Server sends browser its certificate (public key + digital signature signed by CA);&lt;/li&gt;&#10;&lt;li&gt;Browser has preloaded public key of CA and uses it to decrypt digital signature and get the digest of public key;&amp;nbsp;&lt;/li&gt;&#10;&lt;li&gt;Browser calculate digest of received public key and compares it against the digest from the previous step;&lt;/li&gt;&#10;&lt;li&gt;If the result is the same, public key is trusted, a green lock is displayed; otherwise, a warning is displayed;&lt;/li&gt;&#10;&lt;li&gt;proceed to the rest of the steps in TLS handshake.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Secure connection in Java&lt;/strong&gt;: Java applications manages keys and certificates through two classes: java.security.KeyStore and java.security.TrustStore. Suppose a Java application client initiates TLS connection to server. The server application will present its certificates from server&amp;#8217;s Key Store. The client will use certificates stored in client&amp;#8217;s Trust Store to verify the identity of the server. Once validated, the client then presents certificates stored in client&amp;#8217;s Key Store back to the server for validation.&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;A KeyStore keeps keys and certificates for your own application. Typically, you store a KeyPair in a KeyStore file.&lt;/li&gt;&#10;&lt;li&gt;A TrustStore keeps the certificates of external systems that your application trusts.&amp;nbsp;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Below is a great diagram:&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img loading="lazy" decoding="async" width="1362" height="956" src="https://static.digihunch.com/wp-content/uploads/2019/10/JavaJKS.png" alt="" class="wp-image-153"/&gt;&lt;figcaption class="wp-element-caption"&gt;Secure Java application in TLS&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;JKS file &lt;/strong&gt;is Java&amp;#8217;s version of PKCS#12 (private key + certificate, password protected). Entries in a JKS file must have an &amp;#8220;alias&amp;#8221; that is unique. The JKS file type can be used for both Key Store and Trust Store. When it&amp;#8217;s used in Key Store, it contains a certificate and private key for the Java application. When it&amp;#8217;s used in Trust Store, it only contains certificate from external trusted applications. Note that JKS is the default keystore format until Java 8. Since Java 9 the default keystore format is PKCS12.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Finally, we can introduce some tools:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Command line Tools&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;openssl &lt;/strong&gt;is a versatile tool for cryptography and keytool is a similar tool for Java applications.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;keytool &lt;/strong&gt;is for store keys/certificates in Java Key Store or Trust Store.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;I do not include any openssl or keytool command in this article in order to remain theoretical. However, once through the conceptual hurdles, one should become fairly comfortable picking up the tools and understand why each command is needed to achieve its purpose.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://static.digihunch.com/2019/08/aws-certified-devops-engineer-exam-tips/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;AWS Certified DevOps Engineer Exam Tips&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://static.digihunch.com/2019/10/personal-vim-cheatsheet/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Personal Vim cheatsheet&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item></channel></rss>