RatchetSKM: Group debug output for IB tagsets by pubkey, not session key

ElGamalSKM: Debug header change
ElGamalAESEngine: Minor cleanups for efficiency
This commit is contained in:
zzz
2020-04-06 11:31:18 +00:00
parent c77e41c59e
commit 1ca9674f3f
3 changed files with 31 additions and 26 deletions

View File

@ -94,8 +94,8 @@ public final class ElGamalAESEngine {
if (_log.shouldLog(Log.ERROR)) _log.error("Null data being decrypted?");
return null;
} else if (data.length < MIN_ENCRYPTED_SIZE) {
if (_log.shouldLog(Log.ERROR))
_log.error("Data is less than the minimum size (" + data.length + " < " + MIN_ENCRYPTED_SIZE + ")");
if (_log.shouldWarn())
_log.warn("Data is less than the minimum size (" + data.length + " < " + MIN_ENCRYPTED_SIZE + ")");
return null;
}
if (targetPrivateKey.getType() != EncType.ELGAMAL_2048)
@ -663,9 +663,9 @@ public final class ElGamalAESEngine {
long paddedSize, int prefixBytes) {
//_log.debug("iv for encryption: " + DataHelper.toString(iv, 16));
//_log.debug("Encrypting AES");
if (tagsForDelivery == null) tagsForDelivery = Collections.emptySet();
int tagCount = (tagsForDelivery != null) ? tagsForDelivery.size() : 0;
int size = 2 // sizeof(tags)
+ SessionTag.BYTE_LENGTH*tagsForDelivery.size()
+ SessionTag.BYTE_LENGTH * tagCount
+ 4 // payload length
+ Hash.HASH_LENGTH
+ (newKey == null ? 1 : 1 + SessionKey.KEYSIZE_BYTES)
@ -675,12 +675,14 @@ public final class ElGamalAESEngine {
byte aesData[] = new byte[totalSize + prefixBytes];
int cur = prefixBytes;
DataHelper.toLong(aesData, cur, 2, tagsForDelivery.size());
DataHelper.toLong(aesData, cur, 2, tagCount);
cur += 2;
if (tagsForDelivery != null && !tagsForDelivery.isEmpty()) {
for (SessionTag tag : tagsForDelivery) {
System.arraycopy(tag.getData(), 0, aesData, cur, SessionTag.BYTE_LENGTH);
cur += SessionTag.BYTE_LENGTH;
}
}
//_log.debug("# tags created, registered, and written: " + tagsForDelivery.size());
DataHelper.toLong(aesData, cur, 4, data.length);
cur += 4;

View File

@ -779,7 +779,7 @@ public class TransientSessionKeyManager extends SessionKeyManager {
@Override
public void renderStatusHTML(Writer out) throws IOException {
StringBuilder buf = new StringBuilder(1024);
buf.append("<h3 class=\"debug_inboundsessions\">Inbound sessions</h3>" +
buf.append("<h3 class=\"debug_inboundsessions\">ElGamal Inbound Sessions</h3>" +
"<table>");
Map<SessionKey, Set<TagSet>> inboundSets = getInboundTagSetsBySessionKey();
int total = 0;
@ -814,7 +814,7 @@ public class TransientSessionKeyManager extends SessionKeyManager {
.append("; sessions: ").append(inboundSets.size())
.append("</th></tr>\n" +
"</table>" +
"<h3 class=\"debug_outboundsessions\">Outbound sessions</h3>" +
"<h3 class=\"debug_outboundsessions\">ElGamal Outbound Sessions</h3>" +
"<table>");
total = 0;
totalSets = 0;

View File

@ -710,17 +710,19 @@ public class RatchetSKM extends SessionKeyManager implements SessionTagListener
/// end ACKS ///
/**
* Return a map of session key to a set of inbound RatchetTagSets for that SessionKey
* Return a map of PublicKey to a set of inbound RatchetTagSets for that key.
* Only for renderStatusHTML() below.
*/
private Map<SessionKey, Set<RatchetTagSet>> getRatchetTagSetsBySessionKey() {
private Map<PublicKey, Set<RatchetTagSet>> getRatchetTagSetsByPublicKey() {
Set<RatchetTagSet> inbound = getRatchetTagSets();
Map<SessionKey, Set<RatchetTagSet>> inboundSets = new HashMap<SessionKey, Set<RatchetTagSet>>(inbound.size());
// Build a map of the inbound tag sets, grouped by SessionKey
Map<PublicKey, Set<RatchetTagSet>> inboundSets = new HashMap<PublicKey, Set<RatchetTagSet>>(inbound.size());
// Build a map of the inbound tag sets, grouped by PublicKey
for (RatchetTagSet ts : inbound) {
Set<RatchetTagSet> sets = inboundSets.get(ts.getAssociatedKey());
PublicKey pk = ts.getRemoteKey();
Set<RatchetTagSet> sets = inboundSets.get(pk);
if (sets == null) {
sets = new HashSet<RatchetTagSet>(4);
inboundSets.put(ts.getAssociatedKey(), sets);
inboundSets.put(pk, sets);
}
sets.add(ts);
}
@ -734,31 +736,32 @@ public class RatchetSKM extends SessionKeyManager implements SessionTagListener
// inbound
buf.append("<h3 class=\"debug_inboundsessions\">Ratchet Inbound sessions</h3>" +
"<table>");
Map<SessionKey, Set<RatchetTagSet>> inboundSets = getRatchetTagSetsBySessionKey();
Map<PublicKey, Set<RatchetTagSet>> inboundSets = getRatchetTagSetsByPublicKey();
int total = 0;
int totalSets = 0;
long now = _context.clock().now();
Set<RatchetTagSet> sets = new TreeSet<RatchetTagSet>(new RatchetTagSetComparator());
for (Map.Entry<SessionKey, Set<RatchetTagSet>> e : inboundSets.entrySet()) {
SessionKey skey = e.getKey();
for (Map.Entry<PublicKey, Set<RatchetTagSet>> e : inboundSets.entrySet()) {
PublicKey skey = e.getKey();
sets.clear();
sets.addAll(e.getValue());
totalSets += sets.size();
buf.append("<tr><td><b>Session key:</b> ").append(skey.toBase64()).append("</td>" +
buf.append("<tr><td><b>Public key:</b> ").append(skey.toBase64()).append("</td>" +
"<td><b>Sets:</b> ").append(sets.size()).append("</td></tr>" +
"<tr class=\"expiry\"><td colspan=\"2\"><ul>");
for (RatchetTagSet ts : sets) {
int size = ts.size();
total += size;
buf.append("<li><b>ID: ").append(ts.getID())
.append(" / ").append(ts.getDebugID());
buf.append(" created:</b> ").append(DataHelper.formatTime(ts.getCreated()))
.append(" <b>last use:</b> ").append(DataHelper.formatTime(ts.getDate()));
.append('/').append(ts.getDebugID());
// inbound sets are multi-column, keep it short
//buf.append(" created:</b> ").append(DataHelper.formatTime(ts.getCreated()))
// .append(" <b>last use:</b> ").append(DataHelper.formatTime(ts.getDate()));
long expires = ts.getExpiration() - now;
if (expires > 0)
buf.append(" <b>expires in:</b> ").append(DataHelper.formatDuration2(expires)).append(" with ");
buf.append(" expires in:</b> ").append(DataHelper.formatDuration2(expires)).append(" with ");
else
buf.append(" <b>expired:</b> ").append(DataHelper.formatDuration2(0 - expires)).append(" ago with ");
buf.append(" expired:</b> ").append(DataHelper.formatDuration2(0 - expires)).append(" ago with ");
buf.append(size).append('/').append(ts.remaining()).append(" tags remaining</li>");
}
buf.append("</ul></td></tr>\n");
@ -792,7 +795,7 @@ public class RatchetSKM extends SessionKeyManager implements SessionTagListener
for (RatchetTagSet ts : sets) {
int size = ts.remaining();
buf.append("<li><b>ID: ").append(ts.getID())
.append(" / ").append(ts.getDebugID())
.append('/').append(ts.getDebugID())
.append(" created:</b> ").append(DataHelper.formatTime(ts.getCreated()))
.append(" <b>last use:</b> ").append(DataHelper.formatTime(ts.getDate()));
long expires = ts.getExpiration() - now;