This commit is contained in:
parent
01700017e9
commit
ae520e9076
5 changed files with 31 additions and 0 deletions
2
Gemfile
2
Gemfile
|
@ -25,6 +25,8 @@ gem 'jbuilder', '~> 2.7'
|
||||||
# Reduces boot times through caching; required in config/boot.rb
|
# Reduces boot times through caching; required in config/boot.rb
|
||||||
gem 'bootsnap', '>= 1.4.4', require: false
|
gem 'bootsnap', '>= 1.4.4', require: false
|
||||||
|
|
||||||
|
gem 'ssh_data'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
||||||
|
|
|
@ -214,6 +214,7 @@ GEM
|
||||||
actionpack (>= 5.2)
|
actionpack (>= 5.2)
|
||||||
activesupport (>= 5.2)
|
activesupport (>= 5.2)
|
||||||
sprockets (>= 3.0.0)
|
sprockets (>= 3.0.0)
|
||||||
|
ssh_data (1.3.0)
|
||||||
thor (1.1.0)
|
thor (1.1.0)
|
||||||
tilt (2.0.10)
|
tilt (2.0.10)
|
||||||
turbolinks (5.2.1)
|
turbolinks (5.2.1)
|
||||||
|
@ -266,6 +267,7 @@ DEPENDENCIES
|
||||||
sass-rails (>= 6)
|
sass-rails (>= 6)
|
||||||
selenium-webdriver
|
selenium-webdriver
|
||||||
spring
|
spring
|
||||||
|
ssh_data
|
||||||
turbolinks (~> 5)
|
turbolinks (~> 5)
|
||||||
tzinfo-data
|
tzinfo-data
|
||||||
web-console (>= 4.1.0)
|
web-console (>= 4.1.0)
|
||||||
|
|
|
@ -15,6 +15,8 @@ class ReadingsController < ActionController::API
|
||||||
reading = raspberry.readings.build reading_params
|
reading = raspberry.readings.build reading_params
|
||||||
reading.id = params[:transaction_uuid]
|
reading.id = params[:transaction_uuid]
|
||||||
reading.signature = request.headers[:'X-Signature']
|
reading.signature = request.headers[:'X-Signature']
|
||||||
|
reading.transaction = request.raw_post
|
||||||
|
reading.verified = reading.verify
|
||||||
|
|
||||||
params[:arduinos]&.each do |a|
|
params[:arduinos]&.each do |a|
|
||||||
arduino = reading.arduinos.build local_id: a[:id], raspberry: raspberry
|
arduino = reading.arduinos.build local_id: a[:id], raspberry: raspberry
|
||||||
|
|
|
@ -3,4 +3,20 @@
|
||||||
class Reading < ApplicationRecord
|
class Reading < ApplicationRecord
|
||||||
belongs_to :raspberry
|
belongs_to :raspberry
|
||||||
has_many :arduinos
|
has_many :arduinos
|
||||||
|
|
||||||
|
def verify
|
||||||
|
ssh_signature.verify transaction
|
||||||
|
rescue SSHData::Error
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def ssh_signature
|
||||||
|
@ssh_signature ||= SSHData::Signature.parse_pem <<~PEM
|
||||||
|
-----BEGIN SSH SIGNATURE-----
|
||||||
|
#{signature}
|
||||||
|
-----END SSH SIGNATURE-----
|
||||||
|
PEM
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Agrega la verificación de firma en la lectura
|
||||||
|
class AddVerificationToReadings < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :readings, :transaction, :text
|
||||||
|
add_column :readings, :verified, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue