Added support for reading certificates from Base64 encoded strings.
This commit is contained in:
@ -43,9 +43,9 @@ public class JSONInterface{
|
|||||||
int srvPort = _conf.getConf("server-port", 7656);
|
int srvPort = _conf.getConf("server-port", 7656);
|
||||||
String srvTarget = _conf.getConf("server-target", "jsonrpc");
|
String srvTarget = _conf.getConf("server-target", "jsonrpc");
|
||||||
try {
|
try {
|
||||||
srvURL = new URL("http://"+srvHost+":"+srvPort+"/"+srvTarget);
|
srvURL = new URL("https://"+srvHost+":"+srvPort+"/"+srvTarget);
|
||||||
} catch (MalformedURLException e){
|
} catch (MalformedURLException e){
|
||||||
_log.error("Bad URL: http://"+srvHost+":"+srvPort+"/"+srvTarget, e);
|
_log.error("Bad URL: https://"+srvHost+":"+srvPort+"/"+srvTarget, e);
|
||||||
}
|
}
|
||||||
session = new JSONRPC2Session(srvURL);
|
session = new JSONRPC2Session(srvURL);
|
||||||
}
|
}
|
||||||
@ -84,7 +84,6 @@ public class JSONInterface{
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static String getEcho(String str) throws JSONRPC2Error{
|
public static String getEcho(String str) throws JSONRPC2Error{
|
||||||
|
|
||||||
|
|
||||||
JSONRPC2Request req = new JSONRPC2Request("echo", incrNonce());
|
JSONRPC2Request req = new JSONRPC2Request("echo", incrNonce());
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
Map params = new HashMap();
|
Map params = new HashMap();
|
||||||
|
34
src/net/i2p/itoopie/security/CertificateHelper.java
Normal file
34
src/net/i2p/itoopie/security/CertificateHelper.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package net.i2p.itoopie.security;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.CertificateFactory;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
|
||||||
|
|
||||||
|
public class CertificateHelper {
|
||||||
|
|
||||||
|
private static Log _log;
|
||||||
|
|
||||||
|
static {
|
||||||
|
_log = LogFactory.getLog(CertificateHelper.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static X509Certificate certFromBase64(String base64){
|
||||||
|
try {
|
||||||
|
CertificateFactory cf = CertificateFactory.getInstance(CertificateManager.DEFAULT_CERT_SPI);
|
||||||
|
byte[] bytes = Base64.decode(base64);
|
||||||
|
return (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(bytes));
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
_log.fatal("Unable to load service interface provider, " +
|
||||||
|
CertificateManager.DEFAULT_CERT_SPI +
|
||||||
|
" used for reading base64 encoded certificates", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -29,10 +29,10 @@ public class CertificateManager {
|
|||||||
private static final String DEFAULT_KEYSTORE_LOCATION = "key.store";
|
private static final String DEFAULT_KEYSTORE_LOCATION = "key.store";
|
||||||
private static final String DEFAULT_KEYSTORE_PASSWORD = "nut'nfancy";
|
private static final String DEFAULT_KEYSTORE_PASSWORD = "nut'nfancy";
|
||||||
private static final String DEFAULT_KEYSTORE_ALGORITHM = "SunX509";
|
private static final String DEFAULT_KEYSTORE_ALGORITHM = "SunX509";
|
||||||
|
public static final String DEFAULT_CERT_SPI = "X.509";
|
||||||
private static KeyStore _ks;
|
private static KeyStore _ks;
|
||||||
private static Log _log;
|
private static Log _log;
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
_log = LogFactory.getLog(CertificateManager.class);
|
_log = LogFactory.getLog(CertificateManager.class);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user