[
https://issues.apache.org/jira/browse/SSHD-982?focusedWorklogId=425723&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-425723
]
ASF GitHub Bot logged work on SSHD-982:
---------------------------------------
Author: ASF GitHub Bot
Created on: 21/Apr/20 14:50
Start Date: 21/Apr/20 14:50
Worklog Time Spent: 10m
Work Description: lgoldstein commented on a change in pull request #124:
URL: https://github.com/apache/mina-sshd/pull/124#discussion_r412253325
##########
File path:
sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java
##########
@@ -153,35 +153,43 @@ public void
setModifiedServerKeyAcceptor(ModifiedServerKeyAcceptor acceptor) {
@Override
public boolean verifyServerKey(ClientSession clientSession, SocketAddress
remoteAddress, PublicKey serverKey) {
- Collection<HostEntryPair> knownHosts = getLoadedHostsEntries();
try {
if (checkReloadRequired()) {
Path file = getPath();
if (exists()) {
- knownHosts = reloadKnownHosts(clientSession, file);
+ updateReloadAttributes();
+ keysSupplier =
GenericUtils.memoizeLock(getKnownHostSupplier(clientSession, file));
Review comment:
Update of keysSupplier field is not mutually exclusive...
##########
File path:
sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java
##########
@@ -153,35 +153,43 @@ public void
setModifiedServerKeyAcceptor(ModifiedServerKeyAcceptor acceptor) {
@Override
public boolean verifyServerKey(ClientSession clientSession, SocketAddress
remoteAddress, PublicKey serverKey) {
- Collection<HostEntryPair> knownHosts = getLoadedHostsEntries();
try {
if (checkReloadRequired()) {
Path file = getPath();
if (exists()) {
- knownHosts = reloadKnownHosts(clientSession, file);
+ updateReloadAttributes();
+ keysSupplier =
GenericUtils.memoizeLock(getKnownHostSupplier(clientSession, file));
} else {
if (log.isDebugEnabled()) {
log.debug("verifyServerKey({})[{}] missing known hosts
file {}",
clientSession, remoteAddress, file);
}
- knownHosts = Collections.emptyList();
+ keysSupplier =
GenericUtils.memoizeLock(Collections::emptyList);
}
-
- setLoadedHostsEntries(knownHosts);
}
} catch (Throwable t) {
return acceptIncompleteHostKeys(clientSession, remoteAddress,
serverKey, t);
}
+ Collection<HostEntryPair> knownHosts = keysSupplier.get();
+
return acceptKnownHostEntries(clientSession, remoteAddress, serverKey,
knownHosts);
}
- protected Collection<HostEntryPair> getLoadedHostsEntries() {
- return keysHolder.get();
+ protected Supplier<Collection<HostEntryPair>>
getKnownHostSupplier(ClientSession clientSession, Path file) {
+ return () -> {
+ try {
+ return reloadKnownHosts(clientSession, file);
+ } catch (Exception e) {
+ log.warn("verifyServerKey({}) Could not reload known hosts
file {}",
+ clientSession, file, e);
+ return Collections.emptyList();
+ }
+ };
}
protected void setLoadedHostsEntries(Collection<HostEntryPair> keys) {
- keysHolder.set(keys);
+ keysSupplier = () -> keys;
Review comment:
Update of keysSupplier field is not mutually exclusive...
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 425723)
Time Spent: 0.5h (was: 20m)
> Race condition when loading known hosts
> ---------------------------------------
>
> Key: SSHD-982
> URL: https://issues.apache.org/jira/browse/SSHD-982
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 2.4.0
> Reporter: FliegenKLATSCH
> Priority: Minor
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> When multiple (client) connections are instantiated in parallel the loaded
> known hosts collection might be empty and therefore host key verification
> fails.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]