[Ttssh2-commit] [4569] DNS(SSHFP) 関連を別ファイルに分離。

svnno****@sourc***** svnno****@sourc*****
2011年 8月 4日 (木) 15:00:18 JST


Revision: 4569
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4569
Author:   doda
Date:     2011-08-04 15:00:17 +0900 (Thu, 04 Aug 2011)

Log Message:
-----------
DNS(SSHFP) 関連を別ファイルに分離。
# BIND の libresolv 等の OS 標準以外のリゾルバに対応し易くする為だけれど
# libresolv 対応は挫折中…

Modified Paths:
--------------
    trunk/ttssh2/ttxssh/hosts.c
    trunk/ttssh2/ttxssh/ssh.h
    trunk/ttssh2/ttxssh/ttxssh.vcproj

Added Paths:
-----------
    trunk/ttssh2/ttxssh/dns.c
    trunk/ttssh2/ttxssh/dns.h


-------------- next part --------------
Added: trunk/ttssh2/ttxssh/dns.c
===================================================================
--- trunk/ttssh2/ttxssh/dns.c	                        (rev 0)
+++ trunk/ttssh2/ttxssh/dns.c	2011-08-04 06:00:17 UTC (rev 4569)
@@ -0,0 +1,116 @@
+/*
+Copyright (c) TeraTerm Project.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+  1. Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright notice,
+     this list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+  3. The name of the author may not be used to endorse or promote products derived
+     from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
+*/
+
+#include <memory.h>
+
+#include "ttxssh.h"
+#include "ssh.h"
+#include "key.h"
+#include "dns.h"
+
+int is_numeric_hostname(const char *hostname)
+{
+	struct addrinfo hints, *res;
+
+	if (!hostname) {
+		return -1;
+	}
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = PF_UNSPEC;
+	hints.ai_flags = AI_NUMERICHOST;
+
+	if (getaddrinfo(hostname, NULL, &hints, &res) == 0) {
+		freeaddrinfo(res);
+		return 1;
+	}
+
+	return 0;
+}
+
+int verify_hostkey_dns(char FAR *hostname, Key *key)
+{
+	DNS_STATUS status;
+	PDNS_RECORD rec, p;
+	PDNS_SSHFP_DATA t;
+	int hostkey_alg, hostkey_dtype, hostkey_dlen;
+	BYTE *hostkey_digest;
+	int found = DNS_VERIFY_NOTFOUND;
+
+	switch (key->type) {
+	case KEY_RSA:
+		hostkey_alg = SSHFP_KEY_RSA;
+		hostkey_dtype = SSHFP_HASH_SHA1;
+		break;
+	case KEY_DSA:
+		hostkey_alg = SSHFP_KEY_DSA;
+		hostkey_dtype = SSHFP_HASH_SHA1;
+		break;
+	case KEY_ECDSA256:
+	case KEY_ECDSA384:
+	case KEY_ECDSA521:
+		hostkey_alg = SSHFP_KEY_ECDSA;
+		hostkey_dtype = SSHFP_HASH_SHA256;
+		break;
+	default: // Un-supported algorithm
+		hostkey_alg = SSHFP_KEY_RESERVED;
+		hostkey_dtype = SSHFP_HASH_RESERVED;
+	}
+
+	if (hostkey_alg) {
+		hostkey_digest = key_fingerprint_raw(key, hostkey_dtype, &hostkey_dlen);
+	}
+	else {
+		hostkey_digest = NULL;
+	}
+
+	status = DnsQuery(hostname, DNS_TYPE_SSHFP, DNS_QUERY_STANDARD, NULL, &rec, NULL);
+
+	if (status == 0) {
+		for (p=rec; p!=NULL; p=p->pNext) {
+			if (p->wType == DNS_TYPE_SSHFP) {
+				t = (PDNS_SSHFP_DATA)&(p->Data.Null);
+				if (t->Algorithm == hostkey_alg && t->DigestType == hostkey_dtype) {
+					if (hostkey_dlen == p->wDataLength-2 && memcmp(hostkey_digest, t->Digest, hostkey_dlen) == 0) {
+						found = DNS_VERIFY_MATCH;
+						break;
+					}
+					else {
+						found = DNS_VERIFY_MISMATCH;
+						break;
+					}
+				}
+				else {
+					found = DNS_VERIFY_DIFFERENTTYPE;
+				}
+			}
+		}
+	}
+
+	free(hostkey_digest);
+	DnsRecordListFree(rec, DnsFreeRecordList);
+	return found;
+}

