ronin-db-activerecord 0.1.6 → 0.2.0.rc1

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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +91 -0
  3. data/README.md +49 -1
  4. data/db/migrate/0037_add_created_at_column_to_ronin_ports_table.rb +40 -0
  5. data/db/migrate/0038_add_created_at_column_to_ronin_services_table.rb +40 -0
  6. data/db/migrate/0039_create_ronin_cert_names_table.rb +37 -0
  7. data/db/migrate/0040_create_ronin_cert_issuers_table.rb +52 -0
  8. data/db/migrate/0041_create_ronin_cert_subjects_table.rb +54 -0
  9. data/db/migrate/0042_create_ronin_cert_subject_alt_names_table.rb +42 -0
  10. data/db/migrate/0043_create_ronin_certs_table.rb +61 -0
  11. data/db/migrate/0044_add_cert_id_column_to_ronin_open_ports_table.rb +35 -0
  12. data/db/migrate/0045_create_ronin_notes_table.rb +120 -0
  13. data/db/migrate/0046_create_ronin_web_vulns_table.rb +61 -0
  14. data/db/migrate/0047_create_ronin_phone_numbers_table.rb +47 -0
  15. data/db/migrate/0048_create_ronin_street_addresses_table.rb +46 -0
  16. data/db/migrate/0049_create_ronin_people_table.rb +48 -0
  17. data/db/migrate/0050_create_ronin_personal_connections_table.rb +48 -0
  18. data/db/migrate/0051_create_ronin_personal_phone_numbers_table.rb +48 -0
  19. data/db/migrate/0052_create_ronin_personal_email_addresses_table.rb +45 -0
  20. data/db/migrate/0053_create_ronin_personal_street_addresses_table.rb +47 -0
  21. data/db/migrate/0054_add_type_column_to_ronin_organizations_table.rb +33 -0
  22. data/db/migrate/0055_add_parent_id_column_to_ronin_organizations_table.rb +43 -0
  23. data/db/migrate/0056_create_ronin_organization_departments_table.rb +59 -0
  24. data/db/migrate/0057_create_ronin_organization_members_table.rb +62 -0
  25. data/db/migrate/0058_create_ronin_organization_customers_table.rb +52 -0
  26. data/db/migrate/0059_create_ronin_organization_phone_numbers_table.rb +47 -0
  27. data/db/migrate/0060_create_ronin_organization_email_addresses_table.rb +45 -0
  28. data/db/migrate/0061_create_ronin_organization_street_addresses_table.rb +47 -0
  29. data/db/migrate/0062_add_source_ip_column_to_http_requests_table.rb +30 -0
  30. data/db/migrate/0063_create_ronin_dns_queries_table.rb +41 -0
  31. data/db/migrate/0064_create_ronin_dns_records_table.rb +42 -0
  32. data/db/migrate/0065_create_ronin_organization_host_names_table.rb +43 -0
  33. data/db/migrate/0066_create_ronin_organization_ip_addresses_table.rb +43 -0
  34. data/gemspec.yml +1 -1
  35. data/lib/ronin/db/address.rb +1 -1
  36. data/lib/ronin/db/advisory.rb +66 -1
  37. data/lib/ronin/db/arch.rb +1 -1
  38. data/lib/ronin/db/asn.rb +15 -1
  39. data/lib/ronin/db/cert.rb +501 -0
  40. data/lib/ronin/db/cert_issuer.rb +78 -0
  41. data/lib/ronin/db/cert_name.rb +107 -0
  42. data/lib/ronin/db/cert_organization.rb +127 -0
  43. data/lib/ronin/db/cert_subject.rb +81 -0
  44. data/lib/ronin/db/cert_subject_alt_name.rb +88 -0
  45. data/lib/ronin/db/credential.rb +10 -1
  46. data/lib/ronin/db/dns_query.rb +98 -0
  47. data/lib/ronin/db/dns_record.rb +76 -0
  48. data/lib/ronin/db/email_address.rb +139 -1
  49. data/lib/ronin/db/host_name.rb +45 -1
  50. data/lib/ronin/db/host_name_ip_address.rb +1 -1
  51. data/lib/ronin/db/http_header_name.rb +1 -1
  52. data/lib/ronin/db/http_query_param.rb +1 -1
  53. data/lib/ronin/db/http_query_param_name.rb +1 -1
  54. data/lib/ronin/db/http_request.rb +13 -1
  55. data/lib/ronin/db/http_request_header.rb +1 -1
  56. data/lib/ronin/db/http_response.rb +1 -1
  57. data/lib/ronin/db/http_response_header.rb +1 -1
  58. data/lib/ronin/db/ip_address.rb +46 -1
  59. data/lib/ronin/db/ip_address_mac_address.rb +1 -1
  60. data/lib/ronin/db/mac_address.rb +28 -1
  61. data/lib/ronin/db/migrations.rb +1 -1
  62. data/lib/ronin/db/model/has_name.rb +18 -1
  63. data/lib/ronin/db/model/has_unique_name.rb +1 -1
  64. data/lib/ronin/db/model/importable.rb +1 -1
  65. data/lib/ronin/db/model/last_scanned_at.rb +1 -1
  66. data/lib/ronin/db/model.rb +1 -1
  67. data/lib/ronin/db/models.rb +44 -2
  68. data/lib/ronin/db/note.rb +199 -0
  69. data/lib/ronin/db/open_port.rb +104 -3
  70. data/lib/ronin/db/organization.rb +237 -3
  71. data/lib/ronin/db/organization_customer.rb +73 -0
  72. data/lib/ronin/db/organization_department.rb +97 -0
  73. data/lib/ronin/db/organization_email_address.rb +66 -0
  74. data/lib/ronin/db/organization_host_name.rb +65 -0
  75. data/lib/ronin/db/organization_ip_address.rb +65 -0
  76. data/lib/ronin/db/organization_member.rb +158 -0
  77. data/lib/ronin/db/organization_phone_number.rb +66 -0
  78. data/lib/ronin/db/organization_street_address.rb +66 -0
  79. data/lib/ronin/db/os.rb +35 -1
  80. data/lib/ronin/db/os_guess.rb +1 -1
  81. data/lib/ronin/db/password.rb +84 -1
  82. data/lib/ronin/db/person.rb +455 -0
  83. data/lib/ronin/db/personal_connection.rb +110 -0
  84. data/lib/ronin/db/personal_email_address.rb +66 -0
  85. data/lib/ronin/db/personal_phone_number.rb +76 -0
  86. data/lib/ronin/db/personal_street_address.rb +66 -0
  87. data/lib/ronin/db/phone_number.rb +330 -0
  88. data/lib/ronin/db/port.rb +110 -1
  89. data/lib/ronin/db/service.rb +130 -1
  90. data/lib/ronin/db/service_credential.rb +1 -1
  91. data/lib/ronin/db/software.rb +37 -1
  92. data/lib/ronin/db/software_vendor.rb +1 -1
  93. data/lib/ronin/db/street_address.rb +340 -0
  94. data/lib/ronin/db/url.rb +37 -1
  95. data/lib/ronin/db/url_query_param.rb +1 -1
  96. data/lib/ronin/db/url_query_param_name.rb +9 -1
  97. data/lib/ronin/db/url_scheme.rb +1 -1
  98. data/lib/ronin/db/user_name.rb +58 -1
  99. data/lib/ronin/db/vulnerability.rb +1 -1
  100. data/lib/ronin/db/web_credential.rb +1 -1
  101. data/lib/ronin/db/web_vuln.rb +348 -0
  102. metadata +57 -2
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -19,6 +19,7 @@
19
19
  #
