藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年6月6日 10:18


Convert openssh key to putty key in batch mode

I'm writing a Perl script to convert Openssh DSA public key to Putty format. There's a C code does similar thing but only for RSA key. I got problem when creating hmac hash. I don't know much C and want to use Perl to do the same thing as followig C routine does. Can anyone helps? Thanks.

source
http://www.anchor.net.au/code/openssh2putty.c

// binary strings with 4 octet length header when dumped
typedef struct {
    int length;
    unsigned char data[1];
} bstring;

bstring *

asciiz_to_bstring(const char *s)

{

unsigned l;

bstring *b;

l = strlen(s);

b = (bstring *)xmalloc(4 + l);

b->;length = l;

memcpy(&b->;data, s, l);

return b;

}

Convert openssh key to putty key in batch mode

unsigned l;

bstring *b;

l = strlen(s);       求出傳入字符串的長度

b = (bstring *)xmalloc(4 + l);    分配一塊內存  siseof(int)=4  sizeof(char)=1   
  
b->;length = l;   結構體的一field放長度

memcpy(&b->;data, s, l);  結構體的另一field存傳入的字符串

return b;   返回剛才申請的那快內存

Convert openssh key to putty key in batch mode

Thanks for all the reply.

I didn't get my Perl script to work. But I found a modified source code which supports DSA key. It works fine after I removed the private key encryption part. I post the source code here just in case someone want to convert openssh key to PuTTY format in batch mode.  


How to compile

1. Download openssh-3.4p1 source code
2. put the openssh2putty.c under openssh-3.4p1
3. Modify the Configure.in and copy the lines with ssh-add and change ssh-add to openssh2putty
4. ./configure
5. make openssh2putty



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com