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
41 changes: 41 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CodeQL

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 6 * * 1'

permissions:
contents: read

jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
security-events: write
packages: read

strategy:
fail-fast: false
matrix:
language: [python]

steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false

- name: Initialize CodeQL
uses: github/codeql-action/init@c10b8064de6f491fea524254123dbe5e09572f13 # v4
with:
languages: ${{ matrix.language }}
queries: security-and-quality

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@c10b8064de6f491fea524254123dbe5e09572f13 # v4
with:
category: "/language:${{ matrix.language }}"
41 changes: 41 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: OpenSSF Scorecard

on:
branch_protection_rule:
workflow_dispatch:
schedule:
- cron: '0 5 * * 1'
push:
branches: [main]

permissions: read-all

jobs:
analysis:
runs-on: ubuntu-latest
permissions:
security-events: write
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false

- name: Run Scorecard
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
with:
results_file: results.sarif
results_format: sarif
publish_results: true

- name: Upload Scorecard results
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: scorecard-results
path: results.sarif
retention-days: 5

- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4
with:
sarif_file: results.sarif
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# pipelock-verify

[![PyPI version](https://img.shields.io/pypi/v/pipelock-verify.svg)](https://pypi.org/project/pipelock-verify/)
[![Python versions](https://img.shields.io/pypi/pyversions/pipelock-verify.svg)](https://pypi.org/project/pipelock-verify/)
[![PyPI](https://img.shields.io/pypi/v/pipelock-verify.svg?label=PyPI&logo=pypi&logoColor=white)](https://pypi.org/project/pipelock-verify/)
[![Python](https://img.shields.io/pypi/pyversions/pipelock-verify.svg?label=Python&logo=python&logoColor=white)](https://pypi.org/project/pipelock-verify/)
[![CI](https://github.com/luckyPipewrench/pipelock-verify-python/actions/workflows/ci.yml/badge.svg)](https://github.com/luckyPipewrench/pipelock-verify-python/actions/workflows/ci.yml)
[![CodeQL](https://github.com/luckyPipewrench/pipelock-verify-python/actions/workflows/codeql.yml/badge.svg)](https://github.com/luckyPipewrench/pipelock-verify-python/actions/workflows/codeql.yml)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/luckyPipewrench/pipelock-verify-python/badge)](https://scorecard.dev/viewer/?uri=github.com/luckyPipewrench/pipelock-verify-python)
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)

Python verifier for [Pipelock](https://github.com/luckyPipewrench/pipelock)
action receipts. Verifies the Ed25519 signature, chain linkage, and
flight-recorder wrapping of receipts emitted by the Pipelock mediator.
**Python verifier for [Pipelock](https://github.com/luckyPipewrench/pipelock) action receipts.** Verifies the Ed25519 signature, chain linkage, and flight-recorder wrapping of receipts emitted by the Pipelock mediator.

The library mirrors the Go reference implementation byte-for-byte. The
conformance golden files in `tests/conformance/` are generated by Pipelock's
Go code and verified identically by both sides.
Mirrors the Go reference implementation byte-for-byte. The conformance golden files in `tests/conformance/` are generated by Pipelock's Go code and verified identically by both sides.

[Install](#install) · [Usage](#usage) · [What gets verified](#what-gets-verified) · [Canonicalization](#canonicalization-rules) · [Spec](https://pipelab.org/learn/action-receipt-spec/) · [Go reference](https://github.com/luckyPipewrench/pipelock)

## Install

```bash
pip install pipelock-verify
```

Only one runtime dependency: [`cryptography`](https://cryptography.io) for
the Ed25519 primitives.
Only one runtime dependency: [`cryptography`](https://cryptography.io) for the Ed25519 primitives.

## Usage

Expand Down
25 changes: 21 additions & 4 deletions pipelock_verify/_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,34 @@
def _is_valid_rfc3339(value: Any) -> bool:
"""Return True if value parses as an RFC 3339 timestamp Go would accept.

Python's datetime.fromisoformat accepts the ``Z`` suffix natively only
on 3.11+, so we substitute it with ``+00:00`` before parsing to support
3.9 and 3.10 as well.
Go's ``time.RFC3339Nano`` allows up to 9 fractional digits (nanoseconds).
Python's ``datetime.fromisoformat`` tops out at microsecond precision
(6 fractional digits) and the ``Z`` suffix only parses natively on 3.11+.
We handle both differences here so valid Go timestamps verify on 3.9-3.13.
"""
if not isinstance(value, str):
return False
if not _RFC3339_RE.match(value):
return False
candidate = value[:-1] + "+00:00" if value.endswith("Z") else value
# Truncate fractional seconds to 6 digits so fromisoformat accepts
# Go's nanosecond timestamps on Python 3.9/3.10. The regex above has
# already validated the overall shape, so we know there is at most one
# ``.`` before the timezone offset.
match = re.match(
r"^(?P<prefix>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})"
r"(?:\.(?P<frac>\d{1,9}))?"
r"(?P<offset>[+-]\d{2}:\d{2})$",
candidate,
)
if match is None:
return False
prefix = match.group("prefix")
frac = match.group("frac") or ""
offset = match.group("offset")
truncated = f"{prefix}.{frac[:6]}{offset}" if frac else f"{prefix}{offset}"
try:
datetime.fromisoformat(candidate)
datetime.fromisoformat(truncated)
except ValueError:
return False
return True
Expand Down
Loading