forked from I2P_Developers/i2p.i2p
moved i2cp password to PasswordManager
This commit is contained in:
@ -394,11 +394,12 @@ public class ConfigClientsHandler extends FormHandler {
|
|||||||
if (intfc != null)
|
if (intfc != null)
|
||||||
changes.put(ClientManagerFacadeImpl.PROP_CLIENT_HOST, intfc);
|
changes.put(ClientManagerFacadeImpl.PROP_CLIENT_HOST, intfc);
|
||||||
String user = getJettyString("user");
|
String user = getJettyString("user");
|
||||||
if (user != null)
|
|
||||||
changes.put(ConfigClientsHelper.PROP_USER, user);
|
|
||||||
String pw = getJettyString("pw");
|
String pw = getJettyString("pw");
|
||||||
if (pw != null)
|
if (user != null && pw != null && user.length() > 0 && pw.length() > 0) {
|
||||||
changes.put(ConfigClientsHelper.PROP_PW, pw);
|
ConsolePasswordManager mgr = new ConsolePasswordManager(_context);
|
||||||
|
mgr.saveHash(ConfigClientsHelper.PROP_AUTH, user, pw);
|
||||||
|
addFormNotice(_("Added user {0}", user));
|
||||||
|
}
|
||||||
String mode = getJettyString("mode");
|
String mode = getJettyString("mode");
|
||||||
boolean disabled = "0".equals(mode);
|
boolean disabled = "0".equals(mode);
|
||||||
boolean ssl = "2".equals(mode);
|
boolean ssl = "2".equals(mode);
|
||||||
|
@ -24,8 +24,6 @@ public class ConfigClientsHelper extends HelperBase {
|
|||||||
public static final String PROP_ENABLE_SSL = "i2cp.SSL";
|
public static final String PROP_ENABLE_SSL = "i2cp.SSL";
|
||||||
/** from ClientMessageEventListener */
|
/** from ClientMessageEventListener */
|
||||||
public static final String PROP_AUTH = "i2cp.auth";
|
public static final String PROP_AUTH = "i2cp.auth";
|
||||||
public static final String PROP_USER = "i2cp.username";
|
|
||||||
public static final String PROP_PW = "i2cp.password";
|
|
||||||
|
|
||||||
public ConfigClientsHelper() {}
|
public ConfigClientsHelper() {}
|
||||||
|
|
||||||
@ -35,16 +33,6 @@ public class ConfigClientsHelper extends HelperBase {
|
|||||||
Integer.toString(ClientManagerFacadeImpl.DEFAULT_PORT));
|
Integer.toString(ClientManagerFacadeImpl.DEFAULT_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 0.8.3 */
|
|
||||||
public String getUser() {
|
|
||||||
return _context.getProperty(PROP_USER, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @since 0.8.3 */
|
|
||||||
public String getPw() {
|
|
||||||
return _context.getProperty(PROP_PW, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @since 0.8.3 */
|
/** @since 0.8.3 */
|
||||||
public String i2cpModeChecked(int mode) {
|
public String i2cpModeChecked(int mode) {
|
||||||
boolean disabled = _context.getBooleanProperty(PROP_DISABLE_EXTERNAL);
|
boolean disabled = _context.getBooleanProperty(PROP_DISABLE_EXTERNAL);
|
||||||
|
@ -36,6 +36,7 @@ import net.i2p.data.i2cp.SetDateMessage;
|
|||||||
import net.i2p.router.ClientTunnelSettings;
|
import net.i2p.router.ClientTunnelSettings;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
import net.i2p.util.PasswordManager;
|
||||||
import net.i2p.util.RandomSource;
|
import net.i2p.util.RandomSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,6 +50,8 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
private final ClientConnectionRunner _runner;
|
private final ClientConnectionRunner _runner;
|
||||||
private final boolean _enforceAuth;
|
private final boolean _enforceAuth;
|
||||||
|
|
||||||
|
private static final String PROP_AUTH = "i2cp.auth";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param enforceAuth set false for in-JVM, true for socket access
|
* @param enforceAuth set false for in-JVM, true for socket access
|
||||||
*/
|
*/
|
||||||
@ -169,26 +172,23 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Auth, since 0.8.2
|
// Auth, since 0.8.2
|
||||||
if (_enforceAuth && _context.getBooleanProperty("i2cp.auth")) {
|
if (_enforceAuth && _context.getBooleanProperty(PROP_AUTH)) {
|
||||||
String configUser = _context.getProperty("i2cp.username");
|
|
||||||
String configPW = _context.getProperty("i2cp.password");
|
|
||||||
if (configUser != null && configPW != null) {
|
|
||||||
Properties props = in.getOptions();
|
Properties props = in.getOptions();
|
||||||
String user = props.getProperty("i2cp.username");
|
String user = props.getProperty("i2cp.username");
|
||||||
String pw = props.getProperty("i2cp.password");
|
String pw = props.getProperty("i2cp.password");
|
||||||
if (user == null || pw == null) {
|
if (user == null || user.length() == 0 || pw == null || pw.length() == 0) {
|
||||||
_log.error("I2CP auth failed for client: " + props.getProperty("inbound.nickname"));
|
_log.error("I2CP auth failed for client: " + props.getProperty("inbound.nickname"));
|
||||||
_runner.disconnectClient("Authorization required to create session, specify i2cp.username and i2cp.password in session options");
|
_runner.disconnectClient("Authorization required to create session, specify i2cp.username and i2cp.password in session options");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((!user.equals(configUser)) || (!pw.equals(configPW))) {
|
PasswordManager mgr = new PasswordManager(_context);
|
||||||
|
if (!mgr.checkHash(PROP_AUTH, user, pw)) {
|
||||||
_log.error("I2CP auth failed for client: " + props.getProperty("inbound.nickname") + " user: " + user);
|
_log.error("I2CP auth failed for client: " + props.getProperty("inbound.nickname") + " user: " + user);
|
||||||
_runner.disconnectClient("Authorization failed for Create Session, user = " + user);
|
_runner.disconnectClient("Authorization failed for Create Session, user = " + user);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info("I2CP auth success for client: " + props.getProperty("inbound.nickname") + " user: " + user);
|
_log.info("I2CP auth success for client: " + props.getProperty("inbound.nickname") + " user: " + user);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionId sessionId = new SessionId();
|
SessionId sessionId = new SessionId();
|
||||||
@ -244,9 +244,9 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
|
|||||||
msg.setSessionId(_runner.getSessionId().getSessionId());
|
msg.setSessionId(_runner.getSessionId().getSessionId());
|
||||||
Payload payload = _runner.getPayload(new MessageId(message.getMessageId()));
|
Payload payload = _runner.getPayload(new MessageId(message.getMessageId()));
|
||||||
if (payload == null) {
|
if (payload == null) {
|
||||||
if (_log.shouldLog(Log.ERROR))
|
if (_log.shouldLog(Log.WARN))
|
||||||
_log.error("Payload for message id [" + message.getMessageId()
|
_log.warn("Payload for message id [" + message.getMessageId()
|
||||||
+ "] is null! Unknown message id?");
|
+ "] is null! Dropped or Unknown message id");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msg.setPayload(payload);
|
msg.setPayload(payload);
|
||||||
|
@ -24,7 +24,8 @@ public class RouterPasswordManager extends PasswordManager {
|
|||||||
|
|
||||||
private static final String PROP_MIGRATED = "router.passwordManager.migrated";
|
private static final String PROP_MIGRATED = "router.passwordManager.migrated";
|
||||||
// migrate these to hash
|
// migrate these to hash
|
||||||
private static final String PROP_I2CP_OLD = "i2cp.password";
|
private static final String PROP_I2CP_OLD_PW = "i2cp.password";
|
||||||
|
private static final String PROP_I2CP_OLD_USER = "i2cp.username";
|
||||||
private static final String PROP_I2CP_NEW = "i2cp.auth";
|
private static final String PROP_I2CP_NEW = "i2cp.auth";
|
||||||
/****
|
/****
|
||||||
// migrate these to b64
|
// migrate these to b64
|
||||||
@ -64,11 +65,10 @@ public class RouterPasswordManager extends PasswordManager {
|
|||||||
if (_context.getBooleanProperty(PROP_MIGRATED))
|
if (_context.getBooleanProperty(PROP_MIGRATED))
|
||||||
return true;
|
return true;
|
||||||
// i2cp.password
|
// i2cp.password
|
||||||
String pw = _context.getProperty(PROP_I2CP_OLD);
|
String user = _context.getProperty(PROP_I2CP_OLD_USER);
|
||||||
if (pw != null) {
|
String pw = _context.getProperty(PROP_I2CP_OLD_PW);
|
||||||
if (pw.length() > 0)
|
if (pw != null && user != null && pw.length() > 0 && user.length() > 0) {
|
||||||
saveHash(PROP_I2CP_NEW, null, pw);
|
saveHash(PROP_I2CP_NEW, user, pw);
|
||||||
_context.router().saveConfig(PROP_I2CP_OLD, null);
|
|
||||||
}
|
}
|
||||||
// obfuscation of plaintext passwords
|
// obfuscation of plaintext passwords
|
||||||
Map<String, String> toAdd = new HashMap(5);
|
Map<String, String> toAdd = new HashMap(5);
|
||||||
@ -81,6 +81,8 @@ public class RouterPasswordManager extends PasswordManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
****/
|
****/
|
||||||
|
toDel.add(PROP_I2CP_OLD_USER);
|
||||||
|
toDel.add(PROP_I2CP_OLD_PW);
|
||||||
toAdd.put(PROP_MIGRATED, "true");
|
toAdd.put(PROP_MIGRATED, "true");
|
||||||
return _context.router().saveConfig(toAdd, toDel);
|
return _context.router().saveConfig(toAdd, toDel);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user