Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Tutorial**:
- Added a tutorial to the documentation to help new users get started with writing a provider using `tf`.

### Fixed

- Fixed the gRPC server self-signed certificate being generated with `not_valid_before` in the future
- This was caused by generating a `datetime` in the local timezone, but `x509` treating it as UTC

## 1.1.0

### Added
Expand Down
8 changes: 4 additions & 4 deletions tf/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ def _get_cert_cache_path() -> Path:
def _self_signed_cert() -> Tuple[bytes, Any]:
"""Generate or load cached keypair and cert, return a server credentials object"""
# Lazy load expensive cryptography imports
from datetime import timezone

import grpc
from cryptography import x509
from cryptography.hazmat.primitives import hashes, serialization
Expand All @@ -213,10 +215,8 @@ def _self_signed_cert() -> Tuple[bytes, Any]:
# Check if certificate is still valid
cert_pem = cached["cert_pem"].encode()
cert = x509.load_pem_x509_certificate(cert_pem)
# Compare UTC times
from datetime import timezone as tz

if cert.not_valid_after_utc > datetime.now(tz.utc):
if cert.not_valid_after_utc > datetime.now(timezone.utc):
# Certificate is still valid, use cached version
private_key_pem = cached["key_pem"].encode()
cert_chain = base64.b64decode(cached["cert_chain"])
Expand All @@ -238,7 +238,7 @@ def _self_signed_cert() -> Tuple[bytes, Any]:
)

name = x509.Name([x509.NameAttribute(x509.NameOID.COMMON_NAME, "localhost")])
now = datetime.now()
now = datetime.now(timezone.utc)

# With subject alternative names
certificate = (
Expand Down