Subversion Repositories Kolibri OS

Rev

Rev 6419 | Rev 6922 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6419 Rev 6469
1
;    ssh.asm - SSH client for KolibriOS
1
;    ssh.asm - SSH client for KolibriOS
2
;
2
;
3
;    Copyright (C) 2015-2016 Jeffrey Amelynck
3
;    Copyright (C) 2015-2016 Jeffrey Amelynck
4
;
4
;
5
;    This program is free software: you can redistribute it and/or modify
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
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
7
;    the Free Software Foundation, either version 3 of the License, or
8
;    (at your option) any later version.
8
;    (at your option) any later version.
9
;
9
;
10
;    This program is distributed in the hope that it will be useful,
10
;    This program is distributed in the hope that it will be useful,
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;    GNU General Public License for more details.
13
;    GNU General Public License for more details.
14
;
14
;
15
;    You should have received a copy of the GNU General Public License
15
;    You should have received a copy of the GNU General Public License
16
;    along with this program.  If not, see .
16
;    along with this program.  If not, see .
17
 
17
 
18
format binary as ""
18
format binary as ""
19
 
19
 
20
__DEBUG__       = 1
20
__DEBUG__       = 1
21
__DEBUG_LEVEL__ = 1
21
__DEBUG_LEVEL__ = 2             ; 1: Extreme debugging, 2: Debugging, 3: Errors only
22
 
22
 
23
BUFFERSIZE      = 4096
23
BUFFERSIZE      = 4096
24
MAX_BITS        = 8192
24
MAX_BITS        = 8192
25
 
25
 
26
DH_PRIVATE_KEY_SIZE     = 256
26
DH_PRIVATE_KEY_SIZE     = 256
27
 
27
 
28
use32
28
use32
29
 
29
 
30
        db      'MENUET01'      ; signature
30
        db      'MENUET01'      ; signature
31
        dd      1               ; header version
31
        dd      1               ; header version
32
        dd      start           ; entry point
32
        dd      start           ; entry point
33
        dd      i_end           ; initialized size
33
        dd      i_end           ; initialized size
34
        dd      mem+4096        ; required memory
34
        dd      mem+4096        ; required memory
35
        dd      mem+4096        ; stack pointer
35
        dd      mem+4096        ; stack pointer
36
        dd      hostname        ; parameters
36
        dd      params          ; parameters
37
        dd      0               ; path
37
        dd      0               ; path
38
 
38
 
39
include '../../macros.inc'
39
include '../../macros.inc'
-
 
40
;include '../../struct.inc'
40
purge mov,add,sub
41
purge mov,add,sub
41
include '../../proc32.inc'
42
include '../../proc32.inc'
42
include '../../dll.inc'
43
include '../../dll.inc'
43
include '../../debug-fdo.inc'
44
include '../../debug-fdo.inc'
44
include '../../network.inc'
45
include '../../network.inc'
45
;include '../../develop/libraries/libcrash/trunk/libcrash.inc'
46
include '../../develop/libraries/libcrash/trunk/libcrash.inc'
46
 
47
 
47
include 'mcodes.inc'
48
include 'mcodes.inc'
48
include 'ssh_transport.inc'
49
include 'ssh_transport.inc'
49
include 'dh_gex.inc'
50
include 'dh_gex.inc'
50
 
51
 
51
include 'mpint.inc'
52
include 'mpint.inc'
52
include 'random.inc'
53
include 'random.inc'
53
include 'aes256.inc'
54
include 'aes256.inc'
54
include 'aes256-ctr.inc'
55
include 'aes256-ctr.inc'
55
include 'aes256-cbc.inc'
56
include 'aes256-cbc.inc'
56
include '../../fs/kfar/trunk/kfar_arc/sha256.inc'
57
include 'hmac_sha256.inc'
57
 
58
 
58
; macros for network byte order
59
; macros for network byte order
59
macro dd_n op {
60
macro dd_n op {
60
   dd 0 or (((op) and 0FF000000h) shr 24) or \
61
   dd 0 or (((op) and 0FF000000h) shr 24) or \
61
           (((op) and 000FF0000h) shr  8) or \
62
           (((op) and 000FF0000h) shr  8) or \
62
           (((op) and 00000FF00h) shl  8) or \
63
           (((op) and 00000FF00h) shl  8) or \
63
           (((op) and 0000000FFh) shl 24)
64
           (((op) and 0000000FFh) shl 24)
64
}
65
}
65
 
66
 
66
macro dw_n op {
67
macro dw_n op {
67
   dw 0 or (((op) and 0FF00h) shr 8) or \
68
   dw 0 or (((op) and 0FF00h) shr 8) or \
68
           (((op) and 000FFh) shl 8)
69
           (((op) and 000FFh) shl 8)
69
}
70
}
-
 
71
 
-
 
72
proc dump_hex _ptr, _length
-
 
73
if __DEBUG_LEVEL__ <= 1
-
 
74
        pushad
-
 
75
 
-
 
76
        mov     esi, [_ptr]
-
 
77
        mov     ecx, [_length]
-
 
78
  .next_dword:
-
 
79
        lodsd
-
 
80
        bswap   eax
-
 
81
        DEBUGF  1,'%x',eax
-
 
82
        loop    .next_dword
-
 
83
        DEBUGF  1,'\n'
-
 
84
 
-
 
85
        popad
-
 
86
        ret
-
 
87
end if
-
 
88
endp
-
 
89
 
-
 
90
struct  ssh_connection
-
 
91
 
-
 
92
; Connection
-
 
93
 
-
 
94
        hostname                rb 1024
-
 
95
 
-
 
96
        socketnum               dd ?
-
 
97
 
-
 
98
        sockaddr                dw ?            ; Address family
-
 
99
        port                    dw ?
-
 
100
        ip                      dd ?
-
 
101
                                rb 10
-
 
102
 
-
 
103
; Encryption/Decryption
-
 
104
 
-
 
105
        rx_crypt_proc           dd ?
-
 
106
        tx_crypt_proc           dd ?
-
 
107
        rx_crypt_ctx_ptr        dd ?
-
 
108
        tx_crypt_ctx_ptr        dd ?
-
 
109
        rx_crypt_blocksize      dd ?
-
 
110
        tx_crypt_blocksize      dd ?
-
 
111
 
-
 
112
; Message authentication
-
 
113
 
-
 
114
        rx_mac_proc             dd ?
-
 
115
        tx_mac_proc             dd ?
-
 
116
        rx_mac_ctx              hmac_sha256_context
-
 
117
        tx_mac_ctx              hmac_sha256_context
-
 
118
        rx_mac_length           dd ?
-
 
119
        tx_mac_length           dd ?
-
 
120
 
-
 
121
; Buffers
-
 
122
 
-
 
123
        rx_seq                  dd ?            ; Packet sequence number for MAC
-
 
124
        rx_buffer               ssh_packet_header
