Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NMS-16943 : De-Sync Bug between Web UI and SCVCLI Command. #7554

Open
wants to merge 1 commit into
base: foundation-2024
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private void loadCredentials() {
@Override
public Credentials getCredentials(String alias) {
loadCredentials();
reMapCredentials();
synchronized (m_credentialsCache) {
return m_credentialsCache.get(alias);
}
Expand Down Expand Up @@ -205,8 +206,9 @@ private static <T extends Serializable> T fromBase64EncodedByteArray(byte[] byte
@Override
public Set<String> getAliases() {
try {
reloadKeyStoreFile();
return Sets.newHashSet(Collections.list(m_keystore.aliases()));
} catch (KeyStoreException e) {
} catch (KeyStoreException | CertificateException | IOException | NoSuchAlgorithmException e) {
throw Throwables.propagate(e);
}
}
Expand All @@ -231,4 +233,30 @@ private static String getKeystorePassword() {
public static JCEKSSecureCredentialsVault defaultScv() {
return new JCEKSSecureCredentialsVault(getKeystoreFilename(), getKeystorePassword());
}

private void reMapCredentials(){
try {
KeyStore.PasswordProtection keyStorePP = new KeyStore.PasswordProtection(m_password);
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");
for (String aliass : getAliases()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aliass should be alias

KeyStore.SecretKeyEntry ske = (KeyStore.SecretKeyEntry) m_keystore.getEntry(aliass, keyStorePP);
if (ske == null) {
continue;
}
PBEKeySpec keySpec = (PBEKeySpec) factory.getKeySpec(ske.getSecretKey(), PBEKeySpec.class);
m_credentialsCache.put(aliass, fromBase64EncodedByteArray(new String(keySpec.getPassword()).getBytes()));
Copy link
Member

@aurang-zeb313 aurang-zeb313 Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_credentialsCache is access by multiple threads need to synchronize the block

}
} catch (KeyStoreException | InvalidKeySpecException | NoSuchAlgorithmException | IOException | ClassNotFoundException | UnrecoverableEntryException e) {
throw Throwables.propagate(e);
}
}
private void reloadKeyStoreFile() throws CertificateException, IOException, NoSuchAlgorithmException {
if (!m_keystoreFile.isFile()) {
m_keystore.load(null, m_password);
} else {
try (InputStream is = new FileInputStream(m_keystoreFile)) {
m_keystore.load(is, m_password);
}
}
}
}
Loading