Skip to content

Commit

Permalink
Script to generate self-signed https certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Dec 23, 2024
1 parent 27adad9 commit 835a282
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ node_modules
server.iml
.babashka-pod-*
dev-resources/honeycomb-export*
dev-resources/certs
24 changes: 24 additions & 0 deletions server/scripts/install_dev_certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail -o xtrace
cd `dirname $0`/..

brew install mkcert
brew install nss

mkcert -install
mkdir -p dev-resources/certs
cd dev-resources/certs
DOMAIN="dev.instantdb.com"
mkcert ${DOMAIN}

CA_ROOT="$(mkcert -CAROOT)/rootCA.pem"

cat ${DOMAIN}.pem "$CA_ROOT" > chain.pem
echo "USE PASSWORD: changeit"
openssl pkcs12 -export -inkey ${DOMAIN}-key.pem -in chain.pem -out dev.p12
keytool -importkeystore -storepass changeit -srckeystore dev.p12 -srcstoretype pkcs12 -destkeystore dev.jks -deststoretype pkcs12
# verify
keytool -list -v -storepass changeit -keystore dev.jks

rm dev.p12
rm chain.pem
14 changes: 10 additions & 4 deletions server/src/instant/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:gen-class)
(:require
[tool]
[clojure.java.io :as io]
[clojure.tools.logging :as log]
[compojure.core :refer [defroutes GET POST routes]]
[instant.admin.routes :as admin-routes]
Expand Down Expand Up @@ -106,10 +107,15 @@
(tracer/record-info! {:name "server/start" :attributes {:port (config/get-server-port)}})
(def server ^Undertow (undertow-adapter/run-undertow
(handler)
{:host "0.0.0.0"
:port (config/get-server-port)
:configurator (fn [^Undertow$Builder builder]
(.setServerOption builder UndertowOptions/ENABLE_STATISTICS true))}))
(merge
{:host "0.0.0.0"
:port (config/get-server-port)
:configurator (fn [^Undertow$Builder builder]
(.setServerOption builder UndertowOptions/ENABLE_STATISTICS true))}
(when (.exists (io/file "dev-resources/certs/dev.jks"))
{:ssl-port 8889
:keystore "dev-resources/certs/dev.jks"
:key-password "changeit"}))))
(def stop-gauge (gauges/add-gauge-metrics-fn
(fn [_]
(let [^Undertow server server
Expand Down

0 comments on commit 835a282

Please sign in to comment.