Skip to content

Commit

Permalink
Merge pull request #257 from ShadelessFox/session-host-alias-message
Browse files Browse the repository at this point in the history
Include host alias instead of the real host in messages and exceptions
  • Loading branch information
mwiede committed Jan 3, 2023
2 parents 579c3a3 + 82ebf9c commit 4353541
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/main/java/com/jcraft/jsch/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -919,25 +919,25 @@ private void checkHost(String chost, int port, KeyExchange kex) throws JSchExcep
if((shkc.equals("ask") || shkc.equals("yes")) &&
(i!=HostKeyRepository.OK) && !insert){
if(shkc.equals("yes")){
throw new JSchException("reject HostKey: "+host);
throw new JSchException("reject HostKey: "+chost);
}
//System.err.println("finger-print: "+key_fprint);
if(userinfo!=null){
boolean foo=userinfo.promptYesNo(
"The authenticity of host '"+host+"' can't be established.\n"+
"The authenticity of host '"+chost+"' can't be established.\n"+
key_type+" key fingerprint is "+key_fprint+".\n"+
"Are you sure you want to continue connecting?"
);
if(!foo){
throw new JSchException("reject HostKey: "+host);
throw new JSchException("reject HostKey: "+chost);
}
insert=true;
}
else{
if(i==HostKeyRepository.NOT_INCLUDED)
throw new JSchException("UnknownHostKey: "+host+". "+key_type+" key fingerprint is "+key_fprint);
throw new JSchException("UnknownHostKey: "+chost+". "+key_type+" key fingerprint is "+key_fprint);
else
throw new JSchException("HostKey has been changed: "+host);
throw new JSchException("HostKey has been changed: "+chost);
}
}

Expand All @@ -955,29 +955,29 @@ private void checkHost(String chost, int port, KeyExchange kex) throws JSchExcep
keys[j].getMarker().equals("@revoked")){
if(userinfo!=null){
userinfo.showMessage(
"The "+ key_type +" host key for "+ host +" is marked as revoked.\n"+
"The "+ key_type +" host key for "+ chost +" is marked as revoked.\n"+
"This could mean that a stolen key is being used to "+
"impersonate this host.");
}
if(getLogger().isEnabled(Logger.INFO)){
getLogger().log(Logger.INFO,
"Host '"+host+"' has provided revoked key.");
"Host '"+chost+"' has provided revoked key.");
}
throw new JSchException("revoked HostKey: "+host);
throw new JSchException("revoked HostKey: "+chost);
}
}
}

if(i==HostKeyRepository.OK &&
getLogger().isEnabled(Logger.INFO)){
getLogger().log(Logger.INFO,
"Host '"+host+"' is known and matches the "+key_type+" host key");
"Host '"+chost+"' is known and matches the "+key_type+" host key");
}

if(insert &&
getLogger().isEnabled(Logger.WARN)){
getLogger().log(Logger.WARN,
"Permanently added '"+host+"' ("+key_type+") to the list of known hosts.");
"Permanently added '"+chost+"' ("+key_type+") to the list of known hosts.");
}

if(insert){
Expand Down

0 comments on commit 4353541

Please sign in to comment.