Secure authentication with one-time passwords
Whispered Once
A one-time password won't compromise security if it falls in the wrong hands. OPIE and OTPW bring the safety of one-time password security to Linux.
Despite the biometrics boom, passwords are still the most popular means of authentication. In hostile environments, rogue users try to sniff or log password entries. You can foil these attempts by using one-time passwords. A one-time password becomes obsolete after it is used.
Even if an attacker were to sniff the password en route to the authentication server, the password would be useless.For a one-time password to work, the client must have some means for determining what password to use, and the server must know what password to expect.
Techniques
Security experts have developed several techniques for generating one-time passwords. Some methods base a new password on a mathematical manipulation of the previous password – or on a mathematical manipulation of the current time. Another technique known as challenge-response starts with the server sending a random number to the client. The client then calculates a response using a process that is known to both parties.
Of course, an attacker who sniffs a couple of these challenges and responses could theoretically uncover the method. This crypto-analysis technique, which is often called known plaintext, has been described in several scientific publications. But if both partners apply a hash function after calculating the response, a sniffer will find it far more difficult to uncover the original value. The result looks very much like a random number.
These kinds of calculations are difficult to do in your head, so users often employ an electronic device called a token, which looks something like a pocket calculator. Figures 1 and 2 show examples of some popular tokens. Another option is to set up a mobile phone or PDA with the necessary software to act as a hardware-based token.
Software-Based Solutions
Of course, tokens are relatively expensive; also, the technology is often patented, or else the internal mechanisms are not fully disclosed as a security measure. If you prefer to avoid the effort and expense of a hardware token, you can also use a software-only solution.
Software-based one-time password systems have been around for several years are are even enshrined in a number of Internet RFCs. The S/Key system, which was developed in 1995 by Bellcore, is defined in RFC 1760. S/Key originally relied on MD4 encryption. Its successor, OTP, which is specified in RFC 2289, can also use MD5 and SHA hashes.
Understanding S/Key and OTP
A one-time password system consists of a server and a generator. Users are required to authenticate against the server, and the generator calculates the one-time password for this purpose. The mathematical underpinnings are provided by hash functions or irreversible algorithms: S/Key uses MD4, and OTP uses MD4, MD5, and SHA. The algorithm ensures that an attacker cannot deduce the next password just by gaining knowledge of its predecessor.
Users need to initialize the OTP system on the server side by choosing a password. The server appends a random, or user-defined, seed to the password string (Figure 3) and hashes the resulting string n times to generate the first one-time password. Finally, the server stores the username, the seed, the figure n, and the OTP.
A user wanting to authenticate against the server is sent a challenge including the seed and the figure n-1 (Figure 4). The local generator helps the user calculate a one-time password. This calculation is basically the same as the server-side initialization phase, the difference being that the hash is only run n-1 times.
The user sends the results to the server, which then hashes the incoming string once more and compares the results with the one-time password it has stored. If the two hashes match, everything is okay; the server stores the OTP passed in to it, instead of the original OTP, and decrements n by one.
OTP-managed passwords are 64-bit values from a technical point of view, however, users can enter them in the form of short words. A program would convert an entry such as TUSK JOIN ROBE HUNK HAVE CARL to the internal bit representation.
With OTP providing the cryptographic underpinnings, it is just a question of integrating this framework with the various authentication programs on Linux. These programs include login and sudo, session managers such as xdm, kdm, and gdm, or external services such as the SSH daemon or FTP servers. Linux uses Pluggable Authentication Modules (PAM, [5]) to provide a standardized interface.
If you use one-time passwords to authenticate, you need to add a line to the auth section of your PAM configuration. The required control flag depends on the configuration of your auth stack and the desired system behavior.
Universal OPIE
A pair of open source projects known as OPIE [3] and OTPW [4] provide one-time password tools for Linux. The leading OTP software implementation on Linux comes courtesy of the OPIE project (One-Time Passwords in Everything).
OPIE is easily installed from the packages that exist for many distributions, and easily built from the sources. The installation adds OTP-capable programs for login, su, and ftpd, as well as the pam_opie.so library, a number of tools, and the /etc/opiekeys configuration.
The first step is to initialize the OTP system (see Listing 1). Users handle this step themselves by logging on to the system and executing the opiepasswd command (Line 1). The results might be confusing at first glance (Line 3); by default, the tool assumes that the user is not logged on locally at the console.
Listing 1
Initializing OPIE
Because network traffic is often sniffable and insecure, opiepasswd expects an OTP. To avoid a chicken and egg problem, users must declare (by setting the -c option) that they are working at the secure console (see Line 8 in Listing 1).
If the command catches the user lying, it will refuse to cooperate. Users who take security seriously should avoid the -f option (Line 17), which ignores the subsequent warning.
The process is user-specific; in other words, any user wanting to work with one-time passwords needs to run the command individually.
After completing the initialization, a user entry is added to the /etc/opiekeys file. This file also contains the seed (te5843 in this case), the hash (6f1dba738c197a64), the newly-generated one-time password, and the sequence number (499 in this example – Lines 31 and 32).
To generate valid one-time passwords later, users need their own password, the seed, and the sequence number. There is no need to memorize all this – with the exception of the user password. The other two credentials are provided and displayed by the server.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.