aboutsummaryrefslogtreecommitdiff
path: root/libssh/keyfiles.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2005-08-07 10:48:08 +0000
committerAris Adamantiadis <aris@0xbadc0de.be>2005-08-07 10:48:08 +0000
commit5c26ae735483d140f802d58b1872b2fe9468d219 (patch)
treee8e8e8dea72c371e15f6e510ecc97948a4139383 /libssh/keyfiles.c
parent3113d8756628f463fda33b93801aee3c6ee9aa32 (diff)
downloadlibssh-5c26ae735483d140f802d58b1872b2fe9468d219.tar.gz
libssh-5c26ae735483d140f802d58b1872b2fe9468d219.tar.xz
libssh-5c26ae735483d140f802d58b1872b2fe9468d219.zip
server kex done :)
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@6 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/keyfiles.c')
-rw-r--r--libssh/keyfiles.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index 4891ab5a..93223538 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -74,7 +74,8 @@ PRIVATE_KEY *privatekey_from_file(SSH_SESSION *session,char *filename,int type,
dsa=PEM_read_DSAPrivateKey(file,NULL,(void *)get_password_specified,passphrase);
fclose(file);
if(!dsa){
- ssh_set_error(session,SSH_FATAL,"parsing private key %s : %s",filename,ERR_error_string(ERR_get_error(),NULL));
+ ssh_set_error(session,SSH_FATAL,"parsing private key %s"
+ ": %s",filename,ERR_error_string(ERR_get_error(),NULL));
return NULL;
}
}
@@ -89,7 +90,8 @@ PRIVATE_KEY *privatekey_from_file(SSH_SESSION *session,char *filename,int type,
rsa=PEM_read_RSAPrivateKey(file,NULL,(void *)get_password_specified,passphrase);
fclose(file);
if(!rsa){
- ssh_set_error(session,SSH_FATAL,"parsing private key %s : %s",filename,ERR_error_string(ERR_get_error(),NULL));
+ ssh_set_error(session,SSH_FATAL,"parsing private key %s"
+ ": %s",filename,ERR_error_string(ERR_get_error(),NULL));
return NULL;
}
} else {
@@ -104,6 +106,44 @@ PRIVATE_KEY *privatekey_from_file(SSH_SESSION *session,char *filename,int type,
return privkey;
}
+/* same that privatekey_from_file() but without any passphrase things. */
+PRIVATE_KEY *_privatekey_from_file(void *session,char *filename,int type){
+ FILE *file=fopen(filename,"r");
+ PRIVATE_KEY *privkey;
+ DSA *dsa=NULL;
+ RSA *rsa=NULL;
+ if(!file){
+ ssh_set_error(session,SSH_REQUEST_DENIED,"Error opening %s : %s",filename,strerror(errno));
+ return NULL;
+ }
+ if(type==TYPE_DSS){
+ dsa=PEM_read_DSAPrivateKey(file,NULL,NULL,NULL);
+ fclose(file);
+ if(!dsa){
+ ssh_set_error(session,SSH_FATAL,"parsing private key %s"
+ ": %s",filename,ERR_error_string(ERR_get_error(),NULL));
+ return NULL;
+ }
+ }
+ else if (type==TYPE_RSA){
+ rsa=PEM_read_RSAPrivateKey(file,NULL,NULL,NULL);
+ fclose(file);
+ if(!rsa){
+ ssh_set_error(session,SSH_FATAL,"parsing private key %s"
+ ": %s",filename,ERR_error_string(ERR_get_error(),NULL));
+ return NULL;
+ }
+ } else {
+ ssh_set_error(session,SSH_FATAL,"Invalid private key type %d",type);
+ return NULL;
+ }
+ privkey=malloc(sizeof(PRIVATE_KEY));
+ privkey->type=type;
+ privkey->dsa_priv=dsa;
+ privkey->rsa_priv=rsa;
+ return privkey;
+}
+
void private_key_free(PRIVATE_KEY *prv){
if(prv->dsa_priv)
DSA_free(prv->dsa_priv);