Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/openai/lib/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import re
import hashlib
import hmac
import inspect
from typing import Any, Literal, Mapping, Callable, Optional, Awaitable, cast
from dataclasses import field, replace, dataclass
Expand All @@ -24,7 +24,7 @@
AsyncBedrockTokenProvider = Callable[[], "str | Awaitable[str]"]
_LegacyAuthMode = Literal["bearer", "token_provider", "aws"]
_LegacyAuthConfiguration = tuple[_LegacyAuthMode, Optional[object]]
_LEGACY_SIGNATURE_KEY = os.urandom(32)
_LEGACY_SIGNATURE_NONCE = os.urandom(32)


@dataclass(frozen=True)
Expand Down Expand Up @@ -299,8 +299,9 @@ def _legacy_runtime_signature(
configuration: _LegacyAuthConfiguration,
) -> _LegacyRuntimeSignature:
mode, credential = configuration
# This is an opaque, process-local change detector, not a password hash.
credential_identity: object = (
hashlib.blake2s(credential.encode(), key=_LEGACY_SIGNATURE_KEY).digest()
hmac.digest(credential.encode(), _LEGACY_SIGNATURE_NONCE, "sha256")
if isinstance(credential, str)
else id(credential)
)
Expand Down
Loading