mirror of
https://github.com/laurivosandi/certidude
synced 2024-12-22 16:25:17 +00:00
api: Fix request submission form
This commit is contained in:
parent
3d1e6768bb
commit
345c2802ea
@ -11,7 +11,7 @@ from asn1crypto.csr import CertificationRequest
|
||||
from base64 import b64decode
|
||||
from certidude import config, authority, push, errors
|
||||
from certidude.auth import login_required, login_optional, authorize_admin
|
||||
from certidude.decorators import csrf_protection, MyEncoder
|
||||
from certidude.decorators import csrf_protection, MyEncoder, serialize
|
||||
from certidude.firewall import whitelist_subnets, whitelist_content_types
|
||||
from datetime import datetime
|
||||
from oscrypto import asymmetric
|
||||
@ -38,8 +38,14 @@ class RequestListResource(object):
|
||||
reasons = []
|
||||
body = req.stream.read(req.content_length)
|
||||
|
||||
try:
|
||||
header, _, der_bytes = pem.unarmor(body)
|
||||
csr = CertificationRequest.load(der_bytes)
|
||||
except ValueError:
|
||||
raise falcon.HTTPBadRequest(
|
||||
"Bad request",
|
||||
"Malformed certificate signing request")
|
||||
|
||||
common_name = csr["certification_request_info"]["subject"].native["common_name"]
|
||||
|
||||
"""
|
||||
@ -164,6 +170,9 @@ class RequestListResource(object):
|
||||
# Request was accepted, but not processed
|
||||
resp.status = falcon.HTTP_202
|
||||
resp.body = ". ".join(reasons)
|
||||
if req.client_accepts("application/json"):
|
||||
resp.body = json.dumps({"title":"Accepted", "description":resp.body},
|
||||
cls=MyEncoder)
|
||||
|
||||
|
||||
class RequestDetailResource(object):
|
||||
|
@ -67,6 +67,8 @@ def serialize(func):
|
||||
"""
|
||||
import falcon
|
||||
def wrapped(instance, req, resp, **kwargs):
|
||||
retval = func(instance, req, resp, **kwargs)
|
||||
if not resp.body and not resp.location:
|
||||
if not req.client_accepts("application/json"):
|
||||
logger.debug("Client did not accept application/json")
|
||||
raise falcon.HTTPUnsupportedMediaType(
|
||||
@ -74,6 +76,6 @@ def serialize(func):
|
||||
resp.set_header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
resp.set_header("Pragma", "no-cache")
|
||||
resp.set_header("Expires", "0")
|
||||
resp.body = json.dumps(func(instance, req, resp, **kwargs), cls=MyEncoder)
|
||||
resp.body = json.dumps(retval, cls=MyEncoder)
|
||||
return wrapped
|
||||
|
||||
|
@ -220,6 +220,27 @@ function onAttributeUpdated(e) {
|
||||
})
|
||||
}
|
||||
|
||||
function onSubmitRequest() {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "/api/request/",
|
||||
headers: {
|
||||
"Accept": "application/json; charset=utf-8",
|
||||
"Content-Type": "application/pkcs10"
|
||||
},
|
||||
data: $("#request_body").val(),
|
||||
|
||||
success:function(attributes, status, xhr) {
|
||||
// Close the modal
|
||||
$("[data-dismiss=modal]").trigger({ type: "click" });
|
||||
},
|
||||
error: function(xhr, status, e) {
|
||||
console.info("Submitting request failed with:", status, e);
|
||||
alert(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function onServerStarted() {
|
||||
console.info("Server started");
|
||||
location.reload();
|
||||
|
@ -5,8 +5,8 @@
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title">Request submission</h4>
|
||||
</div>
|
||||
<form action="/api/request/" method="post">
|
||||
<div class="modal-body">
|
||||
|
||||
<h5>Certidude client</h5>
|
||||
|
||||
<p>Submit a certificate signing request from Mac OS X, Ubuntu or Fedora:</p>
|
||||
@ -14,7 +14,7 @@
|
||||
<pre><code>easy_install pip;
|
||||
pip3 install certidude;
|
||||
certidude bootstrap {{session.authority.common_name}}
|
||||
</code></pre>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h5>UNIX & UNIX-like</h5>
|
||||
@ -53,15 +53,15 @@ curl -f -L -H "Content-type: application/pkcs10" \
|
||||
<p>Use whatever tools you have available on your platform to generate
|
||||
keypair and just paste ASCII armored PEM file contents here and hit submit:</p>
|
||||
|
||||
<textarea id="request_body" style="width:100%; min-height: 4em;"
|
||||
placeholder="-----BEGIN CERTIFICATE REQUEST-----\n...\n-----END CERTIFICATE REQUEST-----"></textarea>
|
||||
<textarea id="request_body" style="width:100%; min-height: 10em;" placeholder="-----BEGIN CERTIFICATE REQUEST-----"></textarea>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-success"><i class="fa fa-upload"></i> Submit</button>
|
||||
<button type="button" class="btn" data-dismiss="modal"><i class="fa fa-ban"></i> Close</button>
|
||||
<button type="button" onclick="onSubmitRequest();" class="btn btn-primary"><i class="fa fa-upload"></i> Submit</button>
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fa fa-ban"></i> Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user