@ -1,26 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class EsignSettingsController < ApplicationController
|
||||
before_action :load_encrypted_config
|
||||
|
||||
def create
|
||||
attachment = ActiveStorage::Attachment.find_by!(uuid: params[:attachment_uuid])
|
||||
|
||||
pdf = HexaPDF::Document.new(io: StringIO.new(attachment.download))
|
||||
blobs =
|
||||
params[:blob_signed_ids].map do |sid|
|
||||
ActiveStorage::Blob.find_signed(sid)
|
||||
end
|
||||
|
||||
pdf.signatures
|
||||
end
|
||||
pdfs =
|
||||
blobs.map do |blob|
|
||||
HexaPDF::Document.new(io: StringIO.new(blob.download))
|
||||
end
|
||||
|
||||
private
|
||||
cert = EncryptedConfig.find_by(account: current_account, key: EncryptedConfig::ESIGN_CERTS_KEY).value
|
||||
|
||||
def load_encrypted_config
|
||||
@encrypted_config =
|
||||
EncryptedConfig.find_or_initialize_by(account: current_account, key: EncryptedConfig::ESIGN_CERTS_KEY)
|
||||
end
|
||||
trusted_certs = [OpenSSL::X509::Certificate.new(cert['cert']),
|
||||
OpenSSL::X509::Certificate.new(cert['sub_ca']),
|
||||
OpenSSL::X509::Certificate.new(cert['root_ca'])]
|
||||
|
||||
def storage_configs
|
||||
params.require(:encrypted_config).permit(value: {}).tap do |e|
|
||||
e[:value].compact_blank!
|
||||
end
|
||||
render turbo_stream: turbo_stream.replace('result', partial: 'result', locals: { pdfs:, blobs:, trusted_certs: })
|
||||
rescue HexaPDF::MalformedPDFError
|
||||
render turbo_stream: turbo_stream.replace('result', html: helpers.tag.div('Invalid PDF', id: 'result'))
|
||||
end
|
||||
end
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
<div id="result">
|
||||
<% blobs.zip(pdfs).each do |blob, pdf| %>
|
||||
<div class="mb-4 border border-base-300 rounded-md py-2 px-3">
|
||||
<% if pdf.signatures.to_a.size == 0 %>
|
||||
<div class="text-sm">
|
||||
<%= blob.filename %>
|
||||
</div>
|
||||
<p class="text-xl font-medium">
|
||||
There are no signatures...
|
||||
</p>
|
||||
<% else %>
|
||||
<div class="flex items-center space-x-1 border-b border-dashed border-base-300 pb-2">
|
||||
<%= svg_icon('file_text', class: 'w-5 h-5 inline') %>
|
||||
<span><%= blob.filename %> - <%= pluralize(pdf.signatures.to_a.size, 'Signature') %></span>
|
||||
</div>
|
||||
<% pdf.signatures.to_a.each do |signature| %>
|
||||
<div class="mt-3">
|
||||
<div class="space-y-1 font-medium pb-2 text-xl">
|
||||
<% signature.verify(trusted_certs:).messages.map(&:content).each do |message| %>
|
||||
<p class="flex space-x-1 items-center">
|
||||
<% if message == 'Signature verification failed' %>
|
||||
<%= svg_icon('x_circle', class: 'w-6 h-6 text-red-500') %>
|
||||
<% elsif message == 'Signature valid' %>
|
||||
<%= svg_icon('circle_check', class: 'w-6 h-6 text-green-500') %>
|
||||
<% end %>
|
||||
<span>
|
||||
<%= message %>
|
||||
</span>
|
||||
</p>
|
||||
<% if message == 'Signature valid' %>
|
||||
<p class="flex space-x-1 items-center">
|
||||
<% if signature.signature_handler.signer_certificate.public_key.to_der == trusted_certs.first.public_key.to_der %>
|
||||
<%= svg_icon('circle_check', class: 'w-6 h-6 text-green-500') %>
|
||||
<span>
|
||||
Signed with DocuSeal Certificate
|
||||
</span>
|
||||
<% else %>
|
||||
<%= svg_icon('x_circle', class: 'w-6 h-6 text-red-500') %>
|
||||
<span>
|
||||
Signed with External Certificate
|
||||
</span>
|
||||
<% end %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="flex items-center space-x-1">
|
||||
<%= svg_icon('user', class: 'w-5 h-5 inline') %>
|
||||
<span><%= signature.signing_reason %></span>
|
||||
</div>
|
||||
<div class="flex items-center space-x-1">
|
||||
<%= svg_icon('calendar', class: 'w-5 h-5 inline') %>
|
||||
<span><%= l(signature.signing_time, format: :long) %></span>
|
||||
</div>
|
||||
<div class="flex items-center space-x-1">
|
||||
<%= svg_icon('certificate', class: 'w-5 h-5 inline') %>
|
||||
<span><%= signature.signer_name %></span>
|
||||
</div>
|
||||
<div class="flex items-center space-x-1">
|
||||
<%= svg_icon('lock_access', class: 'w-5 h-5 inline') %>
|
||||
<span><%= signature.signature_type %></span>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
After Width: | Height: | Size: 603 B |
|
After Width: | Height: | Size: 389 B |
|
After Width: | Height: | Size: 443 B |
|
After Width: | Height: | Size: 518 B |
|
After Width: | Height: | Size: 619 B |
|
After Width: | Height: | Size: 407 B |
|
Before Width: | Height: | Size: 261 B After Width: | Height: | Size: 395 B |