Subversion Repositories Kolibri OS

Rev

Rev 9106 | Rev 9113 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9106 Rev 9112
Line 16... Line 16...
16
;    along with this program.  If not, see .
16
;    along with this program.  If not, see .
Line 17... Line 17...
17
 
17
 
18
; https://datatracker.ietf.org/doc/html/rfc4253#section-6.6
18
; https://datatracker.ietf.org/doc/html/rfc4253#section-6.6
Line -... Line 19...
-
 
19
; https://datatracker.ietf.org/doc/html/rfc3447
-
 
20
 
19
; https://datatracker.ietf.org/doc/html/rfc3447
21
; https://datatracker.ietf.org/doc/html/rfc4716
Line 20... Line 22...
20
 
22
 
-
 
23
proc sshlib_host_verify  con_ptr, str_host_key, str_signature, message, message_len
-
 
24
 
21
proc sshlib_host_verify  con_ptr, str_host_key, str_signature, message, message_len
25
locals
-
 
26
        current_hkb64           rb MAX_PUBLIC_KEY_SIZE*4        ; Current Host key in Base64
-
 
27
        cached_hkb64            rb MAX_PUBLIC_KEY_SIZE*4        ; Cached Host key in Base64
22
 
28
        key_name_sz             dd ?
Line 23... Line 29...
23
locals
29
        hostname_sz             dd ?
-
 
30
        current_hk64_end        dd ?
-
 
31
endl
24
        known_key_sz rb MAX_PUBLIC_KEY_SIZE
32
 
25
endl
33
        mov     eax, [con_ptr]
26
 
34
        lea     ebx, [eax + sshlib_connection.hostname_sz]
27
        mov     eax, [con_ptr]
35
        mov     [hostname_sz], ebx
28
        cmp     [eax+sshlib_connection.algo_hostkey], SSHLIB_HOSTKEY_RSA
36
        cmp     [eax+sshlib_connection.algo_hostkey], SSHLIB_HOSTKEY_RSA
Line 29... Line 37...
29
        je      .rsa
37
        je      .rsa
30
        ; ..add more here
38
        ; ..add more here
31
        mov     eax, SSHLIB_ERR_HKEY_NO_ALGO
39
        mov     eax, SSHLIB_ERR_HKEY_NO_ALGO
32
        ret
40
        ret
-
 
41
 
Line 33... Line 42...
33
 
42
  .rsa:
-
 
43
        stdcall sshlib_host_verify_rsa, [str_host_key], [str_signature], [message], [message_len]
34
  .rsa:
44
        test    eax, eax
35
        stdcall sshlib_host_verify_rsa, [str_host_key], [str_signature], [message], [message_len]
45
        jnz     .err
-
 
46
        mov     [key_name_sz], ssh_rsa_sz
-
 
47
 
36
        test    eax, eax
48
  .lookup:
-
 
49
; Convert the current host key to base64
-
 
50
        mov     esi, [str_host_key]
-
 
51
        mov     ecx, [esi]
-
 
52
        bswap   ecx
-
 
53
        add     esi, 4
37
        jnz     .err
54
        lea     edi, [current_hkb64]
38
 
55
        call    base64_encode
39
  .lookup:
56
        mov     [current_hk64_end], edi
40
;        lea     eax, [known_key_sz]
-
 
-
 
57
 
41
;        mov     ebx, [con_ptr]
58
; Try to read the cached key for this host and key type
-
 
59
        lea     edi, [cached_hkb64]
-
 
60
        invoke  ini_get_str, known_hostsfile, [hostname_sz], [key_name_sz], edi, MAX_PUBLIC_KEY_SIZE*4, 0
-
 
61
        test    eax, eax
-
 
62
        jnz     .unknown
-
 
63
; If the cached key is empty, return SSHLIB_HOSTKEY_PROBLEM_UNKNOWN
-
 
64
        lea     esi, [cached_hkb64]
-
 
65
        cmp     byte[esi], 0
-
 
66
        je      .unknown
42
;        lea     ebx, [ebx + sshlib_connection.hostname_sz]
67
; Else, compare it to the current one
43
;        invoke  ini_get_str, known_hosts_file, ebx, ssh_rsa_sz, eax, MAX_PUBLIC_KEY_SIZE, null_sz
-
 
-
 
68
        lea     edi, [current_hkb64]
