ji2p 0.0.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/bin/bundle +15 -0
 - data/bin/ctxirb +119 -0
 - data/bin/simple_http_server +20 -0
 - data/bin/simple_outproxy +96 -0
 - data/lib/actor_system/actor.rb +10 -0
 - data/lib/actor_system/concurrent/processor.rb +21 -0
 - data/lib/actor_system/concurrent/worker.rb +13 -0
 - data/lib/actor_system/core/minimal.rb +84 -0
 - data/lib/actor_system/core/observable_implementation.rb +58 -0
 - data/lib/actor_system/core/props.rb +45 -0
 - data/lib/actor_system/dispatcher.rb +12 -0
 - data/lib/actor_system/mailbox.rb +7 -0
 - data/lib/actor_system/message.rb +60 -0
 - data/lib/core_ext.rb +41 -0
 - data/lib/gen_server.rb +57 -0
 - data/lib/ji2p.rb +37 -0
 - data/lib/ji2p/bundler.rb +165 -0
 - data/lib/ji2p/cluster.rb +6 -0
 - data/lib/ji2p/cluster/etcd.rb +5 -0
 - data/lib/ji2p/cluster/etcd/version3.rb +6 -0
 - data/lib/ji2p/cluster/kubernetes.rb +5 -0
 - data/lib/ji2p/cluster/kubernetes/kube_api.rb +6 -0
 - data/lib/ji2p/concurrent.rb +24 -0
 - data/lib/ji2p/concurrent_executor.rb +56 -0
 - data/lib/ji2p/config.rb +15 -0
 - data/lib/ji2p/control.rb +15 -0
 - data/lib/ji2p/control/client_manager.rb +14 -0
 - data/lib/ji2p/control/dest.rb +34 -0
 - data/lib/ji2p/control/keypair.rb +176 -0
 - data/lib/ji2p/control/server.rb +80 -0
 - data/lib/ji2p/control/socket_manager.rb +77 -0
 - data/lib/ji2p/control/tunnel_manager.rb +62 -0
 - data/lib/ji2p/environment.rb +35 -0
 - data/lib/ji2p/gem_installer.rb +89 -0
 - data/lib/ji2p/jar_dependencies.rb +15 -0
 - data/lib/ji2p/proxy_support.rb +46 -0
 - data/lib/ji2p/rspec.rb +16 -0
 - data/lib/ji2p/server.rb +10 -0
 - data/lib/ji2p/server/api.rb +14 -0
 - data/lib/ji2p/server/database.rb +66 -0
 - data/lib/ji2p/server/http.rb +69 -0
 - data/lib/ji2p/server/http_server.rb +37 -0
 - data/lib/ji2p/server/initializer.rb +4 -0
 - data/lib/ji2p/server/launcher.rb +40 -0
 - data/lib/ji2p/server/models.rb +9 -0
 - data/lib/ji2p/server/models/base_record.rb +7 -0
 - data/lib/ji2p/server/models/keypair.rb +32 -0
 - data/lib/ji2p/server/models/tunnel.rb +4 -0
 - data/lib/ji2p/startup.rb +12 -0
 - data/lib/ji2p/startup/bootstrap.rb +60 -0
 - data/lib/ji2p/startup/client_application.rb +20 -0
 - data/lib/ji2p/startup/router_manager.rb +21 -0
 - data/lib/ji2p/startup/sinatra_app.rb +61 -0
 - data/lib/ji2p/utils/blocking_queue.rb +32 -0
 - data/lib/ji2p/version.rb +3 -0
 - data/lib/ji2p_jars.rb +16 -0
 - data/lib/maybe.rb +148 -0
 - data/lib/net/i2p/client/mstreaming/0.9.43/mstreaming-0.9.43.jar +0 -0
 - data/lib/net/i2p/client/streaming/0.9.43/streaming-0.9.43.jar +0 -0
 - data/lib/net/i2p/i2p/0.9.43/i2p-0.9.43.jar +0 -0
 - data/lib/net/i2p/router/0.9.43/router-0.9.43.jar +0 -0
 - metadata +375 -0
 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'concurrent'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Ji2p
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Concurrent
         
     | 
