Subversion Repositories Kolibri OS

Rev

Rev 9987 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9106 hidnplayr 1
;    sshlib_connection.inc - SSH connection
2
;
9987 hidnplayr 3
;    Copyright (C) 2016-2024 Jeffrey Amelynck
9106 hidnplayr 4
;
5
;    This program is free software: you can redistribute it and/or modify
6
;    it under the terms of the GNU General Public License as published by
7
;    the Free Software Foundation, either version 3 of the License, or
8
;    (at your option) any later version.
9
;
10
;    This program is distributed in the hope that it will be useful,
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;    GNU General Public License for more details.
14
;
15
;    You should have received a copy of the GNU General Public License
16
;    along with this program.  If not, see .
17
 
9987 hidnplayr 18
; https://www.ietf.org/rfc/rfc4253.txt
19
 
9106 hidnplayr 20
proc sshlib_connect con_ptr, hostname_sz
21
 
22
locals
23
        socketnum       dd ?
24
        sockaddr        sockaddr_in
25
        ctx_ptr         dd ?
26
endl
27
 
28
        mov     edi, [con_ptr]
29
        lea     eax, [edi + sshlib_connection.part_ex_hash_ctx]
30
        mov     [ctx_ptr], eax
31
 
32
; Set default values in sockaddr struct
33
        mov     [sockaddr.sin_family], AF_INET4
34
        mov     [sockaddr.sin_port], 22 shl 8
35
 
36
; Parse hostname_sz
37
; Verify length, extract port number if given and copy base url to sshlib_connection struct
38
; Port number, if provided, will be written in sockaddr struct.
39
; Hostname ends with any character equal to 0x20 or lower
40
 
41
        mov     esi, [hostname_sz]
42
        lea     edi, [edi + sshlib_connection.hostname_sz]
43
        mov     ecx, MAX_HOSTNAME_LENGTH
44
  @@:
45
        dec     ecx
46
        jz      .err_hostname
47
        lodsb
48
        cmp     al, ':'
49
        je      .do_port
50
        stosb
51
        cmp     al, 0x20
52
        ja      @r
53
        mov     byte[edi-1], 0
54
        jmp     .hostname_ok
55
 
56
  .do_port:
57
        xor     eax, eax
58
        xor     ebx, ebx
59
        mov     byte[edi-1], 0
60
  .portloop:
61
        lodsb
62
        cmp     al, 0x20
63
        jbe     .port_done
64
        sub     al, '0'
65
        jb      .err_hostname
66
        cmp     al, 9
67
        ja      .err_hostname
68
        lea     ebx, [ebx*4+ebx]
69
        shl     ebx, 1
70
        add     ebx, eax
71
        jmp     .portloop
72
  .port_done:
73
        xchg    bl, bh
74
        mov     [sockaddr.sin_port], bx
75
 
76
  .hostname_ok:
77
; resolve name
78
        push    esp     ; reserve stack place
79
        push    esp
80
        mov     eax, [con_ptr]
81
        lea     eax, [eax+sshlib_connection.hostname_sz]
82
        invoke  getaddrinfo, eax, 0, 0
83
        pop     esi
84
; test for error
85
        test    eax, eax
86
        jnz     .err_hostname
87
 
88
; convert IP address to decimal notation
89
        mov     eax, [esi+addrinfo.ai_addr]
90
        mov     eax, [eax+sockaddr_in.sin_addr]
91
        mov     [sockaddr.sin_addr], eax
92
        invoke  inet_ntoa, eax
93
; write result
94
        stdcall sshlib_callback_connecting, [con_ptr], eax
95
; free allocated memory
96
        invoke  freeaddrinfo, esi
97
 
98
; Create socket
99
        mcall   socket, AF_INET4, SOCK_STREAM, 0
100
        cmp     eax, -1
101
        jz      .err_sock
102
        mov     [socketnum], eax
103
        mov     ebx, [con_ptr]
104
        mov     [ebx + sshlib_connection.socketnum], eax
105
 
106
; Connect
107
        DEBUGF  2, "Connecting to server\n"
108
        lea     edx, [sockaddr]
109
        mcall   connect, [socketnum], , sizeof.sockaddr_in
110
        test    eax, eax
111
        jnz     .err_sock
112
 
113
; Start calculating hash
9990 hidnplayr 114
        invoke  sha2_256.init, [ctx_ptr]
9106 hidnplayr 115
; HASH: string  V_C, the client's version string (CR and NL excluded)
9990 hidnplayr 116
        invoke  sha2_256.update, [ctx_ptr], ssh_ident_ha, ssh_msg_ident.length+4-2
9106 hidnplayr 117
 
118
; >> Send our identification string
119
        DEBUGF  2, "Sending ID string\n"
120
        mcall   send, [socketnum], ssh_msg_ident, ssh_msg_ident.length, 0
121
        cmp     eax, -1
122
        je      .err_sock
123
 
124
; << Check protocol version of server
125
        mov     edx, [con_ptr]
126
        lea     edx, [edx + sshlib_connection.rx_buffer + 4]
127
        mcall   recv, [socketnum], , PACKETSIZE, 0
128
        cmp     eax, -1
129
        je      .err_sock
130
 
131
        DEBUGF  2, "Received ID string\n"
132
        cmp     dword[edx], "SSH-"
133
        jne     .err_proto
134
        cmp     dword[edx+4], "2.0-"
135
        jne     .err_proto
136
 
137
; HASH: string  V_S, the server's version string (CR and NL excluded)
138
        lea     ecx, [eax+2]
139
        sub     eax, 2
140
        bswap   eax
141
        sub     edx, 4
142
        mov     dword[edx], eax
9990 hidnplayr 143
        invoke  sha2_256.update, [ctx_ptr], edx, ecx
9106 hidnplayr 144
 
145
; >> Key Exchange init
146
        mov     eax, [con_ptr]
147
        mov     [eax + sshlib_connection.status], SSHLIB_CON_STAT_INIT
148
 
149
        mov     [eax + sshlib_connection.algo_kex], SSHLIB_ALGO_NONE
150
        mov     [eax + sshlib_connection.algo_hostkey], SSHLIB_ALGO_NONE
151
        mov     [eax + sshlib_connection.algo_crypt_rx], SSHLIB_ALGO_NONE
152
        mov     [eax + sshlib_connection.algo_crypt_tx], SSHLIB_ALGO_NONE
153
        mov     [eax + sshlib_connection.algo_mac_rx], SSHLIB_ALGO_NONE
154
        mov     [eax + sshlib_connection.algo_mac_tx], SSHLIB_ALGO_NONE
155
        mov     [eax + sshlib_connection.algo_compr_rx], SSHLIB_ALGO_NONE
156
        mov     [eax + sshlib_connection.algo_compr_tx], SSHLIB_ALGO_NONE
157
 
158
        mov     [eax + sshlib_connection.rx_mac_seqnr], 0
159
        mov     [eax + sshlib_connection.tx_mac_seqnr], 0
160
        mov     [eax + sshlib_connection.rx_crypt_blocksize], 4             ; minimum blocksize
161
        mov     [eax + sshlib_connection.tx_crypt_blocksize], 4
9987 hidnplayr 162
        mov     [eax + sshlib_connection.rx_crypt_proc], 0
163
        mov     [eax + sshlib_connection.tx_crypt_proc], 0
9106 hidnplayr 164
        mov     [eax + sshlib_connection.rx_mac_proc], 0
165
        mov     [eax + sshlib_connection.tx_mac_proc], 0
166
        mov     [eax + sshlib_connection.rx_mac_length], 0
167
        mov     [eax + sshlib_connection.tx_mac_length], 0
168
        mov     [eax + sshlib_connection.tx_pad_size], 8
169
 
9987 hidnplayr 170
        mov     [eax + sshlib_connection.rx_proc], sshlib_recv_packet_clear
171
        mov     [eax + sshlib_connection.tx_proc], sshlib_send_packet_clear
172
 
9106 hidnplayr 173
        DEBUGF  2, "Sending KEX init\n"
