How To Generate a Self-Signed SSL Certificate With SAN

For development and integration use cases you may need to create or renew a self-signed certificate and store the certificate to your web server host or pass the certificate to your target system to trust only connections from an app using the certificate.

If you are storing the certificate on your webserver and enabled only secured connection via HTTPS on your server.

Chrome may not recognize the SSL certificate as secure without SAN (Subject Alternative Name).

Prerequisite: You should have openssl installed on your machine. Check and download from https://www.openssl.org/source/

To create one in command do the following steps:

Create a configuration file: eg. req.cnf

[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = NZ
ST = AU
L = Auckland
O = Quonsepto
OU = MyDivision
CN = localhost
[v3_req]
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost

Next from the terminal or command prompt run the following:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt -config req.cnf -sha256

You can then generated certificate and it should be compatible with Chrome.

Check this video for sample installing on a locally hosted node app.

How To Use Regular Expressions (Regex)

“Some people, when confronted with a problem, think ‘I know, I’ll use regular expressions.’ Now they have two problems.” – Jamie Zawinski

Every now and then I have some requirements where it entails parsing some data where I need to use some form of Regular Expression(regex), it is a syntax to use to search for patterns in a string or sets of strings. At first, the syntax looks intimidating and most people would shy away and resort to writing some functions to solve the issue.

Learning regex is a must-have skill to have as it can be applied to a wide range of tasks that needs some sort of search or parsing and is widely available in most programming languages, works on shells, text editors and IDEs, etc..). I use it most of the time when writing front end Javascript validation and backend logic in Apex NodeJS, Java/Groovy , Swift and Python

I created this cheat sheet that covers the basics and some handy tips.

Flags

The search pattern is normally delimited by two slash characters /abc/. At the end we can specify a combination of the following flags.

  • g (global) – Don’t return after the first match
  • m (multi-line) – ^ and $ match start/end of line
  • i (insensitive) case insensitive match
  • x (extended) ignore whitespace
  • X (eXtra) disallow meaningless escape
  • s (single line) dot matches new line
  • u (unicode) match with full unicode
  • U (Ungreedy) make quantifiers lazy
  • A (Anchored) anchor to start of pattern
  • J (Jchanged) allow duplicate subpattern names
  • D (Dollar end only) $ matches only end pattern


Anchors

Quantifiers

Or and Brackets

When inside bracket expressions all special character rules do not apply. E.g. \ to escape a character does not apply

Character Classes

In order to be taken literally, you must escape the characters ^.[$()|*+?{\with a backslash \ as they have special meaning.

Groupings

Greedy and Lazy Quantifiers

The quantifiers ( * + {}) are greedy operators, so they expand the match as far as they can through the provided text.

Boundaries

Back References – \1

Look-ahead and Look-behind

Top Regular Expressions

Summary

As we’ve learned regex is so powerful and its’s application is wide. Listed below some of few things you can do with regex within your project.

  • input and data validation –
    • validate user input in forms
    • validate data before applying logic or saving to database
    • validating JSON schema
  • replacing values – replace specific data in a string
  • text parsing – eg. retrieve only bits of data from a string or URL or delimiters
  • string replacement – eg on some IDE you can find and replace a string, use regex to search for particular patterns
  • web scraping – look for specific patterns for data to scrape

Sample Codes

Apex class that implements removal of white space not found in quotes

Python script that crawls pages that matches the pattern.

And finally, as a takeaway just learn the syntax and hack away.

How to Access phpMyAdmin on Google Cloud Compute on your Mac

I’ve been doing a small bit of Google Cloud Compute(GCP) configurations to run this blog. I thought I’ll start sharing some of the steps I’ve gone through which could be useful to others out there. So I’ve setup a GCP instance and configured it with a WordPress Bitnami stack. I’ve got some videos of those in this playlist if you want to follow along.

But on this post I would be discussing about accessing phpMyAdmin on GCP via an SSH Tunnel on your Mac.

In order to access phpMyadmin on a WordPress Bitnami stack from Google Cloud Compute you need to do this using an SSH tunnel. On the WordPress Bitnami stack, phpMyAdmin is blocked from the public and only accessible from the localhost. This is where SSH tunnel comes in. Basically you access the localhost on a particular port on your computer that forwards that information to the remote server on an encrypted channel and then the remote server sends the content back to the local computer.

Here is an illustration on how that access is provided via the SSH tunnel.

Another example of using SSH tunnel is when a website is blocked from your company firewall or proxy filter, you can use SSH tunnel to bypass the proxy and connect to a remote computer that has no restriction and can access the blocked website.

With that said, lets connect via SSH tunnel on your Mac.

  1. Open the terminal and change directory to where your private key is located
  2. Type in following, replace the private key name, user and IP to match yours. Enter passphrase when prompted.
    • ssh -N -L 8888:127.0.0.1:80 -i <keyfile> <username>@<ip>
  3. If successful it would not prompt any errors. If you want to login to the instance you can strip out the -N parameter.
    • ssh¬† -L 8888:127.0.0.1:80 -i <keyfile> <username>@<ip>

  4. Open your brower and enter 127.0.0.1:8888/phpMyAdmin
  5. You should be able to view phpMyAdmin

Here is a video I made for the process.

That should be it. If you have questions or comments please use the section below and feel free to subscribe to my youtube channel.

Fixing Apache after upgrading to MacOS High Sierra

If your previous Apache setup stopped working after updating to MacOS High Sierra, then this post should be useful for you. On every update of the MacOS it ships with its own version of Apache and PHP and creates a new install that overrides your configuration.

Read the rest of this entry »

How to Install Apache Ant on a Mac

Created a video for installing apache ant on Mac running on MacOS Sierra and here is the steps to follow along.

  1. Download Apache Ant to your desktop and unzip the files
  2. Rename the folder to ant
  3. Open the Terminal
  4. Move the files to /usr/local
  5. Fix the permission
  6. Edit the bash_profile with your favorite editor
  7. Add the path to the ant bin directory
  8. Save and exit your editor
  9. Test out if ant was successfully installed.

 

Other Notes: If you are getting an error when you run any commands:

Unable to locate tools.jar. Expected to find it in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/tools.jar

This means you do not have the Java JDK installed. Go to java.com and download and install the JDK.

Edit your bash_profile and update the path for the JAVA_HOME.

Subscribe to my Youtube channel for more how to video tutorials.