Add authorization

New PasswordManager methods for use by SAM
This commit is contained in:
zzz
2015-06-26 20:24:15 +00:00
parent 876729c24e
commit 33672e6a86
4 changed files with 48 additions and 7 deletions

View File

@@ -85,6 +85,9 @@ public class SAMBridge implements Runnable, ClientApp {
private static final String PROP_SAM_SSL = "sam.useSSL";
public static final String PROP_TCP_HOST = "sam.tcp.host";
public static final String PROP_TCP_PORT = "sam.tcp.port";
public static final String PROP_AUTH = "sam.auth";
public static final String PROP_PW_PREFIX = "sam.auth.";
public static final String PROP_PW_SUFFIX = ".shash";
protected static final String DEFAULT_TCP_HOST = "127.0.0.1";
protected static final String DEFAULT_TCP_PORT = "7656";

View File

@@ -18,6 +18,7 @@ import java.util.StringTokenizer;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.Log;
import net.i2p.util.PasswordManager;
import net.i2p.util.VersionComparator;
/**
@@ -93,6 +94,20 @@ class SAMHandlerFactory {
SAMHandler.writeString("HELLO REPLY RESULT=NOVERSION\n", s);
return null;
}
if (Boolean.valueOf(i2cpProps.getProperty(SAMBridge.PROP_AUTH))) {
String user = props.getProperty("USER");
String pw = props.getProperty("PASSWORD");
if (user == null || pw == null)
throw new SAMException("USER and PASSWORD required");
String savedPW = i2cpProps.getProperty(SAMBridge.PROP_PW_PREFIX + user + SAMBridge.PROP_PW_SUFFIX);
if (savedPW == null)
throw new SAMException("Authorization failed");
PasswordManager pm = new PasswordManager(I2PAppContext.getGlobalContext());
if (!pm.checkHash(savedPW, pw))
throw new SAMException("Authorization failed");
}
// Let's answer positively
if (!SAMHandler.writeString("HELLO REPLY RESULT=OK VERSION=" + ver + "\n", s))
throw new SAMException("Error writing to socket");