174
        mov     edi, ssh_msg_kex.cookie
175
        call    MBRandom
176
        stosd
177
        call    MBRandom
178
        stosd
179
        call    MBRandom
180
        stosd
181
        call    MBRandom
182
        stosd
183
        stdcall sshlib_send_packet, [con_ptr], ssh_msg_kex, ssh_msg_kex.length, 0
184
        cmp     eax, -1
185
        je      .err_sock
186
 
187
; HASH: string  I_C, the payload of the client's SSH_MSG_KEXINIT
188
        mov     esi, [con_ptr]
189
        mov     eax, [esi+sshlib_connection.tx_buffer.packet_length]
190
        bswap   eax
191
        movzx   ebx, [esi+sshlib_connection.tx_buffer.padding_length]
192
        sub     eax, ebx
193
        dec     eax
194
        lea     edx, [eax+4]
195
        bswap   eax
196
        lea     esi, [esi+sshlib_connection.tx_buffer+1]
197
        mov     dword[esi], eax
9990 hidnplayr 198
        invoke  sha2_256.update, [ctx_ptr], esi, edx
9106 hidnplayr 199
 
200
; << Check key exchange init of server
201
        stdcall sshlib_recv_packet, [con_ptr], 0
202
        cmp     eax, -1
203
        je      .err_sock
204
 
205
        mov     esi, [con_ptr]
206
        cmp     [esi + sshlib_connection.rx_buffer.message_code], SSH_MSG_KEXINIT
207
        jne     .err_proto
208
        DEBUGF  2, "Received KEX init\n"
209
 
210
        lea     esi, [esi + sshlib_connection.rx_buffer + sizeof.ssh_packet_header + 16]
211
        lodsd
212
        bswap   eax
213
        DEBUGF  1, "kex_algorithms: %s\n", esi
214
        add     esi, eax
215
        lodsd
216
        bswap   eax
217
        DEBUGF  1, "server_host_key_algorithms: %s\n", esi
218
        add     esi, eax
219
        lodsd
220
        bswap   eax
221
        DEBUGF  1, "encryption_algorithms_client_to_server: %s\n", esi
222
        add     esi, eax
223
        lodsd
224
        bswap   eax
225
        DEBUGF  1, "encryption_algorithms_server_to_client: %s\n", esi
226
        add     esi, eax
227
        lodsd
228
        bswap   eax
229
        DEBUGF  1, "mac_algorithms_client_to_server: %s\n", esi
230
        add     esi, eax
231
        lodsd
232
        bswap   eax
233
        DEBUGF  1, "mac_algorithms_server_to_client: %s\n", esi
234
        add     esi, eax
235
        lodsd
236
        bswap   eax
237
        DEBUGF  1, "compression_algorithms_client_to_server: %s\n", esi
238
        add     esi, eax
239
        lodsd
240
        bswap   eax
241
        DEBUGF  1, "compression_algorithms_server_to_client: %s\n", esi
242
        add     esi, eax
243
        lodsd
244
        bswap   eax
245
        DEBUGF  1, "languages_client_to_server: %s\n", esi
246
        add     esi, eax
247
        lodsd
248
        bswap   eax
249
        DEBUGF  1, "languages_server_to_client: %s\n", esi
250
        add     esi, eax
251
        lodsb
252
        DEBUGF  1, "KEX First Packet Follows: %u\n", al
253
 
254
; TODO: parse this structure and set algorithm codes accordingly
255
; FIXME: hardcoded for now
256
        mov     esi, [con_ptr]
257
        mov     [esi+sshlib_connection.algo_kex], SSHLIB_KEX_DH_SHA256
258
        mov     [esi+sshlib_connection.algo_hostkey], SSHLIB_HOSTKEY_RSA
259
        mov     [esi+sshlib_connection.algo_crypt_rx], SSHLIB_CRYPT_AES256_CTR
9990 hidnplayr 260
        mov     [esi+sshlib_connection.algo_crypt_tx], SSHLIB_CRYPT_AES256_CTR  ; SSHLIB_CRYPT_CHACHA20_POLY1305
