Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ttssh2/ttxssh/hostkey.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9210 - (show annotations) (download) (as text)
Sat Apr 17 08:36:59 2021 UTC (2 years, 11 months ago) by nmaya
Original Path: branches/ssh_chacha20poly1305/ttssh2/ttxssh/hostkey.c
File MIME type: text/x-csrc
File size: 5207 byte(s)
ファイルを分割・コードを移動・関数名を整理・新しい OpenSSH からインポート

- OpenSSH からインポート
  cipher-3des1.c from OpenSSH-7.5p1
  ssherr.c from OpenSSH-8.5p1
  ssherr.h from OpenSSH-8.5p1
1 /*
2 * (C) 2021- TeraTerm Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "ttxssh.h"
30 #include "hostkey.h"
31 #include "kex.h"
32
33
34 struct ssh2_host_key_t {
35 ssh_keytype type;
36 char *name;
37 };
38
39 static const struct ssh2_host_key_t ssh2_host_key[] = {
40 {KEY_RSA1, "ssh-rsa1"}, // for SSH1 only
41 {KEY_RSA, "ssh-rsa"}, // RFC4253
42 {KEY_DSA, "ssh-dss"}, // RFC4253
43 {KEY_ECDSA256, "ecdsa-sha2-nistp256"}, // RFC5656
44 {KEY_ECDSA384, "ecdsa-sha2-nistp384"}, // RFC5656
45 {KEY_ECDSA521, "ecdsa-sha2-nistp521"}, // RFC5656
46 {KEY_ED25519, "ssh-ed25519"}, // draft-bjh21-ssh-ed25519-02
47 {KEY_UNSPEC, "ssh-unknown"},
48 {KEY_NONE, NULL},
49 };
50
51 struct ssh_digest_t {
52 digest_algorithm id;
53 char *name;
54 };
55
56 /* NB. Indexed directly by algorithm number */
57 static const struct ssh_digest_t ssh_digests[] = {
58 { SSH_DIGEST_MD5, "MD5" },
59 { SSH_DIGEST_RIPEMD160, "RIPEMD160" },
60 { SSH_DIGEST_SHA1, "SHA1" },
61 { SSH_DIGEST_SHA256, "SHA256" },
62 { SSH_DIGEST_SHA384, "SHA384" },
63 { SSH_DIGEST_SHA512, "SHA512" },
64 { SSH_DIGEST_MAX, NULL },
65 };
66
67
68 ssh_keytype get_hostkey_type_from_name(char *name)
69 {
70 if (strcmp(name, "rsa1") == 0) {
71 return KEY_RSA1;
72 } else if (strcmp(name, "rsa") == 0) {
73 return KEY_RSA;
74 } else if (strcmp(name, "dsa") == 0) {
75 return KEY_DSA;
76 } else if (strcmp(name, "ssh-rsa") == 0) {
77 return KEY_RSA;
78 } else if (strcmp(name, "ssh-dss") == 0) {
79 return KEY_DSA;
80 } else if (strcmp(name, "ecdsa-sha2-nistp256") == 0) {
81 return KEY_ECDSA256;
82 } else if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
83 return KEY_ECDSA384;
84 } else if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
85 return KEY_ECDSA521;
86 } else if (strcmp(name, "ssh-ed25519") == 0) {
87 return KEY_ED25519;
88 }
89 return KEY_UNSPEC;
90 }
91
92 char* get_ssh2_hostkey_type_name(ssh_keytype type)
93 {
94 const struct ssh2_host_key_t *ptr = ssh2_host_key;
95
96 while (ptr->name != NULL) {
97 if (type == ptr->type) {
98 return ptr->name;
99 }
100 ptr++;
101 }
102
103 // not found.
104 return "ssh-unknown";
105 }
106
107 char *get_ssh2_hostkey_type_name_from_key(Key *key)
108 {
109 return get_ssh2_hostkey_type_name(key->type);
110 }
111
112 char* get_digest_algorithm_name(digest_algorithm id)
113 {
114 const struct ssh_digest_t *ptr = ssh_digests;
115
116 while (ptr->name != NULL) {
117 if (id == ptr->id) {
118 return ptr->name;
119 }
120 ptr++;
121 }
122
123 // not found.
124 return "unknown";
125 }
126
127 void normalize_host_key_order(char *buf)
128 {
129 static char default_strings[] = {
130 KEY_ECDSA256,
131 KEY_ECDSA384,
132 KEY_ECDSA521,
133 KEY_ED25519,
134 KEY_RSA,
135 KEY_DSA,
136 KEY_NONE,
137 };
138
139 normalize_generic_order(buf, default_strings, NUM_ELEM(default_strings));
140 }
141
142 ssh_keytype choose_SSH2_host_key_algorithm(char *server_proposal, char *my_proposal)
143 {
144 ssh_keytype type = KEY_UNSPEC;
145 char str_keytype[20];
146 const struct ssh2_host_key_t *ptr = ssh2_host_key;
147
148 choose_SSH2_proposal(server_proposal, my_proposal, str_keytype, sizeof(str_keytype));
149
150 while (ptr->name != NULL) {
151 if (strcmp(ptr->name, str_keytype) == 0) {
152 type = ptr->type;
153 break;
154 }
155 ptr++;
156 }
157
158 return (type);
159 }
160
161 // Host Key�A���S���Y���D���������������Amyproposal[]�������������B
162 // (2011.2.28 yutaka)
163 void SSH2_update_host_key_myproposal(PTInstVar pvar)
164 {
165 static char buf[256]; // TODO: malloc()��������
166 int index;
167 int len, i;
168
169 // ���M�������������������������A�O�������B(2006.6.26 maya)
170 if (pvar->socket != INVALID_SOCKET) {
171 return;
172 }
173
174 buf[0] = '\0';
175 for (i = 0 ; pvar->settings.HostKeyOrder[i] != 0 ; i++) {
176 index = pvar->settings.HostKeyOrder[i] - '0';
177 if (index == KEY_NONE) // disabled line
178 break;
179 strncat_s(buf, sizeof(buf), get_ssh2_hostkey_type_name(index), _TRUNCATE);
180 strncat_s(buf, sizeof(buf), ",", _TRUNCATE);
181 }
182 len = strlen(buf);
183 if (len > 0)
184 buf[len - 1] = '\0'; // get rid of comma
185 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = buf;
186 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26