/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 server.py

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 
97
97
 
98
98
class AvahiService(object):
99
 
    """
 
99
    """An Avahi (Zeroconf) service.
 
100
    Attributes:
100
101
    interface: integer; avahi.IF_UNSPEC or an interface index.
101
102
               Used to optionally bind to the specified interface.
102
 
    name = string; Example: "Mandos"
103
 
    type = string; Example: "_mandos._tcp".
104
 
                   See <http://www.dns-sd.org/ServiceTypes.html>
105
 
    port = integer; what port to announce
106
 
    TXT = list of strings; TXT record for the service
107
 
    domain = string; Domain to publish on, default to .local if empty.
108
 
    host = string; Host to publish records for, default to localhost
109
 
                   if empty.
110
 
    max_renames = integer; maximum number of renames
111
 
    rename_count = integer; counter so we only rename after collisions
112
 
                   a sensible number of times
 
103
    name: string; Example: 'Mandos'
 
104
    type: string; Example: '_mandos._tcp'.
 
105
                  See <http://www.dns-sd.org/ServiceTypes.html>
 
106
    port: integer; what port to announce
 
107
    TXT: list of strings; TXT record for the service
 
108
    domain: string; Domain to publish on, default to .local if empty.
 
109
    host: string; Host to publish records for, default is localhost
 
110
    max_renames: integer; maximum number of renames
 
111
    rename_count: integer; counter so we only rename after collisions
 
112
                  a sensible number of times
113
113
    """
114
114
    def __init__(self, interface = avahi.IF_UNSPEC, name = None,
115
115
                 type = None, port = None, TXT = None, domain = "",
116
116
                 host = "", max_renames = 12):
117
 
        """An Avahi (Zeroconf) service. """
118
117
        self.interface = interface
119
118
        self.name = name
120
119
        self.type = type
222
221
                        _set_interval)
223
222
    del _set_interval
224
223
    def __init__(self, name = None, stop_hook=None, config={}):
225
 
        """Note: the 'checker' argument sets the 'checker_command'
226
 
        attribute and not the 'checker' attribute.."""
 
224
        """Note: the 'checker' key in 'config' sets the
 
225
        'checker_command' attribute and *not* the 'checker'
 
226
        attribute."""
227
227
        self.name = name
228
228
        logger.debug(u"Creating client %r", self.name)
229
 
        # Uppercase and remove spaces from fingerprint
230
 
        # for later comparison purposes with return value of
231
 
        # the fingerprint() function
 
229
        # Uppercase and remove spaces from fingerprint for later
 
230
        # comparison purposes with return value from the fingerprint()
 
231
        # function
232
232
        self.fingerprint = config["fingerprint"].upper()\
233
233
                           .replace(u" ", u"")
234
234
        logger.debug(u"  Fingerprint: %s", self.fingerprint)
395
395
 
396
396
def fingerprint(openpgp):
397
397
    "Convert an OpenPGP bytestring to a hexdigit fingerprint string"
398
 
    # New empty GnuTLS certificate
399
 
    crt = gnutls.library.types.gnutls_openpgp_crt_t()
400
 
    gnutls.library.functions.gnutls_openpgp_crt_init\
401
 
        (ctypes.byref(crt))
402
398
    # New GnuTLS "datum" with the OpenPGP public key
403
399
    datum = gnutls.library.types.gnutls_datum_t\
404
400
        (ctypes.cast(ctypes.c_char_p(openpgp),
405
401
                     ctypes.POINTER(ctypes.c_ubyte)),
406
402
         ctypes.c_uint(len(openpgp)))
 
403
    # New empty GnuTLS certificate
 
404
    crt = gnutls.library.types.gnutls_openpgp_crt_t()
 
405
    gnutls.library.functions.gnutls_openpgp_crt_init\
 
406
        (ctypes.byref(crt))
407
407
    # Import the OpenPGP public key into the certificate
408
 
    ret = gnutls.library.functions.gnutls_openpgp_crt_import\
409
 
        (crt,
410
 
         ctypes.byref(datum),
411
 
         gnutls.library.constants.GNUTLS_OPENPGP_FMT_RAW)
 
408
    gnutls.library.functions.gnutls_openpgp_crt_import\
 
409
                    (crt, ctypes.byref(datum),
 
410
                     gnutls.library.constants.GNUTLS_OPENPGP_FMT_RAW)
412
411
    # New buffer for the fingerprint
413
412
    buffer = ctypes.create_string_buffer(20)
414
413
    buffer_length = ctypes.c_size_t()