|
|
|
@ -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
|
|
|
|
|