Exemple #1
0
def create_event_message(sender, tag, data, key):
    '''
    Create and sign a new event message to send to a Laniakea Lighthouse
    instance for publication.
    '''

    if type(key) is str:
        key = decode_signing_key_base64(NACL_ED25519, key)

    msg = {
        'tag': tag,
        'uuid': str(uuid.uuid1()),
        'format': '1.0',
        'time': datetime.now().isoformat(),
        'data': data
    }

    return sign_json(msg, sender, key)
Exemple #2
0
    def __init__(self, endpoints, pub_queue):
        from laniakea import LocalConfig, LkModule
        from laniakea.msgstream.signing import NACL_ED25519, decode_signing_key_base64, \
            keyfile_read_signing_key

        lconf = LocalConfig()
        self._sockets = []
        self._endpoints = endpoints
        self._ctx = zmq.Context.instance()
        self._pub_queue = pub_queue

        # load our own signing key, so we can sign outgoing messages
        keyfile = lconf.secret_curve_keyfile_for_module(LkModule.LIGHTHOUSE)

        self._signer_id = None
        self._signing_key = None
        if os.path.isfile(keyfile):
            self._signer_id, self._signing_key = keyfile_read_signing_key(keyfile)

        if not self._signing_key:
            log.warning('Can not sign outgoing messages: No valid signing key found for this module.')
        else:
            if type(self._signing_key) is str:
                self._signing_key = decode_signing_key_base64(NACL_ED25519, self._signing_key)
Exemple #3
0
 def test_decode_invalid_key(self):
     with pytest.raises(Exception):
         decode_signing_key_base64("ed25519", "", self.version)
Exemple #4
0
 def test_decode_signing_invalid_algorithm(self):
     with pytest.raises(Exception):
         decode_signing_key_base64("not a valid alg", "", self.version)
Exemple #5
0
 def test_decode(self):
     decoded_key = decode_signing_key_base64(
         "ed25519", self.key_base64, self.version
     )
     assert decoded_key.alg == "ed25519"
     assert decoded_key.version == self.version