| 
      
 5 
     | 
    
         
            +
                java_import java.util.concurrent
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def self.getThreadPool
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @service ||= Executors.new_fixed_thread_pool(10)
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  # shutdown our ExecutorService when someone kills us
         
     | 
| 
      
 11 
     | 
    
         
            +
                  Kernel.trap('SIGINT') { service.shutdown }
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                def self.getSimpleThredPool
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @pool ||= Concurrent::ThreadPoolExecutor.new(
         
     | 
| 
      
 18 
     | 
    
         
            +
                    min_threads: 3, # create up to 3 threads before queueing tasks
         
     | 
| 
      
 19 
     | 
    
         
            +
                    max_threads: 10, # create at most 10 threads
         
     | 
| 
      
 20 
     | 
    
         
            +
                    max_queue: 100, # at most 100 jobs waiting in the queue
         
     | 
| 
      
 21 
     | 
    
         
            +
                )
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Ji2p
         
     | 
| 
      
 2 
     | 
    
         
            +
              module ConcurrentExecutor
         
     | 
| 
      
 3 
     | 
    
         
            +
                class Error < StandardError
         
     | 
| 
      
 4 
     | 
    
         
            +
                  def initialize(exceptions)
         
     | 
| 
      
 5 
     | 
    
         
            +
                    @exceptions = exceptions
         
     | 
| 
      
 6 
     | 
    
         
            +
                    super
         
     | 
| 
      
 7 
     | 
    
         
            +
                  end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  def message
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @exceptions.map { | e | e.message }.join "\n"
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def backtrace
         
     | 
| 
      
 14 
     | 
    
         
            +
                    traces = @exceptions.map { |e| e.backtrace }
         
     | 
| 
      
 15 
     | 
    
         
            +
                    ["ConcurrentExecutor::Error START", traces, "END"].flatten
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                class Future
         
     | 
