Compare commits
No commits in common. "ae520e9076f65d4219ee8002be64fe3aa8d1f812" and "58e51862394ca081d35bca10d3c9f93f19a4750d" have entirely different histories.
ae520e9076
...
58e5186239
5 changed files with 1 additions and 33 deletions
2
Gemfile
2
Gemfile
|
@ -25,8 +25,6 @@ gem 'jbuilder', '~> 2.7'
|
|||
# Reduces boot times through caching; required in config/boot.rb
|
||||
gem 'bootsnap', '>= 1.4.4', require: false
|
||||
|
||||
gem 'ssh_data'
|
||||
|
||||
group :development, :test do
|
||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
||||
|
|
|
@ -214,7 +214,6 @@ GEM
|
|||
actionpack (>= 5.2)
|
||||
activesupport (>= 5.2)
|
||||
sprockets (>= 3.0.0)
|
||||
ssh_data (1.3.0)
|
||||
thor (1.1.0)
|
||||
tilt (2.0.10)
|
||||
turbolinks (5.2.1)
|
||||
|
@ -267,7 +266,6 @@ DEPENDENCIES
|
|||
sass-rails (>= 6)
|
||||
selenium-webdriver
|
||||
spring
|
||||
ssh_data
|
||||
turbolinks (~> 5)
|
||||
tzinfo-data
|
||||
web-console (>= 4.1.0)
|
||||
|
|
|
@ -14,9 +14,8 @@ class ReadingsController < ActionController::API
|
|||
Reading.transaction do
|
||||
reading = raspberry.readings.build reading_params
|
||||
reading.id = params[:transaction_uuid]
|
||||
# TODO: Verificar firma
|
||||
reading.signature = request.headers[:'X-Signature']
|
||||
reading.transaction = request.raw_post
|
||||
reading.verified = reading.verify
|
||||
|
||||
params[:arduinos]&.each do |a|
|
||||
arduino = reading.arduinos.build local_id: a[:id], raspberry: raspberry
|
||||
|
@ -32,8 +31,6 @@ class ReadingsController < ActionController::API
|
|||
head :bad_request
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
render plain: params[:transaction_uuid], status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -3,20 +3,4 @@
|
|||
class Reading < ApplicationRecord
|
||||
belongs_to :raspberry
|
||||
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
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
# 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