-
 
125
                                rb BUFFERSIZE-sizeof.ssh_packet_header
-
 
126
 
-
 
127
        tx_seq                  dd ?            ; Packet sequence number for MAC
-
 
128
        tx_buffer               ssh_packet_header
-
 
129
                                rb BUFFERSIZE-sizeof.ssh_packet_header
-
 
130
 
-
 
131
        send_data               dw ?
-
 
132
 
-
 
133
; Output from key exchange
-
 
134
        dh_K                    dd ?            ; Shared Secret (Big endian)
-
 
135
                                rb MAX_BITS/8
-
 
136
        dh_K_length             dd ?            ; Length in little endian
-
 
137
 
-
 
138
        dh_H                    rb 32           ; Exchange Hash
-
 
139
        session_id_prefix       db ?
-
 
140
        session_id              rb 32
-
 
141
        rx_iv                   rb 32           ; Rx initialisation vector
-
 
142
        tx_iv                   rb 32           ; Tx initialisation vector
-
 
143
        rx_enc_key              rb 32           ; Rx encryption key
-
 
144
        tx_enc_key              rb 32           ; Tx encryption key
-
 
145
        rx_int_key              rb 32           ; Rx integrity key
-
 
146
        tx_int_key              rb 32           ; Tx integrity key
-
 
147
 
-
 
148
; Diffie Hellman
-
 
149
        dh_p                    dd ?
-
 
150
                                rb MAX_BITS/8
-
 
151
        dh_g                    dd ?
-
 
152
                                rb MAX_BITS/8
-
 
153
        dh_x                    dd ?
-
 
154
                                rb MAX_BITS/8
-
 
155
        dh_e                    dd ?
-
 
156
                                rb MAX_BITS/8
-
 
157
        dh_f                    dd ?
-
 
158
                                rb MAX_BITS/8
-
 
159
 
-
 
160
        dh_signature            dd ?
-
 
161
                                rb MAX_BITS/8
-
 
162
 
-
 
163
        temp_ctx                ctx_sha224256
-
 
164
        k_h_ctx                 ctx_sha224256
-
 
165
 
-
 
166
ends
70
 
167
 
71
start:
168
start:
72
        mcall   68, 11          ; Init heap
169
        mcall   68, 11          ; Init heap
73
 
170
 
74
        DEBUGF  1, "SSH: Loading libraries\n"
171
        DEBUGF  2, "SSH: Loading libraries\n"
75
        stdcall dll.Load, @IMPORT
172
        stdcall dll.Load, @IMPORT
76
        test    eax, eax
173
        test    eax, eax
77
        jnz     exit
174
        jnz     exit
78
 
175
 
79
        DEBUGF  1, "SSH: Init PRNG\n"
176
        DEBUGF  2, "SSH: Init PRNG\n"
80
        call    init_random
177
        call    init_random
81
 
178
 
82
        DEBUGF  1, "SSH: Init Console\n"
179
        DEBUGF  2, "SSH: Init Console\n"
83
        invoke  con_start, 1
180
        invoke  con_start, 1
84
        invoke  con_init, 80, 25, 80, 25, title
181
        invoke  con_init, 80, 25, 80, 25, title
85
 
182
 
86
; Check for parameters
183
; Check for parameters TODO
87
        cmp     byte[hostname], 0
184
;        cmp     byte[params], 0
88
        jne     resolve
185
;        jne     resolve
89
 
186
 
90
main:
187
main:
91
        invoke  con_cls
188
        invoke  con_cls
92
; Welcome user
189
; Welcome user
93
        invoke  con_write_asciiz, str1
190
        invoke  con_write_asciiz, str1
94
 
191
 
95
prompt:
192
prompt:
96
; write prompt
193
; write prompt
97
        invoke  con_write_asciiz, str2
194
        invoke  con_write_asciiz, str2
98
; read string
195
; read string
99
        mov     esi, hostname
196
        mov     esi, con.hostname
100
        invoke  con_gets, esi, 256
197
        invoke  con_gets, esi, 256
101
; check for exit
198
; check for exit
102
        test    eax, eax
199
        test    eax, eax
103
        jz      done
200
        jz      done
104
        cmp     byte[esi], 10
201
        cmp     byte[esi], 10
105
        jz      done
202
        jz      done
106
 
203
 
107
resolve:
204
resolve:
-
 
205
        mov     [con.sockaddr], AF_INET4
108
        mov     [sockaddr1.port], 22 shl 8
206
        mov     [con.port], 22 shl 8
109
 
207
 
110
; delete terminating '\n'
208
; delete terminating '\n'
111
        mov     esi, hostname
209
        mov     esi, con.hostname
112
  @@:
210
  @@:
113
        lodsb
211
        lodsb
114
        cmp     al, ':'
212
        cmp     al, ':'
115
        je      .do_port
213
        je      .do_port
116
        cmp     al, 0x20
214
        cmp     al, 0x20
117
        ja      @r
215
        ja      @r
118
        mov     byte[esi-1], 0
216
        mov     byte[esi-1], 0
119
        jmp     .done
217
        jmp     .done
120
 
218
 
121
  .do_port:
219
  .do_port:
122
        xor     eax, eax
220
        xor     eax, eax
123
        xor     ebx, ebx
221
        xor     ebx, ebx
124
        mov     byte[esi-1], 0
222
        mov     byte[esi-1], 0
125
  .portloop:
223
  .portloop:
126
        lodsb
224
        lodsb
127
        cmp     al, 0x20
225
        cmp     al, 0x20
128
        jbe     .port_done
226
        jbe     .port_done
129
        sub     al, '0'
227
        sub     al, '0'
130
        jb      hostname_error
228
        jb      hostname_error
131
        cmp     al, 9
229
        cmp     al, 9
132
        ja      hostname_error
230
        ja      hostname_error
133
        lea     ebx, [ebx*4 + ebx]
231
        lea     ebx, [ebx*4+ebx]
134
        shl     ebx, 1
232
        shl     ebx, 1
135
        add     ebx, eax
233
        add     ebx, eax
136
        jmp     .portloop
234
        jmp     .portloop
137
 
235
 
138
  .port_done:
236
  .port_done:
139
        xchg    bl, bh
237
        xchg    bl, bh
140
        mov     [sockaddr1.port], bx
238
        mov     [con.port], bx
141
 
239
 
142
  .done:
240
  .done:
143
 
241
 
144
; resolve name
242
; resolve name
145
        push    esp     ; reserve stack place
243
        push    esp     ; reserve stack place
146
        push    esp
244
        push    esp
147
        invoke  getaddrinfo, hostname, 0, 0
245
        invoke  getaddrinfo, con.hostname, 0, 0
148
        pop     esi
246
        pop     esi
149
; test for error
247
; test for error
150
        test    eax, eax
248
        test    eax, eax
151
        jnz     dns_error
249
        jnz     dns_error
