@@ -159,7 +159,7 @@ def __add_to_keystore__(self, index, key, id):
159
159
else :
160
160
keystore [index ][store_id ] = key .hex ()
161
161
162
- def __encrypt_keys_from_keystore__ (self , index ):
162
+ def __encrypt_keys_from_keystore__ (self , index , plaintext_length = - 1 ):
163
163
keystore = self .setup ['keystore' ]
164
164
password = index [1 ]
165
165
if index [0 ] == KS_OBFUSCATE :
@@ -201,10 +201,14 @@ def __encrypt_keys_from_keystore__(self, index):
201
201
else :
202
202
iv = get_random_bytes (16 )
203
203
cipher = AES .new (kdfkey , AES .MODE_CBC , iv )
204
- # use it to encrypt the AES-256 key
205
- plaintext = json .dumps (keystore [index ]).encode ()
204
+ # use it to encrypt the AES-256 key(s)
205
+ plaintext = json .dumps (keystore [index ])
206
+ # add spaces to plaintext to make keystores indistinguishable
207
+ if len (plaintext ) < plaintext_length :
208
+ plaintext += ' ' * (plaintext_length - len (plaintext ))
209
+ plaintext_encoded = plaintext .encode ()
206
210
# plaintext must be padded to be a multiple of 16 bytes
207
- plaintext_padded = pad (plaintext , 16 , style = 'pkcs7' )
211
+ plaintext_padded = pad (plaintext_encoded , 16 , style = 'pkcs7' )
208
212
ciphertext = cipher .encrypt (plaintext_padded )
209
213
210
214
if iterations > 1 : #don't calculate entropy for obfuscate passwords
@@ -878,17 +882,24 @@ def on_page_context(self, context, page, config, **kwargs):
878
882
if obfuscate_id not in self .setup ['keystore' ][index2 ].keys ():
879
883
self .setup ['keystore' ][index2 ][obfuscate_id ] = keystore [index ][obfuscate_id ]
880
884
885
+ #find longest keystore
886
+ max_keystore_length = 0
887
+ for index in self .setup ['keystore' ]:
888
+ keystore_length = len (json .dumps (self .setup ['keystore' ][index ]))
889
+ if keystore_length > max_keystore_length :
890
+ max_keystore_length = keystore_length
891
+
881
892
# Encrypt all keys to keystore
882
893
# It just encrypts once, but needs to run on every page
883
894
for index in self .setup ['keystore' ]:
884
895
if index [0 ] == KS_OBFUSCATE :
885
896
pass
886
897
elif index [0 ] == KS_PASSWORD :
887
898
if index not in self .setup ['keystore_password' ]:
888
- self .setup ['keystore_password' ][index ] = ';' .join (self .__encrypt_keys_from_keystore__ (index ))
899
+ self .setup ['keystore_password' ][index ] = ';' .join (self .__encrypt_keys_from_keystore__ (index , max_keystore_length ))
889
900
else :
890
901
if index not in self .setup ['keystore_userpass' ]:
891
- self .setup ['keystore_userpass' ][index ] = ';' .join (self .__encrypt_keys_from_keystore__ (index ))
902
+ self .setup ['keystore_userpass' ][index ] = ';' .join (self .__encrypt_keys_from_keystore__ (index , max_keystore_length ))
892
903
893
904
if hasattr (page , 'encryptcontent' ):
894
905
0 commit comments