[Ttssh2-commit] [5284] PKCS#8形式の鍵を読み込めなくなっていたのを修正。

svnno****@sourc***** svnno****@sourc*****
2013年 5月 25日 (土) 12:58:16 JST


Revision: 5284
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5284
Author:   doda
Date:     2013-05-25 12:58:15 +0900 (Sat, 25 May 2013)
Log Message:
-----------
PKCS#8形式の鍵を読み込めなくなっていたのを修正。

Ticket Links:
------------
    http://sourceforge.jp/projects/ttssh2/tracker/detail/8

Modified Paths:
--------------
    trunk/ttssh2/ttxssh/keyfiles.c
    trunk/ttssh2/ttxssh/keyfiles.h

-------------- next part --------------
Modified: trunk/ttssh2/ttxssh/keyfiles.c
===================================================================
--- trunk/ttssh2/ttxssh/keyfiles.c	2013-05-25 03:25:19 UTC (rev 5283)
+++ trunk/ttssh2/ttxssh/keyfiles.c	2013-05-25 03:58:15 UTC (rev 5284)
@@ -1183,6 +1183,7 @@
 	ssh2_keyfile_type ret = SSH2_KEYFILE_TYPE_NONE;
 	char filename[2048];
 	char line[200];
+	int i;
 
 	// \x91\x8A\x91΃p\x83X\x82\xF0\x90\xE2\x91΃p\x83X\x82֕ϊ\xB7\x82\xB7\x82\xE9\x81B\x82\xB1\x82\xA4\x82\xB7\x82邱\x82Ƃɂ\xE6\x82\xE8\x81A\x81u\x83h\x83b\x83g\x82Ŏn\x82܂\xE9\x81v\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xC9
 	// \x82\xA0\x82\xE9\x83t\x83@\x83C\x83\x8B\x82\xF0\x93ǂݍ\x9E\x82ނ\xB1\x82Ƃ\xAA\x82ł\xAB\x82\xE9\x81B(2005.2.7 yutaka)
@@ -1196,26 +1197,14 @@
 	}
 
 	while (fgets(line, sizeof(line), *fp) != NULL) {
-		if (strncmp(line, "-----BEGIN RSA PRIVATE KEY-----", strlen("-----BEGIN RSA PRIVATE KEY-----")) == 0) {
-			ret = SSH2_KEYFILE_TYPE_OPENSSH;
-			break;
+		for (i=0; keyfile_headers[i].type != SSH2_KEYFILE_TYPE_NONE; i++) {
+			if ( strncmp(line, keyfile_headers[i].header, strlen(keyfile_headers[i].header)) == 0) {
+				ret = keyfile_headers[i].type;
+				break;
+			}
 		}
-		else if (strncmp(line, "-----BEGIN DSA PRIVATE KEY-----", strlen("-----BEGIN DSA PRIVATE KEY-----")) == 0) {
-			ret = SSH2_KEYFILE_TYPE_OPENSSH;
+		if (ret != SSH2_KEYFILE_TYPE_NONE)
 			break;
-		}
-		else if (strncmp(line, "-----BEGIN EC PRIVATE KEY-----", strlen("-----BEGIN EC PRIVATE KEY-----")) == 0) {
-			ret = SSH2_KEYFILE_TYPE_OPENSSH;
-			break;
-		}
-		else if (strncmp(line, "PuTTY-User-Key-File-2", strlen("PuTTY-User-Key-File-2")) == 0) {
-			ret = SSH2_KEYFILE_TYPE_PUTTY;
-			break;
-		}
-		else if (strncmp(line, "---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----", strlen("---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----")) == 0) {
-			ret = SSH2_KEYFILE_TYPE_SECSH;
-			break;
-		}
 	}
 	
 	if (ret == SSH2_KEYFILE_TYPE_NONE) {

Modified: trunk/ttssh2/ttxssh/keyfiles.h
===================================================================
--- trunk/ttssh2/ttxssh/keyfiles.h	2013-05-25 03:25:19 UTC (rev 5283)
+++ trunk/ttssh2/ttxssh/keyfiles.h	2013-05-25 03:58:15 UTC (rev 5284)
@@ -76,4 +76,19 @@
                                    char *errmsg,
                                    int errmsg_len);
 
+typedef struct keyfile_header {
+	ssh2_keyfile_type type;
+	char *header;
+} keyfile_header_t;
+
+static keyfile_header_t keyfile_headers[] = {
+	{SSH2_KEYFILE_TYPE_OPENSSH, "-----BEGIN RSA PRIVATE KEY-----"},
+	{SSH2_KEYFILE_TYPE_OPENSSH, "-----BEGIN DSA PRIVATE KEY-----"},
+	{SSH2_KEYFILE_TYPE_OPENSSH, "-----BEGIN EC PRIVATE KEY-----"},
+	{SSH2_KEYFILE_TYPE_OPENSSH, "-----BEGIN ENCRYPTED PRIVATE KEY-----"},
+	{SSH2_KEYFILE_TYPE_PUTTY,   "PuTTY-User-Key-File-2"},
+	{SSH2_KEYFILE_TYPE_SECSH,   "---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----"},
+	{SSH2_KEYFILE_TYPE_NONE,    NULL},
+
+};
 #endif



Ttssh2-commit メーリングリストの案内