[or-cvs] r10834: reorganised some stuff and added control fuzzer template (in topf/trunk: . lib lib/fuzz-struct)
benedikt at seul.org
benedikt at seul.org
Mon Jul 16 01:14:26 UTC 2007
Author: benedikt
Date: 2007-07-15 21:14:26 -0400 (Sun, 15 Jul 2007)
New Revision: 10834
Added:
topf/trunk/control.rb
topf/trunk/lib/control.rb
topf/trunk/tor-control-fuzz.rb
Modified:
topf/trunk/config.yml
topf/trunk/lib/dir.rb
topf/trunk/lib/fuzz-struct/fuzz-struct.rb
topf/trunk/lib/fuzz-struct/text-field.rb
topf/trunk/lib/fuzz.rb
topf/trunk/lib/pkcs1.rb
topf/trunk/lib/topf.rb
topf/trunk/tor-dir-fuzz.rb
Log:
reorganised some stuff and added control fuzzer template
Modified: topf/trunk/config.yml
===================================================================
--- topf/trunk/config.yml 2007-07-16 00:14:38 UTC (rev 10833)
+++ topf/trunk/config.yml 2007-07-16 01:14:26 UTC (rev 10834)
@@ -1,3 +1,4 @@
-PORT: "2324"
-HOST: 127.0.0.1
+DIRPORT: "2324"
+CONTROLPORT: "2323"
+HOST: "127.0.0.1"
KEYFILE: stuff/fuzz-private.pem
Added: topf/trunk/control.rb
===================================================================
Added: topf/trunk/lib/control.rb
===================================================================
--- topf/trunk/lib/control.rb (rev 0)
+++ topf/trunk/lib/control.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -0,0 +1,41 @@
+module TOPF
+ module Control
+ class ConfItem < BitStruct
+ text :item, 7
+ text :keyword, 10
+ text :assign, 1
+ rest :value
+
+ initial_value.item = "SETCONF"
+ initial_value.assign = "="
+ end
+
+ class ResetConfItem < BitStruct
+ text :item, 9
+ text :keyword, 10
+ text :assign, 1
+ rest :value
+
+ initial_value.item = "RESETCONF"
+ initial_value.assign = "="
+ end
+
+ class GetConfItem < BitStruct
+ text :item, 7
+ text :keyword, 10
+ text :assign, 1
+ rest :value
+
+ initial_value.item = "GETCONF"
+ initial_value.assign = "="
+ end
+
+ class AuthenticateItem < BitStruct
+ text :item, 12
+ rest :crlf
+
+ initial_value.item = "AUTHENTICATE"
+ initial_value.crlf = "\n"
+ end
+ end
+end
Modified: topf/trunk/lib/dir.rb
===================================================================
--- topf/trunk/lib/dir.rb 2007-07-16 00:14:38 UTC (rev 10833)
+++ topf/trunk/lib/dir.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -23,7 +23,7 @@
class RouterItem < BitStruct
char :item, 6*8, :fuzzable => false
- char :nickname, TOP::Dir::DefaultNicknameLength*8
+ char :nickname, TOPF::Dir::DefaultNicknameLength*8
octets :address, 32
signed :OrPort, 32
signed :SocksPort, 32
@@ -33,8 +33,8 @@
initial_value.nickname = "foobar"
initial_value.address = "127.0.0.1"
initial_value.SocksPort = 0
- initial_value.OrPort = TOP::Dir::DefaultOrPort
- initial_value.DirPort = TOP::Dir::DefaultDirPort
+ initial_value.OrPort = TOPF::Dir::DefaultOrPort
+ initial_value.DirPort = TOPF::Dir::DefaultDirPort
end
class PublishedItem < BitStruct
@@ -50,7 +50,7 @@
rest :publicKey # key in PEM Format
initial_value.item = "onion-key"
- initial_value.publicKey = TOP::Dir::PublicCertificate
+ initial_value.publicKey = TOPF::Dir::PublicCertificate
end
class SigningKeyItem < BitStruct
@@ -58,7 +58,7 @@
rest :publicKey # key in PEM Format
initial_value.item = "signing-key"
- initial_value.publicKey = TOP::Dir::PublicCertificate
+ initial_value.publicKey = TOPF::Dir::PublicCertificate
end
class BandwidthItem < BitStruct
@@ -176,11 +176,11 @@
resultString << item.format << "\n"
end
resultString << "router-signature\n"
- sig = @pkcs1.sign(@key, resultString)
+ sig = Base64::b64encode( @pkcs1.sign(@key, resultString) )
resultString << "-----BEGIN SIGNATURE-----\n"
resultString << sig
- resultString << "\n-----END SIGNATURE-----" << "\n"*2
+ resultString << "-----END SIGNATURE-----" << "\n"*2
end
end
end
Modified: topf/trunk/lib/fuzz-struct/fuzz-struct.rb
===================================================================
--- topf/trunk/lib/fuzz-struct/fuzz-struct.rb 2007-07-16 00:14:38 UTC (rev 10833)
+++ topf/trunk/lib/fuzz-struct/fuzz-struct.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -78,12 +78,12 @@
def initialize(offset, length, name, opts = {})
@offset, @length, @name, @options =
offset, length, name, opts
-
+
@class = opts[:field_class] || opts["field_class"]
@display_name = opts[:display_name] || opts["display_name"]
@default = opts[:default] || opts["default"] || self.class.default
@format = opts[:format] || opts["format"]
-
+
if opts.has_key?(:fuzzable) || opts.has_key?("fuzzable")
@fuzzable = opts[:fuzzable] || opts["fuzzable"]
else
Modified: topf/trunk/lib/fuzz-struct/text-field.rb
===================================================================
--- topf/trunk/lib/fuzz-struct/text-field.rb 2007-07-16 00:14:38 UTC (rev 10833)
+++ topf/trunk/lib/fuzz-struct/text-field.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -57,7 +57,7 @@
#
def text(name, length, *rest)
opts = parse_options(rest, name, TextField)
- add_field(name, length, opts)
+ add_field(name, length*8, opts)
end
end
end
Modified: topf/trunk/lib/fuzz.rb
===================================================================
--- topf/trunk/lib/fuzz.rb 2007-07-16 00:14:38 UTC (rev 10833)
+++ topf/trunk/lib/fuzz.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -93,4 +93,58 @@
return false
end
end
+
+ class Host
+ def initialize(args)
+ @type = args[:type]
+ @host = args[:host]
+ @port = args[:port]
+ @path = args[:path]
+ @http_direction = args[:http_direction]
+ @http_url = args[:http_url]
+ @object = args[:object]
+
+ @socket = connect
+ end
+
+ def fuzz
+ send @object.to_s
+ end
+
+ def send( data )
+ case @type
+ when :http
+ case @http_direction
+ when :post
+ @socket.post @http_url ,data
+ when :get
+ @socket.get @http_url, data
+ end
+ else
+ @socket.write data
+ end
+ end
+
+ def stop
+ @socket.close
+ end
+private
+ def connect
+ begin
+ case @type
+ when :tcp
+ return TCPSocket.new(@host, @port)
+ when :unix
+ return UNIXSocket.open( @path )
+ when :http
+ return Net::HTTP.new(@host, @port)
+ when :tls
+ raise "not implemented yet"
+ end
+ rescue Exception
+ puts "Exception: " + $!
+ raise
+ end
+ end
+ end
end
Modified: topf/trunk/lib/pkcs1.rb
===================================================================
--- topf/trunk/lib/pkcs1.rb 2007-07-16 00:14:38 UTC (rev 10833)
+++ topf/trunk/lib/pkcs1.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -755,10 +755,12 @@
end
+=begin
+if $0 == __FILE__
+ #pkeyfile = ARGV.shift or raise "pkey file not given"
-if $0 == __FILE__
- pkeyfile = ARGV.shift or raise "pkey file not given"
- osslkey = OpenSSL::PKey::RSA.new(File.read(pkeyfile))
+ osslkey = OpenSSL::PKey::RSA.new(1024)
+
n = osslkey.n.to_i
e = osslkey.e.to_i
d = osslkey.d.to_i
@@ -768,56 +770,58 @@
dq = osslkey.dmq1.to_i
qinv = osslkey.iqmp.to_i
- require 'pgp/hexdump'
-
+require 'hexdump'
+require 'base64'
rsapss = PKCS1::SignatureScheme::RSASSAPSS.new(Digest::SHA256, 0, PKCS1::MaskGeneration::MGF1.new(Digest::SHA1))
key = PKCS1::Key::RSA.new(n, e, d)
- puts PGP::HexDump.encode(rsapss.sign(key, "hello world"))
- exit
+# {{{
+# key2 = PKCS1::Key::RSACRTPrivateKey.new(n, d, p, q, dp, dq, qinv)
+# puts PGP::HexDump.encode(rsapss.sign_hash(key2, "hello world", "\0"*8))
- puts
-
- key2 = PKCS1::Key::RSACRTPrivateKey.new(n, d, p, q, dp, dq, qinv)
- puts PGP::HexDump.encode(rsapss.sign_hash(key2, "hello world", "\0"*8))
-
- p PKCS1::DataConversion.i2osp(65537, 3)
- p PKCS1::DataConversion.os2ip(PKCS1::DataConversion.i2osp(65537, 3))
-
+ #p Base64::b64encode PKCS1::DataConversion.i2osp(65537, 3)
+ #puts "-"*100
+ #p PKCS1::DataConversion.os2ip(PKCS1::DataConversion.i2osp(65537, 3))
+# }}}
key = PKCS1::Key::RSA.new(osslkey.n.to_i, osslkey.e.to_i, osslkey.d.to_i)
msg = "hello"
- p PKCS1::DataConversion.i2osp(PKCS1::CryptographicPrimitive.rsadp(key, PKCS1::CryptographicPrimitive.rsaep(key, PKCS1::DataConversion.os2ip(msg))), msg.size)
- p PKCS1::DataConversion.i2osp(PKCS1::CryptographicPrimitive.rsavp1(key, PKCS1::CryptographicPrimitive.rsasp1(key, PKCS1::DataConversion.os2ip(msg))), msg.size)
+ #p PKCS1::DataConversion.i2osp(PKCS1::CryptographicPrimitive.rsadp(key, PKCS1::CryptographicPrimitive.rsaep(key, PKCS1::DataConversion.os2ip(msg))), msg.size)# {{{
+ #p PKCS1::DataConversion.i2osp(PKCS1::CryptographicPrimitive.rsavp1(key, PKCS1::CryptographicPrimitive.rsasp1(key, PKCS1::DataConversion.os2ip(msg))), msg.size)
- p PKCS1::MaskGeneration.mgf1("abc", 20)
- p PKCS1::MaskGeneration.mgf1("abcd", 20)
-
+ #p PKCS1::MaskGeneration.mgf1("abc", 20)
+ #p PKCS1::MaskGeneration.mgf1("abcd", 20)
+# }}}
pss = PKCS1::SignatureEncoding::EMSAPSS.new(Digest::SHA1, 8)
- p pss.encode("hello", 1023)
- p pss.verify("hello", pss.encode("hello", 1023), 1023)
+ #p pss.encode("hello", 1023)# {{{
+ #p pss.verify("hello", pss.encode("hello", 1023), 1023)
- rsapss = PKCS1::SignatureScheme::RSASSAPSS.new(Digest::SHA1, 0)
- p rsapss.sign(key, "hello")
- p rsapss.verify(key, "hello", rsapss.sign(key, "hello"))
-
+ #rsapss = PKCS1::SignatureScheme::RSASSAPSS.new(Digest::SHA1, 0)
+ #p rsapss.sign(key, "hello")
+ #p rsapss.verify(key, "hello", rsapss.sign(key, "hello"))
+# }}}
msg = "foo\nbar" * 1024
hash = Digest::SHA1.digest(msg)
- p rsapss.verify_hash(key, hash, rsapss.sign_hash(key, hash))
- p rsapss.verify(key, msg, rsapss.sign_hash(key, hash))
- p rsapss.verify_hash(key, hash, rsapss.sign(key, msg))
+ #p rsapss.verify_hash(key, hash, rsapss.sign_hash(key, hash))# {{{
+ #p rsapss.verify(key, msg, rsapss.sign_hash(key, hash))
+ #p rsapss.verify_hash(key, hash, rsapss.sign(key, msg))
- exit
-
- p PKCS1::SignatureEncoding.emsa_pkcs1_v1_5_encode("foo", 128)
+ #p Base64::b64encode PKCS1::SignatureEncoding.emsa_pkcs1_v1_5_encode("foo", 128)# }}}
+ puts "-"*100
rsapkcs1 = PKCS1::SignatureScheme::RSASSAPKCS1v1_5.new(Digest::SHA1)
- p rsapkcs1.sign(key, "hello")
- p rsapkcs1.verify(key, "hello", rsapkcs1.sign(key, "hello"))
- p osslkey.sign(OpenSSL::Digest::SHA1.new, "hello")
- p osslkey.verify(OpenSSL::Digest::SHA1.new, rsapkcs1.sign(key, "hello"), "hello")
-
+ p Base64::b64encode rsapkcs1.sign(key, "hello")
+ puts "-"*100# {{{
+ #p Base64::b64encode rsapkcs1.verify(key, "hello", rsapkcs1.sign(key, "hello"))
+ puts "-"*100
+ #p Base64::b64encode osslkey.sign(OpenSSL::Digest::SHA1.new, "hello")
+ puts "-"*100
+ #p Base64::b64encode osslkey.verify(OpenSSL::Digest::SHA1.new, rsapkcs1.sign(key, "hello"), "hello")
+# }}}
rsaoaep = PKCS1::EncryptionScheme::RSAESOAEP.new(Digest::SHA1)
msg = "hello"
- p rsaoaep.encrypt(key, msg)
- p osslkey.public_encrypt(msg, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
- p osslkey.private_decrypt(rsaoaep.encrypt(key, msg), OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING) == msg
- p rsaoaep.decrypt(key, rsaoaep.encrypt(key, msg)) == msg
+# p rsaoaep.encrypt(key, msg)
+# p Base64::b64encode osslkey.public_encrypt(msg, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
+ puts "-"*100# {{{
+ #p osslkey.private_decrypt(rsaoaep.encrypt(key, msg), OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING) == msg
+ #puts "-"*100
+ #p rsaoaep.decrypt(key, rsaoaep.encrypt(key, msg)) == msg# }}}
end
+=end
Modified: topf/trunk/lib/topf.rb
===================================================================
--- topf/trunk/lib/topf.rb 2007-07-16 00:14:38 UTC (rev 10833)
+++ topf/trunk/lib/topf.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -5,5 +5,6 @@
require "fuzz-struct"
require "fuzz"
require "pkcs1"
+require "base64"
require "dir"
require "control"
Added: topf/trunk/tor-control-fuzz.rb
===================================================================
--- topf/trunk/tor-control-fuzz.rb (rev 0)
+++ topf/trunk/tor-control-fuzz.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -0,0 +1,24 @@
+require "lib/topf"
+
+require "net/http"
+require "base64"
+require "yaml"
+
+begin
+ config = YAML::load_file "config.yml"
+
+ setconf = TOPF::Control::ConfItem.new
+ setconf.keyword = "blah"
+ setconf.value = "test"
+
+ options = {
+ :object => setconf,
+ :host => config["HOST"],
+ :port => config["CONTROLPORT"],
+ :type => :tcp
+ }
+
+ fuzzer = Fuzz::Host.new( options )
+ fuzzer.send TOPF::Control::AuthenticateItem.new
+ fuzzer.fuzz
+end
Modified: topf/trunk/tor-dir-fuzz.rb
===================================================================
--- topf/trunk/tor-dir-fuzz.rb 2007-07-16 00:14:38 UTC (rev 10833)
+++ topf/trunk/tor-dir-fuzz.rb 2007-07-16 01:14:26 UTC (rev 10834)
@@ -7,34 +7,18 @@
begin
config = YAML::load_file "config.yml"
- host = config["HOST"]
- port = config["PORT"]
- keyFile = config["KEYFILE"]
+ rd = TOPF::Dir::RouterDescriptor.new( config["KEYFILE"], config["HOST"], config["PORT"] )
+
+ options = {
+ :object => rd,
+ :host => config["HOST"],
+ :port => config["DIRPORT"],
+ :type => :http,
+ :http_direction => :post,
+ :http_url => "/tor/"
+ }
- raise "option missing" if !host or !port or !keyFile
-
- reset = 0
- rd = TOPF::Dir::RouterDescriptor.new( keyFile, host, port )
- dirServer = Net::HTTP.new(host, port)
-
- begin
- puts "lets stress #{host} a bit..."
- while true
- response, body = dirServer.post "/tor/", rd.to_s
- rd.fuzz!
- if (reset += 1) == 10
- rd = TOPF::Dir::RouterDescriptor.new
- reset = 0
- end
- end
- rescue
- # something happened.. show the error-message and routerdescriptor that caused this mess..
- puts $!
-
- puts ">"*50
- puts rd.to_s
- puts ">"*50
-
- dirServer.finish
- end
+ fuzzer = Fuzz::Host.new( options )
+ fuzzer.fuzz
+ fuzzer.stop
end
More information about the tor-commits
mailing list