/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos-monitor

  • Committer: Teddy Hogeborn
  • Date: 2014-06-22 02:19:30 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 317.
  • Revision ID: teddy@recompile.se-20140622021930-icl7h4cm97blhjml
mandos-keygen: Generate "checker" option to use SSH fingerprints.

To turn this off, use a new "--no-ssh" option to mandos-keygen.

* INSTALL (Mandos Server, Mandos Client): Document new suggested
                                          installation of SSH.
* Makefile (confdir/clients.conf): Use new "--no-ssh" option to
                                   "mandos-keygen".
* debian/control (mandos/Depends): Changed to "fping | ssh-client".
  (mandos-client/Recommends): New; set to "ssh".
* intro.xml (FREQUENTLY ASKED QUESTIONS): Rename and rewrite section
                                          called "Faking ping
                                          replies?" to address new
                                          default behavior.
* mandos-clients.conf.xml (OPTIONS/checker): Briefly discuss new
                                             behavior of
                                             mandos-keygen.
* mandos-keygen: Bug fix: Suppress failure output of "shred" to remove
                 "sec*", since no such files may exist.
 (password mode): Scan for SSH key fingerprints and output as new
                  "checker" and "ssh_fingerprint" options, unless new
                  "--no-ssh" option is given.
* mandos-keygen.xml (SYNOPSIS/--force): Bug fix: Document short form.
  (OPTIONS/--no-ssh): New.
  (SEE ALSO): Add reference "ssh-keyscan(1)".
* plugins.d/mandos-client.xml (SECURITY): Briefly mention the
                                          possibility of using SSH key
                                          fingerprints for checking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
import locale
50
50
 
51
 
if sys.version_info.major == 2:
 
51
if sys.version_info[0] == 2:
52
52
    str = unicode
53
53
 
54
54
locale.setlocale(locale.LC_ALL, '')
60
60
domain = 'se.recompile'
61
61
server_interface = domain + '.Mandos'
62
62
client_interface = domain + '.Mandos.Client'
63
 
version = "1.6.8"
 
63
version = "1.6.5"
64
64
 
65
65
def isoformat_to_datetime(iso):
66
66
    "Parse an ISO 8601 date string to a datetime.datetime()"
161
161
                                         self.rejected,
162
162
                                         client_interface,
163
163
                                         byte_arrays=True))
164
 
        self.logger('Created client {}'
165
 
                    .format(self.properties["Name"]), level=0)
 
164
        #self.logger('Created client {0}'
 
165
        #            .format(self.properties["Name"]))
166
166
    
167
167
    def using_timer(self, flag):
168
168
        """Call this method with True or False when timer should be
179
179
    
180
180
    def checker_completed(self, exitstatus, condition, command):
181
181
        if exitstatus == 0:
182
 
            self.logger('Checker for client {} (command "{}")'
183
 
                        ' succeeded'.format(self.properties["Name"],
184
 
                                            command), level=0)
185
182
            self.update()
186
183
            return
187
184
        # Checker failed
188
185
        if os.WIFEXITED(condition):
189
 
            self.logger('Checker for client {} (command "{}") failed'
190
 
                        ' with exit code {}'
 
186
            self.logger('Checker for client {0} (command "{1}")'
 
187
                        ' failed with exit code {2}'
191
188
                        .format(self.properties["Name"], command,
192
189
                                os.WEXITSTATUS(condition)))
193
190
        elif os.WIFSIGNALED(condition):
194
 
            self.logger('Checker for client {} (command "{}") was'
195
 
                        ' killed by signal {}'
 
191
            self.logger('Checker for client {0} (command "{1}") was'
 
192
                        ' killed by signal {2}'
196
193
                        .format(self.properties["Name"], command,
197
194
                                os.WTERMSIG(condition)))
198
195
        elif os.WCOREDUMP(condition):
199
 
            self.logger('Checker for client {} (command "{}") dumped'
200
 
                        ' core'.format(self.properties["Name"],
201
 
                                       command))
 
196
            self.logger('Checker for client {0} (command "{1}")'
 
197
                        ' dumped core'
 
198
                        .format(self.properties["Name"], command))
202
199
        else:
203
 
            self.logger('Checker for client {} completed'
 
200
            self.logger('Checker for client {0} completed'
204
201
                        ' mysteriously'
205
202
                        .format(self.properties["Name"]))
206
203
        self.update()
207
204
    
208
205
    def checker_started(self, command):
209
 
        """Server signals that a checker started."""
210
 
        self.logger('Client {} started checker "{}"'
211
 
                    .format(self.properties["Name"],
212
 
                            command), level=0)
 
206
        """Server signals that a checker started. This could be useful
 
