Exemple #1
0
def process_letter(l):
    sender       = alias.get_cert(l.attributes['SENDER'],l.attributes['VIA'],False)
    receiver_pub = alias.get_cert(l.attributes['RECEIVER'],l.attributes['VIA'],False)
    receiver_prv = None

    if sender == False or receiver_pub == False:
        raise Exception("Cannot find sender or/and receiver's certificate.")

    outputbuffer = []

    jsons = splitjsons(l.body.strip())
    k = keys.keys()

    for j in jsons:
        try:
            jp = json.loads(j)
        except Exception,e:
            print 'Error decoding json: %s' % e
            continue
        try:
            if   jp['Title'] == 'Intermediate_Key':
                if receiver_prv == None:
                    receiver_prv = alias.get_cert(l.attributes['RECEIVER'],l.attributes['VIA'],True)
                    if receiver_prv == False:
                        raise Exception("Cannot find receiver's private certificate.")
                k.load(jp,sender,receiver_prv)
            elif jp['Title'] == 'Message':
                outputbuffer.append(packager.depackage(k.decrypt(jp)))
        except Exception,e:
            raise Exception("%s" % e)
Exemple #2
0
def process_letter(l):
    sender_pub = alias.get_cert(l.attributes['SENDER'],l.attributes['VIA'],False)
    receiver   = alias.get_cert(l.attributes['RECEIVER'],l.attributes['VIA'],False)

    if sender_pub == False or receiver == False:
        raise Exception("Cannot find sender[%s] or/and receiver[%s]'s certificate." % (l.attributes['SENDER'],l.attributes['RECEIVER']))

    outputbuffer = []

    k = keys.keys()
    do_gen = False

    if not k.find_key(sender_pub,receiver):
        do_gen = True
    elif k.deprecated:
        do_gen = True
    if do_gen:

        sender_prv = alias.get_cert(l.attributes['SENDER'],l.attributes['VIA'],True)
        if sender_prv == False:
            raise Exception("Cannot find sender's private certificate.")
        newkeystr = k.new(sender_prv,receiver,432000,False)
        outputbuffer.append(newkeystr)
    elif k.activated == False and k.deprecated == False and k.exchange_info != '': # Try Key Exchange
        outputbuffer.append(json.dumps(k.exchange_info))

    trans = k.encrypt(packager.package(l.body),False)
    outputbuffer.append(trans)

    return outputbuffer