00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef PKI_H_
00022 #define PKI_H_
00023
00024 #ifdef HAVE_OPENSSL_EC_H
00025 #include <openssl/ec.h>
00026 #endif
00027 #ifdef HAVE_OPENSSL_ECDSA_H
00028 #include <openssl/ecdsa.h>
00029 #endif
00030
00031 #include "libssh/crypto.h"
00032
00033 #define MAX_PUBKEY_SIZE 0x100000
00034 #define MAX_PRIVKEY_SIZE 0x400000
00035
00036 #define SSH_KEY_FLAG_EMPTY 0x0
00037 #define SSH_KEY_FLAG_PUBLIC 0x0001
00038 #define SSH_KEY_FLAG_PRIVATE 0x0002
00039
00040 struct ssh_key_struct {
00041 enum ssh_keytypes_e type;
00042 int flags;
00043 const char *type_c;
00044 int ecdsa_nid;
00045 #ifdef HAVE_LIBGCRYPT
00046 gcry_sexp_t dsa;
00047 gcry_sexp_t rsa;
00048 void *ecdsa;
00049 #elif HAVE_LIBCRYPTO
00050 DSA *dsa;
00051 RSA *rsa;
00052 #ifdef HAVE_OPENSSL_ECC
00053 EC_KEY *ecdsa;
00054 #else
00055 void *ecdsa;
00056 #endif
00057 #endif
00058 void *cert;
00059 };
00060
00061 struct ssh_signature_struct {
00062 enum ssh_keytypes_e type;
00063 const char *type_c;
00064 #ifdef HAVE_LIBGCRYPT
00065 gcry_sexp_t dsa_sig;
00066 gcry_sexp_t rsa_sig;
00067 void *ecdsa_sig;
00068 #elif defined HAVE_LIBCRYPTO
00069 DSA_SIG *dsa_sig;
00070 ssh_string rsa_sig;
00071 # ifdef HAVE_OPENSSL_ECC
00072 ECDSA_SIG *ecdsa_sig;
00073 # else
00074 void *ecdsa_sig;
00075 # endif
00076 #endif
00077 };
00078
00079 typedef struct ssh_signature_struct *ssh_signature;
00080
00081
00082 ssh_key ssh_key_dup(const ssh_key key);
00083 void ssh_key_clean (ssh_key key);
00084
00085
00086 ssh_signature ssh_signature_new(void);
00087 void ssh_signature_free(ssh_signature sign);
00088
00089 int ssh_pki_export_signature_blob(const ssh_signature sign,
00090 ssh_string *sign_blob);
00091 int ssh_pki_import_signature_blob(const ssh_string sig_blob,
00092 const ssh_key pubkey,
00093 ssh_signature *psig);
00094 int ssh_pki_signature_verify_blob(ssh_session session,
00095 ssh_string sig_blob,
00096 const ssh_key key,
00097 unsigned char *digest,
00098 size_t dlen);
00099
00100
00101 int ssh_pki_export_pubkey_blob(const ssh_key key,
00102 ssh_string *pblob);
00103 int ssh_pki_import_pubkey_blob(const ssh_string key_blob,
00104 ssh_key *pkey);
00105 int ssh_pki_export_pubkey_rsa1(const ssh_key key,
00106 const char *host,
00107 char *rsa1,
00108 size_t rsa1_len);
00109
00110
00111 ssh_string ssh_pki_do_sign(ssh_session session, ssh_buffer sigbuf,
00112 const ssh_key privatekey);
00113 ssh_string ssh_pki_do_sign_agent(ssh_session session,
00114 struct ssh_buffer_struct *buf,
00115 const ssh_key pubkey);
00116 ssh_string ssh_srv_pki_do_sign_sessionid(ssh_session session,
00117 const ssh_key privkey);
00118
00119
00120 ssh_public_key ssh_pki_convert_key_to_publickey(const ssh_key key);
00121 ssh_private_key ssh_pki_convert_key_to_privatekey(const ssh_key key);
00122
00123 #endif