router_crypt 0.3.1 → 0.4.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27c72c9db801e1733ea262975a6057782fc5351b
4
+ data.tar.gz: 60f4d105d9b314e5a8991321bd7a83f081a6590a
5
+ SHA512:
6
+ metadata.gz: 98c8aac4fa9fbc0e7de60ab4f6c67480dc84db69f050f38b67ac1ea11e47bf4d7cbf25d0f2d25a702be35bc653554605f858ad9eb56d6c20c74764450d0c108b
7
+ data.tar.gz: d78ee283d8a74445ffb368b9a9fcdfab392bddecd830c2bf2d06f32a399f60409f288045a9a1ab3e1611c07533d884701e64354c2a850e8bb217fd000df33378
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- group :test do
2
- gem 'rspec'
3
- end
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -1,17 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ router_crypt (0.4.0)
5
+ slop (~> 4.4)
6
+
1
7
  GEM
8
+ remote: https://rubygems.org/
2
9
  specs:
3
- diff-lcs (1.2.1)
4
- rspec (2.13.0)
5
- rspec-core (~> 2.13.0)
6
- rspec-expectations (~> 2.13.0)
7
- rspec-mocks (~> 2.13.0)
8
- rspec-core (2.13.0)
9
- rspec-expectations (2.13.0)
10
- diff-lcs (>= 1.1.3, < 2.0)
11
- rspec-mocks (2.13.0)
10
+ diff-lcs (1.2.5)
11
+ rake (10.5.0)
12
+ rspec (3.5.0)
13
+ rspec-core (~> 3.5.0)
14
+ rspec-expectations (~> 3.5.0)
15
+ rspec-mocks (~> 3.5.0)
16
+ rspec-core (3.5.4)
17
+ rspec-support (~> 3.5.0)
18
+ rspec-expectations (3.5.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.5.0)
21
+ rspec-mocks (3.5.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-support (3.5.0)
25
+ slop (4.4.1)
12
26
 
13
27
  PLATFORMS
14
28
  ruby
15
29
 
16
30
  DEPENDENCIES
31
+ rake
32
+ router_crypt!
17
33
  rspec
34
+
35
+ BUNDLED WITH
36
+ 1.11.2
@@ -1,5 +1,6 @@
1
1
  begin
2
2
  require 'bundler'
3
+ require 'bundler/gem_tasks'
3
4
  require 'rspec/core/rake_task'
4
5
  Bundler.setup
5
6
  rescue LoadError
@@ -9,6 +10,7 @@ end
9
10
 
10
11
 
11
12
  gemspec = eval(File.read(Dir['*.gemspec'].first))
13
+ file = [gemspec.name, gemspec.version].join('-') + '.gem'
12
14
 
13
15
  desc 'Validate the gemspec'
14
16
  task :gemspec do
@@ -17,20 +19,19 @@ end
17
19
 
18
20
  RSpec::Core::RakeTask.new(:spec)
19
21
 
20
-
21
- desc "Build gem locally"
22
- task :build => %i(spec gemspec) do
23
- system "gem build #{gemspec.name}.gemspec"
24
- FileUtils.mkdir_p "gems"
25
- FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", "gems"
26
- end
27
-
28
- desc "Install gem locally"
29
- task :install => :build do
30
- system "sudo sh -c \'umask 022; gem20 install gems/#{gemspec.name}-#{gemspec.version}\'"
31
- end
32
-
33
22
  desc "Clean automatically generated files"
34
23
  task :clean do
35
24
  FileUtils.rm_rf "gems"
36
25
  end
26
+
27
+ desc 'Tag the release'
28
+ task :tag do
29
+ system "git tag #{gemspec.version}"
30
+ end
31
+
32
+ desc 'Push to rubygems'
33
+ task :push => :tag do
34
+ system "gem push pkg/#{file}"
35
+ end
36
+
37
+ task default: :spec
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'router_crypt'
3
+ require_relative '../lib/router_crypt'
4
4
 
5
5
  begin
6
6
  p RouterCrypt::CLI.run
7
7
  rescue => e
8
8
  warn "ERROR: #{e}"
9
+ #raise
9
10
  end
@@ -1,17 +1,43 @@
1
+ require 'slop'
2
+ require 'pp'
3
+
4
+
1
5
  class RouterCrypt::CLI
2
6
  class << self
3
7
  def run
4
- ARGV[0] or raise ArgumentError, 'no password given'
5
- pw = ARGV[0].dup
6
- case pw
7
- when /^\$9\$/
8
- RouterCrypt::JunOS.decrypt pw
9
- when /^[\dA-F]+$/
10
- RouterCrypt::IOS.decrypt pw
11
- else
12
- #presume it's NXOS, no clear way to separate garbage and NXOS PW
13
- RouterCrypt::NXOS.decrypt pw
8
+ opts=opts_parse.to_hash
9
+ #ARGV[0] or raise ArgumentError, 'no password given'
10
+
11
+ if opts[:junipercrypt]
12
+ pw=opts[:junipercrypt]
13
+ if opts[:salt]
14
+ RouterCrypt::JunOS.crypt(opts[:junipercrypt], opts[:salt])
15
+ else
16
+ RouterCrypt::JunOS.crypt opts[:junipercrypt]
17
+ end
18
+ elsif opts [:decrypt]
19
+ pw=opts[:decrypt].dup
20
+ case pw
21
+ when /^\$9\$/
22
+ RouterCrypt::JunOS.decrypt pw
23
+ when /^[\dA-F]+$/
24
+ RouterCrypt::IOS.decrypt pw
25
+ else
26
+ #presume it's NXOS, no clear way to separate garbage and NXOS PW
27
+ RouterCrypt::NXOS.decrypt pw
28
+ end
14
29
  end
15
30
  end
31
+
32
+ def opts_parse
33
+ Slop.parse do |o|
34
+ o.on '-h', '--help' do puts o; exit; end
35
+ o.bool '-D', '--debug', 'turn on debugging'
36
+ o.string '-j', '--junipercrypt', 'crypt Juniper'
37
+ o.string '-s', '--salt', 'salt for crypt'
38
+ o.string '-d', '--decrypt', 'decrypt'
39
+ end
40
+ end
41
+
16
42
  end
17
43
  end
@@ -1,40 +1,77 @@
1
1
  class RouterCrypt::JunOS
2
2
  class InvalidPW < StandardError; end
3
-
3
+
4
4
  ENCODE = [
5
- [ 1, 4, 32 ],
6
- [ 1, 16, 32 ],
7
- [ 1, 8, 32 ],
8
- [ 1, 64 ],
9
- [ 1, 32 ],
10
- [ 1, 4, 16, 128 ],
11
- [ 1, 32, 64 ],
5
+ [ 1, 4, 32 ],
6
+ [ 1, 16, 32 ],
7
+ [ 1, 8, 32 ],
8
+ [ 1, 64 ],
9
+ [ 1, 32 ],
10
+ [ 1, 4, 16, 128 ],
11
+ [ 1, 32, 64 ],
12
12
  ]
13
13
  EXTRA = {}
14
14
  KEY = %w( QzF3n6/9CAtpu0O B1IREhcSyrleKvMW8LXx 7N-dVbwsY2g4oaJZGUDj iHkq.mPf5T )
15
15
  KEYCHAR = KEY.join.each_char.to_a
16
+ CHARKEY = {}
17
+ for q in 0..(KEYCHAR.length - 1)
18
+ CHARKEY[KEYCHAR[q]] = q;
19
+ end
16
20
  KEY.each_with_index do |key, index|
17
21
  key.each_char { |c| EXTRA[c] = 3-index }
18
22
  end
19
-
23
+
20
24
  class << self
21
-
22
- private
23
-
25
+
26
+ private
27
+
24
28
  def nibble str, len
25
29
  nib, str[0..len-1] = str[0..len-1], ''
26
30
  nib.size == len or raise InvalidPW, 'Insufficent amont of characters'
27
31
  nib
28
32
  end
29
-
33
+
30
34
  def gap c1, c2
31
- (KEYCHAR.index(c1) - KEYCHAR.index(c2)) % KEYCHAR.size - 1
35
+ (KEYCHAR.index(c1) - KEYCHAR.index(c2)) % KEYCHAR.size - 1
32
36
  end
33
-
37
+
34
38
  def gap_decode gaps, dec
35
39
  gaps.size == dec.size or raise InvalidPW, 'gaps and dec are unequal size'
36
40
  (gaps.each_with_index.inject(0) { |num, (e, index)| num + e * dec[index] } % 256).chr
37
41
  end
38
-
42
+
43
+ ## return a random number of characters from our alphabet
44
+ def randc cnt
45
+ r = ''
46
+ while cnt>0
47
+ r << KEYCHAR[(rand KEYCHAR.length).to_i]
48
+ cnt-=1
49
+ end
50
+ r
51
+ end
52
+
53
+ ## encode a plain-text character with a series of gaps,
54
+ ## according to the current encoder.
55
+ def gap_encode pc,prev,enc
56
+ ord = pc.ord
57
+
58
+ crypt = ''
59
+ gaps=[]
60
+
61
+ enc.reverse.each do |x|
62
+ gaps.unshift (ord/x).to_i
63
+ ord %= x
64
+ end
65
+
66
+ gaps.each do |gap|
67
+ gap += CHARKEY[prev]+1
68
+ c = KEYCHAR[gap % KEYCHAR.length]
69
+ prev = c
70
+ crypt<<c
71
+ end
72
+
73
+ crypt
74
+ end
75
+
39
76
  end
40
77
  end
@@ -0,0 +1,26 @@
1
+ class RouterCrypt::JunOS
2
+ class << self
3
+ # Encrypts JunOS $9$ style passwords. This is reimplementation of CPAN
4
+ # Crypt::Juniper (by Kevin Brintnall, <kbrint at rufus.net>) ''juniper_crypt' function
5
+ #
6
+ # @param [String] the plaintext string
7
+ # @return [String] the encrypted string
8
+ def crypt (plaintext, *opts)
9
+ salt = opts[0] ? opts[0][0] : randc(1)
10
+ rand = randc(EXTRA[salt])
11
+
12
+ prev = salt
13
+ crypt="$9$"
14
+ crypt<<salt
15
+ crypt<<rand
16
+
17
+ plaintext.chars.each_with_index do |p, pos|
18
+ encode = ENCODE[ pos % ENCODE.length]
19
+ crypt<< gap_encode(p, prev, encode)
20
+ prev = crypt[crypt.size-1]
21
+ end
22
+
23
+ crypt
24
+ end
25
+ end
26
+ end
@@ -1,10 +1,11 @@
1
1
  class RouterCrypt
2
2
  end
3
3
 
4
- require 'junos/common'
5
- require 'junos/decrypt'
6
- require 'ios/common'
7
- require 'ios/decrypt'
8
- require 'nxos/common'
9
- require 'nxos/decrypt'
10
- require 'cli/cli'
4
+ require_relative 'junos/common'
5
+ require_relative 'junos/decrypt'
6
+ require_relative 'junos/crypt'
7
+ require_relative 'ios/common'
8
+ require_relative 'ios/decrypt'
9
+ require_relative 'nxos/common'
10
+ require_relative 'nxos/decrypt'
11
+ require_relative 'cli/cli'
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'router_crypt'
3
- s.version = '0.3.1'
3
+ s.version = '0.4.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ 'Saku Ytti' ]
6
6
  s.email = %w( saku@ytti.fi )
@@ -12,4 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.executables = %w( rtrcrypt )
13
13
  s.require_path = 'lib'
14
14
  s.required_rubygems_version = '>= 1.3.6'
15
+ s.add_runtime_dependency 'slop', '~> 4.4'
16
+ s.add_development_dependency 'rake'
17
+ s.add_development_dependency 'rspec'
15
18
  end
@@ -4,6 +4,6 @@ require 'router_crypt'
4
4
  describe RouterCrypt::IOS, '#decrypt' do
5
5
  it 'returns correct decrypted password' do
6
6
  clear = RouterCrypt::IOS.decrypt CRYPT_IOS
7
- clear.should eq CLEAR
7
+ expect(clear).to eq CLEAR
8
8
  end
9
9
  end
@@ -5,35 +5,35 @@ describe RouterCrypt::JunOS, '#nibble' do
5
5
  it 'returns k for 1 char out of "kakka"' do
6
6
  str = 'kakka'
7
7
  nib = RouterCrypt::JunOS.send :nibble, str, 1
8
- nib.should eq 'k'
9
- str.should eq 'akka'
8
+ expect(nib).to eq 'k'
9
+ expect(str).to eq 'akka'
10
10
  end
11
11
  it 'returns kak for 3 char out of "kakka"' do
12
12
  str = 'kakka'
13
13
  nib = RouterCrypt::JunOS.send :nibble, str, 3
14
- nib.should eq 'kak'
15
- str.should eq 'ka'
14
+ expect(nib).to eq 'kak'
15
+ expect(str).to eq 'ka'
16
16
  end
17
17
  end
18
18
 
19
19
  describe RouterCrypt::JunOS, '#gap' do
20
20
  it 'returns 7 for gap between k and J' do
21
21
  gap = RouterCrypt::JunOS.send :gap, 'k', 'J'
22
- gap.should eq 7
22
+ expect(gap).to eq 7
23
23
  end
24
24
  it 'returns 56 for gap between J and k' do
25
25
  gap = RouterCrypt::JunOS.send :gap, 'J', 'k'
26
- gap.should eq 56
26
+ expect(gap).to eq 56
27
27
  end
28
28
  end
29
29
 
30
30
  describe RouterCrypt::JunOS, "#gaps" do
31
31
  it 'returns ) for [gaps], [dec]' do
32
32
  chr = RouterCrypt::JunOS.send :gap_decode, RouterCrypt::JunOS::ENCODE[1], [9, 42, 12]
33
- chr.should eq ')'
33
+ expect(chr).to eq ')'
34
34
  end
35
35
  it 'returns n for [gaps2], [dec2]' do
36
36
  chr = RouterCrypt::JunOS.send :gap_decode, RouterCrypt::JunOS::ENCODE[5], [42, 69, 99, 4]
37
- chr.should eq 'n'
37
+ expect(chr).to eq 'n'
38
38
  end
39
39
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'router_crypt'
3
+
4
+ describe RouterCrypt::JunOS, '#crypt' do
5
+ it 'returns correct crypted password' do
6
+ crypt = RouterCrypt::JunOS.crypt CLEAR
7
+ clear = RouterCrypt::JunOS.decrypt crypt
8
+ expect(clear).to eq CLEAR
9
+ end
10
+ end
@@ -4,6 +4,6 @@ require 'router_crypt'
4
4
  describe RouterCrypt::JunOS, '#decrypt' do
5
5
  it 'returns correct decrypted password' do
6
6
  clear = RouterCrypt::JunOS.decrypt CRYPT_JUNOS
7
- clear.should eq CLEAR
7
+ expect(clear).to eq CLEAR
8
8
  end
9
9
  end
@@ -4,6 +4,6 @@ require 'router_crypt'
4
4
  describe RouterCrypt::NXOS, '#decrypt' do
5
5
  it 'returns correct decrypted password' do
6
6
  clear = RouterCrypt::NXOS.decrypt CRYPT_NXOS
7
- clear.should eq CLEAR
7
+ expect(clear).to eq CLEAR
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,16 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: router_crypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Saku Ytti
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-07 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
14
55
  description: Library and binary which decrypt (crypt unimplemented) Juniper JunOS
15
56
  $9$, Cisco IOS type 7 and Cisco NX-OS passwords
16
57
  email:
@@ -20,52 +61,50 @@ executables:
20
61
  extensions: []
21
62
  extra_rdoc_files: []
22
63
  files:
23
- - .gitignore
24
- - .rspec
64
+ - ".gitignore"
65
+ - ".rspec"
25
66
  - Gemfile
26
67
  - Gemfile.lock
27
68
  - README.md
69
+ - Rakefile
28
70
  - bin/rtrcrypt
29
71
  - lib/cli/cli.rb
30
72
  - lib/ios/common.rb
31
73
  - lib/ios/decrypt.rb
32
74
  - lib/junos/common.rb
75
+ - lib/junos/crypt.rb
33
76
  - lib/junos/decrypt.rb
34
77
  - lib/nxos/common.rb
35
78
  - lib/nxos/decrypt.rb
36
79
  - lib/router_crypt.rb
37
- - rakefile
38
80
  - router_crypt.gemspec
39
81
  - spec/ios/decrypt_spec.rb
40
82
  - spec/junos/common_spec.rb
83
+ - spec/junos/crypt_spec.rb
41
84
  - spec/junos/decrypt_spec.rb
42
85
  - spec/nxos/decrypt_spec.rb
43
86
  - spec/spec_helper.rb
44
87
  homepage: http://github.com/ytti/router_crypt
45
88
  licenses: []
89
+ metadata: {}
46
90
  post_install_message:
47
91
  rdoc_options: []
48
92
  require_paths:
49
93
  - lib
50
94
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
95
  requirements:
53
- - - '>='
96
+ - - ">="
54
97
  - !ruby/object:Gem::Version
55
98
  version: '0'
56
- segments:
57
- - 0
58
- hash: -1168524170456204524
59
99
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
100
  requirements:
62
- - - '>='
101
+ - - ">="
63
102
  - !ruby/object:Gem::Version
64
103
  version: 1.3.6
65
104
  requirements: []
66
105
  rubyforge_project: router_crypt
67
- rubygems_version: 1.8.25
106
+ rubygems_version: 2.5.2
68
107
  signing_key:
69
- specification_version: 3
108
+ specification_version: 4
70
109
  summary: Crypt library for JunOS/IOS/NX-OS passwords
71
110
  test_files: []