anchor.diff:      KnownHostsEnc = public_key:ssh_encode(KnownHosts, known_hosts),
       KHFile = filename:join(UserDir, "known_hosts"),
       file:write_file(KHFile, KnownHostsEnc).
  -
  -setup_dsa_auth_keys(Dir, UserDir) ->
  -    {ok, Pem} = file:read_file(filename:join(Dir, "id_dsa")),
  -    DSA = public_key:pem_entry_decode(hd(public_key:pem_decode(Pem))),
  -    PKey = DSA#'DSAPrivateKey'.y,
  -    P = DSA#'DSAPrivateKey'.p,
  -    Q = DSA#'DSAPrivateKey'.q,
  -    G = DSA#'DSAPrivateKey'.g,
  -    Dss = #'Dss-Parms'{p=P, q=Q, g=G},
  -    setup_auth_keys([{{PKey, Dss}, [{comment, "Test"}]}], UserDir).
  -
  -setup_rsa_auth_keys(Dir, UserDir) ->
  -    {ok, Pem} = file:read_file(filename:join(Dir, "id_rsa")),
  -    RSA = public_key:pem_entry_decode(hd(public_key:pem_decode(Pem))),
  -    #'RSAPrivateKey'{publicExponent = E, modulus = N} = RSA,
  -    PKey = #'RSAPublicKey'{publicExponent = E, modulus = N},
  -    setup_auth_keys([{ PKey, [{comment, "Test"}]}], UserDir).
  -
  -setup_ecdsa_auth_keys(Size, Dir, UserDir) ->
  -    {ok, Pem} =
  -        case file:read_file(F=filename:join(Dir, "id_ecdsa"++Size)) of
  -            {error,E} ->
  -                ct:log("Failed (~p) to read ~p~nFiles: ~p", [E,F,file:list_dir(Dir)]),
  -                file:read_file(filename:join(Dir, "id_ecdsa"));
  -            Other ->
  -                Other
  -        end,
  -    ECDSA = public_key:pem_entry_decode(hd(public_key:pem_decode(Pem))),
  -    #'ECPrivateKey'{publicKey = Q,
  -		    parameters = Param = {namedCurve,_Id0}} = ECDSA,
  -    PKey = #'ECPoint'{point = Q},
  -    setup_auth_keys([{ {PKey,Param}, [{comment, "Test"}]}], UserDir).
  -
  -setup_eddsa_auth_keys(Alg, Dir, UserDir) ->
  -    SshAlg = case Alg of
  -                 ed25519 -> 'ssh-ed25519';
  -                 ed448 -> 'ssh-ed448'
  -             end,
  -    {ok, {ed_pri,Alg,Pub,_}} = ssh_file:user_key(SshAlg, [{user_dir,Dir}]),
  -    setup_auth_keys([{{ed_pub,Alg,Pub}, [{comment, "Test"}]}], UserDir).
   
   setup_auth_keys(Keys, Dir) ->
       AuthKeys = public_key:ssh_encode(Keys, auth_keys),
  