Added: trunk/ttssh2/ttxssh/dns.h
===================================================================
--- trunk/ttssh2/ttxssh/dns.h	                        (rev 0)
+++ trunk/ttssh2/ttxssh/dns.h	2011-08-04 06:00:17 UTC (rev 4569)
@@ -0,0 +1,67 @@
+/*
+Copyright (c) TeraTerm Project.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+  1. Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright notice,
+     this list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+  3. The name of the author may not be used to endorse or promote products derived
+     from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
+*/
+
+#ifndef __TTSSH_DNS_H
+#define __TTSSH_DNS_H
+
+#include <windns.h>
+
+#define DNS_TYPE_SSHFP	44
+
+enum sshfp_types {
+        SSHFP_KEY_RESERVED,
+        SSHFP_KEY_RSA,
+        SSHFP_KEY_DSA,
+        SSHFP_KEY_ECDSA
+};
+
+enum sshfp_hashes {
+        SSHFP_HASH_RESERVED,
+        SSHFP_HASH_SHA1,
+        SSHFP_HASH_SHA256
+};
+
+enum verifydns_result {
+	DNS_VERIFY_NONE,
+	DNS_VERIFY_NOTFOUND,
+	DNS_VERIFY_MATCH,
+	DNS_VERIFY_MISMATCH,
+	DNS_VERIFY_DIFFERENTTYPE,
+	DNS_VERIFY_AUTH_MATCH,
+	DNS_VERIFY_AUTH_MISMATCH,
+	DNS_VERIFY_AUTH_DIFFERENTTYPE
+};
+
+typedef struct {
+	BYTE Algorithm;
+	BYTE DigestType;
+	BYTE Digest[1];
+} DNS_SSHFP_DATA, *PDNS_SSHFP_DATA;
+
+int is_numeric_hostname(const char *hostname);
+int verify_hostkey_dns(char FAR *hostname, Key *key);
+
+#endif //  __TTSSH_DNS_H

Modified: trunk/ttssh2/ttxssh/hosts.c
===================================================================
--- trunk/ttssh2/ttxssh/hosts.c	2011-08-03 14:42:03 UTC (rev 4568)
+++ trunk/ttssh2/ttxssh/hosts.c	2011-08-04 06:00:17 UTC (rev 4569)
@@ -38,6 +38,7 @@
 #include "ssh.h"
 #include "key.h"
 #include "hosts.h"
+#include "dns.h"
 
 #include <openssl/bn.h>
 #include <openssl/evp.h>
@@ -51,25 +52,7 @@
 #include <direct.h>
 #include <memory.h>
 
-#include <windns.h>
 
-#define DNS_TYPE_SSHFP	44
-typedef struct {
-	BYTE Algorithm;
-	BYTE DigestType;
-	BYTE Digest[1];
-} DNS_SSHFP_DATA, *PDNS_SSHFP_DATA;
-enum verifydns_result {
-	DNS_VERIFY_NONE,
-	DNS_VERIFY_NOTFOUND,
-	DNS_VERIFY_MATCH,
-	DNS_VERIFY_MISMATCH,
-	DNS_VERIFY_DIFFERENTTYPE,
-	DNS_VERIFY_AUTH_MATCH,
-	DNS_VERIFY_AUTH_MISMATCH,
-	DNS_VERIFY_AUTH_DIFFERENTTYPE
-};
-
 static HFONT DlgHostsAddFont;
 static HFONT DlgHostsReplaceFont;
 
@@ -1755,90 +1738,6 @@
 	}
 }
 
