@fireemu/darwin-arm64 0.48.0 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @fireemu/darwin-arm64
|
|
2
2
|
|
|
3
3
|
The [fireemu](https://www.npmjs.com/package/fireemu) daemon built for `darwin-arm64`
|
|
4
|
-
(Rust target `aarch64-apple-darwin`), version 0.
|
|
4
|
+
(Rust target `aarch64-apple-darwin`), version 0.49.0.
|
|
5
5
|
|
|
6
6
|
macOS 13 or newer on Apple silicon.
|
|
7
7
|
|
package/bin/fireemu
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/fireemu
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 37955792 bytes
|
|
4
|
+
sha256: 810585382a0a8675ccebbac9ea5a919a0f11614fbbe6e9368d8acda23b4d82eb
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Auth blocking tokens: run the SDK's production verification with the daemon's public keys.
|
|
2
|
+
|
|
3
|
+
SECURITY-SENSITIVE. The SDK skips signature and audience checks in the Auth emulator. When the daemon supplies
|
|
4
|
+
its public keys, this module confines production verification and certificate responses to the SDK verifier;
|
|
5
|
+
without the environment variable the SDK's emulator behavior is unchanged.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import contextvars
|
|
9
|
+
import importlib.metadata
|
|
10
|
+
import json
|
|
11
|
+
|
|
12
|
+
ENVIRONMENT_VARIABLE = "FIREEMU_AUTH_BLOCKING_JWKS"
|
|
13
|
+
NOTE_VERSION = "0.6.0"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class VerificationUnavailable(Exception):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def parse_keys(text) -> dict[str, str] | None:
|
|
21
|
+
"""Build the certificate mapping consumed by the SDK from the daemon's public JWKS."""
|
|
22
|
+
import jwt
|
|
23
|
+
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
document = json.loads(text)
|
|
27
|
+
except (ValueError, TypeError):
|
|
28
|
+
return None
|
|
29
|
+
entries = document.get("keys") if isinstance(document, dict) else None
|
|
30
|
+
if not isinstance(entries, list) or not entries:
|
|
31
|
+
return None
|
|
32
|
+
keys = {}
|
|
33
|
+
for entry in entries:
|
|
34
|
+
if not isinstance(entry, dict) or entry.get("kty") != "RSA" or not isinstance(entry.get("kid"), str) or not entry["kid"] or not isinstance(entry.get("n"), str) or not isinstance(entry.get("e"), str):
|
|
35
|
+
continue
|
|
36
|
+
try:
|
|
37
|
+
keys[entry["kid"]] = jwt.PyJWK(entry).key.public_bytes(Encoding.PEM, PublicFormat.SubjectPublicKeyInfo).decode("ascii")
|
|
38
|
+
except Exception:
|
|
39
|
+
continue
|
|
40
|
+
return keys or None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def install_from_environment(environ) -> bool:
|
|
44
|
+
"""Install the SDK-only verification hook when the daemon provides usable public keys."""
|
|
45
|
+
if ENVIRONMENT_VARIABLE not in environ:
|
|
46
|
+
return False
|
|
47
|
+
value = environ.pop(ENVIRONMENT_VARIABLE)
|
|
48
|
+
try:
|
|
49
|
+
keys = parse_keys(value)
|
|
50
|
+
if not keys:
|
|
51
|
+
raise VerificationUnavailable("no usable public keys")
|
|
52
|
+
from firebase_admin import _auth_utils
|
|
53
|
+
from firebase_functions.private import token_verifier
|
|
54
|
+
from google.auth.exceptions import TransportError
|
|
55
|
+
|
|
56
|
+
stock = token_verifier._JWTVerifier
|
|
57
|
+
if not isinstance(stock, type) or not callable(token_verifier._auth_utils.is_emulated) or not token_verifier._token_gen.ID_TOKEN_CERT_URI:
|
|
58
|
+
raise VerificationUnavailable("unsupported SDK")
|
|
59
|
+
cert_url = token_verifier._token_gen.ID_TOKEN_CERT_URI
|
|
60
|
+
data = json.dumps(keys).encode()
|
|
61
|
+
active = contextvars.ContextVar("fireemu_auth_blocking_verification", default=False)
|
|
62
|
+
|
|
63
|
+
class AuthUtilsView:
|
|
64
|
+
def is_emulated(self):
|
|
65
|
+
return False if active.get() else _auth_utils.is_emulated()
|
|
66
|
+
|
|
67
|
+
def __getattr__(self, name):
|
|
68
|
+
return getattr(_auth_utils, name)
|
|
69
|
+
|
|
70
|
+
class Verifier(stock):
|
|
71
|
+
def verify(self, token, request):
|
|
72
|
+
def certificate_request(url, method="GET", body=None, headers=None, timeout=None, **kwargs):
|
|
73
|
+
if url != cert_url:
|
|
74
|
+
raise TransportError("unexpected certificate URL")
|
|
75
|
+
return type("CertificateResponse", (), {"status": 200, "headers": {}, "data": data})()
|
|
76
|
+
|
|
77
|
+
marker = active.set(True)
|
|
78
|
+
try:
|
|
79
|
+
if isinstance(token, (str, bytes)) and token:
|
|
80
|
+
_, payload = self._decode_unverified(token.encode() if isinstance(token, str) else token)
|
|
81
|
+
if not isinstance(payload.get("aud"), str):
|
|
82
|
+
raise self._invalid_token_error('Firebase Auth Blocking token has an invalid "aud" claim.')
|
|
83
|
+
return super().verify(token, certificate_request)
|
|
84
|
+
finally:
|
|
85
|
+
active.reset(marker)
|
|
86
|
+
|
|
87
|
+
auth_utils_view = AuthUtilsView()
|
|
88
|
+
token_verifier._JWTVerifier = Verifier
|
|
89
|
+
token_verifier._auth_utils = auth_utils_view
|
|
90
|
+
return True
|
|
91
|
+
except VerificationUnavailable:
|
|
92
|
+
raise
|
|
93
|
+
except Exception as error:
|
|
94
|
+
raise VerificationUnavailable("SDK hook installation failed") from error
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def default_note(functions_version) -> str | None:
|
|
98
|
+
if functions_version != NOTE_VERSION:
|
|
99
|
+
return None
|
|
100
|
+
return '[functions] note: firebase-functions (Python) 0.6.0 accepts only a "run.app" audience in an Auth blocking token, while firebase-tools 15.28.2 registers the function\'s cloudfunctions.net address, so in production every Auth blocking function written with it fails with 503 "Error code: 47"; fireemu skips that check by default and runs it, so this function passes here (functions.authBlockingToken: "production", set by productionExact, reproduces the production failure)'
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def announce_default_note(stderr):
|
|
104
|
+
try:
|
|
105
|
+
version = importlib.metadata.version("firebase-functions")
|
|
106
|
+
except Exception:
|
|
107
|
+
version = None
|
|
108
|
+
note = default_note(version)
|
|
109
|
+
if note is not None:
|
|
110
|
+
stderr.write(note + "\n")
|
|
@@ -6,7 +6,7 @@ import platform
|
|
|
6
6
|
import sys
|
|
7
7
|
import traceback
|
|
8
8
|
|
|
9
|
-
from . import appcheck
|
|
9
|
+
from . import appcheck, blocking
|
|
10
10
|
from .dispatch import Dispatcher
|
|
11
11
|
from .environment import EnvironmentGate, load_local_secrets
|
|
12
12
|
from .framing import FrameWriter, ProtocolError, read_frame
|
|
@@ -30,10 +30,12 @@ def load_codebase(source: str) -> dict:
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
def serve(
|
|
33
|
-
functions: dict, codebase: str, secret: str, stdin, writer: FrameWriter, gate: EnvironmentGate | None = None, app_check_verified: bool = False
|
|
33
|
+
functions: dict, codebase: str, secret: str, stdin, writer: FrameWriter, gate: EnvironmentGate | None = None, app_check_verified: bool = False, blocking_verified: bool = False
|
|
34
34
|
) -> int:
|
|
35
35
|
"""Says hello, then serves frames from `stdin` until `shutdown` or the end of the stream."""
|
|
36
36
|
manifest = build_manifest(functions, app_check_verified)
|
|
37
|
+
if not blocking_verified and any(spec["trigger"]["type"] == "blockingAuth" for spec in manifest["functions"]):
|
|
38
|
+
blocking.announce_default_note(sys.stderr)
|
|
37
39
|
server = None
|
|
38
40
|
port = None
|
|
39
41
|
if any(spec["trigger"]["type"] in HTTP_TRIGGERS for spec in manifest["functions"]):
|
|
@@ -84,9 +86,16 @@ def run(argv) -> int:
|
|
|
84
86
|
return 1
|
|
85
87
|
# Before any user code runs, so the Admin SDK's App Check service is built against the emulator's keys.
|
|
86
88
|
app_check_verified = appcheck.install_from_environment(os.environ)
|
|
89
|
+
try:
|
|
90
|
+
blocking_verified = blocking.install_from_environment(os.environ)
|
|
91
|
+
except blocking.VerificationUnavailable as error:
|
|
92
|
+
sys.stderr.write(f"[functions] error: Auth blocking token verification was requested but is unavailable ({error}); not serving\n")
|
|
93
|
+
return 1
|
|
87
94
|
try:
|
|
88
95
|
functions = load_codebase(args.source)
|
|
89
96
|
except BaseException: # a failing import in user code is reported with its traceback
|
|
90
97
|
traceback.print_exc()
|
|
91
98
|
return 1
|
|
99
|
+
if blocking_verified:
|
|
100
|
+
return serve(functions, args.codebase, secret, sys.stdin.buffer, writer, gate, app_check_verified, blocking_verified=True)
|
|
92
101
|
return serve(functions, args.codebase, secret, sys.stdin.buffer, writer, gate, app_check_verified)
|