Skip to main content

Posts

How to see if a website supports each TLS version in command line

This is a quick post about checking TLS version support using the command line. Of course, there are plenty of GUI tools and online services to do this. Yet, I find it is much easier to use just a simple command to check this. I'm going to use badssl.com to test this out since it provides various examples with different SSL configurations. We'll be using openssl command to check this. Openssl is a command-line tool to work with SSL connections. If you don't have it in your machine, you'll have to install it first. Let's check a website that supports TLS1.0 TLS 1.0 has been deprecated by all web browsers and servers due to security vulnerabilities in that protocol version which you shouldn't use at all. If you have this enabled in your sever/website, please disable ASAP. openssl s_client -connect tls-v1-0.badssl.com:1010 -tls1 Let's break the command to it's parts openssl : command line tool s_client : s_client is the first command of this t...

How to serialize a class with static variables in Java

TL;DR You can't! Instead; Change the static variables into a none static member variable of a singleton class. By making the variables holding class to a singleton, still, it caters to the requirement of keeping your variables having a single reference for the entire application. (This is one of the ways of doing it, surely there are more other elegant ways and crude hacks of doing this depending on the situation) This is a problem that a scholar asked me for some help with. We have a simple use case where there's a configuration class that it requires to hold some values used in application-wide. So the easiest way (not the best) somebody could think would be making the variables static, so it would be only a single reference for it throughout the whole application. Let's imagine the configuration class would look like below. import java.io.Serializable ; public class BranchConfig implements Serializable { private static String branchNa...

Wget download pause and continue

If you are downloading a file with the wget command, sometimes you may need to pause it and start it back from the place where you paused rather than starting from the beginning. So you don't have to re-download the entire package. Wget can do this just like downloading from a web browser. Let's say I need to download a file from the web. So I'm using the wget command as follows. Download wget <url for the file> Pause To pause the download just hit ctrl + c  the shortcut to terminate the current command. Continue This is going to be the same command but -c switch to continue from the previous download. wget -c <url for the file> Simple as that! Yeah, you can download from a web browser, but this is more fun and easier 😋 If you are lazy like me, wget saves a couple of clicks.

Java String NullPointerException safe equals check

If you compare two Strings in Java, normally you would use the equals method to compare them to see if they are similar. This will be some common use case for input validations. However, if you don't do it properly it may cause you to throw a NullPointerException. This is pretty much like common sense, but I've seen even more experienced developers make this mistake. Let's consider the following code. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public class DemoApplication { final static String theStringIknow = "Hello" ; public static void myTestMethod ( String someString ) { //do not do this if ( someString . equals ( theStringIknow )) { System . out . println ( "Same same" ); } } public static void main ( String [] args ) { String testString = "Hello" ; myTestMethod ( testString ); } } In myTestMethod, I'm checking if the String in the a...

How to detect page scroll to bottom of a React component

Depending on your UI framework, some of them don't really support scroll aware components. If you had to work on one of them, then this will be great for you. I had to work with one of the old UI frameworks with ReactJs. It didn't support any scroll event awareness by default. So, I had to write some custom logic to do that. Following is a sample component with scroll event awareness to detect the bottom. class MyComponent extends React.Component { constructor(props) { super (props); //atBottom state is kept to smooth things out, // to avoid again and again detecting the bottom event if we are at the bottom this .state = {atBottom : false }; // This binding is necessary to make `this` work in the callback this .handleScroll = this .handleScroll.bind( this ); } handleScroll(event) { console.log( "scrolled" ); const element = document .getElementById( 'mylist' ); if ( ! this .st...

How to set terminal title in Ubuntu 18.04 LTS

In older Ubuntu versions, you could have just right-clicked on the Ubuntu Terminal window's title bar and set any title you would like. But unfortunately after Ubuntu 18.04 LTS this feature is gone. I used to love this feature because I'm multiple tabs in the single terminal window kind of a guy. I usually like to work in multiple named terminal tabs like below. By default, in newer Ubuntu version, it is showing just the current directory. Let's see how we can do this. Ubuntu prompt In ubuntu's Bash, there's an environment variable $PS1 which is responsible for the details that the command line prompts. You'll be able to echo this and see what's inside it. If I echo it it will print something like this. echo $PS1 \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ If you really want to understand what this means, you can refer this page .  Updating the termina...

When NOT to use MongoDB background unique indexing

This is based on my personal experience working on MongoDB with a Java app. My Java app is a Springboot app using Spring Data MongoDB to connect with the database. And here is the maven dependency that I used. <dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-data-mongodb </artifactId> </dependency> Before jumping into the problem, let me just brief about the indexes that we are using here. Indexes Indexes are set to a collection because, during my operations, I might need the collections to be queried based on these indexed fields faster and efficiently. Unique index : This could be a field that is unique for each document that you are saving in the collection. This field can be a Candidate key which would be a field where you could use to uniquely identify a document. Sometimes these indexes are created as a validation in the database level. So, you cannot insert two similar re...

How to fix SSLHandshakeException PKIX path building failed in Java

TL ; DR 1. Extract the public certificate of the website/API that you are trying to connect from your Java application. Steps are mentioned in this post 2. Use the Java keytool to install the extracted certificate into the "cacerts" file (Trust store) keytool -import -trustcacerts -alias <domain name> -file <public certificate>.cert -keystore /path_to_java_home/jre/lib/security/cacerts -storepass changeit 3. Restart your Java application Exception A typical exception stack trace would look like below. 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 at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) at sun.security.ssl.Handshake...