diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2011-08-07 13:08:49 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2011-08-08 15:28:31 +0200 |
commit | 6ccb3f7a8245c0c5e6b42cdeaae9d3285f9037bc (patch) | |
tree | 802b8833c0bef79b166fb363f45277087ed64a57 /src | |
parent | 37b80e92613de0e56b1558d09298899276b56217 (diff) | |
download | libssh-6ccb3f7a8245c0c5e6b42cdeaae9d3285f9037bc.tar.gz libssh-6ccb3f7a8245c0c5e6b42cdeaae9d3285f9037bc.tar.xz libssh-6ccb3f7a8245c0c5e6b42cdeaae9d3285f9037bc.zip |
pki: Add pki_crypto.c.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/pki_crypto.c | 69 |
2 files changed, 79 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ef74562..392944a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -114,11 +114,16 @@ set(libssh_SRCS ) if (WITH_GCRYPT) - set(libssh_SRCS - ${libssh_SRCS} - libgcrypt.c - gcrypt_missing.c - ) + set(libssh_SRCS + ${libssh_SRCS} + libgcrypt.c + gcrypt_missing.c + ) +else (WITH_GCRYPT) + set(libssh_SRCS + ${libssh_SRCS} + pki_crypto.c + ) endif (WITH_GCRYPT) if (WITH_SFTP) diff --git a/src/pki_crypto.c b/src/pki_crypto.c new file mode 100644 index 0000000..c6b9224 --- /dev/null +++ b/src/pki_crypto.c @@ -0,0 +1,69 @@ +/* + * pki_crypto.c - PKI infrastructure using OpenSSL + * + * This file is part of the SSH Library + * + * Copyright (c) 2003-2009 by Aris Adamantiadis + * Copyright (c) 2009-2011 by Andreas Schneider <asn@cryptomilk.org> + * + * 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. + */ + +#ifndef _PKI_CRYPTO_H +#define _PKI_CRYPTO_H + +#include "config.h" + +#include <openssl/pem.h> +#include <openssl/dsa.h> +#include <openssl/err.h> +#include <openssl/rsa.h> + +#include "libssh/priv.h" +#include "libssh/libssh.h" +#include "libssh/session.h" +#include "libssh/callbacks.h" + +static int pem_get_password(char *buf, int size, int rwflag, void *userdata) { + ssh_session session = userdata; + + (void) rwflag; /* unused */ + + if (buf == NULL) { + return 0; + } + + ssh_log(session, SSH_LOG_RARE, + "Trying to call external authentication function"); + + memset(buf, '\0', size); + if (session && + session->common.callbacks && + session->common.callbacks->auth_function) { + int rc; + + rc = session->common.callbacks->auth_function("Passphrase for private key:", + buf, size, 0, 0, + session->common.callbacks->userdata); + if (rc == 0) { + return strlen(buf); + } + } + + return 0; +} + +#endif /* _PKI_CRYPTO_H */ |