Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 60 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 60 Rev 63
Line 7... Line 7...
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
Line 19... Line 19...
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)
Line 49... Line 49...
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;
Line 170... Line 197...
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);
Line 217... Line 237...
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))
Line 244... Line 290...
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;
Line 325... Line 371...
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))