1
1
package org .cryptomator .linux .keychain ;
2
2
3
+ import org .cryptomator .integrations .common .OperatingSystem ;
4
+ import org .cryptomator .integrations .common .Priority ;
3
5
import org .cryptomator .integrations .keychain .KeychainAccessException ;
4
6
import org .cryptomator .integrations .keychain .KeychainAccessProvider ;
5
7
import org .freedesktop .secret .simple .SimpleCollection ;
6
8
7
9
import java .io .IOException ;
8
- import java .security .AccessControlException ;
9
10
import java .util .List ;
10
11
import java .util .Map ;
11
12
13
+ @ Priority (900 )
14
+ @ OperatingSystem (OperatingSystem .Value .LINUX )
12
15
public class SecretServiceKeychainAccess implements KeychainAccessProvider {
13
16
14
17
private final String LABEL_FOR_SECRET_IN_KEYRING = "Cryptomator" ;
@@ -33,15 +36,21 @@ public boolean isLocked() {
33
36
}
34
37
35
38
@ Override
39
+ @ Deprecated
36
40
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 {
37
46
try (SimpleCollection keyring = new SimpleCollection ()) {
38
47
List <String > list = keyring .getItems (createAttributes (key ));
39
48
if (list == null || list .isEmpty ()) {
40
49
keyring .createItem (LABEL_FOR_SECRET_IN_KEYRING , passphrase , createAttributes (key ));
41
50
} else {
42
51
changePassphrase (key , passphrase );
43
52
}
44
- } catch (IOException | AccessControlException e ) {
53
+ } catch (IOException | SecurityException e ) {
45
54
throw new KeychainAccessException ("Storing password failed." , e );
46
55
}
47
56
}
@@ -55,7 +64,7 @@ public char[] loadPassphrase(String key) throws KeychainAccessException {
55
64
} else {
56
65
return null ;
57
66
}
58
- } catch (IOException | AccessControlException e ) {
67
+ } catch (IOException | SecurityException e ) {
59
68
throw new KeychainAccessException ("Loading password failed." , e );
60
69
}
61
70
}
@@ -67,19 +76,25 @@ public void deletePassphrase(String key) throws KeychainAccessException {
67
76
if (list != null && !list .isEmpty ()) {
68
77
keyring .deleteItem (list .get (0 ));
69
78
}
70
- } catch (IOException | AccessControlException e ) {
79
+ } catch (IOException | SecurityException e ) {
71
80
throw new KeychainAccessException ("Deleting password failed." , e );
72
81
}
73
82
}
74
83
75
84
@ Override
85
+ @ Deprecated
76
86
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 {
77
92
try (SimpleCollection keyring = new SimpleCollection ()) {
78
93
List <String > list = keyring .getItems (createAttributes (key ));
79
94
if (list != null && !list .isEmpty ()) {
80
95
keyring .updateItem (list .get (0 ), LABEL_FOR_SECRET_IN_KEYRING , passphrase , createAttributes (key ));
81
96
}
82
- } catch (IOException | AccessControlException e ) {
97
+ } catch (IOException | SecurityException e ) {
83
98
throw new KeychainAccessException ("Changing password failed." , e );
84
99
}
85
100
}
0 commit comments