Thread Crypt::NaCl::Sodium Übersetzung aus C (4 answers)
Opened by Perlentaucher at 2019-02-04 15:00

Perlentaucher
 2019-02-04 15:01
#189711 #189711
User since
2014-08-04
23 articles
BenutzerIn

user image
Der derzeitige Code der Unterfunktion lautet:

more (10.2kb):
Code: (dl )
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
sub DoorBird_X_Test($) {
my ($hash) = @_;
my $name = $hash->{NAME};
my $username = "foobar0001";
my $password = "QzT3jeK3JY";


### Define Test UDP Package
my $buf = pack('C*' , 0xDE, 0xAD, 0xBE, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x20, 0x00, 0x77, 0x35, 0x36, 0xDC
, 0xC3, 0x0E, 0x2E, 0x84, 0x7E, 0x0E, 0x75, 0x29, 0xE2, 0x34, 0x60, 0xCF, 0xE3, 0xFF, 0xCC, 0x52
, 0x3F, 0x37, 0xB2, 0xF2, 0xDC, 0x1A, 0x71, 0x80, 0xF2, 0x9B, 0x2E, 0xA0, 0x27, 0xA9, 0x82, 0x41
, 0x9C, 0xCE, 0x45, 0x9D, 0x27, 0x45, 0x2E, 0x42, 0x14, 0xBE, 0x9C, 0x74, 0xE9, 0x33, 0x3A, 0x21
, 0xDB, 0x10, 0x78, 0xB9, 0xF6, 0x7B);

my $StrechedPWTestReference = "0x47 0xB8 0xA5 0xBC 0xDD 0xDA 0x29 0xEB 0x4C 0x0F 0xF6 0x78 0x46 0x41 0xE7 0x2F 0x7B 0x9C 0x45 0xD5 0x46 0x1A 0x60 0x71 0x2C 0x68 0x1F 0x05 0x23 0x9B 0xCC 0xA2";


### Unpack Hex-Pachacke
my $data = unpack('H*', $buf);

### Generate user friendly hex-string
my $DataHexFriendly;
for (my $i=0; $i < (length($data)/2); $i++) {
$DataHexFriendly .= "0x" . substr($data, $i*2, 2) . " ";
}

### Split up in accordance to API 0.24 description
my $IDENT = substr($data, 0, 6);
my $VERSION = substr($data, 6, 2);
my $OPSLIMIT = substr($data, 8, 8);
my $MEMLIMIT = substr($data, 16, 8);
my $SALT = substr($data, 24, 32);
my $NONCE = substr($data, 56, 16);
my $CIPHERTEXT = substr($data, 72, 68);
my $FiveCharPw = substr($password, 0, 5);

### Log Entry for debugging purposes
Log3 $name, 5, $name. " : DoorBird_Read - UDP Client said packed : " . $buf;
Log3 $name, 5, $name. " : DoorBird_Read - UDP Client said hex : " . $data;
Log3 $name, 5, $name. " : DoorBird_Read - UDP Client said hex friendly : " . $DataHexFriendly;
Log3 $name, 5, $name. " : DoorBird_Read -- Part 1 ----------------------------------------";
Log3 $name, 5, $name. " : DoorBird_Read - UDP length data in decimal : " . length($data);
Log3 $name, 5, $name. " : DoorBird_Read - UDP IDENT in hexadecimal : " . $IDENT;
Log3 $name, 5, $name. " : DoorBird_Read - UDP VERSION in hexadecimal : " . $VERSION;
Log3 $name, 5, $name. " : DoorBird_Read - UDP OPSLIMIT in hexadecimal : " . $OPSLIMIT;
Log3 $name, 5, $name. " : DoorBird_Read - UDP MEMLIMIT in hexadecimal : " . $MEMLIMIT;
Log3 $name, 5, $name. " : DoorBird_Read - UDP SALT in hexadecimal : " . $SALT;
Log3 $name, 5, $name. " : DoorBird_Read - UDP NONCE in hexadecimal : " . $NONCE;
Log3 $name, 5, $name. " : DoorBird_Read - UDP CIPHERTEXT in hexadecimal : " . $CIPHERTEXT;
Log3 $name, 5, $name. " : DoorBird_Read - UDP FiveCharPw in character : " . $FiveCharPw;


Log3 $name, 5, $name. " : DoorBird_Read -- Part 2 ----------------------------------------";
Log3 $name, 5, $name. " : DoorBird_Read - UDP IDENT in decimal : " . hex($IDENT);
Log3 $name, 5, $name. " : DoorBird_Read - UDP VERSION in decimal : " . hex($VERSION);
Log3 $name, 5, $name. " : DoorBird_Read - UDP OPSLIMIT in decimal : " . hex($OPSLIMIT);
Log3 $name, 5, $name. " : DoorBird_Read - UDP MEMLIMIT in decimal : " . hex($MEMLIMIT);


### Pack SALT and Password
$SALT = pack('A*', $SALT);
$FiveCharPw = pack('A*', $FiveCharPw);

### Log Entry for debugging purposes
Log3 $name, 5, $name. " : DoorBird_Read -- Part 3 ----------------------------------------";
Log3 $name, 5, $name. " : DoorBird_Read - UDP SALT packed : " . $SALT;
Log3 $name, 5, $name. " : DoorBird_Read - UDP length(SALT) : " . length($SALT);
Log3 $name, 5, $name. " : DoorBird_Read - UDP FiveCharPw packed : " . $FiveCharPw;
Log3 $name, 5, $name. " : DoorBird_Read - UDP length(FiveCharPw) : " . length($FiveCharPw);

my $StrechedPW;
my $key;
my $crypto_pwhash = Crypt::NaCl::Sodium->pwhash();

eval
{
### PW-Hash: https://metacpan.org/pod/distribution/Crypt-NaCl-Sodium/lib/Crypt/NaCl/Sodium/pwhash.pod#key
$key = $crypto_pwhash->key( $FiveCharPw, $SALT, bytes => 32, opslimit => hex($OPSLIMIT), memlimit => hex($MEMLIMIT));

### Wie komme ich an diesen verflixten Key, den diese Zeile generiert???

1;
}
or do
{
### Log Entry
Log3 $name, 3, $name. " : DoorBird_Read - error - crypto_pwhash_scrypt_str : " . $@;
return
};





### Unpack Streched Password
my $StrechedPWHex = unpack('H*', $StrechedPW);


### Generate user friendly hex-string
my $StrechedPWHexFriendly;
for (my $i=0; $i < (length($StrechedPWHex)/2); $i++) {
$StrechedPWHexFriendly .= "0x" . substr($StrechedPWHex, $i*2, 2) . " ";
}


### Log Entry for debugging purposes
Log3 $name, 5, $name. " : DoorBird_Read -- Part 4 ----------------------------------------";
Log3 $name, 5, $name. " : DoorBird_Read - UDP crypto_pwhash : " . Dumper($crypto_pwhash);
Log3 $name, 5, $name. " : DoorBird_Read - UDP StrechedPW : " . Dumper($StrechedPW);
Log3 $name, 5, $name. " : DoorBird_Read - UDP StrechedPW hex : " . $StrechedPWHex;
Log3 $name, 5, $name. " : DoorBird_Read - UDP StrechedPW hex friendly : " . $StrechedPWHexFriendly;
Log3 $name, 5, $name. " : DoorBird_Read - UDP StrechedPW API Reference : " . $StrechedPWTestReference;
}


