Changeset ff5d29d for apps/streaming


Ignore:
Timestamp:
Apr 18, 2015 7:50:14 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
57b641bf
Parents:
91e98ba
Message:

I2CP Multisession - Work in progress:
Fix NPE in addSubsession() by creating key stream
Set sigtype for subsession

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java

    r91e98ba rff5d29d  
    11package net.i2p.client.streaming.impl;
    22
     3import java.io.ByteArrayInputStream;
     4import java.io.ByteArrayOutputStream;
    35import java.io.IOException;
    46import java.io.InputStream;
     
    1820import net.i2p.I2PAppContext;
    1921import net.i2p.I2PException;
     22import net.i2p.client.I2PClient;
    2023import net.i2p.client.I2PSession;
    2124import net.i2p.client.I2PSessionException;
     
    2427import net.i2p.client.streaming.I2PSocketManager;
    2528import net.i2p.client.streaming.I2PSocketOptions;
     29import net.i2p.crypto.SigType;
     30import net.i2p.data.Certificate;
    2631import net.i2p.data.Destination;
     32import net.i2p.data.PrivateKey;
     33import net.i2p.data.PublicKey;
     34import net.i2p.data.SimpleDataStructure;
    2735import net.i2p.util.Log;
    2836
     
    134142     */
    135143    public I2PSession addSubsession(InputStream privateKeyStream, Properties opts) throws I2PSessionException {
     144        if (privateKeyStream == null) {
     145            ByteArrayOutputStream keyStream = new ByteArrayOutputStream(1024);
     146            try {
     147                SigType type = getSigType(opts);
     148                if (type != SigType.DSA_SHA1) {
     149                    // hassle, have to set up the padding and cert, see I2PClientImpl
     150                    throw new I2PSessionException("type " + type + " unsupported");
     151                }
     152                PublicKey pub = _session.getMyDestination().getPublicKey();
     153                PrivateKey priv = _session.getDecryptionKey();
     154                SimpleDataStructure[] keys = _context.keyGenerator().generateSigningKeys(type);
     155                pub.writeBytes(keyStream);
     156                keys[0].writeBytes(keyStream); // signing pub
     157                Certificate.NULL_CERT.writeBytes(keyStream);
     158                priv.writeBytes(keyStream);
     159                keys[1].writeBytes(keyStream); // signing priv
     160            } catch (Exception e) {
     161                throw new I2PSessionException("Error creating keys", e);
     162            }
     163            privateKeyStream = new ByteArrayInputStream(keyStream.toByteArray());
     164        }
    136165        I2PSession rv = _session.addSubsession(privateKeyStream, opts);
    137166        ConnectionOptions defaultOptions = new ConnectionOptions(opts);
     
    147176            _log.warn("Added subsession " + rv);
    148177        return rv;
     178    }
     179
     180    /**
     181     *  @param opts may be null
     182     *  @since 0.9.20 copied from I2PSocketManagerFactory
     183     */
     184    private SigType getSigType(Properties opts) {
     185        if (opts != null) {
     186            String st = opts.getProperty(I2PClient.PROP_SIGTYPE);
     187            if (st != null) {
     188                SigType rv = SigType.parseSigType(st);
     189                if (rv != null && rv.isAvailable())
     190                    return rv;
     191                if (rv != null)
     192                    st = rv.toString();
     193                _log.logAlways(Log.WARN, "Unsupported sig type " + st +
     194                                         ", reverting to " + I2PClient.DEFAULT_SIGTYPE);
     195                // TODO throw instead?
     196            }
     197        }
     198        return I2PClient.DEFAULT_SIGTYPE;
    149199    }
    150200   
Note: See TracChangeset for help on using the changeset viewer.