forked from I2P_Developers/i2p.i2p
* 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:
@ -1223,7 +1223,8 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new keypair
|
||||
* Generate a new keypair.
|
||||
* Does NOT support non-default sig types.
|
||||
* Deprecated - only used by CLI
|
||||
*
|
||||
* Sets the event "genkeysResult" = "ok" or "error" after the generation is complete
|
||||
@ -1266,7 +1267,8 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new keypair
|
||||
* Generate a new keypair.
|
||||
* Does NOT support non-default sig types.
|
||||
* Deprecated - only used by CLI
|
||||
*
|
||||
* Sets the event "privateKey" = base64 of the privateKey stream and
|
||||
@ -1275,7 +1277,7 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
* @param l logger to receive events and output
|
||||
*/
|
||||
private static void runGenTextKeys(Logging l) {
|
||||
ByteArrayOutputStream privkey = new ByteArrayOutputStream(512);
|
||||
ByteArrayOutputStream privkey = new ByteArrayOutputStream(1024);
|
||||
ByteArrayOutputStream pubkey = new ByteArrayOutputStream(512);
|
||||
makeKey(privkey, pubkey, l);
|
||||
l.log("Private key: " + Base64.encode(privkey.toByteArray()));
|
||||
@ -1527,10 +1529,11 @@ public class I2PTunnel extends EventDispatcherImpl implements Logging {
|
||||
|
||||
/**
|
||||
* Create a new destination, storing the destination and its private keys where
|
||||
* instructed
|
||||
* instructed.
|
||||
* Does NOT support non-default sig types.
|
||||
* Deprecated - only used by CLI
|
||||
*
|
||||
* @param writeTo location to store the private keys
|
||||
* @param writeTo location to store the destination and private keys
|
||||
* @param pubDest location to store the destination
|
||||
* @param l logger to send messages to
|
||||
*/
|
||||
|
@ -7,11 +7,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.I2PException;
|
||||
import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.crypto.SigType;
|
||||
import net.i2p.data.Base32;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.i2ptunnel.socks.I2PSOCKSTunnel;
|
||||
@ -49,8 +51,8 @@ public class TunnelController implements Logging {
|
||||
* the prefix should be used (and, in turn, that prefix should be stripped off
|
||||
* before being interpreted by this controller)
|
||||
*
|
||||
* @param config original key=value mapping
|
||||
* @param prefix beginning of key values that are relevent to this tunnel
|
||||
* @param config original key=value mapping non-null
|
||||
* @param prefix beginning of key values that are relevant to this tunnel
|
||||
*/
|
||||
public TunnelController(Properties config, String prefix) {
|
||||
this(config, prefix, true);
|
||||
@ -58,6 +60,8 @@ public class TunnelController implements Logging {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param config original key=value mapping non-null
|
||||
* @param prefix beginning of key values that are relevant to this tunnel
|
||||
* @param createKey for servers, whether we want to create a brand new destination
|
||||
* with private keys at the location specified or not (does not
|
||||
* overwrite existing ones)
|
||||
@ -99,7 +103,16 @@ public class TunnelController implements Logging {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new SecureFileOutputStream(keyFile);
|
||||
Destination dest = client.createDestination(fos);
|
||||
SigType stype = I2PClient.DEFAULT_SIGTYPE;
|
||||
String st = _config.getProperty("option." + I2PClient.PROP_SIGTYPE);
|
||||
if (st != null) {
|
||||
SigType type = SigType.parseSigType(st);
|
||||
if (type != null)
|
||||
stype = type;
|
||||
else
|
||||
log("Unsupported sig type " + st);
|
||||
}
|
||||
Destination dest = client.createDestination(fos, stype);
|
||||
String destStr = dest.toBase64();
|
||||
log("Private key created and saved in " + keyFile.getAbsolutePath());
|
||||
log("You should backup this file in a secure place.");
|
||||
|
@ -12,6 +12,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.data.Destination;
|
||||
import net.i2p.i2ptunnel.I2PTunnel;
|
||||
import net.i2p.i2ptunnel.I2PTunnelTask;
|
||||
@ -78,8 +79,17 @@ import net.i2p.util.EventDispatcher;
|
||||
I2PClient client = I2PClientFactory.createClient();
|
||||
byte[] key;
|
||||
try {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
|
||||
client.createDestination(out);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
||||
SigType stype = I2PClient.DEFAULT_SIGTYPE;
|
||||
String st = tunnel.getClientOptions().getProperty(I2PClient.PROP_SIGTYPE);
|
||||
if (st != null) {
|
||||
SigType type = SigType.parseSigType(st);
|
||||
if (type != null)
|
||||
stype = type;
|
||||
else
|
||||
l.log("Unsupported sig type " + st);
|
||||
}
|
||||
client.createDestination(out, stype);
|
||||
key = out.toByteArray();
|
||||
} catch(Exception exc) {
|
||||
throw new RuntimeException("failed to create i2p-destination", exc);
|
||||
|
Reference in New Issue
Block a user