Java manage certificates như thế nào
This Course Is awesome it gave me a new look on how my brain works and that i should actually take breaks which is
probably why i get frustrated. I am Excited to Put what i have learned into practice.
Show
by BHNov 14, 2015 I found this course to be incredibly helpful. I am 33 and wish that I would have been taught a more efficient way of learning many years ago. There are definitely some great takeaways from this class. by KKJun 24, 2021 This course is more than what I expected to learn from this course. The explaining skills of the educators of this course are great. Thank to our educators dr.barbara oakley and terrance sejwoniski by DDJul 10, 2020 This course is necessary in sharpening learning skills and test taking techniques. The scope of the course enables the student to development effective leading strategies whilst avoiding the bad ones. View all reviews This article will go into detail on how to install certificates on Java Based Web Servers (Tomcat). Installing SSL Certificate Chain (Root, Intermediate(s) and the End Entity) 1. Import Root Certificate 2. Import Intermediate(s) Note: Depending on the type of certificate that was purchased, there may be more than one Intermediate certificate in the chain of trust. Please install all intermediates in numberical order until you get to the domain/end entity certificate. For more information on 3. Import Entity/Domain certificate You should you should receive a message: Certificate reply was installed in keystore if successful. It should NOT match the output of Step 1 or 2 above. Note: If an alias was specified upon creation of the CSR then please use that alias instead of mykey. 4. Restart the Web Server Service. Note: Tomcat will first need an SSL Connector configured before it can accept secure connections. Please ensure this is set BEFORE the server is restarted. OverviewWhen developing web applications, we often need to integrate with other applications using SSL. This could be over different protocols such as HTTPS, IMAPS, or LDAPS. In this article, we’ll cover what Java developers need to know about SSL certificates. Certificate ChainAn SSL connection succeeds only if the client can trust the server. Let’s take a look at how this trust model works. In Chrome, go to google.com and bring up the Developer Tools (F12 on Windows, Cmd+Option+i on Mac). Under the Security tab, click the View Certificate button to show details about the certificate. We can see that the site certificate is part of a chain. This particular chain consists of 3 certificates. Certificate chain for google.comThe site certificate has been issued by a certificate named Google Internet Authority G2. This is the intermediate certificate. In turn, the intermediate certificate is issued by the root certificate GeoTrust Global CA. When we establish a connection over HTTPS, the web server will respond by providing its site and intermediate certificates. It is then up to the client to complete the chain by having the root certificate. This chain validation is necessary for the client to trust the site. Since Chrome has the root certificate GeoTrust Global CA in its certificate store, our connection succeeds and we are not presented with any errors or warnings.
Self-signed CertificatesCertificates not issued by known CA but rather by the server hosting the certificate are called self-signed. These are often used in internal development environments that are not customer facing. The root certificates for these will be absent in the browser’s certificate store. An example of self-signed certificate is at https://self-signed.badssl.com. We can see that this was issued by Avast Untrusted CA which the browser does not recognize so it displays a warning. Self-signed certificateJava Truststore & KeyStoreIn this section, we’ll discuss where certificates live on a system where the JDK/JRE is installed. TruststoreThe truststore is a file that contains the root certificates for Certificate Authorities (CA) that issue certificates such as GoDaddy, Verisign, Network Solutions, and others. The
truststore comes bundled with the JDK/JRE and is located in The truststore is used whenever our Java code establishes a connection over SSL. KeystoreThe keystore is a file used by an application server to store its private key and site certificate. So if we were running a web application over SSL at tomcat.codebyamir.com, the keystore file named keystore.jks would contain two entries — one for the private key and one for the certificate. The keystore is used by Java application servers such as Tomcat to serve the certificates.
KeytoolKeytool is a utility bundled with the JRE for managing key pairs and certificates. This allows us to view/modify/create certificate stores in the Java world. List the certificates in the truststorekeytool -list -keystore $JAVA_HOME/lib/security/cacerts We’ll be prompted for a password for the truststore. The default password is “changeit”. This truststore contains 104 entries and each entry has a unique alias and fingerprint. We’ve truncated the output below for brevity. Keystore type: JKS Using the google.com example from before, let’s take a look at the fingerprint for the GeoTrust Global CA from our browser: Root CA Certificate for google.comThe SHA-1 fingerprint is Let’s look for that in our truststore: keytool -list -keystore $JAVA_HOME/lib/security/cacerts | grep -B1 -i DE:28 The output tells us that the certificate is in the truststore: What does this mean to a Java developer?It means that code connecting to https://www.google.com won’t throw an exception due to an SSL handshake error. Add a certificate to the truststoreAdding a certificate to the truststore is necessary if we want to trust a certificate issued from a CA not present in the bundled truststore. keytool -import -trustcacerts -file [certificate] -alias [alias] -keystore $JAVA_HOME/lib/security/cacerts Code ExampleBelow is some Java code that will connect to a URL and print the contents of the page onto the screen. Connecting to Site with a Trusted CertificateLet’s try our code on another site with a valid SSL certificate. CodeReplace line 12 from the code with this line: private static final String URL = "https://httpbin.org/user-agent"; OutputWe can see that the code output successfully shows that our user-agent string is our Java version. { Connecting to Site with an Untrusted CertificateLet’s try our code on a site with a self-signed certificate. CodeReplace line 12 from the code with this line: private static final String URL = "https://self-signed.badssl.com"; OutputThe code throws an Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target If we wanted to trust the self-signed certificate from the previous example, we could add its root certificate to our truststore using the command covered previously in the keytool section. After adding the certificate, running the code again successfully displays the page contents:
Common SSL Validation ExceptionsExpired CertificateWhen connecting to a site with an expired SSL certificate, we’ll see the following exception: java.security.cert.CertPathValidatorException: timestamp check failed Wrong Common Name (CN)When connecting to a site with a certificate name different than the hostname, we’ll see the following exception: java.security.cert.CertificateException: No subject alternative DNS name matching wrong.host.badssl.com found. FAQDoes the JRE cacerts truststore get updated?Yes, new releases of Oracle JDK/JRE will add new certificates to the truststore as needed. How can I tell Java to use a custom truststore?Add the following JVM property when starting the application: -Djavax.net.ssl.trustStore=/app/security/truststore.jks If the truststore password is different than “changeit”, then also specify the password: -Djavax.net.ssl.trustStorePassword=myTrustStorePassword How can I verify that a site is sending an intermediate certificate?We can use the openssl utility on Linux to verify this: openssl s_client -showcerts -connect google.com:443 |