forked from I2P_Developers/i2p.i2p
Tunnels: Improved logging and handling of offline signature expiration
Store back ref to controller in tunnel Stop server controller on I2PException Support generation of keys with fractional days expiration for testing
This commit is contained in:
@@ -150,8 +150,11 @@ class I2CPMessageProducer {
|
||||
cfg.setOptions(p);
|
||||
if (isOffline) {
|
||||
long exp = session.getOfflineExpiration();
|
||||
if (exp < _context.clock().now())
|
||||
throw new I2PSessionException("Offline signature expired " + DataHelper.formatTime(exp));
|
||||
if (exp < _context.clock().now()) {
|
||||
String s = "Offline signature for tunnel expired " + DataHelper.formatTime(exp);
|
||||
_log.log(Log.CRIT, s);
|
||||
throw new I2PSessionException(s);
|
||||
}
|
||||
cfg.setOfflineSignature(exp,
|
||||
session.getTransientSigningPublicKey(),
|
||||
session.getOfflineSignature());
|
||||
@@ -218,7 +221,7 @@ class I2CPMessageProducer {
|
||||
msg.setDestination(dest);
|
||||
SessionId sid = session.getSessionId();
|
||||
if (sid == null) {
|
||||
_log.error(session.toString() + " send message w/o session", new Exception());
|
||||
_log.error(session.toString() + " cannot send message, session closed", new Exception());
|
||||
return;
|
||||
}
|
||||
msg.setSessionId(sid);
|
||||
@@ -245,7 +248,7 @@ class I2CPMessageProducer {
|
||||
msg.setDestination(dest);
|
||||
SessionId sid = session.getSessionId();
|
||||
if (sid == null) {
|
||||
_log.error(session.toString() + " send message w/o session", new Exception());
|
||||
_log.error(session.toString() + " cannot send message, session closed", new Exception());
|
||||
return;
|
||||
}
|
||||
msg.setSessionId(sid);
|
||||
@@ -412,7 +415,7 @@ class I2CPMessageProducer {
|
||||
msg.setLeaseSet(leaseSet);
|
||||
SessionId sid = session.getSessionId();
|
||||
if (sid == null) {
|
||||
_log.error(session.toString() + " create LS w/o session", new Exception());
|
||||
_log.error(session.toString() + " cannot create LS, session closed", new Exception());
|
||||
return;
|
||||
}
|
||||
msg.setSessionId(sid);
|
||||
@@ -444,7 +447,7 @@ class I2CPMessageProducer {
|
||||
msg.setSessionConfig(cfg);
|
||||
SessionId sid = session.getSessionId();
|
||||
if (sid == null) {
|
||||
_log.error(session.toString() + " update config w/o session", new Exception());
|
||||
_log.error(session.toString() + " cannot update config, session closed", new Exception());
|
||||
return;
|
||||
}
|
||||
msg.setSessionId(sid);
|
||||
|
||||
@@ -326,10 +326,16 @@ class RequestLeaseSetMessageHandler extends HandlerImpl {
|
||||
// offline keys
|
||||
if (session.isOffline()) {
|
||||
LeaseSet2 ls2 = (LeaseSet2) leaseSet;
|
||||
boolean ok = ls2.setOfflineSignature(session.getOfflineExpiration(), session.getTransientSigningPublicKey(),
|
||||
long exp = session.getOfflineExpiration();
|
||||
boolean ok = ls2.setOfflineSignature(exp, session.getTransientSigningPublicKey(),
|
||||
session.getOfflineSignature());
|
||||
if (!ok) {
|
||||
session.propogateError("Bad offline signature", new Exception());
|
||||
String s;
|
||||
if (exp <= _context.clock().now())
|
||||
s = "Offline signature for tunnel expired " + DataHelper.formatTime(exp);
|
||||
else
|
||||
s = "Bad offline signature";
|
||||
session.propogateError(s, new Exception());
|
||||
session.destroySession();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class PrivateKeyFile {
|
||||
String signername = null;
|
||||
String signaction = null;
|
||||
String certfile = null;
|
||||
int days = 365;
|
||||
double days = 365;
|
||||
int mode = 0;
|
||||
boolean error = false;
|
||||
Getopt g = new Getopt("pkf", args, "t:nuxhse:c:a:o:d:r:p:b:y:z:w:");
|
||||
@@ -178,7 +178,7 @@ public class PrivateKeyFile {
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
days = Integer.parseInt(g.getOptarg());
|
||||
days = Double.parseDouble(g.getOptarg());
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
@@ -344,7 +344,7 @@ public class PrivateKeyFile {
|
||||
SigningPublicKey tSigningPubKey = (SigningPublicKey) signingKeys[0];
|
||||
SigningPrivateKey tSigningPrivKey = (SigningPrivateKey) signingKeys[1];
|
||||
// set expires
|
||||
long expires = System.currentTimeMillis() + (days * 24*60*60*1000L);
|
||||
long expires = System.currentTimeMillis() + (long) (days * 24*60*60*1000L);
|
||||
// sign
|
||||
byte[] data = new byte[4 + 2 + tSigningPubKey.length()];
|
||||
DataHelper.toLong(data, 0, 4, expires / 1000);
|
||||
@@ -374,7 +374,7 @@ public class PrivateKeyFile {
|
||||
java.security.PrivateKey jpriv = SigUtil.toJavaKey(priv);
|
||||
if (signername == null)
|
||||
signername = "example.i2p";
|
||||
X509Certificate cert = SelfSignedGenerator.generate(priv, signername, days);
|
||||
X509Certificate cert = SelfSignedGenerator.generate(priv, signername, (int) days);
|
||||
java.security.cert.Certificate[] certs = { cert };
|
||||
out = new FileOutputStream(certfile);
|
||||
CertUtil.exportPrivateKey(jpriv, certs, out);
|
||||
|
||||
Reference in New Issue
Block a user