diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-09-25 01:22:15 +0300 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-10-20 15:12:47 +0300 |
commit | d95328554885ac9a0101297ae313018165e2aca4 (patch) | |
tree | 6c384f21f6fb4824e7150433830ecf07af016048 | |
parent | 1fcddebadc178670e49447d4e7f07804add15a46 (diff) | |
download | libssh-d95328554885ac9a0101297ae313018165e2aca4.tar.gz libssh-d95328554885ac9a0101297ae313018165e2aca4.tar.xz libssh-d95328554885ac9a0101297ae313018165e2aca4.zip |
examples: ssh-keygen tryaris_work
-rw-r--r-- | examples/CMakeLists.txt | 3 | ||||
-rw-r--r-- | examples/ssh-keygen.c | 61 |
2 files changed, 64 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 5513b758..f310bad7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -55,3 +55,6 @@ target_link_libraries(libsshpp ${LIBSSH_SHARED_LIBRARY}) add_executable(libsshpp_noexcept libsshpp_noexcept.cpp) target_link_libraries(libsshpp_noexcept ${LIBSSH_SHARED_LIBRARY}) + +add_executable(ssh-keygen ssh-keygen.c) +target_link_libraries(ssh-keygen ${LIBSSH_SHARED_LIBRARY}) diff --git a/examples/ssh-keygen.c b/examples/ssh-keygen.c new file mode 100644 index 00000000..8d2a42c4 --- /dev/null +++ b/examples/ssh-keygen.c @@ -0,0 +1,61 @@ +/* + * This file is part of the SSH Library + * + * Copyright (c) 2011 by Aris Adamantiadis <aris@0xbadc0de.be> + * + * The SSH Library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * The SSH Library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the SSH Library; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#include <libssh/libssh.h> +#include <stdio.h> +#include <string.h> + +int main(int argc, char **argv){ + ssh_key key; + int rc; + char path[256]; + char passphrase[256]; + char *ptr; + + printf("ssh-keygen, using libssh %s\n", ssh_version(0)); + printf("Generating rsa keypair\n"); + rc = ssh_pki_generate(SSH_KEYTYPE_RSA,2048,&key); + if (rc != SSH_OK){ + printf("error\n"); + return 1; + } + printf("Enter the filename for private key (id_rsa):"); + fflush(stdout); + ptr = fgets(path,sizeof(path),stdin); + if (!ptr) + return 1; + ptr = strchr(path,'\n'); + if(ptr) + *ptr=0; + ptr = strchr(path,'\r'); + if(ptr) + *ptr=0; + rc = ssh_getpass("Enter passphrase (empty for no passphrase):", + passphrase,sizeof(passphrase),0,1); + if (rc != SSH_OK) + return 1; + rc = ssh_pki_export_pubkey_file(key, path); + if (rc != SSH_OK){ + printf("Error exporting pubkey\n"); + return 1; + } + return 0; +} |