OpenSSL is more than just an open source SSL library implementation.

It can be used to create, request, sign, and revoke certificates and can also be used to perform other cryptographic operations such as creating hashes for files, testing SSL connections, and more. This week, we'll take a look at some of the interesting things that can be done with the openssl command-line program.

To test SSL connections to a mail server, use the openssl command with the s_client parameter:

$ openssl s_client -connect smtp.myhost.com:25 -starttls smtp

This essentially opens a telnet-like connection to smtp.myhost.com on port 25 using the STARTTLS extension. This is an interactive session, so you can send commands to the remote SMTP server as well as view the certificate used, view the details of the SSL session, and more. To test SMTP over SSL, don't use the -starttls option:

$ openssl s_client -connect smtp.myhost.com:465

The above can also be used to connect to any service that uses SSL, such as HTTPS (port 443), POP3 over SSL (port 995), and so forth.

The openssl command can also be used to create digests of a file, which can be used to verify that a file has not been tampered with:

$ echo "test file"> foo.txt

$ openssl dgst -md5 foo.txt

MD5(foo.txt)= b05403212c66bdc8ccc597fedf6cd5fe

$ openssl dgst -sha1 foo.txt

SHA1(foo.txt)= 0181d93fee60b818e3f92e470ea97a2aff4ca56a

To view the other message digests that can be used, look at the output of openssl list-message-digest-commands.

You can also use openssl to encrypt files. To view the list of available ciphers, use openssl list-cipher-commands. Once you've chosen a cipher to use, you can encrypt the file using the following commands:

$ openssl enc -aes-256-cbc -salt -in foo.txt -out foo.enc

enter aes-256-cbc encryption password:

Verifying - enter aes-256-cbc encryption password:

$ file foo.enc

foo.enc: data

$ cat foo.enc

Salted__yvi{!e????i"Yt?;(Ѱ e%
$ openssl enc -d -aes-256-cbc -in foo.enc

enter aes-256-cbc decryption password:

test file

In the above example, the file foo.txt was encrypted using 256-bit AES in CBC mode, the encrypted copy being saved as the file foo.enc. Looking at the contents of the file provide gibberish. Decrypting the file is done using the -d option; however, keep in mind that not only do you need to remember the password, you also need to know the cipher used.

As you can see, OpenSSL provides more than just a library for other applications to use, and the openssl command-line binary is a powerful program in its own right, allowing for many uses.

Advertisement

Open Sourcery This was published in Open Sourcery, check every Monday for more stories

Related links

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

Log in


Sign up | Forgot your password?

  • Lana Kovacevic What's new in GWT 1.5?

    I recently wrote an introduction to the Google Web Toolkit based on Lars Rasmussen's session at the Google Developer Day 2008 in Sydney. Following the introductory session Lars gave us a deeper insight into GWT, particularly what's new in version 1.5. Read more »

    -- posted by Lana Kovacevic

  • Lana Kovacevic The Portal of the Future

    At this year's Gartner Application Development, Integration and Web Services Summit, I attended Gene Phifer talk: "Portal of the Future: What's Beyond Web 2.0?". Read more »

    -- posted by Lana Kovacevic

  • Staff Google's new foray into image search

    Google is developing visual crawling software that can be used for facial recognition and scene analysis. In addition images can be matched with display ads and utilise geotagging information for various applications. Read more »

    -- posted by Staff

What's on?

  • Club Builder: Sports, Gates and Gears

    This week on Club Builder: Steve Ballmer gives a teary goodbye to Bill Gates, Mark Taylor moves into IT endorsements and we ask some Google Gears questions.