positive.code: 	    file:rename(B, KnownHosts)
      end.
  
  setup_dsa(DataDir, UserDir) ->
      file:copy(filename:join(DataDir, "id_dsa"), filename:join(UserDir, "id_dsa")),
      System = filename:join(UserDir, "system"),
      file:make_dir(System),
      file:copy(filename:join(DataDir, "ssh_host_dsa_key"), filename:join(System, "ssh_host_dsa_key")),
      file:copy(filename:join(DataDir, "ssh_host_dsa_key.pub"), filename:join(System, "ssh_host_dsa_key.pub")),
  ct:log("DataDir ~p:~n ~p~n~nSystDir ~p:~n ~p~n~nUserDir ~p:~n ~p",[DataDir, file:list_dir(DataDir), System, file:list_dir(System), UserDir, file:list_dir(UserDir)]),
      setup_dsa_known_host(DataDir, UserDir),
      setup_dsa_auth_keys(DataDir, UserDir).
      
  setup_rsa(DataDir, UserDir) ->
      file:copy(filename:join(DataDir, "id_rsa"), filename:join(UserDir, "id_rsa")),
      System = filename:join(UserDir, "system"),
      file:make_dir(System),
      file:copy(filename:join(DataDir, "ssh_host_rsa_key"), filename:join(System, "ssh_host_rsa_key")),
      file:copy(filename:join(DataDir, "ssh_host_rsa_key.pub"), filename:join(System, "ssh_host_rsa_key.pub")),
  ct:log("DataDir ~p:~n ~p~n~nSystDir ~p:~n ~p~n~nUserDir ~p:~n ~p",[DataDir, file:list_dir(DataDir), System, file:list_dir(System), UserDir, file:list_dir(UserDir)]),
      setup_rsa_known_host(DataDir, UserDir),
      setup_rsa_auth_keys(DataDir, UserDir).
  
  setup_ecdsa(Size, DataDir, UserDir) ->
      file:copy(filename:join(DataDir, "id_ecdsa"++Size), filename:join(UserDir, "id_ecdsa")),
      System = filename:join(UserDir, "system"),
      file:make_dir(System),
      file:copy(filename:join(DataDir, "ssh_host_ecdsa_key"++Size), filename:join(System, "ssh_host_ecdsa_key")),
      file:copy(filename:join(DataDir, "ssh_host_ecdsa_key"++Size++".pub"), filename:join(System, "ssh_host_ecdsa_key.pub")),
  ct:log("DataDir ~p:~n ~p~n~nSystDir ~p:~n ~p~n~nUserDir ~p:~n ~p",[DataDir, file:list_dir(DataDir), System, file:list_dir(System), UserDir, file:list_dir(UserDir)]),
      setup_ecdsa_known_host(Size, System, UserDir),
      setup_ecdsa_auth_keys(Size, DataDir, UserDir).
  
  setup_eddsa(Alg, DataDir, UserDir) ->
      {IdPriv, _IdPub, HostPriv, HostPub} =
          case Alg of
              ed25519 -> {"id_ed25519", "id_ed25519.pub", "ssh_host_ed25519_key", "ssh_host_ed25519_key.pub"};
              ed448   -> {"id_ed448",   "id_ed448.pub",   "ssh_host_ed448_key",   "ssh_host_ed448_key.pub"}
          end,
      file:copy(filename:join(DataDir, IdPriv), filename:join(UserDir, IdPriv)),
      System = filename:join(UserDir, "system"),
      file:make_dir(System),
      file:copy(filename:join(DataDir, HostPriv), filename:join(System, HostPriv)),
      file:copy(filename:join(DataDir, HostPub), filename:join(System, HostPub)),
  ct:log("DataDir ~p:~n ~p~n~nSystDir ~p:~n ~p~n~nUserDir ~p:~n ~p",[DataDir, file:list_dir(DataDir), System, file:list_dir(System), UserDir, file:list_dir(UserDir)]),
      setup_eddsa_known_host(HostPub, DataDir, UserDir),
      setup_eddsa_auth_keys(Alg, DataDir, UserDir).
  
  clean_dsa(UserDir) ->
      del_dirs(filename:join(UserDir, "system")),
      file:delete(filename:join(UserDir,"id_dsa")),
      file:delete(filename:join(UserDir,"known_hosts")),
      file:delete(filename:join(UserDir,"authorized_keys")).
  
  clean_rsa(UserDir) ->
      del_dirs(filename:join(UserDir, "system")),
      file:delete(filename:join(UserDir,"id_rsa")),
      file:delete(filename:join(UserDir,"known_hosts")),
      file:delete(filename:join(UserDir,"authorized_keys")).
  
  setup_dsa_pass_phrase(DataDir, UserDir, Phrase) ->
      try
          {ok, KeyBin} = file:read_file(filename:join(DataDir, "id_dsa")),
          setup_pass_phrase(KeyBin, filename:join(UserDir, "id_dsa"), Phrase),
          System = filename:join(UserDir, "system"),
          file:make_dir(System),
          file:copy(filename:join(DataDir, "ssh_host_dsa_key"), filename:join(System, "ssh_host_dsa_key")),
          file:copy(filename:join(DataDir, "ssh_host_dsa_key.pub"), filename:join(System, "ssh_host_dsa_key.pub")),
          setup_dsa_known_host(DataDir, UserDir),
          setup_dsa_auth_keys(DataDir, UserDir)
      of 
          _ -> true
      catch
          _:_ -> false
      end.
  
  setup_rsa_pass_phrase(DataDir, UserDir, Phrase) ->
      try
          {ok, KeyBin} = file:read_file(filename:join(DataDir, "id_rsa")),
          setup_pass_phrase(KeyBin, filename:join(UserDir, "id_rsa"), Phrase),
          System = filename:join(UserDir, "system"),
          file:make_dir(System),
          file:copy(filename:join(DataDir, "ssh_host_rsa_key"), filename:join(System, "ssh_host_rsa_key")),
          file:copy(filename:join(DataDir, "ssh_host_rsa_key.pub"), filename:join(System, "ssh_host_rsa_key.pub")),
          setup_rsa_known_host(DataDir, UserDir),
          setup_rsa_auth_keys(DataDir, UserDir)
      of 
          _ -> true
      catch
          _:_ -> false
      end.
  
  setup_ecdsa_pass_phrase(Size, DataDir, UserDir, Phrase) ->
      try
          {ok, KeyBin} = 
              case file:read_file(F=filename:join(DataDir, "id_ecdsa"++Size)) of
                  {error,E} ->
                      ct:log("Failed (~p) to read ~p~nFiles: ~p", [E,F,file:list_dir(DataDir)]),
                      file:read_file(filename:join(DataDir, "id_ecdsa"));
                  Other ->
                      Other
              end,
          setup_pass_phrase(KeyBin, filename:join(UserDir, "id_ecdsa"), Phrase),
          System = filename:join(UserDir, "system"),
          file:make_dir(System),
          file:copy(filename:join(DataDir, "ssh_host_ecdsa_key"++Size), filename:join(System, "ssh_host_ecdsa_key")),
          file:copy(filename:join(DataDir, "ssh_host_ecdsa_key"++Size++".pub"), filename:join(System, "ssh_host_ecdsa_key.pub")),
          setup_ecdsa_known_host(Size, System, UserDir),
          setup_ecdsa_auth_keys(Size, DataDir, UserDir)
      of 
          _ -> true
      catch
          _:_ -> false
      end.
  
  setup_pass_phrase(KeyBin, OutFile, Phrase) ->
      [{KeyType, _,_} = Entry0] = public_key:pem_decode(KeyBin),
      Key =  public_key:pem_entry_decode(Entry0),
      Salt = crypto:strong_rand_bytes(8),
      Entry = public_key:pem_entry_encode(KeyType, Key,
  					{{"DES-CBC", Salt}, Phrase}),
      Pem = public_key:pem_encode([Entry]),
      file:write_file(OutFile, Pem).
  
  setup_dsa_known_host(SystemDir, UserDir) ->
      {ok, SshBin} = file:read_file(filename:join(SystemDir, "ssh_host_dsa_key.pub")),
      [{Key, _}] = public_key:ssh_decode(SshBin, public_key),
      setup_known_hosts(Key, UserDir).
  
  setup_rsa_known_host(SystemDir, UserDir) ->
      {ok, SshBin} = file:read_file(filename:join(SystemDir, "ssh_host_rsa_key.pub")),
      [{Key, _}] = public_key:ssh_decode(SshBin, public_key),
      setup_known_hosts(Key, UserDir).
  
  setup_ecdsa_known_host(_Size, SystemDir, UserDir) ->
      {ok, SshBin} = file:read_file(filename:join(SystemDir, "ssh_host_ecdsa_key.pub")),
      [{Key, _}] = public_key:ssh_decode(SshBin, public_key),
      setup_known_hosts(Key, UserDir).
  
  setup_eddsa_known_host(HostPub, SystemDir, UserDir) ->
      {ok, SshBin} = file:read_file(filename:join(SystemDir, HostPub)),
      [{Key, _}] = public_key:ssh_decode(SshBin, public_key),
      setup_known_hosts(Key, UserDir).
  
  setup_known_hosts(Key, UserDir) ->
      {ok, Hostname} = inet:gethostname(),
  
