cryptorecord 0.9.1

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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +11 -0
  5. data/.travis.yml +14 -0
  6. data/Gemfile +11 -0
  7. data/LICENSE.txt +340 -0
  8. data/README.md +137 -0
  9. data/Rakefile +10 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/cryptorecord.gemspec +37 -0
  13. data/exe/openpgpkeysrecord +36 -0
  14. data/exe/sshfprecord +55 -0
  15. data/exe/tlsarecord +49 -0
  16. data/lib/cryptorecord.rb +5 -0
  17. data/lib/cryptorecord/.yardoc/checksums +0 -0
  18. data/lib/cryptorecord/.yardoc/complete +0 -0
  19. data/lib/cryptorecord/.yardoc/object_types +0 -0
  20. data/lib/cryptorecord/.yardoc/objects/root.dat +0 -0
  21. data/lib/cryptorecord/.yardoc/proxy_types +0 -0
  22. data/lib/cryptorecord/doc/_index.html +85 -0
  23. data/lib/cryptorecord/doc/class_list.html +51 -0
  24. data/lib/cryptorecord/doc/css/common.css +1 -0
  25. data/lib/cryptorecord/doc/css/full_list.css +58 -0
  26. data/lib/cryptorecord/doc/css/style.css +499 -0
  27. data/lib/cryptorecord/doc/file_list.html +51 -0
  28. data/lib/cryptorecord/doc/frames.html +17 -0
  29. data/lib/cryptorecord/doc/index.html +85 -0
  30. data/lib/cryptorecord/doc/js/app.js +248 -0
  31. data/lib/cryptorecord/doc/js/full_list.js +216 -0
  32. data/lib/cryptorecord/doc/js/jquery.js +4 -0
  33. data/lib/cryptorecord/doc/method_list.html +51 -0
  34. data/lib/cryptorecord/doc/top-level-namespace.html +100 -0
  35. data/lib/cryptorecord/exceptions.rb +16 -0
  36. data/lib/cryptorecord/openpgpkeys.rb +142 -0
  37. data/lib/cryptorecord/sshfp.rb +143 -0
  38. data/lib/cryptorecord/tlsa.rb +167 -0
  39. data/lib/cryptorecord/version.rb +24 -0
  40. metadata +131 -0
