Exemple #1
0
 def _authenticateUserPassword(self, password):
     encrypt = self.trailer['/Encrypt'].getObject()
     rev = encrypt['/R'].getObject()
     owner_entry = encrypt['/O'].getObject().original_bytes
     p_entry = encrypt['/P'].getObject()
     id_entry = self.trailer['/ID'].getObject()
     id1_entry = id_entry[0].getObject()
     real_U = encrypt['/U'].getObject().original_bytes
     if rev == 2:
         U, key = _alg34(password, owner_entry, p_entry, id1_entry)
     elif rev >= 3:
         U, key = _alg35(
             password, rev, encrypt["/Length"].getObject() // 8,
             owner_entry, p_entry, id1_entry,
             encrypt.get("/EncryptMetadata",
                         BooleanObject(False)).getObject())
         U, real_U = U[:16], real_U[:16]
     return U == real_U, key
Exemple #2
0
 def _authenticateUserPassword(self, password):
     encrypt = self.trailer['/Encrypt'].getObject()
     rev = encrypt['/R'].getObject()
     owner_entry = encrypt['/O'].getObject().original_bytes
     p_entry = encrypt['/P'].getObject()
     id_entry = self.trailer['/ID'].getObject()
     id1_entry = id_entry[0].getObject()
     real_U = encrypt['/U'].getObject().original_bytes
     if rev == 2:
         U, key = _alg34(password, owner_entry, p_entry, id1_entry)
     elif rev >= 3:
         U, key = _alg35(password, rev,
                         encrypt["/Length"].getObject() // 8, owner_entry,
                         p_entry, id1_entry,
                         encrypt.get("/EncryptMetadata",
                                     BooleanObject(False)).getObject())
         U, real_U = U[:16], real_U[:16]
     return U == real_U, key
Exemple #3
0
 def encrypt(self, user_pwd, owner_pwd=None, use_128bit=True):
     import time
     import random
     if owner_pwd is None:
         owner_pwd = user_pwd
     if use_128bit:
         V = 2
         rev = 3
         keylen = 128 / 8
     else:
         V = 1
         rev = 2
         keylen = 40 / 8
     # permit everything:
     P = -1
     O = ByteStringObject(_alg33(owner_pwd, user_pwd, rev, keylen))
     ID_1 = md5(repr(time.time())).digest()
     ID_2 = md5(repr(random.random())).digest()
     self._ID = ArrayObject(
         (ByteStringObject(ID_1), ByteStringObject(ID_2)))
     if rev == 2:
         U, key = _alg34(user_pwd, O, P, ID_1)
     else:
         assert rev == 3
         U, key = _alg35(user_pwd, rev, keylen, O, P, ID_1, False)
     encrypt = DictionaryObject()
     encrypt[NameObject("/Filter")] = NameObject("/Standard")
     encrypt[NameObject("/V")] = NumberObject(V)
     if V == 2:
         encrypt[NameObject("/Length")] = NumberObject(keylen * 8)
     encrypt[NameObject("/R")] = NumberObject(rev)
     encrypt[NameObject("/O")] = ByteStringObject(O)
     encrypt[NameObject("/U")] = ByteStringObject(U)
     encrypt[NameObject("/P")] = NumberObject(P)
     self._encrypt = self._addObject(encrypt)
     self._encrypt_key = key
Exemple #4
0
 def encrypt(self, user_pwd, owner_pwd=None, use_128bit=True):
     import time
     import random
     if owner_pwd is None:
         owner_pwd = user_pwd
     if use_128bit:
         V = 2
         rev = 3
         keylen = 128 / 8
     else:
         V = 1
         rev = 2
         keylen = 40 / 8
     # permit everything:
     P = -1
     O = ByteStringObject(_alg33(owner_pwd, user_pwd, rev, keylen))
     ID_1 = md5(repr(time.time())).digest()
     ID_2 = md5(repr(random.random())).digest()
     self._ID = ArrayObject((ByteStringObject(ID_1),
                             ByteStringObject(ID_2)))
     if rev == 2:
         U, key = _alg34(user_pwd, O, P, ID_1)
     else:
         assert rev == 3
         U, key = _alg35(user_pwd, rev, keylen, O, P, ID_1, False)
     encrypt = DictionaryObject()
     encrypt[NameObject("/Filter")] = NameObject("/Standard")
     encrypt[NameObject("/V")] = NumberObject(V)
     if V == 2:
         encrypt[NameObject("/Length")] = NumberObject(keylen * 8)
     encrypt[NameObject("/R")] = NumberObject(rev)
     encrypt[NameObject("/O")] = ByteStringObject(O)
     encrypt[NameObject("/U")] = ByteStringObject(U)
     encrypt[NameObject("/P")] = NumberObject(P)
     self._encrypt = self._addObject(encrypt)
     self._encrypt_key = key