@@ -152,7 +152,8 @@ impl BrowserId {
152152 keychain_service : PlatformStr {
153153 darwin : Some ( "Opera Safe Storage" ) ,
154154 win32 : None ,
155- linux : Some ( "opera" ) ,
155+ // Opera on Linux uses Chromium's default keyring name
156+ linux : Some ( "chromium" ) ,
156157 } ,
157158 } ,
158159 Self :: Vivaldi => BrowserDescriptor {
@@ -170,7 +171,8 @@ impl BrowserId {
170171 keychain_service : PlatformStr {
171172 darwin : Some ( "Vivaldi Safe Storage" ) ,
172173 win32 : None ,
173- linux : Some ( "vivaldi" ) ,
174+ // Vivaldi on Linux uses Chrome's keyring name
175+ linux : Some ( "chrome" ) ,
174176 } ,
175177 } ,
176178 }
@@ -418,9 +420,7 @@ fn get_macos_key_provider(browser: BrowserId) -> Result<KeyProvider> {
418420
419421 // Chromium stores the keychain entry with account = browser name (e.g. "Chrome")
420422 // and service = "Chrome Safe Storage". Specifying both avoids ambiguity.
421- let account = service
422- . strip_suffix ( " Safe Storage" )
423- . unwrap_or ( service) ;
423+ let account = service. strip_suffix ( " Safe Storage" ) . unwrap_or ( service) ;
424424
425425 let output = std:: process:: Command :: new ( "security" )
426426 . args ( [ "find-generic-password" , "-w" , "-a" , account, "-s" , service] )
@@ -761,10 +761,7 @@ fn reencrypt_cookies_db(original_path: &Path, provider: &KeyProvider) -> Result<
761761 // Old Chromium versions (macOS/Windows) stored cookies as plaintext
762762 // without a version prefix. Treat non-v10/v11/v20 data as plaintext.
763763 let is_known_prefix = encrypted_value. len ( ) >= 3
764- && matches ! (
765- & encrypted_value[ ..3 ] ,
766- b"v10" | b"v11" | b"v20"
767- ) ;
764+ && matches ! ( & encrypted_value[ ..3 ] , b"v10" | b"v11" | b"v20" ) ;
768765
769766 let plaintext = if is_known_prefix {
770767 decrypt_cookie (
@@ -1116,8 +1113,7 @@ mod tests {
11161113 #[ test]
11171114 fn ytdlp_linux_v10_peanuts ( ) {
11181115 let key = derive_key ( "peanuts" , 1 ) ;
1119- let encrypted_value: & [ u8 ] =
1120- b"v10\xcc W%\xcd \xe6 \xe6 \x9f M\x22 \x20 \xa7 \xb0 \xca \xe4 \x07 \xd6 " ;
1116+ let encrypted_value: & [ u8 ] = b"v10\xcc W%\xcd \xe6 \xe6 \x9f M\x22 \x20 \xa7 \xb0 \xca \xe4 \x07 \xd6 " ;
11211117 let result =
11221118 decrypt_cookie ( encrypted_value, & key, "" , 0 , CryptoAlgorithm :: Aes128Cbc ) . unwrap ( ) ;
11231119 assert_eq ! ( result, "USD" ) ;
@@ -1136,8 +1132,7 @@ mod tests {
11361132 #[ test]
11371133 fn ytdlp_macos_v10 ( ) {
11381134 let key = derive_key ( "6eIDUdtKAacvlHwBVwvg/Q==" , 1003 ) ;
1139- let encrypted_value: & [ u8 ] =
1140- b"v10\xb3 \xbe \xad \xa1 [\x9f C\xa1 \x98 \xe0 \x9a \x01 \xd9 \xcf \xbf c" ;
1135+ let encrypted_value: & [ u8 ] = b"v10\xb3 \xbe \xad \xa1 [\x9f C\xa1 \x98 \xe0 \x9a \x01 \xd9 \xcf \xbf c" ;
11411136 let result =
11421137 decrypt_cookie ( encrypted_value, & key, "" , 0 , CryptoAlgorithm :: Aes128Cbc ) . unwrap ( ) ;
11431138 assert_eq ! ( result, "2021-06-01-22" ) ;
@@ -1154,16 +1149,25 @@ mod tests {
11541149
11551150 #[ test]
11561151 fn ytdlp_derive_key_peanuts ( ) {
1157- // yt-dlp: pbkdf2_sha1(b'peanuts', b' ' * 16, 1, 16) == b'g\xe1...'
1158- // but Chromium uses salt="saltysalt", not spaces. Verify our derive_key matches.
1159- let key = derive_key ( "peanuts" , 1 ) ;
1160- assert_eq ! ( key. len( ) , 16 ) ;
11611152 // Cross-check: yt-dlp's LinuxChromeCookieDecryptor.derive_key(b'abc')
11621153 // == b'7\xa1\xec\xd4m\xfcA\xc7\xb19Z\xd0\x19\xdcM\x17'
1163- let abc_key = derive_key ( "abc" , 1 ) ;
1154+ let abc_key_linux = derive_key ( "abc" , 1 ) ;
1155+ assert_eq ! (
1156+ abc_key_linux,
1157+ [
1158+ 0x37 , 0xa1 , 0xec , 0xd4 , 0x6d , 0xfc , 0x41 , 0xc7 , 0xb1 , 0x39 , 0x5a , 0xd0 , 0x19 , 0xdc ,
1159+ 0x4d , 0x17
1160+ ]
1161+ ) ;
1162+ // Cross-check: yt-dlp's MacChromeCookieDecryptor.derive_key(b'abc')
1163+ // == b'Y\xe2\xc0\xd0P\xf6\xf4\xe1l\xc1\x8cQ\xcb|\xcdY'
1164+ let abc_key_mac = derive_key ( "abc" , 1003 ) ;
11641165 assert_eq ! (
1165- abc_key,
1166- [ 0x37 , 0xa1 , 0xec , 0xd4 , 0x6d , 0xfc , 0x41 , 0xc7 , 0xb1 , 0x39 , 0x5a , 0xd0 , 0x19 , 0xdc , 0x4d , 0x17 ]
1166+ abc_key_mac,
1167+ [
1168+ 0x59 , 0xe2 , 0xc0 , 0xd0 , 0x50 , 0xf6 , 0xf4 , 0xe1 , 0x6c , 0xc1 , 0x8c , 0x51 , 0xcb , 0x7c ,
1169+ 0xcd , 0x59
1170+ ]
11671171 ) ;
11681172 }
11691173
0 commit comments