-int is_numeric_hostname(const char *hostname)
-{
-	struct addrinfo hints, *ai;
-
-	if (hostname == NULL) {
-		return -1;
-	}
-
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_socktype = SOCK_DGRAM;
-	hints.ai_flags = AI_NUMERICHOST;
-
-	if (getaddrinfo(hostname, NULL, &hints, &ai) == 0) {
-		freeaddrinfo(ai);
-		return 1;
-	}
-
-	return 0;
-}
-
-int verify_hostkey_dns(char FAR *hostname, Key *key)
-{
-	DNS_STATUS status;
-	PDNS_RECORD rec, p;
-	PDNS_SSHFP_DATA t;
-	int hostkey_alg, hostkey_dtype, hostkey_dlen;
-	BYTE *hostkey_digest;
-	int found = DNS_VERIFY_NOTFOUND;
-
-	switch (key->type) {
-	case KEY_RSA:
-		hostkey_alg = SSHFP_KEY_RSA;
-		hostkey_dtype = SSHFP_HASH_SHA1;
-		break;
-	case KEY_DSA:
-		hostkey_alg = SSHFP_KEY_DSA;
-		hostkey_dtype = SSHFP_HASH_SHA1;
-		break;
-	case KEY_ECDSA256:
-	case KEY_ECDSA384:
-	case KEY_ECDSA521:
-		hostkey_alg = SSHFP_KEY_ECDSA;
-		hostkey_dtype = SSHFP_HASH_SHA256;
-		break;
-	default: // Un-supported algorithm
-		hostkey_alg = SSHFP_KEY_RESERVED;
-		hostkey_dtype = SSHFP_HASH_RESERVED;
-	}
-
-	if (hostkey_alg) {
-		hostkey_digest = key_fingerprint_raw(key, hostkey_dtype, &hostkey_dlen);
-	}
-	else {
-		hostkey_digest = NULL;
-	}
-
-	status = DnsQuery(hostname, DNS_TYPE_SSHFP, DNS_QUERY_STANDARD, NULL, &rec, NULL);
-
-	if (status == 0) {
-		for (p=rec; p!=NULL; p=p->pNext) {
-			if (p->wType == DNS_TYPE_SSHFP) {
-				t = (PDNS_SSHFP_DATA)&(p->Data.Null);
-				if (t->Algorithm == hostkey_alg && t->DigestType == hostkey_dtype) {
-					if (hostkey_dlen == p->wDataLength-2 && memcmp(hostkey_digest, t->Digest, hostkey_dlen) == 0) {
-						found = DNS_VERIFY_MATCH;
-						break;
-					}
-					else {
-						found = DNS_VERIFY_MISMATCH;
-						break;
-					}
-				}
-				else {
-					found = DNS_VERIFY_DIFFERENTTYPE;
-				}
-			}
-		}
-	}
-
-	free(hostkey_digest);
-	DnsRecordListFree(rec, DnsFreeRecordList);
-	return found;
-}
-
 //
 // ƒT[ƒo‚©‚ç‘—‚ç‚ê‚Ä‚«‚½ƒzƒXƒgŒöŠJŒ®‚̑Ó–«‚ðƒ`ƒFƒbƒN‚·‚é
 //

Modified: trunk/ttssh2/ttxssh/ssh.h
===================================================================
--- trunk/ttssh2/ttxssh/ssh.h	2011-08-03 14:42:03 UTC (rev 4568)
+++ trunk/ttssh2/ttxssh/ssh.h	2011-08-04 06:00:17 UTC (rev 4569)
@@ -479,19 +479,6 @@
 	SSH_FP_SHA256
 };
 
-enum sshfp_types {
-	SSHFP_KEY_RESERVED,
-	SSHFP_KEY_RSA,
-	SSHFP_KEY_DSA,
-	SSHFP_KEY_ECDSA
-};
-
-enum sshfp_hashes {
-	SSHFP_HASH_RESERVED,
-	SSHFP_HASH_SHA1,
-	SSHFP_HASH_SHA256
-};
-
 enum scp_dir {
 	TOREMOTE, FROMREMOTE,
 };

Modified: trunk/ttssh2/ttxssh/ttxssh.vcproj
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.vcproj	2011-08-03 14:42:03 UTC (rev 4568)
+++ trunk/ttssh2/ttxssh/ttxssh.vcproj	2011-08-04 06:00:17 UTC (rev 4569)
@@ -245,6 +245,14 @@
 			>
 		</File>
 		<File
+			RelativePath="dns.c"
+			>
+		</File>
+		<File
+			RelativePath="dns.h"
+			>
+		</File>
+		<File
 			RelativePath="fwd.c"
 			>
 		</File>



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