Secure authentication with one-time passwords

Safety Net

The next step is to integrate the authentication mechanism with the PAM stack (see Listing 2). The pam_unix or pam_unix2 modules do most of the work. These modules are tagged with a sufficient control flag, but as you want to replace the pam_unix.so or pam_unix2.so libraries with the pam_opie.so library, you should modify the configuration accordingly.

Listing 2

pam_opie.so

 

Note that it is possible to configure your system so that, if OPIE fails for any reason, users can still use legacy passwords to authenticate.

Once you have modified the PAM configuration, your system is OTP-capable. Some services, such as the SSH daemon, still need some manual attention before they start using one-time passwords. In the case of SSH, you need the following line in the server configuration file /etc/sshd/sshd_config:

ChallengeResponseAuthenticationyes

Listing 3 shows an SSH login using OPIE. After successfully authenticating, OPIE updates the /etc/opiekeys file, adding the new sequence number and the hash of the last password used.

Listing 3

SSH Login with OPIE

 

Sowing and Harvesting

Users need opiekey to generate one-time passwords. The generator in Listing 4 expects the user password, the seed, and the current sequence number. Users can run opieinfo to view this information. OPIE also has a mechanism that generates a list of OTPs in case a user doesn't have a generator.

Listing 4

Creating three OTPs with opiekey

 

Other generators in addition to opiekey are also available. The Java program JOTP [6] will run on a Java-capable cellphone or on a normal website, although the website must be trustworthy. Palm owners can run Palmkey [7] or Pilotp [8], and desktop users can run Optcalc [9].

The opiepasswd -d command disables a user entry in /etc/opiekeys and thus bans the user from the OPIE system (see Listing 5). The system overwrites the password hash with a series of asterisks (*), although the sequence number and seed remain visible.

Listing 5

Disabling OPIE for a User

 

Pluggable Authentication Modules (PAM)

PAM defines four categories for the authentication process: auth, account, password, and session. The auth category handles the authentication itself, while password defines whether and how a user can change their password. PAM uses account to manage access based on the user account and session to handle the environment setup.

PAM has a selection of various modules in each category and organizes them in a stack. Each module is tagged with a control flag. This approach lets admins define how PAM reacts to successful or unsuccessful processing of a module. The following flags exist: required, requisite, sufficient, and optional. If a module flagged required, requisite, or sufficient fails, the complete authentication process fails. If the module is tagged requisite, PAM immediately stops processing the stack.

After successfully processing a module flagged required, requisite, or optional, the next PAM library steps up. PAM views the category as successfully processed if the module is flagged sufficient.

The OTPW Alternative

The OTPW software-based solution does not use the method specified by RFC 2289 but relies instead on a 160-bit version of the RIPEMD hash. OTPW includes a modified version of the program login (demologin) and an alternative module for integration with the PAM stack. Users are issued passwords in the form of a list, which is similar to the legacy TAN lists issued by banks.

When authenticating, the user types a string comprising the list entry and their own password. The OTPW server stores the RIPEMD hashes of all valid one-time passwords (along with a number) in the .otpw file below the user's home directory. The program overwrites used passwords with dashes, thus preventing reuse.

The OTPW package is far smaller than OPIE; the source code comprises just 18 files. A simple make will create the demologin and otpw-gen programs, as well as the pam_otpw.so PAM library.

For Linux systems with PAM, OTPW requires only the otpw-gen generator and the pam_otpw module. The user initializes the OTPW system by running otpw-gen (Listing 6). After entering a password, otpw-gen creates a list of OTPs and displays the results.

Listing 6

Setting up OTPW

 

The -p1 parameter tells otpw-gen to output the OTPs as a list of four-letter words, for example:

hare lane fyfe self lucy

Deleting the .otpw file disables the use of one-time passwords for the account.

It makes sense to print the list. Users are responsible for keeping track of how many valid one-time passwords they still have.

If you want to save paper, check the content of .otpw when you log in. Used OTPs are tagged with -. Integration of OTPW with the PAM system follows the same steps as for OPIE.

According to the documentation, adding this entry

session optional pam_otpw.so

tells OTPW to let you know how many OTPs you have left when you log in. This command did not work in our lab. The manual steps for the SSH daemon are similar to those for OPIE.

Users create one-time passwords by concatenating their user passwords with the strings in the list generated by otpw-gen.

When a user attempts to log in, OTPW creates a symbolic link for .otpw.lock in the user's home directory. If the user cancels the login attempt by pressing Ctrl+C, the symbolic link is kept. The user is locked out while the link exists, as it prevents the use of OTPW.

On top of this, OTPW does not normally support simultaneous logins for security reasons. According to the program documentation, the user enters an extended one-time password in this case. The extended OTP comprises the user password and three strings from the list. We were unable to test this behavior in our lab.

One-time passwords are useful for insecure environments with a danger of password sniffing. The OPIE and OTPW implementations are easily integrated with popular Linux distributions thanks to PAM.

Infos

  1. Digipass 300 Pro: http://www.vasco.com
  2. RSA Secur ID: http://www.rsa.com
  3. Onetime Password In Everything (OPIE): http://www.inner.net/opie
  4. One-Time Password (OTPW): http://www.cl.cam.ac.uk/~mgk25/otpw.html
  5. Pluggable Authentication Modules (PAM): http://www.kernel.org/pub/linux/libs/pam/
  6. Java OTP Calculator (JOTP): http://www.cs.umd.edu/~harry/jotp/
  7. Palmkey: http://palmkey.sf.net
  8. Pilot OTP Generator: http://www.valdes.us/palm/pilOTP/
  9. OTP and S/Key Calculator for X-Window: http://killa.net/infosec/otpCalc/

The Author

Dr. Udo Seidel is math and physics teacher who has been a big Linux fan since 1996. Since completing his PhD, he has worked as a Linux/Unix trainer, system administrator, and senior solution engineer. Today, he heads the Linux/Unix team at Amadeus Data Processing GmbH in Erding, Germany.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Smart Access Intro

    Maybe password security isn't perfect, but most networks depend on it. This month we examine some tools for smarter, more versatile authentication.

  • Secure Online Passwords

    Securely storing passwords online can be a complex task. With a few tools, websites can offer better security, but users still need to choose their passwords wisely.

  • Nitrokey Pro 2

    The Nitrokey Pro 2 is a small device that covers a wide range of cryptographic functions.

  • 2FA

    Protect your system from unwanted visitors with two-factor authentication.

  • OpenKubus

    If you are ready to experiment, an OpenKubus USB stick just might solve your password problems.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News