-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaplug-flash.c
67 lines (54 loc) · 1.62 KB
/
daplug-flash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdlib.h>
#include <daplug/keyboard.h>
#include <daplug/DaplugDongle.h>
int main()
{
DaplugDongle *card;
Keyset keyset01, hmacSha1Keyset;
// default keyset on card from factory
if(!keyset_createKeys(&keyset01, 0x01,"404142434445464748494a4b4c4d4e4f",NULL,NULL)){
return 0;
}
//Hmac-sha1 keyset
if(!keyset_createKeys(&hmacSha1Keyset, 0x54,
"1b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
"0b0b0b0b000000000000000000000000",
"00000000000000000000000000000000"
)){
return 0;
}
hmacSha1Keyset.usage = USAGE_HMAC_SHA1;
int access4[] = {ACCESS_ALWAYS, 48};
if(!keyset_setKeyAccess(&hmacSha1Keyset,access4)){
return 0;
}
char **donglesList = NULL;
int nbDongles = Daplug_getDonglesList(&donglesList);
if(nbDongles > 0){
fprintf(stdout,"\n+Connected dongles:\n");
}else{
return 0;
}
int i;
for(i=0;i<nbDongles;i++){
fprintf(stderr, "\n%s", donglesList[i]);
}
fprintf(stderr, "\n\nget card on %s...", donglesList[0]);
if((card = Daplug_getDongleById(0)) == NULL){
return 0;
}else{
fprintf(stderr, "\nOk.\n");
}
if(!Daplug_authenticate(card, keyset01,C_MAC+C_DEC+R_MAC+R_ENC,NULL,NULL)){
fprintf(stderr, "\n***** An error occured during the test ! *****\n");
return 0;
}
if(!Daplug_putKey(card, hmacSha1Keyset, 0)){
fprintf(stderr, "\n***** An error occured during the test ! *****\n");
return 0;
}
if(card) Daplug_close(card);
if(donglesList) Daplug_exit(&donglesList);
return 1;
}