261
        mov     [esi+sshlib_connection.algo_mac_rx], SSHLIB_HMAC_SHA2_256_ETM
262
        mov     [esi+sshlib_connection.algo_mac_tx], SSHLIB_HMAC_SHA2_256_ETM
263
        mov     [esi+sshlib_connection.algo_compr_rx], SSHLIB_ALGO_NONE
264
        mov     [esi+sshlib_connection.algo_compr_tx], SSHLIB_ALGO_NONE
9106 hidnplayr 265
 
266
; HASH: string I_S, the payload of the servers's SSH_MSG_KEXINIT
267
        mov     esi, [con_ptr]
268
        mov     eax, [esi+sshlib_connection.rx_buffer.packet_length]
269
        movzx   ebx, [esi+sshlib_connection.rx_buffer.padding_length]
270
        sub     eax, ebx
271
        dec     eax
272
        lea     edx, [eax+4]
273
        bswap   eax
274
        lea     esi, [esi+sshlib_connection.rx_buffer+1]
275
        mov     dword[esi], eax
9990 hidnplayr 276
        invoke  sha2_256.update, [ctx_ptr], esi, edx
9106 hidnplayr 277
 
278
; Exchange keys with the server
279
 
280
        stdcall sshlib_dh_gex, [con_ptr]
281
        test    eax, eax
282
        jnz     .err
283
 
9987 hidnplayr 284
; Set keys and initialize transport subroutines
285
 
286
        DEBUGF  2, "SSH: Setting encryption keys\n"
287
 
288
        mov     ebx, [con_ptr]
289
 
9990 hidnplayr 290
        cmp     [ebx + sshlib_connection.algo_crypt_rx], SSHLIB_CRYPT_AES256_CTR
291
        je      .rx_crypt_aes256_ctr
292
        cmp     [ebx + sshlib_connection.algo_crypt_rx], SSHLIB_CRYPT_AES256_CBC
293
        je      .rx_crypt_aes256_cbc
294
        cmp     [ebx + sshlib_connection.algo_crypt_rx], SSHLIB_CRYPT_CHACHA20_POLY1305
295
        je      .rx_crypt_poly1305_chacha20
9987 hidnplayr 296
 
9990 hidnplayr 297
        jmp     .err_proto
298
 
299
  .rx_crypt_aes256_ctr:
300
        lea     ecx, [ebx + sshlib_connection.rx_crypt_ctx]
301
        lea     edx, [ebx + sshlib_connection.rx_enc_key]
302
        lea     esi, [ebx + sshlib_connection.rx_iv]
303
        invoke  aes256ctr.init, ecx, edx, esi, 0
304
        push    [aes256ctr.update]
305
        pop     [ebx + sshlib_connection.rx_crypt_proc]
306
        mov     [ebx + sshlib_connection.rx_crypt_blocksize], 16        ; AES_BLOCKSIZE
307
        jmp     .have_rx_crypt
308
 
309
  .rx_crypt_aes256_cbc:
310
        lea     ecx, [ebx + sshlib_connection.rx_crypt_ctx]
311
        lea     edx, [ebx + sshlib_connection.rx_enc_key]
312
        lea     esi, [ebx + sshlib_connection.rx_iv]
313
        invoke  aes256cbc.init, ecx, edx, esi, 0
314
        push    [aes256cbc.update]
315
        pop     [ebx + sshlib_connection.rx_crypt_proc]
316
        mov     [ebx + sshlib_connection.rx_crypt_blocksize], 16        ; AES_BLOCKSIZE
317
        jmp     .have_rx_crypt
318
 
319
  .rx_crypt_poly1305_chacha20:
9987 hidnplayr 320
        mov     [ebx + sshlib_connection.rx_proc], sshlib_recv_packet_poly1305chacha20
9990 hidnplayr 321
        jmp     .have_rx_crypt_and_mac
322
 
323
 
324
 
325
  .have_rx_crypt:
326
        cmp     [ebx + sshlib_connection.algo_mac_rx], SSHLIB_HMAC_SHA2_256
327
        je      .rx_hmac_sha2_256