152
 
250
 
153
        invoke  con_cls
251
        invoke  con_cls
154
        invoke  con_write_asciiz, str3
252
        invoke  con_write_asciiz, str3
155
        invoke  con_write_asciiz, hostname
253
        invoke  con_write_asciiz, con.hostname
156
 
254
 
157
; write results
255
; write results
158
        invoke  con_write_asciiz, str8
256
        invoke  con_write_asciiz, str8
159
 
257
 
160
; convert IP address to decimal notation
258
; convert IP address to decimal notation
161
        mov     eax, [esi+addrinfo.ai_addr]
259
        mov     eax, [esi+addrinfo.ai_addr]
162
        mov     eax, [eax+sockaddr_in.sin_addr]
260
        mov     eax, [eax+sockaddr_in.sin_addr]
163
        mov     [sockaddr1.ip], eax
261
        mov     [con.ip], eax
164
        invoke  inet_ntoa, eax
262
        invoke  inet_ntoa, eax
165
; write result
263
; write result
166
        invoke  con_write_asciiz, eax
264
        invoke  con_write_asciiz, eax
167
; free allocated memory
265
; free allocated memory
168
        invoke  freeaddrinfo, esi
266
        invoke  freeaddrinfo, esi
169
 
267
 
170
        invoke  con_write_asciiz, str9
268
        invoke  con_write_asciiz, str9
171
 
269
 
172
        mcall   40, EVM_STACK + EVM_KEY
270
        mcall   40, EVM_STACK + EVM_KEY
173
        invoke  con_cls
271
        invoke  con_cls
174
 
272
 
175
; Create socket
273
; Create socket
176
        mcall   socket, AF_INET4, SOCK_STREAM, 0
274
        mcall   socket, AF_INET4, SOCK_STREAM, 0
177
        cmp     eax, -1
275
        cmp     eax, -1
178
        jz      socket_err
276
        jz      socket_err
179
        mov     [socketnum], eax
277
        mov     [con.socketnum], eax
180
 
278
 
-
 
279
; Connect
181
; Connect
280
        DEBUGF  2, "Connecting to server\n"
182
        mcall   connect, [socketnum], sockaddr1, 18
281
        mcall   connect, [con.socketnum], con.sockaddr, 18
183
        test    eax, eax
282
        test    eax, eax
184
        jnz     socket_err
283
        jnz     socket_err
185
 
284
 
186
; Start calculating hash meanwhile
285
; Start calculating hash
187
        call    sha256_init
286
        invoke  sha256_init, con.temp_ctx
188
; HASH: string  V_C, the client's version string (CR and NL excluded)
-
 
189
        mov     esi, ssh_ident_ha
287
; HASH: string  V_C, the client's version string (CR and NL excluded)
190
        mov     edx, ssh_ident.length+4-2
-
 
191
        call    sha256_update
288
        invoke  sha256_update, con.temp_ctx, ssh_ident_ha, ssh_ident.length+4-2
192
 
289
 
193
; Send our identification string
290
; >> Send our identification string
194
        DEBUGF  1, "Sending ID string\n"
291
        DEBUGF  2, "Sending ID string\n"
195
        mcall   send, [socketnum], ssh_ident, ssh_ident.length, 0
292
        mcall   send, [con.socketnum], ssh_ident, ssh_ident.length, 0
196
        cmp     eax, -1
293
        cmp     eax, -1
197
        je      socket_err
294
        je      socket_err
198
 
295
 
199
; Check protocol version of server
296
; << Check protocol version of server
200
        mcall   recv, [socketnum], rx_buffer, BUFFERSIZE, 0
297
        mcall   recv, [con.socketnum], con.rx_buffer, BUFFERSIZE, 0
201
        cmp     eax, -1
298
        cmp     eax, -1
202
        je      socket_err
299
        je      socket_err
203
 
300
 
204
        DEBUGF  1, "Received ID string\n"
301
        DEBUGF  2, "Received ID string\n"
205
        cmp     dword[rx_buffer], "SSH-"
302
        cmp     dword[con.rx_buffer], "SSH-"
206
        jne     proto_err
303
        jne     proto_err
207
        cmp     dword[rx_buffer+4], "2.0-"
304
        cmp     dword[con.rx_buffer+4], "2.0-"
208
        jne     proto_err
305
        jne     proto_err
209
 
306
 
210
; HASH: string  V_S, the server's version string (CR and NL excluded)
307
; HASH: string  V_S, the server's version string (CR and NL excluded)
211
        lea     edx, [eax+2]
308
        lea     edx, [eax+2]
212
        sub     eax, 2
309
        sub     eax, 2
213
        bswap   eax
310
        bswap   eax
214
        mov     [rx_buffer-4], eax
311
        mov     dword[con.rx_buffer-4], eax
-
 
312
        invoke  sha256_update, con.temp_ctx, con.rx_buffer-4, edx
-
 
313
 
-
 
314
; >> Key Exchange init
215
        mov     esi, rx_buffer-4
315
        mov     [con.rx_seq], 0
216
        call    sha256_update
316
        mov     [con.tx_seq], 0
-
 
317
        mov     [con.rx_crypt_blocksize], 4             ; minimum blocksize
-
 
318
        mov     [con.tx_crypt_blocksize], 4
-
 
319
        mov     [con.rx_crypt_proc], 0
-
 
320
        mov     [con.tx_crypt_proc], 0
-
 
321
        mov     [con.rx_mac_proc], 0
-
 
322
        mov     [con.tx_mac_proc], 0
-
 
323
        mov     [con.rx_mac_length], 0
-
 
324
        mov     [con.tx_mac_length], 0
217
 
-
 
218
; Key Exchange init
325
 
219
        DEBUGF  1, "Sending KEX init\n"
326
        DEBUGF  2, "Sending KEX init\n"
220
        mov     edi, ssh_kex.cookie
327
        mov     edi, ssh_kex.cookie
221
        call    MBRandom
328
        call    MBRandom
222
        stosd
329
        stosd
223
        call    MBRandom
330
        call    MBRandom
224
        stosd
331
        stosd
225
        call    MBRandom
332
        call    MBRandom
226
        stosd
333
        stosd
227
        call    MBRandom
334
        call    MBRandom
228
        stosd
335
        stosd
229
        stdcall ssh_send_packet, [socketnum], ssh_kex, ssh_kex.length, 0
336
        stdcall ssh_send_packet, con, ssh_kex, ssh_kex.length, 0
230
        cmp     eax, -1
337
        cmp     eax, -1
231
        je      socket_err
338
        je      socket_err
232
 
339
 
233
; HASH: string  I_C, the payload of the client's SSH_MSG_KEXINIT
340
; HASH: string  I_C, the payload of the client's SSH_MSG_KEXINIT
234
        mov     eax, [tx_buffer+ssh_header.length]
341
        mov     eax, dword[con.tx_buffer+ssh_packet_header.packet_length]
