ircdh1080 0.1.0
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/.gitignore +10 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ircdh1080.gemspec +28 -0
- data/lib/ircdh1080.rb +45 -0
- data/lib/ircdh1080/base64.rb +71 -0
- data/lib/ircdh1080/version.rb +3 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66aaeeddcec29c9b7710887f2617dd9ed31b4ce6
|
4
|
+
data.tar.gz: a63b2f1b880a692e59908aa454e9c16eda022724
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c71eaa440ab74f02fd5705944e9720796b86b85818ad99b15fed47f169f8812719ea85e522124ff716c863b5dcdc50d150199670adbb9519ec3d69cfb52d31f6
|
7
|
+
data.tar.gz: 2e6245b64f3c34b21881e355f628c2b42656d204288e4d916142ed373ca60afd636119b0eca6bb4294aecb91ca9dfa39eff0ff3ab891e3a2b6c346664c53f774
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Jason Iverson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# IrcDH1080
|
2
|
+
|
3
|
+
A Ruby module for handling DH1080 key exchange for IRC.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ircdh1080'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ircdh1080
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
dh = IrcDH1080.new
|
25
|
+
pub_key = dh.pub_key
|
26
|
+
|
27
|
+
# IRC DH1080 Base64 encoded public key
|
28
|
+
peer_key = '...'
|
29
|
+
|
30
|
+
shared_secret = dh.compute_key peer_key
|
31
|
+
```
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/JasonIverson/ircdh1080-ruby.
|
42
|
+
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
47
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ircdh1080"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/ircdh1080.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ircdh1080/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ircdh1080"
|
8
|
+
spec.version = IrcDH1080::VERSION
|
9
|
+
spec.authors = ["Jason Iverson"]
|
10
|
+
spec.email = ["iverson.jason.code@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby Diffie-Hellman 1080 Key-Exchange Module for IRC}
|
13
|
+
spec.description = %q{A Ruby module for handling DH1080 key exchange for IRC}
|
14
|
+
spec.homepage = "https://github.com/JasonIverson/ircdh1080-ruby/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.test_files = `git ls-files -z {test,spec,features}/*`.split("\x0")
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
|
27
|
+
spec.requirements << 'openssl'
|
28
|
+
end
|
data/lib/ircdh1080.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "ircdh1080/version"
|
2
|
+
require "ircdh1080/base64"
|
3
|
+
|
4
|
+
require "openssl"
|
5
|
+
|
6
|
+
class IrcDH1080
|
7
|
+
# @return [String] Our public key pre-encoded for sending to others
|
8
|
+
attr_reader :pub_key
|
9
|
+
|
10
|
+
# Initializes the DH1080 object
|
11
|
+
# @note The public/private keys are randomly generated with each call of IrcDH1080.new and remains the same for the duration of the object
|
12
|
+
def initialize
|
13
|
+
# p = 0xFBE1022E23D213E8ACFA9AE8B9DFADA3EA6B7AC7A7B7E95AB5EB2DF858921
|
14
|
+
# FEADE95E6AC7BE7DE6ADBAB8A783E7AF7A7FA6A2B7BEB1E72EAE2B72F9FA2
|
15
|
+
# BFB2A2EFBEFAC868BADB3E828FA8BADFADA3E4CC1BE7E8AFE85E9698A783E
|
16
|
+
# B68FA07A77AB6AD7BEB618ACF9CA2897EB28A6189EFA07AB99A8A7FA9AE29
|
17
|
+
# 9EFA7BA66DEAFEFBEFBF0B7D8B
|
18
|
+
# g = 2
|
19
|
+
# 1080bit
|
20
|
+
|
21
|
+
# The p and g used in the IRC DH1080 protocol stored in pem format to speed
|
22
|
+
# up Diffie-Hellman initialization
|
23
|
+
pem = "-----BEGIN DH PARAMETERS-----\n" \
|
24
|
+
"MIGOAoGIAPvhAi4j0hPorPqa6LnfraPqa3rHp7fpWrXrLfhYkh/q3pXmrHvn3mrb\n" \
|
25
|
+
"q4p4Pnr3p/pqK3vrHnLq4rcvn6K/sqLvvvrIaLrbPoKPqLrfraPkzBvn6K/oXpaY\n" \
|
26
|
+
"p4PraPoHp3q2rXvrYYrPnKKJfrKKYYnvoHq5mop/qa4pnvp7pm3q/vvvvwt9iwIB\n" \
|
27
|
+
"Ag==\n" \
|
28
|
+
"-----END DH PARAMETERS-----\n"
|
29
|
+
|
30
|
+
@dh = OpenSSL::PKey::DH.new pem
|
31
|
+
@dh.generate_key!
|
32
|
+
|
33
|
+
# Store the public key pre-encoded. This is what we send to others.
|
34
|
+
@pub_key = IrcDH1080::Base64.encode(@dh.pub_key.to_s(2))
|
35
|
+
end
|
36
|
+
|
37
|
+
# Computes the shared secret key
|
38
|
+
# @param key [String] the base64 encoded key sent by the other user
|
39
|
+
# @return [String] the shared secret key
|
40
|
+
def compute_key(key)
|
41
|
+
peer_key = OpenSSL::BN.new(IrcDH1080::Base64.decode(key), 2)
|
42
|
+
secret = @dh.compute_key(peer_key)
|
43
|
+
IrcDH1080::Base64.encode(OpenSSL::Digest::SHA256.digest(secret))
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class IrcDH1080
|
2
|
+
module Base64
|
3
|
+
B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.freeze
|
4
|
+
|
5
|
+
def self.encode(bin)
|
6
|
+
str = ''
|
7
|
+
|
8
|
+
i, j, t, m = 0, 0, 0, 0x80
|
9
|
+
l = bin.bytesize * 8
|
10
|
+
|
11
|
+
while i < l
|
12
|
+
t |= 1 unless bin[i>>3].ord & m == 0
|
13
|
+
j += 1
|
14
|
+
m >>= 1
|
15
|
+
m = 0x80 if m == 0
|
16
|
+
|
17
|
+
if j % 6 == 0
|
18
|
+
str += B64[t]
|
19
|
+
t &= 0
|
20
|
+
end
|
21
|
+
|
22
|
+
t = (t << 1) % 0x100
|
23
|
+
i += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
m = 5 - (j % 6)
|
27
|
+
str += B64[(t << m) % 0x100] unless m == 0
|
28
|
+
str
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.decode(str)
|
32
|
+
l = str.bytesize
|
33
|
+
return str if l < 2
|
34
|
+
|
35
|
+
buf = [0] * 256
|
36
|
+
B64.each_byte.with_index { |x,i| buf[x] = i }
|
37
|
+
|
38
|
+
str.reverse.each_byte do |x,i|
|
39
|
+
break if buf[x] == 0
|
40
|
+
l -= 1
|
41
|
+
end
|
42
|
+
|
43
|
+
return str if l < 2
|
44
|
+
|
45
|
+
d = [0] * l
|
46
|
+
|
47
|
+
i, k = 0, 0
|
48
|
+
|
49
|
+
while true
|
50
|
+
break unless k + 1 < l
|
51
|
+
d[i] = (buf[str[k].ord] << 2) % 0x100
|
52
|
+
d[i] |= buf[str[k+=1].ord] >> 4
|
53
|
+
|
54
|
+
break unless k + 1 < l
|
55
|
+
i += 1
|
56
|
+
d[i] = (buf[str[k].ord] << 4) % 0x100
|
57
|
+
d[i] |= buf[str[k+=1].ord] >> 2
|
58
|
+
|
59
|
+
break unless k + 1 < l
|
60
|
+
i += 1
|
61
|
+
d[i] = (buf[str[k].ord] << 6) % 0x100
|
62
|
+
d[i] |= buf[str[k+=1].ord] % 0x100
|
63
|
+
|
64
|
+
i += 1
|
65
|
+
k += 1
|
66
|
+
end
|
67
|
+
|
68
|
+
d[0,i].map { |x| x.chr }.join('')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ircdh1080
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Iverson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A Ruby module for handling DH1080 key exchange for IRC
|
56
|
+
email:
|
57
|
+
- iverson.jason.code@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- ircdh1080.gemspec
|
72
|
+
- lib/ircdh1080.rb
|
73
|
+
- lib/ircdh1080/base64.rb
|
74
|
+
- lib/ircdh1080/version.rb
|
75
|
+
homepage: https://github.com/JasonIverson/ircdh1080-ruby/
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements:
|
94
|
+
- openssl
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.5.1
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Ruby Diffie-Hellman 1080 Key-Exchange Module for IRC
|
100
|
+
test_files: []
|