328
        cmp     [ebx + sshlib_connection.algo_mac_rx], SSHLIB_HMAC_SHA2_512
329
        je      .rx_hmac_sha2_512
330
        cmp     [ebx + sshlib_connection.algo_mac_rx], SSHLIB_HMAC_SHA2_256_ETM
331
        je      .rx_hmac_sha2_256_etm
332
        cmp     [ebx + sshlib_connection.algo_mac_rx], SSHLIB_HMAC_SHA2_512_ETM
333
        je      .rx_hmac_sha2_512_etm
334
 
335
        jmp     .err_proto
336
 
337
  .rx_hmac_sha2_256:
338
        push    [hmac_sha2_256.oneshot]
339
        pop     [ebx + sshlib_connection.rx_mac_proc]
340
        mov     [ebx + sshlib_connection.rx_mac_length], SHA2_256_LEN
341
        mov     [ebx + sshlib_connection.rx_proc], sshlib_recv_packet_hmac
342
        jmp     .have_rx_crypt_and_mac
343
 
344
  .rx_hmac_sha2_512:
345
        push    [hmac_sha2_512.oneshot]
346
        pop     [ebx + sshlib_connection.rx_mac_proc]
347
        mov     [ebx + sshlib_connection.rx_mac_length], SHA2_512_LEN
348
        mov     [ebx + sshlib_connection.rx_proc], sshlib_recv_packet_hmac
349
        jmp     .have_rx_crypt_and_mac
350
 
351
  .rx_hmac_sha2_256_etm:
352
        push    [hmac_sha2_256.oneshot]
353
        pop     [ebx + sshlib_connection.rx_mac_proc]
354
        mov     [ebx + sshlib_connection.rx_mac_length], SHA2_256_LEN
355
        mov     [ebx + sshlib_connection.rx_proc], sshlib_recv_packet_hmac_etm
356
        jmp     .have_rx_crypt_and_mac
357
 
358
  .rx_hmac_sha2_512_etm:
359
        push    [hmac_sha2_512.oneshot]
360
        pop     [ebx + sshlib_connection.rx_mac_proc]
361
        mov     [ebx + sshlib_connection.rx_mac_length], SHA2_512_LEN
362
        mov     [ebx + sshlib_connection.rx_proc], sshlib_recv_packet_hmac_etm
363
        jmp     .have_rx_crypt_and_mac
364
 
365
 
366
  .have_rx_crypt_and_mac:
367
 
368
        cmp     [ebx + sshlib_connection.algo_crypt_tx], SSHLIB_CRYPT_AES256_CTR
369
        je      .tx_crypt_aes256_ctr
370
        cmp     [ebx + sshlib_connection.algo_crypt_tx], SSHLIB_CRYPT_AES256_CBC
371
        je      .tx_crypt_aes256_cbc
372
        cmp     [ebx + sshlib_connection.algo_crypt_tx], SSHLIB_CRYPT_CHACHA20_POLY1305
373
        je      .tx_crypt_poly1305_chacha20
374
 
375
        jmp     .err_proto
376
 
377
  .tx_crypt_aes256_ctr:
378
        lea     ecx, [ebx + sshlib_connection.tx_crypt_ctx]
379
        lea     edx, [ebx + sshlib_connection.tx_enc_key]
380
        lea     esi, [ebx + sshlib_connection.tx_iv]
381
        invoke  aes256ctr.init, ecx, edx, esi, 0
382
        push    [aes256ctr.update]
383
        pop     [ebx + sshlib_connection.tx_crypt_proc]
384
        mov     [ebx + sshlib_connection.tx_crypt_blocksize], 16        ; AES_BLOCKSIZE
385
        mov     [ebx + sshlib_connection.tx_pad_size], 16               ; AES_BLOCKSIZE
386
        jmp     .have_tx_crypt
387
 
388
  .tx_crypt_aes256_cbc:
389
        lea     ecx, [ebx + sshlib_connection.tx_crypt_ctx]
390
        lea     edx, [ebx + sshlib_connection.tx_enc_key]
