ai_root_shield 0.5.0 → 1.0.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 +4 -4
- data/CHANGELOG.md +52 -4
- data/README.md +33 -2
- data/bindings/python/README.md +304 -0
- data/bindings/python/ai_root_shield.py +438 -0
- data/bindings/python/setup.py +65 -0
- data/examples/device_logs/android_safetynet_device.json +148 -0
- data/examples/device_logs/ios_jailbroken_device.json +172 -0
- data/lib/ai_root_shield/ci_cd/security_test_module.rb +743 -0
- data/lib/ai_root_shield/dashboard/web_dashboard.rb +441 -0
- data/lib/ai_root_shield/enterprise/alert_system.rb +601 -0
- data/lib/ai_root_shield/enterprise/hybrid_detection_engine.rb +650 -0
- data/lib/ai_root_shield/enterprise/performance_optimizer.rb +613 -0
- data/lib/ai_root_shield/enterprise/policy_manager.rb +637 -0
- data/lib/ai_root_shield/integrations/siem_connector.rb +695 -0
- data/lib/ai_root_shield/platform/android_security_module.rb +263 -0
- data/lib/ai_root_shield/platform/hardware_security_analyzer.rb +452 -0
- data/lib/ai_root_shield/platform/ios_security_module.rb +513 -0
- data/lib/ai_root_shield/platform/unified_report_generator.rb +613 -0
- data/lib/ai_root_shield/version.rb +1 -1
- data/security_test_artifacts/security_report.json +124 -0
- data/security_test_artifacts/security_results.sarif +16 -0
- data/security_test_artifacts/security_tests.xml +3 -0
- metadata +20 -1
@@ -0,0 +1,637 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module AiRootShield
|
7
|
+
module Enterprise
|
8
|
+
# Enterprise policy manager for industry-specific security profiles
|
9
|
+
class PolicyManager
|
10
|
+
SUPPORTED_INDUSTRIES = %w[fintech healthcare government corporate].freeze
|
11
|
+
POLICY_VERSION = '1.0'
|
12
|
+
|
13
|
+
attr_reader :current_policy, :industry_type, :compliance_frameworks
|
14
|
+
|
15
|
+
def initialize(industry_type: nil, custom_policy: nil)
|
16
|
+
@industry_type = industry_type
|
17
|
+
@custom_policy = custom_policy
|
18
|
+
@compliance_frameworks = []
|
19
|
+
@policy_cache = {}
|
20
|
+
@audit_log = []
|
21
|
+
|
22
|
+
load_policy if industry_type || custom_policy
|
23
|
+
end
|
24
|
+
|
25
|
+
# Load industry-specific policy profile
|
26
|
+
def load_policy
|
27
|
+
if @custom_policy
|
28
|
+
@current_policy = load_custom_policy(@custom_policy)
|
29
|
+
elsif @industry_type
|
30
|
+
@current_policy = load_industry_policy(@industry_type)
|
31
|
+
else
|
32
|
+
raise ArgumentError, "Either industry_type or custom_policy must be provided"
|
33
|
+
end
|
34
|
+
|
35
|
+
validate_policy(@current_policy)
|
36
|
+
log_policy_event("Policy loaded", { industry: @industry_type, version: @current_policy[:version] })
|
37
|
+
end
|
38
|
+
|
39
|
+
# Evaluate device compliance against loaded policy
|
40
|
+
def evaluate_compliance(analysis_results)
|
41
|
+
return { compliant: false, reason: "No policy loaded" } unless @current_policy
|
42
|
+
|
43
|
+
compliance_result = {
|
44
|
+
compliant: true,
|
45
|
+
policy_version: @current_policy[:version],
|
46
|
+
industry_type: @industry_type,
|
47
|
+
evaluation_timestamp: Time.now.utc.iso8601,
|
48
|
+
violations: [],
|
49
|
+
warnings: [],
|
50
|
+
compliance_score: 100,
|
51
|
+
framework_compliance: {},
|
52
|
+
recommendations: []
|
53
|
+
}
|
54
|
+
|
55
|
+
# Evaluate security requirements
|
56
|
+
evaluate_security_requirements(analysis_results, compliance_result)
|
57
|
+
|
58
|
+
# Evaluate compliance frameworks
|
59
|
+
evaluate_compliance_frameworks(analysis_results, compliance_result)
|
60
|
+
|
61
|
+
# Calculate final compliance score
|
62
|
+
calculate_compliance_score(compliance_result)
|
63
|
+
|
64
|
+
# Log compliance evaluation
|
65
|
+
log_policy_event("Compliance evaluated", {
|
66
|
+
compliant: compliance_result[:compliant],
|
67
|
+
score: compliance_result[:compliance_score],
|
68
|
+
violations: compliance_result[:violations].length
|
69
|
+
})
|
70
|
+
|
71
|
+
compliance_result
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get policy requirements for specific category
|
75
|
+
def get_requirements(category)
|
76
|
+
@current_policy&.dig(:requirements, category.to_sym) || {}
|
77
|
+
end
|
78
|
+
|
79
|
+
# Get compliance framework requirements
|
80
|
+
def get_framework_requirements(framework)
|
81
|
+
@current_policy&.dig(:compliance_frameworks, framework.to_sym) || {}
|
82
|
+
end
|
83
|
+
|
84
|
+
# Update policy configuration
|
85
|
+
def update_policy_config(config_updates)
|
86
|
+
return false unless @current_policy
|
87
|
+
|
88
|
+
@current_policy[:configuration].merge!(config_updates)
|
89
|
+
validate_policy(@current_policy)
|
90
|
+
|
91
|
+
log_policy_event("Policy configuration updated", config_updates)
|
92
|
+
true
|
93
|
+
end
|
94
|
+
|
95
|
+
# Get audit log
|
96
|
+
def audit_log
|
97
|
+
@audit_log.dup
|
98
|
+
end
|
99
|
+
|
100
|
+
# Export policy for sharing/backup
|
101
|
+
def export_policy
|
102
|
+
return nil unless @current_policy
|
103
|
+
|
104
|
+
{
|
105
|
+
exported_at: Time.now.utc.iso8601,
|
106
|
+
policy: @current_policy,
|
107
|
+
industry_type: @industry_type,
|
108
|
+
audit_log: @audit_log
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
# Load industry-specific policy
|
115
|
+
def load_industry_policy(industry)
|
116
|
+
case industry.to_s.downcase
|
117
|
+
when 'fintech', 'banking'
|
118
|
+
load_fintech_policy
|
119
|
+
when 'healthcare', 'hipaa'
|
120
|
+
load_healthcare_policy
|
121
|
+
when 'government', 'public'
|
122
|
+
load_government_policy
|
123
|
+
when 'corporate', 'enterprise'
|
124
|
+
load_corporate_policy
|
125
|
+
else
|
126
|
+
raise ArgumentError, "Unsupported industry type: #{industry}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Load custom policy from file or hash
|
131
|
+
def load_custom_policy(policy_source)
|
132
|
+
if policy_source.is_a?(String)
|
133
|
+
# Load from file
|
134
|
+
JSON.parse(File.read(policy_source), symbolize_names: true)
|
135
|
+
elsif policy_source.is_a?(Hash)
|
136
|
+
# Use provided hash
|
137
|
+
policy_source.transform_keys(&:to_sym)
|
138
|
+
else
|
139
|
+
raise ArgumentError, "Custom policy must be a file path or hash"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Fintech/Banking industry policy
|
144
|
+
def load_fintech_policy
|
145
|
+
{
|
146
|
+
name: "Fintech Security Policy",
|
147
|
+
version: "1.0.0",
|
148
|
+
industry: "fintech",
|
149
|
+
description: "PCI DSS and financial services security requirements",
|
150
|
+
compliance_frameworks: [:pci_dss, :sox, :ffiec, :psd2],
|
151
|
+
requirements: {
|
152
|
+
device_integrity: {
|
153
|
+
root_detection: { required: true, severity: "critical" },
|
154
|
+
emulator_detection: { required: true, severity: "critical" },
|
155
|
+
debugging_detection: { required: true, severity: "high" },
|
156
|
+
hooking_detection: { required: true, severity: "critical" }
|
157
|
+
},
|
158
|
+
network_security: {
|
159
|
+
certificate_pinning: { required: true, severity: "critical" },
|
160
|
+
proxy_detection: { required: true, severity: "high" },
|
161
|
+
vpn_detection: { required: true, severity: "medium" },
|
162
|
+
mitm_detection: { required: true, severity: "critical" }
|
163
|
+
},
|
164
|
+
data_protection: {
|
165
|
+
encryption_required: { required: true, severity: "critical" },
|
166
|
+
keystore_protection: { required: true, severity: "critical" },
|
167
|
+
biometric_authentication: { required: true, severity: "high" },
|
168
|
+
secure_storage: { required: true, severity: "critical" }
|
169
|
+
},
|
170
|
+
compliance: {
|
171
|
+
pci_dss_level: 1,
|
172
|
+
data_retention_days: 90,
|
173
|
+
audit_logging: { required: true, severity: "critical" },
|
174
|
+
incident_response: { required: true, severity: "high" }
|
175
|
+
}
|
176
|
+
},
|
177
|
+
risk_thresholds: {
|
178
|
+
critical: 0,
|
179
|
+
high: 10,
|
180
|
+
medium: 30,
|
181
|
+
low: 50
|
182
|
+
},
|
183
|
+
configuration: {
|
184
|
+
real_time_monitoring: true,
|
185
|
+
automated_blocking: true,
|
186
|
+
alert_escalation: true,
|
187
|
+
compliance_reporting: true
|
188
|
+
}
|
189
|
+
}
|
190
|
+
end
|
191
|
+
|
192
|
+
# Healthcare/HIPAA industry policy
|
193
|
+
def load_healthcare_policy
|
194
|
+
{
|
195
|
+
name: "Healthcare Security Policy",
|
196
|
+
version: "1.0.0",
|
197
|
+
industry: "healthcare",
|
198
|
+
description: "HIPAA and healthcare data protection requirements",
|
199
|
+
compliance_frameworks: [:hipaa, :hitech, :gdpr, :fda_21cfr11],
|
200
|
+
requirements: {
|
201
|
+
device_integrity: {
|
202
|
+
root_detection: { required: true, severity: "critical" },
|
203
|
+
emulator_detection: { required: true, severity: "high" },
|
204
|
+
debugging_detection: { required: true, severity: "high" },
|
205
|
+
hooking_detection: { required: true, severity: "high" }
|
206
|
+
},
|
207
|
+
network_security: {
|
208
|
+
certificate_pinning: { required: true, severity: "critical" },
|
209
|
+
proxy_detection: { required: true, severity: "medium" },
|
210
|
+
vpn_detection: { required: false, severity: "low" },
|
211
|
+
mitm_detection: { required: true, severity: "critical" }
|
212
|
+
},
|
213
|
+
data_protection: {
|
214
|
+
encryption_required: { required: true, severity: "critical" },
|
215
|
+
keystore_protection: { required: true, severity: "critical" },
|
216
|
+
biometric_authentication: { required: false, severity: "medium" },
|
217
|
+
secure_storage: { required: true, severity: "critical" },
|
218
|
+
phi_protection: { required: true, severity: "critical" }
|
219
|
+
},
|
220
|
+
compliance: {
|
221
|
+
hipaa_compliance: true,
|
222
|
+
data_retention_days: 2555, # 7 years
|
223
|
+
audit_logging: { required: true, severity: "critical" },
|
224
|
+
breach_notification: { required: true, severity: "critical" },
|
225
|
+
access_controls: { required: true, severity: "critical" }
|
226
|
+
}
|
227
|
+
},
|
228
|
+
risk_thresholds: {
|
229
|
+
critical: 0,
|
230
|
+
high: 15,
|
231
|
+
medium: 35,
|
232
|
+
low: 60
|
233
|
+
},
|
234
|
+
configuration: {
|
235
|
+
real_time_monitoring: true,
|
236
|
+
automated_blocking: false, # Healthcare requires human oversight
|
237
|
+
alert_escalation: true,
|
238
|
+
compliance_reporting: true,
|
239
|
+
phi_detection: true
|
240
|
+
}
|
241
|
+
}
|
242
|
+
end
|
243
|
+
|
244
|
+
# Government/Public sector policy
|
245
|
+
def load_government_policy
|
246
|
+
{
|
247
|
+
name: "Government Security Policy",
|
248
|
+
version: "1.0.0",
|
249
|
+
industry: "government",
|
250
|
+
description: "Government and public sector security requirements",
|
251
|
+
compliance_frameworks: [:fisma, :nist_800_53, :fedramp, :cjis],
|
252
|
+
requirements: {
|
253
|
+
device_integrity: {
|
254
|
+
root_detection: { required: true, severity: "critical" },
|
255
|
+
emulator_detection: { required: true, severity: "critical" },
|
256
|
+
debugging_detection: { required: true, severity: "critical" },
|
257
|
+
hooking_detection: { required: true, severity: "critical" }
|
258
|
+
},
|
259
|
+
network_security: {
|
260
|
+
certificate_pinning: { required: true, severity: "critical" },
|
261
|
+
proxy_detection: { required: true, severity: "critical" },
|
262
|
+
vpn_detection: { required: true, severity: "high" },
|
263
|
+
mitm_detection: { required: true, severity: "critical" }
|
264
|
+
},
|
265
|
+
data_protection: {
|
266
|
+
encryption_required: { required: true, severity: "critical" },
|
267
|
+
keystore_protection: { required: true, severity: "critical" },
|
268
|
+
biometric_authentication: { required: true, severity: "high" },
|
269
|
+
secure_storage: { required: true, severity: "critical" },
|
270
|
+
classified_data_protection: { required: true, severity: "critical" }
|
271
|
+
},
|
272
|
+
compliance: {
|
273
|
+
fisma_level: "high",
|
274
|
+
nist_compliance: true,
|
275
|
+
data_retention_days: 2555, # 7 years
|
276
|
+
audit_logging: { required: true, severity: "critical" },
|
277
|
+
incident_response: { required: true, severity: "critical" },
|
278
|
+
continuous_monitoring: { required: true, severity: "critical" }
|
279
|
+
}
|
280
|
+
},
|
281
|
+
risk_thresholds: {
|
282
|
+
critical: 0,
|
283
|
+
high: 5,
|
284
|
+
medium: 20,
|
285
|
+
low: 40
|
286
|
+
},
|
287
|
+
configuration: {
|
288
|
+
real_time_monitoring: true,
|
289
|
+
automated_blocking: true,
|
290
|
+
alert_escalation: true,
|
291
|
+
compliance_reporting: true,
|
292
|
+
continuous_monitoring: true
|
293
|
+
}
|
294
|
+
}
|
295
|
+
end
|
296
|
+
|
297
|
+
# Corporate/Enterprise policy
|
298
|
+
def load_corporate_policy
|
299
|
+
{
|
300
|
+
name: "Corporate Security Policy",
|
301
|
+
version: "1.0.0",
|
302
|
+
industry: "corporate",
|
303
|
+
description: "General corporate and enterprise security requirements",
|
304
|
+
compliance_frameworks: [:iso27001, :gdpr, :ccpa, :sox],
|
305
|
+
requirements: {
|
306
|
+
device_integrity: {
|
307
|
+
root_detection: { required: true, severity: "high" },
|
308
|
+
emulator_detection: { required: true, severity: "medium" },
|
309
|
+
debugging_detection: { required: true, severity: "medium" },
|
310
|
+
hooking_detection: { required: true, severity: "high" }
|
311
|
+
},
|
312
|
+
network_security: {
|
313
|
+
certificate_pinning: { required: true, severity: "high" },
|
314
|
+
proxy_detection: { required: true, severity: "medium" },
|
315
|
+
vpn_detection: { required: false, severity: "low" },
|
316
|
+
mitm_detection: { required: true, severity: "high" }
|
317
|
+
},
|
318
|
+
data_protection: {
|
319
|
+
encryption_required: { required: true, severity: "high" },
|
320
|
+
keystore_protection: { required: true, severity: "high" },
|
321
|
+
biometric_authentication: { required: false, severity: "medium" },
|
322
|
+
secure_storage: { required: true, severity: "high" }
|
323
|
+
},
|
324
|
+
compliance: {
|
325
|
+
data_retention_days: 1095, # 3 years
|
326
|
+
audit_logging: { required: true, severity: "high" },
|
327
|
+
incident_response: { required: true, severity: "medium" },
|
328
|
+
privacy_protection: { required: true, severity: "high" }
|
329
|
+
}
|
330
|
+
},
|
331
|
+
risk_thresholds: {
|
332
|
+
critical: 5,
|
333
|
+
high: 25,
|
334
|
+
medium: 50,
|
335
|
+
low: 75
|
336
|
+
},
|
337
|
+
configuration: {
|
338
|
+
real_time_monitoring: true,
|
339
|
+
automated_blocking: false,
|
340
|
+
alert_escalation: true,
|
341
|
+
compliance_reporting: true
|
342
|
+
}
|
343
|
+
}
|
344
|
+
end
|
345
|
+
|
346
|
+
# Evaluate security requirements
|
347
|
+
def evaluate_security_requirements(analysis_results, compliance_result)
|
348
|
+
requirements = @current_policy[:requirements]
|
349
|
+
|
350
|
+
requirements.each do |category, category_requirements|
|
351
|
+
category_requirements.each do |requirement, config|
|
352
|
+
next unless config[:required]
|
353
|
+
|
354
|
+
violation = check_requirement_compliance(requirement, config, analysis_results)
|
355
|
+
if violation
|
356
|
+
compliance_result[:violations] << violation
|
357
|
+
compliance_result[:compliant] = false if config[:severity] == "critical"
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
# Check individual requirement compliance
|
364
|
+
def check_requirement_compliance(requirement, config, analysis_results)
|
365
|
+
case requirement
|
366
|
+
when :root_detection
|
367
|
+
if analysis_results[:factors]&.include?('ROOT_DETECTED')
|
368
|
+
create_violation(requirement, config, "Root access detected on device")
|
369
|
+
end
|
370
|
+
when :emulator_detection
|
371
|
+
if analysis_results[:factors]&.include?('EMULATOR_DETECTED')
|
372
|
+
create_violation(requirement, config, "Emulator environment detected")
|
373
|
+
end
|
374
|
+
when :debugging_detection
|
375
|
+
if analysis_results[:factors]&.include?('DEBUGGING_DETECTED')
|
376
|
+
create_violation(requirement, config, "Debugging tools detected")
|
377
|
+
end
|
378
|
+
when :hooking_detection
|
379
|
+
if analysis_results[:factors]&.include?('HOOKING_DETECTED')
|
380
|
+
create_violation(requirement, config, "Code hooking/tampering detected")
|
381
|
+
end
|
382
|
+
when :certificate_pinning
|
383
|
+
if analysis_results[:network_analysis]&.dig(:certificate_pinning, :valid) == false
|
384
|
+
create_violation(requirement, config, "Certificate pinning validation failed")
|
385
|
+
end
|
386
|
+
when :proxy_detection
|
387
|
+
if analysis_results[:network_analysis]&.dig(:proxy_detection, :proxy_detected) == true
|
388
|
+
create_violation(requirement, config, "Proxy/VPN connection detected")
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
# Create violation record
|
394
|
+
def create_violation(requirement, config, message)
|
395
|
+
{
|
396
|
+
requirement: requirement,
|
397
|
+
severity: config[:severity],
|
398
|
+
message: message,
|
399
|
+
detected_at: Time.now.utc.iso8601,
|
400
|
+
category: get_requirement_category(requirement)
|
401
|
+
}
|
402
|
+
end
|
403
|
+
|
404
|
+
# Get requirement category
|
405
|
+
def get_requirement_category(requirement)
|
406
|
+
@current_policy[:requirements].each do |category, requirements|
|
407
|
+
return category if requirements.key?(requirement)
|
408
|
+
end
|
409
|
+
:unknown
|
410
|
+
end
|
411
|
+
|
412
|
+
# Evaluate compliance frameworks
|
413
|
+
def evaluate_compliance_frameworks(analysis_results, compliance_result)
|
414
|
+
@current_policy[:compliance_frameworks].each do |framework|
|
415
|
+
framework_result = evaluate_framework(framework, analysis_results)
|
416
|
+
compliance_result[:framework_compliance][framework] = framework_result
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
# Evaluate specific compliance framework
|
421
|
+
def evaluate_framework(framework, analysis_results)
|
422
|
+
case framework
|
423
|
+
when :pci_dss
|
424
|
+
evaluate_pci_dss_compliance(analysis_results)
|
425
|
+
when :hipaa
|
426
|
+
evaluate_hipaa_compliance(analysis_results)
|
427
|
+
when :fisma
|
428
|
+
evaluate_fisma_compliance(analysis_results)
|
429
|
+
when :iso27001
|
430
|
+
evaluate_iso27001_compliance(analysis_results)
|
431
|
+
else
|
432
|
+
{ compliant: true, score: 100, requirements_met: [], requirements_failed: [] }
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
# PCI DSS compliance evaluation
|
437
|
+
def evaluate_pci_dss_compliance(analysis_results)
|
438
|
+
requirements_met = []
|
439
|
+
requirements_failed = []
|
440
|
+
|
441
|
+
# PCI DSS Requirement 2: Do not use vendor-supplied defaults
|
442
|
+
if !analysis_results[:factors]&.include?('DEFAULT_CREDENTIALS')
|
443
|
+
requirements_met << "2.1 - No default credentials detected"
|
444
|
+
else
|
445
|
+
requirements_failed << "2.1 - Default credentials detected"
|
446
|
+
end
|
447
|
+
|
448
|
+
# PCI DSS Requirement 4: Encrypt transmission of cardholder data
|
449
|
+
if analysis_results[:network_analysis]&.dig(:certificate_pinning, :valid) == true
|
450
|
+
requirements_met << "4.1 - Secure transmission validated"
|
451
|
+
else
|
452
|
+
requirements_failed << "4.1 - Insecure transmission detected"
|
453
|
+
end
|
454
|
+
|
455
|
+
# PCI DSS Requirement 6: Develop and maintain secure systems
|
456
|
+
if !analysis_results[:factors]&.include?('DEBUGGING_DETECTED')
|
457
|
+
requirements_met << "6.5 - No debugging tools detected"
|
458
|
+
else
|
459
|
+
requirements_failed << "6.5 - Debugging tools detected"
|
460
|
+
end
|
461
|
+
|
462
|
+
score = (requirements_met.length.to_f / (requirements_met.length + requirements_failed.length) * 100).round
|
463
|
+
|
464
|
+
{
|
465
|
+
compliant: requirements_failed.empty?,
|
466
|
+
score: score,
|
467
|
+
requirements_met: requirements_met,
|
468
|
+
requirements_failed: requirements_failed
|
469
|
+
}
|
470
|
+
end
|
471
|
+
|
472
|
+
# HIPAA compliance evaluation
|
473
|
+
def evaluate_hipaa_compliance(analysis_results)
|
474
|
+
requirements_met = []
|
475
|
+
requirements_failed = []
|
476
|
+
|
477
|
+
# HIPAA Security Rule - Access Control
|
478
|
+
if analysis_results[:factors]&.include?('BIOMETRIC_AUTHENTICATION')
|
479
|
+
requirements_met << "164.312(a)(1) - Access control implemented"
|
480
|
+
else
|
481
|
+
requirements_failed << "164.312(a)(1) - Insufficient access control"
|
482
|
+
end
|
483
|
+
|
484
|
+
# HIPAA Security Rule - Integrity
|
485
|
+
if !analysis_results[:factors]&.include?('TAMPERING_DETECTED')
|
486
|
+
requirements_met << "164.312(c)(1) - Data integrity maintained"
|
487
|
+
else
|
488
|
+
requirements_failed << "164.312(c)(1) - Data integrity compromised"
|
489
|
+
end
|
490
|
+
|
491
|
+
# HIPAA Security Rule - Transmission Security
|
492
|
+
if analysis_results[:network_analysis]&.dig(:certificate_pinning, :valid) == true
|
493
|
+
requirements_met << "164.312(e)(1) - Secure transmission"
|
494
|
+
else
|
495
|
+
requirements_failed << "164.312(e)(1) - Insecure transmission"
|
496
|
+
end
|
497
|
+
|
498
|
+
score = (requirements_met.length.to_f / (requirements_met.length + requirements_failed.length) * 100).round
|
499
|
+
|
500
|
+
{
|
501
|
+
compliant: requirements_failed.empty?,
|
502
|
+
score: score,
|
503
|
+
requirements_met: requirements_met,
|
504
|
+
requirements_failed: requirements_failed
|
505
|
+
}
|
506
|
+
end
|
507
|
+
|
508
|
+
# FISMA compliance evaluation
|
509
|
+
def evaluate_fisma_compliance(analysis_results)
|
510
|
+
requirements_met = []
|
511
|
+
requirements_failed = []
|
512
|
+
|
513
|
+
# NIST 800-53 SI-3: Malicious Code Protection
|
514
|
+
if !analysis_results[:factors]&.include?('MALWARE_DETECTED')
|
515
|
+
requirements_met << "SI-3 - No malicious code detected"
|
516
|
+
else
|
517
|
+
requirements_failed << "SI-3 - Malicious code detected"
|
518
|
+
end
|
519
|
+
|
520
|
+
# NIST 800-53 SI-4: Information System Monitoring
|
521
|
+
if analysis_results[:rasp_status]&.dig(:active) == true
|
522
|
+
requirements_met << "SI-4 - Real-time monitoring active"
|
523
|
+
else
|
524
|
+
requirements_failed << "SI-4 - Real-time monitoring inactive"
|
525
|
+
end
|
526
|
+
|
527
|
+
# NIST 800-53 SC-13: Cryptographic Protection
|
528
|
+
if analysis_results[:factors]&.include?('ENCRYPTION_ENABLED')
|
529
|
+
requirements_met << "SC-13 - Cryptographic protection enabled"
|
530
|
+
else
|
531
|
+
requirements_failed << "SC-13 - Insufficient cryptographic protection"
|
532
|
+
end
|
533
|
+
|
534
|
+
score = (requirements_met.length.to_f / (requirements_met.length + requirements_failed.length) * 100).round
|
535
|
+
|
536
|
+
{
|
537
|
+
compliant: requirements_failed.empty?,
|
538
|
+
score: score,
|
539
|
+
requirements_met: requirements_met,
|
540
|
+
requirements_failed: requirements_failed
|
541
|
+
}
|
542
|
+
end
|
543
|
+
|
544
|
+
# ISO 27001 compliance evaluation
|
545
|
+
def evaluate_iso27001_compliance(analysis_results)
|
546
|
+
requirements_met = []
|
547
|
+
requirements_failed = []
|
548
|
+
|
549
|
+
# A.12.6.1 Management of technical vulnerabilities
|
550
|
+
if !analysis_results[:factors]&.include?('KNOWN_VULNERABILITIES')
|
551
|
+
requirements_met << "A.12.6.1 - No known vulnerabilities detected"
|
552
|
+
else
|
553
|
+
requirements_failed << "A.12.6.1 - Known vulnerabilities detected"
|
554
|
+
end
|
555
|
+
|
556
|
+
# A.13.1.1 Network controls
|
557
|
+
if analysis_results[:network_analysis]&.dig(:proxy_detection, :proxy_detected) == false
|
558
|
+
requirements_met << "A.13.1.1 - Network controls effective"
|
559
|
+
else
|
560
|
+
requirements_failed << "A.13.1.1 - Network controls bypassed"
|
561
|
+
end
|
562
|
+
|
563
|
+
# A.18.1.4 Privacy and protection of personally identifiable information
|
564
|
+
if analysis_results[:factors]&.include?('PRIVACY_PROTECTION')
|
565
|
+
requirements_met << "A.18.1.4 - Privacy protection implemented"
|
566
|
+
else
|
567
|
+
requirements_failed << "A.18.1.4 - Insufficient privacy protection"
|
568
|
+
end
|
569
|
+
|
570
|
+
score = (requirements_met.length.to_f / (requirements_met.length + requirements_failed.length) * 100).round
|
571
|
+
|
572
|
+
{
|
573
|
+
compliant: requirements_failed.empty?,
|
574
|
+
score: score,
|
575
|
+
requirements_met: requirements_met,
|
576
|
+
requirements_failed: requirements_failed
|
577
|
+
}
|
578
|
+
end
|
579
|
+
|
580
|
+
# Calculate overall compliance score
|
581
|
+
def calculate_compliance_score(compliance_result)
|
582
|
+
base_score = 100
|
583
|
+
|
584
|
+
# Deduct points for violations based on severity
|
585
|
+
compliance_result[:violations].each do |violation|
|
586
|
+
case violation[:severity]
|
587
|
+
when 'critical'
|
588
|
+
base_score -= 25
|
589
|
+
when 'high'
|
590
|
+
base_score -= 15
|
591
|
+
when 'medium'
|
592
|
+
base_score -= 10
|
593
|
+
when 'low'
|
594
|
+
base_score -= 5
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
# Ensure score doesn't go below 0
|
599
|
+
compliance_result[:compliance_score] = [base_score, 0].max
|
600
|
+
|
601
|
+
# Set overall compliance based on thresholds
|
602
|
+
thresholds = @current_policy[:risk_thresholds]
|
603
|
+
if compliance_result[:compliance_score] < thresholds[:critical]
|
604
|
+
compliance_result[:compliant] = false
|
605
|
+
end
|
606
|
+
end
|
607
|
+
|
608
|
+
# Validate policy structure
|
609
|
+
def validate_policy(policy)
|
610
|
+
required_keys = [:name, :version, :industry, :requirements, :risk_thresholds, :configuration]
|
611
|
+
missing_keys = required_keys - policy.keys
|
612
|
+
|
613
|
+
raise ArgumentError, "Policy missing required keys: #{missing_keys.join(', ')}" unless missing_keys.empty?
|
614
|
+
|
615
|
+
# Validate risk thresholds
|
616
|
+
threshold_keys = [:critical, :high, :medium, :low]
|
617
|
+
missing_thresholds = threshold_keys - policy[:risk_thresholds].keys
|
618
|
+
|
619
|
+
raise ArgumentError, "Policy missing risk thresholds: #{missing_thresholds.join(', ')}" unless missing_thresholds.empty?
|
620
|
+
end
|
621
|
+
|
622
|
+
# Log policy events for audit trail
|
623
|
+
def log_policy_event(event_type, details)
|
624
|
+
@audit_log << {
|
625
|
+
timestamp: Time.now.utc.iso8601,
|
626
|
+
event_type: event_type,
|
627
|
+
details: details,
|
628
|
+
policy_version: @current_policy&.dig(:version),
|
629
|
+
industry_type: @industry_type
|
630
|
+
}
|
631
|
+
|
632
|
+
# Keep only last 1000 events
|
633
|
+
@audit_log = @audit_log.last(1000) if @audit_log.length > 1000
|
634
|
+
end
|
635
|
+
end
|
636
|
+
end
|
637
|
+
end
|