20090313

Linux stuff in the AIX neighbourhood

When I logged in into the AIX system for a very first time I had experienced the beauty of IBM system, and helplessness. I had known only the four AIX specific commands, and a bunch of experiences from Sun Solaris system.

The first stonghold was the ksh system shell. No history. No command completion. "No" in a way I used to use it. It took me a while to find out the fc cmd.
So, the fist thought was to bring in the zsh.

But... in order to make it possible, I have to know - HOW and FROM.
The Solaris has got it's sunfreeware.com and blastwave.org. AIX - rpm database of ppc packages.

Here it is: http://www-03.ibm.com/systems/power/software/aix/linux/toolbox/alpha.html
How to get the rpm itself: http://www-03.ibm.com/systems/power/software/aix/linux/toolbox/altlic.html

The rest is as simple as:

# rpm -i zsh*rpm

... after installing the dependencies ;-) (rpm packages: coreutils, grep)

20090310

SSL: be prepared

Before you could start with SSL changes on application level of configuration, you have to prepare certificate and its database.
First the certificate should be converted from PEM to PKCS#12 format.


# openssl pkcs12 -export -in cert.pem -inkey key.rsa -out cert.pkcs12 -name Server-Cert


cert.pem - certificate taken from Certificate Authority (CA), either local or public (Thawte, Verisign, other)
key.rsa - private key used to sign the Certificate Signing Request (CSR)
cert.pkcs12 - pkcs#12 output file
Server-Cert - you could use any other, but in the most cases it's a default certificate name (alias) used within SSL configuration, ex.
 
# configutil -o encryption.rsa.nssslpersonalityssl
Server-Cert


Messaging Server

Initialize certificate database:

# msgcert generate-certDB
Choose the Certificate Database password:
Confirm the Certificate Database password:

It lead to creation of database files: cert8.db, key3.db, secmod.db and sslpassword.conf - plain text file, used to store software token (password provided during the generation process).
Initialization has created the self-signed certificate, with Server-Cert alias name.
Before we start the import, we have to remove it unless different cert name will be used.

# msgcert remove-cert Server-Cert
Enter the certificate database password:
book [/opt/sun/comms/messaging64/config]# msgcert list-certs
Enter the certificate database password:
Alias Valid from Expires on Self-signed? Issued by Issued to
----- ---------- ---------- ------------ --------- ---------
0 certificates found


Now, let's eat some certificates.

# msgcert import-cert /root/SSL/cert.pkcs12
Enter the PKCS#12 file password:
Enter the certificate database password:

Voile!

If there's a need of rollback to self-signed certificate or renew the expired one, use the similar commads:

# msgcert add-selfsign-cert -S "CN=mail.wisnios.com" Server-Cert

# msgcert renew-selfsign-cert Server-Cert


Errors:

· Internal error: NSS error (SEC_PKCS12DecoderUpdate) in importCert:
security library: improperly formatted DER-encoded message. (-8183)
Failed to import the certificate

The certificate file has not been converted from PEM to PKCS#12
(use openssl pkcs12 -export)


· A certificate with the same alias already exists in the database.
Failed to import the certificate

The previously created (self-signed) certificate has not been removed
(use msgcert remove-cert)


Web Server

We could use the same converted file to feed the web server database.

[/var/opt/SUNWwbsvr7/https-mail.wisnios.com/config]
# /opt/SUNWwbsvr7/bin/pk12util -i /root/SSL/cert.pkcs12 -d .
Enter a password which will be used to encrypt your keys.
The password should be at least 8 characters long,
and should contain at least one non-alphabetic character.

Enter new password:
Re-enter password:
Enter password for PKCS12 file:
pk12util: PKCS12 IMPORT SUCCESSFUL

[/var/opt/SUNWwbsvr7/https-mail.wisnios.com/config]
# certutil -L -d .
Server-Cert u,u,u

The triple 'u' means that certificate could be used for authentication (SSL, email) and object signing.

The self-signed cert could be generated with wadm administration command:

wadm> create-selfsigned-cert --config=mail.wisnios.com --server-name=mail.wisnios.com \
--nickname=Server-Cert --token=internal
CLI201 Command 'create-selfsigned-cert' ran successfully


Application Server (Glassfish)

The same trick with appsvr.

[/opt/SUNWappserver/domains/domain1/config]
# pk12util -i /root/SSL/cert.pkcs12 -d .

[/opt/SUNWappserver/domains/domain1/config]
# certutil -L -n Server-Cert -d .


To change the default instance ssl configuration, follow those steps:

[https://appserver:4848]

Configurations:
default-config:
HTTP Service:
http-listener-2: (switch to right panel)

[right panel]
SSL:
Certificate NickName: Server-Cert (replace the default s1as entry)


Good luck.

20090225

port to pid / pid to port mapper

Finally, I've developed the mutual pid/port mapper.

Here it is. Feel free to use.

#!/bin/bash
#
# The mutual pid/port mapper
# - Marcin Wisnios [marcin AT wisnios.com]
#
case "$1" in
'')
echo "Usage: $0 PORT | -p PID | -n NAME | -a (ALL)"
exit 1
;;
'-p')
# pid search
P_ID=$2
;;
'-n')
# name search
P_ID=`pgrep $2`
;;
'-a')
# list all
P_ID=`ps -e -o pid,comm | sed '/PID/d; /ps/d; /sed/d; /bash/d; s/\([0-9]\{1,5\}\).*/\1/p;d'`
;;
*)
# port search
P_ID=`ps -e -o pid,comm | sed '/PID/d; /ps/d; /sed/d; /bash/d; s/\([0-9]\{1,5\}\).*/\1/p;d'`
PORT=$1
;;
esac