-
 
69
        mov     ecx, MAX_PUBLIC_KEY_SIZE*4
-
 
70
  .cmploop:
-
 
71
        lodsb
44
;        test    eax, eax
72
        scasb
Line -... Line 73...
-
 
73
        jne     .mismatch
45
;        jnz     .unknown
74
        test    al, al
46
 
75
        jz      .match
Line 47... Line 76...
47
; TODO: verify cached host key
76
        dec     ecx
-
 
77
        jnz     .cmploop
48
;        jne     .mismatch
78
        jmp     .mismatch
49
 
79
 
50
        jmp     .unknown        ; FIXME
80
  .match:
51
 
81
        xor     eax, eax
52
        xor     eax, eax
82
        ret
Line 53... Line 83...
53
        ret
83
 
54
 
84
  .mismatch:
55
  .mismatch:
85
int3
56
        lea     eax, [known_key_sz]
86
        lea     eax, [current_hkb64]
57
        stdcall sshlib_callback_hostkey_problem, [con_ptr], SSHLIB_HOSTKEY_PROBLEM_MISMATCH, eax
87
        stdcall sshlib_callback_hostkey_problem, [con_ptr], SSHLIB_HOSTKEY_PROBLEM_MISMATCH, eax
58
        cmp     eax, SSHLIB_HOSTKEY_ACCEPT
88
        cmp     eax, SSHLIB_HOSTKEY_ACCEPT
Line 59... Line 89...
59
        je      .store
89
        je      .store
-
 
90
        ret
-
 
91
 
-
 
92
  .unknown:
60
        ret
93
        lea     eax, [current_hkb64]
61
 
-
 
-
 
94
        stdcall sshlib_callback_hostkey_problem, [con_ptr], SSHLIB_HOSTKEY_PROBLEM_UNKNOWN, eax
62
  .unknown:
95
        cmp     eax, SSHLIB_HOSTKEY_ACCEPT
Line 63... Line 96...
63
        lea     eax, [known_key_sz]
96
        je      .store
64
        stdcall sshlib_callback_hostkey_problem, [con_ptr], SSHLIB_HOSTKEY_PROBLEM_UNKNOWN, eax
97
        ret
Line 232... Line 265...
232
        ret
265
        ret
Line 233... Line 266...
233
 
266
 
Line -... Line 267...
-
 
267
endp
-
 
268
 
-
 
269
 
-
 
270
base64_encode:
-
 
271
 
-
 
272
        xor     ebx, ebx
-
 
273
  .loop:
-
 
274
        lodsb
-
 
275
        call    .byte
-
 
276
        dec     ecx
-
 
277
        jnz     .loop
-
 
278
 
-
 
279
  .final:
-
 
280
        mov     al, 0
-
 
281
        test    ebx, ebx
-
 
282
        jz      .f000
-
 
283
        call    .byte
-
 
284
        test    ebx, ebx
-
 
285
        jz      .f001
-
 
286
        call    .byte
-
 
287
        mov     byte[edi-2], '='
-
 
288
 
-
 
289
  .f001:
-
 
290
        mov     byte[edi-1], '='
-
 
291
 
-
 
292
  .f000:
-
 
293
        mov     byte[edi], 0
-
 
294
        ret
-
 
295
 
-
 
296
  .byte:
-
 
297
        inc     ebx
-
 
298
        shl     edx, 8
-
 
299
        mov     dl, al
-
 
300
        cmp     ebx, 3
-
 
301
        je      .b001
-
 
302
        ret
-
 
303
 
-
 
304
  .b001:
-
 
305
        shl     edx, 8
-
 
306
        inc     ebx
-
 
307
 
-
 
308
  .b002:
-
 
309
        rol     edx, 6
-
 
310
        xor     eax, eax
-
 
311
        xchg    al, dl
-
 
312
        mov     al, [base64_table+eax]
-
 
313
        stosb
-
 
314
        dec     ebx
-
 
315
        jnz     .b002
-
 
316
        ret
-
 
317
 
234
endp
318
 
Line -... Line 319...
-
 
319
 
-
 
320
 
235
 
321
iglobal
236
 
322
 
-
 
323
        known_hostsfile db '/sys/settings/known_hosts.ini', 0
Line 237... Line 324...
237
iglobal
324
        base64_table    db 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'