Changeset 535f2da for core


Ignore:
Timestamp:
Nov 23, 2018 1:04:28 PM (19 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.

Location:
core/java/src/net/i2p
Files:
3 edited

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[]) {
Note: See TracChangeset for help on using the changeset viewer.