20
20
 
21
21
  require 'ronin/db/model'
22
+ require 'ronin/db/model/has_name'
22
23
 
23
24
  require 'active_record'
24
25
 
@@ -30,6 +31,7 @@ module Ronin
30
31
  class Software < ActiveRecord::Base
31
32
 
32
33
  include Model
34
+ include Model::HasName
33
35
 
34
36
  # @!attribute [rw] id
35
37
  # The primary key of the software.
@@ -65,6 +67,40 @@ module Ronin
65
67
  # @return [Array<OpenPort>]
66
68
  has_many :open_ports
67
69
 
70
+ #
71
+ # Queries all software with the matching version.
72
+ #
73
+ # @param [String] version
74
+ # The version number to search for.
75
+ #
76
+ # @return [Array<Software>]
77
+ # The matching software.
78
+ #
79
+ # @api public
80
+ #
81
+ # @since 0.2.0
82
+ #
83
+ def self.with_version(version)
84
+ where(version: version)
85
+ end
86
+
87
+ #
88
+ # Queries all software with the matching vendor name.
89
+ #
90
+ # @param [String] name
91
+ # The vendor name to search for.
92
+ #
93
+ # @return [Array<Software>]
94
+ # The matching software.
95
+ #
96
+ # @api public
97
+ #
98
+ # @since 0.2.0
99
+ #
100
+ def self.with_vendor_name(name)
101
+ joins(:vendor).where(vendor: {name: name})
102
+ end
103
+
68
104
  #