235
        bswap   eax
342
        bswap   eax
236
        movzx   ebx, [tx_buffer+ssh_header.padding]
343
        movzx   ebx, [con.tx_buffer+ssh_packet_header.padding_length]
237
        sub     eax, ebx
344
        sub     eax, ebx
238
        dec     eax
345
        dec     eax
239
        lea     edx, [eax+4]
346
        lea     edx, [eax+4]
240
        bswap   eax
347
        bswap   eax
241
        mov     [tx_buffer+1], eax
348
        mov     dword[con.tx_buffer+1], eax
242
        mov     esi, tx_buffer+1
349
        invoke  sha256_update, con.temp_ctx, con.tx_buffer+1, edx
243
        call    sha256_update
-
 
244
 
350
 
245
; Check key exchange init of server
351
; << Check key exchange init of server
246
        stdcall ssh_recv_packet, [socketnum], rx_buffer, BUFFERSIZE, 0
352
        stdcall ssh_recv_packet, con, 0
247
        cmp     eax, -1
353
        cmp     eax, -1
248
        je      socket_err
354
        je      socket_err
249
 
355
 
250
        cmp     [rx_buffer+ssh_header.message_code], SSH_MSG_KEXINIT
356
        cmp     [con.rx_buffer.message_code], SSH_MSG_KEXINIT
251
        jne     proto_err
357
        jne     proto_err
252
        DEBUGF  1, "Received KEX init\n"
358
        DEBUGF  2, "Received KEX init\n"
253
 
359
 
254
        lea     esi, [rx_buffer+sizeof.ssh_header+16]
360
        lea     esi, [con.rx_buffer+sizeof.ssh_packet_header+16]
255
        lodsd
361
        lodsd
256
        bswap   eax
362
        bswap   eax
257
        DEBUGF  1, "kex_algorithms: %s\n", esi
363
        DEBUGF  1, "kex_algorithms: %s\n", esi
258
        add     esi, eax
364
        add     esi, eax
259
        lodsd
365
        lodsd
260
        bswap   eax
366
        bswap   eax
261
        DEBUGF  1, "server_host_key_algorithms: %s\n", esi
367
        DEBUGF  1, "server_host_key_algorithms: %s\n", esi
262
        add     esi, eax
368
        add     esi, eax
263
        lodsd
369
        lodsd
264
        bswap   eax
370
        bswap   eax
265
        DEBUGF  1, "encryption_algorithms_client_to_server: %s\n", esi
371
        DEBUGF  1, "encryption_algorithms_client_to_server: %s\n", esi
266
        add     esi, eax
372
        add     esi, eax
267
        lodsd
373
        lodsd
268
        bswap   eax
374
        bswap   eax
269
        DEBUGF  1, "encryption_algorithms_server_to_client: %s\n", esi
375
        DEBUGF  1, "encryption_algorithms_server_to_client: %s\n", esi
270
        add     esi, eax
376
        add     esi, eax
271
        lodsd
377
        lodsd
272
        bswap   eax
378
        bswap   eax
273
        DEBUGF  1, "mac_algorithms_client_to_server: %s\n", esi
379
        DEBUGF  1, "mac_algorithms_client_to_server: %s\n", esi
274
        add     esi, eax
380
        add     esi, eax
275
        lodsd
381
        lodsd
276
        bswap   eax
382
        bswap   eax
277
        DEBUGF  1, "mac_algorithms_server_to_client: %s\n", esi
383
        DEBUGF  1, "mac_algorithms_server_to_client: %s\n", esi
278
        add     esi, eax
384
        add     esi, eax
279
        lodsd
385
        lodsd
280
        bswap   eax
386
        bswap   eax
281
        DEBUGF  1, "compression_algorithms_client_to_server: %s\n", esi
387
        DEBUGF  1, "compression_algorithms_client_to_server: %s\n", esi
282
        add     esi, eax
388
        add     esi, eax
283
        lodsd
389
        lodsd
284
        bswap   eax
390
        bswap   eax
285
        DEBUGF  1, "compression_algorithms_server_to_client: %s\n", esi
391
        DEBUGF  1, "compression_algorithms_server_to_client: %s\n", esi
286
        add     esi, eax
392
        add     esi, eax
287
        lodsd
393
        lodsd
288
        bswap   eax
394
        bswap   eax
289
        DEBUGF  1, "languages_client_to_server: %s\n", esi
395
        DEBUGF  1, "languages_client_to_server: %s\n", esi
290
        add     esi, eax
396
        add     esi, eax
291
        lodsd
397
        lodsd
292
        bswap   eax
398
        bswap   eax
293
        DEBUGF  1, "languages_server_to_client: %s\n", esi
399
        DEBUGF  1, "languages_server_to_client: %s\n", esi
294
        add     esi, eax
400
        add     esi, eax
295
        lodsb
401
        lodsb
296
        DEBUGF  1, "KEX First Packet Follows: %u\n", al
402
        DEBUGF  1, "KEX First Packet Follows: %u\n", al
297
 
403
 
298
        ; TODO
404
        ; TODO: parse this structure and init procedures accordingly
299
 
405
 
300
; HASH: string I_S, the payload of the servers's SSH_MSG_KEXINIT
406
; HASH: string I_S, the payload of the servers's SSH_MSG_KEXINIT
301
        mov     eax, [rx_buffer+ssh_header.length]
407
        mov     eax, dword[con.rx_buffer+ssh_packet_header.packet_length]
302
        movzx   ebx, [rx_buffer+ssh_header.padding]
408
        movzx   ebx, [con.rx_buffer+ssh_packet_header.padding_length]
303
        sub     eax, ebx
409
        sub     eax, ebx
304
        dec     eax
410
        dec     eax
305
        lea     edx, [eax+4]
411
        lea     edx, [eax+4]
306
        bswap   eax
412
        bswap   eax
307
        mov     [rx_buffer+sizeof.ssh_header-5], eax
413
        mov     dword[con.rx_buffer+sizeof.ssh_packet_header-5], eax
308
        mov     esi, rx_buffer+sizeof.ssh_header-5
414
        invoke  sha256_update, con.temp_ctx, con.rx_buffer+sizeof.ssh_packet_header-5, edx
309
        call    sha256_update
-
 
310
 
415
 
-
 
416
; Exchange keys with the server
311
; Exchange keys with the server
417
 
312
        stdcall dh_gex
418
        stdcall dh_gex
313
        test    eax, eax
419
        test    eax, eax
314
        jnz     exit
420
        jnz     exit
315
 
421
 
316
; Set keys
422
; Set keys
-
 
423
 
317
        DEBUGF  1, "SSH: Init encryption\n"
424
        DEBUGF  2, "SSH: Setting encryption keys\n"
-
 
425
 
318
        stdcall aes256_cbc_init, rx_iv
426
        stdcall aes256_cbc_init, con.rx_iv