@@ -0,0 +1,167 @@
1
+ #--
2
+ # Copyright (C) 2018 Wolfgang Hotwagner <code@feedyourhead.at>
3
+ #
4
+ # This file is part of the cryptorecord gem
5
+ #
6
+ # This cryptorecord gem is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation; either version 2
9
+ # of the License, or (at your option) any later version.
10
+ #
11
+ # This cryptorecord gem is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this cryptorecord gem; if not, write to the
18
+ # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #++
21
+
22
+ # This module provides the api for cryptorecords
23
+ module Cryptorecord
24
+ require 'openssl'
25
+ # Cryptorecord::Tlsa-class generates
26
+ # tlsa-dns-records.
27
+ # @!attribute [r] selector
28
+ # @return [Integer] the selector
29
+ # @!attribute [r] mtype
30
+ # @return [Integer] the match-type
31
+ # @!attribute [r] usage
32
+ # @return [Integer] the usage
33
+ # @!attribute cert
34
+ # @return [String] the x509 certificate
35
+ # @!attribute host
36
+ # @return [String] the fqdn for the record
37
+ # @!attribute proto
38
+ # @return [String] the network protocol
39
+ # @!attribute port
40
+ # @return [String] the network port
41
+ class Tlsa
42
+ attr_reader :selector, :mtype, :usage, :cert
43
+ attr_accessor :host, :proto, :port
44
+
45
+ # constructor for the tlsa-object
46
+ #
47
+ # @param [Hash] args
48
+ # @option args [Integer] mtype the matching type
49
+ # @option args [Integer] selector the selector for the tlsa-record
50
+ # @option args [String] host host-part for the tlsa-record
51
+ # @option args [String] proto the network-protocol for the tlsa-record
52
+ # @option args [Integer] port the network-port for the tlsa-record
53
+ # @option args [Integer] usage the usage for this record
54
+ # @option args [String] cert the certificate as a string
55
+ def initialize(args = {})
56
+ self.mtype = args.fetch(:mtype, 1)
57
+ self.selector = args.fetch(:selector, 0)
58
+ @host = args.fetch(:host, 'localhost')
59
+ @proto = args.fetch(:proto, 'tcp')
60
+ @port = args.fetch(:port, 443)
61
+ self.usage = args.fetch(:usage, 3)
62
+ self.cert = args.fetch(:cert, nil)
63
+ end
64
+
65
+ # This setter initializes the selector
66
+ #
67
+ # @param [Integer] val Selector for the association.
68
+ # 0 = Full Cert, 1 = SubjectPublicKeyInfo
69
+ def selector=(val)
70
+ if val.to_i < 0 || val.to_i > 1
71
+ raise ArgumentError, 'Invalid selector. Has to be 0 or 1'
72
+ end
73
+ @selector = val
74
+ end
75
+
76
+ # This setter initializes the mtype
77
+ #
78
+ # @param [Integer] val The Matching Type of the association.
79
+ # 0 = Exact Match, 1 = SHA-256, 2 = SHA-512
80
+ def mtype=(val)
81
+ if val.to_i < 0 || val.to_i > 2
82
+ raise ArgumentError, 'Invalid match type.'\
83
+ 'Has to be 0,1 or 2'
84
+ end
85
+ @mtype = val
86
+ end
87
+
88
+ # This setter initializes the usage
89
+ #
90
+ # @param [Integer] val Usage for the association.
91
+ # 0 = PKIX-CA, 1 = PKIX-EE, 2 = DANE-TA, 3 = DANE-EE
92
+ # @raise Cryptorecord::ArgumentError
93
+ def usage=(val)
94
+ if val.to_i < 0 || val.to_i > 3
95
+ raise ArgumentError, 'Invalid usage. Has to be 0,1,2 or 3'
96
+ end
97
+ @usage = val
98
+ end
99
+
100
+ # this setter initializes the certificate
101
+ #
102
+ # @param [OpenSSL::X509::Certificate] val the x509 certificate
103
+ # @raise Cryptorecord::ArgumentError
104
+ def cert=(val)
105
+ unless val.is_a?(OpenSSL::X509::Certificate) || val.nil?
106
+ raise ArgumentError, 'cert has to be a OpenSSL::X509::Certificate'
107
+ end
108
+
109
+ @cert = val
110
+ end
111
+
112
+ # This function reads in the certificate from file
113
+ #
114
+ # @param [String] file path to certificate-file
115
+ def read_file(file)
116
+ data = File.read(file)
117
+ self.cert = OpenSSL::X509::Certificate.new(data)
118
+ end
119
+
120
+ # this function creates a hash-string defined by mtype and selector
121
+ # @return depending on mtype and selector a proper hash will be returned
122
+ # @raise Cryptorecord::MatchTypeError
123
+ def fingerprint
124
+ raise Cryptorecord::MatchTypeError, 'No certificate defined' if @cert.nil?
125
+
126
+ case @mtype.to_i
127
+ when 0
128
+ return bin_to_hex(msg)
129
+ when 1
130
+ return OpenSSL::Digest::SHA256.new(msg).to_s
131
+ when 2
132
+ return OpenSSL::Digest::SHA512.new(msg).to_s
133
+ end
134
+ end
135
+
136
+ # This method concats the tlsa-record
137
+ #
138
+ # @return [String] tlsa dns-record as defined in rfc6698
139
+ def to_s
140
+ "_#{@port}._#{@proto}.#{@host}. IN TLSA"\
141
+ " #{@usage} #{@selector} #{@mtype} #{fingerprint}"
142
+ end
143
+
144
+ private
145
+
146
+ # This function selects the msg to hash using the selector
147
+ #
148
+ # @return if selector = 0 it returns cert.to_der,
149
+ # if selector = 1 it returns cert.public_key.to_der
150
+ def msg
151
+ case @selector.to_i
152
+ when 0
153
+ @cert.to_der
154
+ when 1
155
+ @cert.public_key.to_der
156
+ end
157
+ end
158
+
159
+ # This helper-function converts binary data into hex
160
+ #
161
+ # @param [String] str Binary-string
162
+ # @return hex-string
163
+ def bin_to_hex(str)
164
+ str.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,24 @@
1
+ #--
2
+ # Copyright (C) 2018 Wolfgang Hotwagner <code@feedyourhead.at>
3
+ #
4
+ # This file is part of the cryptorecord gem
5
+ #
6
+ # This cryptorecord gem is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation; either version 2
9
+ # of the License, or (at your option) any later version.
10
+ #
11
+ # This cryptorecord gem is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this cryptorecord gem; if not, write to the
18
+ # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #++
21
+ module Cryptorecord
22
+ # Guess what..
23
+ VERSION = '0.9.1'.freeze
24
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cryptorecord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ platform: ruby
6
+ authors:
7
+ - Wolfgang Hotwagner
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-07 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: "This gem provides an API and scripts for creating crypto-related dns-records(e.g.
56
+ DANE). \nAt the moment the following records are supported:\n * TLSA\n * SSHFP\n
57
+ \ * OPENPGPKEYS\n\nThis API does not create nor provide any public keys or certificates.
58
+ It uses existing keys\nto create the dns-records.\n"
59
+ email:
60
+ - code@feedyourhead.at
61
+ executables:
62
+ - openpgpkeysrecord
63
+ - sshfprecord
64
+ - tlsarecord
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".rspec"
70
+ - ".rubocop.yml"
71
+ - ".travis.yml"
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/console
77
+ - bin/setup
78
+ - cryptorecord.gemspec
79
+ - exe/openpgpkeysrecord
80
+ - exe/sshfprecord
81
+ - exe/tlsarecord
82
+ - lib/cryptorecord.rb
83
+ - lib/cryptorecord/.yardoc/checksums
84
+ - lib/cryptorecord/.yardoc/complete
85
+ - lib/cryptorecord/.yardoc/object_types
86
+ - lib/cryptorecord/.yardoc/objects/root.dat
87
+ - lib/cryptorecord/.yardoc/proxy_types
88
+ - lib/cryptorecord/doc/_index.html
89
+ - lib/cryptorecord/doc/class_list.html
90
+ - lib/cryptorecord/doc/css/common.css
91
+ - lib/cryptorecord/doc/css/full_list.css
92
+ - lib/cryptorecord/doc/css/style.css
93
+ - lib/cryptorecord/doc/file_list.html
94
+ - lib/cryptorecord/doc/frames.html
95
+ - lib/cryptorecord/doc/index.html
96
+ - lib/cryptorecord/doc/js/app.js
97
+ - lib/cryptorecord/doc/js/full_list.js
98
+ - lib/cryptorecord/doc/js/jquery.js
99
+ - lib/cryptorecord/doc/method_list.html
100
+ - lib/cryptorecord/doc/top-level-namespace.html
101
+ - lib/cryptorecord/exceptions.rb
102
+ - lib/cryptorecord/openpgpkeys.rb
103
+ - lib/cryptorecord/sshfp.rb
104
+ - lib/cryptorecord/tlsa.rb
105
+ - lib/cryptorecord/version.rb
106
+ homepage: https://github.com/whotwagner/cryptorecord
107
+ licenses:
108
+ - GPL
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: cryptorecord is a ruby-gem that helps creating crypto-related dns-records
130
+ like tlsa/sshfp/openpgpkey
131
+ test_files: []