Subversion Repositories Kolibri OS

Rev

Rev 6922 | Rev 9070 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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