optimize tsa settings controller
This commit is contained in:
@@ -4,6 +4,8 @@ class TimestampServerController < ApplicationController
|
|||||||
before_action :build_encrypted_config
|
before_action :build_encrypted_config
|
||||||
authorize_resource :encrypted_config
|
authorize_resource :encrypted_config
|
||||||
|
|
||||||
|
TimestampError = Class.new(StandardError)
|
||||||
|
|
||||||
def create
|
def create
|
||||||
return head :not_found if Docuseal.multitenant?
|
return head :not_found if Docuseal.multitenant?
|
||||||
|
|
||||||
@@ -14,25 +16,29 @@ class TimestampServerController < ApplicationController
|
|||||||
else
|
else
|
||||||
redirect_back fallback_location: settings_notifications_path, alert: 'Unable to save'
|
redirect_back fallback_location: settings_notifications_path, alert: 'Unable to save'
|
||||||
end
|
end
|
||||||
rescue HexaPDF::Error, SocketError, Submissions::TimestampHandler::TimestampError, OpenSSL::Timestamp::TimestampError
|
rescue SocketError, TimestampError, OpenSSL::Timestamp::TimestampError
|
||||||
redirect_back fallback_location: settings_notifications_path, alert: 'Invalid Timeserver'
|
redirect_back fallback_location: settings_notifications_path, alert: 'Invalid Timeserver'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def test_timeserver_url(url)
|
def test_timeserver_url(url)
|
||||||
pdf = HexaPDF::Document.new
|
req = OpenSSL::Timestamp::Request.new
|
||||||
pdf.pages.add
|
req.algorithm = 'SHA512'
|
||||||
|
req.message_imprint = 'test'
|
||||||
|
|
||||||
pkcs = Accounts.load_signing_pkcs(current_account)
|
uri = Addressable::URI.parse(url)
|
||||||
|
|
||||||
pdf.sign(StringIO.new,
|
conn = Faraday.new(uri.origin) do |c|
|
||||||
reason: 'Test',
|
c.basic_auth(uri.user, uri.password) if uri.password.present?
|
||||||
certificate: pkcs.certificate,
|
end
|
||||||
key: pkcs.key,
|
|
||||||
signature_size: 10_000,
|
response = conn.post(uri.path, req.to_der,
|
||||||
certificate_chain: pkcs.ca_certs || [],
|
'content-type' => 'application/timestamp-query')
|
||||||
timestamp_handler: Submissions::TimestampHandler.new(tsa_url: url))
|
|
||||||
|
raise TimestampError if response.status != 200 || response.body.blank?
|
||||||
|
|
||||||
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_encrypted_config
|
def load_encrypted_config
|
||||||
|
|||||||
Reference in New Issue
Block a user