OpenSSL Hacks

OpenSSL contains a command-line tool to do nearly everything possible within the OpenSSL library. Even better, it's probably already installed on your system.
Encrypted Passwords

Here's something that GnuPG can't do. OpenSSL has a built-in command for creating encrypted Linux passwords exactly like those made by /bin/passwd.

Skip this paragraph to avoid pedantic cryptography. Although commonly called encrypted, Linux passwords are actually hashed using either MD5 or the old UNIX password hash (based on the DES encryption algorithm). This allows Linux not to know your password even though it knows when you provide the correct password. When you set your password, Linux hashes your password and stores it in /etc/shadow. When you log in, Linux takes the password you provide and hashes it again, and then compares that hash to what's stored in /etc/shadow for your account. If they match, you provided the correct password and can log in. If they don't match, you don't know your password, and because only the hash was stored, the computer still doesn't know your password either.

Here's why making your own password hash is useful. Let's say you need a new password on another computer. Perhaps it's a new account or you forgot the old password and asked the system administrator to reset it for you. If you can talk to the sysadmin in person, this works well, but what if the sysadmin is somewhere else? Perhaps you've never even met your sysadmin. How do you communicate your new password? E-mail is not secure at all, and telephones are scarcely better. Postal mail takes days (and has other security problems). Fax machines, text messaging and most pagers aren't secure either.

It gets worse. Maybe you don't even trust that sysadmin. Sure, the sysadmin usually has root, but someone else knowing your password bypasses even root accountability. Maybe you want to use the same password on other computers, and you don't trust those sysadmins either.

So, do this instead:

$ openssl passwd -1
Password:
Verifying - Password:
$1$zmUy5lry$aG45DkcaJwM/GNlpBLTDy0

Enter your new password twice; it won't echo. If you have multiple accounts, run the above example multiple times. The output is the cryptographic hash of your password. The hash is randomly salted so that every time it's run, the output will be different, even if the password is the same.

In my example, the password hash is:

$1$zmUy5lry$aG45DkcaJwM/GNlpBLTDy0

Your password hash probably will be completely different, except for the initial $1$.

This password hash can now be e-mailed, faxed, text messaged or even spoken over the phone to a sysadmin to set as your password hash.

After the sysadmin receives your password hash, it can be entered into /etc/shadow manually or with chpasswd. The latter requires a temporary new file, call it newpassword, with your loginid and password hash like this:

LoginidHere:$1$ywrU2ttf$yjm9OXTIBnoKJLQK2Fw5c/

The file can contain multiple lines for other accounts too.

Then, the sysadmin runs this as root:


chpasswd --encrypted < newpassword

Now, the new password is set. It's a good idea to change your password once you log in, unless you use a really strong passphrase. This is because the password hash, once exposed, is subject to off-line brute-force attacks, unless the password is really long.

This method of resetting passwords can be quite secure. For example, using this technique, someone could take the password hash published above, create an account, then tell the person the loginid and hostname and that the password hash above was used. Only the person who originally created the password hash could know the password, even though the password hash was published in a magazine.

By the way, the password for that hash is 28 completely random base64 characters long, so it should be extremely difficult to crack. But please, don't create any accounts with that hash because the password is also published, it's:

HXzNnCTo8k44k8v7iz4ZkR/QWkM2

That password and hash were created like this:

$ openssl rand 21 -base64
HXzNnCTo8k44k8v7iz4ZkR/QWkM2
$ openssl passwd -1 HXzNnCTo8k44k8v7iz4ZkR/QWkM2

These examples use the MD5 password hashes now common on Linux systems. If you need to use the old UNIX password hash, simply leave off the -1. For example:

$ openssl passwd
Password:
Verifying - Password:
xcx7DofWC0LpQ

The password for this last password hash example is: TheLinux.

Crypto Benchmarking

The many algorithms that OpenSSL supports makes it well suited for cryptographic benchmarking. This is useful for comparing the relative performance of different cryptographic algorithms and different hardware architectures using a consistent code base. And, it has a built-in benchmarking command.

The openssl speed command, by default, runs through every single algorithm in every single supported mode and option, with several different sizes of data. The different sizes are important because of algorithm start-up overhead.

A complete speed run takes about six minutes, regardless of hardware performance, and produces 124 lines of performance data with 29 lines of summary.

However, note that cryptographic algorithm performance is extremely dependent on the specific implementation. For higher performance, OpenSSL has x86 assembly code for several algorithms. Other architectures, such as ia64, SPARC and x86-64, have much less assembly code, and most others have none. The assembly code is located in these OpenSSL source code directories: crypto/*/asm. Excerpts of the speed report for three different systems are shown in Tables 2 and 3.

Table 2. Hash and Block Cipher Performance (The numbers are in 1,000s of bytes per second using 1,024-byte blocks.)

 AMD K6-2 300MHz, Linux 2.6.12, OpenSSL 0.9.7gAMD Athlon 1.333GHz, Linux 2.4.27, OpenSSL 0.9.7dPowerMac G5 1.6GHz, Darwin Kernel Version 8.0.0, OpenSSL 0.9.7b
md526,733.93k169,207.13k76,921.71k
sha112,665.41k113,973.25k76,187.82k
blowfish cbc9,663.40k56,940.54k44,433.14k
aes-128 cbc5,134.78k31,355.90k54,987.78k

Table 3. Public Key Crypto Performance

 sign/sverify/s 
rsa 1024 bits30.8563.1AMD K6-2 300MHz, Linux 2.6.12, OpenSSL 0.9.7g
dsa 1024 bits61.650.7AMD K6-2 300MHz, Linux 2.6.12, OpenSSL 0.9.7g
rsa 1024 bits239.94,514.6AMD Athlon 1.333 GHz, Linux 2.4.27, OpenSSL 0.9.7d
dsa 1024 bits498.2410.6AMD Athlon 1.333 GHz, Linux 2.4.27, OpenSSL 0.9.7d
rsa 1024 bits148.82,739.1PowerMac G5 1.6 GHz, Darwin Kernel Version 8.0.0, OpenSSL 0.9.7b
dsa 1024 bits289.5234.6PowerMac G5 1.6 GHz, Darwin Kernel Version 8.0.0, OpenSSL 0.9.7b
______________________

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState