mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
OneTimeString — do not clear on set
This commit is contained in:
@@ -46,7 +46,7 @@ internal class KeyChainCredentialStore() : CredentialStore {
|
||||
return
|
||||
}
|
||||
|
||||
val password = credentials!!.password!!.toByteArray()
|
||||
val password = credentials!!.password!!.toByteArray(false)
|
||||
saveGenericPassword(attributes.serviceName.toByteArray(), attributes.userName ?: credentials.userName, password, password.size)
|
||||
password.fill(0)
|
||||
}
|
||||
|
||||
@@ -86,13 +86,16 @@ class OneTimeString(value: CharArray, offset: Int = 0, length: Int = value.size)
|
||||
}
|
||||
|
||||
// string will be cleared and not valid after
|
||||
fun toByteArray(): ByteArray {
|
||||
if (!consumed.compareAndSet(false, true)) {
|
||||
@JvmOverloads
|
||||
fun toByteArray(clear: Boolean = true): ByteArray {
|
||||
if (clear && !consumed.compareAndSet(false, true)) {
|
||||
throw Error("Already consumed")
|
||||
}
|
||||
|
||||
val result = Charsets.UTF_8.encode(CharBuffer.wrap(myChars, myStart, length))
|
||||
myChars.fill('\u0000', myStart, myEnd)
|
||||
if (clear) {
|
||||
myChars.fill('\u0000', myStart, myEnd)
|
||||
}
|
||||
return result.toByteArray()
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -43,11 +43,11 @@ public abstract class BasePasswordSafeProvider implements PasswordStorage {
|
||||
|
||||
public final void set(@NotNull CredentialAttributes attributes, @Nullable Credentials value) {
|
||||
byte[] key = EncryptionUtil.encryptKey(key(), EncryptionUtil.rawKey(attributes));
|
||||
if (value == null) {
|
||||
if (value == null || value.getPassword() == null) {
|
||||
removeEncryptedPassword(key);
|
||||
}
|
||||
else {
|
||||
storeEncryptedPassword(key, EncryptionUtil.encryptText(key(), value == null ? null : value.getPassword()));
|
||||
storeEncryptedPassword(key, EncryptionUtil.encryptText(key(), value.getPassword()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -171,7 +171,7 @@ public class EncryptionUtil {
|
||||
* @return encrypted text
|
||||
*/
|
||||
public static byte[] encryptText(byte[] password, @NotNull OneTimeString value) {
|
||||
byte[] data = value.toByteArray();
|
||||
byte[] data = value.toByteArray(false);
|
||||
return encryptData(password, data.length, data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user