diff --git a/src/coulobre/hosting/certificate_uploads.py b/src/coulobre/hosting/certificate_uploads.py
new file mode 100644
index 0000000..1ad3b87
--- /dev/null
+++ b/src/coulobre/hosting/certificate_uploads.py
@@ -0,0 +1,97 @@
+import json
+from base64 import urlsafe_b64encode
+from hashlib import sha256
+
+from cryptography.fernet import Fernet, InvalidToken, MultiFernet
+from django import forms
+from django.conf import settings
+from django.views.decorators.debug import sensitive_variables
+
+from coulobre.web_certificates import (
+ MAX_CERTIFICATE_BYTES,
+ MAX_KEY_BYTES,
+ validated_pem,
+)
+
+UPLOAD_LIFETIME = 60 * 60
+
+
+class CertificateUploadForm(forms.Form):
+ chain = forms.FileField(
+ label="Certificate chain (PEM)",
+ help_text="Include the website certificate followed by intermediates.",
+ )
+ key = forms.FileField(
+ label="Private key (PEM)",
+ help_text="Use its matching unencrypted private key.",
+ )
+
+ @sensitive_variables()
+ def clean(self):
+ data = super().clean()
+ if self.errors:
+ return data
+ try:
+ chain, key = (
+ read_upload(data[name], limit)
+ for name, limit in (
+ ("chain", MAX_CERTIFICATE_BYTES),
+ ("key", MAX_KEY_BYTES),
+ )
+ )
+ data["chain_pem"], data["key_pem"] = validated_pem(chain, key)
+ except (UnicodeError, ValueError) as error:
+ raise forms.ValidationError(
+ "Provide a valid PEM certificate chain and matching key."
+ ) from error
+ return data
+
+
+def read_upload(upload, limit):
+ data = upload.read(limit + 1)
+ if len(data) > limit:
+ raise ValueError("The uploaded file exceeds the size limit.")
+ return data.decode("ascii")
+
+
+def upload_encryption():
+ return MultiFernet(
+ [
+ Fernet(
+ urlsafe_b64encode(
+ sha256(
+ b"coulobre-website-certificate\0"
+ + secret.encode("utf-8")
+ ).digest()
+ )
+ )
+ for secret in (settings.SECRET_KEY, *settings.SECRET_KEY_FALLBACKS)
+ ]
+ )
+
+
+@sensitive_variables()
+def seal_upload(site, customer_id, form):
+ response = json.dumps(
+ [
+ site.manifest(),
+ customer_id,
+ form.cleaned_data["chain_pem"],
+ form.cleaned_data["key_pem"],
+ ]
+ ).encode("utf-8")
+ return upload_encryption().encrypt(response).decode("ascii")
+
+
+@sensitive_variables()
+def open_upload(job):
+ try:
+ payload = upload_encryption().decrypt(
+ job.encrypted_upload.encode("ascii"), ttl=UPLOAD_LIFETIME
+ )
+ site, customer_id, chain, key = json.loads(payload)
+ if site == job.site and customer_id == job.requested_customer_id:
+ return chain, key
+ except (InvalidToken, UnicodeError, ValueError):
+ pass
+ raise ValueError("The certificate upload expired. Upload the files again.")
diff --git a/src/coulobre/hosting/certificate_views.py b/src/coulobre/hosting/certificate_views.py
new file mode 100644
index 0000000..ed724c2
--- /dev/null
+++ b/src/coulobre/hosting/certificate_views.py
@@ -0,0 +1,202 @@
+from datetime import timedelta
+
+from django.conf import settings
+from django.core.exceptions import PermissionDenied, ValidationError
+from django.core.paginator import Paginator
+from django.db import transaction
+from django.http import Http404
+from django.shortcuts import get_object_or_404, redirect, render
+from django.urls import reverse
+from django.utils import timezone
+from django.views.decorators.cache import never_cache
+from django.views.decorators.debug import sensitive_variables
+from django.views.decorators.http import require_http_methods, require_safe
+
+from coulobre.domain_names import canonical_domain
+from coulobre.web_certificates import ACTIONS
+from coulobre.web_node import WebSite
+
+from .access import customer_for_user
+from .certificate_uploads import CertificateUploadForm, seal_upload
+from .independent_websites import active_websites
+from .installation_features import panel_feature_allowed
+from .models import HostingAccount, WebsiteCertificateJob
+from .resource_requests import lock_hosting_account, require_active_services
+from .sftp import site_is_active
+
+
+def account_certificate_sites(account):
+ sites = [
+ website.spec
+ for website in active_websites(account).filter(suspended=False)
+ ]
+ if site_is_active(account):
+ sites.insert(0, WebSite(account.pk, account.primary_domain))
+ return {site.domain: site for site in sites}
+
+
+@transaction.atomic
+def queue_certificate(
+ account, site, actor, action, customer_id, *, encrypted_upload=""
+):
+ account = lock_hosting_account(account.pk, customer_id)
+ require_active_services(account)
+ if account_certificate_sites(account).get(site.domain) != site:
+ raise ValidationError("This website is no longer active.")
+ recent = account.certificate_jobs.filter(site=site.manifest())
+ if recent.filter(finished_at__isnull=True).exists():
+ raise ValidationError("Wait for the current certificate operation.")
+ if (
+ action == "reissue"
+ and recent.filter(
+ action=action,
+ requested_at__gte=timezone.now() - timedelta(hours=12),
+ ).exists()
+ ):
+ raise ValidationError(
+ "Wait 12 hours before requesting another reissue."
+ )
+ WebsiteCertificateJob.objects.create(
+ account=account,
+ site=site.manifest(),
+ actor=actor,
+ requested_customer_id=customer_id,
+ action=action,
+ encrypted_upload=encrypted_upload,
+ )
+
+
+@never_cache
+@sensitive_variables("encrypted_upload", "upload_form")
+@require_http_methods(("GET", "HEAD", "POST"))
+def customer_certificates(request, pk):
+ customer = customer_for_user(request.user)
+ if customer is None:
+ raise PermissionDenied
+ account = get_object_or_404(
+ HostingAccount, pk=pk, customer=customer, retired_at__isnull=True
+ )
+ sites = account_certificate_sites(account)
+ try:
+ domain = canonical_domain(
+ request.GET.get(
+ "domain", next(iter(sites), account.primary_domain)
+ )
+ )
+ except ValueError as error:
+ raise Http404 from error
+ site = sites.get(domain)
+ if "domain" in request.GET and site is None:
+ raise Http404
+ tab = request.GET.get("tab", "manage")
+ if tab not in {"manage", "acme", "history"}:
+ raise Http404
+ enabled = panel_feature_allowed("LOCAL_WEB_HTTPS")
+ problem = ""
+ is_upload = (
+ request.method == "POST" and request.POST.get("action") == "upload"
+ )
+ upload_form = CertificateUploadForm(
+ request.POST if is_upload else None,
+ request.FILES if is_upload else None,
+ )
+ if request.method == "POST" and (not is_upload or upload_form.is_valid()):
+ if not site or not enabled:
+ raise Http404
+ action = request.POST.get("action")
+ if action not in ACTIONS:
+ raise Http404
+ try:
+ encrypted_upload = (
+ seal_upload(site, customer.pk, upload_form)
+ if is_upload
+ else ""
+ )
+ queue_certificate(
+ account,
+ site,
+ request.user,
+ action,
+ customer.pk,
+ encrypted_upload=encrypted_upload,
+ )
+ except HostingAccount.DoesNotExist:
+ raise Http404 from None
+ except ValidationError as error:
+ problem = " ".join(error.messages)
+ else:
+ return redirect(
+ reverse(
+ "panel:customer_certificates",
+ args=[account.pk],
+ query={"domain": domain, "tab": "history"},
+ )
+ )
+ history = []
+ certificate = None
+ if site:
+ jobs = account.certificate_jobs.filter(
+ site=site.manifest(),
+ requested_customer_id=customer.pk,
+ )
+ history = list(jobs.order_by("-pk")[:25])
+ certificate = jobs.exclude(certificate={}).order_by("-pk").first()
+ return render(
+ request,
+ "hosting/customer_certificates.html",
+ {
+ "account": account,
+ "sites": sites,
+ "domain": domain,
+ "tab": tab,
+ "certificate": certificate,
+ "upload_form": upload_form,
+ "history": history,
+ "enabled": enabled,
+ "problem": problem,
+ "site": site,
+ },
+ )
+
+
+@never_cache
+@require_safe
+def operator_certificates(request):
+ if not (request.user.is_superuser and request.user.is_verified()):
+ raise PermissionDenied
+ mode = request.GET.get("tab", "websites")
+ if mode not in {"websites", "server"}:
+ raise Http404
+ accounts = HostingAccount.objects.filter(retired_at__isnull=True).order_by(
+ "primary_domain"
+ )
+ page_obj = Paginator(accounts, 30).get_page(request.GET.get("page"))
+ sites = (
+ [
+ (
+ site.domain,
+ account,
+ account.certificate_jobs.filter(site=site.manifest())
+ .exclude(certificate={})
+ .order_by("-pk")
+ .first(),
+ )
+ for account in page_obj
+ for site in account_certificate_sites(account).values()
+ ]
+ if mode == "websites"
+ else []
+ )
+ return render(
+ request,
+ "hosting/operator_certificates.html",
+ {
+ "mode": mode,
+ "sites": sites,
+ "page_obj": page_obj,
+ "is_paginated": page_obj.has_other_pages,
+ "panel_origin": settings.PASSWORD_RESET_ORIGIN,
+ "imap_host": settings.MAIL_IMAP_HOST,
+ "submission_host": settings.MAIL_SUBMISSION_HOST,
+ },
+ )
diff --git a/src/coulobre/hosting/migrations/0068_website_certificate_jobs.py b/src/coulobre/hosting/migrations/0068_website_certificate_jobs.py
new file mode 100644
index 0000000..511c7b5
--- /dev/null
+++ b/src/coulobre/hosting/migrations/0068_website_certificate_jobs.py
@@ -0,0 +1,67 @@
+# Generated by Django 5.2.19 on 2026-11-23 21:38
+
+import django.db.models.deletion
+import django.utils.timezone
+from django.conf import settings
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("hosting", "0067_mail_delivery_search"),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="WebsiteCertificateJob",
+ fields=[
+ (
+ "id",
+ models.BigAutoField(
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name="ID",
+ ),
+ ),
+ (
+ "requested_at",
+ models.DateTimeField(default=django.utils.timezone.now),
+ ),
+ (
+ "last_dispatched_at",
+ models.DateTimeField(blank=True, null=True),
+ ),
+ ("started_at", models.DateTimeField(blank=True, null=True)),
+ ("finished_at", models.DateTimeField(blank=True, null=True)),
+ ("problem", models.TextField(blank=True)),
+ ("site", models.JSONField()),
+ ("action", models.CharField(max_length=12)),
+ (
+ "requested_customer_id",
+ models.PositiveBigIntegerField(null=True),
+ ),
+ ("certificate", models.JSONField(default=dict)),
+ (
+ "account",
+ models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="certificate_jobs",
+ to="hosting.hostingaccount",
+ ),
+ ),
+ (
+ "actor",
+ models.ForeignKey(
+ null=True,
+ on_delete=django.db.models.deletion.SET_NULL,
+ to=settings.AUTH_USER_MODEL,
+ ),
+ ),
+ ],
+ options={
+ "abstract": False,
+ },
+ ),
+ ]
diff --git a/src/coulobre/hosting/migrations/0069_certificate_uploads.py b/src/coulobre/hosting/migrations/0069_certificate_uploads.py
new file mode 100644
index 0000000..9996833
--- /dev/null
+++ b/src/coulobre/hosting/migrations/0069_certificate_uploads.py
@@ -0,0 +1,17 @@
+# Generated by Django 5.2.19 on 2026-11-23 21:40
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("hosting", "0068_website_certificate_jobs"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="websitecertificatejob",
+ name="encrypted_upload",
+ field=models.TextField(blank=True, default=""),
+ ),
+ ]
diff --git a/src/coulobre/hosting/models.py b/src/coulobre/hosting/models.py
index f759da4..f100706 100644
--- a/src/coulobre/hosting/models.py
+++ b/src/coulobre/hosting/models.py
@@ -1019,6 +1019,24 @@ class WebHTTPS(ProvisioningJob):
verbose_name = "website HTTPS request"
+class WebsiteCertificateJob(ProvisioningJob):
+ account = models.ForeignKey(
+ HostingAccount,
+ on_delete=models.CASCADE,
+ related_name="certificate_jobs",
+ )
+ site = models.JSONField()
+ action = models.CharField(max_length=12)
+ actor = models.ForeignKey(
+ settings.AUTH_USER_MODEL,
+ on_delete=models.SET_NULL,
+ null=True,
+ )
+ requested_customer_id = models.PositiveBigIntegerField(null=True)
+ encrypted_upload = models.TextField(blank=True, default="")
+ certificate = models.JSONField(default=dict)
+
+
class WebsiteAlias(ProvisioningJob):
wait_for_website = models.BooleanField(default=False)
diff --git a/src/coulobre/hosting/tasks.py b/src/coulobre/hosting/tasks.py
index aba4cfe..0715366 100644
--- a/src/coulobre/hosting/tasks.py
+++ b/src/coulobre/hosting/tasks.py
@@ -64,6 +64,7 @@ from .models import (
WebHTTPS,
WebProvisioningPlan,
WebsiteAlias,
+ WebsiteCertificateJob,
WebsiteRestoreJob,
WebsiteScheduledJob,
)
@@ -221,7 +222,15 @@ def dispatch_site_storage_limits():
@shared_task
def dispatch_web_https():
+ from .certificate_uploads import UPLOAD_LIFETIME
+
+ WebsiteCertificateJob.objects.filter(
+ requested_at__lte=timezone.now() - timedelta(seconds=UPLOAD_LIFETIME)
+ ).exclude(encrypted_upload="").update(encrypted_upload="")
if settings.LOCAL_WEB_HTTPS:
+ dispatch_provisioning_jobs(
+ WebsiteCertificateJob, apply_certificate_job, WEB_HTTPS_QUEUE
+ )
dispatch_provisioning_jobs(
IndependentWebsite,
provision_independent_website,
@@ -1392,3 +1401,64 @@ def search_mail_delivery(job_id):
apply,
"The mail node did not return a delivery report.",
)
+
+
+@shared_task(acks_late=True, reject_on_worker_lost=True)
+def apply_certificate_job(job_id):
+ from django.views.decorators.debug import sensitive_variables
+
+ from coulobre.web_certificates import WebCertificateRequest
+
+ from .certificate_uploads import open_upload
+ from .certificate_views import account_certificate_sites
+ from .node_client import apply_on_local_node
+
+ @sensitive_variables()
+ def apply(job):
+ site = WebSite.from_manifest(job.site)
+ with transaction.atomic():
+ try:
+ account = lock_hosting_account(
+ job.account_id, job.requested_customer_id
+ )
+ except HostingAccount.DoesNotExist:
+ raise ValueError(
+ "This hosting account is no longer available."
+ ) from None
+ if (
+ account.services_suspended
+ or account.retired_at is not None
+ or account_certificate_sites(account).get(site.domain) != site
+ ):
+ raise ValueError("This website is no longer active.")
+ spec = WebCertificateRequest(
+ site,
+ job.action,
+ *(open_upload(job) if job.action == "upload" else ()),
+ )
+ reply = apply_on_local_node(
+ spec,
+ "/run/coulobre-https-apply.sock",
+ "web node",
+ "certificate operation",
+ identity=spec.identity(),
+ )
+ certificate = reply.get("certificate")
+ if (
+ not isinstance(certificate, dict)
+ or type(certificate.get("installed")) is not bool
+ ):
+ raise ValueError("The web node did not return certificate status.")
+ return {"certificate": certificate}
+
+ if settings.LOCAL_WEB_HTTPS:
+ run_provisioning_job(
+ WebsiteCertificateJob.objects.all(),
+ job_id,
+ apply,
+ "The HTTPS worker did not confirm the certificate operation.",
+ )
+
+ WebsiteCertificateJob.objects.filter(
+ pk=job_id, finished_at__isnull=False
+ ).exclude(encrypted_upload="").update(encrypted_upload="")
diff --git a/src/coulobre/hosting/templates/hosting/customer_certificates.html b/src/coulobre/hosting/templates/hosting/customer_certificates.html
new file mode 100644
index 0000000..d6ccd1b
--- /dev/null
+++ b/src/coulobre/hosting/templates/hosting/customer_certificates.html
@@ -0,0 +1,63 @@
+{% extends "hosting/base.html" %}
+{% block title %}SSL Certificates · Coulobre Panel{% endblock %}
+{% block content %}
+ SSL Certificates
{{ problem }}
{% endif %} + {% if tab == 'manage' %} +No HTTPS certificate was installed when last checked.
+ {% else %}Check the website to see its current certificate.
{% endif %} + {% if enabled %} + + {% endif %} +The website's DNS must resolve to this node and HTTP port 80 must be reachable for validation.
+Wildcard certificates require DNS-01 support on the server.
+{{ job.problem }}
{% endif %}Activate a website to manage its certificate.
{% endif %} +{% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/operator_certificates.html b/src/coulobre/hosting/templates/hosting/operator_certificates.html new file mode 100644 index 0000000..10b223c --- /dev/null +++ b/src/coulobre/hosting/templates/hosting/operator_certificates.html @@ -0,0 +1,27 @@ +{% extends "hosting/base.html" %} +{% block title %}SSL Overview · Coulobre Panel{% endblock %} +{% block content %} +| Website | Account | Last known issuer | Expiry |
|---|---|---|---|
| {{ domain }} | {{ account.name }} | +{{ job.certificate.issuer|default:"Unavailable" }} | {{ job.certificate.not_after|default:"Unavailable" }} | +
| No active websites on this page. | |||