vacman_controller 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ddbe7c0b1cf7bc1f64efa3ffa86ea66925dbdb27afa2f68434f0acfd3493fb8
4
- data.tar.gz: cf653c109a8ba1bebdae0ecbdef5662978a05e56bfab0ee8a9f223ebc922d6fc
3
+ metadata.gz: 67a9773142027f6186de76542e27229381c7d6924f84611d6a6bee758e14c6cd
4
+ data.tar.gz: 00ac5fc4821601707fafc354fff76b1084106f4aa8aafe5ae1c9edc40cce43bf
5
5
  SHA512:
6
- metadata.gz: e81eed72afeda1a0d31053e55cc3eeaa7274e6324f02f8eb528361edd285e61a9a5e15b6a0de21abc8a1659c143f8dfcc93a449c6ebfa61f55e1cbf3aee2b13c
7
- data.tar.gz: 97857b1596694fd6d40ff34aa8aad9b88b273b62fe69e2c5d90320c83fd21772599add8ce3f69a8e6094f5b03eed4d90c568fc78c923f9313951b71c8655f9a0
6
+ metadata.gz: 6b7f76e6e157aec41406eb8ab887db4cec02637d9ddc531f667f005928697d249b66d2675c6f1525caa9e6b713b231c0ea686829a974044bd5e680387814b607
7
+ data.tar.gz: c16ceeaacddd6628de788c6f45db2857326cb2aff9c4d87177ae4f136de548c565e4366b8be404a949d45f06d11036f624a3750eb7b773ff34c21209f2167679
@@ -0,0 +1,73 @@
1
+ /*
2
+ * Vacman Controller wrapper
3
+ *
4
+ * This Ruby Extension wraps the VASCO Vacman Controller
5
+ * library and makes its API accessible to Ruby code.
6
+ *
7
+ * (C) 2013 https://github.com/mlankenau
8
+ * (C) 2019 m.barnaba@ifad.org
9
+ */
10
+ #include "vacman_controller.h"
11
+
12
+ /*
13
+ * Imports a .DPX file containing token seeds and initialisation values.
14
+ *
15
+ * Pass the pre-shared key to validate it as the second argument. The
16
+ * key is not validated by the AAL2 library, if you pass a different
17
+ * key than the one that was used to create the DPX, you will get back
18
+ * tokens that generate different OTPs.
19
+ *
20
+ */
21
+ VALUE vacman_dpx_import(VALUE module, VALUE filename, VALUE key) {
22
+ TDPXHandle dpx_handle;
23
+ aat_int16 appl_count;
24
+ aat_ascii appl_names[13*8];
25
+ aat_int16 token_count;
26
+
27
+ aat_int32 result = AAL2DPXInit(&dpx_handle,
28
+ rb_string_value_cstr(&filename),
29
+ rb_string_value_cstr(&key),
30
+ &appl_count,
31
+ appl_names,
32
+ &token_count);
33
+
34
+ if (result != 0) {
35
+ vacman_library_error("AAL2DPXInit", result);
36
+ return Qnil;
37
+ }
38
+
39
+ aat_ascii sw_out_serial_No[22+1];
40
+ aat_ascii sw_out_type[5+1];
41
+ aat_ascii sw_out_authmode[2+1];
42
+ TDigipassBlob dpdata;
43
+
44
+ VALUE list = rb_ary_new();
45
+
46
+ while (1) {
47
+ result = AAL2DPXGetToken(&dpx_handle,
48
+ &g_KernelParms,
49
+ appl_names,
50
+ sw_out_serial_No,
51
+ sw_out_type,
52
+ sw_out_authmode,
53
+ &dpdata);
54
+
55
+
56
+ if (result < 0) {
57
+ vacman_library_error("AAL2DPXGetToken", result);
58
+ return Qnil;
59
+ }
60
+
61
+ if (result == 107) break;
62
+
63
+ VALUE hash = rb_hash_new();
64
+
65
+ vacman_digipass_to_rbhash(&dpdata, hash);
66
+
67
+ rb_ary_push(list, hash);
68
+ }
69
+
70
+ AAL2DPXClose(&dpx_handle);
71
+
72
+ return list;
73
+ }
@@ -17,7 +17,7 @@ append_cflags "-I#{VACMAN_CONTROLLER}/include -Wall -std=c99 -Wno-declaration-af
17
17
  append_ldflags "-L#{VACMAN_CONTROLLER}/lib -laal2sdk -Wl,-rpath #{VACMAN_CONTROLLER}/lib"