319
        mov     [rx_context], eax
427
        mov     [con.rx_crypt_ctx_ptr], eax
-
 
428
 
320
        stdcall aes256_set_encrypt_key, [rx_context], rx_enc_key
429
        stdcall aes256_set_decrypt_key, eax, con.rx_enc_key
321
        mov     [decrypt_proc], aes256_cbc_decrypt
430
        mov     [con.rx_crypt_proc], aes256_cbc_decrypt
322
        mov     [rx_blocksize], 32
431
        mov     [con.rx_crypt_blocksize], AES256_BLOCKSIZE
323
 
432
 
324
        DEBUGF  1, "SSH: Init decryption\n"
-
 
325
        stdcall aes256_cbc_init, tx_iv
433
        stdcall aes256_cbc_init, con.tx_iv
326
        mov     [tx_context], eax
434
        mov     [con.tx_crypt_ctx_ptr], eax
-
 
435
 
327
        stdcall aes256_set_decrypt_key, [tx_context], tx_enc_key
436
        stdcall aes256_set_encrypt_key, eax, con.tx_enc_key
328
        mov     [encrypt_proc], aes256_cbc_encrypt
437
        mov     [con.tx_crypt_proc], aes256_cbc_encrypt
329
        mov     [tx_blocksize], 32
438
        mov     [con.tx_crypt_blocksize], AES256_BLOCKSIZE
-
 
439
 
-
 
440
        stdcall hmac_sha256_setkey, con.rx_mac_ctx, con.rx_int_key, SHA256_HASH_SIZE
-
 
441
        mov     [con.rx_mac_proc], hmac_sha256
-
 
442
        mov     [con.rx_mac_length], SHA256_HASH_SIZE
-
 
443
 
-
 
444
        stdcall hmac_sha256_setkey, con.tx_mac_ctx, con.tx_int_key, SHA256_HASH_SIZE
-
 
445
        mov     [con.tx_mac_proc], hmac_sha256
-
 
446
        mov     [con.tx_mac_length], SHA256_HASH_SIZE
-
 
447
 
-
 
448
; TODO: erase all keys from memory and free the memory
-
 
449
 
-
 
450
; >> Request service (user-auth)
-
 
451
 
-
 
452
        DEBUGF  2, "SSH: Requesting service\n"
-
 
453
 
-
 
454
        stdcall ssh_send_packet, con, ssh_request_service, ssh_request_service.length, 0
-
 
455
        cmp     eax, -1
-
 
456
        je      socket_err
-
 
457
 
-
 
458
; << Check for service acceptance
-
 
459
 
-
 
460
        stdcall ssh_recv_packet, con, 0
-
 
461
        cmp     eax, -1
-
 
462
        je      socket_err
-
 
463
 
-
 
464
        cmp     [con.rx_buffer.message_code], SSH_MSG_SERVICE_ACCEPT
-
 
465
        jne     proto_err
-
 
466
 
-
 
467
; >> Request user authentication
-
 
468
 
-
 
469
; TODO: Request username from the user
-
 
470
;        invoke  con_write_asciiz, str12
-
 
471
;        invoke  con_gets, username, 256
-
 
472
;        test    eax, eax
-
 
473
;        jz      done
-
 
474
 
-
 
475
; TODO: implement password authentication
-
 
476
 
-
 
477
        DEBUGF  2, "SSH: User authentication\n"
-
 
478
 
-
 
479
        stdcall ssh_send_packet, con, ssh_request_userauth, ssh_request_userauth.length, 0
-
 
480
        cmp     eax, -1
-
 
481
        je      socket_err
-
 
482
 
-
 
483
; << Check for userauth acceptance
-
 
484
 
-
 
485
        stdcall ssh_recv_packet, con, 0
-
 
486
        cmp     eax, -1
-
 
487
        je      socket_err
-
 
488
 
-
 
489
        cmp     [con.rx_buffer.message_code], SSH_MSG_USERAUTH_SUCCESS
-
 
490
        jne     proto_err
-
 
491
 
-
 
492
; >> Open channel
-
 
493
 
-
 
494
        DEBUGF  2, "SSH: Open channel\n"
-
 
495
 
-
 
496
        stdcall ssh_send_packet, con, ssh_channel_open, ssh_channel_open.length, 0
-
 
497
        cmp     eax, -1
-
 
498
        je      socket_err
-
 
499
 
-
 
500
; << Check for channel open confirmation
-
 
501
 
-
 
502
        stdcall ssh_recv_packet, con, 0
-
 
503
        cmp     eax, -1
-
 
504
        je      socket_err
-
 
505
 
-
 
506
        cmp     [con.rx_buffer.message_code], SSH_MSG_CHANNEL_OPEN_CONFIRMATION
-
 
507
        jne     proto_err
-
 
508
 
-
 
509
; >> Channel request: pty
-
 
510
 
-
 
511
        DEBUGF  2, "SSH: Request pty\n"
-
 
512
 
-
 
513
        stdcall ssh_send_packet, con, ssh_channel_request, ssh_channel_request.length, 0
-
 
514
        cmp     eax, -1
-
 
515
        je      socket_err
-
 
516
 
-
 
517
; << Check for channel request confirmation
-
 
518
 
-
 
519
        stdcall ssh_recv_packet, con, 0
-
 
520
        cmp     eax, -1
-
 
521
        je      socket_err
-
 
522
 
-
 
523
        cmp     [con.rx_buffer.message_code], SSH_MSG_CHANNEL_SUCCESS
-
 
524
        jne     proto_err
-
 
525
 
-
 
526
; >> Channel request: shell
-
 
527
 
-
 
528
        DEBUGF  2, "SSH: Request shell\n"
-
 
529
 
-
 
530
        stdcall ssh_send_packet, con, ssh_shell_request, ssh_shell_request.length, 0
-
 
531
        cmp     eax, -1
-
 
532
        je      socket_err
-
 
533
 
-
 
534
; << Check for channel request confirmation (FIXME: this may not be first packet!)
-
 
535
 
-
 
536
;        stdcall ssh_recv_packet, con, 0
-
 
537
;        cmp     eax, -1
-
 
538
;        je      socket_err
-
 
539
 
-
 
540
;        cmp     [con.rx_buffer.message_code], SSH_MSG_CHANNEL_SUCCESS
-
 
541
;        jne     proto_err
330
 
542
 
331
; Launch network thread
543
; Launch network thread
332
        mcall   18, 7
544
        mcall   18, 7
333
        push    eax
545
        push    eax
334
        mcall   51, 1, thread, mem - 2048
546
        mcall   51, 1, thread, mem - 2048
335
        pop     ecx
547
        pop     ecx
336
        mcall   18, 3
548
        mcall   18, 3
337
 
549
 
338
mainloop:
550
mainloop:
339
        call    [con_get_flags]
551
        call    [con_get_flags]