| 
      
 20 
     | 
    
         
            +
                  def initialize(pool: nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    @pool = pool || Concurrent::FixedThreadPool.new(20)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    @exceptions = Concurrent::Array.new
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  # Sample Usage
         
     | 
| 
      
 26 
     | 
    
         
            +
                  # executor = ConcurrentExecutor::Future.new(pool: pool)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  # executor.execute(carriers) do | carrier |
         
     | 
| 
      
 28 
     | 
    
         
            +
                  #   ...
         
     | 
| 
      
 29 
     | 
    
         
            +
                  # end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  #
         
     | 
| 
      
 31 
     | 
    
         
            +
                  # values = executor.resolve
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  def execute array, &block
         
     | 
| 
      
 34 
     | 
    
         
            +
                    @futures = array.map do | element |
         
     | 
| 
      
 35 
     | 
    
         
            +
                      Concurrent::Future.execute({ executor: @pool }) do
         
     | 
| 
      
 36 
     | 
    
         
            +
                        yield(element)
         
     | 
| 
      
 37 
     | 
    
         
            +
                      end.rescue do | exception |
         
     | 
| 
      
 38 
     | 
    
         
            +
                        @exceptions << exception
         
     | 
| 
      
 39 
     | 
    
         
            +
                      end
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                    self
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  def resolve
         
     | 
| 
      
 46 
     | 
    
         
            +
                    values = @futures.map(&:value)
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    if @exceptions.length > 0
         
     | 
| 
      
 49 
     | 
    
         
            +
                      raise ConcurrentExecutor::Error.new(@exceptions)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                    values
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/ji2p/config.rb
    ADDED
    
    
    
        data/lib/ji2p/control.rb
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'digest/sha1'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Ji2p
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Control
         
     | 
| 
      
 5 
     | 
    
         
            +
                autoload :ClientManager, File.expand_path('control/client_manager.rb', __dir__)
         
     | 
| 
      
 6 
     | 
    
         
            +
                autoload :Dest, File.expand_path('control/dest.rb', __dir__)
         
     | 
| 
      
 7 
     | 
    
         
            +
                autoload :Keypair, File.expand_path('control/keypair.rb', __dir__)
         
     | 
| 
      
 8 
     | 
    
         
            +
                autoload :SocketManager, File.expand_path('control/socket_manager.rb', __dir__)
         
     | 
| 
      
 9 
     | 
    
         
            +
                autoload :TunnelManager, File.expand_path('control/tunnel_manager.rb', __dir__)
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def self.unique_id
         
     | 
| 
      
 12 
     | 
    
         
            +
                  Digest::SHA1.hexdigest([Time.now, rand].join)
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Ji2p::Control
         
     | 
| 
      
 2 
     | 
    
         
            +
              class ClientManager
         
     | 
| 
      
 3 
     | 
    
         
            +
                java_import 'net.i2p.client.I2PClient'
         
     | 
| 
      
 4 
     | 
    
         
            +
                java_import 'net.i2p.client.I2PClientFactory'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                def self.listClients
         
     | 
| 
      
 7 
     | 
    
         
            +
                  context.clientManager.listClients.to_a
         
     | 
| 
      
 8 
     | 
    
         
            +
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                def self.context
         
     | 
| 
      
 11 
     | 
    
         
            +
                  RouterContext.getCurrentContext
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'java'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Ji2p::Control
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Dest
         
     | 
| 
      
 5 
     | 
    
         
            +
                java_import 'net.i2p.data.Destination'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def initialize keypair=nil
         
     | 
| 
      
 8 
     | 
    
         
            +
                  setKeypair(keypair) unless keypair.nil?
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def setKeypair keypair
         
     | 
| 
      
 12 
     | 
    
         
            +
                  return if keypair.nil?
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @keypair = keypair
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @dest = Java::NetI2pData::Destination.create keypair.inputstream
         
     | 
| 
      
 15 
     | 
    
         
            +
                  #@dest.setPublicKey @keypair.pub
         
     | 
| 
      
 16 
     | 
    
         
            +
                  #@dest.setSigningPublicKey @keypair.spub
         
     | 
| 
      
 17 
     | 
    
         
            +
                  #@dest.setCertificate @keypair.cert
         
     | 
| 
      
 18 
     | 
    
         
            +
                  #@dest.setPadding @keypair.padding
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                def base64
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @dest.toBase64
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                def base32
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @dest.toBase32
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                def raw
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @dest
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,176 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'java'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'thread'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require File.expand_path('dest.rb', __dir__)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module Ji2p::Control
         
     | 
| 
      
 6 
     | 
    
         
            +
              java_import 'net.i2p.crypto.SigType'
         
     | 
| 
      
 7 
     | 
    
         
            +
              java_import 'net.i2p.crypto.EncType'
         
     | 
| 
      
 8 
     | 
    
         
            +
              java_import 'net.i2p.I2PAppContext'
         
     | 
| 
      
 9 
     | 
    
         
            +
              java_import 'net.i2p.data.SigningPublicKey'
         
     | 
| 
      
 10 
     | 
    
         
            +
              java_import 'net.i2p.data.SigningPrivateKey'
         
     | 
| 
      
 11 
     | 
    
         
            +
              java_import 'net.i2p.data.Certificate'
         
     | 
| 
      
 12 
     | 
    
         
            +
              java_import 'net.i2p.data.KeyCertificate'
         
     | 
| 
      
 13 
     | 
    
         
            +
              java_import 'net.i2p.data.PublicKey'
         
     | 
| 
      
 14 
     | 
    
         
            +
              java_import 'net.i2p.data.PrivateKey'
         
     | 
| 
      
 15 
     | 
    
         
            +
              java_import 'net.i2p.data.Destination'
         
     | 
| 
      
 16 
     | 
    
         
            +
              java_import 'net.i2p.crypto.KeyGenerator'
         
     | 
| 
      
 17 
     | 
    
         
            +
              java_import 'net.i2p.client.I2PClientFactory'
         
     | 
| 
      
 18 
     | 
    
         
            +
              java_import 'java.util.Properties'
         
     | 
| 
      
 19 
     | 
    
         
            +
              java_import 'java.lang.Thread'
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              DEFAULT_SIG_TYPE = Java::NetI2pCrypto::SigType::EdDSA_SHA512_Ed25519 unless defined? DEFAULT_SIG_TYPE
         
     | 
| 
      
 22 
     | 
    
         
            +
              DEFAULT_ENC_TYPE = Java::NetI2pCrypto::EncType::ELGAMAL_2048 unless defined? DEFAULT_ENC_TYPE
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              VALID_ENC_TYPES = Java::NetI2pCrypto::EncType.constants.map { |c| c.to_s }.freeze unless defined? VALID_ENC_TYPES
         
     | 
| 
      
 25 
     | 
    
         
            +
              VALID_SIG_TYPES = Java::NetI2pCrypto::SigType.constants.map { |c| c.to_s }.freeze unless defined? VALID_SIG_TYPES
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              module KeyGen
         
     | 
| 
      
 28 
     | 
    
         
            +
                def self.genPKIkeys
         
     | 
| 
      
 29 
     | 
    
         
            +
                  KeyGenerator.getInstance.generatePKIKeypair
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                def self.genSigningKeys(arg=nil)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  unless arg.nil?
         
     | 
| 
      
 34 
     | 
    
         
            +
                    KeyGenerator.getInstance.generateSigningKeys arg
         
     | 
| 
      
 35 
     | 
    
         
            +
                  else
         
     | 
| 
      
 36 
     | 
    
         
            +
                    KeyGenerator.getInstance.generateSigningKeys
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              class Keypair
         
     | 
| 
      
 42 
     | 
    
         
            +
                attr_accessor :dest, :cert, :pub, :spub, :priv, :spriv
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def self.generate! sig=DEFAULT_SIG_TYPE
         
     | 
| 
      
 45 
     | 
    
         
            +
                  ost = StringIO.new
         
     | 
| 
      
 46 
     | 
    
         
            +
                  c = I2PClientFactory.createClient
         
     | 
| 
      
 47 
     | 
    
         
            +
                  c.createDestination(ost.to_outputstream, sig)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  keystream = StringIO.new ost.string
         
     | 
| 
      
 49 
     | 
    
         
            +
                  load_from_stream! keystream
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                def self.load_from_stream! keystream
         
     | 
| 
      
 53 
     | 
    
         
            +
                  c = I2PClientFactory.createClient
         
     | 
| 
      
 54 
     | 
    
         
            +
                  s = c.createSession(keystream.to_inputstream, Java::JavaUtil::Properties.new)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  pub = s.myDestination.getPublicKey
         
     | 
| 
      
 56 
     | 
    
         
            +
                  spub = s.myDestination.getSigningPublicKey
         
     | 
| 
      
 57 
     | 
    
         
            +
                  priv = s.decryptionKey
         
     | 
| 
      
 58 
     | 
    
         
            +
                  spriv = s.privateKey
         
     | 
| 
      
 59 
     | 
    
         
            +
                  # This will be equal to the content of a
         
     | 
| 
      
 60 
     | 
    
         
            +
                  # net.i2p.data.PrivateKeyFile
         
     | 
| 
      
 61 
     | 
    
         
            +
                  cert = s.myDestination.getCertificate
         
     | 
| 
      
 62 
     | 
    
         
            +
                  new cert,pub,priv,spub,spriv,keystream.string
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                def initialize cert,pub,priv,spub,spriv,data
         
     | 
| 
      
 66 
     | 
    
         
            +
                  @cert = cert
         
     | 
| 
      
 67 
     | 
    
         
            +
                  @pub = pub
         
     | 
| 
      
 68 
     | 
    
         
            +
                  @priv = priv
         
     | 
| 
      
 69 
     | 
    
         
            +
                  @spub = spub
         
     | 
| 
      
 70 
     | 
    
         
            +
                  @spriv = spriv
         
     | 
| 
      
 71 
     | 
    
         
            +
                  @data = data
         
     | 
| 
      
 72 
     | 
    
         
            +
                  @dest = Ji2p::Control::Dest.new
         
     | 
| 
      
 73 
     | 
    
         
            +
                  @dest.setKeypair self
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                def inputstream
         
     | 
| 
      
 77 
     | 
    
         
            +
                  stream = StringIO.new @data
         
     | 
| 
      
 78 
     | 
    
         
            +
                  stream.to_inputstream
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                def destination
         
     | 
| 
      
 82 
     | 
    
         
            +
                  @dest
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                def createSession opts=Java::JavaUtil::Properties.new
         
     | 
| 
      
 86 
     | 
    
         
            +
                  c = I2PClientFactory.createClient
         
     | 
| 
      
 87 
     | 
    
         
            +
                  @session = c.createSession(inputstream, opts)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  @session
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                def private_key_format
         
     | 
| 
      
 92 
     | 
    
         
            +
                  @data
         
     | 
| 
      
 93 
     | 
    
         
            +
                end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                def padding_size
         
     | 
| 
      
 96 
     | 
    
         
            +
                  ((Java::NetI2pData::SigningPublicKey::KEYSIZE_BYTES - @spub.length)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    + (Java::NetI2pData::PublicKey::KEYSIZE_BYTES - @pub.length))
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                def padding
         
     | 
| 
      
 101 
     | 
    
         
            +
                  SecureRandom.random_bytes(padding_size).to_java_bytes
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                def write_file f
         
     | 
| 
      
 105 
     | 
    
         
            +
                  f = File.open(f, 'wb') unless f.is_a? File
         
     | 
| 
      
 106 
     | 
    
         
            +
                  f.write(@data)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  f.close
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                module Old
         
     | 
| 
      
 111 
     | 
    
         
            +
                  def self.old_generate! sig=DEFAULT_SIG_TYPE, enc=DEFAULT_ENC_TYPE
         
     | 
| 
      
 112 
     | 
    
         
            +
                    if sig.is_a? String
         
     | 
| 
      
 113 
     | 
    
         
            +
                      unless VALID_SIG_TYPES.include? sig
         
     | 
| 
      
 114 
     | 
    
         
            +
                        raise ArgumentError, 'Unknown signature type', caller
         
     | 
| 
      
 115 
     | 
    
         
            +
                      end
         
     | 
| 
      
 116 
     | 
    
         
            +
                      sig = Java::NetI2pCrypto::SigType.const_get sig
         
     | 
| 
      
 117 
     | 
    
         
            +
                    end
         
     | 
| 
      
 118 
     | 
    
         
            +
                    if enc.is_a? String
         
     | 
| 
      
 119 
     | 
    
         
            +
                      unless VALID_ENC_TYPES.include? enc
         
     | 
| 
      
 120 
     | 
    
         
            +
                        raise ArgumentError, 'Unknown encryption type', caller
         
     | 
| 
      
 121 
     | 
    
         
            +
                      end
         
     | 
| 
      
 122 
     | 
    
         
            +
                      enc = Java::NetI2pCrypto::EncType.const_get enc
         
     | 
| 
      
 123 
     | 
    
         
            +
                    end
         
     | 
| 
      
 124 
     | 
    
         
            +
                    ctx = I2PAppContext.getGlobalContext
         
     | 
| 
      
 125 
     | 
    
         
            +
                    enckp = ctx.keyGenerator.generatePKIKeys enc
         
     | 
| 
      
 126 
     | 
    
         
            +
                    pub = enckp.getPublic.to_java(Java::NetI2pData::PublicKey)
         
     | 
| 
      
 127 
     | 
    
         
            +
                    priv = enckp.getPrivate.to_java(Java::NetI2pData::PrivateKey)
         
     | 
| 
      
 128 
     | 
    
         
            +
                    if (sig != Java::NetI2pCrypto::SigType::DSA_SHA1) or (enc != Java::NetI2pCrypto::EncType::ELGAMAL_2048)
         
     | 
| 
      
 129 
     | 
    
         
            +
                      unless sig.getPubkeyLen > 128
         
     | 
| 
      
 130 
     | 
    
         
            +
                        cert = Java::NetI2pData::KeyCertificate.new sig,enc
         
     | 
| 
      
 131 
     | 
    
         
            +
                      else
         
     | 
| 
      
 132 
     | 
    
         
            +
                        raise ArgumentError, 'Wrong combination of enc/sig keys', caller
         
     | 
| 
      
 133 
     | 
    
         
            +
                      end
         
     | 
| 
      
 134 
     | 
    
         
            +
                    else
         
     | 
| 
      
 135 
     | 
    
         
            +
                      cert = Java::NetI2pData::Certificate::NULL_CERT
         
     | 
| 
      
 136 
     | 
    
         
            +
                    end
         
     | 
| 
      
 137 
     | 
    
         
            +
                    signingkp = ctx.keyGenerator.generateSigningKeys sig.to_java
         
     | 
| 
      
 138 
     | 
    
         
            +
                    #signingkp = KeyGen.genSigningKeys sig
         
     | 
| 
      
 139 
     | 
    
         
            +
                    spub = signingkp[0].to_java(Java::NetI2pData::SigningPublicKey)
         
     | 
| 
      
 140 
     | 
    
         
            +
                    spriv = signingkp[1].to_java(Java::NetI2pData::SigningPrivateKey)
         
     | 
| 
      
 141 
     | 
    
         
            +
                    #cert.calculateHash
         
     | 
| 
      
 142 
     | 
    
         
            +
                    data = old_getPrivateKeyFileFormat cert,pub,priv,spub,spriv
         
     | 
| 
      
 143 
     | 
    
         
            +
                    new cert,pub,priv,spub,spriv,data
         
     | 
| 
      
 144 
     | 
    
         
            +
                  end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                  def self.old_getPrivateKeyFileFormat cert,pub,priv,spub,spriv
         
     | 
| 
      
 147 
     | 
    
         
            +
                    out = StringIO.new
         
     | 
| 
      
 148 
     | 
    
         
            +
                    outs = out.to_outputstream
         
     | 
| 
      
 149 
     | 
    
         
            +
                    pub.writeBytes outs
         
     | 
| 
      
 150 
     | 
    
         
            +
                    padding_size = ((Java::NetI2pData::SigningPublicKey::KEYSIZE_BYTES - spub.length)
         
     | 
| 
      
 151 
     | 
    
         
            +
                                    + (Java::NetI2pData::PublicKey::KEYSIZE_BYTES - pub.length))
         
     | 
| 
      
 152 
     | 
    
         
            +
                    if padding_size > 0
         
     | 
| 
      
 153 
     | 
    
         
            +
                      outs.write SecureRandom.random_bytes(padding_size).to_java_bytes
         
     | 
| 
      
 154 
     | 
    
         
            +
                    end
         
     | 
| 
      
 155 
     | 
    
         
            +
                    spub.writeBytes outs
         
     | 
| 
      
 156 
     | 
    
         
            +
                    cert.writeBytes outs
         
     | 
| 
      
 157 
     | 
    
         
            +
                    priv.writeBytes outs
         
     | 
| 
      
 158 
     | 
    
         
            +
                    spriv.writeBytes outs
         
     | 
| 
      
 159 
     | 
    
         
            +
                    outs.flush
         
     | 
| 
      
 160 
     | 
    
         
            +
                    outs.close
         
     | 
| 
      
 161 
     | 
    
         
            +
                    StringIO.new out.string
         
     | 
| 
      
 162 
     | 
    
         
            +
                  end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                  def self.old_load_from_obj! obj
         
     | 
| 
      
 165 
     | 
    
         
            +
                    pub   = Java::NetI2pData::PublicKey.new obj[:enc_type],obj[:public_key].to_java_bytes
         
     | 
| 
      
 166 
     | 
    
         
            +
                    priv  = Java::NetI2pData::PrivateKey.new obj[:enc_type],obj[:private_key].to_java_bytes
         
     | 
| 
      
 167 
     | 
    
         
            +
                    spub  = Java::NetI2pData::SigningPublicKey.new obj[:sig_type],obj[:signing_public_key].to_java_bytes
         
     | 
| 
      
 168 
     | 
    
         
            +
                    spriv = Java::NetI2pData::SigningPrivateKey.new obj[:sig_type],obj[:signing_private_key].to_java_bytes
         
     | 
| 
      
 169 
     | 
    
         
            +
                    cert  = Java::NetI2pData::KeyCertificate.new spub,pub
         
     | 
| 
      
 170 
     | 
    
         
            +
                    data = old_getPrivateKeyFileFormat cert,pub,priv,spub,spriv
         
     | 
| 
      
 171 
     | 
    
         
            +
                    new cert,pub,priv,spub,spriv,data
         
     | 
| 
      
 172 
     | 
    
         
            +
                  end
         
     | 
| 
      
 173 
     | 
    
         
            +
                end
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
              end
         
     | 
| 
      
 176 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,80 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'java'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'thread'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module Ji2p::Control
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              class ServerConnection
         
     | 
| 
      
 7 
     | 
    
         
            +
                def initialize i2pconn
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @i2pconn = i2pconn
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def raw
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @i2pconn
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def close
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @i2pconn.close
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def is_closed?
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @i2pconn.is_closed
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                def write data
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @i2pconn.getOutputStream.write data.to_java_bytes
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def getPeerDestination
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @i2pconn.getPeerDestination
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                def readstring n=nil
         
     | 
| 
      
 32 
     | 
    
         
            +
                  String.from_java_bytes readbytes(n || readybytes)
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                def readline
         
     | 
| 
      
 36 
     | 
    
         
            +
                  line = ""
         
     | 
| 
      
 37 
     | 
    
         
            +
                  loop {
         
     | 
| 
      
 38 
     | 
    
         
            +
                    c = String.from_java_bytes(readbytes(1))
         
     | 
| 
      
 39 
     | 
    
         
            +
                    break if c=="\n"
         
     | 
| 
      
 40 
     | 
    
         
            +
                    line += c
         
     | 
| 
      
 41 
     | 
    
         
            +
                  }
         
     | 
| 
      
 42 
     | 
    
         
            +
                  line + "\n"
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                def readbytes n=nil
         
     | 
| 
      
 46 
     | 
    
         
            +
                  return nil if is_closed?
         
     | 
| 
      
 47 
     | 
    
         
            +
                  num = n || readybytes
         
     | 
| 
      
 48 
     | 
    
         
            +
                  @i2pconn.getInputStream.readNBytes num
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                def readybytes
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @i2pconn.getInputStream.totalReadySize
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                alias :read :readstring
         
     | 
| 
      
 56 
     | 
    
         
            +
                alias :gets :readline
         
     | 
| 
      
 57 
     | 
    
         
            +
                alias :puts :write
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                def toString
         
     | 
| 
      
 60 
     | 
    
         
            +
                  b32 = @i2pconn.getPeerDestination.toBase32
         
     | 
| 
      
 61 
     | 
    
         
            +
                  "<ServerConnection client=#{b32} is_closed=#{@i2pconn.is_closed}>"
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              class SocketServer
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                def initialize i2psocket
         
     | 
| 
      
 68 
     | 
    
         
            +
                  @i2psocket = i2psocket
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                def accept
         
     | 
| 
      
 72 
     | 
    
         
            +
                  ServerConnection.new @i2psocket.accept
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                def raw
         
     | 
| 
      
 76 
     | 
    
         
            +
                  @i2psocket
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
              end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            end
         
     |