ap2_mandate_verifier 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -23
- data/docs/SUPPORT_CONTRACT.md +15 -7
- data/lib/ap2_mandate_verifier/input_builder.rb +211 -0
- data/lib/ap2_mandate_verifier.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1367482ba612018a83790debee921f546003a7eabc0b43341602d9e3c1d4f9a6
|
|
4
|
+
data.tar.gz: 92d43d757d99b941a8724a4e4f4a9bbe450ae1b5f297cb5b6ec86c0007c915ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 444098518c421863e6a4ffaf41c33312f6634d88ddad3ad11402613bf068cbfbf0740351de43a4a5d1a8571c3d0b349d7e4697d3afa5c297fb1c08427683f8c8
|
|
7
|
+
data.tar.gz: 5bd155bc56710aea9a84a70d0c0c7342fa26b0d0523694691b06e727a16977dd42d5257f08f8f2dc71d27a231409fa5bc11dd0d8770282d91797b16a56dc7987
|
data/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
# AP2 Mandate Verifier — 0.
|
|
1
|
+
# AP2 Mandate Verifier — 0.3.0 candidate
|
|
2
|
+
|
|
3
|
+
The unpublished 0.3.0 candidate adds `InputBuilder`: map authenticated business records once, prepare and persist a challenge, then supply independent current state to the complete verifier. No hand-written trust/selection/Host JSON or hashes are needed. Start with the [runnable business-data example and Rails mapping](docs/INPUT_BUILDER.md). Existing seven-input APIs remain supported. Published installation below remains 0.2.1 until release approval.
|
|
2
4
|
|
|
3
5
|
[Japanese / 日本語](README.ja.md)
|
|
4
6
|
|
|
@@ -15,53 +17,48 @@ For a Japanese walkthrough of the three demo scenarios, see the [Zenn article](h
|
|
|
15
17
|
| Route | Start here |
|
|
16
18
|
| --- | --- |
|
|
17
19
|
| Docker demo: compare three synthetic cases | Follow the [demo README](https://github.com/cuichangquan/ap2-mandate-verifier-demo#readme) for local startup and valid / tampered / expired examples. Docker commands are maintained there. |
|
|
18
|
-
| Ruby without the demo:
|
|
20
|
+
| Ruby without the demo: MRI 3.4.12 or 4.0.9 | Follow [installation](#distribution-and-installation), then the [saved synthetic example](#try-the-saved-synthetic-example) below. |
|
|
19
21
|
|
|
20
22
|
Both routes use the fixed-profile verifier, not payment execution or Host authorization. See the [supported contract](#supported-contract) for the scope. The goal is to make the choices understandable in about five minutes, not to promise a five-minute installation or build.
|
|
21
23
|
|
|
22
24
|
## Distribution and installation
|
|
23
25
|
|
|
24
|
-
[0.2.
|
|
26
|
+
[0.2.1 is published on RubyGems](https://rubygems.org/gems/ap2_mandate_verifier/versions/0.2.1). This is the fixed-profile, verifier-only stable release; the research prerelease pre3 is a separate artifact.
|
|
25
27
|
|
|
26
|
-
Use an
|
|
28
|
+
Use an MRI 3.4.12 or MRI 4.0.9 environment and your chosen Gem isolation. Normal installation may fetch dependencies and build JSON native extensions. Stop on conflicts or unknown providers rather than relaxing pins.
|
|
27
29
|
|
|
28
30
|
```sh
|
|
29
|
-
ruby --version # MRI 4.0.9
|
|
30
|
-
gem install ap2_mandate_verifier --version 0.2.
|
|
31
|
+
ruby --version # MRI 3.4.12 or MRI 4.0.9
|
|
32
|
+
gem install ap2_mandate_verifier --version 0.2.1
|
|
31
33
|
```
|
|
32
34
|
|
|
33
35
|
Bundler Gemfile:
|
|
34
36
|
|
|
35
37
|
```ruby
|
|
36
|
-
gem "ap2_mandate_verifier", "= 0.2.
|
|
38
|
+
gem "ap2_mandate_verifier", "= 0.2.1"
|
|
37
39
|
```
|
|
38
40
|
|
|
39
41
|
Fixed runtime dependencies: JSON 2.19.9, JWT 3.3.0, base64 0.3.0, OpenSSL gem 4.0.2 and Digest 3.2.1.
|
|
40
42
|
Bundler 4.0.20 is the observed resolver baseline, not a runtime dependency. Gem version constraints alone do not enforce the MRI engine, OS or native-provider provenance.
|
|
41
43
|
|
|
42
|
-
##
|
|
43
|
-
|
|
44
|
-
0.2.1 is being prepared; RubyGems publication, a public tag and GitHub Release require a separate Owner decision. The published 0.2.0 commands above continue to require MRI 4.0.9.
|
|
44
|
+
## Ruby 3.4.12 compatibility and published artifact
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
0.2.1 formally supports exactly MRI 3.4.12 and MRI 4.0.9 with the same five fixed dependencies. Its installation metadata permits Ruby `>= 3.4.12, < 4.1`; that interval does not declare every intermediate version or another engine supported.
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
Both versions were measured on Debian 12/arm64 with official Ruby bookworm images: 885 source regressions, 190 additional checkout cases and 7 metadata cases passed per Ruby. The same final Gem passed ordinary installation, all 13 payload-file comparisons, 10 normally loaded product files and 118 installed cases on each version. Exact providers and evidence are in the [compatibility record](docs/RUBY_3_4_12_COMPATIBILITY.md). Historical macOS/Ubuntu observations are separate and do not establish 0.2.1 compatibility there.
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
ruby --version # MRI 3.4.12 or MRI 4.0.9
|
|
52
|
-
gem install ./ap2_mandate_verifier-0.2.1.gem --no-document
|
|
53
|
-
```
|
|
50
|
+
Published 2026-10-30 11:51:55.894 UTC; verified 11:53:55 UTC. Official RubyGems metadata, distribution bytes and the retained final Gem matched: **34,816 bytes**, SHA256 `a4ab7e0f6c9bd87355695369374f8e6e2dad104fb673700e9f616053afe6e114`, source `5a02bc3a192e16aa3628cf7899617623b0aed78c`. Owner `cuichangquan`, platform `ruby`, non-prerelease, not yanked at verification. The [v0.2.1 GitHub Release](https://github.com/cuichangquan/ap2-mandate-verifier/releases/tag/v0.2.1) uses that exact source tag.
|
|
54
51
|
|
|
55
|
-
|
|
52
|
+
The Gem's packaged README/contract retain their preparation snapshot. These repository updates do not rebuild or replace the published bytes. GitHub source archives differ from the RubyGems Gem. Seven inputs, fixed profile, Fail Closed, Result/Evidence v2 and existing API meanings remain unchanged; publication does not establish Host production GO.
|
|
56
53
|
|
|
57
|
-
## Verification APIs: 0.2.
|
|
54
|
+
## Verification APIs: 0.2.1 and compatibility
|
|
58
55
|
|
|
59
|
-
**The installation commands and saved example use published 0.2.
|
|
56
|
+
**The installation commands and saved example use published 0.2.1 and its recommended `verify_checkout` entry.** Existing 0.1.0 applications can continue using `verify_research`; it remains available in 0.2.1 without a deprecation warning. Installing 0.1.0 does not provide `verify_checkout`.
|
|
60
57
|
|
|
61
58
|
| Entry | Availability and contract |
|
|
62
59
|
| --- | --- |
|
|
63
|
-
| `verify_checkout(**inputs)` | Recommended full-verification entry
|
|
64
|
-
| `verify_research(**inputs)` | Full-verification entry in published 0.1.0; retained unchanged in v0.2.
|
|
60
|
+
| `verify_checkout(**inputs)` | Recommended full-verification entry since 0.2.0, retained in 0.2.1. Delegates directly to `ResearchResult.verify` without changing inputs or the verification pipeline. |
|
|
61
|
+
| `verify_research(**inputs)` | Full-verification entry in published 0.1.0; retained unchanged in v0.2.1, without a deprecation warning. |
|
|
65
62
|
| `verify(presentation_json:)` | Existing JSON syntax check only. Valid JSON returns `:unverified` / `:verification_not_implemented`, never successful Evidence. It is not a substitute for full verification. |
|
|
66
63
|
|
|
67
64
|
The recommended entry takes all seven inputs. In the saved example below, these values come from `full`; real integrations must supply the authenticated Host inputs described below:
|
|
@@ -96,7 +93,7 @@ See [SUPPORT_CONTRACT](docs/SUPPORT_CONTRACT.md) for exact required shapes, boun
|
|
|
96
93
|
|
|
97
94
|
## Environment, compatibility and maintenance
|
|
98
95
|
|
|
99
|
-
The
|
|
96
|
+
The supported MRI versions are 3.4.12 and 4.0.9 with fixed dependencies; current 0.2.1 measurements cover the exact Debian 12/arm64 configurations in the compatibility record above. Earlier MRI 4.0.9 MBA/macOS arm64 and Ubuntu 24.04/x86_64 observations retain their historical scope. Distinguish [historical release-package/provider evidence](research/stable010_release_linux_package/README.md) from the current artifact. Other OS versions, engines, architectures and arbitrary provider updates are not covered.
|
|
100
97
|
|
|
101
98
|
Supported-input semantics and APIs do not change silently. Security-driven narrowing identifies reason, impact and migration; breaking API/required-field/profile changes are explicit. Dependency updates are not automatically compatible.
|
|
102
99
|
|
|
@@ -187,7 +184,7 @@ The Host supplies authenticated token-independent trust/keys/profile and current
|
|
|
187
184
|
|
|
188
185
|
## Evidence and history
|
|
189
186
|
|
|
190
|
-
The published 0.2.0 Gem is **33,280 bytes**, SHA256 `9a52e802de5a0564c34d198f4c4ad2c2b60791a8f1eb6e31db14c49e28e91f16`, from source commit `9b2e28d91fc4886722de7b9c39a5422e966953a9`. Publication on 2026-10-30 was verified against official RubyGems metadata, distribution bytes and the retained Gem. Its final Debian 12/arm64 / MRI 4.0.9 packaging observation matched all 13 payload files across source/archive/installation, loaded 10 product Ruby files normally and passed 118 installed cases using saved inputs/expected values. This is a limited observation, not a supported-platform expansion; source190/885 were not rerun in that packaging step. See [
|
|
187
|
+
The published 0.2.0 Gem is **33,280 bytes**, SHA256 `9a52e802de5a0564c34d198f4c4ad2c2b60791a8f1eb6e31db14c49e28e91f16`, from source commit `9b2e28d91fc4886722de7b9c39a5422e966953a9`. Publication on 2026-10-30 was verified against official RubyGems metadata, distribution bytes and the retained Gem. Its final Debian 12/arm64 / MRI 4.0.9 packaging observation matched all 13 payload files across source/archive/installation, loaded 10 product Ruby files normally and passed 118 installed cases using saved inputs/expected values. This is a limited observation, not a supported-platform expansion; source190/885 were not rerun in that packaging step. See [historical 0.2.0 publication record](docs/PROJECT_STATUS.md#020公開済み--現在の配布状態).
|
|
191
188
|
|
|
192
189
|
The packaged README and contract are snapshots from before publication. These repository documentation updates do not change the published Gem, require no rebuild, and do not transfer its validation to a rebuilt artifact. GitHub source archives contain repository source, not the RubyGems binary.
|
|
193
190
|
|
data/docs/SUPPORT_CONTRACT.md
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
# Fixed-profile AP2 verification — 0.2.1
|
|
1
|
+
# Fixed-profile AP2 verification — published 0.2.1 / historical 0.2.0
|
|
2
|
+
|
|
3
|
+
## Unpublished 0.3.0 input-assistance candidate
|
|
4
|
+
|
|
5
|
+
`InputBuilder` is an additive, Rails-independent conversion layer for explicit authenticated Host business records, versioned challenge preparation/restoration, and independently obtained current state. `verify` enters the unchanged complete `verify_checkout` core; assembly/restore alone never returns Evidence. Existing seven inputs, fixed profile/AP2 source, Result/Evidence v2, MRI 3.4.12/4.0.9 and all five pinned runtime dependencies remain unchanged.
|
|
6
|
+
|
|
7
|
+
New business Hash/Array graphs are bounded before serialization and require plain built-ins with String keys; unknown fields, formats/profiles, conflicting keys and unsupported shapes fail closed. Persist the original returned challenge String and original signed wires. `restore_trust` validates and preserves exact stored trust/selection Strings. Rebuilding trust from business records creates a new snapshot whose exact bytes may differ; it must not repair old challenge references. Stored B/digests/references are never regenerated from current values. Host authentication, freshness/revocation, storage, issuance/atomic consumption and final authorization remain Host duties. See [input assistance](INPUT_BUILDER.md). These candidate statements do not authorize publication or production operation.
|
|
2
8
|
|
|
3
9
|
**Fixed-profile verification contract; Evidence is not Host ALLOW or payment permission.**
|
|
4
10
|
Distribution availability is determined by the official RubyGems version listing, not by this document. Specific Host production GO remains separate.
|
|
5
11
|
Owner adopted the existing verification API and bounded stable-release conditions below. Publication and a specific Host's production operation are separate decisions; this contract does not authorize either.
|
|
6
12
|
Published research-only pre3 remains unchanged. Its historical observations below do not certify this new archive.
|
|
7
13
|
|
|
8
|
-
##
|
|
14
|
+
## Published 0.2.1 compatibility and artifact
|
|
15
|
+
|
|
16
|
+
[0.2.1 is published on RubyGems](https://rubygems.org/gems/ap2_mandate_verifier/versions/0.2.1). Formal runtime support is exactly MRI 3.4.12 and MRI 4.0.9, with JSON 2.19.9, JWT 3.3.0, base64 0.3.0, OpenSSL gem 4.0.2 and Digest 3.2.1 unchanged. Bundler 4.0.20 is the resolver validation baseline, not a runtime dependency. The installation requirement `>= 3.4.12, < 4.1` is a resolution interval, not certification of other Ruby versions or engines.
|
|
9
17
|
|
|
10
|
-
|
|
18
|
+
Both versions passed source885 + additional checkout190 + metadata7 on Debian 12/arm64 with official Ruby bookworm images. The same final artifact passed ordinary installation, 13 payload-file comparisons, 10 normally loaded product Ruby files and 118 installed cases per Ruby. Actual OS/native-provider identities and evidence are in the [compatibility record](RUBY_3_4_12_COMPATIBILITY.md). These measurements cover their exact recorded configurations; historical macOS/Ubuntu evidence below does not validate 0.2.1 there.
|
|
11
19
|
|
|
12
|
-
|
|
20
|
+
Published 2026-10-30 11:51:55.894 UTC; verified 11:53:55 UTC: owner `cuichangquan`, platform `ruby`, non-prerelease, not yanked at verification. Official metadata, distributed Gem and retained artifact matched: **34,816 bytes**, SHA256 `a4ab7e0f6c9bd87355695369374f8e6e2dad104fb673700e9f616053afe6e114`, source `5a02bc3a192e16aa3628cf7899617623b0aed78c`. The [v0.2.1 GitHub Release](https://github.com/cuichangquan/ap2-mandate-verifier/releases/tag/v0.2.1) tag points to that exact source.
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
Seven inputs, fixed profile, Fail Closed, Result/Evidence v2 and `verify_checkout` / `verify_research` / legacy `verify` meanings remain unchanged; product `lib/` is unchanged. Packaged README/contract retain the preparation snapshot. Repository publication updates do not rebuild or replace those bytes. GitHub source archives differ from the RubyGems Gem. Publication does not establish real Issuer trust, Host production GO or Phase 2-B; existing HOLDs remain.
|
|
15
23
|
|
|
16
24
|
## Published 0.2.0 API
|
|
17
25
|
|
|
@@ -35,7 +43,7 @@ Published 2026-10-30 06:43:10 UTC, verified 06:44:48 UTC: owner `cuichangquan`,
|
|
|
35
43
|
|
|
36
44
|
This final candidate separately passed the limited Debian 12/arm64 / MRI 4.0.9 observation: all 13 payload files matched source/archive/installation, 10 product Ruby files loaded through ordinary require, and 118 installed cases passed (42 research +42 checkout +24 unavailable +7 legacy +2 invalid inputs +1 constructor). Fixed dependencies and saved inputs/expected values were reused; source190/885 were NOT_RUN in this packaging step. Final report SHA256 `4348837cc153c65633e36c83c7939540819f164f43588d8140656e5ab50c2ccd`; publication receipt SHA256 `4b8264c5b990b10ad76a3fa3f01fc4ca94e6a828664ab3cefe11e6792c94a139`. These identify retained local records, not public downloads.
|
|
37
45
|
|
|
38
|
-
Publication does not expand supported-platform guarantees or establish real Issuer trust, revocation, actual Host operation, performance, production GO or Phase 2-B. The published Gem's documents are the pre-publication snapshot. Repository-only follow-up edits do not alter its bytes and require no rebuild; rebuilt artifacts do not inherit its validation. GitHub source archives differ from the RubyGems Gem. See [
|
|
46
|
+
Publication does not expand supported-platform guarantees or establish real Issuer trust, revocation, actual Host operation, performance, production GO or Phase 2-B. The published Gem's documents are the pre-publication snapshot. Repository-only follow-up edits do not alter its bytes and require no rebuild; rebuilt artifacts do not inherit its validation. GitHub source archives differ from the RubyGems Gem. See [0.2.0 publication record](PROJECT_STATUS.md#020公開済み--現在の配布状態).
|
|
39
47
|
|
|
40
48
|
## Verification contract
|
|
41
49
|
|
|
@@ -56,7 +64,7 @@ Manual dependency/provider review is adopted monthly, on relevant advisories and
|
|
|
56
64
|
|
|
57
65
|
## Existing API/limits and historical evidence baseline
|
|
58
66
|
|
|
59
|
-
The API/limit specification below preserves the existing contract. All pre2/pre3/MBA409/R1 observations are historical, not proof of a newly built archive. Historical release source/archive/installed identities and observations are recorded in [release-package evidence](../research/stable010_release_linux_package/README.md);
|
|
67
|
+
The API/limit specification below preserves the existing contract. All pre2/pre3/MBA409/R1 observations are historical, not proof of a newly built archive. Historical release source/archive/installed identities and observations are recorded in [release-package evidence](../research/stable010_release_linux_package/README.md); 0.2.1 has its separate compatibility record above. No old result is relabelled.
|
|
60
68
|
|
|
61
69
|
## Supported proposition and environment
|
|
62
70
|
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AP2MandateVerifier
|
|
4
|
+
# Pure, fixed-profile conversion of authenticated Host business information.
|
|
5
|
+
# Preparation is not issuance, verification, nonce consumption or Host ALLOW.
|
|
6
|
+
module InputBuilder
|
|
7
|
+
FORMAT_VERSION = "1"
|
|
8
|
+
ORDER_FIELDS = %w[tenant_id buyer_account_id order_id merchant_id audience order_version currency expected_total].freeze
|
|
9
|
+
RECORD_FIELDS = (TrustContext::RECORD_FIELDS - %w[profile_ref profile_version algorithm key_fingerprint]).freeze
|
|
10
|
+
class Invalid < ArgumentError; end
|
|
11
|
+
|
|
12
|
+
class Trust
|
|
13
|
+
attr_reader :trust_json, :selection_json
|
|
14
|
+
def initialize(trust_json, selection_json, context)
|
|
15
|
+
@trust_json, @selection_json = trust_json.freeze, selection_json.freeze
|
|
16
|
+
@context = context
|
|
17
|
+
freeze
|
|
18
|
+
end
|
|
19
|
+
private_class_method :new
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# All registry entries are preserved, including inactive/nonselected entries.
|
|
23
|
+
# Selection is explicit Host policy, never extracted from signed claims.
|
|
24
|
+
def self.trust(snapshot:, tenant_id:, issuer:, agent:, merchant:, verified_at:)
|
|
25
|
+
verified_at = copy!(verified_at)
|
|
26
|
+
source = copy!(snapshot)
|
|
27
|
+
shape!(source, %w[id policy_version active not_before not_after records])
|
|
28
|
+
invalid! unless source["records"].instance_of?(Array) && source["records"].length.between?(1, 16)
|
|
29
|
+
source["records"].each do |record|
|
|
30
|
+
shape!(record, RECORD_FIELDS)
|
|
31
|
+
record.merge!("profile_ref" => TrustContext::PROFILE_REF, "profile_version" => TrustContext::PROFILE_VERSION,
|
|
32
|
+
"algorithm" => "ES256", "key_fingerprint" => Digest::SHA256.hexdigest(record.fetch("public_key_pem")))
|
|
33
|
+
end
|
|
34
|
+
body = json!(source, 65_536)
|
|
35
|
+
selection = {"trust_snapshot_id" => source["id"], "policy_version" => source["policy_version"],
|
|
36
|
+
"trust_content_hash" => Digest::SHA256.hexdigest(body), "tenant_id" => copy!(tenant_id),
|
|
37
|
+
"profile_ref" => TrustContext::PROFILE_REF, "profile_version" => TrustContext::PROFILE_VERSION,
|
|
38
|
+
"profile_definition_hash" => TrustContext::PROFILE_HASH,
|
|
39
|
+
"Issuer" => copy!(issuer), "Agent" => copy!(agent), "Merchant" => copy!(merchant)}
|
|
40
|
+
TrustContext::ROLES.each_key { |role| shape!(selection[role], %w[identity purpose key_ref]) }
|
|
41
|
+
wire = json!({"snapshot" => {"id" => source["id"], "policy_version" => source["policy_version"],
|
|
42
|
+
"content_hash" => selection["trust_content_hash"], "body" => body},
|
|
43
|
+
"profile" => {"profile_ref" => TrustContext::PROFILE_REF, "version" => TrustContext::PROFILE_VERSION,
|
|
44
|
+
"definition_hash" => TrustContext::PROFILE_HASH, "body" => TrustContext::PROFILE_BODY}})
|
|
45
|
+
selected = json!(selection, 16_384)
|
|
46
|
+
context = TrustContext.verified_context!(trust_json: wire, selection_json: selected, verified_at: verified_at,
|
|
47
|
+
expected_merchant_id: selection.fetch("Merchant").fetch("identity"))
|
|
48
|
+
Trust.send(:new, wire, selected, context)
|
|
49
|
+
rescue RootSignature::Unavailable
|
|
50
|
+
raise
|
|
51
|
+
rescue InputValidator::Invalid, RootSignature::Rejected, KeyError, TypeError
|
|
52
|
+
invalid!
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Restore authenticated registry bytes without reserializing the snapshot
|
|
56
|
+
# or profile body. The Host remains responsible for freshness and provenance.
|
|
57
|
+
def self.restore_trust(trust_json:, selection_json:, verified_at:)
|
|
58
|
+
wire = InputValidator.snapshot!(trust_json)
|
|
59
|
+
selected = InputValidator.snapshot!(selection_json, max_bytes: 16_384)
|
|
60
|
+
selection = InputValidator.parse!(selected)
|
|
61
|
+
context = TrustContext.verified_context!(trust_json: wire, selection_json: selected,
|
|
62
|
+
verified_at: copy!(verified_at), expected_merchant_id: selection.fetch("Merchant").fetch("identity"))
|
|
63
|
+
Trust.send(:new, wire, selected, context)
|
|
64
|
+
rescue RootSignature::Unavailable
|
|
65
|
+
raise
|
|
66
|
+
rescue InputValidator::Invalid, RootSignature::Rejected, KeyError, TypeError, NoMethodError
|
|
67
|
+
invalid!
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Persist the returned original String in authenticated Host storage. A nonce
|
|
71
|
+
# and identifier must already have been chosen by the Host, independently.
|
|
72
|
+
def self.prepare(trust:, order:, root_presentation:, host_checkout_jws:, challenge_id:, nonce:, issuer_id:, not_before:, not_after:)
|
|
73
|
+
context = context!(trust, not_before)
|
|
74
|
+
TrustContext.verified_context!(trust_json: trust.trust_json, selection_json: trust.selection_json,
|
|
75
|
+
verified_at: not_before, expected_merchant_id: context.fetch(:selected_keys).find { |r| r["role"] == "Merchant" }.fetch("identity"))
|
|
76
|
+
challenge = {"challenge_id" => copy!(challenge_id), "nonce" => copy!(nonce), "issuer_id" => copy!(issuer_id),
|
|
77
|
+
"B" => binding!(context, order, root_presentation, host_checkout_jws),
|
|
78
|
+
"not_before" => copy!(not_before), "not_after" => copy!(not_after), "state" => "issued"}
|
|
79
|
+
HostBinding::REFERENCES.each { |field| challenge[field] = context.fetch(:references).fetch(field) }
|
|
80
|
+
saved = json!({"format_version" => FORMAT_VERSION, "profile_ref" => TrustContext::PROFILE_REF,
|
|
81
|
+
"profile_version" => TrustContext::PROFILE_VERSION, "challenge" => challenge}, 32_768)
|
|
82
|
+
restore(saved_challenge: saved)
|
|
83
|
+
rescue RootSignature::Unavailable
|
|
84
|
+
raise
|
|
85
|
+
rescue InputValidator::Invalid, RootSignature::Rejected, KeyError, TypeError
|
|
86
|
+
invalid!
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Validate, but never regenerate, hash or repair persisted challenge fields.
|
|
90
|
+
# This does not authenticate the storage or attest that its nonce is unused.
|
|
91
|
+
def self.restore(saved_challenge:)
|
|
92
|
+
wire = InputValidator.snapshot!(saved_challenge, max_bytes: 32_768)
|
|
93
|
+
value = InputValidator.parse!(wire)
|
|
94
|
+
shape!(value, %w[format_version profile_ref profile_version challenge])
|
|
95
|
+
invalid! unless value.values_at("format_version", "profile_ref", "profile_version") ==
|
|
96
|
+
[FORMAT_VERSION, TrustContext::PROFILE_REF, TrustContext::PROFILE_VERSION]
|
|
97
|
+
challenge = value["challenge"]
|
|
98
|
+
shape!(challenge, HostBinding::CHALLENGE_FIELDS)
|
|
99
|
+
HostBinding.send(:binding!, challenge["B"])
|
|
100
|
+
invalid! unless challenge["B"].values_at("profile_ref", "profile_version") ==
|
|
101
|
+
[TrustContext::PROFILE_REF, TrustContext::PROFILE_VERSION]
|
|
102
|
+
%w[challenge_id nonce issuer_id trust_snapshot_id policy_version state].each { |field| HostBinding.send(:id!, challenge[field]) }
|
|
103
|
+
%w[trust_content_hash profile_definition_hash].each { |field| HostBinding.send(:hash!, challenge[field]) }
|
|
104
|
+
%w[not_before not_after].each { |field| HostBinding.send(:time!, challenge[field]) }
|
|
105
|
+
invalid! unless challenge["not_before"] < challenge["not_after"]
|
|
106
|
+
wire
|
|
107
|
+
rescue RootSignature::Unavailable
|
|
108
|
+
raise
|
|
109
|
+
rescue InputValidator::Invalid, RootSignature::Rejected, KeyError, TypeError
|
|
110
|
+
invalid!
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.inputs(trust:, saved_challenge:, order:, root_presentation:, terminal_jws:, host_checkout_jws:,
|
|
114
|
+
expected_challenge_issuer_id:, clock_source_id:, verified_at:)
|
|
115
|
+
context = context!(trust, verified_at)
|
|
116
|
+
saved = InputValidator.parse!(restore(saved_challenge: saved_challenge))
|
|
117
|
+
root = InputValidator.snapshot!(root_presentation)
|
|
118
|
+
checkout = InputValidator.snapshot!(host_checkout_jws, max_bytes: 16_384)
|
|
119
|
+
terminal = InputValidator.snapshot!(terminal_jws, max_bytes: 32_768)
|
|
120
|
+
host = {"binding" => binding!(context, order, root, checkout), "challenge" => saved.fetch("challenge"),
|
|
121
|
+
"expected_challenge_issuer_id" => copy!(expected_challenge_issuer_id), "clock_source_id" => copy!(clock_source_id)}
|
|
122
|
+
{trust_json: trust.trust_json, selection_json: trust.selection_json, host_json: json!(host, 32_768),
|
|
123
|
+
root_presentation: root, terminal_jws: terminal, host_checkout_jws: checkout, verified_at: verified_at}.freeze
|
|
124
|
+
rescue RootSignature::Unavailable
|
|
125
|
+
raise
|
|
126
|
+
rescue InputValidator::Invalid, RootSignature::Rejected, KeyError, TypeError
|
|
127
|
+
invalid!
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Building alone never produces Evidence; always enter the full old core.
|
|
131
|
+
def self.verify(**arguments)
|
|
132
|
+
AP2MandateVerifier.verify_checkout(**inputs(**arguments))
|
|
133
|
+
rescue Invalid, ArgumentError
|
|
134
|
+
Result.new(status: :rejected, code: :invalid_host_context)
|
|
135
|
+
rescue InputValidator::Unavailable, RootSignature::Unavailable, LoadError
|
|
136
|
+
Result.new(status: :unavailable, code: :research_verification_unavailable)
|
|
137
|
+
rescue StandardError
|
|
138
|
+
Result.new(status: :unavailable, code: :research_verification_unavailable)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def self.context!(trust, now)
|
|
142
|
+
invalid! unless Object.instance_method(:instance_of?).bind_call(trust, Trust)
|
|
143
|
+
HostBinding.send(:time!, copy!(now))
|
|
144
|
+
trust.instance_variable_get(:@context)
|
|
145
|
+
end
|
|
146
|
+
def self.binding!(context, order, root, checkout)
|
|
147
|
+
value = copy!(order)
|
|
148
|
+
shape!(value, ORDER_FIELDS)
|
|
149
|
+
references = context.fetch(:references)
|
|
150
|
+
value.merge!("profile_ref" => references.fetch("profile_ref"), "profile_version" => references.fetch("profile_version"),
|
|
151
|
+
"approved_agent_key_fingerprint" => context.fetch(:agent_fingerprint),
|
|
152
|
+
"root_presentation_digest" => Digest::SHA256.hexdigest(InputValidator.snapshot!(root)),
|
|
153
|
+
"checkout_jwt_digest" => Digest::SHA256.hexdigest(InputValidator.snapshot!(checkout, max_bytes: 16_384)))
|
|
154
|
+
HostBinding.send(:binding!, value)
|
|
155
|
+
value
|
|
156
|
+
end
|
|
157
|
+
def self.shape!(value, fields)
|
|
158
|
+
invalid! unless value.instance_of?(Hash) && value.keys.sort == fields.sort
|
|
159
|
+
end
|
|
160
|
+
def self.invalid! = raise(Invalid, "invalid input-builder information")
|
|
161
|
+
def self.json!(value, limit = InputValidator::MAX_BYTES)
|
|
162
|
+
require "json"
|
|
163
|
+
raise InputValidator::Unavailable, :json_dependency_unavailable unless JSON::VERSION == InputValidator::JSON_VERSION
|
|
164
|
+
InputValidator.snapshot!(JSON.generate(value), max_bytes: limit)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Bound and detach before JSON generation, including the pre-serialization
|
|
168
|
+
# graph. No coercion, subclass or singleton callback is invoked by copying.
|
|
169
|
+
def self.copy!(value)
|
|
170
|
+
budget = [0, 0]
|
|
171
|
+
walk!(value, 1, {}, budget)
|
|
172
|
+
end
|
|
173
|
+
def self.walk!(value, depth, ancestors, budget)
|
|
174
|
+
invalid! if depth > 16 || (budget[0] += 1) > 2048
|
|
175
|
+
invalid! unless Object.instance_method(:singleton_methods).bind_call(value, true).empty?
|
|
176
|
+
klass = Object.instance_method(:class).bind_call(value)
|
|
177
|
+
if klass == String
|
|
178
|
+
wire = InputValidator.snapshot!(value, max_bytes: 65_536)
|
|
179
|
+
invalid! if (budget[1] += wire.bytesize) > 131_072
|
|
180
|
+
wire.dup
|
|
181
|
+
elsif klass == Integer
|
|
182
|
+
invalid! unless value.between?(0, ScopedConstraints::MAX_AMOUNT)
|
|
183
|
+
value
|
|
184
|
+
elsif klass == TrueClass || klass == FalseClass || klass == NilClass
|
|
185
|
+
value
|
|
186
|
+
elsif klass == Hash || klass == Array
|
|
187
|
+
id = Object.instance_method(:object_id).bind_call(value)
|
|
188
|
+
invalid! if ancestors[id]
|
|
189
|
+
ancestors[id] = true
|
|
190
|
+
invalid! if value.size > 256
|
|
191
|
+
result = if klass == Array
|
|
192
|
+
value.map { |child| walk!(child, depth + 1, ancestors, budget) }
|
|
193
|
+
else
|
|
194
|
+
result = {}
|
|
195
|
+
value.each do |key, child|
|
|
196
|
+
invalid! unless Object.instance_method(:class).bind_call(key) == String
|
|
197
|
+
copied_key = walk!(key, depth + 1, ancestors, budget)
|
|
198
|
+
invalid! if result.key?(copied_key)
|
|
199
|
+
result[copied_key] = walk!(child, depth + 1, ancestors, budget)
|
|
200
|
+
end
|
|
201
|
+
result
|
|
202
|
+
end
|
|
203
|
+
ancestors.delete(id)
|
|
204
|
+
result
|
|
205
|
+
else
|
|
206
|
+
invalid!
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
private_class_method :context!, :binding!, :shape!, :invalid!, :json!, :copy!, :walk!
|
|
210
|
+
end
|
|
211
|
+
end
|
data/lib/ap2_mandate_verifier.rb
CHANGED
|
@@ -9,6 +9,7 @@ require_relative "ap2_mandate_verifier/scoped_constraints"
|
|
|
9
9
|
require_relative "ap2_mandate_verifier/trust_context"
|
|
10
10
|
require_relative "ap2_mandate_verifier/host_binding"
|
|
11
11
|
require_relative "ap2_mandate_verifier/research_result"
|
|
12
|
+
require_relative "ap2_mandate_verifier/input_builder"
|
|
12
13
|
|
|
13
14
|
module AP2MandateVerifier
|
|
14
15
|
# Accepts original JSON bytes only. Syntax validity is not AP2 validity,
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ap2_mandate_verifier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- AP2 Mandate Verifier contributors
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: json
|
|
@@ -92,6 +92,7 @@ files:
|
|
|
92
92
|
- docs/SUPPORT_CONTRACT.md
|
|
93
93
|
- lib/ap2_mandate_verifier.rb
|
|
94
94
|
- lib/ap2_mandate_verifier/host_binding.rb
|
|
95
|
+
- lib/ap2_mandate_verifier/input_builder.rb
|
|
95
96
|
- lib/ap2_mandate_verifier/input_validator.rb
|
|
96
97
|
- lib/ap2_mandate_verifier/purchase_binding.rb
|
|
97
98
|
- lib/ap2_mandate_verifier/research_result.rb
|