[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/4] tests: Add ssh server setup functionality
[Thread Prev] | [Thread Next]
- Subject: Re: [PATCH 3/4] tests: Add ssh server setup functionality
- From: Andreas Schneider <asn@xxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Tue, 06 May 2014 09:01:29 +0200
- To: libssh@xxxxxxxxxx
On Saturday 19 April 2014 15:29:25 Alan Dunn wrote: > Add the ability to generate a keypair (RSA, but tests that focus on > what occurs over a connection may well not care) and an ssh_bind > easily. I've pushed the fix but for the server testing I need to get cwrap done. I think I will find on the train next week. You can read more about it on: https://lwn.net/Articles/594863/ > > Signed-off-by: Alan Dunn <amdunn@xxxxxxxxx> > --- > tests/torture.c | 54 > +++++++++++++++++++++++++++++++++++++++++ tests/torture.h | > 15 ++++++++++++ > tests/unittests/torture_pki.c | 6 +---- > 3 files changed, 70 insertions(+), 5 deletions(-) > > diff --git a/tests/torture.c b/tests/torture.c > index fb4707a..ce26050 100644 > --- a/tests/torture.c > +++ b/tests/torture.c > @@ -235,6 +235,60 @@ failed: > return NULL; > } > > +int torture_setup_rsa_key() { > + int rc; > + > + unlink(LIBSSH_RSA_TESTKEY); > + unlink(LIBSSH_RSA_TESTKEY ".pub"); > + > + rc = system("ssh-keygen -t rsa -q -N \"\" -f " LIBSSH_RSA_TESTKEY); > + return rc; > +} We removed calls to ssh-keygen and embedded the keys. You should do the same. > +#ifdef WITH_SERVER > + > +ssh_bind torture_ssh_bind(const char *addr, > + const unsigned int port, > + const char *private_key_file) { For such things I would like to have a new file torture_server.c. I will create a torture_client.c with the current client functions soon. I've already started with cwrap stuff here: http://git.libssh.org/users/asn/libssh.git/log/?h=cwrap > + int rc; > + ssh_bind sshbind = NULL; > + > + sshbind = ssh_bind_new(); > + if (sshbind == NULL) { > + goto out; > + } > + > + rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, addr); > + if (rc != 0) { > + goto out_free; > + } > + > + rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port); > + if (rc != 0) { > + goto out_free; > + } > + > + rc = ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, > + private_key_file); > + if (rc != 0) { > + goto out_free; > + } > + > + rc = ssh_bind_listen(sshbind); > + if (rc != SSH_OK) { > + goto out_free; > + } > + > + goto out; > + out_free: > + ssh_bind_free(sshbind); > + sshbind = NULL; > + out: > + return sshbind; > +} > + > +#endif > + > #ifdef WITH_SFTP > > struct torture_sftp *torture_sftp_session(ssh_session session) { > diff --git a/tests/torture.h b/tests/torture.h > index fb7ac5a..d6e5e47 100644 > --- a/tests/torture.h > +++ b/tests/torture.h > @@ -35,6 +35,7 @@ > #include <setjmp.h> > > #include "libssh/priv.h" > +#include "libssh/server.h" > #include "libssh/sftp.h" > > #include <cmocka.h> > @@ -66,6 +67,20 @@ ssh_session torture_ssh_session(const char *host, > const char *user, > const char *password); > > +#define LIBSSH_RSA_TESTKEY "libssh_testkey.id_rsa" > + > +/* > + * Set up an RSA key pair with private key at LIBSSH_RSA_TESTKEY and > + * public key at the same filename extended with ".pub". > + * > + * Returns 0 on success. > + */ > +int torture_setup_rsa_key(void); > + > +ssh_bind torture_ssh_bind(const char *addr, > + const unsigned int port, > + const char *private_key_file); > + > struct torture_sftp *torture_sftp_session(ssh_session session); > void torture_sftp_close(struct torture_sftp *t); > > diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c > index 7eab95d..3672055 100644 > --- a/tests/unittests/torture_pki.c > +++ b/tests/unittests/torture_pki.c > @@ -5,7 +5,6 @@ > #include <sys/stat.h> > #include <fcntl.h> > > -#define LIBSSH_RSA_TESTKEY "libssh_testkey.id_rsa" > #define LIBSSH_DSA_TESTKEY "libssh_testkey.id_dsa" > #define LIBSSH_ECDSA_TESTKEY "libssh_testkey.id_ecdsa" > #define LIBSSH_PASSPHRASE "libssh-rocks" > @@ -16,10 +15,7 @@ static void setup_rsa_key(void **state) { > > (void) state; /* unused */ > > - unlink(LIBSSH_RSA_TESTKEY); > - unlink(LIBSSH_RSA_TESTKEY ".pub"); > - > - rc = system("ssh-keygen -t rsa -q -N \"\" -f " LIBSSH_RSA_TESTKEY); > + rc = torture_setup_rsa_key(); > assert_true(rc == 0); > } -- Andreas Schneider GPG-ID: CC014E3D www.cryptomilk.org asn@xxxxxxxxxxxxxx
Archive administrator: postmaster@lists.cynapses.org