Skip to content

Commit

Permalink
Format java files in o.e.equinox.security.win32.x86_64
Browse files Browse the repository at this point in the history
This was achieved by running:
eclipse -consolelog -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \
  -config .settings/org.eclipse.jdt.core.prefs . -data `mktemp -d`

Signed-off-by: Torbjörn SVENSSON <[email protected]>
  • Loading branch information
Torbjorn-Svensson committed Oct 1, 2023
1 parent 0ee6304 commit 17a90d2
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class WinCrypto extends PasswordProvider {
static {
System.loadLibrary("jnicrypt64");
}

private final static String WIN_PROVIDER_NODE = "/org.eclipse.equinox.secure.storage/windows64";
private final static String PASSWORD_KEY = "encryptedPassword";

Expand All @@ -56,22 +56,23 @@ public PBEKeySpec getPassword(IPreferencesContainer container, int passwordType)
encryptedPassword = getEncryptedPassword(container);
else
encryptedPassword = null;

if (encryptedPassword != null) {
byte[] decryptedPassword = windecrypt(encryptedPassword);
if (decryptedPassword != null) {
String password = new String(decryptedPassword);
return new PBEKeySpec(password.toCharArray());
} else {
StorageException e = new StorageException(StorageException.ENCRYPTION_ERROR, WinCryptoMessages.decryptPasswordFailed);
StorageException e = new StorageException(StorageException.ENCRYPTION_ERROR,
WinCryptoMessages.decryptPasswordFailed);
AuthPlugin.getDefault().logError(WinCryptoMessages.decryptPasswordFailed, e);
return null;
}
}

// add info message in the log
AuthPlugin.getDefault().logMessage(WinCryptoMessages.newPasswordGenerated);

byte[] rawPassword = new byte[PASSWORD_LENGTH];
SecureRandom random = new SecureRandom();
random.setSeed(System.currentTimeMillis());
Expand All @@ -85,7 +86,7 @@ public PBEKeySpec getPassword(IPreferencesContainer container, int passwordType)

private byte[] getEncryptedPassword(IPreferencesContainer container) {
ISecurePreferences node = container.getPreferences().node(WIN_PROVIDER_NODE);
String passwordHint;
String passwordHint;
try {
passwordHint = node.get(PASSWORD_KEY, null);
} catch (StorageException e) { // should never happen in this scenario
Expand All @@ -97,10 +98,11 @@ private byte[] getEncryptedPassword(IPreferencesContainer container) {
return Base64.decode(passwordHint);
}

private boolean savePassword(String password, IPreferencesContainer container){
private boolean savePassword(String password, IPreferencesContainer container) {
byte[] data = winencrypt(password.getBytes());
if (data == null) { // this is bad. Something wrong with OS or JNI.
StorageException e = new StorageException(StorageException.ENCRYPTION_ERROR, WinCryptoMessages.encryptPasswordFailed);
StorageException e = new StorageException(StorageException.ENCRYPTION_ERROR,
WinCryptoMessages.encryptPasswordFailed);
AuthPlugin.getDefault().logError(WinCryptoMessages.encryptPasswordFailed, e);
return false;
}
Expand All @@ -125,7 +127,8 @@ private boolean savePassword(String password, IPreferencesContainer container){
public boolean retryOnError(Exception e, IPreferencesContainer container) {
// It would be rather dangerous to allow this password to be changed
// as it would permanently trash all entries in the secure storage.
// Rather applications using get...() should handle exceptions and offer to overwrite
// Rather applications using get...() should handle exceptions and offer to
// overwrite
// data on an entry-by-entry scale.
return false;
}
Expand Down

0 comments on commit 17a90d2

Please sign in to comment.