340
        test    eax, 0x200                      ; con window closed?
552
        test    eax, 0x200                      ; con window closed?
341
        jnz     exit
553
        jnz     exit
342
 
554
 
343
        stdcall ssh_recv_packet, [socketnum], rx_buffer, BUFFERSIZE, 0
555
        stdcall ssh_recv_packet, con, 0
344
        cmp     eax, -1
556
        cmp     eax, 0
-
 
557
        jbe     closed
-
 
558
 
-
 
559
        cmp     [con.rx_buffer.message_code], SSH_MSG_CHANNEL_DATA
-
 
560
        jne     .dump
-
 
561
 
345
        je      closed
562
        mov     eax, dword[con.rx_buffer.message_code+5]
-
 
563
        bswap   eax
-
 
564
        DEBUGF  1, 'SSH: got %u bytes of data !\n', eax
-
 
565
 
-
 
566
        lea     esi, [con.rx_buffer.message_code+5+4]
-
 
567
        mov     ecx, eax
-
 
568
        lea     edi, [esi + eax]
-
 
569
        mov     byte [edi], 0
-
 
570
        invoke  con_write_asciiz, esi
346
 
571
        jmp     mainloop
347
        DEBUGF  1, 'SSH: got %u bytes of data !\n', eax
572
 
348
 
573
  .dump:
349
        mov     esi, rx_buffer
574
        lea     esi, [con.rx_buffer]
350
        mov     ecx, eax
575
        mov     ecx, eax
351
        pusha
576
        pusha
352
@@:
577
@@:
353
        lodsb
578
        lodsb
354
        DEBUGF  1, "%x ", eax:2
579
        DEBUGF  1, "%x ", eax:2
355
        dec     ecx
580
        dec     ecx
356
        jnz     @r
581
        jnz     @r
357
        popa
582
        popa
358
        lea     edi, [esi + eax]
-
 
359
        mov     byte [edi], 0
583
        DEBUGF  1, "\n"
360
        invoke  con_write_asciiz, esi
-
 
361
        jmp     mainloop
584
        jmp     mainloop
-
 
585
 
362
 
586
 
363
proto_err:
587
proto_err:
364
        DEBUGF  1, "SSH: protocol error\n"
588
        DEBUGF  3, "SSH: protocol error\n"
365
        invoke  con_write_asciiz, str7
589
        invoke  con_write_asciiz, str7
366
        jmp     prompt
590
        jmp     prompt
367
 
591
 
368
socket_err:
592
socket_err:
369
        DEBUGF  1, "SSH: socket error %d\n", ebx
593
        DEBUGF  3, "SSH: socket error %d\n", ebx
370
        invoke  con_write_asciiz, str6
594
        invoke  con_write_asciiz, str6
371
        jmp     prompt
595
        jmp     prompt
372
 
596
 
373
dns_error:
597
dns_error:
374
        DEBUGF  1, "SSH: DNS error %d\n", eax
598
        DEBUGF  3, "SSH: DNS error %d\n", eax
375
        invoke  con_write_asciiz, str5
599
        invoke  con_write_asciiz, str5
376
        jmp     prompt
600
        jmp     prompt
377
 
601
 
378
hostname_error:
602
hostname_error:
379
        invoke  con_write_asciiz, str10
603
        invoke  con_write_asciiz, str10
380
        jmp     prompt
604
        jmp     prompt
381
 
605
 
382
closed:
606
closed:
383
        invoke  con_write_asciiz, str11
607
        invoke  con_write_asciiz, str11
384
        jmp     prompt
608
        jmp     prompt
385
 
609
 
386
done:
610
done:
387
        invoke  con_exit, 1
611
        invoke  con_exit, 1
388
exit:
612
exit:
389
        DEBUGF  1, "SSH: Exiting\n"
613
        DEBUGF  3, "SSH: Exiting\n"
390
        mcall   close, [socketnum]
614
        mcall   close, [con.socketnum]
391
        mcall   -1
615
        mcall   -1
392
 
616
 
393
 
617
 
394
thread:
618
thread:
395
        mcall   40, 0
619
        mcall   40, 0
396
  .loop:
620
  .loop:
397
        invoke  con_getch2
621
        invoke  con_getch2
398
        mov     [send_data], ax
622
        mov     [ssh_channel_data+9], al
399
        xor     esi, esi
-
 
400
        inc     esi
-
 
401
        test    al, al
-
 
402
        jnz     @f
-
 
403
        inc     esi
-
 
404
  @@:
-
 
405
        stdcall ssh_send_packet, [socketnum], send_data, 0
623
        stdcall ssh_send_packet, con, ssh_channel_data, ssh_channel_data.length, 0
406
 
624
 
407
        invoke  con_get_flags
625
        invoke  con_get_flags
408
        test    eax, 0x200                      ; con window closed?
626
        test    eax, 0x200                      ; con window closed?
409
        jz      .loop
627
        jz      .loop
410
        mcall   -1
628
        mcall   -1
411
 
629
 
412
; data
630
; data
413
title   db      'Secure Shell',0
631
title   db      'Secure Shell',0
414
str1    db      'SSH client for KolibriOS',10,10,\
632
str1    db      'SSH client for KolibriOS',10,10,\
415
                'Please enter URL of SSH server (host:port)',10,10,0
633
                'Please enter URL of SSH server (host:port)',10,10,0
416
str2    db      '> ',0
634
str2    db      '> ',0
417
str3    db      'Connecting to ',0
635
str3    db      'Connecting to ',0
418
str4    db      10,0
636
str4    db      10,0
419
str5    db      'Name resolution failed.',10,10,0
637
str5    db      'Name resolution failed.',10,10,0
420
str6    db      'A socket error occured.',10,10,0
638
str6    db      'A socket error occured.',10,10,0
421
str7    db      'A protocol error occured.',10,10,0
639
str7    db      'A protocol error occured.',10,10,0
422
str8    db      ' (',0
640
str8    db      ' (',0
423
str9    db      ')',10,0
641
str9    db      ')',10,0
424
str10   db      'Invalid hostname.',10,10,0
642
str10   db      'Invalid hostname.',10,10,0
425
str11   db      10,'Remote host closed the connection.',10,10,0
643
str11   db      10,'Remote host closed the connection.',10,10,0
426
 
-
 
427
sockaddr1:
-
 
428
        dw AF_INET4
644
str12   db      'Enter username: ',0
429
  .port dw 0
-
 
430
  .ip   dd 0
-
 
431
        rb 10
-
 
432
 
645
 
433
ssh_ident_ha:
646
ssh_ident_ha:
434
        dd_n (ssh_ident.length-2)
647
        dd_n (ssh_ident.length-2)
435
ssh_ident:
648
ssh_ident:
436
        db "SSH-2.0-KolibriOS_SSH_0.01",13,10
649
        db "SSH-2.0-KolibriOS_SSH_0.02",13,10