negative.code: receive_exec_result([]) ->
      expected;
  receive_exec_result(Msgs) when is_list(Msgs) ->
      ct:log("~p:~p Expect data! ~p", [?MODULE,?FUNCTION_NAME,Msgs]),
      receive
          Msg ->
              case lists:member(Msg, Msgs)
                  orelse lists:member({optional,Msg}, Msgs)
              of
                  true ->
                      ct:log("~p:~p Collected data ~p", [?MODULE,?FUNCTION_NAME,Msg]),
                      receive_exec_result(Msgs--[Msg,{optional,Msg}]);
                  false ->
                      case Msg of
                          {ssh_cm,_,{data,_,1, Data}} ->
                              ct:log("~p:~p StdErr: ~p~n", [?MODULE,?FUNCTION_NAME,Data]),
                              receive_exec_result(Msgs);
                          Other ->
                              ct:log("~p:~p Other ~p", [?MODULE,?FUNCTION_NAME,Other]),
                              {unexpected_msg, Other}
                      end
              end
      after 
  	30000 ->
              case lists:all(fun(M) ->
                                     is_tuple(M) andalso (element(1,M) == optional)
                             end, Msgs)
              of
                  false ->
                      ct:fail("timeout ~p:~p",[?MODULE,?FUNCTION_NAME]);
                  true ->
                      ct:log("~p:~p Only optional messages expected!~n ~p", [?MODULE,?FUNCTION_NAME,Msgs]),
                      expected
              end
      end;
  receive_exec_result(Msg) ->
      receive_exec_result([Msg]).
  