mirror of https://github.com/docusealco/docuseal
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							30 lines
						
					
					
						
							1.1 KiB
						
					
					
				
			
		
		
	
	
							30 lines
						
					
					
						
							1.1 KiB
						
					
					
				| # frozen_string_literal: true
 | |
| 
 | |
| class VerifyPdfSignatureController < ApplicationController
 | |
|   def create
 | |
|     pdfs =
 | |
|       params[:files].map do |file|
 | |
|         HexaPDF::Document.new(io: file.open)
 | |
|       end
 | |
| 
 | |
|     cert_data = EncryptedConfig.find_by(account: current_account,
 | |
|                                         key: EncryptedConfig::ESIGN_CERTS_KEY)&.value || {}
 | |
| 
 | |
|     default_pkcs = GenerateCertificate.load_pkcs(cert_data)
 | |
| 
 | |
|     custom_certs = (cert_data['custom'] || []).map do |e|
 | |
|       OpenSSL::PKCS12.new(Base64.urlsafe_decode64(e['data']), e['password'])
 | |
|     end
 | |
| 
 | |
|     trusted_certs = [default_pkcs.certificate,
 | |
|                      *default_pkcs.ca_certs,
 | |
|                      *custom_certs.map(&:certificate),
 | |
|                      *custom_certs.flat_map(&:ca_certs).compact]
 | |
| 
 | |
|     render turbo_stream: turbo_stream.replace('result', partial: 'result',
 | |
|                                                         locals: { pdfs:, files: params[:files], trusted_certs: })
 | |
|   rescue HexaPDF::MalformedPDFError
 | |
|     render turbo_stream: turbo_stream.replace('result', html: helpers.tag.div('Invalid PDF', id: 'result'))
 | |
|   end
 | |
| end
 |