Changeset 535f2da


Ignore:
Timestamp:
Nov 23, 2018 1:04:28 PM (17 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d6e3501
Parents:
5c0c69c
Message:

Router: Move ElGamalAESEngine from core to router
Client end-to-end crypto removed 13 years ago
Not used by any client, app, or plugin.

Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/I2PAppContext.java

    r5c0c69c r535f2da  
    1414import net.i2p.crypto.CryptixAESEngine;
    1515import net.i2p.crypto.DSAEngine;
    16 import net.i2p.crypto.ElGamalAESEngine;
    1716import net.i2p.crypto.ElGamalEngine;
    1817import net.i2p.crypto.HMAC256Generator;
     
    7574    private NamingService _namingService;
    7675    private ElGamalEngine _elGamalEngine;
    77     private ElGamalAESEngine _elGamalAESEngine;
    7876    private AESEngine _AESEngine;
    7977    private LogManager _logManager;
     
    9593    private volatile boolean _namingServiceInitialized;
    9694    private volatile boolean _elGamalEngineInitialized;
    97     private volatile boolean _elGamalAESEngineInitialized;
    9895    private volatile boolean _AESEngineInitialized;
    9996    private volatile boolean _logManagerInitialized;
     
    121118    // split up big lock on this to avoid deadlocks
    122119    private final Object _lock1 = new Object(), _lock2 = new Object(), _lock3 = new Object(), _lock4 = new Object(),
    123                          _lock5 = new Object(), _lock6 = new Object(), _lock7 = new Object(), _lock8 = new Object(),
     120                         _lock5 = new Object(), _lock7 = new Object(), _lock8 = new Object(),
    124121                         _lock9 = new Object(), _lock10 = new Object(), _lock11 = new Object(), _lock12 = new Object(),
    125122                         _lock13 = new Object(), _lock14 = new Object(), _lock16 = new Object(),
     
    682679        }
    683680    }
    684    
    685     /**
    686      * Access the ElGamal/AES+SessionTag engine for this context.  The algorithm
    687      * makes use of the context's sessionKeyManager to coordinate transparent
    688      * access to the sessionKeys and sessionTags, as well as the context's elGamal
    689      * engine (which in turn keeps stats, etc).
    690      *
    691      */
    692     public ElGamalAESEngine elGamalAESEngine() {
    693         if (!_elGamalAESEngineInitialized)
    694             initializeElGamalAESEngine();
    695         return _elGamalAESEngine;
    696     }
    697 
    698     private void initializeElGamalAESEngine() {
    699         synchronized (_lock6) {
    700             if (_elGamalAESEngine == null)
    701                 _elGamalAESEngine = new ElGamalAESEngine(this);
    702             _elGamalAESEngineInitialized = true;
    703         }
    704     }
    705    
     681
    706682    /**
    707683     * Ok, I'll admit it.  there is no good reason for having a context specific
  • core/java/src/net/i2p/client/impl/I2CPMessageProducer.java

    r5c0c69c r535f2da  
    165165        msg.setSessionId(sid);
    166166        msg.setNonce(nonce);
    167         Payload data = createPayload(dest, payload, null, null, null, null);
     167        Payload data = createPayload(payload);
    168168        msg.setPayload(data);
    169169        session.sendMessage(msg);
     
    192192        msg.setSessionId(sid);
    193193        msg.setNonce(nonce);
    194         Payload data = createPayload(dest, payload, null, null, null, null);
     194        Payload data = createPayload(payload);
    195195        msg.setPayload(data);
    196196        session.sendMessage(msg);
     
    300300    }
    301301   
    302     /**
    303      * Should we include the I2CP end to end crypto (which is in addition to any
    304      * garlic crypto added by the router)
    305      *
    306      */
    307     static final boolean END_TO_END_CRYPTO = false;
    308    
    309     /**
    310      * Create a new signed payload and send it off to the destination
    311      *
    312      * @param tag unused - no end-to-end crypto
    313      * @param tags unused - no end-to-end crypto
    314      * @param key unused - no end-to-end crypto
    315      * @param newKey unused - no end-to-end crypto
    316      */
    317     private Payload createPayload(Destination dest, byte[] payload, SessionTag tag, SessionKey key, Set<SessionTag> tags,
    318                                   SessionKey newKey) throws I2PSessionException {
    319         if (dest == null) throw new I2PSessionException("No destination specified");
     302    /**
     303     * Create a new payload.
     304     * No more end-to-end encryption, just set the "encrypted" data to the payload.
     305     */
     306    private static Payload createPayload(byte[] payload) throws I2PSessionException {
    320307        if (payload == null) throw new I2PSessionException("No payload specified");
    321 
    322308        Payload data = new Payload();
    323         if (!END_TO_END_CRYPTO) {
    324             data.setEncryptedData(payload);
    325             return data;
    326         }
    327         // no padding at this level
    328         // the garlic may pad, and the tunnels may pad, and the transports may pad
    329         int size = payload.length;
    330         byte encr[] = _context.elGamalAESEngine().encrypt(payload, dest.getPublicKey(), key, tags, tag, newKey, size);
    331         // yes, in an intelligent component, newTags would be queued for confirmation along with key, and
    332         // generateNewTags would only generate tags if necessary
    333 
    334         data.setEncryptedData(encr);
    335         //_log.debug("Encrypting the payload to public key " + dest.getPublicKey().toBase64() + "\nPayload: "
    336         //           + data.calculateHash());
     309        data.setEncryptedData(payload);
    337310        return data;
    338311    }
  • core/java/src/net/i2p/crypto/AESEngine.java

    r5c0c69c r535f2da  
    8080                 + 4 // sizeof(payload)
    8181                 + payload.length;
    82         int padding = ElGamalAESEngine.getPaddingSize(size, paddedSize);
     82        int padding = getPaddingSize(size, paddedSize);
    8383       
    8484        byte data[] = new byte[size + padding];
     
    9090        System.arraycopy(payload, 0, data, cur, payload.length);
    9191        cur += payload.length;
    92         byte paddingData[] = ElGamalAESEngine.getPadding(_context, size, paddedSize);
     92        byte paddingData[] = getPadding(_context, size, paddedSize);
    9393        System.arraycopy(paddingData, 0, data, cur, paddingData.length);
    9494       
     
    183183        System.arraycopy(payload, inIndex, rv, outIndex, rv.length - outIndex);
    184184    }
    185    
     185
     186    /**
     187     * Return random bytes for padding the data to a mod 16 size so that it is
     188     * at least minPaddedSize
     189     *
     190     * Public for ElGamalAESEngine.
     191     * Not a public API, not for external use.
     192     *
     193     * @since 0.9.38 moved from ElGamalAESEngine
     194     */
     195    public final static byte[] getPadding(I2PAppContext context, int curSize, long minPaddedSize) {
     196        int size = getPaddingSize(curSize, minPaddedSize);
     197        byte rv[] = new byte[size];
     198        context.random().nextBytes(rv);
     199        return rv;
     200    }
     201
     202    /**
     203     * Return size for padding the data to a mod 16 size so that it is
     204     * at least minPaddedSize
     205     *
     206     * Public for ElGamalAESEngine.
     207     * Not a public API, not for external use.
     208     *
     209     * @since 0.9.38 moved from ElGamalAESEngine
     210     */
     211    public final static int getPaddingSize(int curSize, long minPaddedSize) {
     212        int diff = 0;
     213        if (curSize < minPaddedSize) {
     214            diff = (int) minPaddedSize - curSize;
     215        }
     216
     217        int numPadding = diff;
     218        if (((curSize + diff) % 16) != 0) numPadding += (16 - ((curSize + diff) % 16));
     219        return numPadding;
     220    }
     221
     222 
    186223/******
    187224    public static void main(String args[]) {
  • router/java/src/net/i2p/router/RouterContext.java

    r5c0c69c r535f2da  
    1616import net.i2p.internal.InternalClientManager;
    1717import net.i2p.router.client.ClientManagerFacadeImpl;
     18import net.i2p.router.crypto.ElGamalAESEngine;
    1819import net.i2p.router.crypto.TransientSessionKeyManager;
    1920import net.i2p.router.dummy.*;
     
    6970    private RouterKeyGenerator _routingKeyGenerator;
    7071    private GarlicMessageParser _garlicMessageParser;
     72    private ElGamalAESEngine _elGamalAESEngine;
    7173    private final Set<Runnable> _finalShutdownTasks;
    7274    // split up big lock on this to avoid deadlocks
     
    212214            // internal client manager is null
    213215        }
     216        _elGamalAESEngine = new ElGamalAESEngine(this);
    214217        _garlicMessageParser = new GarlicMessageParser(this);
    215218        _clientMessagePool = new ClientMessagePool(this);
     
    668671        return _garlicMessageParser;
    669672    }
     673
     674    /**
     675     * Access the ElGamal/AES+SessionTag engine for this context.  The algorithm
     676     * makes use of the context's sessionKeyManager to coordinate transparent
     677     * access to the sessionKeys and sessionTags, as well as the context's elGamal
     678     * engine (which in turn keeps stats, etc).
     679     *
     680     * @since 0.9.38 moved from superclass (app context)
     681     */
     682    public ElGamalAESEngine elGamalAESEngine() {
     683        return _elGamalAESEngine;
     684    }
    670685}
  • router/java/src/net/i2p/router/crypto/ElGamalAESEngine.java

    r5c0c69c r535f2da  
    1 package net.i2p.crypto;
     1package net.i2p.router.crypto;
    22
    33/*
     
    1717
    1818import net.i2p.I2PAppContext;
     19import net.i2p.crypto.AESEngine;
     20import net.i2p.crypto.SessionKeyManager;
    1921import net.i2p.data.DataFormatException;
    2022import net.i2p.data.DataHelper;
     
    3234 *
    3335 * No, this does not extend AESEngine or CryptixAESEngine.
     36 *
     37 * @since 0.9.38 moved from net.i2p.crypto
    3438 */
    3539public final class ElGamalAESEngine {
     
    650654                 + (newKey == null ? 1 : 1 + SessionKey.KEYSIZE_BYTES)
    651655                 + data.length;
    652         int totalSize = size + getPaddingSize(size, paddedSize);
     656        int totalSize = size + AESEngine.getPaddingSize(size, paddedSize);
    653657
    654658        byte aesData[] = new byte[totalSize + prefixBytes];
     
    684688
    685689        //_log.debug("raw data written: " + len);
    686         byte padding[] = getPadding(_context, size, paddedSize);
     690        byte padding[] = AESEngine.getPadding(_context, size, paddedSize);
    687691        //_log.debug("padding length: " + padding.length);
    688692        System.arraycopy(padding, 0, aesData, cur, padding.length);
     
    697701    }
    698702
    699     /**
    700      * Return random bytes for padding the data to a mod 16 size so that it is
    701      * at least minPaddedSize
    702      *
    703      */
    704     final static byte[] getPadding(I2PAppContext context, int curSize, long minPaddedSize) {
    705         int size = getPaddingSize(curSize, minPaddedSize);
    706         byte rv[] = new byte[size];
    707         context.random().nextBytes(rv);
    708         return rv;
    709     }
    710 
    711     final static int getPaddingSize(int curSize, long minPaddedSize) {
    712         int diff = 0;
    713         if (curSize < minPaddedSize) {
    714             diff = (int) minPaddedSize - curSize;
    715         }
    716 
    717         int numPadding = diff;
    718         if (((curSize + diff) % 16) != 0) numPadding += (16 - ((curSize + diff) % 16));
    719         return numPadding;
    720     }
    721703
    722704/****
  • router/java/src/net/i2p/router/message/GarlicMessageParser.java

    r5c0c69c r535f2da  
    1111import java.util.Date;
    1212
    13 import net.i2p.I2PAppContext;
    1413import net.i2p.crypto.SessionKeyManager;
    1514import net.i2p.data.Certificate;
     
    1918import net.i2p.data.i2np.GarlicClove;
    2019import net.i2p.data.i2np.GarlicMessage;
     20import net.i2p.router.RouterContext;
    2121import net.i2p.util.Log;
    2222
     
    2828public class GarlicMessageParser {
    2929    private final Log _log;
    30     private final I2PAppContext _context;
     30    private final RouterContext _context;
    3131   
    3232    /**
     
    3636    private static final int MAX_CLOVES = 32;
    3737
    38     public GarlicMessageParser(I2PAppContext context) {
     38    public GarlicMessageParser(RouterContext context) {
    3939        _context = context;
    4040        _log = _context.logManager().getLog(GarlicMessageParser.class);
Note: See TracChangeset for help on using the changeset viewer.