@@ -64,7 +64,7 @@ protected virtual byte[] DeriveDeviceSecret(byte[] sharedSecret)
64
64
X25519PrivateKeyParameters ? clientPrivateKey = null , bool shouldCompress = false )
65
65
{
66
66
if ( ServerPublicKey == null )
67
- throw new InvalidDataException ( "No server public key provided" ) ;
67
+ throw new InvalidDataException ( "No server public key provided. " ) ;
68
68
69
69
const int headerSize = 0x4 + 0x20 + 0x10 ;
70
70
@@ -186,7 +186,7 @@ private byte[] EncryptMessageInternal(BinaryWriter encryptedWriter, byte[] messa
186
186
using var inputReader = new BinaryReader ( inputStream ) ;
187
187
188
188
if ( inputReader . ReadUInt32 ( ) != HeaderMagic )
189
- throw new InvalidDataException ( "Invalid message header." ) ;
189
+ throw new IOException ( "Invalid message header." ) ;
190
190
191
191
var clientEncPubKey = inputReader . ReadBytes ( 0x20 ) ;
192
192
var expectedChecksum = inputReader . ReadBytes ( 0x10 ) ;
@@ -215,7 +215,7 @@ public byte[] DecryptResponseMessage(byte[] encrypted, byte[] sharedSecret)
215
215
using var inputReader = new BinaryReader ( inputStream ) ;
216
216
217
217
if ( inputReader . ReadUInt32 ( ) != HeaderMagic )
218
- throw new InvalidDataException ( "Invalid message header." ) ;
218
+ throw new IOException ( "Invalid message header." ) ;
219
219
220
220
var iv = inputReader . ReadBytes ( 16 ) ;
221
221
var expectedChecksum = inputReader . ReadBytes ( 16 ) ;
@@ -244,7 +244,7 @@ private byte[] DecryptMessageInternal(byte[] encryptedBody, byte[] key, byte[] i
244
244
var checksum = checksumHash . Hash ! ;
245
245
246
246
if ( ! checksum . SequenceEqual ( expectedChecksum ) )
247
- throw new InvalidDataException ( "Body checksum mismatch." ) ;
247
+ throw new CryptographicException ( "Body checksum mismatch." ) ;
248
248
249
249
var decompressedLength = body [ 0 ] | ( body [ 1 ] << 8 ) | ( body [ 2 ] << 16 ) | ( body [ 3 ] << 24 ) ;
250
250
var bodyData = body . Skip ( 4 ) . ToArray ( ) ;
@@ -285,7 +285,7 @@ public virtual byte[] DecryptVfs(byte[] dbData, bool skipVerification = false)
285
285
var inputReader = new BinaryReader ( inputStream ) ;
286
286
287
287
if ( inputReader . ReadUInt32 ( ) != VfsHeaderMagic )
288
- throw new InvalidDataException ( "Invalid database header." ) ;
288
+ throw new IOException ( "Invalid database header." ) ;
289
289
290
290
return DecryptVfsInternal ( dbData , inputReader , skipVerification , ! skipVerification ? DeriveVfsPublicKey ( VfsCertConstants ) : "" ) ;
291
291
}
@@ -296,7 +296,7 @@ protected static byte[] DecryptVfsInternal(byte[] dbData, BinaryReader inputRead
296
296
var headerSize = fullHeaderSize - headerOffset ;
297
297
298
298
if ( dbData . Length < headerSize )
299
- throw new InvalidDataException ( "Encrypted database too short." ) ;
299
+ throw new IOException ( "Encrypted database too short." ) ;
300
300
301
301
var gcmAdd1 = inputReader . ReadUInt32 ( ) ;
302
302
var gcmKey = inputReader . ReadBytes ( 0x10 ) ;
@@ -310,7 +310,7 @@ protected static byte[] DecryptVfsInternal(byte[] dbData, BinaryReader inputRead
310
310
var encryptedLength = dbData . Length - headerSize ;
311
311
var encryptedData = new byte [ encryptedLength + gcmTag . Length ] ;
312
312
if ( inputReader . Read ( encryptedData , 0 , encryptedLength ) != encryptedLength )
313
- throw new InvalidDataException ( "Failed to read encrypted data from database." ) ;
313
+ throw new IOException ( "Failed to read encrypted data from database." ) ;
314
314
315
315
Buffer . BlockCopy ( gcmTag , 0 , encryptedData , encryptedLength , gcmTag . Length ) ;
316
316
@@ -324,7 +324,7 @@ protected static byte[] DecryptVfsInternal(byte[] dbData, BinaryReader inputRead
324
324
rsa . ImportFromPem ( publicKey ) ;
325
325
var sigResult = rsa . VerifyHash ( signedData , signature , HashAlgorithmName . SHA1 , RSASignaturePadding . Pkcs1 ) ;
326
326
if ( ! sigResult )
327
- throw new InvalidDataException ( "Failed to verify VFS signature." ) ;
327
+ throw new CryptographicException ( "Failed to verify VFS signature." ) ;
328
328
}
329
329
330
330
var gcm = new GcmBlockCipher ( new AesEngine ( ) ) ;
@@ -339,7 +339,7 @@ protected static byte[] DecryptVfsInternal(byte[] dbData, BinaryReader inputRead
339
339
}
340
340
catch ( Exception ex )
341
341
{
342
- throw new InvalidDataException ( $ "Failed to decrypt database: { ex . Message } ") ;
342
+ throw new CryptographicException ( $ "Failed to decrypt database: { ex . Message } ") ;
343
343
}
344
344
345
345
var decompressedLength = decryptedData [ 0 ] | ( decryptedData [ 1 ] << 8 ) | ( decryptedData [ 2 ] << 16 ) | ( decryptedData [ 3 ] << 24 ) ;
0 commit comments