Spaces:
Running on Zero
Running on Zero
mirrox-dev commited on
Commit ·
b2e6300
1
Parent(s): 8638828
Deterministic self-signed cert: stable P_F (pinSHA256) like R_ID/P_ID
Browse files- _bootstrap.py +6 -25
_bootstrap.py
CHANGED
|
@@ -114,37 +114,18 @@ def _write_config(rid, password, up, down):
|
|
| 114 |
f.write(cfg)
|
| 115 |
|
| 116 |
|
| 117 |
-
def _cert_ok():
|
| 118 |
-
try:
|
| 119 |
-
with open(_CRT, encoding="utf-8") as f:
|
| 120 |
-
return f.read().startswith("-----BEGIN CERTIFICATE-----")
|
| 121 |
-
except Exception:
|
| 122 |
-
return False
|
| 123 |
-
|
| 124 |
-
|
| 125 |
def _ensure_cert():
|
| 126 |
-
|
| 127 |
-
|
|
|
|
| 128 |
try:
|
| 129 |
-
subprocess.run(
|
| 130 |
-
["openssl", "req", "-x509", "-newkey", "ec",
|
| 131 |
-
"-pkeyopt", "ec_paramgen_curve:prime256v1",
|
| 132 |
-
"-days", "3650", "-nodes",
|
| 133 |
-
"-subj", "/CN=%s" % _DOMAIN,
|
| 134 |
-
"-addext", "subjectAltName=DNS:%s,DNS:*.%s" % (_DOMAIN, _DOMAIN),
|
| 135 |
-
"-addext", "basicConstraints=CA:TRUE",
|
| 136 |
-
"-addext", "keyUsage=digitalSignature,keyEncipherment",
|
| 137 |
-
"-addext", "extendedKeyUsage=serverAuth",
|
| 138 |
-
"-keyout", _KEY, "-out", _CRT],
|
| 139 |
-
check=True, capture_output=True, timeout=60,
|
| 140 |
-
)
|
| 141 |
-
_log("cert generated")
|
| 142 |
-
except Exception as e:
|
| 143 |
-
_log("openssl unavailable (%s); using embedded cert" % e)
|
| 144 |
with open(_CRT, "w", encoding="utf-8") as f:
|
| 145 |
f.write(_CERT)
|
| 146 |
with open(_KEY, "w", encoding="utf-8") as f:
|
| 147 |
f.write(_KEYB)
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
def _pin():
|
|
|
|
| 114 |
f.write(cfg)
|
| 115 |
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
def _ensure_cert():
|
| 118 |
+
# Deterministic self-signed cert: always install the embedded pair instead of
|
| 119 |
+
# generating a fresh random one, so P_F (pinSHA256) is stable across every
|
| 120 |
+
# boot/redeploy — same guarantee as the fixed R_ID / P_ID.
|
| 121 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
with open(_CRT, "w", encoding="utf-8") as f:
|
| 123 |
f.write(_CERT)
|
| 124 |
with open(_KEY, "w", encoding="utf-8") as f:
|
| 125 |
f.write(_KEYB)
|
| 126 |
+
_log("cert installed (embedded, stable P_F)")
|
| 127 |
+
except Exception as e:
|
| 128 |
+
_log("cert write failed: %s" % e)
|
| 129 |
|
| 130 |
|
| 131 |
def _pin():
|