65 lines
1.9 KiB
OCaml
65 lines
1.9 KiB
OCaml
(* ssh rfc: https://datatracker.ietf.org/doc/html/rfc4253 *)
|
|
|
|
open Unix
|
|
open Printf
|
|
|
|
open CoqSSH
|
|
open Message
|
|
module M = Message
|
|
|
|
let () =
|
|
let addr_str = "10.7.0.4" in
|
|
|
|
let socket_fd = socket PF_INET SOCK_STREAM 0 in
|
|
let inet_addr = inet_addr_of_string addr_str in
|
|
let sock_addr = ADDR_INET (inet_addr, 22) in
|
|
|
|
connect socket_fd sock_addr;
|
|
printf "Connected to %s.\n" addr_str;
|
|
|
|
(* protocol negotiation *)
|
|
|
|
let hello = "2.0 SSH-2.0-CoqSSH0.1\r\n" |> Bytes.of_string in
|
|
let bytes_written = write socket_fd hello 0 (Bytes.length hello) in
|
|
printf "Sent greeting (%d bytes).\n" bytes_written;
|
|
|
|
let buf = Bytes.create 1024 in
|
|
let bytes_read = read socket_fd buf 0 1024 in
|
|
let actual = Bytes.sub buf 0 bytes_read |> Bytes.to_string in
|
|
printf "Read '%s' (%d bytes).\n" actual bytes_read;
|
|
|
|
let version = "SSH-2.0-CoqSSH0.1 Coggers\r\n" |> Bytes.of_string in
|
|
let bytes_written = write socket_fd version 0 (Bytes.length version) in
|
|
printf "Sent protocol version (%d bytes).\n" bytes_written;
|
|
|
|
(* key exchange *)
|
|
|
|
let kex_msg = M.empty () in
|
|
M.add_byte kex_msg msg_kexinit;
|
|
(*
|
|
byte SSH_MSG_KEXINIT
|
|
byte[16] cookie (random bytes)
|
|
name-list kex_algorithms
|
|
name-list server_host_key_algorithms
|
|
name-list encryption_algorithms_client_to_server
|
|
name-list encryption_algorithms_server_to_client
|
|
name-list mac_algorithms_client_to_server
|
|
name-list mac_algorithms_server_to_client
|
|
name-list compression_algorithms_client_to_server
|
|
name-list compression_algorithms_server_to_client
|
|
name-list languages_client_to_server
|
|
name-list languages_server_to_client
|
|
boolean first_kex_packet_follows
|
|
uint32 0 (reserved for future extension)
|
|
*)
|
|
printf "len %d\n" (M.off kex_msg);
|
|
|
|
(* random crap *)
|
|
|
|
let n : SSH.nat = SSH.O in
|
|
match n with
|
|
| SSH.O -> print_endline "o"
|
|
| _ -> ();
|
|
|
|
close socket_fd;
|