Module: VacmanController::LowLevel
- Defined in:
- ext/vacman_controller/low_level.c
Class Method Summary collapse
-
.generate_password(token) ⇒ Object
Generate an OTP from the given token, if the token allows it.
-
.get_kernel_param(paramname) ⇒ Object
Get kernel parameter.
-
.get_token_property(token, property) ⇒ Object
Get the given property value from the given token.
-
.import(filename, key) ⇒ Object
Imports a .DPX file containing token seeds and initialisation values.
-
.kernel_property_names ⇒ Object
Get kernel parameter names.
-
.library_version ⇒ Object
Use AAL2GetLibraryVersion to obtain library version and return it as a Ruby Hash.
-
.set_kernel_param(paramname, rbval) ⇒ Object
Set kernel parameter.
-
.set_token_pin(token, pin) ⇒ Object
Changes the static password on the given token.
-
.set_token_property(token, property, rbval) ⇒ Object
Set the given token property to the given value.
-
.token_property_names ⇒ Object
Get token property names.
-
.verify_password(token, password) ⇒ Object
Verifies the given OTP against the given token.
Class Method Details
.generate_password(token) ⇒ Object
Generate an OTP from the given token, if the token allows it.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'ext/vacman_controller/low_level.c', line 153 static VALUE vacman_generate_password(VALUE module, VALUE token) { TDigipassBlob dpdata; rbhash_to_digipass(token, &dpdata); aat_ascii password[18]; memset(password, 0, sizeof(password)); aat_int32 result = AAL2GenPassword(&dpdata, &g_KernelParms, password, NULL); digipass_to_rbhash(&dpdata, token); if (result != 0) { vacman_library_error("AAL2GenPassword", result); return Qnil; } return rb_str_new2(password); } |
.get_kernel_param(paramname) ⇒ Object
Get kernel parameter
489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'ext/vacman_controller/low_level.c', line 489 static VALUE vacman_get_kernel_param(VALUE module, VALUE paramname) { char *name = StringValueCStr(paramname); for (size_t i = 0; i < kernel_properties_count; i++) { if (strcmp(name, kernel_properties[i].name) == 0) { return LONG2FIX(*kernel_properties[i].value); } } rb_raise(e_VacmanError, "Invalid kernel param %s", name); return Qnil; } |
.get_token_property(token, property) ⇒ Object
Get the given property value from the given token.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'ext/vacman_controller/low_level.c', line 260 static VALUE vacman_get_token_property(VALUE module, VALUE token, VALUE property) { TDigipassBlob dpdata; rbhash_to_digipass(token, &dpdata); aat_ascii value[64]; aat_int32 property_id = vacman_get_property_id(StringValueCStr(property)); aat_int32 result = AAL2GetTokenProperty(&dpdata, &g_KernelParms, property_id, value); if (result == 0) { return rb_str_new2(value); } else { vacman_library_error("AAL2GetTokenProperty", result); return Qnil; } } |
.import(filename, key) ⇒ Object
Imports a .DPX file containing token seeds and initialisation values.
Pass the pre-shared key to validate it as the second argument. The key is not validated by the AAL2 library, if you pass a different key than the one that was used to create the DPX, you will get back tokens that generate different OTPs.
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'ext/vacman_controller/low_level.c', line 358 static VALUE vacman_import(VALUE module, VALUE filename, VALUE key) { TDPXHandle dpx_handle; aat_int16 appl_count; aat_ascii appl_names[13*8]; aat_int16 token_count; aat_int32 result = AAL2DPXInit(&dpx_handle, rb_string_value_cstr(&filename), rb_string_value_cstr(&key), &appl_count, appl_names, &token_count); if (result != 0) { vacman_library_error("AAL2DPXInit", result); return Qnil; } aat_ascii sw_out_serial_No[22+1]; aat_ascii sw_out_type[5+1]; aat_ascii sw_out_authmode[2+1]; TDigipassBlob dpdata; VALUE list = rb_ary_new(); while (1) { result = AAL2DPXGetToken(&dpx_handle, &g_KernelParms, appl_names, sw_out_serial_No, sw_out_type, sw_out_authmode, &dpdata); if (result < 0) { vacman_library_error("AAL2DPXGetToken", result); return Qnil; } if (result == 107) break; VALUE hash = rb_hash_new(); digipass_to_rbhash(&dpdata, hash); rb_ary_push(list, hash); } AAL2DPXClose(&dpx_handle); return list; } |
.kernel_property_names ⇒ Object
Get kernel parameter names
455 456 457 458 459 460 461 462 463 464 |
# File 'ext/vacman_controller/low_level.c', line 455 static VALUE vacman_get_kernel_property_names(void) { VALUE ret = rb_ary_new(); for (size_t i = 0; i < kernel_properties_count; i++) { const char *name = kernel_properties[i].name; rb_ary_push(ret, rb_str_new2(name)); } return ret; } |
.library_version ⇒ Object
Use AAL2GetLibraryVersion to obtain library version and return it as a Ruby Hash
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'ext/vacman_controller/low_level.c', line 47 static VALUE vacman_library_version(VALUE module) { aat_ascii version[16]; aat_int32 version_len = sizeof(version); aat_ascii bitness[4]; aat_int32 bitness_len = sizeof(bitness); aat_ascii type[8]; aat_int32 type_len = sizeof(type); aat_int32 result = AAL2GetLibraryVersion(version, &version_len, bitness, &bitness_len, type, &type_len); if (result != 0) { vacman_library_error("AAL2GetLibraryVersion", result); return Qnil; } VALUE hash = rb_hash_new(); rb_hash_aset(hash, rb_str_new2("version"), rb_str_new2(version)); rb_hash_aset(hash, rb_str_new2("bitness"), rb_str_new2(bitness)); rb_hash_aset(hash, rb_str_new2("type"), rb_str_new2(type)); return hash; } |
.set_kernel_param(paramname, rbval) ⇒ Object
Set kernel parameter
470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'ext/vacman_controller/low_level.c', line 470 static VALUE vacman_set_kernel_param(VALUE module, VALUE paramname, VALUE rbval) { char *name = StringValueCStr(paramname); int value = rb_fix2int(rbval); for (size_t i = 0; i < kernel_properties_count; i++) { if (strcmp(name, kernel_properties[i].name) == 0) { *kernel_properties[i].value = value; return Qtrue; } } rb_raise(e_VacmanError, "Invalid kernel param %s", name); return Qnil; } |
.set_token_pin(token, pin) ⇒ Object
Changes the static password on the given token.
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'ext/vacman_controller/low_level.c', line 304 static VALUE vacman_set_token_pin(VALUE module, VALUE token, VALUE pin) { TDigipassBlob dpdata; if (!RB_TYPE_P(pin, T_STRING)) { rb_raise(e_VacmanError, "invalid pin given, requires a string"); return Qnil; } rbhash_to_digipass(token, &dpdata); aat_ascii *passwd = StringValueCStr(pin); aat_int32 result = AAL2ChangeStaticPassword(&dpdata, &g_KernelParms, passwd, passwd); digipass_to_rbhash(&dpdata, token); if (result == 0) { return Qtrue; } else { vacman_library_error("AAL2ChangeStaticPassword", result); return Qnil; } } |
.set_token_property(token, property, rbval) ⇒ Object
Set the given token property to the given value.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'ext/vacman_controller/low_level.c', line 280 static VALUE vacman_set_token_property(VALUE module, VALUE token, VALUE property, VALUE rbval) { TDigipassBlob dpdata; aat_int32 property_id = vacman_get_property_id(StringValueCStr(property)); aat_int32 value = rb_fix2int(rbval); rbhash_to_digipass(token, &dpdata); aat_int32 result = AAL2SetTokenProperty(&dpdata, &g_KernelParms, property_id, value); digipass_to_rbhash(&dpdata, token); if (result == 0) { return Qtrue; } else { vacman_library_error("AAL2SetTokenProperty", result); return Qnil; } } |
.token_property_names ⇒ Object
Get token property names
245 246 247 248 249 250 251 252 253 254 |
# File 'ext/vacman_controller/low_level.c', line 245 static VALUE vacman_get_token_property_names(void) { VALUE ret = rb_ary_new(); for (size_t i = 0; i < token_properties_count; i++) { const char *name = token_properties[i].name; rb_ary_push(ret, rb_str_new2(name)); } return ret; } |
.verify_password(token, password) ⇒ Object
Verifies the given OTP against the given token.
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'ext/vacman_controller/low_level.c', line 331 static VALUE vacman_verify_password(VALUE module, VALUE token, VALUE password) { TDigipassBlob dpdata; rbhash_to_digipass(token, &dpdata); aat_int32 result = AAL2VerifyPassword(&dpdata, &g_KernelParms, rb_string_value_cstr(&password), 0); digipass_to_rbhash(&dpdata, token); if (result == 0) return Qtrue; else { vacman_library_error("AAL2VerifyPassword", result); return Qnil; } } |