Skip to content

Commit e17cb06

Browse files
committed
Remove redundant public key fingerprint
Store only the signing key public DER and enforce uniqueness on that source value instead of carrying a derived hash that can drift.
1 parent 719abc4 commit e17cb06

4 files changed

Lines changed: 7 additions & 17 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ The authorization registry has three main tables:
127127

128128
| Table | Key Columns | Purpose |
129129
|---|---|---|
130-
| `principal_signing_keys` | `key_id`, `algorithm`, `public_key_spki_der`, `pubkey_sha256`, `not_before`, `not_after`, `revoked_at` | Stores trusted P-256 public keys that may sign permissions. |
130+
| `principal_signing_keys` | `key_id`, `algorithm`, `public_key_spki_der`, `not_before`, `not_after`, `revoked_at` | Stores trusted P-256 public keys that may sign permissions. |
131131
| `principal_key_permissions` | `signing_key_id`, `subject_identity`, `destination`, `not_before`, `not_after`, `revoked_at` | Defines what each signing key is allowed to delegate. |
132132
| `permission_registry` | `permission_id`, `signing_key_id`, `subject_identity`, `destination`, `not_before`, `not_after`, `revoked_at`, `signature` | Stores signed permissions that authorize a subject identity to reach a normalized destination. |
133133

examples/register-principal-key.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,40 @@ tmpdir="$(mktemp -d)"
3434
trap 'rm -rf "$tmpdir"' EXIT
3535

3636
public_der="$tmpdir/public.der"
37-
pubkey_hash="$tmpdir/pubkey.sha256"
3837
openssl ec -in "$PRIVATE_KEY" -pubout -outform DER -out "$public_der" 2>/dev/null
39-
openssl dgst -sha256 -binary "$public_der" > "$pubkey_hash"
4038

4139
hex_file() {
4240
od -An -tx1 -v "$1" | tr -d ' \n'
4341
}
4442

4543
PUBLIC_KEY_HEX="$(hex_file "$public_der")"
46-
PUBKEY_SHA256_HEX="$(hex_file "$pubkey_hash")"
4744

4845
psql "$DATABASE_URL" \
4946
--set=ON_ERROR_STOP=1 \
5047
--set=key_id="$KEY_ID" \
5148
--set=public_key_spki_der="$PUBLIC_KEY_HEX" \
52-
--set=pubkey_sha256="$PUBKEY_SHA256_HEX" \
5349
--set=valid_days="$VALID_DAYS" <<'SQL'
5450
WITH input AS (
5551
SELECT
5652
:'key_id'::text AS key_id,
5753
decode(:'public_key_spki_der', 'hex') AS public_key_spki_der,
58-
decode(:'pubkey_sha256', 'hex') AS pubkey_sha256,
5954
:'valid_days'::int AS valid_days
6055
)
6156
INSERT INTO principal_signing_keys (
62-
key_id, algorithm, public_key_spki_der, pubkey_sha256,
57+
key_id, algorithm, public_key_spki_der,
6358
not_before, not_after, revoked_at
6459
)
6560
SELECT
66-
key_id, 'ecdsa_p256_sha256', public_key_spki_der, pubkey_sha256,
61+
key_id, 'ecdsa_p256_sha256', public_key_spki_der,
6762
now(), now() + make_interval(days => valid_days), NULL
6863
FROM input
6964
ON CONFLICT (key_id) DO UPDATE SET
7065
public_key_spki_der = EXCLUDED.public_key_spki_der,
71-
pubkey_sha256 = EXCLUDED.pubkey_sha256,
7266
not_before = now(),
7367
not_after = EXCLUDED.not_after,
7468
revoked_at = NULL,
7569
updated_at = now()
76-
RETURNING key_id, encode(pubkey_sha256, 'hex') AS pubkey_sha256, not_after;
70+
RETURNING key_id, not_after;
7771
SQL
7872

7973
echo "Private key: $PRIVATE_KEY"

migrations/0001_signed_authorization_registry.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ INSERT INTO agent_gateway_schema_version (version) VALUES (1);
88
CREATE TABLE principal_signing_keys (
99
key_id TEXT PRIMARY KEY,
1010
algorithm TEXT NOT NULL CHECK (algorithm = 'ecdsa_p256_sha256'),
11-
public_key_spki_der BYTEA NOT NULL,
12-
pubkey_sha256 BYTEA NOT NULL UNIQUE CHECK (length(pubkey_sha256) = 32),
11+
public_key_spki_der BYTEA NOT NULL UNIQUE,
1312
not_before TIMESTAMPTZ NOT NULL,
1413
not_after TIMESTAMPTZ NOT NULL,
1514
revoked_at TIMESTAMPTZ,

tests/common/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rcgen::{
1313
};
1414
use rustls::server::WebPkiClientVerifier;
1515
use rustls_pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};
16-
use sha2::{Digest, Sha256};
1716
use sqlx::postgres::PgPoolOptions;
1817
use tokio::io::{AsyncReadExt, AsyncWriteExt};
1918
use tokio::net::TcpListener;
@@ -368,22 +367,20 @@ impl TestAuthzRegistry {
368367
.expect("encode verifying key")
369368
.as_bytes()
370369
.to_vec();
371-
let pubkey_sha256 = Sha256::digest(&public_key_spki_der).to_vec();
372370
let key_id = unique_id("test-key");
373371
let (not_before, not_after) = active_window();
374372

375373
sqlx::query(
376374
r#"
377375
INSERT INTO principal_signing_keys (
378-
key_id, algorithm, public_key_spki_der, pubkey_sha256,
376+
key_id, algorithm, public_key_spki_der,
379377
not_before, not_after
380378
)
381-
VALUES ($1, 'ecdsa_p256_sha256', $2, $3, $4, $5)
379+
VALUES ($1, 'ecdsa_p256_sha256', $2, $3, $4)
382380
"#,
383381
)
384382
.bind(&key_id)
385383
.bind(&public_key_spki_der)
386-
.bind(&pubkey_sha256)
387384
.bind(not_before)
388385
.bind(not_after)
389386
.execute(&pool)

0 commit comments

Comments
 (0)