{"id":1045,"date":"2015-06-07T17:26:34","date_gmt":"2015-06-07T17:26:34","guid":{"rendered":"http:\/\/fatsquirrel.org\/oldfartsalmanac\/?page_id=1045"},"modified":"2015-06-07T17:43:39","modified_gmt":"2015-06-07T17:43:39","slug":"the-joy-of-skey","status":"publish","type":"page","link":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/random\/the-joy-of-skey\/","title":{"rendered":"The Joy of S\/Key"},"content":{"rendered":"<p style=\"text-align: left;\">One Time Passwords (OTP) are certainly nothing new. In fact, they have been in use for<br \/>\nover ten years. The idea is essentially very simple: every time you login to a system, you use a different password. If someone were to eavesdrop on the connection, the password they captured would be<br \/>\nuseless to them.<\/p>\n<p style=\"text-align: left;\">In 1994, Neil Haller of Bellcore announced the \u201cS\/KEY One Time Password System\u201d<br \/>\nat the Symposium on Network and Distributed System Security. It described a practical way to implement OTP that was both secure and simple. Over the years it has matured into strong, practical system that is now described by RFC2289. Furthermore, implementations exist for many Operating Systems, and just about all BSD flavours include it as standard. Despite this, it is still rare, in my experience anyway, to encounter people that have even heard of it. As far as I can tell, there are two main reasons for its lack of popularity:<\/p>\n<ol>\n<li>In the days of SSH and encrypted traffic, people no longer think it&#8217;s necessary.<\/li>\n<li>In order to login to a system using S\/KEY, you need a computer to generate the next<br \/>\npassword, which raises the question of how you securely login to it.<\/li>\n<\/ol>\n<p>While both points appear valid, they are both flawed.<\/p>\n<p>It is true that SSH arguably does a better job of protecting passwords from eavesdroppers. In fact SSH provides for more than that, and it also protects all content from eavesdroppers. However there is one very common form of attack to which SSH is not immune: keylogging. Keyloggers record the keys you hit, and they don&#8217;t care whether<br \/>\nyou&#8217;re using an SSH client or telnet. They have to be installed on the machine you are using, either in software or hardware. However, now that we live in the age of Microsoft and Cybercafes, using a<br \/>\ntrojanised machine is all too easy to do. What most people don&#8217;t realise is that SSH, or at least OpenSSH, is already S\/KEY aware. So why not use it ?<\/p>\n<p>As for the second point, indeed you do need a computer. However &#8211; you, dear reader, almost certainly have a computer in your pocket or on your wrist at this moment. In fact, if your mobile phone is Java-enabled , which<br \/>\nthese days is quite likely, then you can use it to generate S\/KEY passwords. Very much like an RSA SecurID fob, only cheaper, and without a six-month lifespan.<\/p>\n<p>This article gives an introduction to S\/Key, together with an example of how to start using<br \/>\nit on OpenBSD. The final section of this article lists several links to further reading, S\/Key generators and details of using it on other Operating Systems.<\/p>\n<h2>The Guts<\/h2>\n<p>This section explains how S\/Key actually works. Feel free to skip it if you&#8217;re not interested although, in my opinion at least, it is not only interesting, but quite beautiful!<\/p>\n<p>A user wishing to use OTP to login to a server<br \/>\nmust first initialise the S\/Key system. The initialisation consists<br \/>\nof a short string provided by the server, known as the <i>seed,<\/i><br \/>\nand a secret passphrase provided by the user. The two strings are<br \/>\nconcatenated and passed through a hash function. RFC2289 allows for<br \/>\nthe use of three different hash functions: MD4, MD5 and SHA-1. The<br \/>\nchoice of hash is left up to the user.<\/p>\n<p>The output of the hash function is then reduced,<br \/>\nor <i>folded,<\/i> to 64-bits using a method described in the RFC.<br \/>\nThis 64-bit value, known as the<i>initial step,<\/i>is then<br \/>\npassed through the hash function, and again folded. This process<br \/>\ncontinues until the hash has been applied a number of times, let&#8217;s<br \/>\nsay 99. The server then stores the final output, together with the<br \/>\nseed value and the number of times the hash was applied, the<i><br \/>\nsequence number, <\/i>in the server&#8217;s<br \/>\nS\/Key database. The system is now ready to accept a login.<\/p>\n<p>When the user wishes to<br \/>\nlogin to the server, the server provides a <i>challenge,<\/i> which<br \/>\nconsists of the chosen hash, the seed and a number which is one less<br \/>\nthan the sequence number stored in the database; in this case, 98.<\/p>\n<p>The user then<br \/>\ngoes through the same procedure used to produce the initial step and<br \/>\nhashes it that number of times. The resulting 64-bit hash is<br \/>\nthe One Time Password.<\/p>\n<p>The user then conveys this password to the server<br \/>\n(more about this later).<\/p>\n<p>Remember that this is not going to be the same as<br \/>\nthe hash stored in the server&#8217;s S\/Key database, which has been hashed<br \/>\none more time. So, in order to compare it to that which is stored in<br \/>\nthe database , the server must hash the password one more time. If it<br \/>\nmatches, the user has demonstrated they know the passphrase and so<br \/>\nthey have successfully been authenticated. The server stores the<br \/>\npassword as provided by the user (i.e. before the server applied the<br \/>\nfinal hash) together with the new, lower, sequence number (98) in the<br \/>\ndatabase and logs the user in.<\/p>\n<p>The next time the user logs in, the sequence<br \/>\nnumber in the challenge will be the next lowest sequence number, in<br \/>\nthis case 97.<\/p>\n<p>From this we can infer:<\/p>\n<ul>\n<li>Eavesdroppers, or keyloggers, obtaining the<br \/>\npassword will find it of no use since the next login will require a<br \/>\ndifferent password.<\/li>\n<li>Even if someone gains access to the S\/Key<br \/>\ndatabase, the information will be useless to them, as they will need<br \/>\nto reverse the hash algorithm to find the next password.<\/li>\n<li>After all of the sequence numbers have been<br \/>\nexhausted, the user will need to re-initialise the system with a new<br \/>\nseed, and optionally a new passphrase. This is arguably a good side<br \/>\neffect.<\/li>\n<\/ul>\n<p>There is one significant step in the process that<br \/>\nhas been omitted thus far. Whilst the user may legitimately type the<br \/>\n8 digit hex number in response to the challenge, humans are<br \/>\nnotoriously averse to this sort of thing. Consequently, RFC2289 also<br \/>\nprovides a user-friendly way of expressing the 64-bit passphrase in<br \/>\nEnglish. A simple algorithm is provided, together with a small<br \/>\nlexicon, that describes a method by which any 64-bit string can be<br \/>\nconverted to a list of six words, and back again. For example, the<br \/>\n64-bit number:<\/p>\n<pre>3F3B F4B4 145F D74B\r\n<\/pre>\n<p>would be converted to the English words:<\/p>\n<pre>TAG SLOW NOV MIN WOOL KENO<\/pre>\n<p>For most users, this makes the whole procedure far<br \/>\nless painless and far more acceptable.<\/p>\n<h2>Using S\/KEY<\/h2>\n<p>Initially, the system<br \/>\nneeds to have S\/Key enabled. The superuser merely needs to issue the<br \/>\ncommand:<\/p>\n<pre>skeyinit -E<\/pre>\n<p>And the system will be available to all users.<\/p>\n<p>Each user that wishes to use S\/Key needs to initialise their account. The skeyinit(1)<br \/>\nprogram is used for this, too. In this example we plan to use SHA1<br \/>\nhashes, and so the command issued is:<\/p>\n<pre>skeyinit -sha1\r\n<\/pre>\n<p>The system responds with a warning and prompts the user to enter their current system password:<\/p>\n<pre>Reminder\r\n- Only use this method if you are directly connected\r\n          or have an encrypted channel.  If you are using telnet,\r\n          hit return now and use skeyinit -s.\r\nPassword:\r\n<\/pre>\n<p>If the authentication<br \/>\nwas successful, the user is then prompted for their secret<br \/>\npassphrase. In our example the passphrase is \u201cfred is dead\u201d:<\/p>\n<pre>[Updating zaphod with sha1]\r\nEnter secret passphrase: \r\nAgain secret passphrase:\r\n\r\nID zaphod skey is otp-sha1 99 dorm23705\r\nNext login password: MASK OMEN BOOM IRMA SMUG TORE\r\n<\/pre>\n<p>The account is now initialised, and skeyinit responds with the next<br \/>\nchallenge and corresponding password. You don&#8217;t need to know these at<br \/>\nthis stage but it&#8217;s comforting to know that everything is working.<\/p>\n<p>So,<br \/>\nlet&#8217;s try logging in. We ssh as normal, except we append &#8216;:skey&#8217; to<br \/>\nthe username. This tells ssh that we wish to use S\/Key<br \/>\nauthentication:<\/p>\n<pre>$ ssh -l zaphod:skey<\/pre>\n<p>The server then<br \/>\nresponds with a challenge:<\/p>\n<pre>otp-sha1 98 dorm23705\r\nS\/Key Password: \r\n<\/pre>\n<p>So,<br \/>\nusing our favourite S\/Key generator, we generate the password for<br \/>\nthis session. This simply involves supplying the generator with the<br \/>\nchallenge, which consists of the sequence number (\u201c98\u201d)<br \/>\nand seed (\u201cdorm23705\u201d), the hash type (&#8216;SHA1&#8217;),<br \/>\nand the secret passphrase (\u201cfred is dead\u201d).<\/p>\n<p>How these are supplied<br \/>\nto the generator depends entirely on generator used. For example, if<br \/>\nyou are logging in from a OpenBSD machine, you will probably use the<br \/>\nskey(1) command line tool. In this case the command issued would be:<\/p>\n<pre>skey-sha1 98 dorm23705\r\n<\/pre>\n<p>which will then prompt<br \/>\nyou for the passphrase.<\/p>\n<p>If, however, you are<br \/>\nusing vejotp, the challenge can be stored in the Java device&#8217;s memory<br \/>\nand so the most you will need to supply is the passphrase.<\/p>\n<p>Whichever S\/Key<br \/>\ngenerator you choose, the password in this case will be:<\/p>\n<pre>TWIG LET IFFY DATE RON CARL\r\n<\/pre>\n<p>Type this at the \u201cS\/Key<br \/>\nPassword\u201d prompt and, all being well, you&#8217;re in!<\/p>\n<p>The<br \/>\nnext time you wish to login, the challenge will be slightly<br \/>\ndifferent. The seed (\u201cdorm23705\u201d) will remain the same,<br \/>\nhowever the sequence number will be decreased by one (\u201c97\u201d).<br \/>\nYou&#8217;ll see that the password generated in response to this challenge<br \/>\nwill be completely different:<\/p>\n<pre>PAP LARK MULE DUMB FUSS WARD\r\n<\/pre>\n<p>If you use a BSD and<br \/>\nare concerned about security, then this simple, brilliant system is<br \/>\nalready there for you. It is not a replacement for SSH and other<br \/>\nforms of encrypted protocols, but it does provide additional security<br \/>\nfor a very small amount of extra effort. It also impresses the suits<br \/>\nwho, at last, have been forced to take security seriously.<\/p>\n<ul>\n<li><a href=\"http:\/\/www.openbsd.org\/faq\/faq8.html#SKey\">Using OTP on OpenBSD<\/a><\/li>\n<li><a href=\"http:\/\/www.freebsd.org\/doc\/en_US.ISO8859-1\/books\/handbook\/one-time-passwords.html\">Using OTP on FreeBSD<\/a><\/li>\n<li><a href=\"http:\/\/inner.net\/opieOPIE\">One Time Passwords In Everything.<\/a> A freely redistributable S\/Key compatible implementation:<\/li>\n<li><a href=\"http:\/\/www.cs.umd.edu\/~harry\/jotp\/\">JOTP a handy Java S\/Key password generator<\/a><\/li>\n<li><a href=\"http:\/\/motp.sourceforge.net\/\">Mobile OTP &#8211; a complete two factor authentication system.<\/a><\/li>\n<li><a href=\"http:\/\/www.fatsquirrel.org\/veghead\/software\/vejotp\/\">VeJOTP<\/a><br \/>\n\u2013 my own S\/Key password generator for Java enabled mobile<br \/>\nphones, based on JOTP (see above). Full source included.If you have WAP, the<br \/>\nsimplest way to install VeJOTP is by pointing your phone&#8217;s browser to<br \/>\nthe WAP site:<\/p>\n<p><a href=\"http:\/\/www.fatsquirrel.org\/wap\/\">http:\/\/www.fatsquirrel.org\/wap\/<\/a><\/li>\n<li><a href=\"http:\/\/www.mulliner.org\/wj\/\">Paranoia<\/a> \u2013 Closed<br \/>\nsource OTP Generator for certain Siemens mobile phones:<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>One Time Passwords (OTP) are certainly nothing new. In fact, they have been in use for over ten years. The idea is essentially very simple: every time you login to a system, you use a different password. If someone were to eavesdrop on the connection, the password they captured would be useless to them. In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1029,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-1045","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/pages\/1045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/comments?post=1045"}],"version-history":[{"count":3,"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/pages\/1045\/revisions"}],"predecessor-version":[{"id":1054,"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/pages\/1045\/revisions\/1054"}],"up":[{"embeddable":true,"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/pages\/1029"}],"wp:attachment":[{"href":"https:\/\/fatsquirrel.org\/oldfartsalmanac\/wp-json\/wp\/v2\/media?parent=1045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}