www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: [libssh2] #248: A small patch to handle private key in memory

[libssh2] #248: A small patch to handle private key in memory

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Mon, 10 Sep 2012 09:05:56 -0000

#248: A small patch to handle private key in memory
-------------------------+--------------------
 Reporter: intron | Owner:
     Type: enhancement | Status: new
 Priority: normal | Milestone: 1.4.3
Component: API | Version: 1.4.2
 Keywords: | Blocked By:
   Blocks: |
-------------------------+--------------------
 Here is my small patch to handle private key in memory:
     http://ftp.intron.ac/tmp/openssl.c.diff
 This feature is useful to work with a private key stored in a
 USB key. I wish that this patch was useful to this project.

 With this patch, if the argument "privatekey" of
 libssh2_userauth_publickey_fromfile_ex() points to a string
 starting with "mem://", the contents in the string after "mem://"
 will be interpreted as a private key. Otherwise, the full contents
 of "privatekey" is interpreted as a filename of private key.

 Example:

   char usbkeybuf[4096], pvk[4096];

   /* Read a private key from USB key to usbkeybuf[] */
   ...

   strcpy(pvk, "mem://");
   strcat(pvk, usbkeybuf);

   /*
      pvk now contains
        "mem://-----BEGIN RSA PRIVATE KEY-----\n"
           ...
        "-----END RSA PRIVATE KEY-----"
    */

   nret = libssh2_userauth_publickey_fromfile(session,
       username, NULL, pvk, NULL);

-- 
Ticket URL: <https://trac.libssh2.org/ticket/248>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-09-10

the libssh2 team