/mandos/trunk

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

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2019-07-29 16:35:53 UTC
  • Revision ID: teddy@recompile.se-20190729163553-1i442i2cbx64c537
Make tests and man page examples match

Make the tests test_manual_page_example[1-5] match exactly what is
written in the manual page, and add comments to manual page as
reminders to keep tests and manual page examples in sync.

* mandos-ctl (Test_commands_from_options.test_manual_page_example_1):
  Remove "--verbose" option, since the manual does not have it as the
  first example, and change assertion to match.
* mandos-ctl.xml (EXAMPLE): Add comments to all examples documenting
  which test function they correspond to.  Also remove unnecessary
  quotes from option arguments in fourth example, and clarify language
  slightly in fifth example.

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
if sys.version_info.major == 2:
116
116
    str = unicode
117
117
 
118
 
version = "1.7.20"
 
118
version = "1.8.4"
119
119
stored_state_file = "clients.pickle"
120
120
 
121
121
logger = logging.getLogger()
275
275
 
276
276
 
277
277
# Pretend that we have an Avahi module
278
 
class Avahi(object):
279
 
    """This isn't so much a class as it is a module-like namespace.
280
 
    It is instantiated once, and simulates having an Avahi module."""
 
278
class avahi(object):
 
279
    """This isn't so much a class as it is a module-like namespace."""
281
280
    IF_UNSPEC = -1               # avahi-common/address.h
282
281
    PROTO_UNSPEC = -1            # avahi-common/address.h
283
282
    PROTO_INET = 0               # avahi-common/address.h
287
286
    DBUS_INTERFACE_SERVER = DBUS_NAME + ".Server"
288
287
    DBUS_PATH_SERVER = "/"
289
288
 
290
 
    def string_array_to_txt_array(self, t):
 
289
    @staticmethod
 
290
    def string_array_to_txt_array(t):
291
291
        return dbus.Array((dbus.ByteArray(s.encode("utf-8"))
292
292
                           for s in t), signature="ay")
293
293
    ENTRY_GROUP_ESTABLISHED = 2  # avahi-common/defs.h
298
298
    SERVER_RUNNING = 2           # avahi-common/defs.h
299
299
    SERVER_COLLISION = 3         # avahi-common/defs.h
300
300
    SERVER_FAILURE = 4           # avahi-common/defs.h
301
 
avahi = Avahi()
302
301
 
303
302
 
304
303
class AvahiError(Exception):
504
503
 
505
504
 
506
505
# Pretend that we have a GnuTLS module
507
 
class GnuTLS(object):
508
 
    """This isn't so much a class as it is a module-like namespace.
509
 
    It is instantiated once, and simulates having a GnuTLS module."""
 
506
class gnutls(object):
 
507
    """This isn't so much a class as it is a module-like namespace."""
510
508
 
511
509
    library = ctypes.util.find_library("gnutls")
512
510
    if library is None:
513
511
        library = ctypes.util.find_library("gnutls-deb0")
514
512
    _library = ctypes.cdll.LoadLibrary(library)
515
513
    del library
516
 
    _need_version = b"3.3.0"
517
 
    _tls_rawpk_version = b"3.6.6"
518
 
 
519
 
    def __init__(self):
520
 
        # Need to use "self" here, since this method is called before
521
 
        # the assignment to the "gnutls" global variable happens.
522
 
        if self.check_version(self._need_version) is None:
523
 
            raise self.Error("Needs GnuTLS {} or later"
524
 
                             .format(self._need_version))
525
514
 
526
515
    # Unless otherwise indicated, the constants and types below are
527
516
    # all from the gnutls/gnutls.h C header file.
569
558
 
570
559
    # Exceptions
571
560
    class Error(Exception):
572
 
        # We need to use the class name "GnuTLS" here, since this
573
 
        # exception might be raised from within GnuTLS.__init__,
574
 
        # which is called before the assignment to the "gnutls"
575
 
        # global variable has happened.
576
561
        def __init__(self, message=None, code=None, args=()):
577
562
            # Default usage is by a message string, but if a return
578
563
            # code is passed, convert it to a string with