391
        lea     esi, [ebx + sshlib_connection.tx_iv]
392
        invoke  aes256cbc.init, ecx, edx, esi, 0
393
        push    [aes256cbc.update]
394
        pop     [ebx + sshlib_connection.tx_crypt_proc]
395
        mov     [ebx + sshlib_connection.tx_crypt_blocksize], 16        ; AES_BLOCKSIZE
396
        mov     [ebx + sshlib_connection.tx_pad_size], 16               ; AES_BLOCKSIZE
397
        jmp     .have_tx_crypt
398
 
399
  .tx_crypt_poly1305_chacha20:
9987 hidnplayr 400
        mov     [ebx + sshlib_connection.tx_proc], sshlib_send_packet_poly1305chacha20
9990 hidnplayr 401
        jmp     .have_tx_crypt_and_mac
9987 hidnplayr 402
 
9990 hidnplayr 403
 
404
 
405
  .have_tx_crypt:
406
        cmp     [ebx + sshlib_connection.algo_mac_tx], SSHLIB_HMAC_SHA2_256
407
        je      .tx_hmac_sha2_256
408
        cmp     [ebx + sshlib_connection.algo_mac_tx], SSHLIB_HMAC_SHA2_512
409
        je      .tx_hmac_sha2_512
410
        cmp     [ebx + sshlib_connection.algo_mac_tx], SSHLIB_HMAC_SHA2_256_ETM
411
        je      .tx_hmac_sha2_256_etm
412
        cmp     [ebx + sshlib_connection.algo_mac_tx], SSHLIB_HMAC_SHA2_512_ETM
413
        je      .tx_hmac_sha2_512_etm
414
 
415
        jmp     .err_proto
416
 
417
  .tx_hmac_sha2_256:
418
        push    [hmac_sha2_256.oneshot]
419
        pop     [ebx + sshlib_connection.tx_mac_proc]
420
        mov     [ebx + sshlib_connection.tx_mac_length], SHA2_256_LEN
421
        mov     [ebx + sshlib_connection.tx_proc], sshlib_send_packet_hmac
422
        jmp     .have_tx_crypt_and_mac
423
 
424
  .tx_hmac_sha2_512:
425
        push    [hmac_sha2_512.oneshot]
426
        pop     [ebx + sshlib_connection.tx_mac_proc]
427
        mov     [ebx + sshlib_connection.tx_mac_length], SHA2_512_LEN
428
        mov     [ebx + sshlib_connection.tx_proc], sshlib_send_packet_hmac
429
        jmp     .have_tx_crypt_and_mac
430
 
431
  .tx_hmac_sha2_256_etm:
432
        push    [hmac_sha2_256.oneshot]
433
        pop     [ebx + sshlib_connection.tx_mac_proc]
434
        mov     [ebx + sshlib_connection.tx_mac_length], SHA2_256_LEN
435
        mov     [ebx + sshlib_connection.tx_proc], sshlib_send_packet_hmac_etm
436
        jmp     .have_tx_crypt_and_mac
437
 
438
  .tx_hmac_sha2_512_etm:
439
        push    [hmac_sha2_512.oneshot]
440
        pop     [ebx + sshlib_connection.tx_mac_proc]
441
        mov     [ebx + sshlib_connection.tx_mac_length], SHA2_512_LEN
442
        mov     [ebx + sshlib_connection.tx_proc], sshlib_send_packet_hmac_etm
443
        jmp     .have_tx_crypt_and_mac
444
 
445
 
446
  .have_tx_crypt_and_mac:
447
 
448
 
9106 hidnplayr 449
; Re-seed RNG for padding bytes
450
 
451
        call    create_seed
452
        call    init_random
453
 
454
        xor     eax, eax
455
        ret
456
 
457
  .err_hostname:
458
        mov     eax, SSHLIB_ERR_HOSTNAME
459
        ret
460
 
461
  .err_sock:
462
        mov     eax, SSHLIB_ERR_SOCKET
463
        ret
464
 
465
  .err_proto:
466
        mov     eax, SSHLIB_ERR_PROTOCOL
