Added read/write config file support.

Configuration request with no value will save the defaultValue provided.
This commit is contained in:
dev
2011-07-01 08:16:26 +00:00
parent 5a0b34889d
commit ad4e96cf4c
3 changed files with 8 additions and 12 deletions

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="java"/>
<classpathentry kind="lib" path="build/I2PControl.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/home/hottuna/Apps/i2p/lib/i2p.jar"/>
<classpathentry kind="lib" path="/home/hottuna/Apps/i2p/lib/org.mortbay.jetty.jar"/>

View File

@ -29,6 +29,8 @@ import sun.misc.BASE64Encoder;
import net.i2p.I2PAppContext;
import net.i2p.crypto.SHA256Generator;
import net.i2p.i2pcontrol.security.jbcrypt.BCrypt;
import net.i2p.i2pcontrol.servlets.configuration.ConfigurationManager;
import net.i2p.util.Log;
/**
@ -36,8 +38,8 @@ import net.i2p.util.Log;
*/
public class SecurityManager {
public final static String CERT_ALIAS = "CA";
private final int HASH_ITERATIONS = 1000;
private final static String SSL_PROVIDER = "SunJSSE";
private final static String DEFAULT_BCRYPT_SALT = "$2a$10$DEBg.V4E4RLrQRaY5IvEKe";
private static String[] SSL_CIPHER_SUITES;
private static KeyStore _ks;
private static Log _log;
@ -98,12 +100,7 @@ public class SecurityManager {
* @return input hashed HASH_ITERATIONS times
*/
public static String getPasswdHash(String pwd){
SHA256Generator hashGen = new SHA256Generator(I2PAppContext.getGlobalContext());
byte[] bytes = pwd.getBytes();
for (int i = 0; i < 1000; i++){
bytes = hashGen.calculateHash(bytes).toByteArray();
}
return new String(bytes);
return BCrypt.hashpw(pwd, ConfigurationManager.getInstance().getConf("hashedPassword", DEFAULT_BCRYPT_SALT));
}
/**

View File

@ -66,7 +66,7 @@ public class JSONRPCServlet extends HttpServlet{
disp = new Dispatcher();
disp.register(new EchoHandler());
disp.register(new StatHandler());
disp.register(new ServerCertHandler());
//disp.register(new ServerCertHandler());
}
@Override
@ -193,15 +193,15 @@ public class JSONRPCServlet extends HttpServlet{
// Reports the method names of the handled requests
public String[] handledRequests() {
return new String[]{"getServerCert"};
return new String[]{"authenticate"};
}
// Processes the requests
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
if (req.getMethod().equals("getServerCert")) {
if (req.getMethod().equals("authenticate")) {
Map outParams = new HashMap();
outParams.put("serverCert", SecurityManager.getBase64Cert());
//outParams.put("token", );
return new JSONRPC2Response(outParams, req.getID());
}
else {