579
564
            # gnutls.strerror()
580
565
            self.code = code
581
566
            if message is None and code is not None:
582
 
                message = GnuTLS.strerror(code)
583
 
            return super(GnuTLS.Error, self).__init__(
 
567
                message = gnutls.strerror(code)
 
568
            return super(gnutls.Error, self).__init__(
584
569
                message, *args)
585
570
 
586
571
    class CertificateSecurityError(Error):
601
586
        def __init__(self, socket, credentials=None):
602
587
            self._c_object = gnutls.session_t()
603
588
            gnutls_flags = gnutls.CLIENT
604
 
            if gnutls.check_version("3.5.6"):
 
589
            if gnutls.check_version(b"3.5.6"):
605
590
                gnutls_flags |= gnutls.NO_TICKETS
606
591
            if gnutls.has_rawpk:
607
592
                gnutls_flags |= gnutls.ENABLE_RAWPK
744
729
    check_version.argtypes = [ctypes.c_char_p]
745
730
    check_version.restype = ctypes.c_char_p
746
731
 
 
732
    _need_version = b"3.3.0"
 
733
    if check_version(_need_version) is None:
 
734
        raise self.Error("Needs GnuTLS {} or later"
 
735
                         .format(_need_version))
 
736
 
 
737
    _tls_rawpk_version = b"3.6.6"
747
738
    has_rawpk = bool(check_version(_tls_rawpk_version))
748
739
 
749
740
    if has_rawpk:
803
794
                                                    ctypes.c_size_t)]
804
795
        openpgp_crt_get_fingerprint.restype = _error_code
805
796
 
806
 
    if check_version("3.6.4"):
 
797
    if check_version(b"3.6.4"):
807
798
        certificate_type_get2 = _library.gnutls_certificate_type_get2
808
799
        certificate_type_get2.argtypes = [session_t, ctypes.c_int]
809
800
        certificate_type_get2.restype = _error_code
810
801
 
811
802
    # Remove non-public functions
812
803
    del _error_code, _retry_on_error
813
 
# Create the global "gnutls" object, simulating a module
814
 
gnutls = GnuTLS()
815
804
 
816
805
 
817
806
def call_pipe(connection,       # : multiprocessing.Connection
2298
2287
            approval_required = False
2299
2288
            try:
2300
2289
                if gnutls.has_rawpk:
2301
 
                    fpr = ""
 
2290
                    fpr = b""
2302
2291
                    try:
2303
2292
                        key_id = self.key_id(
2304
2293
                            self.peer_certificate(session))
2308
2297
                    logger.debug("Key ID: %s", key_id)
2309
2298
 
2310
2299
                else:
2311
 
                    key_id = ""
 
2300
                    key_id = b""
2312
2301
                    try:
2313
2302
                        fpr = self.fingerprint(
2314
2303
                            self.peer_certificate(session))
2616
2605
                    raise
2617
2606
        # Only bind(2) the socket if we really need to.
2618
2607
        if self.server_address[0] or self.server_address[1]:
 
2608
            if self.server_address[1]:
 
2609
                self.allow_reuse_address = True
2619
2610
            if not self.server_address[0]:
2620
2611
                if self.address_family == socket.AF_INET6:
2621
2612
                    any_address = "::"  # in6addr_any
2700
2691
            address = request[3]
2701
2692
 
2702
2693
            for c in self.clients.values():
 
2694
                if key_id == "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855":
 
2695
                    continue
2703
2696
                if key_id and c.key_id == key_id:
2704
2697
                    client = c
2705
2698
                    break
3251
3244
                        for k in ("name", "host"):
3252
3245
                            if isinstance(value[k], bytes):
3253
3246
                                value[k] = value[k].decode("utf-8")
3254
 
                        if not value.has_key("key_id"):
 
3247
                        if "key_id" not in value:
3255
3248
                            value["key_id"] = ""
3256
 
                        elif not value.has_key("fingerprint"):
 
3249
                        elif "fingerprint" not in value:
3257
3250
                            value["fingerprint"] = ""
3258
3251
                    #  old_client_settings
3259
3252
                    # .keys()