for P in $P_ID; do

N=`ps -o comm -p $P | sed '/COMMAND/d'`
N=`basename $N`

pfiles $P | sed 's/.*sockname:\ AF_INET[6]\{0,1\} \(.*\)\ \ port:\ \(.*\)/\1:\2/p;d' | while read L; do
if [ -z $PORT ]; then
echo "$L $P/$N"
else
echo "$L $P/$N" | sed "/:$PORT/p;d"
fi
done

done


Examples of use:

book [/home/wisnios]# ./ppm.sh 22
:::22 6963/sshd
::ffff:208.64.63.178:22 13491/sshd
::ffff:208.64.63.178:22 13507/sshd

book [/home/wisnios]# ./ppm.sh -n ns-slapd
:::389 7128/ns-slapd
:::636 7128/ns-slapd

book [/home/wisnios]# ./ppm.sh -p 20623
0.0.0.0:80 20623/cherokee-worker

20081127

Core system support - the journey begins

OK, I've installed 'core system support' software group. Solaris has started.
What now? There's for ex. no ssh service, no bash or zsh shell.
So I've decided to mount dvd image and install additional packages.

But... which dsk device is the right one?
No mounted device, no vfstab entry, no cdrom life marks on planet Solaris.

I've found it finally with:

for d in `ls /dev/dsk/*s2`; do prtvtoc $d; sleep 2; done

The right one is that with only one slice, with sector count of 4509440 (dvd image size):

* First Sector Last
* Partition Tag Flags Sector Count Sector Mount Directory
0 5 01 0 4509440 4509439
2 5 01 0 4509440 4509439

Mount:

mount -F hsfs -o ro /dev/dsk/c1t0d0s2 /cdrom

and install desired software:

pkgadd -R /a -d /cdrom/Solaris_10/Product
[...]

Select package(s) you wish to process (or 'all' to process all packages).
(default: all) [?,??,q]: SUNWsshcu,SUNWsshr,SUNWsshu,SUNWsshdr,SUNWsshdu,SUNWbash,SUNWzsh

I've used the -R switch because I've done the work inside the shell session invoked from the Installation menu.
The root system has been mounted at /a directory.

20081117

libcrypt_d.so.1: open failed: No such file or directory

During the rubygems installation process I've encountered the following problem:

thumper [/export/install/sources/rubygems-1.3.1]# ruby setup.rb
ld.so.1: ruby: fatal: libcrypt_d.so.1: open failed: No such file or directory
Killed


Because of a cryptographic technology export restrictions there's no build-in support for some of the algorithms.

To accomplish the task you should download and install 'Solaris 10 Encryption Kit for Sparc / x86'.
Enjoy the screener:


thumper [/export/install]# unzip sol-10-encrypt-GA-iso.zip
thumper [/export/install]# lofiadm -a /export/install/sol-10-encrypt-GA.iso
/dev/lofi/1
thumper [/export/install]# mount -F hsfs -o ro /dev/lofi/1 /mnt
thumper [/export/install]# mount -p | tail -1
/dev/lofi/1 - /mnt hsfs - no ro,noglobal,maplcase,rr,traildot
thumper [/export/install]# pkgadd -d /mnt/Encryption_10/i386/Packages

The following packages are available:
1 SUNWcrman Encryption Kit On-Line Manual Pages
(i386) 10.0,REV=52.0
2 SUNWcry Crypt Utilities
(i386) 11.10.0,REV=2005.01.21.16.34
3 SUNWcryr Solaris Root Crypto
(i386) 11.10.0,REV=2005.01.21.16.34

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]: all
[...]

thumper [/export/install]# umount /mnt
thumper [/export/install]# lofiadm -d /dev/lofi/1
thumper [/export/install]# find /usr/lib -name libcrypt_d*
/usr/lib/amd64/libcrypt_d.so
/usr/lib/amd64/libcrypt_d.so.1
/usr/lib/libcrypt_d.so
/usr/lib/libcrypt_d.so.1


To make your ruby/gem environment fully usable don't forget to install coreutils and make sunfreeware packages.
I've also linked the ginstall to install command:

thumper [/usr/local/bin]# ln -s install ginstall

It's a solution for the gem package builder error messages.

20081108

On which partition?

Last time I wrote the script for Messaging Server backups I faced the problem with proper partition selection. It's easy to achieve with a mboxutil utility... but I only need the names of the account and a corresponding partition.

Up to today I've used the solution with sed & awk. But I hate using many tools where the swiss army knife is available.
So...

# mboxutil -l -x| sed 's/.*user\/\(.*\)\/INBOX.*partition\/\(.*\)\/\=user\/.*/\1 \2/p;d'
admin primary
marcin.wisnios@somedomain.com secondary