I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 5e5dc35a authored by zzz's avatar zzz
Browse files

moved i2cp password to PasswordManager

parent 24b7b6fa
No related branches found
No related tags found
No related merge requests found
......@@ -394,11 +394,12 @@ public class ConfigClientsHandler extends FormHandler {
if (intfc != null)
changes.put(ClientManagerFacadeImpl.PROP_CLIENT_HOST, intfc);
String user = getJettyString("user");
if (user != null)
changes.put(ConfigClientsHelper.PROP_USER, user);
String pw = getJettyString("pw");
if (pw != null)
changes.put(ConfigClientsHelper.PROP_PW, pw);
if (user != null && pw != null && user.length() > 0 && pw.length() > 0) {
ConsolePasswordManager mgr = new ConsolePasswordManager(_context);
mgr.saveHash(ConfigClientsHelper.PROP_AUTH, user, pw);
addFormNotice(_("Added user {0}", user));
}
String mode = getJettyString("mode");
boolean disabled = "0".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";
/** from ClientMessageEventListener */
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() {}
......@@ -35,16 +33,6 @@ public class ConfigClientsHelper extends HelperBase {
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 */
public String i2cpModeChecked(int mode) {
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.RouterContext;
import net.i2p.util.Log;
import net.i2p.util.PasswordManager;
import net.i2p.util.RandomSource;
/**
......@@ -49,6 +50,8 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
private final ClientConnectionRunner _runner;
private final boolean _enforceAuth;
private static final String PROP_AUTH = "i2cp.auth";
/**
* @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
if (_enforceAuth && _context.getBooleanProperty("i2cp.auth")) {
String configUser = _context.getProperty("i2cp.username");
String configPW = _context.getProperty("i2cp.password");
if (configUser != null && configPW != null) {
if (_enforceAuth && _context.getBooleanProperty(PROP_AUTH)) {
Properties props = in.getOptions();
String user = props.getProperty("i2cp.username");
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"));
_runner.disconnectClient("Authorization required to create session, specify i2cp.username and i2cp.password in session options");
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);
_runner.disconnectClient("Authorization failed for Create Session, user = " + user);
return;
}
if (_log.shouldLog(Log.INFO))
_log.info("I2CP auth success for client: " + props.getProperty("inbound.nickname") + " user: " + user);
}
}
SessionId sessionId = new SessionId();
......@@ -244,9 +244,9 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
msg.setSessionId(_runner.getSessionId().getSessionId());
Payload payload = _runner.getPayload(new MessageId(message.getMessageId()));
if (payload == null) {
if (_log.shouldLog(Log.ERROR))
_log.error("Payload for message id [" + message.getMessageId()
+ "] is null! Unknown message id?");
if (_log.shouldLog(Log.WARN))
_log.warn("Payload for message id [" + message.getMessageId()
+ "] is null! Dropped or Unknown message id");
return;
}
msg.setPayload(payload);
......
......@@ -24,7 +24,8 @@ public class RouterPasswordManager extends PasswordManager {
private static final String PROP_MIGRATED = "router.passwordManager.migrated";
// 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";
/****
// migrate these to b64
......@@ -64,11 +65,10 @@ public class RouterPasswordManager extends PasswordManager {
if (_context.getBooleanProperty(PROP_MIGRATED))
return true;
// i2cp.password
String pw = _context.getProperty(PROP_I2CP_OLD);
if (pw != null) {
if (pw.length() > 0)
saveHash(PROP_I2CP_NEW, null, pw);
_context.router().saveConfig(PROP_I2CP_OLD, null);
String user = _context.getProperty(PROP_I2CP_OLD_USER);
String pw = _context.getProperty(PROP_I2CP_OLD_PW);
if (pw != null && user != null && pw.length() > 0 && user.length() > 0) {
saveHash(PROP_I2CP_NEW, user, pw);
}
// obfuscation of plaintext passwords
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");
return _context.router().saveConfig(toAdd, toDel);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment