ji2p 0.0.1-jruby
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/ctxirb +114 -0
- data/bin/simple_http_server +20 -0
- data/bin/simple_outproxy +96 -0
- data/lib/ji2p/cluster/etcd/version3.rb +6 -0
- data/lib/ji2p/cluster/etcd.rb +5 -0
- data/lib/ji2p/cluster/kubernetes/kube_api.rb +6 -0
- data/lib/ji2p/cluster/kubernetes.rb +5 -0
- data/lib/ji2p/cluster.rb +6 -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 +74 -0
- data/lib/ji2p/control/tunnel_ctrl.rb +48 -0
- data/lib/ji2p/control/tunnel_manager.rb +62 -0
- data/lib/ji2p/control.rb +14 -0
- data/lib/ji2p/server/api.rb +15 -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/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/server/models.rb +9 -0
- data/lib/ji2p/server.rb +6 -0
- data/lib/ji2p/startup/bootstrap.rb +60 -0
- data/lib/ji2p/startup/router_manager.rb +21 -0
- data/lib/ji2p/startup.rb +12 -0
- data/lib/ji2p/version.rb +3 -0
- data/lib/ji2p.rb +19 -0
- metadata +299 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a76e69bb6162a5892246ae3d5561a43c256a9a9195631519c18a96359ee21ab5
|
4
|
+
data.tar.gz: d4b84142f919db7da78742ad5c9879a2bc21288d534a944c736daab293dd325e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea76df63c6be7214beda44ab6f88c9408b1f4077d880b2232f77268024f2b9ac665d71ad8f23c2e9ef2c245f2fcb8a345c5abb8d14ca513b023b3e319ce709a4
|
7
|
+
data.tar.gz: 371982f7bded249a77101c3d9655e005ec81d5d525217c536d3a0ec10056f4dba6c6fb8b4f69f8c9024d0ecb55b252fb73c7a4188bd8298a6aef4d67e700f0ea
|
data/bin/ctxirb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
3
|
+
require 'bundler/setup'
|
4
|
+
lib = File.expand_path("../lib", __dir__)
|
5
|
+
$:.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
puts $:
|
7
|
+
|
8
|
+
require 'irb'
|
9
|
+
require 'irb/completion'
|
10
|
+
require 'irb/ext/save-history'
|
11
|
+
|
12
|
+
# Method to pretty-print object methods
|
13
|
+
# Coded by sebastian delmont
|
14
|
+
# http://snippets.dzone.com/posts/show/2916
|
15
|
+
class Object
|
16
|
+
ANSI_BOLD = "\033[1m"
|
17
|
+
ANSI_RESET = "\033[0m"
|
18
|
+
ANSI_LGRAY = "\033[0;37m"
|
19
|
+
ANSI_GRAY = "\033[1;30m"
|
20
|
+
# Print object's methods
|
21
|
+
def pm(*options)
|
22
|
+
methods = self.methods
|
23
|
+
methods -= Object.methods unless options.include? :more
|
24
|
+
filter = options.select {|opt| opt.kind_of? Regexp}.first
|
25
|
+
methods = methods.select {|name| name =~ filter} if filter
|
26
|
+
|
27
|
+
data = methods.sort.collect do |name|
|
28
|
+
method = self.method(name)
|
29
|
+
if method.arity == 0
|
30
|
+
args = "()"
|
31
|
+
elsif method.arity > 0
|
32
|
+
n = method.arity
|
33
|
+
args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")})"
|
34
|
+
elsif method.arity < 0
|
35
|
+
n = -method.arity
|
36
|
+
args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")}, ...)"
|
37
|
+
end
|
38
|
+
klass = $1 if method.inspect =~ /Method: (.*?)#/
|
39
|
+
[name, args, klass]
|
40
|
+
end
|
41
|
+
max_name = data.collect {|item| item[0].size}.max
|
42
|
+
max_args = data.collect {|item| item[1].size}.max
|
43
|
+
data.each do |item|
|
44
|
+
print " #{ANSI_BOLD}#{item[0].to_s.rjust(max_name)}#{ANSI_RESET}"
|
45
|
+
print "#{ANSI_GRAY}#{item[1].ljust(max_args)}#{ANSI_RESET}"
|
46
|
+
print " #{ANSI_LGRAY}#{item[2]}#{ANSI_RESET}\n"
|
47
|
+
end
|
48
|
+
data.size
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
module IRB # :nodoc:
|
53
|
+
def self.start_session(binding)
|
54
|
+
unless @__initialized
|
55
|
+
args = ARGV
|
56
|
+
ARGV.replace(ARGV.dup)
|
57
|
+
IRB.setup(nil)
|
58
|
+
ARGV.replace(args)
|
59
|
+
@__initialized = true
|
60
|
+
end
|
61
|
+
|
62
|
+
workspace = WorkSpace.new(binding)
|
63
|
+
|
64
|
+
irb = Irb.new(workspace)
|
65
|
+
|
66
|
+
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
|
67
|
+
@CONF[:MAIN_CONTEXT] = irb.context
|
68
|
+
@CONF[:SAVE_HISTORY] = 10000
|
69
|
+
@CONF[:HISTORY_FILE] = File.join(ENV['PWD'], '.irb-history')
|
70
|
+
@CONF[:BACK_TRACE_LIMIT] = 16
|
71
|
+
@CONF[:USE_READLINE] = true
|
72
|
+
@CONF[:AUTO_INDENT] = true
|
73
|
+
histfile = @CONF[:HISTORY_FILE]
|
74
|
+
|
75
|
+
#puts @CONF
|
76
|
+
maxsize = @CONF[:SAVE_HISTORY]
|
77
|
+
|
78
|
+
if File::exists?(histfile)
|
79
|
+
lines = IO::readlines(histfile).collect { |line| line.chomp }
|
80
|
+
puts "Read #{lines.nitems} saved history commands from '#{histfile}'." if $VERBOSE
|
81
|
+
Readline::HISTORY.push(*lines)
|
82
|
+
end
|
83
|
+
|
84
|
+
Kernel::at_exit do
|
85
|
+
lines = Readline::HISTORY.to_a.reverse.uniq.reverse
|
86
|
+
lines = lines[-maxsize, maxsize] if lines.length > maxsize
|
87
|
+
puts "Saving #{lines.length} history lines to '#{histfile}'."
|
88
|
+
File::open(histfile, File::WRONLY|File::CREAT|File::TRUNC) { |io| io.puts lines.join("\n") }
|
89
|
+
end
|
90
|
+
|
91
|
+
catch(:IRB_EXIT) do
|
92
|
+
irb.eval_input
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
require 'ji2p'
|
98
|
+
|
99
|
+
def reload!(print = true)
|
100
|
+
puts 'Reloading ...' if print
|
101
|
+
# Main project directory.
|
102
|
+
root_dir = File.expand_path('..', __dir__)
|
103
|
+
# Directories within the project that should be reloaded.
|
104
|
+
reload_dirs = %w{lib}
|
105
|
+
# Loop through and reload every file in all relevant project directories.
|
106
|
+
reload_dirs.each do |dir|
|
107
|
+
Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
|
108
|
+
end
|
109
|
+
# Return true when complete.
|
110
|
+
true
|
111
|
+
end
|
112
|
+
|
113
|
+
IRB.start_session(binding)
|
114
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
3
|
+
require 'bundler/setup'
|
4
|
+
lib = File.expand_path("../lib", __dir__)
|
5
|
+
$:.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
#puts $:
|
7
|
+
|
8
|
+
require 'ji2p'
|
9
|
+
|
10
|
+
app = Proc.new { |env| ['200', {'Content-Type' => 'text/html'}, ['get rack\'d']] }
|
11
|
+
|
12
|
+
kp = Ji2p::Control::Keypair.generate!
|
13
|
+
ssmgr = Ji2p::Control::SocketManager.defineManager! "testing", kp
|
14
|
+
ssmgr.connectTunnel
|
15
|
+
socket = ssmgr.getServerSocket
|
16
|
+
server = Ji2p::Server::HttpServer.new(app, socket)
|
17
|
+
|
18
|
+
puts "Your destination: #{kp.dest.base32}"
|
19
|
+
|
20
|
+
server.run
|
data/bin/simple_outproxy
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
3
|
+
require 'bundler/setup'
|
4
|
+
lib = File.expand_path("../lib", __dir__)
|
5
|
+
$:.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
#puts $:
|
7
|
+
|
8
|
+
require 'socket'
|
9
|
+
require 'uri'
|
10
|
+
require 'ji2p'
|
11
|
+
|
12
|
+
class Proxy
|
13
|
+
def run socket
|
14
|
+
begin
|
15
|
+
@socket = socket
|
16
|
+
|
17
|
+
# Handle every request in another thread
|
18
|
+
loop do
|
19
|
+
s = @socket.accept
|
20
|
+
Thread.new s, &method(:handle_request)
|
21
|
+
end
|
22
|
+
|
23
|
+
# CTRL-C
|
24
|
+
rescue Interrupt
|
25
|
+
puts 'Got Interrupt..'
|
26
|
+
# Ensure that we release the socket on errors
|
27
|
+
ensure
|
28
|
+
if @socket
|
29
|
+
@socket.close
|
30
|
+
puts 'Socked closed..'
|
31
|
+
end
|
32
|
+
puts 'Quitting.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def handle_request to_client
|
37
|
+
request_line = to_client.readline
|
38
|
+
|
39
|
+
verb = request_line[/^\w+/]
|
40
|
+
url = request_line[/^\w+\s+(\S+)/, 1]
|
41
|
+
version = request_line[/HTTP\/(1\.\d)\s*$/, 1]
|
42
|
+
uri = URI::parse url
|
43
|
+
|
44
|
+
# Show what got requested
|
45
|
+
puts((" %4s "%verb) + url)
|
46
|
+
|
47
|
+
to_server = TCPSocket.new(uri.host, (uri.port.nil? ? 80 : uri.port))
|
48
|
+
to_server.write("#{verb} #{uri.path}?#{uri.query} HTTP/#{version}\r\n")
|
49
|
+
|
50
|
+
content_len = 0
|
51
|
+
|
52
|
+
loop do
|
53
|
+
line = to_client.readline
|
54
|
+
|
55
|
+
if line =~ /^Content-Length:\s+(\d+)\s*$/
|
56
|
+
content_len = $1.to_i
|
57
|
+
end
|
58
|
+
|
59
|
+
# Strip proxy headers
|
60
|
+
if line =~ /^proxy/i
|
61
|
+
next
|
62
|
+
elsif line.strip.empty?
|
63
|
+
to_server.write("Connection: close\r\n\r\n")
|
64
|
+
|
65
|
+
if content_len >= 0
|
66
|
+
to_server.write(to_client.read(content_len))
|
67
|
+
end
|
68
|
+
|
69
|
+
break
|
70
|
+
else
|
71
|
+
to_server.write(line)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
buff = ""
|
76
|
+
loop do
|
77
|
+
to_server.read(4048, buff)
|
78
|
+
to_client.write(buff)
|
79
|
+
break if buff.size < 4048
|
80
|
+
end
|
81
|
+
|
82
|
+
# Close the sockets
|
83
|
+
to_client.close
|
84
|
+
to_server.close
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
kp = Ji2p::Control::Keypair.generate!
|
91
|
+
ssmgr = Ji2p::Control::SocketManager.defineManager! "testing", kp
|
92
|
+
ssmgr.connectTunnel
|
93
|
+
socket = ssmgr.getServerSocket
|
94
|
+
puts "Your destination: #{kp.dest.base32}"
|
95
|
+
|
96
|
+
Proxy.new.run socket
|
data/lib/ji2p/cluster.rb
ADDED
@@ -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
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'thread'
|
3
|
+
require_relative 'server.rb'
|
4
|
+
|
5
|
+
module Ji2p::Control
|
6
|
+
java_import 'net.i2p.I2PAppContext'
|
7
|
+
java_import 'net.i2p.client.I2PClientFactory'
|
8
|
+
java_import 'net.i2p.client.streaming.I2PSocketManager'
|
9
|
+
java_import 'net.i2p.client.streaming.I2PSocketManagerFactory'
|
10
|
+
java_import 'net.i2p.client.streaming.impl.I2PSocketManagerFull'
|
11
|
+
java_import 'net.i2p.client.streaming.IncomingConnectionFilter'
|
12
|
+
java_import 'java.util.Properties'
|
13
|
+
java_import 'java.lang.Thread'
|
14
|
+
|
15
|
+
class SocketManager
|
16
|
+
|
17
|
+
def self.defineManager! name, kp, opts=Java::JavaUtil::Properties.new, filter=IncomingConnectionFilter::ALLOW
|
18
|
+
ctx = I2PAppContext.getGlobalContext
|
19
|
+
session = kp.createSession opts
|
20
|
+
new Java::NetI2pClientStreamingImpl::I2PSocketManagerFull.new(ctx,session,opts,name,filter)
|
21
|
+
end
|
22
|
+
|
23
|
+
def connectTunnel
|
24
|
+
@smgr.getSession.connect
|
25
|
+
end
|
26
|
+
|
27
|
+
def myDestination
|
28
|
+
@smgr.getSession.myDestination
|
29
|
+
end
|
30
|
+
|
31
|
+
def leaseSet
|
32
|
+
@smgr.getSession.leaseSet
|
33
|
+
end
|
34
|
+
|
35
|
+
def sessionId
|
36
|
+
@smgr.getSession.sessionId
|
37
|
+
end
|
38
|
+
|
39
|
+
def supports_ls2?
|
40
|
+
@smgr.getSession.supports_ls2?
|
41
|
+
end
|
42
|
+
|
43
|
+
def is_closed?
|
44
|
+
@smgr.getSession.closed?
|
45
|
+
end
|
46
|
+
|
47
|
+
def session
|
48
|
+
@smgr.session
|
49
|
+
end
|
50
|
+
|
51
|
+
def destroy
|
52
|
+
@smgr.getSession.destroySession
|
53
|
+
end
|
54
|
+
|
55
|
+
def lookupDest dest
|
56
|
+
@smgr.getSession.lookupDest dest
|
57
|
+
end
|
58
|
+
|
59
|
+
def getServerSocket
|
60
|
+
SocketServer.new @smgr.getServerSocket
|
61
|
+
end
|
62
|
+
|
63
|
+
def raw
|
64
|
+
@smgr
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def initialize smgr
|
70
|
+
@smgr = smgr
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Ji2p::Control
|
5
|
+
class TunnelCtrl
|
6
|
+
def initialize obj, conf
|
7
|
+
@tunnel = obj
|
8
|
+
@conf = conf
|
9
|
+
end
|
10
|
+
|
11
|
+
def start!
|
12
|
+
@tunnel.startTunnelBackground
|
13
|
+
end
|
14
|
+
|
15
|
+
def stop!
|
16
|
+
@tunnel.stopTunnel
|
17
|
+
end
|
18
|
+
|
19
|
+
def base32
|
20
|
+
@tunnel.myDestHashBase32
|
21
|
+
end
|
22
|
+
|
23
|
+
def base64
|
24
|
+
@tunnel.myDestination
|
25
|
+
end
|
26
|
+
|
27
|
+
def destination
|
28
|
+
@tunnel.myDestination
|
29
|
+
end
|
30
|
+
|
31
|
+
def raw
|
32
|
+
@tunnel
|
33
|
+
end
|
34
|
+
|
35
|
+
def raw_conf
|
36
|
+
@conf
|
37
|
+
end
|
38
|
+
|
39
|
+
def privateKey base64_armored = true
|
40
|
+
d = I2PAppContext.getGlobalContext.getRouterDir.to_s
|
41
|
+
filename = File.join d, @conf['privKeyFile']
|
42
|
+
f = File.open filename, 'rb'
|
43
|
+
data = f.read
|
44
|
+
data = Base64.encode64(data) if base64_armored
|
45
|
+
data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|