Module: VacmanLowLevel

Defined in:
ext/vacman_controller/vacman_controller.c

Class Method Summary collapse

Class Method Details

.generate_password(token) ⇒ Object

generate a password this will not work with all the dpx files available, it must be prepared for it



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'ext/vacman_controller/vacman_controller.c', line 90

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, &KernelParms, password, NULL);
  digipass_to_rbhash(&dpdata, token);

  if (result != 0) {
    vacman_raise_error("AAL2GenPassword", result);
    return Qnil;
  }

  return rb_str_new2(password);
}

.get_kernel_param(paramname) ⇒ Object

Get kernel parameter



346
347
348
349
350
351
352
353
354
355
356
357
# File 'ext/vacman_controller/vacman_controller.c', line 346

static VALUE vacman_get_kernel_param(VALUE module, VALUE paramname) {
  char *name = StringValueCStr(paramname);

  for (int 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 token properties



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'ext/vacman_controller/vacman_controller.c', line 182

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, &KernelParms, property_id, value);

  if (result == 0) {
    return rb_str_new2(value);
  } else {
    vacman_raise_error("AAL2GetTokenProperty", result);
    return Qnil;
  }
}

.import(filename, key) ⇒ Object

Import a .DPX file containing token seeds and initialisation values.

Pass the pre-shared key to validate it as the second argument. Or if you don’t have the key, replace the DC line with one from a file you know the key. Yes.



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'ext/vacman_controller/vacman_controller.c', line 253

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_raise_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,
        &KernelParms,
        appl_names,
        sw_out_serial_No,
        sw_out_type,
        sw_out_authmode,
        &dpdata);


    if (result < 0) {
      vacman_raise_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;
}

.set_kernel_param(paramname, rbval) ⇒ Object

Set kernel parameter



327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'ext/vacman_controller/vacman_controller.c', line 327

static VALUE vacman_set_kernel_param(VALUE module, VALUE paramname, VALUE rbval) {
  char *name = StringValueCStr(paramname);
  int value  = rb_fix2int(rbval);

  for (int 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_property(token, property, rbval) ⇒ Object

Set token properties



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'ext/vacman_controller/vacman_controller.c', line 202

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, &KernelParms, property_id, value);

  digipass_to_rbhash(&dpdata, token);

  if (result == 0) {
    return Qtrue;
  } else {
    vacman_raise_error("AAL2SetTokenProperty", result);
    return Qnil;
  }
}

.verify_password(token, password) ⇒ Object

verify password this is the main usecase, check the use input for authentication



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'ext/vacman_controller/vacman_controller.c', line 227

static VALUE vacman_verify_password(VALUE module, VALUE token, VALUE password ) {
  TDigipassBlob dpdata;

  rbhash_to_digipass(token, &dpdata);

  aat_int32 result = AAL2VerifyPassword(&dpdata, &KernelParms, rb_string_value_cstr(&password), 0);

  digipass_to_rbhash(&dpdata, token);

  if (result == 0)
    return Qtrue;
  else {
    vacman_raise_error("AAL2VerifyPassword", result);
    return Qnil;
  }
}

.versionObject

Get library version and return it as an hash



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'ext/vacman_controller/vacman_controller.c', line 59

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_raise_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;
}