467
        ret
468
 
469
  .err:
470
        ret
471
 
472
endp
473
 
474
 
475
 
476
 
477
; Handle common messages and return to caller for specific ones
478
proc sshlib_msg_handler, con_ptr, flags
479
 
480
  .recv:
481
; Send a window update if advertised window drops below half
482
        cmp     [ssh_chan.rcv_wnd], BUFFERSIZE/2
483
        ja      .no_wnd
484
        mov     eax, BUFFERSIZE
485
        bswap   eax
486
        mov     [ssh_msg_channel_window_adjust.wnd], eax
487
        stdcall sshlib_send_packet, [con_ptr], ssh_msg_channel_window_adjust, ssh_msg_channel_window_adjust.length, 0
488
        mov     [ssh_chan.rcv_wnd], BUFFERSIZE
489
  .no_wnd:
490
 
491
; Receive 1 SSH packet
492
        stdcall sshlib_recv_packet, [con_ptr], [flags]
493
        cmp     eax, 0
494
        jle     .ret
495
 
496
        mov     esi, [con_ptr]
497
        lea     esi, [esi + sshlib_connection.rx_buffer]
498
        mov     al, [esi + ssh_packet_header.message_code]
9987 hidnplayr 499
        add     esi, sizeof.ssh_packet_header
9106 hidnplayr 500
 
501
        cmp     al, SSH_MSG_DISCONNECT
502
        je      .disc
503
        cmp     al, SSH_MSG_IGNORE
504
        je      .ign
505
        cmp     al, SSH_MSG_DEBUG
506
        je      .dbg
507
        cmp     al, SSH_MSG_GLOBAL_REQUEST
508
        je      .glob_req
509
        cmp     al, SSH_MSG_CHANNEL_WINDOW_ADJUST
510
        je      .chan_win_adj
511
;        cmp     al, SSH_MSG_CHANNEL_REQUEST
512
;        je      .chan_req
513
        cmp     al, SSH_MSG_CHANNEL_EOF
514
        je      .chan_eof
515
        cmp     al, SSH_MSG_CHANNEL_CLOSE
516
        je      .chan_close
517
 
9987 hidnplayr 518
        DEBUGF  3, "SSH: Message type: %u\n", al
519
 
9106 hidnplayr 520
  .ret:
521
        ret
522
 
523
  .disc:
524
        DEBUGF  3, "SSH: Disconnect message received\n"
525
        mov     eax, SSHLIB_ERR_DISCONNECTING
526
        ret
527
 
528
  .ign:
529
        DEBUGF  3, "SSH: Ignore MSG received\n"
530
        jmp     .recv
531
 
532
  .dbg:
533
        DEBUGF  3, "SSH: Debug MSG received\n"
534
        ;TODO
535
        jmp     .recv
536
 
537
  .glob_req:
9987 hidnplayr 538
        add     esi, 4
539
        DEBUGF  3, "SSH: Global MSG received: %s\n", esi
9106 hidnplayr 540
        ;TODO
541
        jmp     .recv
542
 
543
  .chan_win_adj:
544
        mov     eax, dword[esi]
545
        bswap   eax
546
        mov     [ssh_chan.snd_wnd], eax
547
        ; TODO: validate channel number, act accordingly
548
        DEBUGF  3, "SSH: Channel %u window update received\n", eax
549
        jmp     .recv
550
 
551
  .chan_eof:
552
        mov     eax, dword[esi]
553
        bswap   eax
554
        ; TODO: validate channel number, act accordingly
555
        DEBUGF  3, "SSH: Channel %u EOF received\n", eax
556
        jmp     .recv
557
 
558
  .chan_close:
559
        mov     eax, dword[esi]
560
        bswap   eax
561
        ; TODO: validate channel number
562
        DEBUGF  3, "SSH: Channel %u close received\n", eax
563
        ; Reply with close message
564
        stdcall sshlib_send_packet, [con_ptr], ssh_msg_channel_close, ssh_msg_channel_close.length, 0
565
        xor     eax, eax
566
        ret
567
 
9216 dunkaist 568
endp