Ejemplo n.º 1
0
def send_beaker_encrypt(validate_key, add, payload, encrypt_key):
    from beaker import crypto #yes we need it, will port it when we have time
    nonce = '12345678' #anything 8 bytes
    encrypt_key = crypto.generateCryptoKeys(encrypt_key, validate_key + nonce, 1)
    data = nonce + b64(crypto.aesEncrypt(payload, encrypt_key))
    mac = hmac(validate_key, data.encode('UTF-8'), hashlib.sha1).hexdigest()
    s = mac + data
    print requests.get(add, cookies={'beaker.session.id':s})
Ejemplo n.º 2
0
 def _encrypt_data(self):
     """Serialize, encipher, and base64 the session dict"""
     if self.encrypt_key:
         nonce = b64encode(os.urandom(40))[:8]
         encrypt_key = crypto.generateCryptoKeys(self.encrypt_key, self.validate_key + nonce, 1)
         data = pickle.dumps(self.copy(), 2)
         return nonce + b64encode(crypto.aesEncrypt(data, encrypt_key))
     else:
         data = pickle.dumps(self.copy(), 2)
         return b64encode(data)
Ejemplo n.º 3
0
 def _encrypt_data(self):
     """Serialize, encipher, and base64 the session dict"""
     if self.encrypt_key:
         nonce = b64encode(os.urandom(40))[:8]
         encrypt_key = generateCryptoKeys(self.encrypt_key,
                                          self.validate_key + nonce, 1)
         data = cPickle.dumps(self.copy(), 2)
         return nonce + b64encode(aesEncrypt(data, encrypt_key))
     else:
         data = cPickle.dumps(self.copy(), 2)
         return b64encode(data)
Ejemplo n.º 4
0
    def _encrypt_data(self, session_data=None):
        """Serialize, encipher, and base64 the session dict"""
        session_data = session_data or self.copy()
        if self.encrypt_key:
            nonce = b64encode(os.urandom(6))[:8]
            encrypt_key = crypto.generateCryptoKeys(self.encrypt_key,
                                             self.validate_key + nonce, 1)
            data = util.pickle.dumps(session_data, 2)
            return nonce + b64encode(crypto.aesEncrypt(data, encrypt_key))
        else:
	    return b64encode(util.pickle.dumps(session_data))
Ejemplo n.º 5
0
 def _encrypt_data(self, session_data=None):
     """Serialize, encipher, and base64 the session dict"""
     session_data = session_data or self.copy()
     if self.encrypt_key:
         nonce = b64encode(os.urandom(40))[:8]
         encrypt_key = crypto.generateCryptoKeys(self.encrypt_key,
                                          self.validate_key + nonce, 1)
         data = util.pickle.dumps(session_data, 2)
         return nonce + b64encode(crypto.aesEncrypt(data, encrypt_key))
     else:
         data = util.pickle.dumps(session_data, 2)
         return b64encode(data)
Ejemplo n.º 6
0
 def _encrypt_data(self, session_data=None):
     """Serialize, encipher, and base64 the session dict"""
     session_data = session_data or self.copy()
     if self.encrypt_key:
         nonce_len, nonce_b64len = self.encrypt_nonce_size
         nonce = b64encode(os.urandom(nonce_len))[:nonce_b64len]
         encrypt_key = crypto.generateCryptoKeys(self.encrypt_key,
                                                 self.validate_key + nonce, 1)
         data = self.serializer.dumps(session_data)
         return nonce + b64encode(crypto.aesEncrypt(data, encrypt_key))
     else:
         data = self.serializer.dumps(session_data)
         return b64encode(data)
Ejemplo n.º 7
0
 def _decrypt_data(self):
     """Bas64, decipher, then un-serialize the data for the session
     dict"""
     if self.encrypt_key:
         nonce = self.cookie[self.key].value[:8]
         encrypt_key = generateCryptoKeys(self.encrypt_key,
                                          self.validate_key + nonce, 1)
         payload = b64decode(self.cookie[self.key].value[8:])
         data = aesEncrypt(payload, encrypt_key)
         return cPickle.loads(data)
     else:
         data = b64decode(self.cookie[self.key].value)
         return cPickle.loads(data)