Files
metacrypt/web/templates/pki.html

178 lines
6.3 KiB
HTML

{{define "title"}} - PKI: {{.MountName}}{{end}}
{{define "content"}}
<h2>PKI Engine: {{.MountName}}</h2>
<p><a href="/dashboard">&larr; Dashboard</a></p>
{{if .Error}}
<div class="error">{{.Error}}</div>
{{end}}
<h3>Root CA</h3>
{{if .HasRoot}}
<table>
<tr><th>Common Name</th><td>{{.RootCN}}</td></tr>
<tr><th>Organization</th><td>{{.RootOrg}}</td></tr>
<tr><th>Valid From</th><td>{{.RootNotBefore}}</td></tr>
<tr>
<th>Valid Until</th>
<td>
{{.RootNotAfter}}
{{if .RootExpired}} <span class="badge badge-danger">Expired</span>{{end}}
</td>
</tr>
</table>
<p style="margin-top: 0.5rem;">
<a href="/v1/pki/{{.MountName}}/ca" download="root-ca.pem">Download Root CA (PEM)</a>
</p>
{{else}}
<p>No root CA configured.</p>
{{end}}
{{if .IsAdmin}}
{{if or (not .HasRoot) .RootExpired}}
<h3>Import Root CA</h3>
<p>{{if .RootExpired}}The current root CA has expired. Import a new one.{{else}}No root CA is present. Import one to get started.{{end}}</p>
<form method="post" action="/pki/import-root" enctype="multipart/form-data">
<div class="form-group">
<label for="cert_file">Certificate PEM</label>
<input type="file" id="cert_file" name="cert_file" accept=".pem,.crt">
</div>
<div class="form-group">
<label for="cert_pem">Or paste certificate PEM</label>
<textarea id="cert_pem" name="cert_pem" rows="6" class="pem-input" placeholder="-----BEGIN CERTIFICATE-----"></textarea>
</div>
<div class="form-group">
<label for="key_file">Private Key PEM</label>
<input type="file" id="key_file" name="key_file" accept=".pem,.key">
</div>
<div class="form-group">
<label for="key_pem">Or paste private key PEM</label>
<textarea id="key_pem" name="key_pem" rows="6" class="pem-input" placeholder="-----BEGIN PRIVATE KEY-----"></textarea>
</div>
<button type="submit">Import Root CA</button>
</form>
{{end}}
{{end}}
<h3>Issuers</h3>
{{if .Issuers}}
<table>
<thead><tr><th>Name</th><th>Actions</th></tr></thead>
<tbody>
{{range .Issuers}}
<tr>
<td><a href="/pki/issuer/{{.}}">{{.}}</a></td>
<td><a href="/pki/{{.}}" download="{{.}}.pem">Download Cert (PEM)</a></td>
</tr>
{{end}}
</tbody>
</table>
{{else}}
<p>No issuers configured.</p>
{{end}}
{{if and .HasRoot .Issuers}}
<h3>Issue Certificate</h3>
{{if .IssuedCert}}
<div class="success">
<p>Certificate issued successfully.</p>
<div class="form-group">
<label>Certificate PEM</label>
<textarea rows="8" class="pem-input" readonly>{{index .IssuedCert "cert_pem"}}</textarea>
</div>
<div class="form-group">
<label>Private Key PEM</label>
<textarea rows="8" class="pem-input" readonly>{{index .IssuedCert "key_pem"}}</textarea>
</div>
<div class="form-group">
<label>Chain PEM</label>
<textarea rows="8" class="pem-input" readonly>{{index .IssuedCert "chain_pem"}}</textarea>
</div>
<p><small>Serial: {{index .IssuedCert "serial"}} &mdash; Expires: {{index .IssuedCert "expires_at"}}</small></p>
</div>
{{else}}
<form method="post" action="/pki/issue">
<div class="form-row">
<div class="form-group">
<label for="issue_cn">Common Name</label>
<input type="text" id="issue_cn" name="common_name" placeholder="example.com" required>
</div>
<div class="form-group">
<label for="issue_issuer">Issuer</label>
<select id="issue_issuer" name="issuer" required>
<option value="">-- select issuer --</option>
{{range .Issuers}}<option value="{{.}}">{{.}}</option>{{end}}
</select>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="issue_profile">Profile</label>
<select id="issue_profile" name="profile">
<option value="server">server (default)</option>
<option value="client">client</option>
<option value="peer">peer</option>
</select>
</div>
<div class="form-group">
<label for="issue_ttl">TTL (optional)</label>
<input type="text" id="issue_ttl" name="ttl" placeholder="2160h">
</div>
</div>
<details>
<summary>SANs</summary>
<div class="form-row">
<div class="form-group">
<label for="issue_dns">DNS Names (one per line)</label>
<textarea id="issue_dns" name="dns_names" rows="3" placeholder="example.com&#10;www.example.com"></textarea>
</div>
<div class="form-group">
<label for="issue_ips">IP Addresses (one per line)</label>
<textarea id="issue_ips" name="ip_addresses" rows="3" placeholder="10.0.0.1"></textarea>
</div>
</div>
</details>
<button type="submit">Issue Certificate</button>
</form>
{{end}}
{{end}}
{{if .IsAdmin}}
{{if .HasRoot}}
<h3>Create Issuer</h3>
{{if .IssuerError}}<div class="error">{{.IssuerError}}</div>{{end}}
<form method="post" action="/pki/create-issuer">
<div class="form-row">
<div class="form-group">
<label for="issuer_name">Issuer Name</label>
<input type="text" id="issuer_name" name="name" placeholder="default" required>
</div>
<div class="form-group">
<label for="issuer_expiry">Expiry</label>
<input type="text" id="issuer_expiry" name="expiry" placeholder="26280h (3 years)">
</div>
</div>
<details>
<summary>Advanced options</summary>
<div class="form-row">
<div class="form-group">
<label for="issuer_key_alg">Key Algorithm</label>
<input type="text" id="issuer_key_alg" name="key_algorithm" placeholder="ecdsa (default)">
</div>
<div class="form-group">
<label for="issuer_key_size">Key Size</label>
<input type="text" id="issuer_key_size" name="key_size" placeholder="521 (default)">
</div>
</div>
<div class="form-group">
<label for="issuer_max_ttl">Max Leaf TTL</label>
<input type="text" id="issuer_max_ttl" name="max_ttl" placeholder="2160h (90 days)">
</div>
</details>
<button type="submit">Create Issuer</button>
</form>
{{end}}
{{end}}
{{end}}