69
105
  # Converts the software to a String.
70
106
  #
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -0,0 +1,340 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+
23
+ require 'active_record'
24
+
25
+ module Ronin
26
+ module DB
27
+ #
28
+ # Represents a street address.
29
+ #
30
+ # @since 0.2.0
31
+ #
32
+ class StreetAddress < ActiveRecord::Base
33
+
34
+ include Model
35
+
36
+ # @!attribute [rw] id
37
+ # The primary key of the street address.
38
+ #
39
+ # @return [Integer]
40
+ attribute :id, :integer
41
+
42
+ # @!attribute [rw] address
43
+ # The address number and street name.
44
+ #
45
+ # @return [String]
46
+ attribute :address, :string
47
+ validates :address, presence: true,
48
+ length: {maximum: 46},
49
+ uniqueness: {
50
+ scope: [
51
+ :city,
52
+ :state,
53
+ :zipcode,
54
+ :country
55
+ ]
56
+ }
57
+
58
+ # @!attribute [rw] city
59
+ # The city name.
60
+ #
61
+ # @return [String]
62
+ attribute :city, :string
63
+ validates :city, presence: true,
64
+ length: {maximum: 58},
65
+ format: {
66
+ with: /\A\p{Lu}\p{Ll}*(?:[\s'-]\p{Lu}\p{Ll}*)*\z/,
67
+ message: 'Must be a valid capitalized city name'
68
+ }
69
+
70
+ # @!attribute [rw] state
71
+ # The state or province name.
72
+ #
73
+ # @return [String, nil]
74
+ attribute :state, :string
75
+ validates :state, length: {maximum: 13},
76
+ format: {
77
+ with: /\A(?:[A-Z]{2}|\p{Lu}\p{Ll}*(?:\s\p{Lu}\p{Ll}*)*)\z/,
78
+ message: 'Must be a valid capitalized state or province name'
79
+ }
80
+
81
+ # @!attribute [rw] zipcode
82
+ # The zipcode or postal code.
83
+ #
84
+ # @return [String, nil]
85
+ attribute :zipcode, :string
86
+ validates :zipcode, length: {minimum: 4, maximum: 10},
87
+ format: {
88
+ with: /\A[A-Z0-9]+(?:[\s-][A-Z0-9]+)?\z/,
89
+ message: 'Must be a valid zipcode or postal code'
90
+ }
91
+
92
+ # @!attribute [rw] country
93
+ # The country name.
94
+ #
95
+ # @return [String]
96
+ attribute :country, :string
97
+ validates :country, presence: true,
98
+ length: {maximum: 56},
99
+ format: {
100
+ with: /\A(?:[A-Z]{2,3}|\p{Lu}\p{Ll}*(?:[\s-]\p{Lu}\p{Ll}*)*)\z/,
101
+ message: 'Must be a valid capitalized country name'
102
+ }
103
+
104
+ # @!attribute [rw] created_at
105
+ # Tracks when the street address was first created.
106
+ #
107
+ # @return [Time]
108
+ attribute :created_at, :datetime
109
+
110
+ # @!attribute [rw] personal_street_addresses
111
+ # The association of people that associate with the street address.
112
+ #
113
+ # @return [Array<PersonalStreetAddress>]
114
+ has_many :personal_street_addresses, dependent: :destroy
115
+
116
+ # @!attribute [rw] people
117
+ # The people that are associated with the street addresses.
118
+ #
119
+ # @return [Array<Organization>]
120
+ has_many :people, through: :personal_street_addresses
121
+
122
+ # @!attribute [rw] notes
123
+ # The associated notes.
124
+ #
125
+ # @return [Array<Note>]
126
+ has_many :notes
127
+
128
+ # @!attribute [rw] organization_street_addresses
129
+ # The association of organizations that associate with the street
130
+ # address.
131
+ #
132
+ # @return [Array<OrganizationStreetAddress>]
133
+ has_many :organization_street_addresses, dependent: :destroy
134
+
135
+ # @!attribute [rw] organization_departments
136
+ # The organization departments located at the street address.
137
+ #
138
+ # @return [Array<OrganizationDepartment>]
139
+ has_many :organization_departments, dependent: :nullify
140
+
141
+ #
142
+ # Queries all street addresses associated with the person's full name.
143
+ #
144
+ # @param [String] full_name
145
+ # The person's full name to search for.
146
+ #
147
+ # @return [Array<StreetAddress>]
148
+ # The street addresses associated with the person.
149
+ #
150
+ # @api public
151
+ #
152
+ def self.for_person(full_name)
153
+ joins(:people).where(people: {full_name: full_name})
154
+ end
155
+
156
+ #
157
+ # Queries all street addresses associated with an organization's name.
158
+ #
159
+ # @param [String] name
160
+ # The organization name to search for.
161
+ #
162
+ # @return [Array<StreetAddress>]
163
+ # The street addresses associated with the organization.
164
+ #
165
+ # @api public
166
+ #
167
+ def self.for_organization(name)
168
+ joins(organization_street_addresses: :organization).where(
169
+ organization_street_addresses: {
170
+ ronin_organizations: {name: name}
171
+ }
172
+ )
173
+ end
174
+
175
+ #
176
+ # Queries all street addresses with the matching address.
177
+ #
178
+ # @param [String] address
179
+ # The street address to search for.
180
+ #
181
+ # @return [Array<StreetAddress>]
182
+ # The matching street addresses.
183
+ #
184
+ # @api public
185
+ #
186
+ def self.with_address(address)
187
+ where(address: address)
188
+ end
189
+
190
+ #
191
+ # Queries all street addresses with the matching city.
192
+ #
193
+ # @param [String] city
194
+ # The city to search for.
195
+ #
196
+ # @return [Array<StreetAddress>]
197
+ # The matching street addresses.
198
+ #
199
+ # @api public
200
+ #
201
+ def self.with_city(city)
202
+ where(city: city)
203
+ end
204
+
205
+ #
206
+ # Queries all street addresses with the matching state.
207
+ #
208
+ # @param [String] state
209
+ # The state to search for.
210
+ #
211
+ # @return [Array<StreetAddress>]
212
+ # The matching street addresses.
213
+ #
214
+ # @api public
215
+ #
216
+ def self.with_state(state)
217
+ where(state: state)
218
+ end
219
+
220
+ #
221
+ # Alias for {with_state}.
222
+ #
223
+ # @see with_state
224
+ #
225
+ # @api public
226
+ #
227
+ def self.with_province(province)
228
+ with_state(province)
229
+ end
230
+
231
+ #
232
+ # Queries all street addresses with the matching country.
233
+ #
234
+ # @param [String] country
235
+ # The country to search for.
236
+ #
237
+ # @return [Array<StreetAddress>]
238
+ # The matching street addresses.
239
+ #
240
+ # @api public
241
+ #
242
+ def self.with_country(country)
243
+ where(country: country)
244
+ end
245
+
246
+ #
247
+ # Queries all street addresses with the matching zipcode.
248
+ #
249
+ # @param [String] zipcode
250
+ # The zipcode to search for.
251
+ #
252
+ # @return [Array<StreetAddress>]
253
+ # The matching street addresses.
254
+ #
255
+ # @api public
256
+ #
257
+ def self.with_zipcode(zipcode)
258
+ where(zipcode: zipcode)
259
+ end
260
+
261
+ #
262
+ # Alias for {#state}.
263
+ #
264
+ # @return [String, nil]
265
+ #
266
+ # @see state
267
+ #
268
+ # @api public
269
+ #
270
+ def province
271
+ state
272
+ end
273
+
274
+ #
275
+ # Alias for {#state=}.
276
+ #
277
+ # @param [String, nil] new_province
278
+ # The new province value.
279
+ #
280
+ # @return [String, nil]
281
+ #
282
+ # @see state=
283
+ #
284
+ # @api public
285
+ #
286
+ def province=(new_province)
287
+ self.state = new_province
288
+ end
289
+
290
+ #
291
+ # Alias for {#zipcode}.
292
+ #
293
+ # @return [String, nil]
294
+ #
295
+ # @see zipcode
296
+ #
297
+ # @api public
298
+ #
299
+ def postal_code
300
+ zipcode
301
+ end
302
+
303
+ #
304
+ # Alias for {#zipcode=}.
305
+ #
306
+ # @param [String, nil] new_postal_code
307
+ # The new postal code value.
308
+ #
309
+ # @return [String, nil]
310
+ #
311
+ # @see zipcode=
312
+ #
313
+ # @api public
314
+ #
315
+ def postal_code=(new_postal_code)
316
+ self.zipcode = new_postal_code
317
+ end
318
+
319
+ #
320
+ # Converts the street address to a String.
321
+ #
322
+ # @return [String]
323
+ #
324
+ def to_s
325
+ string = "#{address}#{$/}#{city}"
326
+ string << ", #{state}" if state
327
+ string << " #{zipcode}" if zipcode
328
+ string << "#{$/}#{country}"
329
+ return string
330
+ end
331
+
332
+ end
333
+ end
334
+ end
335
+
336
+ require 'ronin/db/personal_street_address'
337
+ require 'ronin/db/person'
338
+ require 'ronin/db/organization_street_address'
339
+ require 'ronin/db/organization_department'
340
+ require 'ronin/db/note'
data/lib/ronin/db/url.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -116,6 +116,38 @@ module Ronin
116
116
  # @return [Array<Credentials>]
117
117
  has_many :credentials, through: :web_credentials
118
118
 
119
+ # @!attribute [rw] web_vulns
120
+ # The web vulnerabilities which reference the URL.
121
+ #
122
+ # @return [Array<WebVuln>]
123
+ #
124
+ # @since 0.2.0
125
+ has_many :web_vulns, dependent: :destroy
126
+
127
+ # @!attribute [rw] vulnerabilities
128
+ # The vulnerabilities which reference the URL.
129
+ #
130
+ # @return [Array<Vulnerability>]
131
+ #
132
+ # @since 0.2.0
133
+ has_many :vulnerabilities, dependent: :destroy
134
+
135
+ # @!attribute [rw] advisories
136
+ # The advisories that the URLs is vulnerable to.
137
+ #
138
+ # @return [Array<Advisory>]
139
+ #
140
+ # @since 0.2.0
141
+ has_many :advisories, through: :vulnerabilities
142
+
143
+ # @!attribute [rw] notes
144
+ # The associated notes.
145
+ #
146
+ # @return [Array<Note>]
147
+ #
148
+ # @since 0.2.0
149
+ has_many :notes, dependent: :destroy
150
+
119
151
  #
120
152
  # Searches for all URLs using HTTP.
121
153
  #
@@ -492,3 +524,7 @@ require 'ronin/db/url_scheme'
492
524
  require 'ronin/db/url_query_param_name'
493
525
  require 'ronin/db/url_query_param'
494
526
  require 'ronin/db/web_credential'
527
+ require 'ronin/db/web_vuln'
528
+ require 'ronin/db/vulnerability'
529
+ require 'ronin/db/advisory'
530
+ require 'ronin/db/note'
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -53,6 +53,14 @@ module Ronin
53
53
  has_many :query_params, class_name: 'URLQueryParam',
54
54
  foreign_key: :name_id
55
55
 
56
+ # @!attribute [rw] urls
57
+ # The URLs that use this query param name.
58
+ #
59
+ # @return [Array<URL>]
60
+ #
61
+ # @since 0.2.0
62
+ has_many :urls, through: :query_params
63
+
56
64
  # @!attribute [r] created_at
57
65
  # When the URL query param name was first created.
58
66
  #
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -56,12 +56,67 @@ module Ronin
56
56
  # @return [Array<Credential>]
57
57
  has_many :credentials, dependent: :destroy
58
58
 
59
+ # @!attribute [rw] service_credentials
60
+ # The service credentials that use the user name.
61
+ #
62
+ # @return [Array<ServiceCredential>]
63
+ #
64
+ # @since 0.2.0
65
+ has_many :service_credentials, through: :credentials
66
+
67
+ # @!attribute [rw] web_credentials
68
+ # Any web credentials that use the user name.
69
+ #
70
+ # @return [Array<WebCredential>]
71
+ #
72
+ # @since 0.2.0
73
+ has_many :web_credentials, through: :credentials
74
+
75
+ # @!attribute [rw] passwords
76
+ # Any passwords used with the user name.
77
+ #
78
+ # @return [Array<Password>]
79
+ #
80
+ # @since 0.2.0
81
+ has_many :passwords, through: :credentials
82
+
59
83
  # @!attribute [rw] email_addresses
60
84
  # The email addresses of the user.
61
85
  #
62
86
  # @return [Array<EmailAddress>]
63
87
  has_many :email_addresses, dependent: :destroy
64
88
 
89
+ # @!attribute [rw] notes
90
+ # The associated notes.
91
+ #
92
+ # @return [Array<Note>]
93
+ #
94
+ # @since 0.2.0
95
+ has_many :notes, dependent: :destroy
96
+
97
+ #
98
+ # Queries all user names that are associated with the password.
99
+ #
100
+ # @param [String] password
101
+ # The plain-text password.
102
+ #
103
+ # @return [Array<UserName>]
104
+ # The user names that are associated with the password.
105
+ #
106
+ # @api public
107
+ #
108
+ # @since 0.2.0
109
+ #
110
+ def self.with_password(password)
111
+ joins(credentials: :password).where(
112
+ credentials: {
113
+ ronin_passwords: {
114
+ plain_text: password
115
+ }
116
+ }
117
+ )
118
+ end
119
+
65
120
  #
66
121
  # Looks up the user name.
67
122
  #
@@ -93,4 +148,6 @@ module Ronin
93
148
  end
94
149
 
95
150
  require 'ronin/db/credential'
151
+ require 'ronin/db/password'
96
152
  require 'ronin/db/email_address'
153
+ require 'ronin/db/note'
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published