Using self sign certificate with mono in Centos family Linux communicating with IIS Server

sometimes we do not want to pay for the Certificate authority – CA to issue a real certificate or for development, we just want to use a self sign cert that we signed and manually trusted it for testing https traffic just for development environment.

In Windows, we can just click on the self sign cert and it prompts us to where we want to store it which usually should be stored in Trusted Root Authority store.

Windows Cert. Trust - Trusted Root Certification Authorities vs Enterprise  Trust

But where is it in Linux and especially for mono? also I am not going to cover self sign cert for IIS server creation here in this post and I assume you already know how to do it. if you go to IIS manager (inetmgr) you should be able to create it there.

How to Install an SSL/TLS Certificate In Microsoft IIS 8 - The SSL Store™

I wrote a bash script here where it will download your IIS self signed cert from your IIS Server in pem format and then merge it with existing certificate bundle – tls-ca-bundle.pem. Then sync the newly merged cert list to mono store – Trust store

registerIISServerCertSelfSignForMono.sh

#!/bin/bash
echo "Server:Port = $1";

### Download IIS self sign cert in pem format from given server:port
openssl s_client -showcerts -verify 5 -connect $1 < /dev/null | awk '/BEGIN/,/END/{ if(/BEGIN/) out="IISSelfSignCert.pem"; print >out}'

TEMPDIR=/etc/pki/ca-trust/source/temp

### Cleaning up our temp directory
rm -rf $TEMPDIR
mkdir -p $TEMPDIR

### copy our IIS Server self sign cert pem to our temp directory
cp IISSelfSignCert.pem $TEMPDIR

### Merge our IIS self sign cert pem to existing tls ca bundle cert pem
cp /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem $TEMPDIR/MergedCertList.pem

echo -e "\n# $f added for IIS Server Self Sign Cert" >> $TEMPDIR/MergedCertList.pem
cat $TEMPDIR/IISSelfSignCert.pem >> $TEMPDIR/MergedCertList.pem

cat $TEMPDIR/MergedCertList.pem

#now sync with Mono store, Trust store
cert-sync $TEMPDIR/MergedCertList.pem

Execute it at the terminal:

$ registerIISServerCertSelfSignForMono.sh yourServerName:Port

eg:

$ registerIISServerCertSelfSignForMono.sh www.vic-llc.org:443

What if you returns exit code -1 in bash, will bash take it as -1?

Actually no, if we return -1 in bash, it will be interpreted as 255 per https://tldp.org/LDP/abs/html/exitcodes.html

if I can go back in time, I would never return exit code -1 for a failure in Linux. 1 would be ideal in this case.

Let write a simple bash script test – to copy non-existent file

the execution will fail and exit status code is 1 as expected so let’s modify this script and return the exit status code to -1.

Since we alter our script by checking if exit code is not zero, we instead return -1. As a result, bash interprets it as out of range since exit takes only integer args in the range 0 – 255 and therefore interprets it as 255 instead of -1.

String.IndexOf in JavaScript and C#

I am a backend engineer and we are working on a new Linux Project. We have UI UX team with us which they mainly work on UI UX front end. Once they are done with their UI UX work, they handed it over to us – backend engineers to integrate UI UX stuff with the backend Linux daemon service which runs in the background and/or at startup. After the integration, we found few issues with UI UX stuff mainly filtering as we have many options for end user to filter in the front end and I was also assigned to fix them which I did. Through working on fixing them, I came across JS code which uses IndexOf to find a match and I would have thought IndexOf(“”) empty string should yield -1 but it does not and instead it yields 0 and I also wonder what would be yielded in C#. I did a quick console app in .NET to test. And as a result, C# behaves the same way – returns 0.

From MSDN :

https://docs.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-5.0

String.IndexOf Method

Definition

Namespace:SystemAssemblies:mscorlib.dll, System.Runtime.dll

Reports the zero-based index of the first occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance.

But not too quick, if we go further below here it stated:

Returns

Int32

The zero-based index position of value from the start of the current instance if that string is found, or -1 if it is not. If value is Empty, the return value is startIndex.

Visual Studio 2019: Attach To Process takes a very long time to show up and how to fix it

I have VS 2019 enterprise edition and its attach to process took very long time to show up and that have impacted my productivity drastically. So far I have been complaining McAfee Anti-virus for this issue but turned out it was not due to McAfee at all.

Once I deselected Python Development workload in the VS installer screen below, it seems to resolve the issue and attach to process screen above pops up quicker.

Backup and Restore MySQL database on Linux Platform

A while back probably couple years ago I wrote bash scripts to backup and restore MySQL db on Linux platform mainly for debugging and/or troubleshooting purposes and here they are:

########################################
### backup.sh Backup mysql db script ###
########################################
#!/bin/bash
 
userhome=$(eval echo "~$USER")
echo "Executing under $USER context"
 
echo "Enter db username: "
read -s  USER
echo "Enter db password: "
read -s PASS
read -p "Enter database name: " DBNAME
 