437
  .length = $ - ssh_ident
650
  .length = $ - ssh_ident
438
 
651
 
439
ssh_kex:
652
ssh_kex:
440
        db SSH_MSG_KEXINIT
653
        db SSH_MSG_KEXINIT
441
  .cookie:
654
  .cookie:
442
        rd 4
655
        rd 4
443
  .kex_algorithms:
656
  .kex_algorithms:
444
        dd_n .server_host_key_algorithms - .kex_algorithms - 4
657
        dd_n .server_host_key_algorithms - .kex_algorithms - 4
445
        db "diffie-hellman-group-exchange-sha256" ; diffie-hellman-group-exchange-sha1
658
        db "diffie-hellman-group-exchange-sha256" ; diffie-hellman-group-exchange-sha1
446
  .server_host_key_algorithms:
659
  .server_host_key_algorithms:
447
        dd_n .encryption_algorithms_client_to_server - .server_host_key_algorithms - 4
660
        dd_n .encryption_algorithms_client_to_server - .server_host_key_algorithms - 4
448
        db "ssh-rsa"                    ;,ssh-dss
661
        db "ssh-rsa"                    ;,ssh-dss
449
  .encryption_algorithms_client_to_server:
662
  .encryption_algorithms_client_to_server:
450
        dd_n .encryption_algorithms_server_to_client - .encryption_algorithms_client_to_server - 4
663
        dd_n .encryption_algorithms_server_to_client - .encryption_algorithms_client_to_server - 4
451
        db "aes256-cbc"                 ;,aes256-ctr,aes256-cbc,rijndael-cbc@lysator.liu.se,aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc,arcfour256,arcfour128"
664
        db "aes256-cbc"                 ;,aes256-ctr,aes256-cbc,rijndael-cbc@lysator.liu.se,aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc,arcfour256,arcfour128"
452
  .encryption_algorithms_server_to_client:
665
  .encryption_algorithms_server_to_client:
453
        dd_n .mac_algorithms_client_to_server - .encryption_algorithms_server_to_client - 4
666
        dd_n .mac_algorithms_client_to_server - .encryption_algorithms_server_to_client - 4
454
        db "aes256-cbc"                 ;,aes256-ctr,aes256-cbc,rijndael-cbc@lysator.liu.se,aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc,arcfour256,arcfour128"
667
        db "aes256-cbc"                 ;,aes256-ctr,aes256-cbc,rijndael-cbc@lysator.liu.se,aes192-ctr,aes192-cbc,aes128-ctr,aes128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc,arcfour256,arcfour128"
455
  .mac_algorithms_client_to_server:
668
  .mac_algorithms_client_to_server:
456
        dd_n .mac_algorithms_server_to_client - .mac_algorithms_client_to_server - 4
669
        dd_n .mac_algorithms_server_to_client - .mac_algorithms_client_to_server - 4
457
        db "hmac-sha2-256"              ;,hmac-sha1,hmac-sha1-96,hmac-md5"
670
        db "hmac-sha2-256"              ;,hmac-sha1,hmac-sha1-96,hmac-md5"
458
  .mac_algorithms_server_to_client:
671
  .mac_algorithms_server_to_client:
459
        dd_n .compression_algorithms_client_to_server - .mac_algorithms_server_to_client - 4
672
        dd_n .compression_algorithms_client_to_server - .mac_algorithms_server_to_client - 4
460
        db "hmac-sha2-256"              ;,hmac-sha1,hmac-sha1-96,hmac-md5"
673
        db "hmac-sha2-256"              ;,hmac-sha1,hmac-sha1-96,hmac-md5"
461
  .compression_algorithms_client_to_server:
674
  .compression_algorithms_client_to_server:
462
        dd_n .compression_algorithms_server_to_client - .compression_algorithms_client_to_server - 4
675
        dd_n .compression_algorithms_server_to_client - .compression_algorithms_client_to_server - 4
463
        db "none"                       ;,zlib"
676
        db "none"                       ;,zlib"
464
  .compression_algorithms_server_to_client:
677
  .compression_algorithms_server_to_client:
465
        dd_n .languages_client_to_server - .compression_algorithms_server_to_client - 4
678
        dd_n .languages_client_to_server - .compression_algorithms_server_to_client - 4
466
        db "none"                       ;,zlib"
679
        db "none"                       ;,zlib"
467
  .languages_client_to_server:
680
  .languages_client_to_server:
468
        dd_n .languages_server_to_client - .languages_client_to_server - 4
681
        dd_n .languages_server_to_client - .languages_client_to_server - 4
469
        db ""
682
        db ""
470
  .languages_server_to_client:
683
  .languages_server_to_client:
471
        dd_n .first_kex_packet_follows - .languages_server_to_client - 4
684
        dd_n .first_kex_packet_follows - .languages_server_to_client - 4
472
        db ""
685
        db ""
473
  .first_kex_packet_follows:
686
  .first_kex_packet_follows:
474
        db 0
687
        db 0
475
  .reserved:
688
  .reserved:
476
        dd_n 0
689
        dd_n 0
477
  .length = $ - ssh_kex
690
  .length = $ - ssh_kex
478
 
691
 
479
 
692
 
480
ssh_gex_req:
693
ssh_gex_req:
481
        db SSH_MSG_KEX_DH_GEX_REQUEST
694
        db SSH_MSG_KEX_DH_GEX_REQUEST
482
        dd_n 128                ; DH GEX min
695
        dd_n 128                        ; DH GEX min
483
        dd_n 256                ; DH GEX number of bits
696
        dd_n 256                        ; DH GEX number of bits
484
        dd_n 512                ; DH GEX Max
697
        dd_n 512                        ; DH GEX Max
485
  .length = $ - ssh_gex_req
698
  .length = $ - ssh_gex_req
486
 
699
 
487
 
700
 
488
ssh_new_keys:
701
ssh_new_keys:
489
        db SSH_MSG_NEWKEYS
702
        db SSH_MSG_NEWKEYS
490
  .length = $ - ssh_new_keys
703
  .length = $ - ssh_new_keys
491
 
704
 
492
 
705
 
-
 
706
ssh_request_service:
-
 
707
        db SSH_MSG_SERVICE_REQUEST
-
 
708
        dd_n 12                         ; String length
-
 
709
        db "ssh-userauth"               ; Service name
-
 
710
  .length = $ - ssh_request_service
-
 
711
 
-
 
712
 
-
 
713
ssh_request_userauth:
-
 
714
        db SSH_MSG_USERAUTH_REQUEST
-
 
715
        dd_n 12
-
 
716
        dd_n 8
-
 
717
        db "username"                   ; user name in ISO-10646 UTF-8 encoding [RFC3629]
-
 
718
        dd_n 14
-
 
719
        db "ssh-connection"             ; service name in US-ASCII
-
 
720
        dd_n 4
-
 
721
        db "none"                       ; method name in US-ASCII
