mirror of
https://github.com/docusealco/docuseal
synced 2026-11-05 06:42:32 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c216e43d24 | ||
|
|
d2373c1578 | ||
|
|
474603e1c9 | ||
|
|
1fc1444b8f | ||
|
|
47361da26f | ||
|
|
11dea042ad | ||
|
|
8756931638 | ||
|
|
180b201dcf | ||
|
|
a1c30c2093 | ||
|
|
66bf6af7ba | ||
|
|
1a65e7bcff | ||
|
|
59b5f03948 | ||
|
|
4626518c83 | ||
|
|
c18e263f34 | ||
|
|
c3dae1bfe4 | ||
|
|
b44152fd52 | ||
|
|
2889a7c937 | ||
|
|
91e65e4a19 | ||
|
|
2a1a2cbd82 | ||
|
|
99b3247cf7 | ||
|
|
fa91c6d6be |
No files matched your search
@@ -47,7 +47,8 @@ class AccountsController < ApplicationController
|
|||||||
authorize!(:manage, current_account)
|
authorize!(:manage, current_account)
|
||||||
|
|
||||||
true_user.skip_reconfirmation!
|
true_user.skip_reconfirmation!
|
||||||
true_user.update!(locked_at: Time.current, email: true_user.email.sub('@', '+removed@'))
|
true_user.update!(locked_at: Time.current, archived_at: Time.current,
|
||||||
|
email: true_user.email.sub('@', '+removed@'))
|
||||||
true_user.account.update!(archived_at: Time.current)
|
true_user.account.update!(archived_at: Time.current)
|
||||||
|
|
||||||
# rubocop:disable Layout/LineLength
|
# rubocop:disable Layout/LineLength
|
||||||
|
|||||||
@@ -17,24 +17,23 @@ module Api
|
|||||||
|
|
||||||
def verify
|
def verify
|
||||||
file = Base64.decode64(params[:file])
|
file = Base64.decode64(params[:file])
|
||||||
pdf = HexaPDF::Document.new(io: StringIO.new(file))
|
|
||||||
|
|
||||||
trusted_certs = Accounts.load_trusted_certs(current_account)
|
trusted_certs = Accounts.load_trusted_certs(current_account)
|
||||||
is_checksum_found = CompletedDocument.exists?(sha256: Base64.urlsafe_encode64(Digest::SHA256.digest(file)))
|
is_checksum_found = CompletedDocument.exists?(sha256: Base64.urlsafe_encode64(Digest::SHA256.digest(file)))
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
checksum_status: is_checksum_found ? 'verified' : 'not_found',
|
checksum_status: is_checksum_found ? 'verified' : 'not_found',
|
||||||
signatures: pdf.signatures.map do |sig|
|
signatures: VerifyPdfSignature.call(StringIO.new(file), trusted_certs).map do |sig|
|
||||||
{
|
{
|
||||||
verification_result: sig.verify(trusted_certs:).messages,
|
verification_result: sig.messages.map { |m| { type: m.status || :info, content: m.text } },
|
||||||
signer_name: sig.signer_name,
|
signer_name: sig.common_name,
|
||||||
signing_reason: sig.signing_reason,
|
signing_reason: sig.reason,
|
||||||
signing_time: sig.signing_time,
|
signing_time: sig.signing_time,
|
||||||
signature_type: sig.signature_type
|
signature_type: sig.type
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
rescue HexaPDF::MalformedPDFError
|
rescue Pdfium::PdfiumError
|
||||||
render json: { error: 'Malformed PDF' }, status: :unprocessable_content
|
render json: { error: 'Malformed PDF' }, status: :unprocessable_content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ class MfaSetupController < ApplicationController
|
|||||||
def edit; end
|
def edit; end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
RateLimit.call("mfa-setup-otp-#{current_user.id}", limit: 5, ttl: 5.minutes, enabled: true)
|
||||||
|
|
||||||
if current_user.validate_and_consume_otp!(params[:otp_attempt])
|
if current_user.validate_and_consume_otp!(params[:otp_attempt])
|
||||||
current_user.otp_required_for_login = true
|
current_user.otp_required_for_login = true
|
||||||
current_user.save!
|
current_user.save!
|
||||||
|
|
||||||
redirect_to settings_profile_index_path, notice: I18n.t('2fa_has_been_configured')
|
redirect_to settings_profile_index_path, notice: I18n.t('2fa_has_been_configured')
|
||||||
else
|
else
|
||||||
RateLimit.call("mfa-setup-otp-#{current_user.id}", limit: 5, ttl: 5.minutes, enabled: true)
|
|
||||||
|
|
||||||
@provision_url = current_user.otp_provisioning_uri(current_user.email, issuer: Docuseal.product_name)
|
@provision_url = current_user.otp_provisioning_uri(current_user.email, issuer: Docuseal.product_name)
|
||||||
|
|
||||||
@error_message = I18n.t('code_is_invalid')
|
@error_message = I18n.t('code_is_invalid')
|
||||||
@@ -31,13 +31,13 @@ class MfaSetupController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
RateLimit.call("mfa-setup-otp-#{current_user.id}", limit: 5, ttl: 5.minutes, enabled: true)
|
||||||
|
|
||||||
if current_user.validate_and_consume_otp!(params[:otp_attempt])
|
if current_user.validate_and_consume_otp!(params[:otp_attempt])
|
||||||
current_user.update!(otp_required_for_login: false, otp_secret: nil)
|
current_user.update!(otp_required_for_login: false, otp_secret: nil)
|
||||||
|
|
||||||
redirect_to settings_profile_index_path, notice: I18n.t('2fa_has_been_removed')
|
redirect_to settings_profile_index_path, notice: I18n.t('2fa_has_been_removed')
|
||||||
else
|
else
|
||||||
RateLimit.call("mfa-setup-otp-#{current_user.id}", limit: 5, ttl: 5.minutes, enabled: true)
|
|
||||||
|
|
||||||
@error_message = I18n.t('code_is_invalid')
|
@error_message = I18n.t('code_is_invalid')
|
||||||
|
|
||||||
render turbo_stream: turbo_stream.replace(:modal, template: 'mfa_setup/edit'), status: :unprocessable_content
|
render turbo_stream: turbo_stream.replace(:modal, template: 'mfa_setup/edit'), status: :unprocessable_content
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class SubmitFormCompletedDownloadController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def submitter_slug
|
def submitter_slug
|
||||||
params[:submit_form_slug] || params[:submitter_slug] || params[:submitter_id]
|
params[:submit_form_slug] || params[:submitter_slug]
|
||||||
end
|
end
|
||||||
|
|
||||||
def respond_with_combined(submitter)
|
def respond_with_combined(submitter)
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ class SubmitFormController < ApplicationController
|
|||||||
submitter_version = SubmitterVersion.find_by!(slug: params[:slug] || params[:submit_form_slug])
|
submitter_version = SubmitterVersion.find_by!(slug: params[:slug] || params[:submit_form_slug])
|
||||||
|
|
||||||
@submitter = submitter_version.submitter
|
@submitter = submitter_version.submitter
|
||||||
|
|
||||||
|
maybe_render_locked_page
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class TestingAccountsController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
authorize!(:manage, current_account)
|
authorize!(:manage, current_account)
|
||||||
authorize!(:manage, current_user)
|
authorize!(:manage, current_user)
|
||||||
|
authorize!(:manage, EncryptedConfig)
|
||||||
|
|
||||||
impersonate_user(Accounts.find_or_create_testing_user(true_user.account))
|
impersonate_user(Accounts.find_or_create_testing_user(true_user.account))
|
||||||
|
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ export default {
|
|||||||
download () {
|
download () {
|
||||||
this.isDownloading = true
|
this.isDownloading = true
|
||||||
|
|
||||||
fetch(this.baseUrl + `/submitters/${this.submitterSlug}/download`, {
|
fetch(this.baseUrl + `/s/${this.submitterSlug}/documents`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
...this.fetchOptions
|
...this.fetchOptions
|
||||||
}).then(async (response) => {
|
}).then(async (response) => {
|
||||||
|
|||||||
@@ -366,6 +366,9 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeUnmount () {
|
||||||
|
document.getElementById('list_form_buttons')?.classList?.add('hidden')
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
t (key) {
|
t (key) {
|
||||||
return this.i18n[key] || key
|
return this.i18n[key] || key
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center md:items-end gap-2">
|
<div class="flex items-center md:items-end gap-2">
|
||||||
<%= render 'submissions_filters/applied_filters', filter_params:, with_status: true %>
|
<%= render 'submissions_filters/applied_filters', filter_params:, with_status: true, with_default_status: true %>
|
||||||
<%= render 'submissions_filters/filter_button', filter_params: %>
|
<%= render 'submissions_filters/filter_button', filter_params: %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,15 +3,16 @@
|
|||||||
<% ordered_filters = request.query_parameters.keys.filter_map { |key| filter_names.find { |name| key.start_with?(name) } }.uniq %>
|
<% ordered_filters = request.query_parameters.keys.filter_map { |key| filter_names.find { |name| key.start_with?(name) } }.uniq %>
|
||||||
<% chip_order = ordered_filters.reverse.each_with_index.to_h { |name, index| [name, index + 1] } %>
|
<% chip_order = ordered_filters.reverse.each_with_index.to_h { |name, index| [name, index + 1] } %>
|
||||||
<% chip_order.default = ordered_filters.size + 1 %>
|
<% chip_order.default = ordered_filters.size + 1 %>
|
||||||
<% status_icon = { 'declined' => 'x_circle', 'expired' => 'clock_cancel', 'partially_completed' => 'clock_edit', 'sent' => 'send', 'opened' => 'mail_opened' }[params[:status]] %>
|
|
||||||
<% status_icons = { 'all' => 'list', 'pending' => 'clock', 'completed' => 'circle_check' } %>
|
<% status_icons = { 'all' => 'list', 'pending' => 'clock', 'completed' => 'circle_check' } %>
|
||||||
<% current_status = status_icons.key?(params[:status].to_s) ? params[:status].to_s : 'all' %>
|
<% current_status = status_icons.key?(params[:status].to_s) ? params[:status].to_s : 'all' %>
|
||||||
|
<% status_icon = { 'declined' => 'x_circle', 'expired' => 'clock_cancel', 'partially_completed' => 'clock_edit', 'sent' => 'send', 'opened' => 'mail_opened' }[params[:status]] %>
|
||||||
|
<% default_status_icon = status_icons[params[:status]] if status_icon.blank? && local_assigns[:with_default_status] && current_status != 'all' %>
|
||||||
<% with_status_button = local_assigns[:with_status] && status_icon.blank? %>
|
<% with_status_button = local_assigns[:with_status] && status_icon.blank? %>
|
||||||
<% chips_html = capture do %>
|
<% status_chip_html = capture do %>
|
||||||
<% if status_icon %>
|
<% if status_icon || default_status_icon %>
|
||||||
<div class="order-none flex h-10 px-2 py-1 text-base md:text-lg items-center justify-between border text-center text-neutral font-semibold rounded-xl shrink-0 max-w-[60vw] md:w-36 border-neutral-700">
|
<div class="order-none flex h-10 px-2 py-1 text-base md:text-lg items-center justify-between border text-center text-neutral font-semibold rounded-xl shrink-0 max-w-[60vw] md:w-36 border-neutral-700 <%= 'max-md:hidden' if default_status_icon %>">
|
||||||
<%= link_to submissions_filter_path('status', query_params.merge(path: url_for, with_remove: true)), data: { turbo_frame: 'modal' }, class: 'flex items-center space-x-1 flex-1 min-w-0 pr-1' do %>
|
<%= link_to submissions_filter_path('status', query_params.merge(path: url_for, with_remove: true)), data: { turbo_frame: 'modal' }, class: 'flex items-center space-x-1 flex-1 min-w-0 pr-1' do %>
|
||||||
<%= svg_icon(status_icon, class: 'w-5 h-5 shrink-0') %>
|
<%= svg_icon(status_icon || default_status_icon, class: 'w-5 h-5 shrink-0') %>
|
||||||
<span class="font-normal truncate"><%= t(params[:status]) %></span>
|
<span class="font-normal truncate"><%= t(params[:status]) %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= link_to url_for(params: request.query_parameters.except('status')), class: 'rounded-lg ml-1 shrink-0 hover:bg-base-content hover:text-white' do %>
|
<%= link_to url_for(params: request.query_parameters.except('status')), class: 'rounded-lg ml-1 shrink-0 hover:bg-base-content hover:text-white' do %>
|
||||||
@@ -19,6 +20,8 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% chips_html = capture do %>
|
||||||
<% if params[:folder].present? %>
|
<% if params[:folder].present? %>
|
||||||
<div class="order-<%= chip_order['folder'] %> md:order-none md:tooltip tooltip-no-touch tooltip-bottom flex md:flex h-10 px-2 py-1 text-base md:text-lg items-center justify-between border text-center text-neutral font-semibold rounded-xl shrink-0 max-w-[60vw] md:w-36 border-neutral-700" data-tip="<%= t('folder') %>">
|
<div class="order-<%= chip_order['folder'] %> md:order-none md:tooltip tooltip-no-touch tooltip-bottom flex md:flex h-10 px-2 py-1 text-base md:text-lg items-center justify-between border text-center text-neutral font-semibold rounded-xl shrink-0 max-w-[60vw] md:w-36 border-neutral-700" data-tip="<%= t('folder') %>">
|
||||||
<%= link_to submissions_filter_path('folder', query_params.merge(path: url_for, with_remove: true)), data: { turbo_frame: 'modal' }, class: 'flex items-center space-x-1 flex-1 min-w-0 pr-1' do %>
|
<%= link_to submissions_filter_path('folder', query_params.merge(path: url_for, with_remove: true)), data: { turbo_frame: 'modal' }, class: 'flex items-center space-x-1 flex-1 min-w-0 pr-1' do %>
|
||||||
@@ -78,7 +81,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if with_status_button && chips_html.blank? %>
|
<% with_status_dropdown = with_status_button && chips_html.blank? %>
|
||||||
|
<% if with_status_dropdown %>
|
||||||
<div class="dropdown md:hidden shrink-0">
|
<div class="dropdown md:hidden shrink-0">
|
||||||
<label tabindex="0" class="cursor-pointer flex h-10 px-2 py-1 space-x-1 text-base items-center border text-neutral rounded-xl <%= current_status == 'all' ? 'border-neutral-300' : 'border-neutral-700' %>">
|
<label tabindex="0" class="cursor-pointer flex h-10 px-2 py-1 space-x-1 text-base items-center border text-neutral rounded-xl <%= current_status == 'all' ? 'border-neutral-300' : 'border-neutral-700' %>">
|
||||||
<%= svg_icon(status_icons[current_status], class: 'w-5 h-5 shrink-0') %>
|
<%= svg_icon(status_icons[current_status], class: 'w-5 h-5 shrink-0') %>
|
||||||
@@ -122,15 +126,16 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if chips_html.present? %>
|
<% if chips_html.present? || status_chip_html.present? %>
|
||||||
<scroll-fade class="flex items-center gap-2 overflow-x-auto flex-1 min-w-0 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:h-0 [&::-webkit-scrollbar]:w-0 md:contents">
|
<scroll-fade class="flex items-center gap-2 overflow-x-auto flex-1 min-w-0 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:h-0 [&::-webkit-scrollbar]:w-0 md:contents <%= 'max-md:hidden' if with_status_dropdown %>">
|
||||||
<% if with_status_button %>
|
<% if with_status_button && !with_status_dropdown %>
|
||||||
<a href="<%= submissions_filter_path('status', query_params.merge(path: url_for)) %>" data-turbo-frame="modal" class="order-none md:hidden flex h-10 px-2 py-1 space-x-1 text-base items-center border text-neutral rounded-xl shrink-0 <%= current_status == 'all' ? 'border-neutral-300' : 'border-neutral-700' %>">
|
<a href="<%= submissions_filter_path('status', query_params.merge(path: url_for)) %>" data-turbo-frame="modal" class="order-none md:hidden flex h-10 px-2 py-1 space-x-1 text-base items-center border text-neutral rounded-xl shrink-0 <%= current_status == 'all' ? 'border-neutral-300' : 'border-neutral-700' %>">
|
||||||
<%= svg_icon(status_icons[current_status], class: 'w-5 h-5 shrink-0') %>
|
<%= svg_icon(status_icons[current_status], class: 'w-5 h-5 shrink-0') %>
|
||||||
<span><%= t(current_status) %></span>
|
<span><%= t(current_status) %></span>
|
||||||
<%= svg_icon('chevron_down', class: 'w-4 h-4 shrink-0') %>
|
<%= svg_icon('chevron_down', class: 'w-4 h-4 shrink-0') %>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= status_chip_html %>
|
||||||
<%= chips_html %>
|
<%= chips_html %>
|
||||||
</scroll-fade>
|
</scroll-fade>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -64,9 +64,13 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-wrap gap-2 w-full md:w-fit md:justify-between md:flex-none md:pt-1">
|
<div class="flex flex-wrap gap-2 w-full md:w-fit md:justify-between md:flex-none md:pt-1">
|
||||||
<% if !template.archived_at? && can?(:destroy, template) %>
|
<% if can?(:destroy, template) %>
|
||||||
|
<% if template.archived_at? %>
|
||||||
|
<%= button_to button_title(title: t('restore'), disabled_with: t('restoring')[..-4], icon: svg_icon('rotate', class: 'w-6 h-6')), template_restore_index_path(template), class: 'btn btn-outline btn-sm w-full', form_class: 'flex-1' %>
|
||||||
|
<% else %>
|
||||||
<%= button_to button_title(title: t('archive'), disabled_with: t('archiving')[..-4], title_class: 'inline', icon: svg_icon('archive', class: 'w-6 h-6')), template_path(template), class: 'btn btn-outline btn-sm w-full', form_class: 'flex-1', method: :delete %>
|
<%= button_to button_title(title: t('archive'), disabled_with: t('archiving')[..-4], title_class: 'inline', icon: svg_icon('archive', class: 'w-6 h-6')), template_path(template), class: 'btn btn-outline btn-sm w-full', form_class: 'flex-1', method: :delete %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% end %>
|
||||||
<% if can?(:create, current_account.templates.new(author: current_user)) %>
|
<% if can?(:create, current_account.templates.new(author: current_user)) %>
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<%= link_to new_template_clone_path(template), class: 'btn btn-outline btn-sm w-full', data: { turbo_frame: :modal } do %>
|
<%= link_to new_template_clone_path(template), class: 'btn btn-outline btn-sm w-full', data: { turbo_frame: :modal } do %>
|
||||||
@@ -99,9 +103,6 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if template.archived_at? %>
|
<% if template.archived_at? %>
|
||||||
<% if can?(:destroy, template) %>
|
|
||||||
<%= button_to button_title(title: t('restore'), disabled_with: t('restoring')[..-4], icon: svg_icon('rotate', class: 'w-6 h-6')), template_restore_index_path(template), class: 'btn btn-outline btn-sm w-full', form_class: 'flex-1' %>
|
|
||||||
<% end %>
|
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<%= link_to template_preview_path(template), class: 'btn btn-outline btn-sm w-full' do %>
|
<%= link_to template_preview_path(template), class: 'btn btn-outline btn-sm w-full' do %>
|
||||||
<span class="flex items-center justify-center space-x-2">
|
<span class="flex items-center justify-center space-x-2">
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-nowrap md:flex-wrap md:justify-end items-center gap-2">
|
<div class="flex flex-nowrap md:flex-wrap md:justify-end items-center gap-2">
|
||||||
<%= render 'submissions_filters/applied_filters', filter_params:, with_status: true %>
|
<%= render 'submissions_filters/applied_filters', filter_params:, with_status: true, with_default_status: true %>
|
||||||
<div class="hidden md:block shrink-0 md:order-first">
|
<div class="hidden md:block shrink-0 md:order-first">
|
||||||
<%= link_to new_template_submissions_export_path(@template, archived: true), class: 'btn btn-ghost text-base h-10 min-h-10', data: { turbo_frame: 'modal' } do %>
|
<%= link_to new_template_submissions_export_path(@template, archived: true), class: 'btn btn-ghost text-base h-10 min-h-10', data: { turbo_frame: 'modal' } do %>
|
||||||
<%= svg_icon('download', class: 'w-6 h-6 stroke-2') %>
|
<%= svg_icon('download', class: 'w-6 h-6 stroke-2') %>
|
||||||
|
|||||||
+4
-1
@@ -175,10 +175,13 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
resources :submitters, only: %i[] do
|
resources :submitters, only: %i[] do
|
||||||
resources :download, only: %i[index], controller: 'submitters_download', constraints: { submitter_id: /\d+/ }
|
resources :download, only: %i[index], controller: 'submitters_download', constraints: { submitter_id: /\d+/ }
|
||||||
resources :download, only: %i[index], controller: 'submit_form_completed_download'
|
|
||||||
resources :send_email, only: %i[create], controller: 'submitters_send_email'
|
resources :send_email, only: %i[create], controller: 'submitters_send_email'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :submitters, only: %i[], param: 'slug' do
|
||||||
|
resources :download, only: %i[index], controller: 'submit_form_completed_download'
|
||||||
|
end
|
||||||
|
|
||||||
resources :settings, only: %i[index]
|
resources :settings, only: %i[index]
|
||||||
|
|
||||||
scope '/settings', as: :settings do
|
scope '/settings', as: :settings do
|
||||||
|
|||||||
+30
-74
@@ -3,6 +3,9 @@
|
|||||||
module LoadBmp
|
module LoadBmp
|
||||||
BPPS = [1, 4, 8, 24, 32].freeze
|
BPPS = [1, 4, 8, 24, 32].freeze
|
||||||
|
|
||||||
|
MAX_COORD = ENV.fetch('VIPS_MAX_COORD', '17000').to_i
|
||||||
|
MAX_PIXELS = 145_000_000
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# rubocop:disable Metrics
|
# rubocop:disable Metrics
|
||||||
@@ -18,40 +21,28 @@ module LoadBmp
|
|||||||
header_data[:height]
|
header_data[:height]
|
||||||
)
|
)
|
||||||
|
|
||||||
if header_data[:bpp] <= 8
|
padded_rows = Vips::Image.new_from_memory_copy(
|
||||||
final_pixel_data = decode_indexed_pixel_data(
|
|
||||||
raw_pixel_data_from_file,
|
raw_pixel_data_from_file,
|
||||||
header_data[:bpp],
|
|
||||||
header_data[:width],
|
|
||||||
header_data[:height],
|
|
||||||
header_data[:bmp_stride],
|
header_data[:bmp_stride],
|
||||||
header_data[:color_table]
|
|
||||||
)
|
|
||||||
bands = 3
|
|
||||||
else
|
|
||||||
final_pixel_data = prepare_unpadded_pixel_data_string(
|
|
||||||
raw_pixel_data_from_file,
|
|
||||||
header_data[:bpp],
|
|
||||||
header_data[:width],
|
|
||||||
header_data[:height],
|
header_data[:height],
|
||||||
header_data[:bmp_stride]
|
1,
|
||||||
|
:uchar
|
||||||
)
|
)
|
||||||
bands = header_data[:bpp] / 8
|
|
||||||
end
|
|
||||||
|
|
||||||
image = Vips::Image.new_from_memory_copy(final_pixel_data, header_data[:width], header_data[:height], bands, :uchar)
|
|
||||||
|
|
||||||
image = image.flip(:vertical) if header_data[:orientation] == -1
|
|
||||||
|
|
||||||
image_rgb =
|
image_rgb =
|
||||||
if header_data[:bpp] <= 8
|
if header_data[:bpp] <= 8
|
||||||
image
|
decode_indexed_pixel_data(padded_rows, header_data[:bpp], header_data[:width], header_data[:color_table])
|
||||||
elsif bands == 3
|
else
|
||||||
image.recomb(band3_recomb)
|
bands = header_data[:bpp] / 8
|
||||||
elsif bands == 4
|
|
||||||
image.recomb(band4_recomb)
|
image = padded_rows.extract_area(0, 0, header_data[:width] * bands, header_data[:height])
|
||||||
|
.bandfold(factor: bands)
|
||||||
|
|
||||||
|
bands == 3 ? image.recomb(band3_recomb) : image.recomb(band4_recomb)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
image_rgb = image_rgb.flip(:vertical) if header_data[:orientation] == -1
|
||||||
|
|
||||||
image_rgb = image_rgb.copy(interpretation: :srgb) if image_rgb.interpretation != :srgb
|
image_rgb = image_rgb.copy(interpretation: :srgb) if image_rgb.interpretation != :srgb
|
||||||
|
|
||||||
image_rgb
|
image_rgb
|
||||||
@@ -98,6 +89,9 @@ module LoadBmp
|
|||||||
|
|
||||||
raise ArgumentError, 'BMP width must be positive.' if width <= 0
|
raise ArgumentError, 'BMP width must be positive.' if width <= 0
|
||||||
raise ArgumentError, 'BMP height must be positive.' if height <= 0
|
raise ArgumentError, 'BMP height must be positive.' if height <= 0
|
||||||
|
if width > MAX_COORD || height > MAX_COORD || width * height > MAX_PIXELS
|
||||||
|
raise ArgumentError, "BMP dimensions are too large: #{width}x#{height}."
|
||||||
|
end
|
||||||
|
|
||||||
if compression != 0
|
if compression != 0
|
||||||
raise ArgumentError,
|
raise ArgumentError,
|
||||||
@@ -164,62 +158,24 @@ module LoadBmp
|
|||||||
raw_pixel_data_from_file
|
raw_pixel_data_from_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_unpadded_pixel_data_string(raw_pixel_data_from_file, bpp, width, height, bmp_stride)
|
def decode_indexed_pixel_data(padded_rows, bpp, width, color_table)
|
||||||
bytes_per_pixel = bpp / 8
|
pixels_per_byte = 8 / bpp
|
||||||
actual_row_width_bytes = width * bytes_per_pixel
|
|
||||||
|
|
||||||
unpadded_rows = Array.new(height)
|
image = padded_rows.maplut(build_palette_lut(bpp, color_table))
|
||||||
current_offset_in_blob = 0
|
image = image.bandunfold.bandfold(factor: 3) if pixels_per_byte > 1
|
||||||
|
|
||||||
height.times do |i|
|
image.extract_area(0, 0, width, padded_rows.height)
|
||||||
if current_offset_in_blob + actual_row_width_bytes > raw_pixel_data_from_file.bytesize
|
|
||||||
raise ArgumentError,
|
|
||||||
"Not enough data in pixel blob for row #{i}. Offset #{current_offset_in_blob}, " \
|
|
||||||
"row width #{actual_row_width_bytes}, blob size #{raw_pixel_data_from_file.bytesize}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
unpadded_row_slice = raw_pixel_data_from_file.byteslice(current_offset_in_blob, actual_row_width_bytes)
|
def build_palette_lut(bpp, color_table)
|
||||||
|
pixels_per_byte = 8 / bpp
|
||||||
|
mask = (1 << bpp) - 1
|
||||||
|
|
||||||
if unpadded_row_slice.nil? || unpadded_row_slice.bytesize < actual_row_width_bytes
|
entries = Array.new(256) do |byte_val|
|
||||||
raise ArgumentError, "Failed to slice a full unpadded row from pixel data blob for row #{i}."
|
(0...pixels_per_byte).flat_map { |i| color_table[(byte_val >> ((pixels_per_byte - 1 - i) * bpp)) & mask] }
|
||||||
end
|
end
|
||||||
|
|
||||||
unpadded_rows[i] = unpadded_row_slice
|
Vips::Image.new_from_memory_copy(entries.flatten.pack('C*'), 256, 1, pixels_per_byte * 3, :uchar)
|
||||||
current_offset_in_blob += bmp_stride
|
|
||||||
end
|
|
||||||
|
|
||||||
unpadded_rows.join
|
|
||||||
end
|
|
||||||
|
|
||||||
def decode_indexed_pixel_data(raw_data, bpp, width, height, bmp_stride, color_table)
|
|
||||||
palette = color_table.map { |r, g, b| [r, g, b].pack('CCC') }
|
|
||||||
|
|
||||||
output = String.new(capacity: width * height * 3)
|
|
||||||
|
|
||||||
height.times do |y|
|
|
||||||
row_offset = y * bmp_stride
|
|
||||||
|
|
||||||
case bpp
|
|
||||||
when 1
|
|
||||||
width.times do |x|
|
|
||||||
byte_val = raw_data.getbyte(row_offset + (x >> 3))
|
|
||||||
index = (byte_val >> (7 - (x & 7))) & 0x01
|
|
||||||
output << palette[index]
|
|
||||||
end
|
|
||||||
when 4
|
|
||||||
width.times do |x|
|
|
||||||
byte_val = raw_data.getbyte(row_offset + (x >> 1))
|
|
||||||
index = x.even? ? (byte_val >> 4) & 0x0F : byte_val & 0x0F
|
|
||||||
output << palette[index]
|
|
||||||
end
|
|
||||||
when 8
|
|
||||||
width.times do |x|
|
|
||||||
output << palette[raw_data.getbyte(row_offset + x)]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
output
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def band3_recomb
|
def band3_recomb
|
||||||
|
|||||||
+1
-1
@@ -94,7 +94,7 @@ module LoadIco
|
|||||||
|
|
||||||
palette = []
|
palette = []
|
||||||
if dib_bpp <= 8
|
if dib_bpp <= 8
|
||||||
num_palette_entries = dib_clr_used.zero? ? (1 << dib_bpp) : dib_clr_used
|
num_palette_entries = [dib_clr_used.zero? ? (1 << dib_bpp) : dib_clr_used, 1 << dib_bpp].min
|
||||||
num_palette_entries.times do
|
num_palette_entries.times do
|
||||||
palette_color_bytes = dib_io.read(4)
|
palette_color_bytes = dib_io.read(4)
|
||||||
return nil unless palette_color_bytes && palette_color_bytes.bytesize == 4
|
return nil unless palette_color_bytes && palette_color_bytes.bytesize == 4
|
||||||
|
|||||||
@@ -236,6 +236,8 @@ module SearchEntries
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_hyphens(entry, text)
|
def add_hyphens(entry, text)
|
||||||
|
text = text.tr('\\', ' ')
|
||||||
|
|
||||||
hyphens = text.scan(/\b[^\s]*?\d-[^\s]+?\b/) + text.scan(/\b[^\s]+-\d[^\s]*?\b/)
|
hyphens = text.scan(/\b[^\s]*?\d-[^\s]+?\b/) + text.scan(/\b[^\s]+-\d[^\s]*?\b/)
|
||||||
|
|
||||||
hyphens.uniq.each_with_index do |item, index|
|
hyphens.uniq.each_with_index do |item, index|
|
||||||
|
|||||||
+14
-3
@@ -3,6 +3,11 @@
|
|||||||
module Submissions
|
module Submissions
|
||||||
DEFAULT_SUBMITTERS_ORDER = 'random'
|
DEFAULT_SUBMITTERS_ORDER = 'random'
|
||||||
|
|
||||||
|
SKIP_EMAIL_FIX_LABELS = %w[ga gami gasi gil gma gmao gmi gmsi goi ol].freeze
|
||||||
|
|
||||||
|
SKIP_EMAIL_FIX_TLDS =
|
||||||
|
/\.(?:gob(?:\.\w+)?|om|mm|cm|et|mo|nz|za|ie|mom|free|comsec|unicom|ed(?:\.\w+){1,2})\z/i
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def maybe_update_completed_at(submission)
|
def maybe_update_completed_at(submission)
|
||||||
@@ -210,7 +215,7 @@ module Submissions
|
|||||||
return email.downcase.sub(/@gmail?\z/i, '@gmail.com') if email.match?(/@gmail?\z/i)
|
return email.downcase.sub(/@gmail?\z/i, '@gmail.com') if email.match?(/@gmail?\z/i)
|
||||||
|
|
||||||
return email.downcase if email.include?(',') ||
|
return email.downcase if email.include?(',') ||
|
||||||
email.match?(/\.(?:gob(?:\.\w+)?|om|mm|cm|et|mo|nz|za|ie|ed\.jp)\z/i) ||
|
email.match?(SKIP_EMAIL_FIX_TLDS) ||
|
||||||
email.exclude?('.')
|
email.exclude?('.')
|
||||||
|
|
||||||
fixed_email = EmailTypo.call(email.delete_prefix('<'))
|
fixed_email = EmailTypo.call(email.delete_prefix('<'))
|
||||||
@@ -220,8 +225,7 @@ module Submissions
|
|||||||
domain = email.split('@').last.to_s.downcase
|
domain = email.split('@').last.to_s.downcase
|
||||||
fixed_domain = fixed_email.to_s.split('@').last
|
fixed_domain = fixed_email.to_s.split('@').last
|
||||||
|
|
||||||
return email.downcase if domain == fixed_domain
|
return email.downcase if domain == fixed_domain || skip_email_fix?(domain, fixed_domain)
|
||||||
return email.downcase if fixed_domain.match?(/\Agmail\.(?!com\z)/i)
|
|
||||||
|
|
||||||
threshold = fixed_domain.start_with?('hotmail.') ? 2 : 3
|
threshold = fixed_domain.start_with?('hotmail.') ? 2 : 3
|
||||||
|
|
||||||
@@ -236,6 +240,13 @@ module Submissions
|
|||||||
fixed_email
|
fixed_email
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def skip_email_fix?(domain, fixed_domain)
|
||||||
|
return true if SKIP_EMAIL_FIX_LABELS.include?(domain.split('.').first)
|
||||||
|
return true if fixed_domain.match?(/\Agmail\.(?!com\z)/i)
|
||||||
|
|
||||||
|
fixed_domain.match?(/\A(?:comcast|verizon)\./i) && !domain.match?(/\A(?:comcast|verizon)\./i)
|
||||||
|
end
|
||||||
|
|
||||||
def filtered_conditions_schema(submission, values: nil, include_submitter_uuid: nil)
|
def filtered_conditions_schema(submission, values: nil, include_submitter_uuid: nil)
|
||||||
(submission.template_schema || submission.template.schema).filter_map do |item|
|
(submission.template_schema || submission.template.schema).filter_map do |item|
|
||||||
if item['conditions'].present?
|
if item['conditions'].present?
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ module Submissions
|
|||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
TESTING_FOOTER = GenerateResultAttachments::TESTING_FOOTER
|
TESTING_FOOTER = GenerateResultAttachments::TESTING_FOOTER
|
||||||
|
UNSUPPORTED_IMAGE_TYPES = GenerateResultAttachments::UNSUPPORTED_IMAGE_TYPES
|
||||||
|
|
||||||
RTL_REGEXP = TextUtils::RTL_REGEXP
|
RTL_REGEXP = TextUtils::RTL_REGEXP
|
||||||
MAX_IMAGE_HEIGHT = 100
|
MAX_IMAGE_HEIGHT = 100
|
||||||
@@ -301,7 +302,7 @@ module Submissions
|
|||||||
},
|
},
|
||||||
completed_event.data['ip'] && { text: "IP: #{completed_event.data['ip']}\n" },
|
completed_event.data['ip'] && { text: "IP: #{completed_event.data['ip']}\n" },
|
||||||
completed_event.data['sid'] && { text: "#{I18n.t('session_id')}: #{completed_event.data['sid']}\n" },
|
completed_event.data['sid'] && { text: "#{I18n.t('session_id')}: #{completed_event.data['sid']}\n" },
|
||||||
completed_event.data['ua'] && { text: "User agent: #{completed_event.data['ua']}\n" },
|
completed_event.data['ua'] && { text: "User agent: #{completed_event.data['ua'].to_s.squish}\n" },
|
||||||
submitter.timezone && { text: "Time zone: #{submitter.timezone.to_s.sub('Kiev', 'Kyiv')}\n" },
|
submitter.timezone && { text: "Time zone: #{submitter.timezone.to_s.sub('Kiev', 'Kyiv')}\n" },
|
||||||
"\n"
|
"\n"
|
||||||
].compact_blank, line_spacing: 1.3, padding: [10, 20, 20, 0]
|
].compact_blank, line_spacing: 1.3, padding: [10, 20, 20, 0]
|
||||||
@@ -354,8 +355,9 @@ module Submissions
|
|||||||
|
|
||||||
field_type = field['type']
|
field_type = field['type']
|
||||||
|
|
||||||
if field_type == 'image' &&
|
if (field_type == 'image' || field_type == 'stamp') &&
|
||||||
submitter.attachments.find { |a| a.uuid == value }.then { |a| !a.image? || a.content_type == 'image/heic' }
|
submitter.attachments.find { |a| a.uuid == value }
|
||||||
|
.then { |a| !a.image? || a.content_type.in?(UNSUPPORTED_IMAGE_TYPES) }
|
||||||
field_type = 'file'
|
field_type = 'file'
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -478,7 +480,7 @@ module Submissions
|
|||||||
submitter.name || submitter.email || submitter.phone
|
submitter.name || submitter.email || submitter.phone
|
||||||
end
|
end
|
||||||
|
|
||||||
submitter_name = TextUtils.maybe_rtl_reverse(submitter_name.to_s)
|
submitter_name = TextUtils.maybe_rtl_reverse(submitter_name.to_s.squish)
|
||||||
|
|
||||||
text =
|
text =
|
||||||
if event.event_type == 'complete_verification'
|
if event.event_type == 'complete_verification'
|
||||||
@@ -488,12 +490,12 @@ module Submissions
|
|||||||
(invited_submitter = submission.submitters.find { |e| e.uuid == event.data['uuid'] }) &&
|
(invited_submitter = submission.submitters.find { |e| e.uuid == event.data['uuid'] }) &&
|
||||||
(name = submission.template_submitters.find { |e| e['uuid'] == event.data['uuid'] }&.dig('name'))
|
(name = submission.template_submitters.find { |e| e['uuid'] == event.data['uuid'] }&.dig('name'))
|
||||||
invited_submitter_name = TextUtils.maybe_rtl_reverse(
|
invited_submitter_name = TextUtils.maybe_rtl_reverse(
|
||||||
[invited_submitter.name || invited_submitter.email || invited_submitter.phone, name].join(' ')
|
[invited_submitter.name || invited_submitter.email || invited_submitter.phone, name].join(' ').squish
|
||||||
)
|
)
|
||||||
I18n.t('submission_event_names.invite_party_by_html', invited_submitter_name:,
|
I18n.t('submission_event_names.invite_party_by_html', invited_submitter_name:,
|
||||||
submitter_name:)
|
submitter_name:)
|
||||||
elsif with_audit_sender && (event.event_type == 'send_email' || event.event_type == 'send_sms')
|
elsif with_audit_sender && (event.event_type == 'send_email' || event.event_type == 'send_sms')
|
||||||
created_by_name = TextUtils.maybe_rtl_reverse(submission.created_by_user.full_name)
|
created_by_name = TextUtils.maybe_rtl_reverse(submission.created_by_user.full_name.to_s.squish)
|
||||||
|
|
||||||
[
|
[
|
||||||
I18n.t("submission_event_names.#{event.event_type}_to_html", submitter_name:),
|
I18n.t("submission_event_names.#{event.event_type}_to_html", submitter_name:),
|
||||||
@@ -502,7 +504,7 @@ module Submissions
|
|||||||
elsif event.event_type == 'delegate_form'
|
elsif event.event_type == 'delegate_form'
|
||||||
from = event.data['old_email'].presence ||
|
from = event.data['old_email'].presence ||
|
||||||
versions.rfind { |v| v.created_at <= event.event_timestamp }&.then { |v| v.name || v.phone }
|
versions.rfind { |v| v.created_at <= event.event_timestamp }&.then { |v| v.name || v.phone }
|
||||||
from = TextUtils.maybe_rtl_reverse(from.to_s)
|
from = TextUtils.maybe_rtl_reverse(from.to_s.squish)
|
||||||
I18n.t('submission_event_names.delegate_form_by_html', from:, to: event.data['email'])
|
I18n.t('submission_event_names.delegate_form_by_html', from:, to: event.data['email'])
|
||||||
elsif event.event_type.include?('send_')
|
elsif event.event_type.include?('send_')
|
||||||
I18n.t("submission_event_names.#{event.event_type}_to_html", submitter_name:)
|
I18n.t("submission_event_names.#{event.event_type}_to_html", submitter_name:)
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ module Submissions
|
|||||||
|
|
||||||
SIGN_REASON = 'Signed with DocuSeal.com'
|
SIGN_REASON = 'Signed with DocuSeal.com'
|
||||||
|
|
||||||
|
UNSUPPORTED_IMAGE_TYPES = ['image/heic', 'image/avif'].freeze
|
||||||
|
|
||||||
RTL_REGEXP = TextUtils::RTL_REGEXP
|
RTL_REGEXP = TextUtils::RTL_REGEXP
|
||||||
|
|
||||||
TEXT_LEFT_MARGIN = 1
|
TEXT_LEFT_MARGIN = 1
|
||||||
@@ -300,8 +302,9 @@ module Submissions
|
|||||||
|
|
||||||
field_type = field['type']
|
field_type = field['type']
|
||||||
|
|
||||||
if field_type == 'image' &&
|
if (field_type == 'image' || field_type == 'stamp') &&
|
||||||
submitter.attachments.find { |a| a.uuid == value }.then { |a| !a.image? || a.content_type == 'image/heic' }
|
submitter.attachments.find { |a| a.uuid == value }
|
||||||
|
.then { |a| !a.image? || a.content_type.in?(UNSUPPORTED_IMAGE_TYPES) }
|
||||||
field_type = 'file'
|
field_type = 'file'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ module Submitters
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fulltext_search_field(current_user, submitters, keyword, field_name)
|
def fulltext_search_field(current_user, submitters, keyword, field_name)
|
||||||
keyword = keyword.delete("\0\\")
|
keyword = keyword.delete("\0").tr('\\', ' ').squish
|
||||||
|
|
||||||
return submitters.none if keyword.blank?
|
return submitters.none if keyword.blank?
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,9 @@ module Submitters
|
|||||||
module_function
|
module_function
|
||||||
|
|
||||||
def call(submitter, current_user)
|
def call(submitter, current_user)
|
||||||
user =
|
return if current_user.blank? || current_user.email != submitter.email
|
||||||
if current_user && current_user.email == submitter.email
|
|
||||||
current_user
|
|
||||||
else
|
|
||||||
submitter.account.users.find_by(email: submitter.email)
|
|
||||||
end
|
|
||||||
|
|
||||||
return if user.blank?
|
user = current_user
|
||||||
|
|
||||||
fields = submitter.submission.template_fields || submitter.submission.template.fields
|
fields = submitter.submission.template_fields || submitter.submission.template.fields
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ module Submitters
|
|||||||
VARIABLE_REGEXP = /\{\{?(\w+)\}\}?/
|
VARIABLE_REGEXP = /\{\{?(\w+)\}\}?/
|
||||||
PHONE_REGEXP = /[+\d()\s-]+/
|
PHONE_REGEXP = /[+\d()\s-]+/
|
||||||
NONEDITABLE_FIELD_TYPES = %w[stamp heading strikethrough].freeze
|
NONEDITABLE_FIELD_TYPES = %w[stamp heading strikethrough].freeze
|
||||||
|
REQUIRED_FIELD_TYPES = %w[payment kba verification].freeze
|
||||||
|
|
||||||
STRFTIME_MAP = {
|
STRFTIME_MAP = {
|
||||||
'hour' => '%-k',
|
'hour' => '%-k',
|
||||||
@@ -95,7 +96,9 @@ module Submitters
|
|||||||
required_field_uuids_acc.each do |uuid|
|
required_field_uuids_acc.each do |uuid|
|
||||||
next if submitter.values[uuid].present?
|
next if submitter.values[uuid].present?
|
||||||
|
|
||||||
raise RequiredFieldError, uuid if validate_required
|
if validate_required || submitter.submission.fields_uuid_index.dig(uuid, 'type').in?(REQUIRED_FIELD_TYPES)
|
||||||
|
raise RequiredFieldError, uuid
|
||||||
|
end
|
||||||
|
|
||||||
Rollbar.warning("Required field #{submitter.id}: #{uuid}") if defined?(Rollbar)
|
Rollbar.warning("Required field #{submitter.id}: #{uuid}") if defined?(Rollbar)
|
||||||
end
|
end
|
||||||
|
|||||||
+40
-12
@@ -15,18 +15,29 @@ module VerifyPdfSignature
|
|||||||
|
|
||||||
next [] if signatures.blank?
|
next [] if signatures.blank?
|
||||||
|
|
||||||
has_unsigned_changes = unsigned_changes?(document, io)
|
verified_signatures = signatures.select { |e| verified_signature?(e, io, trusted_certs) }
|
||||||
|
trusted_signatures = verified_signatures.select { |e| trusted_signature?(e, trusted_certs) }
|
||||||
|
last_signature = (trusted_signatures.presence || verified_signatures).max_by(&:signed_end)
|
||||||
|
has_unsigned_changes = last_signature && unsigned_changes?(document, io, last_signature.signed_end)
|
||||||
|
|
||||||
signatures.map.with_index do |signature, index|
|
signatures.map do |signature|
|
||||||
build_signature(signature, io, trusted_certs,
|
build_signature(signature, trusted_certs,
|
||||||
has_unsigned_changes && index == signatures.size - 1)
|
verified: verified_signatures.include?(signature),
|
||||||
|
has_unsigned_changes: has_unsigned_changes && signature == last_signature)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_signature(signature, io, trusted_certs, has_unsigned_changes)
|
def verified_signature?(signature, io, trusted_certs)
|
||||||
|
return false unless covers_signed_revision?(signature, io)
|
||||||
|
|
||||||
|
verify_contents(OpenSSL::PKCS7.new(signature.contents), signed_data(io, signature.byte_range), trusted_certs)
|
||||||
|
rescue OpenSSL::PKCS7::PKCS7Error
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_signature(signature, trusted_certs, verified:, has_unsigned_changes:)
|
||||||
pkcs7 = OpenSSL::PKCS7.new(signature.contents)
|
pkcs7 = OpenSSL::PKCS7.new(signature.contents)
|
||||||
verified = verify_contents(pkcs7, signed_data(io, signature.byte_range), trusted_certs)
|
|
||||||
|
|
||||||
SignatureStruct.new(
|
SignatureStruct.new(
|
||||||
messages: build_messages(pkcs7, verified, trusted_certs, has_unsigned_changes),
|
messages: build_messages(pkcs7, verified, trusted_certs, has_unsigned_changes),
|
||||||
@@ -62,15 +73,25 @@ module VerifyPdfSignature
|
|||||||
end
|
end
|
||||||
|
|
||||||
def certificate_message(pkcs7, trusted_certs)
|
def certificate_message(pkcs7, trusted_certs)
|
||||||
public_key = signer_certificate(pkcs7)&.public_key&.to_der
|
if trusted_certificate?(pkcs7, trusted_certs)
|
||||||
|
|
||||||
if trusted_certs.any? { |e| e.public_key.to_der == public_key }
|
|
||||||
MessageStruct.new(text: I18n.t('signed_with_trusted_certificate'), status: :success)
|
MessageStruct.new(text: I18n.t('signed_with_trusted_certificate'), status: :success)
|
||||||
else
|
else
|
||||||
MessageStruct.new(text: I18n.t('signed_with_external_certificate'), status: :error)
|
MessageStruct.new(text: I18n.t('signed_with_external_certificate'), status: :error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def trusted_signature?(signature, trusted_certs)
|
||||||
|
trusted_certificate?(OpenSSL::PKCS7.new(signature.contents), trusted_certs)
|
||||||
|
rescue OpenSSL::PKCS7::PKCS7Error
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def trusted_certificate?(pkcs7, trusted_certs)
|
||||||
|
public_key = signer_certificate(pkcs7)&.public_key&.to_der
|
||||||
|
|
||||||
|
trusted_certs.any? { |e| e.public_key.to_der == public_key }
|
||||||
|
end
|
||||||
|
|
||||||
def verify_contents(pkcs7, signed_data, trusted_certs)
|
def verify_contents(pkcs7, signed_data, trusted_certs)
|
||||||
return false if digest_algorithms(pkcs7).blank?
|
return false if digest_algorithms(pkcs7).blank?
|
||||||
|
|
||||||
@@ -137,9 +158,16 @@ module VerifyPdfSignature
|
|||||||
Time.strptime("#{time.first(14)}#{offset.start_with?('+', '-') ? offset : '+0000'}", TIME_FORMAT)
|
Time.strptime("#{time.first(14)}#{offset.start_with?('+', '-') ? offset : '+0000'}", TIME_FORMAT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsigned_changes?(document, io)
|
def covers_signed_revision?(signature, io)
|
||||||
signed_end = document.signatures.map(&:signed_end).max
|
byte_range = signature.byte_range
|
||||||
|
|
||||||
|
return false if byte_range.size != 4 || byte_range.any?(&:negative?) || byte_range[0].positive?
|
||||||
|
return false if signature.signed_end > io.size
|
||||||
|
|
||||||
|
byte_range[2] == byte_range[1] + (signature.contents.bytesize * 2) + 2
|
||||||
|
end
|
||||||
|
|
||||||
|
def unsigned_changes?(document, io, signed_end)
|
||||||
return false if document.trailer_ends.none? { |offset| offset > signed_end }
|
return false if document.trailer_ends.none? { |offset| offset > signed_end }
|
||||||
|
|
||||||
io.seek(0)
|
io.seek(0)
|
||||||
@@ -164,7 +192,7 @@ module VerifyPdfSignature
|
|||||||
def signed_data(io, byte_range)
|
def signed_data(io, byte_range)
|
||||||
byte_range.each_slice(2).map do |offset, length|
|
byte_range.each_slice(2).map do |offset, length|
|
||||||
io.seek(offset)
|
io.seek(offset)
|
||||||
io.read(length)
|
io.read(length.clamp(0, [io.size - offset, 0].max))
|
||||||
end.join
|
end.join
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user