Esempio n. 1
0
def pull_message(server,user,secret,messageid,bits=22):
    hc = hashcash.hashcash(user,messageid,bits)
    
    url = "https://%s/pull.php" % server
    post = {'hashcash':hc,'auth':''}
    retrived = curlhttp.http(url,post)
    
    if retrived != '' and retrived != False:
        retrived = find_jsonstr(retrived)
        if retrived == False:
            return False
        try:
            j = json.loads(retrived)
            # figure out the decrypt key.
            decrypt_key = hmac.HMAC(secret,j['keyseed'].strip(),hashlib.sha1).hexdigest()
            # do HMAC check
            wanted_hmac = hmac.HMAC(decrypt_key,j['message'],hashlib.sha1).hexdigest()
            #print "deckey: %s" % decrypt_key
            #print "hmac:   %s" % wanted_hmac
            if wanted_hmac.strip().lower() == j['hmac'].strip().lower():
                j['message'] = aes.decrypt(j['message'],decrypt_key,128)
            else:
                return False
            
        except:
            return False
        return j
    else:
        return False
Esempio n. 2
0
def query_onlinestate(server,username,bits=23):
    hc = hashcash.hashcash(username,username,bits).strip()
    url = "https://%s/online.php" % server
    post = {'hashcash':hc}
    retrived = curlhttp.http(url,post)
    if retrived == False:
        return False
    try:
        return int(retrived.strip())
    except:
        return False
Esempio n. 3
0
def push_message(server,sender,secret,receiver,message,bits=22):
    hc = hashcash.hashcash(sender,receiver,bits).strip()
    secret = str(secret)

    auth = hmac.HMAC(secret,hashlib.sha1(hc).hexdigest().lower(),hashlib.sha512).hexdigest().lower()

    html = StringIO.StringIO()
    url = str("https://%s/push.php" % server)
    
    # encrypt message using SECRET
    message_encrypted = aes.encrypt(message,secret,128)
    message_hmac = hmac.HMAC(secret,message_encrypted,hashlib.sha1).hexdigest()
    
    post = {'hashcash':hc,'message':message_encrypted,'auth':auth,'hmac':message_hmac}
#    print urllib.urlencode(post)
#    exit()
    retrived = curlhttp.http(url,post)

    if retrived == '':
        return False

    return retrived
Esempio n. 4
0
def check_messages_list(server,username,secret,bits=22):
    hc = hashcash.hashcash(username,username,bits).strip()
    hc_sha1 = hashlib.sha1(hc).hexdigest().lower()
    auth = hmac.HMAC(secret,hc_sha1,hashlib.sha512).hexdigest().lower()
    
    url = "https://%s/pull.php" % server
    post = {'hashcash':hc,'auth':auth}
    retrived = curlhttp.http(url,post)

    if retrived != '' and retrived != False:
        try:
            retrived = find_jsonstr(retrived)
            if retrived == False:
                return False
            j = json.loads(retrived)
            seed = j['seed'].strip()
            deckey = hmac.HMAC(secret,seed,hashlib.sha1).hexdigest()
            codes = []
            for c in j['codes']:
                codes.append(victoria_decrypt(c,deckey))
        except Exception,e:
            print "Error: %s" % e
            return False
        return codes