### Backing up database ###
mysqldump -u$USER -p"$PASS" $DBNAME > $userhome/$DBNAME.sql
 
 
echo "---------------------------------------------------------------------------------"
echo "if no error, $DBNAME backup will be saved to $userhome/$DBNAME.sql"
echo "---------------------------------------------------------------------------------"
##########################################
### restore.sh restore mysql db script ###
##########################################
#!/bin/bash
 
userhome=$(eval echo "~$USER")
echo "Executing under $USER context"
 
echo "Enter dba username: "
read -s  USER
echo "Enter dba password: "
read -s PASS
read -p "Enter database name: " DBNAME
read -p "Enter database backup location (.sql): " DBBACKUPSQL
 
### restore backup database ###
mysql -u$USER -p"$PASS" -e "drop database $DBNAME;"
mysql -u$USER -p"$PASS" -e "create database $DBNAME;"
mysql -u$USER -p"$PASS" $DBNAME < $DBBACKUPSQL
 
echo "---------------------------------------------------------------------------------"
echo "if no error, $DBBACKUPSQL backup has been restored"
echo "---------------------------------------------------------------------------------"
To backup, at terminal execute backup.sh
# bash backup.sh 

it will prompt you for the database username and password and db.sql will be saved to the home directory of the user you use to execute this script.

To restore, at the terminal execute restore.sh

it will prompt you for the database admin username, password, and the backup script .sql location.

Centos/Oracle Linux switching from Desktop to CLI and how to start GUI application under CLI

Sometime we might want to login to CLI (Command Line Interface) where Desktop won’t be available and only terminal is accessible. Most of the time the reason we login under CLIs is that it is lightweight so it is running faster than running with Desktop. So how do we boot Centos or Oracle Linux into CLIs?

To switch from Desktop to CLI, execute below command:
# sudo systemctl set-default multi-user.target 
# sudo reboot

To switch from CLI back to Desktop, execute below command:
# sudo systemctl set-default graphical.target
# sudo reboot

Now under CLIs, we do not have Desktop (Windows system) available so how do we launch GUI App (X app) in CLI environment then? Yes we can please follow:

Example, how to we launch GUI App like Google Chrome under CLIs (Desktopless).

We need to use startx to launch it under X session (so-called X windows system or simply Graphical session)
you can read more about startx here https://www.x.org/releases/X11R7.5/doc/man/man1/startx.1.html

 startx [ [ client ] options ... ] [ -- [ server ] [ display ] options ... ] 

In our case, client is going to be the Google Chrome and please note that startx requires the full path of the client, Google Chrome.
To locate the full path of Google Chrome, execute below command:
#which google-chrome
/usr/bin/google-chrome

so now we are ready start it in single X Windows system by execute below command:
#/usr/bin/startx /usr/bin/google-chrome https://chanvicheka-ouk.com  -- vt1

You might wonder what is -- vt1 for?
vt1 means we will display it in x windows system at virtual terminal number 1.
Linux in CLI has six virtual terminals total which you can switch between them using ctrl+alt+F# where # is the number of the terminal (1-6)
google-chrome open url “https://chanvicheka-ouk.com” in CLI at virtual terminal#1

Install Chrome on Oracle Linux Server release 7.6

You can follow below steps:

You can check your Oracle Linux Release by execute below command at the terminal
# sudo cat /etc/oracle-release 

Ok, now it is the time to install Chrome
#sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
#sudo yum -y install redhat-lsb libXScrnSaver 
#sudo yum -y localinstall google-chrome-stable_current_x86_64.rpm

Remark: If you run into following issue:
Error: Package: google-chrome-stable-88.0.4324.182-1.x86_64 (/google-chrome-stable_current_x86_64)
           Requires: libvulkan.so.1()(64bit)

you can resolve it by execute following two commands:
#sudo yum-config-manager --enable ol7_optional_latest
#sudo yum -y localinstall google-chrome-stable_current_x86_64.rpm

Installed:
  google-chrome-stable.x86_64 0:88.0.4324.182-1

Dependency Installed:
liberation-fonts.noarch 1:1.07.2-16.el7        
liberation-mono-fonts.noarch 1:1.07.2-16.el7      
liberation-narrow-fonts.noarch 1:1.07.2-16.el7      
liberation-serif-fonts.noarch 1:1.07.2-16.el7     
vulkan.x86_64 0:1.1.97.0-1.el7
vulkan-filesystem.noarch 0:1.1.97.0-1.el7

Voila, it is installed. you can find it here:

Fixing VirtualBox Raspberry pi small screen resolution

First, if you do not know how to download its iso and load it in the virtualbox, please refer to tutorial at this url: https://roboticsbackend.com/install-raspbian-desktop-on-a-virtual-machine-virtualbox/

And once you have it setup and running then you will need to install virtualbox guest additions as describe here:

First mount it to the virtual OS

  • Click on Devices menu and then Insert Guest Additional CD Image
  • This will popup. Click Ok
  • Right click on VBox _GAs… and Open in Terminal
  • Execute this below command with sudo meaning you elevated yourself as privileged user.
  • sudo bash VBoxLinuxAdditions.run
  • Hit enter and wait till it complete
  • Next we need to edit /etc/X11/app-defaults/Editres
  • Execute below command
  • sudo mousepad /etc/X11/app-default/Editres
  • Next give it a desired resolution we like. in my case I gave 1000 width/height.