Subject: [libssh2] [ libssh2-Bugs-1592645 ] Public key can not be readed from file

[libssh2] [ libssh2-Bugs-1592645 ] Public key can not be readed from file

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Thu, 28 Jun 2007 13:59:15 -0700

Bugs item #1592645, was opened at 2006-11-08 15:00
Message generated for change (Comment added) made by bagder
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1592645&group_id=125852

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
>Resolution: Remind
Priority: 5
Private: No
Submitted By: Esteban Sánchez (esanchezm)
>Assigned to: Daniel Stenberg (bagder)
Summary: Public key can not be readed from file

Initial Comment:
If the public key file does not finish with '\n' or
'\r' the pubic key is not readed and the connection can
not be established using
libssh2_userauth_publickey_fromfile()

This kind of files can be done by copy-pasting a public
key in an empty file using notepad in Windows. I attach
one of this files. You can try to reproduce with any
private key.

----------------------------------------------------------------------

>Comment By: Daniel Stenberg (bagder)
Date: 2007-06-28 22:59

Message:
Logged In: YES
user_id=1110
Originator: NO

It seems parts of what have been discussed here have been committed. Is
this still a problem? If it is, can you please resubmit an updated patch
against recent CVS or at least 0.15?

----------------------------------------------------------------------

Comment By: Esteban Sánchez (esanchezm)
Date: 2006-11-13 15:58

Message:
Logged In: YES
user_id=1203199

I was a bit quick in the previous comment and I realize it
didn't work really good. When I looked the code you sent,
something looks strange to me. You rewind the file
descriptor and check if it was EOF, which will never be as
long as you have rewind it. This code will works ok.

while (!feof(fd) && (c = fgetc(fd)) != '\r' && c != '\n')
pubkey_len++;
if (feof(fd)) {
        /* the last character was EOF */
        pubkey_len--;
}
rewind(fd);

----------------------------------------------------------------------

Comment By: Esteban Sánchez (esanchezm)
Date: 2006-11-13 12:09

Message:
Logged In: YES
user_id=1203199

I have test your patch and it works fine. BTW, the problem
was from cut-n-paste, yes, but that's the way to generate
OpenSSH keys using PuttyGen on Windows.

----------------------------------------------------------------------

Comment By: James Housley (jehousley)
Date: 2006-11-12 18:28

Message:
Logged In: YES
user_id=32239

I think this would be a better fix. The cause you suggest is from
cut-n-paste, I believe that could also put spaces at the end too.

Jim

RCS file: /cvsroot/libssh2/libssh2/src/userauth.c,v
retrieving revision 1.16
diff -u -r1.16 userauth.c
--- src/userauth.c 4 Nov 2006 19:30:32 -0000 1.16
+++ src/userauth.c 12 Nov 2006 17:25:51 -0000
@@ -37,6 +37,8 @@
 
 #include "libssh2_priv.h"
 
+#include <ctype.h>
+
 /* Needed for struct iovec on some platforms */
 #ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
@@ -252,7 +254,11 @@
        }
        while (!feof(fd) && (c = fgetc(fd)) != '\r' && c != '\n')
pubkey_l
en++;
        rewind(fd);
-
+ if (feof(fd)) {
+ /* the last character was EOF */
+ pubkey_len--;
+ }
+
        if (pubkey_len <= 1) {
                libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid data
in public key file", 0);
                fclose(fd);
@@ -272,7 +278,10 @@
                return -1;
        }
        fclose(fd);
- while (pubkey_len && (pubkey[pubkey_len-1] == '\r' ||
pubkey[pubkey_len-1] == '\n')) pubkey_len--;
+ /*
+ * Remove trailing whitespace
+ */
+ while (pubkey_len && isspace(pubkey[pubkey_len-1])) pubkey_len--;
 
        if (!pubkey_len) {
                libssh2_error(session, LIBSSH2_ERROR_FILE, "Missing public
key data", 0);

----------------------------------------------------------------------

Comment By: Esteban Sánchez (esanchezm)
Date: 2006-11-08 15:02

Message:
Logged In: YES
user_id=1203199

I add a patch to solve this bug. This works on my system,
but may be buggy...

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1592645&group_id=125852

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2007-06-28