Convert JKS and P12 to Crt and Key files with OpenSSL

PKCS#12 is a successor to Microsoft’s PFX format. It defines an archive file format for storing many cryptography objects as a single file. It is commonly used to bundle a private key with its X509 certificate or to bundle all the members of a chain of trusted certificates, starting from the root certificate authority. The files PFX (.pfx) and PKCS#12 (.p12), including terms, are somewhat used interchangeably and refer to same standard.

PKCS#12 are normally generated using OpenSSL, which is an open-source tool. We can use the same tool to convert JKS, which is Java keystore and PKCS#12 certs to crt and key files.

Read More »

Debug Bash Shell Scripts in Linux

Debugging code can be time consuming and tricky at times. Programmers have traditionally taken advantage of the techniques like syntax highlighting, code completion, intellisense, etc while writing and debugging code. Also no amount of such features can reduce logic based errors, where the script executes but not in a way we expected. This is more problematic with complex bash scripts as bash itself has no support for advanced features like these and most of the sysadmins spend their time with the editors like vi/nano/atom. Sometimes, even simple mistakes like missing a space, can make your scripts fail to run. In this blog post, we’ll discuss some of the common ways to debug bash shell scripts.

Read More »

Testing Bash Script Syntax Before Running

The terminal based editors for bash scripts do not usually point out any errors in bash script syntax. You can often make mistakes when creating a complicated syntax or editing long scripts. It would be good to have bash script checked for syntax before running it or before checking into source control management systems, so as to prevent any last minute issues.

For this issue, we can use bash -n syntax. Let’s see what happens if we run this on a well structured script:

Read More »

Using ternary operator in PowerShell 7

Developers for high level programming language have been familiar with the ternary operator ? : which goes like: <condition> ? <if-true> : <if-false>. It makes for more concise code in case of simple conditions and expressions. With PowerShell 7, this operator has been available and we can utilize the same.

The condition-expression is always evaluated and its result is converted to a Boolean to determine which branch is evaluated next:

  • The <if-true> expression is executed if the <condition> expression is true
  • The <if-false> expression is executed if the <condition> expression is false
Read More »

Change default Login Shell to PowerShell on Linux

With PowerShell 7, PowerShell Core has been improved and resolved the issues with environmental variables in the *-nix based operating systems. If you have been working with Linux Servers and are using PowerShell to perform some kind of administrative tasks, you may also want to set it as default login shell for certain users. This makes it easy to invoke certain scripts since a familiar shell is available when you are calling the environment.

There are many ways to change the shell like using usermod or chsh or may be if you are feeling adventurous, by modifying /etc/passwd directly using vi editor. So let’s get started.

Read More »

Using Pipeline Chain Operators in PowerShell 7

We all know how pipeline is an important and useful feature of PowerShell. It makes it incredibly easy to take output from one expression / cmdlet and pass it to another expression / cmdlet. It has also allowed to chain them together to create complex expressions. However, what was lacking is the ability to conditionally execute the expressions on the right side of the pipeline operator like the more modern versions of Bash shell. PowerShell 7 covers this gap by introducing Pipeline Chain Operators || and &&. These operators allow the conditional execution of commands or expressions depending on whether the previous command / expression succeeded for failed.

Read More »

Using Null Conditional Access Operators in PowerShell 7

Some of the common reasons we check if our variable is null or not, are because we have been trying to access an property on an object which does not exists or misspelled, the object itself does not exist, or iterating through an collection where some members are null or invalid, etc. To deal with these kind of situations, we had to use if..else condition blocks. PowerShell 7 introduced two experimental null conditional access operators: ?. and ?[]. However to enable and use them, you had to use Enable-ExperimentalFeature cmdlet. These have been moved to GA with release of version 7.1.

Read More »

Using Null Conditional Assignment in PowerShell 7

PowerShell 7 introduces few new operators to help sysadmins and dev alike, to work with null values. One of these operator is null conditional assignment operator (??=). Using this operator, allows us to write more cleaner and concise code. In this blog post, we’ll learn about the null conditional assignment operator.

Life Before PowerShell 7

Before PowerShell 7, we needed to use an if condition to check if the variable is null or not using $null operator and then perform the assignment, if that’s the case. For example, consider below code:

Read More »