Skip to main content

I made a GIF!

SSL management tasks

Ran into some SSL issues today and did not have the tools to generate an acceptable CSR/PEM/DER. Here is what I gathered for next time.

For *nix:

#! /usr/bin/bash
PATH="/usr/local/ssl/bin:$PATH"
OPENSSL=`which openssl`
MOD=1024
KEY=f00bar

if [ ! -e "$OPENSSL" ]; then exit; else echo "$OPENSSL exists"; fi
if [ ! -d "$HOME/ssl" ]; then mkdir $HOME/ssl; else echo "$HOME/ssl exists"; fi
if [ ! -d "$HOME/ssl/csr" ]; then mkdir $HOME/ssl/csr; else echo "$HOME/ssl/csr exists"; fi
if [ ! -d "$HOME/ssl/cert" ]; then mkdir $HOME/ssl/cert; else echo "$HOME/ssl/cert exists"; fi
if [ ! -d "$HOME/ssl/key" ]; then mkdir $HOME/ssl/key; else echo "$HOME/ssl/key exists"; fi

echo -e "\t*\n***\tCreate Server certificate key\n\t*"
$OPENSSL genrsa -passout pass:$KEY -des3 -out $HOME/ssl/key/server-pass.key $MOD
$OPENSSL rsa -passin pass:$KEY -in $HOME/ssl/key/server-pass.key -out $HOME/ssl/key/server.key

echo -e "\t*\n***\tCreate Server self-signed certificates in PEM, DER formats\n\t*"
$OPENSSL req -new -x509 -days 1440 -key $HOME/ssl/key/server.key -out $HOME/ssl/cert/server.pem.crt
$OPENSSL x509 -in $HOME/ssl/cert/server.pem.crt -outform DER -out $HOME/ssl/cert/server.der

#echo -e "\t*\n***\tCreate Server certificate signing request\n\t*"
#$OPENSSL req -new -key $HOME/ssl/key/server.key -out $HOME/ssl/csr/server.csr

#echo -e "\t*\n***\tCreate CA certificate key\n\t*"
#$OPENSSL genrsa -passout pass:$KEY -des3 -out $HOME/ssl/key/ca-pass.key $MOD
#$OPENSSL rsa -passin pass:$KEY -in $HOME/ssl/key/ca-pass.key -out $HOME/ssl/key/ca.key

#echo -e "\t*\n***\tCreate CA certificate\n\t*"
#$OPENSSL req -new -x509 -days 1440 -key $HOME/ssl/key/ca.key -out $HOME/ssl/cert/ca.pem.crt

## Use this command if the CSR was generated by another system
#echo -e "\t*\n***\tCreate Server certificate from certificate signing request and CA certificate, CA certificate key (3rd party verification)\n\t*"
#$OPENSSL x509 -req -days 1440 -in $HOME/ssl/csr/server.csr -CA $HOME/ssl/cert/ca.pem.crt -CAkey $HOME/ssl/key/ca.key -set_serial 01 -out $HOME/ssl/cert/server-csr.pem.crt


For Windows using Win32 OpenSSL:

@echo off
set PATH=C:\OpenSSL\bin;%PATH%
set OPENSSL=openssl.exe
set MOD=1024
set KEY=f00bar

IF NOT EXIST "%USERPROFILE%\Desktop\ssl" mkdir %USERPROFILE%\Desktop\ssl
::ELSE echo "%USERPROFILE%\Desktop\ssl exists"

IF NOT EXIST "%USERPROFILE%\Desktop\ssl\csr" mkdir %USERPROFILE%\Desktop\ssl\csr
::ELSE echo "%USERPROFILE%\Desktop\ssl\csr exists"
IF NOT EXIST "%USERPROFILE%\Desktop\ssl\cert" mkdir %USERPROFILE%\Desktop\ssl\cert
::ELSE echo "%USERPROFILE%\Desktop\ssl\cert exists"; fi
IF NOT EXIST "%USERPROFILE%\Desktop\ssl\key" mkdir %USERPROFILE%\Desktop\ssl\key
::ELSE echo "%USERPROFILE%\Desktop\ssl\key exists"

echo ***
echo *** Create Server certificate key
%OPENSSL% genrsa -passout pass:%KEY% -des3 -out %USERPROFILE%\Desktop\ssl\key\server-pass.key %MOD%
%OPENSSL% rsa -passin pass:%KEY% -in %USERPROFILE%\Desktop\ssl\key\server-pass.key -out %USERPROFILE%\Desktop\ssl\key\server.key

