bendiken-cryptograph 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README +57 -0
- data/Rakefile +5 -0
- data/VERSION +1 -0
- data/bin/cryptographd +3 -0
- data/lib/cryptograph.rb +6 -0
- data/lib/cryptograph/gateway.rb +7 -0
- data/lib/cryptograph/gateway/http.rb +34 -0
- data/lib/cryptograph/gateway/smtp.rb +78 -0
- data/lib/cryptograph/gateway/xmpp.rb +95 -0
- data/lib/cryptograph/version.rb +11 -0
- metadata +82 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Arto Bendiken <http://ar.to/>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= Cryptograph.rb
|
2
|
+
|
3
|
+
This is the pure-Ruby reference implementation of a Cryptograph node,
|
4
|
+
including gateway daemons for XMPP, SMTP and HTTP.
|
5
|
+
|
6
|
+
|
7
|
+
== Documentation
|
8
|
+
|
9
|
+
* http://cryptograph.rubyforge.org
|
10
|
+
|
11
|
+
|
12
|
+
== Download
|
13
|
+
|
14
|
+
To get a local working copy of the development repository, do:
|
15
|
+
|
16
|
+
% git clone git://github.com/bendiken/cryptograph.git
|
17
|
+
|
18
|
+
Alternatively, you can download the latest development version as a tarball
|
19
|
+
as follows:
|
20
|
+
|
21
|
+
% wget http://github.com/bendiken/cryptograph/tarball/master
|
22
|
+
|
23
|
+
|
24
|
+
== Requirements
|
25
|
+
|
26
|
+
* OpenPGP.rb
|
27
|
+
* http://openpgp.rubyforge.org
|
28
|
+
* EventMachine (only needed for the SMTP gateway)
|
29
|
+
* http://rubyeventmachine.com
|
30
|
+
* Rack (only needed for the HTTP gateway)
|
31
|
+
* http://rack.github.com
|
32
|
+
* XMPP4R (only needed for the XMPP gateway)
|
33
|
+
* http://home.gna.org/xmpp4r
|
34
|
+
|
35
|
+
|
36
|
+
== Installation
|
37
|
+
|
38
|
+
The recommended installation method is via RubyGems. To install the latest
|
39
|
+
official release from RubyForge, do:
|
40
|
+
|
41
|
+
% [sudo] gem install cryptograph
|
42
|
+
|
43
|
+
To use the very latest bleeding-edge development version, install the gem
|
44
|
+
directly from GitHub as follows:
|
45
|
+
|
46
|
+
% [sudo] gem install bendiken-cryptograph -s http://gems.github.com
|
47
|
+
|
48
|
+
|
49
|
+
== Authors
|
50
|
+
|
51
|
+
* Arto Bendiken (mailto:arto.bendiken@gmail.com) - http://ar.to
|
52
|
+
|
53
|
+
|
54
|
+
== License
|
55
|
+
|
56
|
+
All source code is available under the terms of the MIT license. For more
|
57
|
+
information, see the accompanying LICENSE file.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/cryptographd
ADDED
data/lib/cryptograph.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
require 'rack/response'
|
3
|
+
|
4
|
+
module Cryptograph class Gateway
|
5
|
+
class HTTP < Gateway
|
6
|
+
def self.run(options = {})
|
7
|
+
require 'rack'
|
8
|
+
require 'rack/showexceptions'
|
9
|
+
|
10
|
+
app = Rack::ShowExceptions.new(Rack::Lint.new(self.new))
|
11
|
+
app = Rack::URLMap.new((options[:path] || '/').to_s => app)
|
12
|
+
Rack::Handler::WEBrick.run app, :Port => options[:port]
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
request = Rack::Request.new(env)
|
17
|
+
response = Rack::Response.new do |response|
|
18
|
+
if request.post? || true # FIXME
|
19
|
+
# TODO
|
20
|
+
response.status = 200
|
21
|
+
response['Content-Type'] = 'text/plain'
|
22
|
+
response.write "OK"
|
23
|
+
else
|
24
|
+
response.status = 404
|
25
|
+
response['Content-Type'] = 'text/plain'
|
26
|
+
response.write "Not Found"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
response.finish
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end end
|
33
|
+
|
34
|
+
Cryptograph::Gateway::HTTP.run(:port => 6780, :path => '/') if $0 == __FILE__
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
module Cryptograph class Gateway
|
4
|
+
class SMTP < EM::Protocols::SmtpServer
|
5
|
+
def self.run(options = {})
|
6
|
+
EM.run do
|
7
|
+
EM.start_server options[:hostname] || '127.0.0.1', options[:port], self
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
# The greeting returned in the initial connection message to the client.
|
16
|
+
def get_server_greeting
|
17
|
+
"Cryptograph SMTP Gateway"
|
18
|
+
end
|
19
|
+
|
20
|
+
# The domain name returned in the first line of the response to a
|
21
|
+
# successful EHLO or HELO command.
|
22
|
+
def get_server_domain
|
23
|
+
super # TODO
|
24
|
+
end
|
25
|
+
|
26
|
+
# ...
|
27
|
+
def receive_ehlo_domain(domain)
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
# ...
|
32
|
+
def receive_plain_auth(user, password)
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
# Triggered when the client calls EHLO/HELO or RSET.
|
37
|
+
def receive_transaction
|
38
|
+
# TODO
|
39
|
+
end
|
40
|
+
|
41
|
+
# Triggered when the client issues the RSET command.
|
42
|
+
def receive_reset
|
43
|
+
# TODO
|
44
|
+
end
|
45
|
+
|
46
|
+
# Receives the argument of the MAIL FROM command.
|
47
|
+
def receive_sender(from)
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
# Receives the argument of a RCPT TO command.
|
52
|
+
def receive_recipient(to)
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
# Triggered when the client sends the DATA command.
|
57
|
+
def receive_data_command
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
# Triggered when data from the client is available.
|
62
|
+
def receive_data_chunk(data)
|
63
|
+
# TODO
|
64
|
+
end
|
65
|
+
|
66
|
+
# Triggered after a message has been completely received.
|
67
|
+
def receive_message
|
68
|
+
true # accept message
|
69
|
+
end
|
70
|
+
|
71
|
+
# Triggered when the client has ended the connection.
|
72
|
+
def connection_ended
|
73
|
+
#EM.stop
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end end
|
77
|
+
|
78
|
+
Cryptograph::Gateway::SMTP.run(:port => 6725) if $0 == __FILE__
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'xmpp4r'
|
2
|
+
require 'xmpp4r/roster'
|
3
|
+
|
4
|
+
module Cryptograph class Gateway
|
5
|
+
class XMPP < Gateway
|
6
|
+
include Jabber
|
7
|
+
|
8
|
+
attr_accessor :jid
|
9
|
+
attr_accessor :options
|
10
|
+
|
11
|
+
def self.run(options = {})
|
12
|
+
self.new(options[:jid], options[:password], options).run
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(jid, password, options = {})
|
16
|
+
Jabber::debug = true if options[:debug]
|
17
|
+
|
18
|
+
@options = options
|
19
|
+
connect(jid, password)
|
20
|
+
end
|
21
|
+
|
22
|
+
def connected?
|
23
|
+
@client && @client.is_connected?
|
24
|
+
end
|
25
|
+
|
26
|
+
def connect(jid, password)
|
27
|
+
@jid = JID.new(jid)
|
28
|
+
@client = Client.new(@jid)
|
29
|
+
@client.connect
|
30
|
+
@client.auth(password)
|
31
|
+
|
32
|
+
initialize_roster
|
33
|
+
initialize_messaging
|
34
|
+
send_status(:available, options[:status])
|
35
|
+
|
36
|
+
@client.on_exception do |exception, *args|
|
37
|
+
connect(jid, password)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def disconnect
|
42
|
+
@client.close if connected?
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize_roster
|
46
|
+
@roster = Roster::Helper.new(@client)
|
47
|
+
@roster.wait_for_roster
|
48
|
+
@roster.add_subscription_request_callback() do |item, presence|
|
49
|
+
@roster.accept_subscription(presence.from)
|
50
|
+
send_subscription(presence.from) if @roster.find(presence.from).empty?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize_messaging
|
55
|
+
@client.add_message_callback do |msg|
|
56
|
+
send_chat(msg.from, 'Message received and stored.')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def run
|
61
|
+
Thread.stop
|
62
|
+
end
|
63
|
+
|
64
|
+
def start_keepalive
|
65
|
+
Thread.new do
|
66
|
+
loop { send_presence; sleep options[] || 30 }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def send_presence
|
71
|
+
@client.send(Presence.new)
|
72
|
+
end
|
73
|
+
|
74
|
+
def send_status(type, status = nil)
|
75
|
+
@client.send(Presence.new.set_type(type.to_sym).set_status(status.to_s))
|
76
|
+
end
|
77
|
+
|
78
|
+
def send_subscription(jid)
|
79
|
+
@client.send(Presence.new.set_type(:subscribe).set_to(jid))
|
80
|
+
end
|
81
|
+
|
82
|
+
def send_chat(jid, body)
|
83
|
+
@client.send(Message.new(jid, body).set_type(:chat))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end end
|
87
|
+
|
88
|
+
if $0 == __FILE__
|
89
|
+
Cryptograph::Gateway::XMPP.run({
|
90
|
+
:jid => "#{ARGV.shift}/cryptograph",
|
91
|
+
:password => ARGV.shift,
|
92
|
+
:status => 'Ready to disseminate cryptography',
|
93
|
+
:debug => true,
|
94
|
+
})
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bendiken-cryptograph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arto Bendiken
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-19 00:00:00 -07:00
|
13
|
+
default_executable: cryptographd
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rakefile
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: openpgp
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: ""
|
36
|
+
email: arto.bendiken@gmail.com
|
37
|
+
executables:
|
38
|
+
- cryptographd
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- README
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- bin/cryptographd
|
49
|
+
- lib/cryptograph.rb
|
50
|
+
- lib/cryptograph/gateway.rb
|
51
|
+
- lib/cryptograph/gateway/http.rb
|
52
|
+
- lib/cryptograph/gateway/smtp.rb
|
53
|
+
- lib/cryptograph/gateway/xmpp.rb
|
54
|
+
- lib/cryptograph/version.rb
|
55
|
+
has_rdoc: false
|
56
|
+
homepage: http://github.com/bendiken/cryptograph
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.8.2
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project: cryptograph
|
77
|
+
rubygems_version: 1.2.0
|
78
|
+
signing_key:
|
79
|
+
specification_version: 2
|
80
|
+
summary: The Cryptograph reference implementation.
|
81
|
+
test_files: []
|
82
|
+
|