diff options
author | Ryan Thomas McBride <mcbride@cvs.openbsd.org> | 2013-06-04 18:49:13 +0000 |
---|---|---|
committer | Ryan Thomas McBride <mcbride@cvs.openbsd.org> | 2013-06-04 18:49:13 +0000 |
commit | dba87beac621601a216186c69e6dfdd1bd13705e (patch) | |
tree | 5f7b6d964a9c25a5822fee1c11a39aee13c4195e /libexec/login_yubikey | |
parent | 513df7a406bc38390e30ef82e751199c396d879a (diff) |
Add handling for keyboard layouts which break modhex (like dvorak and many
others); concept and keymap table (covering about 400 layouts) from
modhex.js by Daniel Holth.
ok sthen@, ok halex@ (who also provided much testing and feedback)
Diffstat (limited to 'libexec/login_yubikey')
-rw-r--r-- | libexec/login_yubikey/keymaps.h | 103 | ||||
-rw-r--r-- | libexec/login_yubikey/login_yubikey.c | 70 | ||||
-rw-r--r-- | libexec/login_yubikey/yubikey.c | 64 | ||||
-rw-r--r-- | libexec/login_yubikey/yubikey.h | 7 |
4 files changed, 214 insertions, 30 deletions
diff --git a/libexec/login_yubikey/keymaps.h b/libexec/login_yubikey/keymaps.h new file mode 100644 index 00000000000..80b9f145144 --- /dev/null +++ b/libexec/login_yubikey/keymaps.h @@ -0,0 +1,103 @@ +/* $OpenBSD: keymaps.h,v 1.1 2013/06/04 18:49:12 mcbride Exp $ */ + +/* + * Table based on modhex.js from http://dingoskidneys.com/~dholth/yubikey/ + * with the below license: + */ + +/* Nearly-any-keymap to modhex decoder +Copyright (c) 2009 Daniel Holth <dholth@fastmail.fm> +MIT license. */ + +static const wchar_t keymaps[][16] = { +{ 0x002C, 0x0079, 0x0075, 0x00E9, 0x0065, 0x0062, 0x0066, 0x0063, 0x0073, 0x0074, 0x006E, 0x0078, 0x0067, 0x002E, 0x0076, 0x0069 }, +{ 0x0063, 0x0062, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x0076 }, +{ 0x0063, 0x0062, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x1E63 }, +{ 0x0063, 0x0062, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0131, 0x006A, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x0076 }, +{ 0x0063, 0x0062, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0131, 0x00ED, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x0076 }, +{ 0x0063, 0x0062, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0131, 0x012D, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x0076 }, +{ 0x0063, 0x0062, 0x0064, 0x0065, 0x0161, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x0076 }, +{ 0x0063, 0x0062, 0x0073, 0x0066, 0x0074, 0x0064, 0x0068, 0x0075, 0x006E, 0x0065, 0x0069, 0x006B, 0x0070, 0x0067, 0x006C, 0x0076 }, +{ 0x0063, 0x0062, 0x0257, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x0076 }, +{ 0x0063, 0x017E, 0x0073, 0x0072, 0x0074, 0x006D, 0x0070, 0x0075, 0x006E, 0x0065, 0x0069, 0x0161, 0x006C, 0x0064, 0x006A, 0x0076 }, +{ 0x0067, 0x0077, 0x0063, 0x0062, 0x0064, 0x0074, 0x0068, 0x006F, 0x0065, 0x0061, 0x007A, 0x006E, 0x0079, 0x0075, 0x0073, 0x0076 }, +{ 0x006A, 0x006B, 0x0061, 0x002E, 0x006F, 0x0075, 0x006D, 0x0074, 0x0064, 0x0073, 0x0072, 0x0071, 0x0068, 0x0078, 0x006C, 0x0062 }, +{ 0x006A, 0x006B, 0x0061, 0x002E, 0x006F, 0x0075, 0x006D, 0x0074, 0x0064, 0x0073, 0x0072, 0x011D, 0x0068, 0x0109, 0x006C, 0x0062 }, +{ 0x006A, 0x0078, 0x0065, 0x002E, 0x0069, 0x0075, 0x0068, 0x0063, 0x0064, 0x0072, 0x006E, 0x0062, 0x0070, 0x0079, 0x0067, 0x006B }, +{ 0x006A, 0x0078, 0x0065, 0x002E, 0x0075, 0x0069, 0x0064, 0x0063, 0x0068, 0x0074, 0x006E, 0x0062, 0x0070, 0x0079, 0x0067, 0x006B }, +{ 0x006A, 0x0078, 0x0065, 0x00F1, 0x0075, 0x0069, 0x0064, 0x0063, 0x0072, 0x0074, 0x006E, 0x0062, 0x0070, 0x0079, 0x0067, 0x006B }, +{ 0x006A, 0x0078, 0x0065, 0x00F6, 0x0075, 0x0069, 0x0064, 0x0063, 0x0068, 0x0074, 0x006E, 0x0062, 0x0070, 0x0079, 0x0067, 0x006B }, +{ 0x0076, 0x00E7, 0x0065, 0x0078, 0x0061, 0x0075, 0x0074, 0x006E, 0x006B, 0x006D, 0x006C, 0x007A, 0x0069, 0x006F, 0x0072, 0x0063 }, +{ 0x0076, 0x00E7, 0x0065, 0x011F, 0x0061, 0x00FC, 0x0074, 0x006E, 0x006B, 0x006D, 0x006C, 0x007A, 0x0131, 0x006F, 0x0072, 0x0063 }, +{ 0x0078, 0x0069, 0x007A, 0x0071, 0x0061, 0x0065, 0x0068, 0x0075, 0x0074, 0x0064, 0x0063, 0x006E, 0x002E, 0x006F, 0x0073, 0x002C }, +{ 0x0078, 0x006B, 0x0069, 0x0070, 0x0065, 0x002C, 0x0063, 0x0064, 0x0074, 0x0073, 0x0072, 0x0027, 0x006F, 0x00E8, 0x0076, 0x002E }, +{ 0x00AF, 0x00A6, 0x00C9, 0x00BF, 0x00B8, 0x00C0, 0x0300, 0x00A8, 0x00BE, 0x00C1, 0x00BC, 0x00B6, 0x00BA, 0x00C5, 0x00C3, 0x00B1 }, +{ 0x00E4, 0x007A, 0x0061, 0x006C, 0x0065, 0x006F, 0x0073, 0x0067, 0x006E, 0x0072, 0x0074, 0x0062, 0x0063, 0x0077, 0x0068, 0x0070 }, +{ 0x010D, 0x00F1, 0x010F, 0x00E9, 0x00EB, 0x0155, 0x00FA, 0x00ED, 0x00FC, 0x00F4, 0x013E, 0x0148, 0x0159, 0x0165, 0x016F, 0x00E7 }, +{ 0x014B, 0x0062, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x0076 }, +{ 0x014B, 0x0062, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x0192, 0x006B, 0x006C, 0x006E, 0x0072, 0x0074, 0x0075, 0x0076 }, +{ 0x03C8, 0x03B2, 0x03B4, 0x03B5, 0x03C6, 0x03B3, 0x03B7, 0x03B9, 0x03BE, 0x03BA, 0x03BB, 0x03BD, 0x03C1, 0x03C4, 0x03B8, 0x03C9 }, +{ 0x0436, 0x0431, 0x0434, 0x0435, 0x0444, 0x0433, 0x04A3, 0x0438, 0x0439, 0x043A, 0x043B, 0x043D, 0x0440, 0x0442, 0x0443, 0x0432 }, +{ 0x0439, 0x0449, 0x0435, 0x002E, 0x0443, 0x0438, 0x0434, 0x0446, 0x0445, 0x0442, 0x043D, 0x0431, 0x043F, 0x044B, 0x0433, 0x043A }, +{ 0x0441, 0x0438, 0x0432, 0x0443, 0x0430, 0x043F, 0x0440, 0x0448, 0x043E, 0x043B, 0x0434, 0x0442, 0x043A, 0x0435, 0x0433, 0x043C }, +{ 0x0441, 0x0438, 0x049B, 0x0443, 0x0430, 0x043F, 0x0440, 0x0448, 0x043E, 0x043B, 0x0434, 0x0442, 0x043A, 0x0435, 0x0433, 0x043C }, +{ 0x0441, 0x0456, 0x0432, 0x0443, 0x0430, 0x043F, 0x0440, 0x0448, 0x043E, 0x043B, 0x0434, 0x0442, 0x043A, 0x0435, 0x0433, 0x043C }, +{ 0x0446, 0x0431, 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043D, 0x0440, 0x0442, 0x0443, 0x0432 }, +{ 0x0446, 0x0431, 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043D, 0x0440, 0x0442, 0x0443, 0x0436 }, +{ 0x0446, 0x0431, 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0438, 0x0458, 0x043A, 0x043B, 0x043D, 0x0440, 0x0442, 0x0443, 0x0432 }, +{ 0x0446, 0x0431, 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0456, 0x0439, 0x043A, 0x043B, 0x043D, 0x0440, 0x0442, 0x0443, 0x0436 }, +{ 0x0446, 0x0431, 0x0434, 0x0435, 0x0444, 0x0491, 0x0433, 0x0456, 0x0439, 0x043A, 0x043B, 0x043D, 0x0440, 0x0442, 0x0443, 0x0432 }, +{ 0x044A, 0x0444, 0x0430, 0x0435, 0x043E, 0x0436, 0x0433, 0x0441, 0x0442, 0x043D, 0x0432, 0x0445, 0x0438, 0x0448, 0x043A, 0x044D }, +{ 0x0451, 0x043C, 0x0431, 0x0443, 0x04E9, 0x0430, 0x0445, 0x0448, 0x0440, 0x043E, 0x043B, 0x0438, 0x0436, 0x044D, 0x0433, 0x0441 }, +{ 0x0563, 0x0562, 0x0564, 0x0567, 0x0586, 0x0584, 0x0570, 0x056B, 0x0573, 0x056F, 0x056C, 0x0576, 0x0580, 0x057F, 0x0568, 0x057E }, +{ 0x0563, 0x057A, 0x057F, 0x0567, 0x0586, 0x056F, 0x0570, 0x056B, 0x0573, 0x0584, 0x056C, 0x0576, 0x0580, 0x0564, 0x0568, 0x0582 }, +{ 0x0579, 0x0566, 0x0563, 0x0562, 0x0565, 0x0561, 0x0576, 0x056F, 0x056B, 0x057F, 0x0570, 0x056C, 0x057D, 0x0574, 0x0582, 0x0575 }, +{ 0x0581, 0x0562, 0x0564, 0x0565, 0x0586, 0x0563, 0x0570, 0x056B, 0x0575, 0x056F, 0x056C, 0x0576, 0x057C, 0x057F, 0x0582, 0x057E }, +{ 0x0581, 0x0562, 0x0564, 0x0565, 0x0586, 0x0563, 0x0570, 0x056B, 0x0575, 0x056F, 0x056C, 0x0576, 0x0580, 0x057F, 0x0582, 0x057E }, +{ 0x0584, 0x0562, 0x0564, 0x0567, 0x0586, 0x0563, 0x0570, 0x056B, 0x0573, 0x056F, 0x056C, 0x0576, 0x0580, 0x057F, 0x0568, 0x057E }, +{ 0x05D1, 0x05E0, 0x05D2, 0x05E7, 0x05DB, 0x05E2, 0x05D9, 0x05DF, 0x05D7, 0x05DC, 0x05DA, 0x05DE, 0x05E8, 0x05D0, 0x05D5, 0x05D4 }, +{ 0x0624, 0xFEFB, 0x064A, 0x062B, 0x0628, 0x0644, 0x0627, 0x0647, 0x062A, 0x0646, 0x0645, 0x0649, 0x0642, 0x0641, 0x0639, 0x0631 }, +{ 0x062C, 0x0628, 0x062F, 0x06D5, 0x0641, 0x06AF, 0x0647, 0x062D, 0x0698, 0x06A9, 0x0644, 0x0646, 0x0631, 0x062A, 0x0626, 0x06A4 }, +{ 0x0632, 0x0630, 0x06CC, 0x062B, 0x0628, 0x0644, 0x0627, 0x0647, 0x062A, 0x0646, 0x0645, 0x062F, 0x0642, 0x0641, 0x0639, 0x0631 }, +{ 0x0686, 0x0628, 0x062F, 0x0639, 0x0641, 0x06AF, 0x062D, 0x06CC, 0x062C, 0x06A9, 0x0644, 0x0646, 0x0631, 0x062A, 0x0621, 0x0637 }, +{ 0x0686, 0x0628, 0x062F, 0x0639, 0x0641, 0x06AF, 0x06BE, 0x06CC, 0x062C, 0x06A9, 0x0644, 0x0646, 0x0631, 0x062A, 0x0621, 0x0637 }, +{ 0x06D2, 0x0634, 0x0631, 0x06BE, 0x0646, 0x0644, 0x06C1, 0x0628, 0x0627, 0x06A9, 0x06CC, 0x063A, 0x062F, 0x0679, 0x062A, 0x0633 }, +{ 0x0724, 0x0712, 0x0715, 0x0716, 0x0714, 0x0713, 0x0717, 0x0725, 0x071B, 0x071F, 0x0720, 0x0722, 0x072A, 0x072C, 0x071C, 0x072B }, +{ 0x0724, 0x0727, 0x071D, 0x0716, 0x0712, 0x0720, 0x0710, 0x0717, 0x072C, 0x0722, 0x0721, 0x0700, 0x0729, 0x0726, 0x0725, 0x072A }, +{ 0x0797, 0x0784, 0x078B, 0x07AC, 0x078A, 0x078E, 0x0780, 0x07A8, 0x0796, 0x0786, 0x078D, 0x0782, 0x0783, 0x078C, 0x07AA, 0x0788 }, +{ 0x07D7, 0x07D3, 0x07D8, 0x07CD, 0x07DD, 0x07DC, 0x07E4, 0x07CC, 0x07D6, 0x07DE, 0x07DF, 0x07E3, 0x07D9, 0x07D5, 0x07CE, 0x07E2 }, +{ 0x091A, 0x092C, 0x0921, 0x0947, 0x0919, 0x0917, 0x0939, 0x093F, 0x091C, 0x0915, 0x0932, 0x0928, 0x0930, 0x091F, 0x0941, 0x0935 }, +{ 0x091A, 0x092C, 0x0926, 0x0947, 0x091F, 0x0917, 0x0939, 0x093F, 0x091C, 0x0915, 0x0932, 0x0928, 0x0930, 0x0924, 0x0941, 0x0921 }, +{ 0x091B, 0x092C, 0x0926, 0x0947, 0x0909, 0x0917, 0x0939, 0x093F, 0x091C, 0x0915, 0x0932, 0x0928, 0x0930, 0x0924, 0x0941, 0x0935 }, +{ 0x092E, 0x0935, 0x094D, 0x093E, 0x093F, 0x0941, 0x092A, 0x0917, 0x0930, 0x0915, 0x0924, 0x0932, 0x0940, 0x0942, 0x0939, 0x0928 }, +{ 0x099A, 0x09AC, 0x09A1, 0x09C0, 0x09A4, 0x0997, 0x09B9, 0x09BF, 0x099C, 0x0995, 0x09B2, 0x09A8, 0x09B0, 0x099F, 0x09C1, 0x0986 }, +{ 0x09AE, 0x09AC, 0x09CD, 0x09BE, 0x09BF, 0x09C1, 0x09AA, 0x0997, 0x09B0, 0x0995, 0x09A4, 0x09B2, 0x09C0, 0x09C2, 0x09B9, 0x09A8 }, +{ 0x09C7, 0x09A8, 0x09BF, 0x09A1, 0x09AC, 0x09CD, 0x09BE, 0x09B9, 0x0995, 0x09A4, 0x09A6, 0x09B8, 0x09AA, 0x099F, 0x099C, 0x09B0 }, +{ 0x0A1A, 0x0A2C, 0x0A4D, 0x0A3E, 0x0A3F, 0x0A41, 0x0A39, 0x0A17, 0x0A1C, 0x0A15, 0x0A32, 0x0A28, 0x0A40, 0x0A42, 0x0A26, 0x0A35 }, +{ 0x0A2E, 0x0A35, 0x0A4D, 0x0A3E, 0x0A3F, 0x0A41, 0x0A2A, 0x0A17, 0x0A30, 0x0A15, 0x0A24, 0x0A32, 0x0A40, 0x0A42, 0x0A39, 0x0A28 }, +{ 0x0AAE, 0x0AB5, 0x0ACD, 0x0ABE, 0x0ABF, 0x0AC1, 0x0AAA, 0x0A97, 0x0AB0, 0x0A95, 0x0AA4, 0x0AB2, 0x0AC0, 0x0AC2, 0x0AB9, 0x0AA8 }, +{ 0x0B2E, 0x0B35, 0x0B4D, 0x0B3E, 0x0B3F, 0x0B41, 0x0B2A, 0x0B17, 0x0B30, 0x0B15, 0x0B24, 0x0B32, 0x0B40, 0x0B42, 0x0B39, 0x0B28 }, +{ 0x0B89, 0x0BC6, 0x0BA9, 0x0BA8, 0x0B95, 0x0BAA, 0x0BBE, 0x0BC8, 0x0BA4, 0x0BAE, 0x0B9F, 0x0B94, 0x0B9A, 0x0BB5, 0x0BB0, 0x0B8E }, +{ 0x0C2E, 0x0C35, 0x0C4D, 0x0C3E, 0x0C3F, 0x0C41, 0x0C2A, 0x0C17, 0x0C30, 0x0C15, 0x0C24, 0x0C32, 0x0C40, 0x0C42, 0x0C39, 0x0C28 }, +{ 0x0CAE, 0x0CB5, 0x0CCD, 0x0CBE, 0x0CBF, 0x0CC1, 0x0CAA, 0x0C97, 0x0CB0, 0x0C95, 0x0CA4, 0x0CB2, 0x0CC0, 0x0CC2, 0x0CB9, 0x0CA8 }, +{ 0x0D1A, 0x0D2C, 0x0D26, 0x0D46, 0x0D2B, 0x0D17, 0x0D39, 0x0D3F, 0x0D1C, 0x0D15, 0x0D32, 0x0D28, 0x0D30, 0x0D24, 0x0D41, 0x0D35 }, +{ 0x0D2E, 0x0D35, 0x0D4D, 0x0D3E, 0x0D3F, 0x0D41, 0x0D2A, 0x0D17, 0x0D30, 0x0D15, 0x0D24, 0x0D32, 0x0D40, 0x0D42, 0x0D39, 0x0D28 }, +{ 0x0DA0, 0x0DB6, 0x0DAF, 0x0D91, 0x0DC6, 0x0D9C, 0x0DC4, 0x0D89, 0x0DA2, 0x0D9A, 0x0DBD, 0x0DB1, 0x0DBB, 0x0DAD, 0x0D8B, 0x0DC0 }, +{ 0x0E25, 0x0E34, 0x0E07, 0x0E22, 0x0E01, 0x0E31, 0x0E35, 0x0E21, 0x0E32, 0x0E19, 0x0E40, 0x0E04, 0x0E2D, 0x0E23, 0x0E14, 0x0E2B }, +{ 0x0E41, 0x0E34, 0x0E01, 0x0E33, 0x0E14, 0x0E40, 0x0E49, 0x0E23, 0x0E48, 0x0E32, 0x0E2A, 0x0E37, 0x0E1E, 0x0E30, 0x0E35, 0x0E2D }, +{ 0x0EC1, 0x0EB6, 0x0E81, 0x0EB3, 0x0E94, 0x0EC0, 0x0EC9, 0x0EA3, 0x0EC8, 0x0EB2, 0x0EAA, 0x0EB7, 0x0E9E, 0x0EB0, 0x0EB5, 0x0EAD }, +{ 0x0F40, 0x0F54, 0x0F51, 0x0F7A, 0x0F56, 0x0F44, 0x0F58, 0x0F72, 0x0F0B, 0x0F42, 0x0F63, 0x0F53, 0x0F62, 0x0F4F, 0x0F74, 0x0F41 }, +{ 0x0F60, 0x0F62, 0x0F51, 0x0F42, 0x0F53, 0x0F54, 0x0F55, 0x0F7C, 0x0F56, 0x0F58, 0x0F59, 0x0F63, 0x0F44, 0x0F72, 0x0F7A, 0x0F61 }, +{ 0x1019, 0x1017, 0x1039, 0x102C, 0x102D, 0x102F, 0x1015, 0x1002, 0x101B, 0x1000, 0x1010, 0x101C, 0x102E, 0x1030, 0x101F, 0x1014 }, +{ 0x10E1, 0x10D8, 0x10D5, 0x10E3, 0x10D0, 0x10DE, 0x10E0, 0x10E8, 0x10DD, 0x10DA, 0x10D3, 0x10E2, 0x10D9, 0x10D4, 0x10D2, 0x10DB }, +{ 0x10E7, 0x10DF, 0x10D0, 0x10E3, 0x10D4, 0x10DD, 0x10D3, 0x10DC, 0x10DB, 0x10E1, 0x10E0, 0x10D6, 0x10EB, 0x10ED, 0x10D7, 0x10E6 }, +{ 0x10EA, 0x10D1, 0x10D3, 0x10D4, 0x10E4, 0x10D2, 0x10F0, 0x10D8, 0x10EF, 0x10D9, 0x10DA, 0x10DC, 0x10E0, 0x10E2, 0x10E3, 0x10D5 }, +{ 0x1278, 0x1260, 0x12F0, 0x0065, 0x1348, 0x1308, 0x1200, 0x0069, 0x1300, 0x12A8, 0x1208, 0x1290, 0x1228, 0x1270, 0x0075, 0x1238 }, +{ 0x13D3, 0x13A8, 0x13D7, 0x13A1, 0x13A9, 0x13A6, 0x13AF, 0x13A2, 0x13DA, 0x13B8, 0x13B5, 0x13BE, 0x13DB, 0x13D4, 0x13A4, 0x13A5 }, +{ 0x1583, 0x1455, 0x1581, 0x157F, 0x146F, 0x1450, 0x14F1, 0x14C2, 0x14A7, 0x14C4, 0x14D7, 0x14F4, 0x146D, 0x144E, 0x14A5, 0x1472 }, +{ 0x1689, 0x1681, 0x1687, 0x1693, 0x1683, 0x168C, 0x1686, 0x1694, 0x1697, 0x1696, 0x1682, 0x1685, 0x168F, 0x1688, 0x1692, 0x168D }, +{ 0x1785, 0x1794, 0x178A, 0x17C1, 0x1790, 0x1784, 0x17A0, 0x17B7, 0x17D2, 0x1780, 0x179B, 0x1793, 0x179A, 0x178F, 0x17BB, 0x179C }, +{ 0x2D5B, 0x2D31, 0x2D37, 0x2D3B, 0x2D3C, 0x2D33, 0x2D40, 0x2D49, 0x2D4A, 0x2D3D, 0x2D4D, 0x2D4F, 0x2D54, 0x2D5C, 0x2D53, 0x2D56 }, +{ 0x30BD, 0x30B3, 0x30B7, 0x30A4, 0x30CF, 0x30AD, 0x30AF, 0x30CB, 0x30DE, 0x30CE, 0x30EA, 0x30DF, 0x30B9, 0x30AB, 0x30CA, 0x30D2 }, + }; +#define YUBIKEY_KEYMAP_COUNT 89 diff --git a/libexec/login_yubikey/login_yubikey.c b/libexec/login_yubikey/login_yubikey.c index 0a5d2477864..2468ba53331 100644 --- a/libexec/login_yubikey/login_yubikey.c +++ b/libexec/login_yubikey/login_yubikey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: login_yubikey.c,v 1.5 2012/12/23 00:50:44 halex Exp $ */ +/* $OpenBSD: login_yubikey.c,v 1.6 2013/06/04 18:49:12 mcbride Exp $ */ /* * Copyright (c) 2010 Daniel Hartmeier <daniel@benzedrine.cx> @@ -43,6 +43,7 @@ #include <string.h> #include <syslog.h> #include <unistd.h> +#include <errno.h> #include "yubikey.h" @@ -183,14 +184,7 @@ yubikey_login(const char *username, const char *password) FILE *f; yubikey_token_st tok; u_int32_t last_ctr = 0, ctr; - - if (strlen(password) > 32) - password = password + strlen(password) - 32; - if (strlen(password) != 32) { - syslog(LOG_INFO, "user %s: password len %zu != 32", - username, strlen(password)); - return (AUTH_FAILED); - } + int r, i = 0, mapok = 0, crcok = 0; snprintf(fn, sizeof(fn), "%s/%s.uid", path, username); if ((f = fopen(fn, "r")) == NULL) { @@ -229,22 +223,54 @@ yubikey_login(const char *username, const char *password) yubikey_hex_decode(uid, hexuid, YUBIKEY_UID_SIZE); yubikey_hex_decode(key, hexkey, YUBIKEY_KEY_SIZE); - yubikey_parse((uint8_t *)password, (uint8_t *)key, &tok); - if (!yubikey_crc_ok_p((uint8_t *)&tok)) { - syslog(LOG_DEBUG, "user %s: crc %04x failed: %s", - username, tok.crc, password); - return (AUTH_FAILED); - } - syslog(LOG_DEBUG, "user %s: crc %04x ok", username, tok.crc); - if (memcmp(tok.uid, uid, YUBIKEY_UID_SIZE)) { - char h[13]; + /* + * Cycle through the key mapping table. + * XXX brute force, unoptimized; a lookup table for valid mappings may + * be appropriate. + */ + while (1) { + r = yubikey_parse((uint8_t *)password, (uint8_t *)key, &tok, i++); + switch (r) { + case EMSGSIZE: + syslog(LOG_INFO, "user %s failed: password %s: %s", + username, password, "too short."); + return (AUTH_FAILED); + case EINVAL: /* keyboard mapping invalid */ + continue; + case 0: /* found a valid keyboard mapping */ + mapok++; + if (!yubikey_crc_ok_p((uint8_t *)&tok)) + continue; /* try another one */ + crcok++; + syslog(LOG_DEBUG, "user %s: crc %04x ok", + username, tok.crc); - yubikey_hex_encode(h, (const char *)tok.uid, YUBIKEY_UID_SIZE); - syslog(LOG_INFO, "user %s: uid %s != %s", username, h, hexuid); - return (AUTH_FAILED); + if (memcmp(tok.uid, uid, YUBIKEY_UID_SIZE)) { + char h[13]; + + yubikey_hex_encode(h, (const char *)tok.uid, + YUBIKEY_UID_SIZE); + syslog(LOG_DEBUG, "user %s: uid %s != %s", + username, h, hexuid); + continue; /* try another one */ + } + break; /* uid matches */ + case -1: + syslog(LOG_INFO, "user %s: %p could not decode " + "with any keymap (%d crc ok)", + username, password, crcok); + return (AUTH_FAILED); + default: + syslog(LOG_DEBUG, "user %s failed: %s: %s", + username, password, strerror(r)); + return (AUTH_FAILED); + } + break; /* only reached through the bottom of case 0 */ } - syslog(LOG_DEBUG, "user %s: uid %s matches", username, hexuid); + + syslog(LOG_INFO, "user %s uid %s: %d matching keymaps (%d checked), " + "%d crc ok", username, hexuid, mapok, i, crcok); ctr = ((u_int32_t)yubikey_counter(tok.ctr) << 8) | tok.use; if (ctr <= last_ctr) { diff --git a/libexec/login_yubikey/yubikey.c b/libexec/login_yubikey/yubikey.c index 92de3afc7bb..69b11c1dfba 100644 --- a/libexec/login_yubikey/yubikey.c +++ b/libexec/login_yubikey/yubikey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: yubikey.c,v 1.3 2012/11/23 23:53:54 halex Exp $ */ +/* $OpenBSD: yubikey.c,v 1.4 2013/06/04 18:49:12 mcbride Exp $ */ /* * Written by Simon Josefsson <simon@josefsson.org>. @@ -33,8 +33,13 @@ */ #include <ctype.h> +#include <stdlib.h> +#include <wchar.h> +#include <locale.h> +#include <errno.h> #include "yubikey.h" +#include "keymaps.h" static const uint8_t RC[] = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36 @@ -299,11 +304,60 @@ yubikey_modhex_decode(char *dst, const char *src, size_t dstSize) *dst++ = 0; } -void -yubikey_parse(const uint8_t token[32], const uint8_t key[16], - yubikey_token_t out) +uint8_t +yubikey_keymap_decode(wchar_t *wpassword, char *token, int index) { + int c, j, found; + for (j=0; j<YUBIKEY_TOKEN_SIZE; j++) { + found = 0; + for (c=0; c<16; c++) { + if (wpassword[j] == keymaps[index][c]) { + token[j] = modhex_trans[c]; + found++; + break; + } + } + if (found == 0) + return 1; + } + return 0; +} + +int +yubikey_parse(const uint8_t *password, const uint8_t key[YUBIKEY_KEY_SIZE], + yubikey_token_t out, int index) +{ + wchar_t *wpassword, *pp; + char token[YUBIKEY_TOKEN_SIZE + 1], *lc_ctype; + int len; + + if (index < 0 || index >= YUBIKEY_KEYMAP_COUNT) + return -1; + + len = strlen(password); + pp = wpassword = malloc(sizeof(wchar_t) * (len + 1)); + if (pp == NULL) + return ENOMEM; + memset(out, 0, sizeof(*out)); - yubikey_modhex_decode((void *)out, (char *)token, sizeof(*out)); + memset(token, 0, YUBIKEY_TOKEN_SIZE + 1); + + lc_ctype = getenv("LC_CTYPE"); + setlocale(LC_CTYPE, lc_ctype ? lc_ctype : "C.UTF-8"); + len = mbstowcs(wpassword, password, len); + if (len < 0) { + return errno; + } + setlocale(LC_CTYPE, "C"); + + if (len > YUBIKEY_TOKEN_SIZE) + pp = pp + len - YUBIKEY_TOKEN_SIZE; + if (len < YUBIKEY_TOKEN_SIZE) + return EMSGSIZE; + + if (yubikey_keymap_decode(pp, token, index)) + return EINVAL; + yubikey_modhex_decode((void *)out, token, sizeof(*out)); yubikey_aes_decrypt((void *)out, key); + return 0; } diff --git a/libexec/login_yubikey/yubikey.h b/libexec/login_yubikey/yubikey.h index e260983296d..a5f134828b1 100644 --- a/libexec/login_yubikey/yubikey.h +++ b/libexec/login_yubikey/yubikey.h @@ -1,4 +1,4 @@ -/* $OpenBSD: yubikey.h,v 1.2 2012/01/31 16:58:38 sobrado Exp $ */ +/* $OpenBSD: yubikey.h,v 1.3 2013/06/04 18:49:12 mcbride Exp $ */ /* * Written by Simon Josefsson <simon@josefsson.org>. @@ -40,6 +40,7 @@ #define YUBIKEY_BLOCK_SIZE 16 #define YUBIKEY_KEY_SIZE 16 +#define YUBIKEY_TOKEN_SIZE 32 #define YUBIKEY_UID_SIZE 6 #define YUBIKEY_CRC_OK_RESIDUE 0xf0b8 @@ -60,8 +61,8 @@ typedef struct { typedef yubikey_token_st *yubikey_token_t; -extern void yubikey_parse(const uint8_t token[YUBIKEY_BLOCK_SIZE], - const uint8_t key[YUBIKEY_KEY_SIZE], yubikey_token_t out); +extern int yubikey_parse(const uint8_t token[YUBIKEY_BLOCK_SIZE], + const uint8_t key[YUBIKEY_KEY_SIZE], yubikey_token_t out, int index); extern void yubikey_modhex_decode(char *dst, const char *src, size_t dstsize); |