echo ***
echo *** Create Server self-signed certificates in PEM, DER formats
%OPENSSL% req -new -x509 -days 1440 -key %USERPROFILE%\Desktop\ssl\key\server.key -out %USERPROFILE%\Desktop\ssl\cert\server.pem.crt
%OPENSSL% x509 -in %USERPROFILE%\Desktop\ssl\cert\server.pem.crt -outform DER -out %USERPROFILE%\Desktop\ssl\cert\server.der

echo ***
::echo *** Create Server certificate signing request
::%OPENSSL% req -new -key %USERPROFILE%\Desktop\ssl\key\server.key -out %USERPROFILE%\Desktop\ssl\csr\server.csr

echo ***
::echo *** Create CA certificate key
::%OPENSSL% genrsa -passout pass:%KEY% -des3 -out %USERPROFILE%\Desktop\ssl\key\ca-pass.key %MOD%
::%OPENSSL% rsa -passin pass:%KEY% -in %USERPROFILE%\Desktop\ssl\key\ca-pass.key -out %USERPROFILE%\Desktop\ssl\key\ca.key

echo ***
::echo *** Create CA certificate
::%OPENSSL% req -new -x509 -days 1440 -key %USERPROFILE%\Desktop\ssl\key\ca.key -out %USERPROFILE%\Desktop\ssl\cert\ca.pem.crt

::# Use this command if the CSR was generated by another system
::echo *** Create Server certificate from certificate signing request and CA certificate, CA certificate key (3rd party verification)
::%OPENSSL% x509 -req -days 1440 -in %USERPROFILE%\Desktop\ssl\csr\server.csr -CA %USERPROFILE%\Desktop\ssl\cert\ca.pem.crt -CAkey %USERPROFILE%\Desktop\ssl\key\ca.key -set_serial 01 -out %USERPROFILE%\Desktop\ssl\cert\server-csr.pem.crt

Comments

Popular posts from this blog

Cisco ASA ICMP packet-tracer

Occasionally devices fail to respond to a ping.  This can result from devices being off-line, having a local firewall enabled or the perimeter firewall configuration.  The Cisco ASA ICMP packet-tracer options differ from the TCP or UDP command options.  An example is below: packet-tracer input outside icmp A.B.C.D 8 0 E.F.G.H The ICMP type is "8" (echo request) with code"0" (none).  There are no options on destination IPv4 address E.F.G.H. Complete ICMP documentation at URL http://www.iana.org/assignments/icmp-parameters/ Complete Cisco ASA packet-tracer documentation at URL http://www.cisco.com/en/US/docs/security/asa/asa80/command/reference/p.html#wp1878788

Xfce4 lock screen not working

Xfce4 would not start a screensaver on my Linux system.  Researching it, it ran xflock4 from the command line ad received an error: Property "/general/LockCommand" does not exist on channel "xfce4-session". To fix this, additional configuration needed, but no hacks. First, verify xflock4 and xfconf-query are available. $ which xflock4 xfconf-query /bin/xflock4 /bin/xfconf-query Next  install a lock screen package that provides 'xlock', 'slock', 'i3lock' or similar.  $ sudo yum install -y xlockmore-gtk i3lock Last, add an executable (with options) as /general/LockCommand in the xfce4-session settings. $ xfconf-query -c xfce4-session --create -p /general/LockCommand --set "xlock -mode matrix" --type  string $ xfconf-query -c xfce4-session --create -p /general/LockCommand --set "i3lock -c 000000" --type string Test by running xflock4 from the command line or through the GUI.

X11 Forwarding issue solved

TL;DR Disabling IPv6 necessitates SSHd AddressFamily is "inet" for X11 Forwarding to work. Issue OpenSSH assumes both IPv6 and IPv4 protocols are enabled, and default SSHd AddressFamily value "any" is valid. Quickly skimming the OpenSSH source code, it was not obvious why SSHd does not fail gracefully, selecting only an available IP address family. Therefore, for X11 Forwarding to work correctly, in /etc/ssh/sshd_config we must choose: Defaults - IPv6 enabled and SSHd AddressFamily value " any " Custom - IPv6 disabled and SSHd AddressFamily value " inet " Background PuTTY was not creating a $HOME/.Xauthority file on ssh login and no X11 applications would run, despite setting $DISPLAY.  PuTTY was correctly configured with: X11 Forwarding enabled X display location empty Remote authentication protocol MIT-Magic-Cookie-1 X authority file for local display empty On the initial ssh login there should be a .Xauthority notic