yubikey 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,6 @@
1
1
  #include "ruby.h"
2
2
  #include "yubikey.h"
3
3
 
4
- /*
5
- * call-seq:
6
- * decode(modhex_string) -> string
7
- *
8
- * Decode a ModHex string into binary data
9
- */
10
- static VALUE
11
- modhex_decode(VALUE self, VALUE modhex_string) {
12
- char* modhex_string_ptr = StringValuePtr(modhex_string);
13
- size_t modhex_string_size = strlen(modhex_string_ptr);
14
- size_t decoded_string_size = modhex_string_size/2;
15
- char* decoded_string;
16
-
17
- if (modhex_string_size % 2 != 0)
18
- rb_raise(rb_eArgError, "ModHex string length is not even");
19
-
20
- yubikey_modhex_decode(decoded_string, modhex_string_ptr, modhex_string_size);
21
-
22
- return rb_str_new(decoded_string, decoded_string_size);
23
- }
24
-
25
4
  /*
26
5
  * call-seq:
27
6
  * decrypt(state, key) -> plaintext
@@ -67,10 +46,8 @@ void
67
46
  Init_yubikey_ext() {
68
47
  VALUE rb_mYubikey = rb_define_module("Yubikey");
69
48
  VALUE rb_mYubikeyAES = rb_define_module_under(rb_mYubikey, "AES");
70
- VALUE rb_mYubikeyModHex = rb_define_module_under(rb_mYubikey, "ModHex");
71
49
  VALUE rb_mYubikeyCRC = rb_define_module_under(rb_mYubikey, "CRC");
72
-
73
- rb_define_module_function(rb_mYubikeyModHex, "decode", modhex_decode, 1);
50
+
74
51
  rb_define_module_function(rb_mYubikeyAES, "decrypt", aes_decrypt, 2);
75
52
  rb_define_module_function(rb_mYubikeyCRC, "valid?", crc_check, 1);
76
53
  }
data/lib/yubikey.rb CHANGED
@@ -3,4 +3,5 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  require 'yubikey_ext'
5
5
  require 'yubikey/hex'
6
+ require 'yubikey/modhex'
6
7
  require 'yubikey/otp'
@@ -0,0 +1,39 @@
1
+ module Yubikey::ModHex
2
+
3
+ TRANS = 'cbdefghijklnrtuv'.split(//)
4
+
5
+ # Decode a ModHex string into binary data
6
+ def self.decode(modhex_string)
7
+ out = ''
8
+ flag = true # to switch between first and last nibble
9
+ byte = 0
10
+
11
+ raise ArgumentError, "ModHex string length is not even" unless modhex_string.length % 2 == 0
12
+
13
+ modhex_string.each_byte do |b|
14
+ x = TRANS.index(b.chr) # lookup occurrence in table
15
+ if flag
16
+ byte = x
17
+ else
18
+ byte = (byte << 4) | x
19
+ out <<= byte.chr
20
+ end
21
+ flag = !flag
22
+ end
23
+
24
+ out
25
+ end
26
+
27
+ # Encode a binary string into ModHex
28
+ def self.encode(string)
29
+ out = ''
30
+
31
+ string.each_byte do |b|
32
+ out <<= TRANS[(b >> 4) & 0xF]
33
+ out <<= TRANS[b & 0xF]
34
+ end
35
+
36
+ out
37
+ end
38
+
39
+ end # Yubikey::ModHex
@@ -4,22 +4,6 @@ $:.unshift File.dirname(__FILE__) + '/../ext/yubikey_ext'
4
4
  require 'yubikey_ext.so'
5
5
 
6
6
  describe 'yubikey_ext' do
7
- it 'should decode modhex' do
8
- Yubikey::ModHex.decode('hknhfjbrjnlnldnhcujvddbikngjrtgh').should == "i\266H\034\213\253\242\266\016\217\"\027\233X\315V"
9
- Yubikey::ModHex.decode('urtubjtnuihvntcreeeecvbregfjibtn').should == "\354\336\030\333\347o\275\f33\017\0345Hq\333"
10
-
11
- Yubikey::ModHex.decode('dteffuje').should == "-4N\203"
12
-
13
- Yubikey::ModHex.decode('ifhgieif').should == 'test'
14
- Yubikey::ModHex.decode('hhhvhvhdhbid').should == 'foobar'
15
-
16
- Yubikey::ModHex.decode('cc').should == "\000"
17
- end
18
-
19
- it 'should raise if modhex string length uneven' do
20
- lambda { Yubikey::ModHex.decode('ifh') }.should raise_error(ArgumentError)
21
- end
22
-
23
7
  it 'should decrypt aes' do
24
8
  key = '72992427a3b8ccd20697493b5532561f'.to_bin
25
9
  state = 'ddf43aec57366784e061a12f767e728a'.to_bin
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'Yubikey::Modhex' do
4
+ it 'should decode modhex' do
5
+ Yubikey::ModHex.decode('hknhfjbrjnlnldnhcujvddbikngjrtgh').should == "i\266H\034\213\253\242\266\016\217\"\027\233X\315V"
6
+ Yubikey::ModHex.decode('urtubjtnuihvntcreeeecvbregfjibtn').should == "\354\336\030\333\347o\275\f33\017\0345Hq\333"
7
+
8
+ Yubikey::ModHex.decode('dteffuje').should == "-4N\203"
9
+
10
+ Yubikey::ModHex.decode('ifhgieif').should == 'test'
11
+ Yubikey::ModHex.decode('hhhvhvhdhbid').should == 'foobar'
12
+
13
+ Yubikey::ModHex.decode('cc').should == "\000"
14
+ end
15
+
16
+ it 'should raise if modhex string length uneven' do
17
+ lambda { Yubikey::ModHex.decode('ifh') }.should raise_error(ArgumentError)
18
+ end
19
+
20
+ it 'should encode modhex' do
21
+ Yubikey::ModHex.encode("i\266H\034\213\253\242\266\016\217\"\027\233X\315V").should == 'hknhfjbrjnlnldnhcujvddbikngjrtgh'
22
+ Yubikey::ModHex.encode("\354\336\030\333\347o\275\f33\017\0345Hq\333").should == 'urtubjtnuihvntcreeeecvbregfjibtn'
23
+
24
+ Yubikey::ModHex.encode("-4N\203").should == 'dteffuje'
25
+
26
+ Yubikey::ModHex.encode('test').should == 'ifhgieif'
27
+ Yubikey::ModHex.encode('foobar').should == 'hhhvhvhdhbid'
28
+
29
+ Yubikey::ModHex.encode("\000").should == 'cc'
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yubikey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rudenberg
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-02 00:00:00 -04:00
12
+ date: 2009-04-21 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,32 +20,39 @@ executables: []
20
20
  extensions:
21
21
  - ext/yubikey_ext/extconf.rb
22
22
  extra_rdoc_files:
23
- - ext/yubikey_ext/yubikey_ext.c
24
- - README.rdoc
25
23
  - LICENSE
24
+ - README.rdoc
25
+ - ext/yubikey_ext/yubikey_ext.c
26
26
  files:
27
+ - examples/otp.rb
28
+ - ext/yubikey_ext/extconf.rb
29
+ - ext/yubikey_ext/ykaes.c
30
+ - ext/yubikey_ext/ykcrc.c
31
+ - ext/yubikey_ext/yubikey.h
32
+ - ext/yubikey_ext/yubikey_ext.c
27
33
  - lib/yubikey.rb
28
34
  - lib/yubikey/hex.rb
35
+ - lib/yubikey/modhex.rb
29
36
  - lib/yubikey/otp.rb
30
- - examples/otp.rb
31
37
  - spec/hex_spec.rb
32
38
  - spec/spec.opts
33
39
  - spec/spec_helper.rb
34
40
  - spec/yubikey_ext_spec.rb
41
+ - spec/yubikey_modhex_spec.rb
35
42
  - spec/yubikey_otp_spec.rb
36
- - ext/yubikey_ext/ykaes.c
37
- - ext/yubikey_ext/ykcrc.c
38
- - ext/yubikey_ext/ykmodhex.c
39
- - ext/yubikey_ext/yubikey_ext.c
40
- - ext/yubikey_ext/yubikey.h
41
- - ext/yubikey_ext/extconf.rb
42
- - README.rdoc
43
43
  - LICENSE
44
+ - README.rdoc
44
45
  has_rdoc: true
45
46
  homepage: http://github.com/titanous/yubikey
47
+ licenses: []
48
+
46
49
  post_install_message:
47
50
  rdoc_options:
48
51
  - --charset=UTF-8
52
+ - --title
53
+ - yubikey
54
+ - --main
55
+ - README.rdoc
49
56
  require_paths:
50
57
  - lib
51
58
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -63,9 +70,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
70
  requirements: []
64
71
 
65
72
  rubyforge_project: yubikey
66
- rubygems_version: 1.3.1
73
+ rubygems_version: 1.3.2
67
74
  signing_key:
68
- specification_version: 2
75
+ specification_version: 3
69
76
  summary: A library to decode, decrypt and parse Yubikey one-time passwords.
70
- test_files: []
71
-
77
+ test_files:
78
+ - spec/hex_spec.rb
79
+ - spec/spec_helper.rb
80
+ - spec/yubikey_ext_spec.rb
81
+ - spec/yubikey_modhex_spec.rb
82
+ - spec/yubikey_otp_spec.rb
83
+ - examples/otp.rb
@@ -1,76 +0,0 @@
1
- /* ykmodhex.c --- Implementation of modhex encoding/decoding
2
- *
3
- * Written by Simon Josefsson <simon@josefsson.org>.
4
- * Copyright (c) 2006, 2007, 2008, 2009 Yubico AB
5
- * All rights reserved.
6
- *
7
- * Redistribution and use in source and binary forms, with or without
8
- * modification, are permitted provided that the following conditions are
9
- * met:
10
- *
11
- * * Redistributions of source code must retain the above copyright
12
- * notice, this list of conditions and the following disclaimer.
13
- *
14
- * * Redistributions in binary form must reproduce the above
15
- * copyright notice, this list of conditions and the following
16
- * disclaimer in the documentation and/or other materials provided
17
- * with the distribution.
18
- *
19
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
- *
31
- */
32
-
33
- #include "yubikey.h"
34
-
35
- #include <stdbool.h>
36
-
37
- static const char trans[] = YUBIKEY_MODHEX_MAP;
38
-
39
- void
40
- yubikey_modhex_encode (char *dst, const char *src, size_t srcSize)
41
- {
42
- while (srcSize--)
43
- {
44
- *dst++ = trans[(*src >> 4) & 0xf];
45
- *dst++ = trans[*src++ & 0xf];
46
- }
47
-
48
- *dst = '\0';
49
- }
50
-
51
- void
52
- yubikey_modhex_decode (char *dst, const char *src, size_t dstSize)
53
- {
54
- char b;
55
- bool flag = false;
56
- char *p1;
57
-
58
- for (; *src && dstSize > 0; src++)
59
- {
60
- if ((p1 = strchr (trans, *src)) == NULL)
61
- b = 0;
62
- else
63
- b = (char) (p1 - trans);
64
-
65
- if ((flag = !flag))
66
- *dst = b;
67
- else
68
- {
69
- *dst = (*dst << 4) | b;
70
- dst++;
71
- dstSize--;
72
- }
73
- }
74
- while (dstSize--)
75
- *dst++ = 0;
76
- }