From 3b75edb715b37c98ff918c44e7f96bec8e021e59 Mon Sep 17 00:00:00 2001
From: Vladimir Krivosheev
Date: Thu, 21 Jul 2016 17:21:58 +0200
Subject: [PATCH 01/26] =?UTF-8?q?PasswordSafe=20=E2=80=94=20do=20not=20ask?=
=?UTF-8?q?=20master=20password?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/intellij/mock/MockApplicationEx.java | 7 +-
.../openapi/application/ex/ApplicationEx.java | 3 +-
.../MasterPasswordUnavailableException.java | 25 --
.../passwordSafe/PasswordSafeException.java | 13 -
.../ide/passwordSafe/PasswordStorage.java | 29 +-
.../com/intellij/util/EncryptionSupport.kt | 67 ++++
.../proxy/PropertiesEncryptionSupport.java | 26 +-
.../intellij/ide/ApplicationLoadListener.java | 8 +-
.../config/PasswordSafeConfigurable.java | 28 +-
.../config/PasswordSafeOptionsPanel.form | 37 +-
.../config/PasswordSafeOptionsPanel.java | 42 +--
.../passwordSafe/impl/PasswordSafeImpl.java | 29 +-
.../impl/PasswordSafeProvider.java | 4 -
.../providers/BasePasswordSafeProvider.java | 26 +-
.../impl/providers/EncryptionUtil.java | 17 +-
.../masterKey/ChangePasswordComponent.java | 43 ---
.../masterKey/EnterPasswordComponent.java | 30 +-
.../masterKey/FilePasswordSafeProvider.kt | 182 ++++++++++
.../masterKey/MasterKeyPasswordSafe.java | 335 ------------------
.../masterKey/MasterPasswordDialog.java | 71 +---
.../masterKey/PasswordComponentBase.form | 12 +-
.../masterKey/PasswordComponentBase.java | 36 +-
.../providers/masterKey/PasswordDatabase.java | 221 ++----------
.../masterKey/ResetPasswordComponent.java | 68 ----
.../impl/providers/masterKey/dbV1Convertor.kt | 124 +++++++
.../providers/memory/MemoryPasswordSafe.java | 8 +-
.../impl/providers/nil/NilProvider.java | 13 +-
.../application/impl/ApplicationImpl.java | 14 +-
.../src/META-INF/PlatformExtensions.xml | 2 +
.../masterKey/MasterKeyPasswordSafeTest.java | 48 ---
.../masterKey/MasterPasswordMigrationTest.kt | 93 +++++
.../util/resources/misc/registry.properties | 1 -
.../commands/GitHttpGuiAuthenticator.java | 5 +-
33 files changed, 639 insertions(+), 1028 deletions(-)
delete mode 100644 platform/platform-api/src/com/intellij/ide/passwordSafe/MasterPasswordUnavailableException.java
create mode 100644 platform/platform-api/src/com/intellij/util/EncryptionSupport.kt
delete mode 100644 platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/ChangePasswordComponent.java
create mode 100644 platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/FilePasswordSafeProvider.kt
delete mode 100644 platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java
delete mode 100644 platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/ResetPasswordComponent.java
create mode 100644 platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/dbV1Convertor.kt
delete mode 100644 platform/platform-tests/testSrc/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafeTest.java
create mode 100644 platform/platform-tests/testSrc/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterPasswordMigrationTest.kt
diff --git a/platform/core-impl/src/com/intellij/mock/MockApplicationEx.java b/platform/core-impl/src/com/intellij/mock/MockApplicationEx.java
index 9d53126fbc8e..361371a2eeba 100644
--- a/platform/core-impl/src/com/intellij/mock/MockApplicationEx.java
+++ b/platform/core-impl/src/com/intellij/mock/MockApplicationEx.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
-import java.io.IOException;
public class MockApplicationEx extends MockApplication implements ApplicationEx {
public MockApplicationEx(@NotNull Disposable parentDisposable) {
@@ -43,11 +42,11 @@ public class MockApplicationEx extends MockApplication implements ApplicationEx
}
@Override
- public void load(String path) {
+ public void load(@Nullable String path) {
}
@Override
- public void load() throws IOException {
+ public void load() {
load(null);
}
diff --git a/platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationEx.java b/platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationEx.java
index 8c4c57946bc6..337dd04eb83a 100644
--- a/platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationEx.java
+++ b/platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationEx.java
@@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
-import java.io.IOException;
/**
* @author max
@@ -37,7 +36,7 @@ public interface ApplicationEx extends Application {
*/
void load(@Nullable String configPath);
- void load() throws IOException;
+ void load();
boolean isLoaded();
diff --git a/platform/platform-api/src/com/intellij/ide/passwordSafe/MasterPasswordUnavailableException.java b/platform/platform-api/src/com/intellij/ide/passwordSafe/MasterPasswordUnavailableException.java
deleted file mode 100644
index 5617c9c11072..000000000000
--- a/platform/platform-api/src/com/intellij/ide/passwordSafe/MasterPasswordUnavailableException.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2000-2016 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.ide.passwordSafe;
-
-/**
- * This exception is thrown when master password is not available (process of entering password is cancelled, or IDEA is running headless mode)
- */
-public class MasterPasswordUnavailableException extends RuntimeException {
- public MasterPasswordUnavailableException(String message) {
- super(message);
- }
-}
diff --git a/platform/platform-api/src/com/intellij/ide/passwordSafe/PasswordSafeException.java b/platform/platform-api/src/com/intellij/ide/passwordSafe/PasswordSafeException.java
index 74bdd1902c56..583b457bbfbf 100644
--- a/platform/platform-api/src/com/intellij/ide/passwordSafe/PasswordSafeException.java
+++ b/platform/platform-api/src/com/intellij/ide/passwordSafe/PasswordSafeException.java
@@ -19,10 +19,6 @@ package com.intellij.ide.passwordSafe;
* The exception that is thrown when password safe is not available (unable to ask for master password)
*/
public class PasswordSafeException extends RuntimeException {
- private static final long MIN_INTERVAL = 1000L;
-
- private long myTimeMillis = System.currentTimeMillis();
-
public PasswordSafeException(String message, Throwable cause) {
super(message, cause);
}
@@ -30,13 +26,4 @@ public class PasswordSafeException extends RuntimeException {
public PasswordSafeException(String message) {
super(message);
}
-
- public boolean justHappened() {
- long timeMillis = System.currentTimeMillis();
- if (timeMillis - myTimeMillis < MIN_INTERVAL) {
- myTimeMillis = timeMillis;
- return true;
- }
- return false;
- }
}
diff --git a/platform/platform-api/src/com/intellij/ide/passwordSafe/PasswordStorage.java b/platform/platform-api/src/com/intellij/ide/passwordSafe/PasswordStorage.java
index 7ee62a58cb7f..c8c2431fcb1d 100644
--- a/platform/platform-api/src/com/intellij/ide/passwordSafe/PasswordStorage.java
+++ b/platform/platform-api/src/com/intellij/ide/passwordSafe/PasswordStorage.java
@@ -15,8 +15,6 @@
*/
package com.intellij.ide.passwordSafe;
-import com.intellij.openapi.application.Application;
-import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -28,41 +26,34 @@ public interface PasswordStorage {
/**
* Get password stored in a password safe.
*
- * NB:
- * This method may be called from the background,
- * and it may need to ask user to enter the master password to access the database by calling
- * {@link Application#invokeAndWait(Runnable, ModalityState) invokeAndWait()} to show a modal dialog.
- * So make sure not to call it from the read action.
- * Calling this method from the dispatch thread is allowed.
- *
- * @param project the project, that is used to ask for the master password if this is the first access to password safe
* @param requestor the requestor class
* @param key the key for the password
* @return the stored password or null if the password record was not found or was removed
- * @throws PasswordSafeException if password safe cannot be accessed
- * @throws IllegalStateException if the method is called from the read action.
*/
@Nullable
- String getPassword(@Nullable Project project, @NotNull Class requestor, String key);
+ String getPassword(@Nullable Project project, @Nullable Class requestor, @NotNull String key);
+
+ @Nullable
+ default String getPassword(@NotNull String key) {
+ return getPassword(null, null, key);
+ }
/**
* Remove password stored in a password safe
*
- * @param project the project, that is used to ask for the master password if this is the first access to password safe
* @param requestor the requestor class
* @param key the key for the password
- * @throws PasswordSafeException if password safe cannot be accessed
*/
- void removePassword(@Nullable Project project, @NotNull Class requestor, String key);
+ default void removePassword(@Nullable Project project, @Nullable Class requestor, String key) {
+ storePassword(project, requestor, key, null);
+ }
/**
* Store password in password safe
*
- * @param project the project, that is used to ask for the master password if this is the first access to password safe
* @param requestor the requestor class
* @param key the key for the password
* @param value the value to store
- * @throws PasswordSafeException if password safe cannot be accessed
*/
- void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value);
+ void storePassword(@Nullable Project project, @Nullable Class requestor, String key, @Nullable String value);
}
diff --git a/platform/platform-api/src/com/intellij/util/EncryptionSupport.kt b/platform/platform-api/src/com/intellij/util/EncryptionSupport.kt
new file mode 100644
index 000000000000..c1d664b63de1
--- /dev/null
+++ b/platform/platform-api/src/com/intellij/util/EncryptionSupport.kt
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.util
+
+import java.security.Key
+import java.security.SecureRandom
+import javax.crypto.Cipher
+import javax.crypto.spec.IvParameterSpec
+import javax.crypto.spec.SecretKeySpec
+
+open class EncryptionSupport(private val key: Key = SecretKeySpec(generateAesKey(), "AES")) {
+ open fun encrypt(data: ByteArray) = encrypt(data, key)
+
+ open fun decrypt(data: ByteArray) = decrypt(data, key)
+}
+
+fun generateAesKey(): ByteArray {
+ // http://security.stackexchange.com/questions/14068/why-most-people-use-256-bit-encryption-instead-of-128-bit
+ val bytes = ByteArray(16)
+ SecureRandom().nextBytes(bytes)
+ return bytes
+}
+
+private fun encrypt(msgBytes: ByteArray, key: Key): ByteArray {
+ val ciph = Cipher.getInstance("AES/CBC/PKCS5Padding")
+ ciph.init(Cipher.ENCRYPT_MODE, key)
+ val body = ciph.doFinal(msgBytes)
+ val iv = ciph.iv
+
+ val data = ByteArray(4 + iv.size + body.size)
+
+ val length = body.size
+ data[0] = (length shr 24 and 0xFF).toByte()
+ data[1] = (length shr 16 and 0xFF).toByte()
+ data[2] = (length shr 8 and 0xFF).toByte()
+ data[3] = (length and 0xFF).toByte()
+
+ System.arraycopy(iv, 0, data, 4, iv.size)
+ System.arraycopy(body, 0, data, 4 + iv.size, body.size)
+ return data
+}
+
+private fun decrypt(data: ByteArray, key: Key): ByteArray {
+ var bodyLength = data[0].toInt() and 0xFF.toInt()
+ bodyLength = (bodyLength shl 8) + data[1] and 0xFF
+ bodyLength = (bodyLength shl 8) + data[2] and 0xFF
+ bodyLength = (bodyLength shl 8) + data[3] and 0xFF
+
+ val ivlength = data.size - 4 - bodyLength
+
+ val ciph = Cipher.getInstance("AES/CBC/PKCS5Padding")
+ ciph.init(Cipher.DECRYPT_MODE, key, IvParameterSpec(data, 4, ivlength))
+ return ciph.doFinal(data, 4 + ivlength, bodyLength)
+}
\ No newline at end of file
diff --git a/platform/platform-api/src/com/intellij/util/proxy/PropertiesEncryptionSupport.java b/platform/platform-api/src/com/intellij/util/proxy/PropertiesEncryptionSupport.java
index 0fc4e8478e6d..c186f918633b 100644
--- a/platform/platform-api/src/com/intellij/util/proxy/PropertiesEncryptionSupport.java
+++ b/platform/platform-api/src/com/intellij/util/proxy/PropertiesEncryptionSupport.java
@@ -16,16 +16,13 @@
package com.intellij.util.proxy;
import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.util.EncryptionSupport;
import org.jetbrains.annotations.NotNull;
-import javax.crypto.Cipher;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.security.Key;
-import java.security.SecureRandom;
import java.util.Properties;
/**
@@ -33,25 +30,24 @@ import java.util.Properties;
* Date: 08-Jul-16
*/
public class PropertiesEncryptionSupport {
- private final Key myKey;
+ private final EncryptionSupport myEncryptionSupport;
public PropertiesEncryptionSupport(Key key) {
- myKey = key;
+ myEncryptionSupport = new EncryptionSupport(key);
}
public PropertiesEncryptionSupport() {
- this(generateKey());
- }
-
- public static Key generateKey() {
- final byte[] bytes = new byte[16];
- new SecureRandom().nextBytes(bytes);
- return new SecretKeySpec(bytes, "AES");
+ myEncryptionSupport = new EncryptionSupport();
}
@NotNull
public Properties load(@NotNull File file) throws Exception {
- final byte[] bytes = decrypt(FileUtil.loadFileBytes(file));
+ return load(FileUtil.loadFileBytes(file));
+ }
+
+ @NotNull
+ public Properties load(@NotNull byte[] data) throws Exception {
+ final byte[] bytes = myEncryptionSupport.decrypt(data);
final Properties props = new Properties();
props.load(new ByteArrayInputStream(bytes));
return props;
@@ -61,7 +57,7 @@ public class PropertiesEncryptionSupport {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
props.store(out, comments);
out.close();
- FileUtil.writeToFile(file, encrypt(out.toByteArray()));
+ FileUtil.writeToFile(file, myEncryptionSupport.encrypt(out.toByteArray()));
}
public byte[] encrypt(byte[] bytes) throws Exception {
diff --git a/platform/platform-impl/src/com/intellij/ide/ApplicationLoadListener.java b/platform/platform-impl/src/com/intellij/ide/ApplicationLoadListener.java
index 47b11480857f..fe81280cb51b 100644
--- a/platform/platform-impl/src/com/intellij/ide/ApplicationLoadListener.java
+++ b/platform/platform-impl/src/com/intellij/ide/ApplicationLoadListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,5 +22,9 @@ import org.jetbrains.annotations.NotNull;
public interface ApplicationLoadListener {
ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.ApplicationLoadListener");
- void beforeApplicationLoaded(@NotNull Application application, @NotNull String configPath);
+ default void beforeApplicationLoaded(@NotNull Application application, @NotNull String configPath) {
+ }
+
+ default void beforeComponentsCreated() {
+ }
}
diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/config/PasswordSafeConfigurable.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/config/PasswordSafeConfigurable.java
index b4b9b1a78106..6091b8c5bc3f 100644
--- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/config/PasswordSafeConfigurable.java
+++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/config/PasswordSafeConfigurable.java
@@ -1,6 +1,20 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.intellij.ide.passwordSafe.config;
-import com.intellij.ide.passwordSafe.PasswordSafe;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
@@ -17,10 +31,7 @@ public class PasswordSafeConfigurable implements SearchableConfigurable, Configu
* The settings for the password safe
*/
final PasswordSafeSettings mySettings;
- /**
- * The password safe service
- */
- private final PasswordSafe myPasswordSafe;
+
/**
* The option panel to use
*/
@@ -31,9 +42,8 @@ public class PasswordSafeConfigurable implements SearchableConfigurable, Configu
*
* @param settings the password safe settings
*/
- public PasswordSafeConfigurable(@NotNull PasswordSafeSettings settings, @NotNull PasswordSafe passwordSafe) {
+ public PasswordSafeConfigurable(@NotNull PasswordSafeSettings settings) {
mySettings = settings;
- myPasswordSafe = passwordSafe;
}
/**
@@ -55,9 +65,9 @@ public class PasswordSafeConfigurable implements SearchableConfigurable, Configu
* {@inheritDoc}
*/
public JComponent createComponent() {
- myPanel = new PasswordSafeOptionsPanel(myPasswordSafe);
+ myPanel = new PasswordSafeOptionsPanel();
myPanel.reset(mySettings);
- return myPanel.getRoot(); //To change body of implemented methods use File | Settings | File Templates.
+ return myPanel.getRoot();
}
/**
diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/config/PasswordSafeOptionsPanel.form b/platform/platform-impl/src/com/intellij/ide/passwordSafe/config/PasswordSafeOptionsPanel.form
index b2db444be071..2f1bcd8086e1 100644
--- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/config/PasswordSafeOptionsPanel.form
+++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/config/PasswordSafeOptionsPanel.form
@@ -1,6 +1,6 @@
*
- * @param project the project to use
- * @param requestor
* @return the secret key to use
* @throws PasswordSafeException in case of problems with access to the password database.
* @throws IllegalStateException if the method is called from the read action.
*/
@NotNull
- protected abstract byte[] key(@Nullable Project project, @NotNull Class requestor);
+ protected abstract byte[] key();
@Nullable
- public String getPassword(@Nullable Project project, @NotNull Class requestor, String key) {
- byte[] ct = getEncryptedPassword(dbKey(project, requestor, key));
- return ct == null ? null : EncryptionUtil.decryptText(key(project, requestor), ct);
+ public String getPassword(@Nullable Project project, @Nullable Class requestor, @NotNull String key) {
+ byte[] masterKey = key();
+ byte[] encryptedPassword = getEncryptedPassword(EncryptionUtil.dbKey(masterKey, requestor, key));
+ return encryptedPassword == null ? null : EncryptionUtil.decryptText(masterKey, encryptedPassword);
}
/**
@@ -63,18 +62,17 @@ public abstract class BasePasswordSafeProvider extends PasswordSafeProvider {
/**
* Get database key
*
- * @param project
* @param requestor the requestor class
* @param key the key to use
* @return the key to use for map
*/
@NotNull
- private byte[] dbKey(@Nullable Project project, Class requestor, String key) {
- return EncryptionUtil.dbKey(key(project, requestor), requestor, key);
+ private byte[] dbKey(@Nullable Class requestor, String key) {
+ return EncryptionUtil.dbKey(key(), requestor, key);
}
- public void removePassword(@Nullable Project project, @NotNull Class requester, String key) throws PasswordSafeException {
- byte[] k = dbKey(project, requester, key);
+ public void removePassword(@Nullable Project project, @Nullable Class requestor, String key) throws PasswordSafeException {
+ byte[] k = dbKey(requestor, key);
removeEncryptedPassword(k);
}
@@ -85,9 +83,9 @@ public abstract class BasePasswordSafeProvider extends PasswordSafeProvider {
*/
protected abstract void removeEncryptedPassword(byte[] key);
- public void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value) throws PasswordSafeException {
- byte[] k = dbKey(project, requestor, key);
- byte[] ct = EncryptionUtil.encryptText(key(project, requestor), value);
+ public void storePassword(@Nullable Project project, @Nullable Class requestor, String key, String value) throws PasswordSafeException {
+ byte[] k = dbKey(requestor, key);
+ byte[] ct = EncryptionUtil.encryptText(key(), value);
storeEncryptedPassword(k, ct);
}
diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/EncryptionUtil.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/EncryptionUtil.java
index 35c1ee376eea..986857db1c59 100644
--- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/EncryptionUtil.java
+++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/EncryptionUtil.java
@@ -17,6 +17,7 @@ package com.intellij.ide.passwordSafe.impl.providers;
import com.intellij.openapi.vfs.CharsetToolkit;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
@@ -81,8 +82,8 @@ public class EncryptionUtil {
* @param key the key
* @return the raw key bytes
*/
- static byte[] rawKey(Class requester, String key) {
- return hash(getUTF8Bytes(requester.getName() + "/" + key));
+ static byte[] rawKey(@Nullable Class requester, String key) {
+ return hash(getUTF8Bytes((requester == null ? "" : (requester.getName() + "/")) + key));
}
/**
@@ -105,7 +106,7 @@ public class EncryptionUtil {
* @param password the password to use
* @return the generated key
*/
- public static byte[] genPasswordKey(String password) {
+ public static byte[] genPasswordKey(@NotNull String password) {
return genKey(hash(getUTF8Bytes(password)));
}
@@ -138,7 +139,7 @@ public class EncryptionUtil {
* @return the key to use in the database
*/
@NotNull
- public static byte[] dbKey(@NotNull byte[] password, Class requestor, String key) {
+ public static byte[] dbKey(@NotNull byte[] password, @Nullable Class requestor, String key) {
return encryptKey(password, rawKey(requestor, key));
}
@@ -211,14 +212,6 @@ public class EncryptionUtil {
}
}
-
- /**
- * Encrypt text
- *
- * @param password the secret key to use
- * @param data the bytes to decrypt
- * @return encrypted text
- */
@NotNull
public static String decryptText(byte[] password, byte[] data) {
byte[] plain = decryptData(password, data);
diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/ChangePasswordComponent.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/ChangePasswordComponent.java
deleted file mode 100644
index 6e4ef44c232b..000000000000
--- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/ChangePasswordComponent.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2000-2014 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.ide.passwordSafe.impl.providers.masterKey;
-
-import com.intellij.ide.passwordSafe.HelpID;
-
-/**
- * @author gregsh
- */
-public class ChangePasswordComponent extends PasswordComponentBase {
-
-
- public ChangePasswordComponent(MasterKeyPasswordSafe safe) {
- super(safe, "Change");
- myPromptLabel.setText("Enter the current password and the new password
" +
- "in order to change the master password.");
- }
-
- @Override
- public String getHelpId() {
- return HelpID.CHANGE_PASSWORD;
- }
-
- @Override
- public boolean apply() {
- String o = new String(myPasswordField.getPassword());
- String n = new String(myNewPasswordField.getPassword());
- return mySafe.changeMasterPassword(o, n, myEncryptCheckBox.isSelected());
- }
-}
diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/EnterPasswordComponent.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/EnterPasswordComponent.java
index d5f164c5108a..dc0b91381664 100644
--- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/EnterPasswordComponent.java
+++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/EnterPasswordComponent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,24 +16,34 @@
package com.intellij.ide.passwordSafe.impl.providers.masterKey;
import com.intellij.ide.passwordSafe.HelpID;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
+import java.util.function.Function;
+
/**
* @author gregsh
*/
public class EnterPasswordComponent extends PasswordComponentBase {
+ @NotNull
+ private final Function myPasswordConsumer;
+
+ public EnterPasswordComponent(@NotNull Function passwordConsumer) {
+ super("Enter");
+
+ myPasswordConsumer = passwordConsumer;
- public EnterPasswordComponent(@NotNull MasterKeyPasswordSafe safe, @NotNull Class> requestor) {
- super(safe, "Enter");
- String requestorName = getRequestorTitle(requestor);
myPromptLabel.setText("
Master password is required to unlock the password database.
" +
"The password database will be unlocked during this session
" +
- "for all subsystems.
" +
- "
Requested by: " + requestorName + "");
+ "for all subsystems.