Fixes #3108 - Allow uploaded S/MIME certificates to download in admin interface (like in other certificate managers).

This commit is contained in:
Rolf Schmidt 2020-07-10 16:18:48 +02:00 committed by Thorsten Eckel
parent 71dcde5876
commit 37a6a748c9
3 changed files with 49 additions and 9 deletions

View file

@ -25,9 +25,25 @@
<td><%- @datetime(cert.not_before_at) %>
<td><%- @datetime(cert.not_after_at) %>
<td>
<div class="btn btn--text js-remove" title="<%- @Ti('Remove') %>">
<%- @Icon('trash') %>
<div class="dropdown dropdown--actions">
<div class="btn btn--table btn--text btn--secondary js-action" data-toggle="dropdown">
<%- @Icon('overflow-button') %>
</div>
<ul class="dropdown-menu dropdown-menu-right js-table-action-menu" role="menu">
<% if cert.private_key: %>
<li role="presentation" data-table-action="download-private">
<a href="<%= @C('http_type') %>://<%= @C('fqdn') %>/api/v1/integration/smime/private_key_download/<%= cert.id %>" download><%- @Icon('download') %> <%- @T('Download Private Key') %></a>
</li>
<% end %>
<li role="presentation" data-table-action="download-public">
<a href="<%= @C('http_type') %>://<%= @C('fqdn') %>/api/v1/integration/smime/certificate_download/<%= cert.id %>" download><%- @Icon('download') %> <%- @T('Download Certificate') %></a>
</li>
<li role="presentation" class="danger js-remove" data-table-action="remove">
<%- @Icon('trash') %> <%- @T('Delete') %>
</li>
</ul>
</div>
</td>
<% end %>
<% end %>
</tbody>

View file

@ -3,6 +3,28 @@
class Integration::SMIMEController < ApplicationController
prepend_before_action { authentication_check && authorize! }
def certificate_download
cert = SMIMECertificate.find(params[:id])
send_data(
cert.raw,
filename: "#{cert.doc_hash}.crt",
type: 'text/plain',
disposition: 'attachment'
)
end
def private_key_download
cert = SMIMECertificate.find(params[:id])
send_data(
cert.private_key,
filename: "#{cert.doc_hash}.key",
type: 'text/plain',
disposition: 'attachment'
)
end
def certificate_list
render json: SMIMECertificate.all
end

View file

@ -7,4 +7,6 @@ Zammad::Application.routes.draw do
match api_path + '/integration/smime/certificate', to: 'integration/smime#certificate_list', via: :get
match api_path + '/integration/smime/private_key', to: 'integration/smime#private_key_add', via: :post
match api_path + '/integration/smime/private_key', to: 'integration/smime#private_key_delete', via: :delete
match api_path + '/integration/smime/certificate_download/:id', to: 'integration/smime#certificate_download', via: :get
match api_path + '/integration/smime/private_key_download/:id', to: 'integration/smime#private_key_download', via: :get
end