mirror of https://github.com/docusealco/docuseal
parent
170cb1ecea
commit
6a41f82e5b
@ -0,0 +1,26 @@
|
||||
# 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))
|
||||
|
||||
pdf.signatures
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_encrypted_config
|
||||
@encrypted_config =
|
||||
EncryptedConfig.find_or_initialize_by(account: current_account, key: EncryptedConfig::ESIGN_CERTS_KEY)
|
||||
end
|
||||
|
||||
def storage_configs
|
||||
params.require(:encrypted_config).permit(value: {}).tap do |e|
|
||||
e[:value].compact_blank!
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SubmissionsDebugController < ApplicationController
|
||||
layout 'flow'
|
||||
|
||||
skip_before_action :authenticate_user!
|
||||
|
||||
def index
|
||||
@submission = Submission.preload({ attachments_attachments: :blob },
|
||||
flow: { documents_attachments: :blob })
|
||||
.find_by(slug: params[:submission_slug])
|
||||
|
||||
respond_to do |f|
|
||||
f.html do
|
||||
render 'submit_flow/show'
|
||||
end
|
||||
f.pdf do
|
||||
Submissions::GenerateResultAttachments.call(@submission)
|
||||
|
||||
send_data ActiveStorage::Attachment.where(name: :documents).last.download,
|
||||
filename: 'debug.pdf',
|
||||
disposition: 'inline',
|
||||
type: 'application/pdf'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,82 @@
|
||||
import { DirectUpload } from '@rails/activestorage'
|
||||
|
||||
import { actionable } from '@github/catalyst/lib/actionable'
|
||||
import { target, targetable } from '@github/catalyst/lib/targetable'
|
||||
|
||||
export default actionable(targetable(class extends HTMLElement {
|
||||
static [target.static] = [
|
||||
'loading',
|
||||
'input',
|
||||
'valueField'
|
||||
]
|
||||
|
||||
connectedCallback () {
|
||||
this.addEventListener('drop', this.onDrop)
|
||||
|
||||
this.addEventListener('dragover', (e) => e.preventDefault())
|
||||
}
|
||||
|
||||
onDrop (e) {
|
||||
e.preventDefault()
|
||||
|
||||
this.uploadFiles(e.dataTransfer.files)
|
||||
}
|
||||
|
||||
onSelectFiles (e) {
|
||||
e.preventDefault()
|
||||
|
||||
this.uploadFiles(this.input.files).then(() => {
|
||||
this.input.value = ''
|
||||
})
|
||||
}
|
||||
|
||||
async uploadFiles (files) {
|
||||
console.log( files )
|
||||
const blobs = await Promise.all(
|
||||
Array.from(files).map(async (file) => {
|
||||
const upload = new DirectUpload(
|
||||
file,
|
||||
'/direct_uploads',
|
||||
this.input
|
||||
)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
upload.create((error, blob) => {
|
||||
if (error) {
|
||||
console.error(error)
|
||||
|
||||
return reject(error)
|
||||
} else {
|
||||
return resolve(blob)
|
||||
}
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.error(error)
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
await Promise.all(
|
||||
blobs.map((blob) => {
|
||||
return fetch('/api/attachments', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name: this.dataset.name,
|
||||
blob_signed_id: blob.signed_id,
|
||||
submission_slug: this.dataset.submissionSlug
|
||||
}),
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
}).then(resp => resp.json()).then((data) => {
|
||||
return data
|
||||
})
|
||||
})).then((result) => {
|
||||
result.forEach((attachment) => {
|
||||
if (this.valueField) {
|
||||
this.valueField.value = attachment.uuid
|
||||
}
|
||||
|
||||
this.dispatchEvent(new CustomEvent('upload', { detail: attachment }))
|
||||
})
|
||||
})
|
||||
}
|
||||
}))
|
||||
@ -0,0 +1,10 @@
|
||||
<%= form_for '', url: settings_esign_index_path, method: :post do |f| %>
|
||||
<file-dropzone data-name="verify_attachments">
|
||||
<label for="file">
|
||||
<input id="attachment_uuid" name="attachment_uuid" class="hidden" data-target="file-dropzone.valueField" type="text">
|
||||
<input id="file" class="hidden" data-action="change:file-dropzone#onSelectFiles" data-target="file-dropzone.input" type="file">
|
||||
LCick to upload
|
||||
</label>
|
||||
</file-dropzone>
|
||||
<%= f.button button_title %>
|
||||
<% end %>
|
||||
@ -0,0 +1,90 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module GenerateCertificate
|
||||
NAME = 'DocuSeal'
|
||||
SIZE = 2**11
|
||||
|
||||
module_function
|
||||
|
||||
def call(name = NAME)
|
||||
root_cert, root_key = generate_root_ca(name)
|
||||
|
||||
sub_cert, sub_key = generate_sub_ca(name, root_cert, root_key)
|
||||
cert, key = generate_certificate(name, sub_cert, sub_key)
|
||||
|
||||
{
|
||||
cert: cert.to_pem,
|
||||
key: key.to_pem,
|
||||
root_ca: root_cert.to_pem,
|
||||
root_key: root_key.to_pem,
|
||||
sub_ca: sub_cert.to_pem,
|
||||
sub_key: sub_key.to_pem
|
||||
}
|
||||
end
|
||||
|
||||
def generate_root_ca(name)
|
||||
key = OpenSSL::PKey::RSA.new(SIZE)
|
||||
|
||||
cert = OpenSSL::X509::Certificate.new
|
||||
cert.subject = OpenSSL::X509::Name.parse("/C=AT/O=#{name}/CN=#{name} Root CA")
|
||||
cert.issuer = cert.subject
|
||||
cert.not_before = Time.current
|
||||
cert.not_after = 100.years.from_now
|
||||
cert.public_key = key.public_key
|
||||
cert.serial = OpenSSL::BN.rand(160)
|
||||
|
||||
ef = OpenSSL::X509::ExtensionFactory.new
|
||||
ef.subject_certificate = cert
|
||||
ef.issuer_certificate = cert
|
||||
cert.add_extension(ef.create_extension('basicConstraints', 'CA:TRUE', true))
|
||||
cert.add_extension(ef.create_extension('keyUsage', 'Certificate Sign, CRL Sign', true))
|
||||
cert.add_extension(ef.create_extension('subjectKeyIdentifier', 'hash', false))
|
||||
cert.sign(key, OpenSSL::Digest.new('SHA256'))
|
||||
|
||||
[cert, key]
|
||||
end
|
||||
|
||||
def generate_sub_ca(name, root_ca_cert, root_ca_key)
|
||||
key = OpenSSL::PKey::RSA.new(SIZE)
|
||||
|
||||
cert = OpenSSL::X509::Certificate.new
|
||||
cert.subject = OpenSSL::X509::Name.parse("/C=AT/O=#{name}/CN=#{name} Sub-CA")
|
||||
cert.issuer = root_ca_cert.subject
|
||||
cert.not_before = Time.current
|
||||
cert.not_after = 100.years.from_now
|
||||
cert.public_key = key.public_key
|
||||
cert.serial = OpenSSL::BN.rand(160)
|
||||
|
||||
ef = OpenSSL::X509::ExtensionFactory.new
|
||||
ef.subject_certificate = cert
|
||||
ef.issuer_certificate = root_ca_cert
|
||||
cert.add_extension(ef.create_extension('basicConstraints', 'CA:TRUE', true))
|
||||
cert.add_extension(ef.create_extension('keyUsage', 'Certificate Sign, CRL Sign', true))
|
||||
cert.add_extension(ef.create_extension('subjectKeyIdentifier', 'hash', false))
|
||||
cert.sign(root_ca_key, OpenSSL::Digest.new('SHA256'))
|
||||
|
||||
[cert, key]
|
||||
end
|
||||
|
||||
def generate_certificate(name, ca_cert, ca_key)
|
||||
key = OpenSSL::PKey::RSA.new(SIZE)
|
||||
|
||||
cert = OpenSSL::X509::Certificate.new
|
||||
cert.subject = OpenSSL::X509::Name.parse("/C=AT/O=#{name}/CN=#{name} Certificate")
|
||||
cert.issuer = ca_cert.subject
|
||||
cert.not_before = Time.current
|
||||
cert.not_after = 100.years.from_now
|
||||
cert.public_key = key.public_key
|
||||
cert.serial = OpenSSL::BN.rand(160)
|
||||
|
||||
ef = OpenSSL::X509::ExtensionFactory.new
|
||||
ef.subject_certificate = cert
|
||||
ef.issuer_certificate = ca_cert
|
||||
cert.add_extension(ef.create_extension('basicConstraints', 'CA:FALSE', true))
|
||||
cert.add_extension(ef.create_extension('keyUsage', 'Digital Signature', true))
|
||||
cert.add_extension(ef.create_extension('subjectKeyIdentifier', 'hash', false))
|
||||
cert.sign(ca_key, OpenSSL::Digest.new('SHA256'))
|
||||
|
||||
[cert, key]
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PdfIcons
|
||||
PATH = Rails.root.join('lib/pdf_icons')
|
||||
|
||||
module_function
|
||||
|
||||
def check_io
|
||||
@check_io ||= StringIO.new(PATH.join('check.png').read)
|
||||
end
|
||||
|
||||
def paperclip_io
|
||||
@paperclip_io ||= StringIO.new(PATH.join('paperclip.png').read)
|
||||
end
|
||||
end
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
Loading…
Reference in new issue