Coverage for ion/core/intercept/signature : 78.65%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#!/usr/bin/env python
@file ion/core/intercept/signature.py @author Michael Meisinger @brief Digitally sign and validate message interceptor """
# Configuration #XXX HACKS
msg = invocation.message
#log.info('IdM interceptor IN') cont = msg.payload.copy() hashrec = cont.pop('signature') blob = json.dumps(cont, sort_keys=True) hash = hashlib.sha1(blob).hexdigest() if hash != hashrec: log.info("*********message signature wrong***********")
return invocation
msg = invocation.message
#log.info('IdM interceptor OUT') blob = json.dumps(msg, sort_keys=True) hash = hashlib.sha1(blob).hexdigest() msg['signature'] = hash
invocation.message = msg return invocation
"""Decorate outgoing messages with security attributes and read security attributes of incoming messages.
@todo Decide on what the necessary security headers are.
What/who is the user? The send command of Process sets the user header to be whatever its proc_name is. So, messages are sent based on process/container identity. That means, once the process is started, the identity does not change, so signing does not need to asynchronously look up credentials.
What is the user of an incoming message? The interceptor will have to do a look up based on the sender-name header in order to verify a signature.
System signature. Use container certificate to sign/validate message.
Need to research more on what other user/security attributes should be included in the message headers. """
#XXX @todo need to be able to properly configure this interceptor #during container startup
""" Get cert path by given id. Read cert file and return cert. """ #bad id
def priv_key(self):
""" Use the system private key to sign the message content. Decorate an outgoing message with a digital signature of the encoded content. Add signature to the message headers. """ except TypeError: # Not sure what to do, being hashable is not really a policy, # so dropping might not be appropriate. Need to raise some kind # of error. invocation.error(note='Error taking hash of content!') return invocation # Do we call invocation.proceed ???
""" If the signature and signer headers are missing, then drop the message. Otherwise, verify the message. """ #hack check of message spec! # Do we call invocation.proceed ??? else: else: invocation.drop('Invalid Message Format') return invocation
|