207
           to log in the future. """
 
208
        #self.logger('Client {0} started checker "{1}"'
 
209
        #            .format(self.properties["Name"],
 
210
        #                    str(command)))
 
211
        pass
213
212
    
214
213
    def got_secret(self):
215
 
        self.logger('Client {} received its secret'
 
214
        self.logger('Client {0} received its secret'
216
215
                    .format(self.properties["Name"]))
217
216
    
218
217
    def need_approval(self, timeout, default):
219
218
        if not default:
220
 
            message = 'Client {} needs approval within {} seconds'
 
219
            message = 'Client {0} needs approval within {1} seconds'
221
220
        else:
222
 
            message = 'Client {} will get its secret in {} seconds'
 
221
            message = 'Client {0} will get its secret in {1} seconds'
223
222
        self.logger(message.format(self.properties["Name"],
224
223
                                   timeout/1000))
225
224
    
226
225
    def rejected(self, reason):
227
 
        self.logger('Client {} was rejected; reason: {}'
 
226
        self.logger('Client {0} was rejected; reason: {1}'
228
227
                    .format(self.properties["Name"], reason))
229
228
    
230
229
    def selectable(self):
274
273
            else:
275
274
                timer = datetime.timedelta()
276
275
            if self.properties["ApprovedByDefault"]:
277
 
                message = "Approval in {}. (d)eny?"
 
276
                message = "Approval in {0}. (d)eny?"
278
277
            else:
279
 
                message = "Denial in {}. (a)pprove?"
 
278
                message = "Denial in {0}. (a)pprove?"
280
279
            message = message.format(str(timer).rsplit(".", 1)[0])
281
280
            self.using_timer(True)
282
281
        elif self.properties["LastCheckerStatus"] != 0:
290
289
                timer = max(expires - datetime.datetime.utcnow(),
291
290
                            datetime.timedelta())
292
291
            message = ('A checker has failed! Time until client'
293
 
                       ' gets disabled: {}'
 
292
                       ' gets disabled: {0}'
294
293
                       .format(str(timer).rsplit(".", 1)[0]))
295
294
            self.using_timer(True)
296
295
        else:
297
296
            message = "enabled"
298
297
            self.using_timer(False)
299
 
        self._text = "{}{}".format(base, message)
 
298
        self._text = "{0}{1}".format(base, message)
300
299
        
301
300
        if not urwid.supports_unicode():
302
301
            self._text = self._text.encode("ascii", "replace")
404
403
    """This is the entire user interface - the whole screen
405
404
    with boxes, lists of client widgets, etc.
