Skip to content

Commit b4daef7

Browse files
committed
samples: add a case with a p256 signature on a third-party block
1 parent 37da76e commit b4daef7

File tree

4 files changed

+264
-0
lines changed

4 files changed

+264
-0
lines changed

biscuit-auth/examples/testcases.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ fn run(target: String, root_key: Option<String>, test: bool, json: bool) {
167167

168168
add_test_result(&mut results, secp256r1(&target, &root, test));
169169

170+
add_test_result(&mut results, secp256r1_third_party(&target, &root, test));
171+
170172
if json {
171173
let s = serde_json::to_string_pretty(&TestCases {
172174
root_private_key: hex::encode(root.private().to_bytes()),
@@ -2418,6 +2420,67 @@ fn secp256r1(target: &str, root: &KeyPair, test: bool) -> TestResult {
24182420
}
24192421
}
24202422

2423+
fn secp256r1_third_party(target: &str, root: &KeyPair, test: bool) -> TestResult {
2424+
let mut rng: StdRng = SeedableRng::seed_from_u64(1234);
2425+
let title = "ECDSA secp256r1 signature on third-party block".to_string();
2426+
let filename = "test037_secp256r1_third_party".to_string();
2427+
let token;
2428+
2429+
let external_keypair = KeyPair::new_with_rng(Algorithm::Secp256r1, &mut rng);
2430+
let keypair2 = KeyPair::new_with_rng(Algorithm::Secp256r1, &mut rng);
2431+
let biscuit1 = biscuit!(
2432+
r#"
2433+
right("file1", "read");
2434+
right("file2", "read");
2435+
right("file1", "write");
2436+
check if from_third(true) trusting {external_pub};
2437+
"#,
2438+
external_pub = external_keypair.public(),
2439+
)
2440+
.build_with_key_pair(&root, SymbolTable::default(), &keypair2)
2441+
.unwrap();
2442+
2443+
let req = biscuit1.third_party_request().unwrap();
2444+
let block = req
2445+
.create_block(
2446+
&external_keypair.private(),
2447+
block!(
2448+
r#" check if resource($0), operation("read"), right($0, "read"); from_third(true);"#
2449+
),
2450+
)
2451+
.unwrap();
2452+
let keypair3 = KeyPair::new_with_rng(Algorithm::Secp256r1, &mut rng);
2453+
2454+
let biscuit2 = biscuit1
2455+
.append_third_party_with_keypair(external_keypair.public(), block, keypair3)
2456+
.unwrap();
2457+
2458+
token = print_blocks(&biscuit2);
2459+
2460+
let data = write_or_load_testcase(target, &filename, root, &biscuit2, test);
2461+
2462+
let mut validations = BTreeMap::new();
2463+
validations.insert(
2464+
"".to_string(),
2465+
validate_token(
2466+
root,
2467+
&data[..],
2468+
r#"
2469+
resource("file1");
2470+
operation("read");
2471+
allow if true;
2472+
"#,
2473+
),
2474+
);
2475+
2476+
TestResult {
2477+
title,
2478+
filename,
2479+
token,
2480+
validations,
2481+
}
2482+
}
2483+
24212484
fn print_blocks(token: &Biscuit) -> Vec<BlockContent> {
24222485
let mut v = Vec::new();
24232486

biscuit-auth/samples/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,3 +3398,114 @@ World {
33983398

33993399
result: `Ok(0)`
34003400

3401+
3402+
------------------------------
3403+
3404+
## ECDSA secp256r1 signature on third-party block: test037_secp256r1_third_party.bc
3405+
### token
3406+
3407+
authority:
3408+
symbols: ["file1", "file2", "from_third"]
3409+
3410+
public keys: ["secp256r1/025e918fd4463832aea2823dfd9716a36b4d9b1377bd53dd82ddf4c0bc75ed6bbf"]
3411+
3412+
block version: 4
3413+
3414+
```
3415+
right("file1", "read");
3416+
right("file2", "read");
3417+
right("file1", "write");
3418+
check if from_third(true) trusting secp256r1/025e918fd4463832aea2823dfd9716a36b4d9b1377bd53dd82ddf4c0bc75ed6bbf;
3419+
```
3420+
3421+
1:
3422+
symbols: ["from_third", "0"]
3423+
3424+
public keys: []
3425+
3426+
external signature by: "secp256r1/025e918fd4463832aea2823dfd9716a36b4d9b1377bd53dd82ddf4c0bc75ed6bbf"
3427+
3428+
block version: 5
3429+
3430+
```
3431+
from_third(true);
3432+
check if resource($0), operation("read"), right($0, "read");
3433+
```
3434+
3435+
### validation
3436+
3437+
authorizer code:
3438+
```
3439+
resource("file1");
3440+
operation("read");
3441+
3442+
allow if true;
3443+
```
3444+
3445+
revocation ids:
3446+
- `70f5402208516fd44cfc9df3dfcfc0a327ee9004f1801ed0a7abdcbbae923d566ddcd2d4a14f4622b35732c4e538af04075cc67ab0888fa2d8923cc668187f0f`
3447+
- `30450220793f95665d9af646339503a073670ea2c352459d2a2c2e14c57565f6c7eaf6bc022100cccadfc37e46755f52bb054ed206d7335067885df599a69431db40e33f33d4cf`
3448+
3449+
authorizer world:
3450+
```
3451+
World {
3452+
facts: [
3453+
Facts {
3454+
origin: {
3455+
None,
3456+
},
3457+
facts: [
3458+
"operation(\"read\")",
3459+
"resource(\"file1\")",
3460+
],
3461+
},
3462+
Facts {
3463+
origin: {
3464+
Some(
3465+
0,
3466+
),
3467+
},
3468+
facts: [
3469+
"right(\"file1\", \"read\")",
3470+
"right(\"file1\", \"write\")",
3471+
"right(\"file2\", \"read\")",
3472+
],
3473+
},
3474+
Facts {
3475+
origin: {
3476+
Some(
3477+
1,
3478+
),
3479+
},
3480+
facts: [
3481+
"from_third(true)",
3482+
],
3483+
},
3484+
]
3485+
rules: []
3486+
checks: [
3487+
Checks {
3488+
origin: Some(
3489+
0,
3490+
),
3491+
checks: [
3492+
"check if from_third(true) trusting secp256r1/025e918fd4463832aea2823dfd9716a36b4d9b1377bd53dd82ddf4c0bc75ed6bbf",
3493+
],
3494+
},
3495+
Checks {
3496+
origin: Some(
3497+
1,
3498+
),
3499+
checks: [
3500+
"check if resource($0), operation(\"read\"), right($0, \"read\")",
3501+
],
3502+
},
3503+
]
3504+
policies: [
3505+
"allow if true",
3506+
]
3507+
}
3508+
```
3509+
3510+
result: `Ok(0)`
3511+

biscuit-auth/samples/samples.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,6 +3088,96 @@
30883088
]
30893089
}
30903090
}
3091+
},
3092+
{
3093+
"title": "ECDSA secp256r1 signature on third-party block",
3094+
"filename": "test037_secp256r1_third_party.bc",
3095+
"token": [
3096+
{
3097+
"symbols": [
3098+
"file1",
3099+
"file2",
3100+
"from_third"
3101+
],
3102+
"public_keys": [
3103+
"secp256r1/025e918fd4463832aea2823dfd9716a36b4d9b1377bd53dd82ddf4c0bc75ed6bbf"
3104+
],
3105+
"external_key": null,
3106+
"code": "right(\"file1\", \"read\");\nright(\"file2\", \"read\");\nright(\"file1\", \"write\");\ncheck if from_third(true) trusting secp256r1/025e918fd4463832aea2823dfd9716a36b4d9b1377bd53dd82ddf4c0bc75ed6bbf;\n",
3107+
"version": 4
3108+
},
3109+
{
3110+
"symbols": [
3111+
"from_third",
3112+
"0"
3113+
],
3114+
"public_keys": [],
3115+
"external_key": "secp256r1/025e918fd4463832aea2823dfd9716a36b4d9b1377bd53dd82ddf4c0bc75ed6bbf",
3116+
"code": "from_third(true);\ncheck if resource($0), operation(\"read\"), right($0, \"read\");\n",
3117+
"version": 5
3118+
}
3119+
],
3120+
"validations": {
3121+
"": {
3122+
"world": {
3123+
"facts": [
3124+
{
3125+
"origin": [
3126+
null
3127+
],
3128+
"facts": [
3129+
"operation(\"read\")",
3130+
"resource(\"file1\")"
3131+
]
3132+
},
3133+
{
3134+
"origin": [
3135+
0
3136+
],
3137+
"facts": [
3138+
"right(\"file1\", \"read\")",
3139+
"right(\"file1\", \"write\")",
3140+
"right(\"file2\", \"read\")"
3141+
]
3142+
},
3143+
{
3144+
"origin": [
3145+
1
3146+
],
3147+
"facts": [
3148+
"from_third(true)"
3149+
]
3150+
}
3151+
],
3152+
"rules": [],
3153+
"checks": [
3154+
{
3155+
"origin": 0,
3156+
"checks": [
3157+
"check if from_third(true) trusting secp256r1/025e918fd4463832aea2823dfd9716a36b4d9b1377bd53dd82ddf4c0bc75ed6bbf"
3158+
]
3159+
},
3160+
{
3161+
"origin": 1,
3162+
"checks": [
3163+
"check if resource($0), operation(\"read\"), right($0, \"read\")"
3164+
]
3165+
}
3166+
],
3167+
"policies": [
3168+
"allow if true"
3169+
]
3170+
},
3171+
"result": {
3172+
"Ok": 0
3173+
},
3174+
"authorizer_code": "resource(\"file1\");\noperation(\"read\");\n\nallow if true;\n",
3175+
"revocation_ids": [
3176+
"70f5402208516fd44cfc9df3dfcfc0a327ee9004f1801ed0a7abdcbbae923d566ddcd2d4a14f4622b35732c4e538af04075cc67ab0888fa2d8923cc668187f0f",
3177+
"30450220793f95665d9af646339503a073670ea2c352459d2a2c2e14c57565f6c7eaf6bc022100cccadfc37e46755f52bb054ed206d7335067885df599a69431db40e33f33d4cf"
3178+
]
3179+
}
3180+
}
30913181
}
30923182
]
30933183
}
Binary file not shown.

0 commit comments

Comments
 (0)