@@ -96,6 +96,7 @@ def version=(version)
9696 ##
9797 # This function adds cryptographic settings to the AppleNoteEmbeddedObject.
9898 def add_cryptographic_settings
99+ @crypto_password = @note . crypto_password
99100 unapplied_encrypted_record_column = "ZUNAPPLIEDENCRYPTEDRECORD"
100101 unapplied_encrypted_record_column = unapplied_encrypted_record_column + "DATA" if @version >= AppleNoteStoreVersion ::IOS_VERSION_18
101102
@@ -107,8 +108,20 @@ def add_cryptographic_settings
107108 "WHERE Z_PK=?" ,
108109 @primary_key ) do |row |
109110
111+ @crypto_iv = row [ "ZCRYPTOINITIALIZATIONVECTOR" ]
112+ @crypto_tag = row [ "ZCRYPTOTAG" ]
113+ @crypto_salt = row [ "ZCRYPTOSALT" ]
114+ @crypto_iterations = row [ "ZCRYPTOITERATIONCOUNT" ]
115+ @crypto_key = row [ "ZCRYPTOVERIFIER" ] if row [ "ZCRYPTOVERIFIER" ]
116+ @crypto_key = row [ "ZCRYPTOWRAPPEDKEY" ] if row [ "ZCRYPTOWRAPPEDKEY" ]
117+
118+ correct_settings = @backup . decrypter . check_cryptographic_settings ( @crypto_password ,
119+ @crypto_salt ,
120+ @crypto_iterations ,
121+ @crypto_key )
122+
110123 # If there is a blob in ZUNAPPLIEDENCRYPTEDRECORD, we need to use it instead of the database values
111- if row [ unapplied_encrypted_record_column ]
124+ if row [ unapplied_encrypted_record_column ] and ! correct_settings
112125 keyed_archive = KeyedArchive . new ( :data => row [ unapplied_encrypted_record_column ] )
113126 unpacked_top = keyed_archive . unpacked_top ( )
114127 ns_keys = unpacked_top [ "root" ] [ "ValueStore" ] [ "RecordValues" ] [ "NS.keys" ]
@@ -118,17 +131,9 @@ def add_cryptographic_settings
118131 @crypto_salt = ns_values [ ns_keys . index ( "CryptoSalt" ) ]
119132 @crypto_iterations = ns_values [ ns_keys . index ( "CryptoIterationCount" ) ]
120133 @crypto_key = ns_values [ ns_keys . index ( "CryptoWrappedKey" ) ]
121- else
122- @crypto_iv = row [ "ZCRYPTOINITIALIZATIONVECTOR" ]
123- @crypto_tag = row [ "ZCRYPTOTAG" ]
124- @crypto_salt = row [ "ZCRYPTOSALT" ]
125- @crypto_iterations = row [ "ZCRYPTOITERATIONCOUNT" ]
126- @crypto_key = row [ "ZCRYPTOVERIFIER" ] if row [ "ZCRYPTOVERIFIER" ]
127- @crypto_key = row [ "ZCRYPTOWRAPPEDKEY" ] if row [ "ZCRYPTOWRAPPEDKEY" ]
128134 end
129135 end
130136
131- @crypto_password = @note . crypto_password
132137 end
133138
134139 ##
0 commit comments