Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;    ssh_userauth.inc - SSH user authentication
  2. ;
  3. ;    Copyright (C) 2021 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.  
  19. proc sshlib_userauth_password con_ptr, username_sz, password_sz
  20.  
  21. ; >> Request service (user-auth)
  22.  
  23.         DEBUGF  2, "SSH: Requesting service\n"
  24.  
  25.         stdcall sshlib_send_packet, [con_ptr], ssh_msg_request_service, ssh_msg_request_service.length, 0
  26.         cmp     eax, 0
  27.         jl      .err
  28.  
  29. ; << Check for service acceptance
  30.  
  31.         stdcall sshlib_msg_handler, [con_ptr], 0
  32.         cmp     eax, 0
  33.         jl      .err
  34.  
  35.         mov     eax, [con_ptr]
  36.         cmp     [eax + sshlib_connection.rx_buffer.message_code], SSH_MSG_SERVICE_ACCEPT
  37.         jne     .err_proto
  38.  
  39. ; >> Request user authentication
  40.  
  41.         DEBUGF  2, "SSH: User authentication\n"
  42.  
  43.         mcall   68, 12, 1024    ; FIXME: hardcoded size
  44.         test    eax, eax
  45.         jz      .err_nomem
  46.         mov     edi, eax
  47.         mov     ebx, eax
  48.         mov     byte[edi], SSH_MSG_USERAUTH_REQUEST
  49.         inc     edi
  50.  
  51. ; Insert username
  52.         stdcall sz_len, [username_sz]
  53.         mov     ecx, eax
  54.         mov     esi, [username_sz]
  55.         bswap   eax
  56.         stosd
  57.         rep movsb
  58.  
  59.         mov     dword[edi], 0x0e000000  ; 14 Bswapped
  60.         mov     dword[edi+4], "ssh-"
  61.         mov     dword[edi+8], "conn"
  62.         mov     dword[edi+12], "ecti"
  63.         mov     word[edi+16], "on"
  64.         add     edi, 18
  65.  
  66.         mov     dword[edi], 0x08000000  ; 8 Bswapped
  67.         mov     dword[edi+4], "pass"
  68.         mov     dword[edi+8], "word"
  69.  
  70.         mov     byte[edi+12], 0         ; bool
  71.         add     edi, 13
  72.  
  73. ; Insert password
  74.         stdcall sz_len, [password_sz]
  75.         mov     ecx, eax
  76.         mov     esi, [password_sz]
  77.         bswap   eax
  78.         stosd
  79.         rep movsb
  80.  
  81.         sub     edi, ebx
  82.         push    ebx
  83.         stdcall sshlib_send_packet, [con_ptr], ebx, edi, 0
  84.  
  85. ; Clear used buffer and free
  86.         pop     edx
  87.         mov     edi, edx
  88.         push    eax
  89.         mov     ecx, 1024/4     ; FIXME
  90.         xor     eax, eax
  91.         rep stosd
  92.         mcall   68, 13, edx
  93.         pop     eax
  94.  
  95.         cmp     eax, 0
  96.         jl      .err
  97.  
  98. ; << Check for userauth acceptance
  99.   @@:
  100.         stdcall sshlib_msg_handler, [con_ptr], 0
  101.         cmp     eax, 0
  102.         jl      .err
  103.  
  104.         mov     eax, [con_ptr]
  105.         mov     al, [eax + sshlib_connection.rx_buffer.message_code]
  106.  
  107.         cmp     al, SSH_MSG_USERAUTH_BANNER
  108.         je      @r      ; TODO
  109.  
  110.         cmp     al, SSH_MSG_USERAUTH_FAILURE
  111.         je      .fail
  112.  
  113.         cmp     al, SSH_MSG_USERAUTH_SUCCESS
  114.         jne     .err_proto
  115.  
  116.         xor     eax, eax
  117.   .err:
  118.         ret
  119.  
  120.   .fail:
  121.         xor     eax, eax
  122.         inc     eax
  123.         ret
  124.  
  125.   .err_proto:
  126.         mov     eax, SSHLIB_ERR_PROTOCOL
  127.         ret
  128.  
  129.   .err_nomem:
  130.         mov     eax, SSHLIB_ERR_NOMEM
  131.         ret
  132.  
  133.  
  134. endp
  135.  
  136.  
  137. ; Actually, string is \n and/or \0 terminated 0_o
  138. proc sz_len uses ecx edi, string
  139.  
  140.         mov     edi, [string]
  141.         mov     ecx, 256     ;;;;
  142.         mov     al, 10
  143.         repne scasb
  144.         dec     edi
  145.         sub     edi, [string]
  146.         mov     eax, edi
  147.         ret
  148.  
  149. endp