-
 
722
; Other options: publickey, password, hostbased
-
 
723
  .length = $ - ssh_request_userauth
-
 
724
 
-
 
725
 
-
 
726
ssh_channel_open:
-
 
727
        db SSH_MSG_CHANNEL_OPEN
-
 
728
        dd_n 7
-
 
729
        db "session"
-
 
730
        dd_n 0                          ; Sender channel
-
 
731
        dd_n 1024                       ; Initial window size
-
 
732
        dd_n 1024                       ; maximum packet size
-
 
733
  .length = $ - ssh_channel_open
-
 
734
 
-
 
735
ssh_channel_request:
-
 
736
        db SSH_MSG_CHANNEL_REQUEST
-
 
737
        dd_n 0                          ; Recipient channel
-
 
738
        dd_n 7
-
 
739
        db "pty-req"
-
 
740
        db 1                            ; Bool: want reply
-
 
741
        dd_n 5
-
 
742
        db "xterm"
-
 
743
        dd_n 80                         ; terminal width (rows)
-
 
744
        dd_n 25                         ; terminal height (rows)
-
 
745
        dd_n 0                          ; terminal width (pixels)
-
 
746
        dd_n 0                          ; terminal height (pixels)
-
 
747
 
-
 
748
        dd_n 0                          ; list of supported opcodes
-
 
749
  .length = $ - ssh_channel_request
-
 
750
 
-
 
751
ssh_shell_request:
-
 
752
        db SSH_MSG_CHANNEL_REQUEST
-
 
753
        dd_n 0                          ; Recipient channel
-
 
754
        dd_n 5
-
 
755
        db "shell"
-
 
756
        db 1                            ; Bool: want reply
-
 
757
  .length = $ - ssh_shell_request
-
 
758
 
-
 
759
ssh_channel_data:
-
 
760
        db SSH_MSG_CHANNEL_DATA
-
 
761
        dd_n 0                          ; Sender channel
-
 
762
        dd_n 1
-
 
763
        db ?
493
include_debug_strings
764
  .length = $ - ssh_channel_data
-
 
765
 
494
 
766
 
495
 
767
include_debug_strings
496
; import
768
 
497
align 4
769
align 4
498
@IMPORT:
770
@IMPORT:
499
 
771
 
500
library network, 'network.obj', \
772
library network, 'network.obj', \
501
        console, 'console.obj';, \
773
        console, 'console.obj', \
502
;        libcrash, 'libcrash.obj'
774
        libcrash, 'libcrash.obj'
503
 
775
 
504
import  network, \
776
import  network, \
505
        getaddrinfo, 'getaddrinfo', \
777
        getaddrinfo, 'getaddrinfo', \
506
        freeaddrinfo, 'freeaddrinfo', \
778
        freeaddrinfo, 'freeaddrinfo', \
507
        inet_ntoa, 'inet_ntoa'
779
        inet_ntoa, 'inet_ntoa'
508
 
780
 
509
import  console, \
781
import  console, \
510
        con_start, 'START', \
782
        con_start, 'START', \
511
        con_init, 'con_init', \
783
        con_init, 'con_init', \
512
        con_write_asciiz, 'con_write_asciiz', \
784
        con_write_asciiz, 'con_write_asciiz', \
513
        con_exit, 'con_exit', \
785
        con_exit, 'con_exit', \
514
        con_gets, 'con_gets', \
786
        con_gets, 'con_gets', \
515
        con_cls, 'con_cls', \
787
        con_cls, 'con_cls', \
516
        con_getch2, 'con_getch2', \
788
        con_getch2, 'con_getch2', \
517
        con_set_cursor_pos, 'con_set_cursor_pos', \
789
        con_set_cursor_pos, 'con_set_cursor_pos', \
518
        con_write_string, 'con_write_string', \
790
        con_write_string, 'con_write_string', \
519
        con_get_flags,  'con_get_flags'
791
        con_get_flags,  'con_get_flags'
520
 
792
 
-
 
793
import  libcrash, \
-
 
794
        sha256_init, 'sha256_init', \
521
;import  libcrash, \
795
        sha256_update, 'sha256_update', \
522
;        crash.hash, 'crash_hash'
796
        sha256_final, 'sha256_final'
523
 
797
 
524
IncludeIGlobals
798
IncludeIGlobals
525
 
799
 
526
i_end:
800
i_end:
527
 
-
 
528
decrypt_proc    dd dummy_encrypt
-
 
529
encrypt_proc    dd dummy_encrypt
-
 
530
rx_blocksize    dd 4
-
 
531
tx_blocksize    dd 4
-
 
532
rx_context      dd ?
-
 
533
tx_context      dd ?
-
 
534
 
801
 
535
IncludeUGlobals
-
 
536
 
-
 
537
socketnum       dd ?
-
 
538
rx_packet_length dd ?   ;;;;;
-
 
539
rx_buffer:      rb BUFFERSIZE+1
-
 
540
tx_buffer:      rb BUFFERSIZE+1
-
 
541
 
-
 
542
send_data       dw ?
802
IncludeUGlobals
543
 
-
 
544
hostname        rb 1024
-
 
545
 
-
 
546
; Diffie Hellman variables
-
 
547
dh_p            dd ?
-
 
548
                rb MAX_BITS/8
-
 
549
dh_g            dd ?
-
 
550
                rb MAX_BITS/8
-
 
551
dh_x            dd ?
-
 
552
                rb MAX_BITS/8
-
 
553
dh_e            dd ?
-
 
554
                rb MAX_BITS/8
-
 
555
dh_f            dd ?
-
 
556
                rb MAX_BITS/8
-
 
557
 
-
 
558
dh_signature    dd ?
-
 
559
                rb MAX_BITS/8
-
 
560
 
-
 
561
; Output from key exchange
-
 
562
dh_K            dd ?            ; Shared Secret (Big endian)
-
 
563
                rb MAX_BITS/8
-
 
564
  .length       dd ?            ; Length in little endian
-
 
565
 
-
 
566
dh_H            rb 32           ; Exchange Hash
-
 
567
session_id      rb 32
-
 
568
rx_iv           rb 32           ; Rx initialisation vector
803
 
569
tx_iv           rb 32           ; Tx initialisation vector
-
 
570
rx_enc_key      rb 32           ; Rx encryption key
-
 
571
tx_enc_key      rb 32           ; Tx encryption key
804
params          rb 1024
572
rx_int_key      rb 32           ; Rx integrity key
805
 
-
 
806
con             ssh_connection
573
tx_int_key      rb 32           ; Tx integrity key
807
 
574
 
808
; Temporary values      ; To be removed FIXME
575
; Temporary values      ; To be removed
809
mpint_tmp       rb MPINT_MAX_LEN+4
576
mpint_tmp       rb MPINT_MAX_LEN+4
810
 
577
 
811
 
578
mem:
812
mem: