Rev 60 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 60 | Rev 63 | ||
---|---|---|---|
1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
2 | ## blacklist.dpatch by Magnus Holmgren <holmgren@debian.org> |
2 | ## blacklist.dpatch by Magnus Holmgren <holmgren@debian.org> |
3 | ## blacklist.c code copied from OpenSSH's authfile.c and adapted for LSH. |
3 | ## blacklist.c code copied from OpenSSH's authfile.c and adapted for LSH. |
4 | ## |
4 | ## |
5 | ## DP: Check keys against openssh-blacklist before accepting for |
5 | ## DP: Check keys against openssh-blacklist before accepting for |
6 | ## DP: pubkey authentication as well as on conversion by lsh-writekey |
6 | ## DP: pubkey authentication as well as on conversion by lsh-writekey |
7 | ## DP: and lsh-decode-key. |
7 | ## DP: and lsh-decode-key. |
8 | 8 | ||
9 | @DPATCH@ |
9 | @DPATCH@ |
10 | diff -urNad trunk~/src/Makefile.am trunk/src/Makefile.am |
10 | diff -urNad trunk~/src/Makefile.am trunk/src/Makefile.am |
11 | --- trunk~/src/Makefile.am 2004-11-18 22:52:16.000000000 +0100 |
11 | --- trunk~/src/Makefile.am 2004-11-18 22:52:16.000000000 +0100 |
12 | +++ trunk/src/Makefile.am 2009-11-06 01:07:40.000000000 +0100 |
12 | +++ trunk/src/Makefile.am 2009-11-0 23:57:07.000000000 +0100 |
13 | @@ -72,7 +72,8 @@ |
13 | @@ -72,7 +72,8 @@ |
14 | unix_interact.c unix_process.c unix_random.c unix_user.c \ |
14 | unix_interact.c unix_process.c unix_random.c unix_user.c \ |
15 | userauth.c \ |
15 | userauth.c \ |
16 | werror.c write_buffer.c write_packet.c \ |
16 | werror.c write_buffer.c write_packet.c \ |
17 | - xalloc.c xauth.c zlib.c |
17 | - xalloc.c xauth.c zlib.c |
18 | + xalloc.c xauth.c zlib.c \ |
18 | + xalloc.c xauth.c zlib.c \ |
19 | + blacklist.c |
19 | + blacklist.c |
20 | 20 | ||
21 | liblsh_a_LIBADD = @LIBOBJS@ |
21 | liblsh_a_LIBADD = @LIBOBJS@ |
22 | 22 | ||
23 | diff -urNad trunk~/src/Makefile.in trunk/src/Makefile.in |
23 | diff -urNad trunk~/src/Makefile.in trunk/src/Makefile.in |
24 | --- trunk~/src/Makefile.in 2009-11-06 01:07:40.000000000 +0100 |
24 | --- trunk~/src/Makefile.in 2009-11-07 23:57:06.000000000 +0100 |
25 | +++ trunk/src/Makefile.in 2009-11-06 01:07:40.000000000 +0100 |
25 | +++ trunk/src/Makefile.in 2009-11-07 23:57:07.000000000 +0100 |
26 | @@ -91,7 +91,8 @@ |
26 | @@ -91,7 +91,8 @@ |
27 | tty.$(OBJEXT) unix_interact.$(OBJEXT) unix_process.$(OBJEXT) \ |
27 | tty.$(OBJEXT) unix_interact.$(OBJEXT) unix_process.$(OBJEXT) \ |
28 | unix_random.$(OBJEXT) unix_user.$(OBJEXT) userauth.$(OBJEXT) \ |
28 | unix_random.$(OBJEXT) unix_user.$(OBJEXT) userauth.$(OBJEXT) \ |
29 | werror.$(OBJEXT) write_buffer.$(OBJEXT) write_packet.$(OBJEXT) \ |
29 | werror.$(OBJEXT) write_buffer.$(OBJEXT) write_packet.$(OBJEXT) \ |
30 | - xalloc.$(OBJEXT) xauth.$(OBJEXT) zlib.$(OBJEXT) |
30 | - xalloc.$(OBJEXT) xauth.$(OBJEXT) zlib.$(OBJEXT) |
31 | + xalloc.$(OBJEXT) xauth.$(OBJEXT) zlib.$(OBJEXT) \ |
31 | + xalloc.$(OBJEXT) xauth.$(OBJEXT) zlib.$(OBJEXT) \ |
32 | + blacklist.$(OBJEXT) |
32 | + blacklist.$(OBJEXT) |
33 | liblsh_a_OBJECTS = $(am_liblsh_a_OBJECTS) |
33 | liblsh_a_OBJECTS = $(am_liblsh_a_OBJECTS) |
34 | am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" \ |
34 | am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" \ |
35 | "$(DESTDIR)$(bindir)" |
35 | "$(DESTDIR)$(bindir)" |
36 | @@ -510,7 +511,8 @@ |
36 | @@ -510,7 +511,8 @@ |
37 | unix_interact.c unix_process.c unix_random.c unix_user.c \ |
37 | unix_interact.c unix_process.c unix_random.c unix_user.c \ |
38 | userauth.c \ |
38 | userauth.c \ |
39 | werror.c write_buffer.c write_packet.c \ |
39 | werror.c write_buffer.c write_packet.c \ |
40 | - xalloc.c xauth.c zlib.c |
40 | - xalloc.c xauth.c zlib.c |
41 | + xalloc.c xauth.c zlib.c \ |
41 | + xalloc.c xauth.c zlib.c \ |
42 | + blacklist.c |
42 | + blacklist.c |
43 | 43 | ||
44 | liblsh_a_LIBADD = @LIBOBJS@ |
44 | liblsh_a_LIBADD = @LIBOBJS@ |
45 | 45 | ||
46 | @@ -705,6 +707,7 @@ |
46 | @@ -705,6 +707,7 @@ |
47 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/algorithms.Po@am__quote@ |
47 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/algorithms.Po@am__quote@ |
48 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alist.Po@am__quote@ |
48 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alist.Po@am__quote@ |
49 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atoms.Po@am__quote@ |
49 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atoms.Po@am__quote@ |
50 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/blacklist.Po@am__quote@ |
50 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/blacklist.Po@am__quote@ |
51 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/channel.Po@am__quote@ |
51 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/channel.Po@am__quote@ |
52 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/channel_commands.Po@am__quote@ |
52 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/channel_commands.Po@am__quote@ |
53 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/channel_forward.Po@am__quote@ |
53 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/channel_forward.Po@am__quote@ |
- | 54 | diff -urNad trunk~/src/abstract_crypto.h trunk/src/abstract_crypto.h |
|
- | 55 | --- trunk~/src/abstract_crypto.h 2003-11-16 19:10:30.000000000 +0100 |
|
- | 56 | +++ trunk/src/abstract_crypto.h 2009-11-07 23:57:37.000000000 +0100 |
|
- | 57 | @@ -162,7 +162,9 @@ |
|
- | 58 | (public_key method (string)) |
|
- | 59 | ||
- | 60 | ; Returns (public-key (<pub-sig-alg-id> <s-expr>*)) |
|
- | 61 | - (public_spki_key method (string) "int transport"))) |
|
- | 62 | + (public_spki_key method (string) "int transport") |
|
- | 63 | + |
|
- | 64 | + (key_size method uint32_t))) |
|
- | 65 | */ |
|
- | 66 | ||
- | 67 | #define VERIFY(verifier, algorithm, length, data, slength, sdata) \ |
|
- | 68 | @@ -170,7 +172,7 @@ |
|
- | 69 | ||
- | 70 | #define PUBLIC_KEY(verifier) ((verifier)->public_key((verifier))) |
|
- | 71 | #define PUBLIC_SPKI_KEY(verifier, t) ((verifier)->public_spki_key((verifier), (t))) |
|
- | 72 | - |
|
- | 73 | +#define KEY_SIZE(verifier) ((verifier)->key_size((verifier))) |
|
- | 74 | ||
- | 75 | /* GABA: |
|
- | 76 | (class |
|
- | 77 | diff -urNad trunk~/src/abstract_crypto.h.x trunk/src/abstract_crypto.h.x |
|
- | 78 | --- trunk~/src/abstract_crypto.h.x 2007-06-04 22:18:39.000000000 +0200 |
|
- | 79 | +++ trunk/src/abstract_crypto.h.x 2009-11-07 23:57:07.000000000 +0100 |
|
- | 80 | @@ -161,6 +161,7 @@ |
|
- | 81 | int (*(verify))(struct verifier *self,int algorithm,uint32_t length,const uint8_t *data,uint32_t signature_length,const uint8_t *signature_data); |
|
- | 82 | struct lsh_string *(*(public_key))(struct verifier *self); |
|
- | 83 | struct lsh_string *(*(public_spki_key))(struct verifier *self,int transport); |
|
- | 84 | + uint32_t *(*(key_size))(struct verifier *self); |
|
- | 85 | }; |
|
- | 86 | extern struct lsh_class verifier_class; |
|
- | 87 | #endif /* !GABA_DEFINE */ |
|
54 | diff -urNad trunk~/src/blacklist.c trunk/src/blacklist.c |
88 | diff -urNad trunk~/src/blacklist.c trunk/src/blacklist.c |
55 | --- trunk~/src/blacklist.c 1970-01-01 01:00:00.000000000 +0100 |
89 | --- trunk~/src/blacklist.c 1970-01-01 01:00:00.000000000 +0100 |
56 | +++ trunk/src/blacklist.c 2009-11-06 01:07:40.000000000 +0100 |
90 | +++ trunk/src/blacklist.c 2009-11-07 23:57:07.000000000 +0100 |
57 | @@ -0,0 +1,164 @@ |
91 | @@ -0,0 +1,150 @@ |
58 | +#if HAVE_CONFIG_H |
92 | +#if HAVE_CONFIG_H |
59 | +#include "config.h" |
93 | +#include "config.h" |
60 | +#endif |
94 | +#endif |
61 | + |
95 | + |
62 | +#include <assert.h> |
96 | +#include <assert.h> |
63 | + |
97 | + |
64 | +#include "nettle/bignum.h" |
- | |
65 | +#include "nettle/dsa.h" |
- | |
66 | +#include "nettle/rsa.h" |
- | |
67 | +#include "xalloc.h" |
- | |
68 | +#include "atoms.h" |
98 | +#include "atoms.h" |
69 | +#include "format.h" |
99 | +#include "format.h" |
70 | +#include "lsh_string.h" |
100 | +#include "lsh_string.h" |
71 | +#include "abstract_crypto.h" |
- | |
72 | +#include "werror.h" |
101 | +#include "werror.h" |
73 | +#include "crypto.h" |
102 | +#include "crypto.h" |
74 | +#define GABA_DECLARE |
- | |
75 | +#include "rsa.c.x" |
- | |
76 | +#include "dsa.c.x" |
- | |
77 | + |
103 | + |
78 | +#include <sys/types.h> |
104 | +#include <sys/types.h> |
79 | +#include <sys/stat.h> |
105 | +#include <sys/stat.h> |
80 | +#include <unistd.h> |
106 | +#include <unistd.h> |
81 | +#include <fcntl.h> |
107 | +#include <fcntl.h> |
82 | +#include <string.h> |
108 | +#include <string.h> |
83 | + |
109 | + |
- | 110 | +int blacklisted_key(struct verifier *v, int method); |
|
- | 111 | + |
|
84 | +/* Scan a blacklist of known-vulnerable keys in blacklist_file. */ |
112 | +/* Scan a blacklist of known-vulnerable keys in blacklist_file. */ |
85 | +static int |
113 | +static int |
86 | +blacklisted_key_in_file(struct lsh_string *lsh_hash, struct lsh_string *blacklist_file) |
114 | +blacklisted_key_in_file(struct lsh_string *lsh_hash, struct lsh_string *blacklist_file) |
87 | +{ |
115 | +{ |
88 | + int fd = -1; |
116 | + int fd = -1; |
89 | + const char *hash = 0; |
117 | + const char *hash = 0; |
90 | + int i; |
- | |
91 | + uint32_t line_len; |
118 | + uint32_t line_len; |
92 | + struct stat st; |
119 | + struct stat st; |
93 | + char buf[256]; |
120 | + char buf[256]; |
94 | + off_t start, lower, upper; |
121 | + off_t start, lower, upper; |
95 | + int ret = 0; |
122 | + int ret = 0; |
96 | + |
123 | + |
97 | + debug("Checking blacklist file %S\n", blacklist_file); |
124 | + debug("Checking blacklist file %S\n", blacklist_file); |
98 | + fd = open(lsh_get_cstring(blacklist_file), O_RDONLY); |
125 | + fd = open(lsh_get_cstring(blacklist_file), O_RDONLY); |
99 | + if (fd < 0) { |
126 | + if (fd < 0) { |
100 | + ret = -1; |
127 | + ret = -1; |
101 | + goto out; |
128 | + goto out; |
102 | + } |
129 | + } |
103 | + |
130 | + |
104 | + hash = lsh_get_cstring(lsh_hash) + 12; |
131 | + hash = lsh_get_cstring(lsh_hash) + 12; |
105 | + line_len = strlen(hash); |
132 | + line_len = strlen(hash); |
106 | + if (line_len != 20) |
133 | + if (line_len != 20) |
107 | + goto out; |
134 | + goto out; |
108 | + |
135 | + |
109 | + /* Skip leading comments */ |
136 | + /* Skip leading comments */ |
110 | + start = 0; |
137 | + start = 0; |
111 | + for (;;) { |
138 | + for (;;) { |
112 | + ssize_t r; |
139 | + ssize_t r; |
113 | + char *newline; |
140 | + char *newline; |
114 | + |
141 | + |
115 | + r = read(fd, buf, sizeof(buf)); |
142 | + r = read(fd, buf, sizeof(buf)); |
116 | + if (r <= 0) |
143 | + if (r <= 0) |
117 | + goto out; |
144 | + goto out; |
118 | + if (buf[0] != '#') |
145 | + if (buf[0] != '#') |
119 | + break; |
146 | + break; |
120 | + |
147 | + |
121 | + newline = memchr(buf, '\n', sizeof(buf)); |
148 | + newline = memchr(buf, '\n', sizeof(buf)); |
122 | + if (!newline) |
149 | + if (!newline) |
123 | + goto out; |
150 | + goto out; |
124 | + start += newline + 1 - buf; |
151 | + start += newline + 1 - buf; |
125 | + if (lseek(fd, start, SEEK_SET) < 0) |
152 | + if (lseek(fd, start, SEEK_SET) < 0) |
126 | + goto out; |
153 | + goto out; |
127 | + } |
154 | + } |
128 | + |
155 | + |
129 | + /* Initialise binary search record numbers */ |
156 | + /* Initialise binary search record numbers */ |
130 | + if (fstat(fd, &st) < 0) |
157 | + if (fstat(fd, &st) < 0) |
131 | + goto out; |
158 | + goto out; |
132 | + lower = 0; |
159 | + lower = 0; |
133 | + upper = (st.st_size - start) / (line_len + 1); |
160 | + upper = (st.st_size - start) / (line_len + 1); |
134 | + |
161 | + |
135 | + while (lower != upper) { |
162 | + while (lower != upper) { |
136 | + off_t cur; |
163 | + off_t cur; |
137 | + int cmp; |
164 | + int cmp; |
138 | + |
165 | + |
139 | + cur = lower + (upper - lower) / 2; |
166 | + cur = lower + (upper - lower) / 2; |
140 | + |
167 | + |
141 | + /* Read this line and compare to digest; this is |
168 | + /* Read this line and compare to digest; this is |
142 | + * overflow-safe since cur < max(off_t) / (line_len + 1) */ |
169 | + * overflow-safe since cur < max(off_t) / (line_len + 1) */ |
143 | + if (lseek(fd, start + cur * (line_len + 1), SEEK_SET) < 0) |
170 | + if (lseek(fd, start + cur * (line_len + 1), SEEK_SET) < 0) |
144 | + break; |
171 | + break; |
145 | + if (read(fd, buf, line_len) != line_len) |
172 | + if (read(fd, buf, line_len) != line_len) |
146 | + break; |
173 | + break; |
147 | + cmp = memcmp(buf, hash, line_len); |
174 | + cmp = memcmp(buf, hash, line_len); |
148 | + if (cmp < 0) { |
175 | + if (cmp < 0) { |
149 | + if (cur == lower) |
176 | + if (cur == lower) |
150 | + break; |
177 | + break; |
151 | + lower = cur; |
178 | + lower = cur; |
152 | + } else if (cmp > 0) { |
179 | + } else if (cmp > 0) { |
153 | + if (cur == upper) |
180 | + if (cur == upper) |
154 | + break; |
181 | + break; |
155 | + upper = cur; |
182 | + upper = cur; |
156 | + } else { |
183 | + } else { |
157 | + ret = 1; |
184 | + ret = 1; |
158 | + break; |
185 | + break; |
159 | + } |
186 | + } |
160 | + } |
187 | + } |
161 | + |
188 | + |
162 | +out: |
189 | +out: |
163 | + if (fd >= 0) |
190 | + if (fd >= 0) |
164 | + close(fd); |
191 | + close(fd); |
165 | + return ret; |
192 | + return ret; |
166 | +} |
193 | +} |
167 | + |
194 | + |
168 | +/* |
195 | +/* |
169 | + * Scan blacklists of known-vulnerable keys. If a vulnerable key is found, |
196 | + * Scan blacklists of known-vulnerable keys. If a vulnerable key is found, |
170 | + * its fingerprint is returned in *fp, unless fp is NULL. |
197 | + * its fingerprint is returned in *fp, unless fp is NULL. |
171 | + */ |
198 | + */ |
172 | +int |
199 | +int |
173 | +blacklisted_key(struct verifier *v, int method) |
200 | +blacklisted_key(struct verifier *v, int method) |
174 | +{ |
201 | +{ |
175 | + size_t keysize; |
- | |
176 | + const char *keytype; |
202 | + const char *keytype; |
177 | + int ret = -1; |
203 | + int ret = -1; |
178 | + const char *paths[] = { "/usr/share/ssh/blacklist", "/etc/ssh/blacklist", NULL }; |
204 | + const char *paths[] = { "/usr/share/ssh/blacklist", "/etc/ssh/blacklist", NULL }; |
179 | + const char **pp; |
205 | + const char **pp; |
180 | + struct lsh_string *lsh_hash = ssh_format("%lfxS", |
206 | + struct lsh_string *lsh_hash = ssh_format("%lfxS", |
181 | + hash_string(&crypto_md5_algorithm, |
207 | + hash_string(&crypto_md5_algorithm, |
182 | + PUBLIC_KEY(v), 1)); |
208 | + PUBLIC_KEY(v), 1)); |
- | 209 | + uint32_t keysize = KEY_SIZE(v); |
|
183 | + |
210 | + |
184 | + switch (method) |
211 | + switch (method) |
185 | + { |
212 | + { |
186 | + case ATOM_SSH_DSS: |
213 | + case ATOM_SSH_DSS: |
187 | + case ATOM_DSA: |
214 | + case ATOM_DSA: |
188 | + { |
- | |
189 | + CAST(dsa_verifier, self, v); |
- | |
190 | + keytype = "DSA"; |
215 | + keytype = "DSA"; |
191 | + keysize = mpz_sizeinbase(self->key.p, 2); |
- | |
192 | + } |
- | |
193 | + break; |
216 | + break; |
194 | + case ATOM_SSH_RSA: |
217 | + case ATOM_SSH_RSA: |
195 | + case ATOM_RSA_PKCS1_SHA1: |
218 | + case ATOM_RSA_PKCS1_SHA1: |
196 | + case ATOM_RSA_PKCS1_MD5: |
219 | + case ATOM_RSA_PKCS1_MD5: |
197 | + case ATOM_RSA_PKCS1: |
220 | + case ATOM_RSA_PKCS1: |
198 | + { |
- | |
199 | + CAST(rsa_verifier, self, v); |
- | |
200 | + keytype = "RSA"; |
221 | + keytype = "RSA"; |
201 | + keysize = mpz_sizeinbase(self->key.n, 2); |
- | |
202 | + } break; |
222 | + break; |
203 | + default: |
223 | + default: |
204 | + werror("Unrecognized key type"); |
224 | + werror("Unrecognized key type"); |
205 | + return 0; |
225 | + return -1; |
206 | + } |
226 | + } |
207 | + |
227 | + |
208 | + for (pp = paths; *pp && ret <= 0; pp++) { |
228 | + for (pp = paths; *pp && ret <= 0; pp++) { |
209 | + struct lsh_string *blacklist_file = ssh_format("%lz.%lz-%di", |
229 | + struct lsh_string *blacklist_file = ssh_format("%lz.%lz-%di", |
210 | + *pp, keytype, keysize); |
230 | + *pp, keytype, keysize); |
211 | + int r = blacklisted_key_in_file(lsh_hash, blacklist_file); |
231 | + int r = blacklisted_key_in_file(lsh_hash, blacklist_file); |
212 | + lsh_string_free(blacklist_file); |
232 | + lsh_string_free(blacklist_file); |
213 | + if (r > ret) ret = r; |
233 | + if (r > ret) ret = r; |
214 | + } |
234 | + } |
215 | + |
235 | + |
216 | + if (ret > 0) { |
236 | + if (ret > 0) { |
217 | + werror("Key is compromised: %z %i %fS\n", keytype, keysize, |
237 | + werror("Key is compromised: %z %i %fS\n", keytype, keysize, |
218 | + lsh_string_colonize(lsh_hash, 2, 0)); |
238 | + lsh_string_colonize(lsh_hash, 2, 0)); |
219 | + } |
239 | + } |
220 | + return ret; |
240 | + return ret; |
221 | +} |
241 | +} |
- | 242 | diff -urNad trunk~/src/dsa.c trunk/src/dsa.c |
|
- | 243 | --- trunk~/src/dsa.c 2004-06-08 20:00:45.000000000 +0200 |
|
- | 244 | +++ trunk/src/dsa.c 2009-11-07 23:57:07.000000000 +0100 |
|
- | 245 | @@ -189,6 +189,14 @@ |
|
- | 246 | "y", self->key.y); |
|
- | 247 | } |
|
- | 248 | ||
- | 249 | +static uint32_t |
|
- | 250 | +do_dsa_key_size(struct verifier *v) |
|
- | 251 | +{ |
|
- | 252 | + CAST(dsa_verifier, self, v); |
|
- | 253 | + |
|
- | 254 | + return mpz_sizeinbase(self->key.p, 2); |
|
- | 255 | +} |
|
- | 256 | + |
|
- | 257 | static void |
|
- | 258 | init_dsa_verifier(struct dsa_verifier *self) |
|
- | 259 | { |
|
- | 260 | @@ -199,6 +207,7 @@ |
|
- | 261 | self->super.verify = do_dsa_verify; |
|
- | 262 | self->super.public_spki_key = do_dsa_public_spki_key; |
|
- | 263 | self->super.public_key = do_dsa_public_key; |
|
- | 264 | + self->super.key_size = do_dsa_key_size; |
|
- | 265 | } |
|
- | 266 | ||
- | 267 | ||
222 | diff -urNad trunk~/src/lsh-decode-key.c trunk/src/lsh-decode-key.c |
268 | diff -urNad trunk~/src/lsh-decode-key.c trunk/src/lsh-decode-key.c |
223 | --- trunk~/src/lsh-decode-key.c 2005-09-06 14:43:15.000000000 +0200 |
269 | --- trunk~/src/lsh-decode-key.c 2005-09-06 14:43:15.000000000 +0200 |
224 | +++ trunk/src/lsh-decode-key.c 2009-11-06 01:07:40.000000000 +0100 |
270 | +++ trunk/src/lsh-decode-key.c 2009-11-07 23:57:07.000000000 +0100 |
225 | @@ -133,6 +133,10 @@ |
271 | @@ -133,6 +133,10 @@ |
226 | werror("Invalid dsa key.\n"); |
272 | werror("Invalid dsa key.\n"); |
227 | return NULL; |
273 | return NULL; |
228 | } |
274 | } |
229 | + else if (blacklisted_key(v, type)) |
275 | + else if (blacklisted_key(v, type)) |
230 | + { |
276 | + { |
231 | + return NULL; |
277 | + return NULL; |
232 | + } |
278 | + } |
233 | else |
279 | else |
234 | return PUBLIC_SPKI_KEY(v, 1); |
280 | return PUBLIC_SPKI_KEY(v, 1); |
235 | } |
281 | } |
236 | @@ -150,6 +154,10 @@ |
282 | @@ -150,6 +154,10 @@ |
237 | werror("Invalid rsa key.\n"); |
283 | werror("Invalid rsa key.\n"); |
238 | return NULL; |
284 | return NULL; |
239 | } |
285 | } |
240 | + else if (blacklisted_key(v, type)) |
286 | + else if (blacklisted_key(v, type)) |
241 | + { |
287 | + { |
242 | + return NULL; |
288 | + return NULL; |
243 | + } |
289 | + } |
244 | else |
290 | else |
245 | return PUBLIC_SPKI_KEY(v, 1); |
291 | return PUBLIC_SPKI_KEY(v, 1); |
246 | } |
292 | } |
247 | diff -urNad trunk~/src/lsh-writekey.c trunk/src/lsh-writekey.c |
293 | diff -urNad trunk~/src/lsh-writekey.c trunk/src/lsh-writekey.c |
248 | --- trunk~/src/lsh-writekey.c 2004-11-17 11:55:11.000000000 +0100 |
294 | --- trunk~/src/lsh-writekey.c 2004-11-17 11:55:11.000000000 +0100 |
249 | +++ trunk/src/lsh-writekey.c 2009-11-06 01:11:54.000000000 +0100 |
295 | +++ trunk/src/lsh-writekey.c 2009-11-07 23:57:07.000000000 +0100 |
250 | @@ -397,14 +397,18 @@ |
296 | @@ -397,14 +397,18 @@ |
251 | { |
297 | { |
252 | struct signer *s; |
298 | struct signer *s; |
253 | struct verifier *v; |
299 | struct verifier *v; |
254 | + int algorithm_name; |
300 | + int algorithm_name; |
255 | 301 | ||
256 | - s = spki_make_signer(options->signature_algorithms, key, NULL); |
302 | - s = spki_make_signer(options->signature_algorithms, key, NULL); |
257 | + s = spki_make_signer(options->signature_algorithms, key, &algorithm_name); |
303 | + s = spki_make_signer(options->signature_algorithms, key, &algorithm_name); |
258 | 304 | ||
259 | if (!s) |
305 | if (!s) |
260 | return NULL; |
306 | return NULL; |
261 | 307 | ||
262 | v = SIGNER_GET_VERIFIER(s); |
308 | v = SIGNER_GET_VERIFIER(s); |
263 | assert(v); |
309 | assert(v); |
264 | + if (blacklisted_key(v, algorithm_name)) { |
310 | + if (blacklisted_key(v, algorithm_name)) { |
265 | + return NULL; |
311 | + return NULL; |
266 | + } |
312 | + } |
267 | 313 | ||
268 | return PUBLIC_SPKI_KEY(v, 1); |
314 | return PUBLIC_SPKI_KEY(v, 1); |
269 | } |
315 | } |
270 | @@ -416,7 +420,8 @@ |
316 | @@ -416,7 +420,8 @@ |
271 | int private_fd; |
317 | int private_fd; |
272 | int public_fd; |
318 | int public_fd; |
273 | struct lsh_string *input; |
319 | struct lsh_string *input; |
274 | - struct lsh_string *output; |
320 | - struct lsh_string *output; |
275 | + struct lsh_string *priv_output; |
321 | + struct lsh_string *priv_output; |
276 | + struct lsh_string *pub_output; |
322 | + struct lsh_string *pub_output; |
277 | const struct exception *e; |
323 | const struct exception *e; |
278 | 324 | ||
279 | argp_parse(&main_argp, argc, argv, 0, NULL, options); |
325 | argp_parse(&main_argp, argc, argv, 0, NULL, options); |
280 | @@ -439,16 +444,22 @@ |
326 | @@ -439,16 +444,22 @@ |
281 | return EXIT_FAILURE; |
327 | return EXIT_FAILURE; |
282 | } |
328 | } |
283 | 329 | ||
284 | - output = process_private(input, options); |
330 | - output = process_private(input, options); |
285 | - if (!output) |
331 | - if (!output) |
286 | + pub_output = process_public(input, options); |
332 | + pub_output = process_public(input, options); |
287 | + if (!pub_output) |
333 | + if (!pub_output) |
288 | + return EXIT_FAILURE; |
334 | + return EXIT_FAILURE; |
289 | + |
335 | + |
290 | + priv_output = process_private(input, options); |
336 | + priv_output = process_private(input, options); |
291 | + if (!priv_output) |
337 | + if (!priv_output) |
292 | return EXIT_FAILURE; |
338 | return EXIT_FAILURE; |
293 | 339 | ||
294 | + lsh_string_free(input); |
340 | + lsh_string_free(input); |
295 | + |
341 | + |
296 | private_fd = open_file(options->private_file); |
342 | private_fd = open_file(options->private_file); |
297 | if (private_fd < 0) |
343 | if (private_fd < 0) |
298 | return EXIT_FAILURE; |
344 | return EXIT_FAILURE; |
299 | 345 | ||
300 | - e = write_raw(private_fd, STRING_LD(output)); |
346 | - e = write_raw(private_fd, STRING_LD(output)); |
301 | - lsh_string_free(output); |
347 | - lsh_string_free(output); |
302 | + e = write_raw(private_fd, STRING_LD(priv_output)); |
348 | + e = write_raw(private_fd, STRING_LD(priv_output)); |
303 | + lsh_string_free(priv_output); |
349 | + lsh_string_free(priv_output); |
304 | 350 | ||
305 | if (e) |
351 | if (e) |
306 | { |
352 | { |
307 | @@ -457,18 +468,12 @@ |
353 | @@ -457,18 +468,12 @@ |
308 | return EXIT_FAILURE; |
354 | return EXIT_FAILURE; |
309 | } |
355 | } |
310 | 356 | ||
311 | - output = process_public(input, options); |
357 | - output = process_public(input, options); |
312 | - lsh_string_free(input); |
358 | - lsh_string_free(input); |
313 | - |
359 | - |
314 | - if (!output) |
360 | - if (!output) |
315 | - return EXIT_FAILURE; |
361 | - return EXIT_FAILURE; |
316 | - |
362 | - |
317 | public_fd = open_file(options->public_file); |
363 | public_fd = open_file(options->public_file); |
318 | if (public_fd < 0) |
364 | if (public_fd < 0) |
319 | return EXIT_FAILURE; |
365 | return EXIT_FAILURE; |
320 | 366 | ||
321 | - e = write_raw(public_fd, STRING_LD(output)); |
367 | - e = write_raw(public_fd, STRING_LD(output)); |
322 | - lsh_string_free(output); |
368 | - lsh_string_free(output); |
323 | + e = write_raw(public_fd, STRING_LD(pub_output)); |
369 | + e = write_raw(public_fd, STRING_LD(pub_output)); |
324 | + lsh_string_free(pub_output); |
370 | + lsh_string_free(pub_output); |
325 | 371 | ||
326 | if (e) |
372 | if (e) |
327 | { |
373 | { |
328 | diff -urNad trunk~/src/publickey_crypto.h trunk/src/publickey_crypto.h |
374 | diff -urNad trunk~/src/publickey_crypto.h trunk/src/publickey_crypto.h |
329 | --- trunk~/src/publickey_crypto.h 2004-06-15 13:32:51.000000000 +0200 |
375 | --- trunk~/src/publickey_crypto.h 2004-06-15 13:32:51.000000000 +0200 |
330 | +++ trunk/src/publickey_crypto.h 2009-11-06 01:07:40.000000000 +0100 |
376 | +++ trunk/src/publickey_crypto.h 2009-11-07 23:57:07.000000000 +0100 |
331 | @@ -203,5 +203,7 @@ |
377 | @@ -203,5 +203,7 @@ |
332 | struct verifier * |
378 | struct verifier * |
333 | make_ssh_dss_verifier(const struct lsh_string *public); |
379 | make_ssh_dss_verifier(const struct lsh_string *public); |
334 | 380 | ||
335 | +int |
381 | +int |
336 | +blacklisted_key(struct verifier *v, int method); |
382 | +blacklisted_key(struct verifier *v, int method); |
337 | 383 | ||
338 | #endif /* LSH_PUBLICKEY_CRYPTO_H_INCLUDED */ |
384 | #endif /* LSH_PUBLICKEY_CRYPTO_H_INCLUDED */ |
- | 385 | diff -urNad trunk~/src/rsa.c trunk/src/rsa.c |
|
- | 386 | --- trunk~/src/rsa.c 2003-11-16 19:49:12.000000000 +0100 |
|
- | 387 | +++ trunk/src/rsa.c 2009-11-07 23:57:07.000000000 +0100 |
|
- | 388 | @@ -167,6 +167,14 @@ |
|
- | 389 | self->key.n, self->key.e); |
|
- | 390 | } |
|
- | 391 | ||
- | 392 | +static uint32_t |
|
- | 393 | +do_rsa_key_size(struct verifier *v) |
|
- | 394 | +{ |
|
- | 395 | + CAST(rsa_verifier, self, v); |
|
- | 396 | + |
|
- | 397 | + return mpz_sizeinbase(self->key.n, 2); |
|
- | 398 | +} |
|
- | 399 | + |
|
- | 400 | ||
- | 401 | /* NOTE: To initialize an rsa verifier, one must |
|
- | 402 | * |
|
- | 403 | @@ -184,6 +192,7 @@ |
|
- | 404 | self->super.verify = do_rsa_verify; |
|
- | 405 | self->super.public_key = do_rsa_public_key; |
|
- | 406 | self->super.public_spki_key = do_rsa_public_spki_key; |
|
- | 407 | + self->super.key_size = do_rsa_key_size; |
|
- | 408 | } |
|
- | 409 | ||
- | 410 | /* Alternative constructor using a key of type ssh-rsa, when the atom |
|
339 | diff -urNad trunk~/src/server_authorization.c trunk/src/server_authorization.c |
411 | diff -urNad trunk~/src/server_authorization.c trunk/src/server_authorization.c |
340 | --- trunk~/src/server_authorization.c 2004-06-08 20:01:15.000000000 +0200 |
412 | --- trunk~/src/server_authorization.c 2004-06-08 20:01:15.000000000 +0200 |
341 | +++ trunk/src/server_authorization.c 2009-11-06 01:07:40.000000000 +0100 |
413 | +++ trunk/src/server_authorization.c 2009-11-07 23:57:07.000000000 +0100 |
342 | @@ -93,7 +93,8 @@ |
414 | @@ -93,7 +93,8 @@ |
343 | PUBLIC_SPKI_KEY(v, 0), |
415 | PUBLIC_SPKI_KEY(v, 0), |
344 | 1)); |
416 | 1)); |
345 | 417 | ||
346 | - if (USER_FILE_EXISTS(keyholder, filename, 1)) |
418 | - if (USER_FILE_EXISTS(keyholder, filename, 1)) |
347 | + if (USER_FILE_EXISTS(keyholder, filename, 1) |
419 | + if (USER_FILE_EXISTS(keyholder, filename, 1) |
348 | + && blacklisted_key(v, method) < 1) |
420 | + && blacklisted_key(v, method) < 1) |
349 | return v; |
421 | return v; |
350 | 422 | ||
351 | return NULL; |
423 | return NULL; |