18
18
 
19
19
  if find_library('aal2sdk', 'AAL2DPXInit', "#{VACMAN_CONTROLLER}/lib")
20
- create_makefile('vacman_controller/low_level')
20
+ create_makefile('vacman_controller/vacman_low_level')
21
21
  else
22
22
  puts "No libaal2sdk found"
23
23
  exit 1
@@ -0,0 +1,97 @@
1
+ /*
2
+ * Vacman Controller wrapper
3
+ *
4
+ * This Ruby Extension wraps the VASCO Vacman Controller
5
+ * library and makes its API accessible to Ruby code.
6
+ *
7
+ * (C) 2013 https://github.com/mlankenau
8
+ * (C) 2019 m.barnaba@ifad.org
9
+ */
10
+ #include "vacman_controller.h"
11
+
12
+ /*
13
+ * Vacman Controller kernel properties
14
+ */
15
+ struct kernel_property {
16
+ const char *name;
17
+ aat_int32 *value;
18
+ aat_int32 deflt;
19
+ };
20
+ static struct kernel_property vacman_kernel_properties[] = {
21
+ { "ITimeWindow", &g_KernelParms.ITimeWindow, 30 }, // Identification Window size in time steps
22
+ { "STimeWindow", &g_KernelParms.STimeWindow, 24 }, // Signature Window size in secs
23
+ { "DiagLevel", &g_KernelParms.DiagLevel, 0 }, // Requested Diagnostic Level
24
+ { "GMTAdjust", &g_KernelParms.GMTAdjust, 0 }, // GMT Time adjustment to perform
25
+ { "CheckChallenge", &g_KernelParms.CheckChallenge, 0 }, // Verify Challenge Corrupted (mandatory for Gordian)
26
+ { "IThreshold", &g_KernelParms.IThreshold, 3 }, // Identification Error Threshold
27
+ { "SThreshold", &g_KernelParms.SThreshold, 1 }, // Signature Error Threshold
28
+ { "ChkInactDays", &g_KernelParms.ChkInactDays, 0 }, // Check Inactive Days
29
+ { "DeriveVector", &g_KernelParms.DeriveVector, 0 }, // Vector used to make Data Encryption unique
30
+ { "SyncWindow", &g_KernelParms.SyncWindow, 2 }, // Synchronisation Time Window (h)
31
+ { "OnLineSG", &g_KernelParms.OnLineSG, 2 }, // On line signature
32
+ { "EventWindow", &g_KernelParms.EventWindow, 100 }, // Event Window size in nbr of iterations
33
+ { "HSMSlotId", &g_KernelParms.HSMSlotId, 0 }, // HSM Slot id uses to store DB and Transport Key
34
+ };
35
+ static size_t vacman_kernel_properties_count = sizeof(vacman_kernel_properties)/sizeof(struct kernel_property);
36
+
37
+ /*
38
+ * Initialise the kernel parameters with their defaults
39
+ */
40
+ void vacman_kernel_init_params() {
41
+ memset(&g_KernelParms, 0, sizeof(g_KernelParms));
42
+
43
+ g_KernelParms.ParmCount = 19; /* Number of valid parameters in this list */
44
+
45
+ for (size_t i = 0; i < vacman_kernel_properties_count; i++) {
46
+ *vacman_kernel_properties[i].value = vacman_kernel_properties[i].deflt;
47
+ }
48
+ }
49
+
50
+
51
+ /*
52
+ * Get kernel parameter names
53
+ */
54
+ VALUE vacman_kernel_get_property_names() {
55
+ VALUE ret = rb_ary_new();
56
+
57
+ for (size_t i = 0; i < vacman_kernel_properties_count; i++) {
58
+ const char *name = vacman_kernel_properties[i].name;
59
+ rb_ary_push(ret, rb_str_new2(name));
60
+ }
61
+
62
+ return ret;
63
+ }
64
+
65
+ /*
66
+ * Get kernel parameter
67
+ */
68
+ VALUE vacman_kernel_get_param(VALUE module, VALUE paramname) {
69
+ char *name = StringValueCStr(paramname);
70
+
71
+ for (size_t i = 0; i < vacman_kernel_properties_count; i++) {
72
+ if (strcmp(name, vacman_kernel_properties[i].name) == 0) {
73
+ return LONG2FIX(*vacman_kernel_properties[i].value);
74
+ }
75
+ }
76
+
77
+ rb_raise(e_VacmanError, "Invalid kernel param %s", name);
78
+ return Qnil;
79
+ }
80
+
81
+ /*
82
+ * Set kernel parameter
83
+ */
84
+ VALUE vacman_kernel_set_param(VALUE module, VALUE paramname, VALUE rbval) {
85
+ char *name = StringValueCStr(paramname);
86
+ int value = rb_fix2int(rbval);
87
+
88
+ for (size_t i = 0; i < vacman_kernel_properties_count; i++) {
89
+ if (strcmp(name, vacman_kernel_properties[i].name) == 0) {
90
+ *vacman_kernel_properties[i].value = value;
91
+ return Qtrue;
92
+ }
93
+ }
94
+
95
+ rb_raise(e_VacmanError, "Invalid kernel param %s", name);
96
+ return Qnil;
97
+ }
@@ -0,0 +1,90 @@
1
+ /*
2
+ * Vacman Controller wrapper
3
+ *
4
+ * This Ruby Extension wraps the VASCO Vacman Controller
5
+ * library and makes its API accessible to Ruby code.
6
+ *
7
+ * (C) 2013 https://github.com/mlankenau
8
+ * (C) 2019 m.barnaba@ifad.org
9
+ */
10
+ #define RUBY_EXPORT
11
+ #include "vacman_controller.h"
12
+
13
+ /*
14
+ * Extension entry point
15
+ */
16
+ void Init_vacman_low_level(void) {
17
+ VALUE controller = rb_define_module("VacmanController");
18
+ VALUE lowlevel = rb_define_module_under(controller, "LowLevel");
19
+
20
+ e_VacmanError = rb_define_class_under(controller, "Error", rb_eStandardError);
21
+
22
+ vacman_kernel_init_params();
23
+
24
+ /* Global methods */
25
+ rb_define_singleton_method(lowlevel, "library_version", vacman_library_version, 0);
26
+ rb_define_singleton_method(lowlevel, "import", vacman_dpx_import, 2);
27
+
28
+ /* Token methods */
29
+ rb_define_singleton_method(lowlevel, "token_property_names", vacman_token_get_property_names, 0);
30
+ rb_define_singleton_method(lowlevel, "get_token_property", vacman_token_get_property, 2);
31
+ rb_define_singleton_method(lowlevel, "set_token_property", vacman_token_set_property, 3);
32
+ rb_define_singleton_method(lowlevel, "set_token_pin", vacman_token_set_pin, 2);
33
+ rb_define_singleton_method(lowlevel, "verify_password", vacman_token_verify_password, 2);
34
+ rb_define_singleton_method(lowlevel, "generate_password", vacman_token_generate_password, 1);
35
+
36
+ /* Kernel methods */
37
+ rb_define_singleton_method(lowlevel, "kernel_property_names", vacman_kernel_get_property_names, 0);
38
+ rb_define_singleton_method(lowlevel, "get_kernel_param", vacman_kernel_get_param, 1);
39
+ rb_define_singleton_method(lowlevel, "set_kernel_param", vacman_kernel_set_param, 2);
40
+ }
41
+
42
+ /*
43
+ * Raises an Error, decoding the Vacman Controller error code.
44
+ */
45
+ void vacman_library_error(const char* method, int vacman_error_code) {
46
+ aat_ascii vacman_error_message[100]; // Recommended value in documentation.
47
+
48
+ AAL2GetErrorMsg(vacman_error_code, vacman_error_message);
49
+
50
+ char error_message[256];
51
+ snprintf(error_message, 255, "%s error %d: %s", method, vacman_error_code,
52
+ vacman_error_message);
53
+
54
+ VALUE exc = rb_exc_new2(e_VacmanError, error_message);
55
+ rb_iv_set(exc, "@library_method", rb_str_new2(method));
56
+ rb_iv_set(exc, "@error_code", INT2FIX(vacman_error_code));
57
+ rb_iv_set(exc, "@error_message", rb_str_new2(vacman_error_message));
58
+
59
+ rb_exc_raise(exc);
60
+ }
61
+
62
+
63
+ /*
64
+ * Use AAL2GetLibraryVersion to obtain library version and return it as a Ruby Hash
65
+ */
66
+ VALUE vacman_library_version(VALUE unused) {
67
+ aat_ascii version[16];
68
+ aat_int32 version_len = sizeof(version);
69
+
70
+ aat_ascii bitness[4];
71
+ aat_int32 bitness_len = sizeof(bitness);
72
+
73
+ aat_ascii type[8];
74
+ aat_int32 type_len = sizeof(type);
75
+
76
+ aat_int32 result = AAL2GetLibraryVersion(version, &version_len, bitness,
77
+ &bitness_len, type, &type_len);
78
+
79
+ if (result != 0) {
80
+ vacman_library_error("AAL2GetLibraryVersion", result);
81
+ return Qnil;
82
+ }
83
+
84
+ VALUE hash = rb_hash_new();
85
+ rb_hash_aset(hash, rb_str_new2("version"), rb_str_new2(version));
86
+ rb_hash_aset(hash, rb_str_new2("bitness"), rb_str_new2(bitness));
87
+ rb_hash_aset(hash, rb_str_new2("type"), rb_str_new2(type));
88
+
89
+ return hash;
90
+ }
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Vacman Controller wrapper
3
+ *
4
+ * This Ruby Extension wraps the VASCO Vacman Controller
5
+ * library and makes its API accessible to Ruby code.
6
+ *
7
+ * (C) 2013 https://github.com/mlankenau
8
+ * (C) 2019 m.barnaba@ifad.org
9
+ */
10
+ #include "vacman_controller.h"
11
+
12
+ static VALUE rbhash_get_key(VALUE token, const char *property, int type);
13
+
14
+ /*
15
+ * Convert a Ruby Hash with the required keys to a TDigipassBlob structure.
16
+ */
17
+ void vacman_rbhash_to_digipass(VALUE token, TDigipassBlob* dpdata) {
18
+ if (!RB_TYPE_P(token, T_HASH)) {
19
+ rb_raise(e_VacmanError, "invalid token object given, requires an hash");
20
+ return;
21
+ }
22
+
23
+ VALUE blob = rbhash_get_key(token, "blob", T_STRING);
24
+ VALUE serial = rbhash_get_key(token, "serial", T_STRING);
25
+ VALUE app_name = rbhash_get_key(token, "app_name", T_STRING);
26
+ VALUE flag1 = rbhash_get_key(token, "flags1", T_FIXNUM);
27
+ VALUE flag2 = rbhash_get_key(token, "flags2", T_FIXNUM);
28
+
29
+ memset(dpdata, 0, sizeof(*dpdata));
30
+
31
+ strcpy(dpdata->Blob, rb_string_value_cstr(&blob));
32
+ strncpy(dpdata->Serial, rb_string_value_cstr(&serial), sizeof(dpdata->Serial));
33
+ strncpy(dpdata->AppName, rb_string_value_cstr(&app_name), sizeof(dpdata->AppName));
34
+ dpdata->DPFlags[0] = rb_fix2int(flag1);
35
+ dpdata->DPFlags[1] = rb_fix2int(flag2);
36
+ }
37
+
38
+ /*
39
+ * Convert a TDigipassBlob structure into a Ruby Hash
40
+ */
41
+ void vacman_digipass_to_rbhash(TDigipassBlob* dpdata, VALUE hash) {
42
+ char buffer[256];
43
+
44
+ memset(buffer, 0, sizeof(buffer));
45
+ strncpy(buffer, dpdata->Serial, 10);
46
+ rb_hash_aset(hash, rb_str_new2("serial"), rb_str_new2(buffer));
47
+
48
+ memset(buffer, 0, sizeof(buffer));
49
+ strncpy(buffer, dpdata->AppName, 12);
50
+ rb_hash_aset(hash, rb_str_new2("app_name"), rb_str_new2(buffer));
51
+
52
+ memset(buffer, 0, sizeof(buffer));
53
+ strncpy(buffer, dpdata->Blob, 224);
54
+ rb_hash_aset(hash, rb_str_new2("blob"), rb_str_new2(buffer));
55
+
56
+ rb_hash_aset(hash, rb_str_new2("flags1"), rb_fix_new(dpdata->DPFlags[0]));
57
+ rb_hash_aset(hash, rb_str_new2("flags2"), rb_fix_new(dpdata->DPFlags[1]));
58
+ }
59
+
60
+ /*
61
+ * Gets the given property from the given token hash and raises an Error
62
+ * if the following conditions occur:
63
+ *
64
+ * * The key is not found
65
+ * * The key is not of the given type
66
+ *
67
+ * Otherwise, the value corresponding to the key is returned.
68
+ *
69
+ */
70
+ static VALUE rbhash_get_key(VALUE token, const char *property, int type) {
71
+ VALUE ret = rb_hash_aref(token, rb_str_new2(property));
72
+
73
+ if (ret == Qnil) {
74
+ rb_raise(e_VacmanError, "invalid token object given: %s property is nil", property);
75
+ return Qnil;
76
+ }
77
+
78
+ if (!RB_TYPE_P(ret, type)) {
79
+ rb_raise(e_VacmanError, "invalid token object given: %s property is not of the correct type", property);
80
+ return Qnil;
81
+ }
82
+
83
+ return ret;
84
+ }
@@ -0,0 +1,207 @@
1
+ /*
2
+ * Vacman Controller wrapper
3
+ *
4
+ * This Ruby Extension wraps the VASCO Vacman Controller
5
+ * library and makes its API accessible to Ruby code.
6
+ *
7
+ * (C) 2013 https://github.com/mlankenau
8
+ * (C) 2019 m.barnaba@ifad.org
9
+ */
10
+ #include "vacman_controller.h"
11
+
12
+ /*
13
+ * Vacman properties names and IDs registry
14
+ */
15
+ struct token_property {
16
+ const char *name;
17
+ aat_int32 id;
18
+ };
19
+ static struct token_property vacman_token_properties[] = {
20
+ {"token_model", TOKEN_MODEL },
21
+ {"token_status", TOKEN_STATUS },
22
+ {"use_count", USE_COUNT },
23
+ {"last_time_used", LAST_TIME_USED },
24
+ {"last_time_shift", LAST_TIME_SHIFT },
25
+ {"time_based_algo", TIME_BASED_ALGO },
26
+ {"event_based_algo", EVENT_BASED_ALGO },
27
+ {"pin_supported", PIN_SUPPORTED },
28
+ {"unlock_supported", UNLOCK_SUPPORTED },
29
+ {"pin_ch_on", PIN_CH_ON },
30
+ {"pin_change_enabled", PIN_CH_ON },
31
+ {"pin_len", PIN_LEN },
32
+ {"pin_length", PIN_LEN },
33
+ {"pin_min_len", PIN_MIN_LEN },
34
+ {"pin_minimum_length", PIN_MIN_LEN },
35
+ {"pin_enabled", PIN_ENABLED },
36
+ {"pin_ch_forced", PIN_CH_FORCED },
37
+ {"pin_change_forced", PIN_CH_FORCED },
38
+ {"virtual_token_type", VIRTUAL_TOKEN_TYPE },
39
+ {"virtual_token_grace_period", VIRTUAL_TOKEN_GRACE_PERIOD },
40
+ {"virtual_token_remain_use", VIRTUAL_TOKEN_REMAIN_USE },
41
+ {"last_response_type", LAST_RESPONSE_TYPE },
42
+ {"error_count", ERROR_COUNT },
43
+ {"event_value", EVENT_VALUE },
44
+ {"last_event_value", LAST_EVENT_VALUE },
45
+ {"sync_windows", SYNC_WINDOWS },
46
+ {"primary_token_enabled", PRIMARY_TOKEN_ENABLED },
47
+ {"virtual_token_supported", VIRTUAL_TOKEN_SUPPORTED },
48
+ {"virtual_token_enabled", VIRTUAL_TOKEN_ENABLED },
49
+ {"code_word", CODE_WORD },
50
+ {"auth_mode", AUTH_MODE },
51
+ {"ocra_suite", OCRA_SUITE },
52
+ {"derivation_supported", DERIVATION_SUPPORTED },
53
+ {"max_dtf_number", MAX_DTF_NUMBER },
54
+ {"response_len", RESPONSE_LEN },
55
+ {"response_length", RESPONSE_LEN },
56
+ {"response_format", RESPONSE_FORMAT },
57
+ {"response_chk", RESPONSE_CHK },
58
+ {"response_checksum", RESPONSE_CHK },
59
+ {"time_step", TIME_STEP },
60
+ {"use_3des", TRIPLE_DES_USED },
61
+ {"triple_des_used", TRIPLE_DES_USED },
62
+ };
63
+
64
+ static size_t vacman_token_properties_count = sizeof(vacman_token_properties)/sizeof(struct token_property);
65
+
66
+ /*
67
+ * Convert property name to property ID
68
+ */
69
+ static long vacman_token_get_property_id(char *property_name) {
70
+ for (size_t i = 0; i < vacman_token_properties_count; i++) {
71
+ if (strcmp(property_name, vacman_token_properties[i].name) == 0) {
72
+ return vacman_token_properties[i].id;
73
+ }
74
+ }
75
+
76
+ rb_raise(e_VacmanError, "Invalid property name `%s'", property_name);
77
+ return 0;
78
+ }
79
+
80
+
81
+ /*
82
+ * Get token property names
83
+ */
84
+ VALUE vacman_token_get_property_names() {
85
+ VALUE ret = rb_ary_new();
86
+
87
+ for (size_t i = 0; i < vacman_token_properties_count; i++) {
88
+ const char *name = vacman_token_properties[i].name;
89
+ rb_ary_push(ret, rb_str_new2(name));
90
+ }
91
+
92
+ return ret;
93
+ }
94
+
95
+
96
+ /*
97
+ * Get the given property value from the given token.
98
+ */
99
+ VALUE vacman_token_get_property(VALUE module, VALUE token, VALUE property) {
100
+ TDigipassBlob dpdata;
101
+ vacman_rbhash_to_digipass(token, &dpdata);
102
+
103
+ aat_ascii value[64];
104
+ aat_int32 property_id = vacman_token_get_property_id(StringValueCStr(property));
105
+ aat_int32 result = AAL2GetTokenProperty(&dpdata, &g_KernelParms, property_id, value);
106
+
107
+ if (result == 0) {
108
+ return rb_str_new2(value);
109
+ } else {
110
+ vacman_library_error("AAL2GetTokenProperty", result);
111
+ return Qnil;
112
+ }
113
+ }
114
+
115
+
116
+ /*
117
+ * Set the given token property to the given value.
118
+ */
119
+ VALUE vacman_token_set_property(VALUE module, VALUE token, VALUE property, VALUE rbval) {
120
+ TDigipassBlob dpdata;
121
+
122
+ aat_int32 property_id = vacman_token_get_property_id(StringValueCStr(property));
123
+ aat_int32 value = rb_fix2int(rbval);
124
+
125
+ vacman_rbhash_to_digipass(token, &dpdata);
126
+
127
+ aat_int32 result = AAL2SetTokenProperty(&dpdata, &g_KernelParms, property_id, value);
128
+
129
+ vacman_digipass_to_rbhash(&dpdata, token);
130
+
131
+ if (result == 0) {
132
+ return Qtrue;
133
+ } else {
134
+ vacman_library_error("AAL2SetTokenProperty", result);
135
+ return Qnil;
136
+ }
137
+ }
138
+
139
+
140
+ /*
141
+ * Changes the static password on the given token.
142
+ */
143
+ VALUE vacman_token_set_pin(VALUE module, VALUE token, VALUE pin) {
144
+ TDigipassBlob dpdata;
145
+
146
+ if (!RB_TYPE_P(pin, T_STRING)) {
147
+ rb_raise(e_VacmanError, "invalid pin given, requires a string");
148
+ return Qnil;
149
+ }
150
+
151
+ vacman_rbhash_to_digipass(token, &dpdata);
152
+
153
+ aat_ascii *passwd = StringValueCStr(pin);
154
+ aat_int32 result = AAL2ChangeStaticPassword(&dpdata, &g_KernelParms, passwd, passwd);
155
+
156
+ vacman_digipass_to_rbhash(&dpdata, token);
157
+
158
+ if (result == 0) {
159
+ return Qtrue;
160
+ } else {
161
+ vacman_library_error("AAL2ChangeStaticPassword", result);
162
+ return Qnil;
163
+ }
164
+ }
165
+
166
+
167
+ /*
168
+ * Verifies the given OTP against the given token.
169
+ */
170
+ VALUE vacman_token_verify_password(VALUE module, VALUE token, VALUE password) {
171
+ TDigipassBlob dpdata;
172
+
173
+ vacman_rbhash_to_digipass(token, &dpdata);
174
+
175
+ aat_int32 result = AAL2VerifyPassword(&dpdata, &g_KernelParms, rb_string_value_cstr(&password), 0);
176
+
177
+ vacman_digipass_to_rbhash(&dpdata, token);
178
+
179
+ if (result == 0)
180
+ return Qtrue;
181
+ else {
182
+ vacman_library_error("AAL2VerifyPassword", result);
183
+ return Qnil;
184
+ }
185
+ }
186
+
187
+ /*
188
+ * Generate an OTP from the given token, if the token allows it.
189
+ */
190
+ VALUE vacman_token_generate_password(VALUE module, VALUE token) {
191
+ TDigipassBlob dpdata;
192
+
193
+ vacman_rbhash_to_digipass(token, &dpdata);
194
+
195
+ aat_ascii password[18];
196
+ memset(password, 0, sizeof(password));
197
+
198
+ aat_int32 result = AAL2GenPassword(&dpdata, &g_KernelParms, password, NULL);
199
+ vacman_digipass_to_rbhash(&dpdata, token);
200
+
201
+ if (result != 0) {
202
+ vacman_library_error("AAL2GenPassword", result);
203
+ return Qnil;
204
+ }
205
+
206
+ return rb_str_new2(password);
207
+ }
@@ -0,0 +1,53 @@
1
+ #ifndef __vacman_controller_h__
2
+ #define __vacman_controller_h__
3
+
4
+ #if defined(__cplusplus)
5
+ extern "C" {
6
+ #if 0
7
+ } /* satisfy cc-mode */
8
+ #endif
9
+ #endif
10
+
11
+ #include <ruby.h>
12
+ #include <string.h>
13
+ #include <aal2sdk.h>
14
+
15
+ /* The Vacman default kernel parameters, set up upon extension initialisation. */
16
+ TKernelParms g_KernelParms;
17
+
18
+ /* Ruby exception type, defined as VacmanController::Error in Ruby land. */
19
+ VALUE e_VacmanError;
20
+
21
+ /* General methods (main.c) */
22
+ void vacman_library_error(const char* method, int vacman_error_code);
23
+ VALUE vacman_library_version(VALUE unused);
24
+
25
+ /* Kernel methods (kernel.c) */
26
+ VALUE vacman_kernel_get_property_names();
27
+ VALUE vacman_kernel_get_param(VALUE module, VALUE paramname);
28
+ VALUE vacman_kernel_set_param(VALUE module, VALUE paramname, VALUE rbval);
29
+ void vacman_kernel_init_params();
30
+
31
+ /* Token methods (token.c) */
32
+ VALUE vacman_token_get_property_names();
33
+ VALUE vacman_token_get_property(VALUE module, VALUE token, VALUE property);
34
+ VALUE vacman_token_set_property(VALUE module, VALUE token, VALUE property, VALUE rbval);
35
+ VALUE vacman_token_set_pin(VALUE module, VALUE token, VALUE pin);
36
+ VALUE vacman_token_verify_password(VALUE module, VALUE token, VALUE password);
37
+ VALUE vacman_token_generate_password(VALUE module, VALUE token);
38
+
39
+ /* Token interchange format between Ruby and libaal2 (serialize.c) */
40
+ void vacman_rbhash_to_digipass(VALUE token, TDigipassBlob* dpdata);
41
+ void vacman_digipass_to_rbhash(TDigipassBlob* dpdata, VALUE hash);
42
+
43
+ /* DPX methods (dpx.c) */
44
+ VALUE vacman_dpx_import(VALUE module, VALUE filename, VALUE key);
45
+
46
+ #if defined(__cplusplus)
47
+ #if 0
48
+ { /* satisfy cc-mode */
49
+ #endif
50
+ } /* extern "C" { */
51
+ #endif
52
+
53
+ #endif /* __vacman_controller_h__ */