* Crypto: More implementation for key certs

- Support i2cp.destination.sigType option in TunnelController and
    I2PSocketManagerFactory
  - Fixup of Destination.create() and Destination.size()
  - Add generic off/len methods in DSAEngine, needed for streaming
  - Fixup of sign/verify in streaming Packet
  - Javadocs
This commit is contained in:
zzz
2014-01-03 00:22:44 +00:00
parent 5842e25205
commit e8e239616f
9 changed files with 149 additions and 68 deletions

View File

@@ -14,6 +14,7 @@ import net.i2p.client.I2PClient;
import net.i2p.client.I2PClientFactory;
import net.i2p.client.I2PSession;
import net.i2p.client.I2PSessionException;
import net.i2p.crypto.SigType;
import net.i2p.util.Log;
/**
@@ -26,7 +27,7 @@ public class I2PSocketManagerFactory {
public static final String PROP_MANAGER = "i2p.streaming.manager";
public static final String DEFAULT_MANAGER = "net.i2p.client.streaming.I2PSocketManagerFull";
/**
* Create a socket manager using a brand new destination connected to the
* I2CP router on the local machine on the default port (7654).
@@ -79,9 +80,9 @@ public class I2PSocketManagerFactory {
*/
public static I2PSocketManager createManager(String i2cpHost, int i2cpPort, Properties opts) {
I2PClient client = I2PClientFactory.createClient();
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(512);
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024);
try {
client.createDestination(keyStream);
client.createDestination(keyStream, getSigType(opts));
ByteArrayInputStream in = new ByteArrayInputStream(keyStream.toByteArray());
return createManager(in, i2cpHost, i2cpPort, opts);
} catch (IOException ioe) {
@@ -168,9 +169,9 @@ public class I2PSocketManagerFactory {
int i2cpPort, Properties opts) throws I2PSessionException {
if (myPrivateKeyStream == null) {
I2PClient client = I2PClientFactory.createClient();
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(512);
ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024);
try {
client.createDestination(keyStream);
client.createDestination(keyStream, getSigType(opts));
} catch (Exception e) {
throw new I2PSessionException("Error creating keys", e);
}
@@ -257,6 +258,23 @@ public class I2PSocketManagerFactory {
return i2cpPort;
}
/**
* @param opts may be null
* @since 0.9.11
*/
private static SigType getSigType(Properties opts) {
if (opts != null) {
String st = opts.getProperty(I2PClient.PROP_SIGTYPE);
if (st != null) {
SigType rv = SigType.parseSigType(st);
if (rv != null)
return rv;
getLog().error("Unsupported sig type " + st);
}
}
return I2PClient.DEFAULT_SIGTYPE;
}
/** @since 0.9.7 */
private static Log getLog() {
return I2PAppContext.getGlobalContext().logManager().getLog(I2PSocketManagerFactory.class);