11package org .cryptomator .linux .keychain ;
22
3+ import org .cryptomator .integrations .common .OperatingSystem ;
4+ import org .cryptomator .integrations .common .Priority ;
35import org .cryptomator .integrations .keychain .KeychainAccessException ;
46import org .cryptomator .integrations .keychain .KeychainAccessProvider ;
57import org .freedesktop .secret .simple .SimpleCollection ;
68
79import java .io .IOException ;
8- import java .security .AccessControlException ;
910import java .util .List ;
1011import java .util .Map ;
1112
13+ @ Priority (900 )
14+ @ OperatingSystem (OperatingSystem .Value .LINUX )
1215public class SecretServiceKeychainAccess implements KeychainAccessProvider {
1316
1417 private final String LABEL_FOR_SECRET_IN_KEYRING = "Cryptomator" ;
@@ -33,15 +36,21 @@ public boolean isLocked() {
3336 }
3437
3538 @ Override
39+ @ Deprecated
3640 public void storePassphrase (String key , CharSequence passphrase ) throws KeychainAccessException {
41+ storePassphrase (key , null , passphrase );
42+ }
43+
44+ @ Override
45+ public void storePassphrase (String key , String displayName , CharSequence passphrase ) throws KeychainAccessException {
3746 try (SimpleCollection keyring = new SimpleCollection ()) {
3847 List <String > list = keyring .getItems (createAttributes (key ));
3948 if (list == null || list .isEmpty ()) {
4049 keyring .createItem (LABEL_FOR_SECRET_IN_KEYRING , passphrase , createAttributes (key ));
4150 } else {
4251 changePassphrase (key , passphrase );
4352 }
44- } catch (IOException | AccessControlException e ) {
53+ } catch (IOException | SecurityException e ) {
4554 throw new KeychainAccessException ("Storing password failed." , e );
4655 }
4756 }
@@ -55,7 +64,7 @@ public char[] loadPassphrase(String key) throws KeychainAccessException {
5564 } else {
5665 return null ;
5766 }
58- } catch (IOException | AccessControlException e ) {
67+ } catch (IOException | SecurityException e ) {
5968 throw new KeychainAccessException ("Loading password failed." , e );
6069 }
6170 }
@@ -67,19 +76,25 @@ public void deletePassphrase(String key) throws KeychainAccessException {
6776 if (list != null && !list .isEmpty ()) {
6877 keyring .deleteItem (list .get (0 ));
6978 }
70- } catch (IOException | AccessControlException e ) {
79+ } catch (IOException | SecurityException e ) {
7180 throw new KeychainAccessException ("Deleting password failed." , e );
7281 }
7382 }
7483
7584 @ Override
85+ @ Deprecated
7686 public void changePassphrase (String key , CharSequence passphrase ) throws KeychainAccessException {
87+ changePassphrase (key , null , passphrase );
88+ }
89+
90+ @ Override
91+ public void changePassphrase (String key , String displayName , CharSequence passphrase ) throws KeychainAccessException {
7792 try (SimpleCollection keyring = new SimpleCollection ()) {
7893 List <String > list = keyring .getItems (createAttributes (key ));
7994 if (list != null && !list .isEmpty ()) {
8095 keyring .updateItem (list .get (0 ), LABEL_FOR_SECRET_IN_KEYRING , passphrase , createAttributes (key ));
8196 }
82- } catch (IOException | AccessControlException e ) {
97+ } catch (IOException | SecurityException e ) {
8398 throw new KeychainAccessException ("Changing password failed." , e );
8499 }
85100 }
0 commit comments