diff options
author | Niclas Eklund <nick@erlang.org> | 2011-05-16 15:25:03 +0200 |
---|---|---|
committer | Niclas Eklund <nick@erlang.org> | 2011-05-19 14:38:24 +0200 |
commit | 26e3b024571952284e026a4f8d3ef55777dc4386 (patch) | |
tree | 71e7130b2aee10195a9a5831e696695b82806430 /lib/ssh/test/ssh_test_lib.erl | |
parent | 2fb636273a06d31f0c24dcecf9302cd6561f02af (diff) | |
download | otp-26e3b024571952284e026a4f8d3ef55777dc4386.tar.gz otp-26e3b024571952284e026a4f8d3ef55777dc4386.tar.bz2 otp-26e3b024571952284e026a4f8d3ef55777dc4386.zip |
Generic key management for test suites.
Diffstat (limited to 'lib/ssh/test/ssh_test_lib.erl')
-rw-r--r-- | lib/ssh/test/ssh_test_lib.erl | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/lib/ssh/test/ssh_test_lib.erl b/lib/ssh/test/ssh_test_lib.erl index f2a6351f96..b11ebc1652 100644 --- a/lib/ssh/test/ssh_test_lib.erl +++ b/lib/ssh/test/ssh_test_lib.erl @@ -232,22 +232,6 @@ known_hosts(BR) -> end. -save_known_hosts(PrivDir) -> - Src = ssh_file:file_name(user, "known_hosts", []), - Dst = filename:join(PrivDir, "kh_save"), - Ok = file:copy(Src, Dst), - io:format("save ~p -> ~p : ~p", [Src, Dst, Ok]). - -restore_known_hosts(_PrivDir) -> - %% Race condition. - ok. -%% Src = filename:join(PrivDir, "kh_save"), -%% Dst = ssh_file:file_name(user, "known_hosts", []), -%% D1 = file:delete(Dst), -%% C = file:copy(Src, Dst), -%% D2 = file:delete(Src), -%% io:format("restore ~p -> ~p : ~p ~p ~p\n", [Src, Dst, D1, C, D2]). - get_user_dir() -> case os:type() of {win32, _} -> @@ -276,17 +260,48 @@ make_dsa_cert_files(RoleStr, Config) -> der_to_pem(KeyFile, [CertKey]), {CaCertFile, CertFile, KeyFile}. -make_dsa_public_key_file(P, Q, G, Y, Config) -> - PK = #ssh_key{type = dsa, public = {P,Q,G,Y}}, - Enc = ssh_file:encode_public_key(PK), - B64 = ssh_bits:b64_encode(Enc), - FileName = filename:join([?config(data_dir, Config), "ssh_host_dsa_key.pub"]), - file:write_file(FileName, <<"ssh-dss ", B64/binary>>). - -make_dsa_private_key_file(LSize, NSize, Config) -> - {Key, EncodedKey} = gen_dsa(LSize, NSize), - FileName = filename:join([?config(data_dir, Config), "ssh_host_dsa_key"]), - file:write_file(FileName, EncodedKey). +make_dsa_files(Config) -> + make_dsa_files(Config, rfc4716_public_key). +make_dsa_files(Config, Type) -> + {DSA, EncodedKey} = ssh_test_lib:gen_dsa(128, 20), + 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}, + {ok, Hostname} = inet:gethostname(), + {ok, {A, B, C, D}} = inet:getaddr(Hostname, inet), + IP = lists:concat([A, ".", B, ".", C, ".", D]), + Attributes = [], % Could be [{comment,"user@" ++ Hostname}], + HostNames = [{hostnames,[IP, IP]}], + PublicKey = [{{PKey, Dss}, Attributes}], + KnownHosts = [{{PKey, Dss}, HostNames}], + + KnownHostsEnc = public_key:ssh_encode(KnownHosts, known_hosts), + KnownHosts = public_key:ssh_decode(KnownHostsEnc, known_hosts), + + PublicKeyEnc = public_key:ssh_encode(PublicKey, Type), +% PublicKey = public_key:ssh_decode(PublicKeyEnc, Type), + + SystemTmpDir = ?config(data_dir, Config), + filelib:ensure_dir(SystemTmpDir), + file:make_dir(SystemTmpDir), + + DSAFile = filename:join(SystemTmpDir, "ssh_host_dsa_key.pub"), + file:delete(DSAFile), + + DSAPrivateFile = filename:join(SystemTmpDir, "ssh_host_dsa_key"), + file:delete(DSAPrivateFile), + + KHFile = filename:join(SystemTmpDir, "known_hosts"), + file:delete(KHFile), + + PemBin = public_key:pem_encode([EncodedKey]), + + file:write_file(DSAFile, PublicKeyEnc), + file:write_file(KHFile, KnownHostsEnc), + file:write_file(DSAPrivateFile, PemBin), + ok. %%-------------------------------------------------------------------- %% Create and return a der encoded certificate |