Die Ausgabe im Log File

Code: (dl )
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
DoorBird_Read - UDP Client said packed            : ޭ� w56��.�~u)�4`����R?7���q��.�'��A��E�'E.B��t�3:!�x��{
DoorBird_Read - UDP Client said hex : deadbe010000000400002000773536dcc30e2e847e0e7529e23460cfe3ffcc523f37b2f2dc1a7180f29b2ea027a982419cce459d27452e4214be9c74e9333a21db1078b9f67b
DoorBird_Read - UDP Client said hex friendly : 0xde 0xad 0xbe 0x01 0x00 0x00 0x00 0x04 0x00 0x00 0x20 0x00 0x77 0x35 0x36 0xdc 0xc3 0x0e 0x2e 0x84 0x7e 0x0e 0x75 0x29 0xe2 0x34 0x60 0xcf 0xe3 0xff 0xcc 0x52 0x3f 0x37 0xb2 0xf2 0xdc 0x1a 0x71 0x80 0xf2 0x9b 0x2e 0xa0 0x27 0xa9 0x82 0x41 0x9c 0xce 0x45 0x9d 0x27 0x45 0x2e 0x42 0x14 0xbe 0x9c 0x74 0xe9 0x33 0x3a 0x21 0xdb 0x10 0x78 0xb9 0xf6 0x7b
DoorBird_Read -- Part 1 ----------------------------------------
DoorBird_Read - UDP length data in decimal : 140
DoorBird_Read - UDP IDENT in hexadecimal : deadbe
DoorBird_Read - UDP VERSION in hexadecimal : 01
DoorBird_Read - UDP OPSLIMIT in hexadecimal : 00000004
DoorBird_Read - UDP MEMLIMIT in hexadecimal : 00002000
DoorBird_Read - UDP SALT in hexadecimal : 773536dcc30e2e847e0e7529e23460cf
DoorBird_Read - UDP NONCE in hexadecimal : e3ffcc523f37b2f2
DoorBird_Read - UDP CIPHERTEXT in hexadecimal : dc1a7180f29b2ea027a982419cce459d27452e4214be9c74e9333a21db1078b9f67b
DoorBird_Read - UDP FiveCharPw in character : QzT3j
DoorBird_Read -- Part 2 ----------------------------------------
DoorBird_Read - UDP IDENT in decimal : 14593470
DoorBird_Read - UDP VERSION in decimal : 1
DoorBird_Read - UDP OPSLIMIT in decimal : 4
DoorBird_Read - UDP MEMLIMIT in decimal : 8192
DoorBird_Read -- Part 3 ----------------------------------------
DoorBird_Read - UDP SALT packed : 773536dcc30e2e847e0e7529e23460cf
DoorBird_Read - UDP length(SALT) : 32
DoorBird_Read - UDP FiveCharPw packed : QzT3j
DoorBird_Read - UDP length(FiveCharPw) : 5
DoorBird_Read -- Part 4 ----------------------------------------
DoorBird_Read - UDP crypto_pwhash : $VAR1 = bless( {}, 'Crypt::NaCl::Sodium::pwhash' );
DoorBird_Read - UDP StrechedPW : $VAR1 = undef;
DoorBird_Read - UDP StrechedPW hex :
DoorBird_Read - UDP StrechedPW hex friendly :
DoorBird_Read - UDP StrechedPW API Reference : 0x47 0xB8 0xA5 0xBC 0xDD 0xDA 0x29 0xEB 0x4C 0x0F 0xF6 0x78 0x46 0x41 0xE7 0x2F 0x7B 0x9C 0x45 0xD5 0x46 0x1A 0x60 0x71 0x2C 0x68 0x1F 0x05 0x23 0x9B 0xCC 0xA2

View full thread Crypt::NaCl::Sodium Übersetzung aus C