406
405
    """
407
 
    def __init__(self, max_log_length=1000, log_level=1):
 
406
    def __init__(self, max_log_length=1000):
408
407
        DBusGMainLoop(set_as_default=True)
409
408
        
410
409
        self.screen = urwid.curses_display.Screen()
448
447
        self.log = []
449
448
        self.max_log_length = max_log_length
450
449
        
451
 
        self.log_level = log_level
452
 
        
453
450
        # We keep a reference to the log widget so we can remove it
454
451
        # from the ListWalker without it getting destroyed
455
452
        self.logbox = ConstrainedListBox(self.log)
469
466
        self.main_loop = gobject.MainLoop()
470
467
    
471
468
    def client_not_found(self, fingerprint, address):
472
 
        self.log_message("Client with address {} and fingerprint {}"
473
 
                         " could not be found"
 
469
        self.log_message("Client with address {0} and fingerprint"
 
470
                         " {1} could not be found"
474
471
                         .format(address, fingerprint))
475
472
    
476
473
    def rebuild(self):
489
486
            self.uilist.append(self.logbox)
490
487
        self.topwidget = urwid.Pile(self.uilist)
491
488
    
492
 
    def log_message(self, message, level=1):
 
489
    def log_message(self, message):
493
490
        """Log message formatted with timestamp"""
494
 
        if level < self.log_level:
495
 
            return
496
491
        timestamp = datetime.datetime.now().isoformat()
497
 
        self.log_message_raw("{}: {}".format(timestamp, message),
498
 
                             level=level)
 
492
        self.log_message_raw(timestamp + ": " + message)
499
493
    
500
 
    def log_message_raw(self, markup, level=1):
 
494
    def log_message_raw(self, markup):
501
495
        """Add a log message to the log buffer."""
502
 
        if level < self.log_level:
503
 
            return
504
496
        self.log.append(urwid.Text(markup, wrap=self.log_wrap))
505
497
        if (self.max_log_length
506
498
            and len(self.log) > self.max_log_length):
513
505
        """Toggle visibility of the log buffer."""
514
506
        self.log_visible = not self.log_visible
515
507
        self.rebuild()
516
 
        self.log_message("Log visibility changed to: {}"
517
 
                         .format(self.log_visible), level=0)
 
508
        #self.log_message("Log visibility changed to: "
 
509
        #                 + str(self.log_visible))
518
510
    
519
511
    def change_log_display(self):
520
512
        """Change type of log display.
525
517
            self.log_wrap = "clip"
526
518
        for textwidget in self.log:
527
519
            textwidget.set_wrap_mode(self.log_wrap)
528
 
        self.log_message("Wrap mode: {}".format(self.log_wrap),
529
 
                         level=0)
 
520
        #self.log_message("Wrap mode: " + self.log_wrap)
530
521
    
531
522
    def find_and_remove_client(self, path, name):
532
523
        """Find a client by its object path and remove it.
537
528
            client = self.clients_dict[path]
538
529
        except KeyError:
539
530
            # not found?
540
 
            self.log_message("Unknown client {!r} ({!r}) removed"
 
531
            self.log_message("Unknown client {0!r} ({1!r}) removed"
541
532
                             .format(name, path))
542
533
            return
543
534
        client.delete()
661
652
            elif key == "window resize":
662
653
                self.size = self.screen.get_cols_rows()
663
654
                self.refresh()
664
 
            elif key == "ctrl l":
665
 
                self.screen.clear()
 
655
            elif key == "\f":  # Ctrl-L
666
656
                self.refresh()
667
657
            elif key == "l" or key == "D":
668
658
                self.toggle_log_display()
680
670
                                            "?: Help",
681
671
                                            "l: Log window toggle",
682
672
                                            "TAB: Switch window",
683
 
                                            "w: Wrap (log lines)",
684
 
                                            "v: Toggle verbose log",
685
 
                                            ))))
 
673
                                            "w: Wrap (log)"))))
686
674
                self.log_message_raw(("bold",
687
675
                                      "  "
688
676
                                      .join(("Clients:",
701
689
                else:
702
690
                    self.topwidget.set_focus(self.logbox)
703
691
                self.refresh()
704
 
            elif key == "v":
705
 
                if self.log_level == 0:
706
 
                    self.log_level = 1
707
 
                    self.log_message("Verbose mode: Off")
708
 
                else:
709
 
                    self.log_level = 0
710
 
                    self.log_message("Verbose mode: On")
711
692
            #elif (key == "end" or key == "meta >" or key == "G"
712
693
            #      or key == ">"):
713
694
            #    pass            # xxx end-of-buffer