Tunnels: Add missing expiration field to ECIES BRR

This commit is contained in:
zzz
2020-10-23 19:42:05 +00:00
parent 470bc77551
commit b52f85ac38
3 changed files with 24 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2020-10-23 zzz
* i2ptunnel: Remove mtn tunnel (new installs only)
* Tunnels:
- Move AES reply keys from HopConfig to TunnelCreatorConfig
- Add missing expiration field to ECIES BRR
2020-10-21 zzz 2020-10-21 zzz
* NetDB: * NetDB:
- ECIES router support for encrypted lookups and stores (proposal #156) - ECIES router support for encrypted lookups and stores (proposal #156)

View File

@ -112,6 +112,7 @@ public class BuildRequestRecord {
public static final int IV_SIZE = 16; public static final int IV_SIZE = 16;
/** we show 16 bytes of the peer hash outside the elGamal block */ /** we show 16 bytes of the peer hash outside the elGamal block */
public static final int PEER_SIZE = 16; public static final int PEER_SIZE = 16;
private static final int DEFAULT_EXPIRATION_SECONDS = 10*60;
/** /**
* @return 222 (ElG) or 464 (ECIES) bytes, non-null * @return 222 (ElG) or 464 (ECIES) bytes, non-null
@ -143,7 +144,8 @@ public class BuildRequestRecord {
private static final int OFF_REPLY_IV_EC = OFF_REPLY_KEY_EC + SessionKey.KEYSIZE_BYTES; private static final int OFF_REPLY_IV_EC = OFF_REPLY_KEY_EC + SessionKey.KEYSIZE_BYTES;
private static final int OFF_FLAG_EC = OFF_REPLY_IV_EC + IV_SIZE; private static final int OFF_FLAG_EC = OFF_REPLY_IV_EC + IV_SIZE;
private static final int OFF_REQ_TIME_EC = OFF_FLAG_EC + 4; private static final int OFF_REQ_TIME_EC = OFF_FLAG_EC + 4;
private static final int OFF_SEND_MSG_ID_EC = OFF_REQ_TIME_EC + 4; private static final int OFF_EXPIRATION = OFF_REQ_TIME_EC + 4;
private static final int OFF_SEND_MSG_ID_EC = OFF_EXPIRATION + 4;
private static final int OFF_OPTIONS = OFF_SEND_MSG_ID_EC + 4; private static final int OFF_OPTIONS = OFF_SEND_MSG_ID_EC + 4;
private static final int LENGTH_EC = 464; private static final int LENGTH_EC = 464;
private static final int MAX_OPTIONS_LENGTH = LENGTH_EC - OFF_OPTIONS; // includes options length private static final int MAX_OPTIONS_LENGTH = LENGTH_EC - OFF_OPTIONS; // includes options length
@ -253,6 +255,16 @@ public class BuildRequestRecord {
return DataHelper.fromLong(_data, off, 4); return DataHelper.fromLong(_data, off, 4);
} }
/**
* The expiration in milliseconds from now.
* @since 0.9.48
*/
public long readExpiration() {
if (!_isEC)
return DEFAULT_EXPIRATION_SECONDS * 1000L;
return DataHelper.fromLong(_data, OFF_EXPIRATION, 4) * 1000L;
}
/** /**
* ECIES only. * ECIES only.
* @return null for ElGamal or on error * @return null for ElGamal or on error
@ -511,6 +523,7 @@ public class BuildRequestRecord {
// this ignores leap seconds // this ignores leap seconds
truncatedMinute /= (60*1000L); truncatedMinute /= (60*1000L);
DataHelper.toLong(buf, OFF_REQ_TIME_EC, 4, truncatedMinute); DataHelper.toLong(buf, OFF_REQ_TIME_EC, 4, truncatedMinute);
DataHelper.toLong(buf, OFF_EXPIRATION, 4, DEFAULT_EXPIRATION_SECONDS);
DataHelper.toLong(buf, OFF_SEND_MSG_ID_EC, 4, nextMsgId); DataHelper.toLong(buf, OFF_SEND_MSG_ID_EC, 4, nextMsgId);
try { try {
int off = DataHelper.toProperties(buf, OFF_OPTIONS, options); int off = DataHelper.toProperties(buf, OFF_OPTIONS, options);
@ -547,7 +560,8 @@ public class BuildRequestRecord {
.append(" reply key: ").append(readReplyKey()) .append(" reply key: ").append(readReplyKey())
.append(" reply IV: ").append(Base64.encode(readReplyIV())) .append(" reply IV: ").append(Base64.encode(readReplyIV()))
.append(" time: ").append(DataHelper.formatTime(readRequestTime())) .append(" time: ").append(DataHelper.formatTime(readRequestTime()))
.append(" reply msg id: ").append(readReplyMessageId()); .append(" reply msg id: ").append(readReplyMessageId())
.append(" expires in: ").append(DataHelper.formatDuration(readExpiration()));
if (_isEC) { if (_isEC) {
buf.append(" options: ").append(readOptions()); buf.append(" options: ").append(readOptions());
if (_chachaReplyKey != null) { if (_chachaReplyKey != null) {
@ -562,6 +576,7 @@ public class BuildRequestRecord {
/**** /****
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("OFF_OPTIONS is " + OFF_OPTIONS);
RouterContext ctx = new RouterContext(null); RouterContext ctx = new RouterContext(null);
TESTKF = new net.i2p.router.transport.crypto.X25519KeyFactory(ctx); TESTKF = new net.i2p.router.transport.crypto.X25519KeyFactory(ctx);
byte[] h = new byte[32]; byte[] h = new byte[32];

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 9; public final static long BUILD = 10;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";