xcim-cli 0.1.0__py3-none-any.whl
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.
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xcim-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Read-only XCIM integration diagnostics for people and agents
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://xcim.org/tools/
|
|
7
|
+
Project-URL: Source, https://github.com/saezbaldo/xcim-cli
|
|
8
|
+
Project-URL: Issues, https://github.com/saezbaldo/xcim-cli/issues
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# XCIM CLI
|
|
15
|
+
|
|
16
|
+
`xcim doctor` reports the configuration that an agent can actually observe. It never provisions an application, writes to an attester, reads SQL, or performs consent. The distribution is **xcim-cli** on both registries; the executable is **xcim**. The npm and Python editions have no runtime dependencies beyond their own runtime.
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
# Once the packages have been published:
|
|
20
|
+
npm exec --package=xcim-cli -- xcim doctor --attester emabled --json
|
|
21
|
+
pipx run --spec xcim-cli xcim doctor --attester emabled --json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Node 22+ or Python 3.9+ is required, respectively. Run from source with `node xcim.mjs doctor --attester emabled --json` or `python xcim_doctor.py doctor --attester emabled --json`.
|
|
25
|
+
|
|
26
|
+
## Choose an attester and profile
|
|
27
|
+
|
|
28
|
+
- `--attester emabled` (default) reads `https://api.emabled.com/v1/capabilities`. An explicit HTTPS origin, without a path, credentials, query, fragment or non-default port, can be used for another attester that implements the same capability contract. That contract is a compatibility requirement for this release, not an XCIM-mandated endpoint.
|
|
29
|
+
- `--profile evp|oidc|both` (default `both`) selects the checks. For EVP, `--evp-mode vendor|hosted` (default `vendor`) distinguishes a vendor-origin form from a hosted one.
|
|
30
|
+
- `--offline` makes no HTTP requests. Otherwise the command makes one unauthenticated HTTPS GET with a five-second deadline and rejects redirects. It does not read browser sessions or use vendor, ESP, database or publishing credentials.
|
|
31
|
+
|
|
32
|
+
## Diagnose workspace configuration
|
|
33
|
+
|
|
34
|
+
The public capability endpoint does not expose workspace settings. An authorized operator can open the application setup view in the Emabled console and save **only the JSON response body** of its existing read-only `GET /v1/control/provisioning/{requestId}/setup` request as `setup.json`. Do not export a HAR, request headers, session cookies or tokens. Keep the JSON local; it may contain workspace metadata. This edition does not log into the console or fetch this private endpoint itself.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
xcim doctor --attester emabled --snapshot setup.json --source src_example --profile both --json
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The snapshot is an operator-supplied observation, not signed evidence. It is supported only by the Emabled adapter and expires after 24 hours. Pass the source ID when multiple sources are linked or the response is paginated; the file must contain that source. Without a source ID the CLI selects a unique linked source only on an unpaginated response. It never infers that a source on another page is missing.
|
|
41
|
+
|
|
42
|
+
The report separates public capabilities from recorded workspace configuration: application registration, signed manifest publication, pairwise key configuration, source binding, recorded website DNS verification, exact return URI, exchange endpoint, provider binding/review and browser bootstrap. It does not independently verify any of those proofs. Live DNS, sender-domain authority, access to signing keys, Origin Trial token validity, end-to-end consent and receipts, and current permission are not checked.
|
|
43
|
+
|
|
44
|
+
## Agent output
|
|
45
|
+
|
|
46
|
+
With `--json`, stdout contains one JSON object (`schema: xcim-doctor/v1`). Each check has:
|
|
47
|
+
|
|
48
|
+
- `status`: `configured` (observed), `missing` (explicitly absent), or `unknown` (insufficient evidence).
|
|
49
|
+
- `evidence`: `attester_capabilities` or `console_snapshot`. Consult the top-level evidence statuses to distinguish an observed response from an unavailable or stale one.
|
|
50
|
+
- `human_required`: the unresolved next step requires a console operator, application owner, provider review or browser action. Missing evidence does not turn every dependent check into a separate human task.
|
|
51
|
+
- `next_action`: stable machine-readable instruction code, or `null` for a configured check.
|
|
52
|
+
|
|
53
|
+
The report does not echo response bodies, raw snapshot values such as keys or URLs, or server error text. It includes the selected application/source IDs for correlation. It has no global “integration ready” verdict.
|
|
54
|
+
|
|
55
|
+
| Exit | Meaning |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| 0 | All selected, in-scope configuration checks were observed. |
|
|
58
|
+
| 2 | At least one check is missing or unknown. This includes a public-only run with no snapshot. |
|
|
59
|
+
| 3 | A requested input could not be read/validated, or the attester request failed. The JSON report still describes what was observed. |
|
|
60
|
+
| 64 | Invalid command or flags. |
|
|
61
|
+
|
|
62
|
+
## Local verification
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
npm test
|
|
66
|
+
python -m unittest discover -s tests
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The suites use synthetic configuration, assert the read-only network contract, and check parity across the two editions. Do not share private setup snapshots or credentials in issues, pull requests, or test fixtures.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
This standalone CLI is licensed under [Apache-2.0](https://github.com/saezbaldo/xcim-cli/blob/main/LICENSE).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
xcim_doctor.py,sha256=7AD3YpzrbSBjMfPZHhEm9ZgqMuC9OTT_P426Qo5Yotc,13773
|
|
2
|
+
xcim_cli-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
3
|
+
xcim_cli-0.1.0.dist-info/METADATA,sha256=uwXEyjuf_pMBb-ZNuCxYcGDcQrXY6T1Nb27PvpE_-0s,5205
|
|
4
|
+
xcim_cli-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
+
xcim_cli-0.1.0.dist-info/entry_points.txt,sha256=3otneTGRARY-sSczU4sLRMYsDdDoZKdIOoF6y4LNtQo,42
|
|
6
|
+
xcim_cli-0.1.0.dist-info/top_level.txt,sha256=QL_YyHiFCi7OTeSE016YDppVcsA6JuOxvm0JFTRIyOE,12
|
|
7
|
+
xcim_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xcim_doctor
|
xcim_doctor.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"""Read-only XCIM integration diagnostics. No runtime dependencies."""
|
|
2
|
+
import datetime
|
|
3
|
+
import http.client
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import queue
|
|
7
|
+
import re
|
|
8
|
+
import stat
|
|
9
|
+
import sys
|
|
10
|
+
import threading
|
|
11
|
+
import time
|
|
12
|
+
|
|
13
|
+
LIMIT = 256 * 1024
|
|
14
|
+
SCHEMA = "xcim-doctor/v1"
|
|
15
|
+
USAGE = "xcim doctor [--attester emabled|https://host] [--profile evp|oidc|both] [--evp-mode vendor|hosted] [--snapshot FILE [--source src_ID]] [--offline] [--json]"
|
|
16
|
+
APP = r"urn:xcim:app:[A-Za-z0-9._~-]{1,54}"
|
|
17
|
+
SOURCE = r"src_[A-Za-z0-9_-]{4,43}"
|
|
18
|
+
REQUEST = r"pr_[A-Za-z0-9_-]{5,44}"
|
|
19
|
+
DATE = r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]{1,7})?(?:Z|[+-][0-9]{2}:[0-9]{2})"
|
|
20
|
+
APP_FIELDS = ("manifestPublicationRecorded", "exchangeEndpointActive", "pairwiseKeyConfigured")
|
|
21
|
+
SOURCE_FIELDS = ("domainVerificationRecorded", "returnRegistered", "oauthBindingActive", "oauthReviewCurrent", "oauthBootstrapConfirmed")
|
|
22
|
+
REQUEST_STATES = ("pending_review", "approved", "provisioning", "active", "rejected", "suspended", "failed")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def matches(value, pattern):
|
|
26
|
+
return isinstance(value, str) and re.fullmatch(pattern, value) is not None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def fail():
|
|
30
|
+
raise ValueError("invalid input")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def parse_args(argv):
|
|
34
|
+
if not argv or argv[0] != "doctor":
|
|
35
|
+
fail()
|
|
36
|
+
opts = {"attester": "emabled", "profile": "both", "evp-mode": "vendor"}
|
|
37
|
+
used = set()
|
|
38
|
+
values = iter(argv[1:])
|
|
39
|
+
for arg in values:
|
|
40
|
+
key = arg[2:]
|
|
41
|
+
if not arg.startswith("--") or key in used:
|
|
42
|
+
fail()
|
|
43
|
+
used.add(key)
|
|
44
|
+
if key in ("json", "offline"):
|
|
45
|
+
opts[key] = True
|
|
46
|
+
elif key in ("attester", "profile", "evp-mode", "snapshot", "source"):
|
|
47
|
+
value = next(values, None)
|
|
48
|
+
if not value or value.startswith("--"):
|
|
49
|
+
fail()
|
|
50
|
+
opts[key] = value
|
|
51
|
+
else:
|
|
52
|
+
fail()
|
|
53
|
+
if opts["profile"] not in ("evp", "oidc", "both") or opts["evp-mode"] not in ("vendor", "hosted"):
|
|
54
|
+
fail()
|
|
55
|
+
if "source" in opts and ("snapshot" not in opts or not matches(opts["source"], SOURCE)):
|
|
56
|
+
fail()
|
|
57
|
+
if opts["attester"] == "emabled":
|
|
58
|
+
opts["origin"] = "https://api.emabled.com"
|
|
59
|
+
else:
|
|
60
|
+
match = re.fullmatch(r"https://([a-z0-9.-]+)/?", opts["attester"], re.I | re.ASCII)
|
|
61
|
+
labels = match[1].lower().split(".") if match else []
|
|
62
|
+
if (not match or len(labels) < 2 or len(match[1]) > 253 or not re.match("[a-z]", labels[-1])
|
|
63
|
+
or any(not matches(label, r"[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?") for label in labels)):
|
|
64
|
+
fail()
|
|
65
|
+
opts["origin"] = "https://" + ".".join(labels)
|
|
66
|
+
opts["attester"] = "emabled" if opts["origin"] == "https://api.emabled.com" else "custom"
|
|
67
|
+
if "snapshot" in opts and opts["attester"] == "custom":
|
|
68
|
+
fail()
|
|
69
|
+
return opts
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def decode(data):
|
|
73
|
+
return json.loads(data.decode("utf-8-sig"), parse_constant=lambda _: fail())
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def load_snapshot(path):
|
|
77
|
+
if re.match(r"^(?:[\\/]{2}|[a-z]+://)", path, re.I) or not stat.S_ISREG(os.lstat(path).st_mode):
|
|
78
|
+
fail()
|
|
79
|
+
with open(path, "rb") as file:
|
|
80
|
+
metadata = os.fstat(file.fileno())
|
|
81
|
+
if not stat.S_ISREG(metadata.st_mode) or metadata.st_size > LIMIT:
|
|
82
|
+
fail()
|
|
83
|
+
data = file.read(LIMIT + 1)
|
|
84
|
+
if len(data) > LIMIT:
|
|
85
|
+
fail()
|
|
86
|
+
return decode(data)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def nullable_booleans(value, fields):
|
|
90
|
+
return all(key in value and (value[key] is None or type(value[key]) is bool) for key in fields)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def inspect_snapshot(data, now=None):
|
|
94
|
+
now = time.time() if now is None else now
|
|
95
|
+
if (not isinstance(data, dict) or not matches(data.get("applicationId"), APP)
|
|
96
|
+
or not matches(data.get("requestId"), REQUEST) or data.get("requestStatus") not in REQUEST_STATES
|
|
97
|
+
or type(data.get("registrationAvailable")) is not bool
|
|
98
|
+
or (data["registrationAvailable"] and data["requestStatus"] != "active")
|
|
99
|
+
or not nullable_booleans(data, APP_FIELDS) or not matches(data.get("observedAt"), DATE)
|
|
100
|
+
or not isinstance(data.get("sources"), list) or len(data["sources"]) > 25
|
|
101
|
+
or "nextSourceCursor" not in data
|
|
102
|
+
or (data["nextSourceCursor"] is not None and not matches(data["nextSourceCursor"], SOURCE))):
|
|
103
|
+
return "invalid"
|
|
104
|
+
ids = set()
|
|
105
|
+
for row in data["sources"]:
|
|
106
|
+
if (not isinstance(row, dict) or not matches(row.get("sourceId"), SOURCE)
|
|
107
|
+
or row["sourceId"] in ids or "applicationId" not in row
|
|
108
|
+
or (row["applicationId"] is not None and not matches(row["applicationId"], APP))
|
|
109
|
+
or not nullable_booleans(row, SOURCE_FIELDS)):
|
|
110
|
+
return "invalid"
|
|
111
|
+
ids.add(row["sourceId"])
|
|
112
|
+
date = re.sub(r"\.(\d{1,7})", lambda m: "." + (m[1] + "000000")[:6], data["observedAt"])
|
|
113
|
+
try:
|
|
114
|
+
observed = datetime.datetime.fromisoformat(date.replace("Z", "+00:00")).timestamp()
|
|
115
|
+
except (ValueError, OverflowError, OSError):
|
|
116
|
+
return "invalid"
|
|
117
|
+
if observed > now + 300:
|
|
118
|
+
return "invalid"
|
|
119
|
+
return "stale" if now - observed > 86400 else "fresh"
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def object_or_empty(value):
|
|
123
|
+
return value if isinstance(value, dict) else {}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def capability_state(caps, profile, mode):
|
|
127
|
+
if not caps:
|
|
128
|
+
return None
|
|
129
|
+
identity = caps["identity_evidence"]
|
|
130
|
+
if profile == "oidc":
|
|
131
|
+
status = object_or_empty(identity.get("oidc_01")).get("status")
|
|
132
|
+
else:
|
|
133
|
+
modes = object_or_empty(object_or_empty(identity.get("evp_01")).get("delivery_modes"))
|
|
134
|
+
status = object_or_empty(modes.get("vendor_origin_handoff" if mode == "vendor" else "emabled_hosted")).get("status")
|
|
135
|
+
if status == "unavailable":
|
|
136
|
+
return False
|
|
137
|
+
if status in ("supported", "experimental") and profile + "-01" in identity["supported_profiles"]:
|
|
138
|
+
return True
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def diagnose(opts, caps, data, snapshot_status, capabilities_status):
|
|
143
|
+
checks = []
|
|
144
|
+
|
|
145
|
+
def add(id_, value, evidence, action, human=False):
|
|
146
|
+
status = "configured" if value is True else "missing" if value is False else "unknown"
|
|
147
|
+
checks.append({"id": id_, "status": status, "evidence": evidence,
|
|
148
|
+
"human_required": human and status != "configured",
|
|
149
|
+
"next_action": None if status == "configured" else action})
|
|
150
|
+
|
|
151
|
+
def public_check(id_, value, action):
|
|
152
|
+
add(id_, value, "attester_capabilities", action)
|
|
153
|
+
|
|
154
|
+
def private_check(id_, value, action):
|
|
155
|
+
if value is None and id_ not in ("setup.snapshot", "source.binding"):
|
|
156
|
+
add(id_, None, "console_snapshot",
|
|
157
|
+
"inspect_setup_prerequisites" if snapshot_status == "fresh" else "provide_setup_snapshot")
|
|
158
|
+
return
|
|
159
|
+
human = value is False or id_ == "setup.snapshot" or action == "export_setup_page_containing_source"
|
|
160
|
+
add(id_, value, "console_snapshot", action, human)
|
|
161
|
+
|
|
162
|
+
evp, oidc = opts["profile"] != "oidc", opts["profile"] != "evp"
|
|
163
|
+
public_check("consent.hosted", caps["consent"]["hosted"] if caps else None, "check_attester_capabilities")
|
|
164
|
+
if evp:
|
|
165
|
+
public_check("evp.delivery_mode", capability_state(caps, "evp", opts["evp-mode"]), "choose_supported_evp_mode")
|
|
166
|
+
if oidc:
|
|
167
|
+
public_check("oidc.support", capability_state(caps, "oidc", None), "check_oidc_availability")
|
|
168
|
+
setup = data if snapshot_status == "fresh" else {}
|
|
169
|
+
private_check("setup.snapshot", True if setup else None, "export_current_setup_in_console")
|
|
170
|
+
actions = {"pending_review": "approve_request_in_workspace", "approved": "await_operator_provisioning",
|
|
171
|
+
"provisioning": "await_operator_provisioning", "rejected": "review_rejected_request",
|
|
172
|
+
"suspended": "review_suspended_application", "failed": "review_provisioning_failure"}
|
|
173
|
+
private_check("application.registration", setup.get("registrationAvailable"),
|
|
174
|
+
actions.get(setup.get("requestStatus"), "check_application_registration"))
|
|
175
|
+
private_check("manifest.publication", setup.get("manifestPublicationRecorded"), "review_and_publish_signed_manifest")
|
|
176
|
+
private_check("application.pairwise_key", setup.get("pairwiseKeyConfigured"), "configure_pairwise_key_with_operator")
|
|
177
|
+
linked = [row for row in setup.get("sources", []) if row["applicationId"] == setup["applicationId"]]
|
|
178
|
+
complete_page = bool(setup) and setup["nextSourceCursor"] is None
|
|
179
|
+
selected = (next((row for row in setup.get("sources", []) if row["sourceId"] == opts["source"]), {})
|
|
180
|
+
if "source" in opts else linked[0] if complete_page and len(linked) == 1 else {})
|
|
181
|
+
bound = (selected["applicationId"] == setup["applicationId"] if selected
|
|
182
|
+
else False if setup.get("registrationAvailable") and "source" not in opts and complete_page and not linked else None)
|
|
183
|
+
private_check("source.binding", bound, "provide_setup_snapshot" if not setup
|
|
184
|
+
else "export_setup_page_containing_source" if "source" in opts and not selected
|
|
185
|
+
else "review_and_bind_source_in_console" if bound is False else "select_source_from_setup_snapshot")
|
|
186
|
+
source = selected if bound else {}
|
|
187
|
+
private_check("source.website_dns_recorded", source.get("domainVerificationRecorded"), "review_website_dns_challenge")
|
|
188
|
+
private_check("source.return_uri", source.get("returnRegistered"), "review_and_register_exact_return_uri")
|
|
189
|
+
if oidc:
|
|
190
|
+
private_check("oidc.exchange_endpoint", setup.get("exchangeEndpointActive"), "review_exchange_endpoint_proof")
|
|
191
|
+
private_check("oidc.provider_binding", source.get("oauthBindingActive"), "review_provider_binding")
|
|
192
|
+
private_check("oidc.provider_review", source.get("oauthReviewCurrent"), "complete_authorized_provider_review")
|
|
193
|
+
private_check("oidc.bootstrap", source.get("oauthBootstrapConfirmed"), "complete_browser_bootstrap_and_backend_confirmation")
|
|
194
|
+
return {
|
|
195
|
+
"schema": SCHEMA, "read_only": True, "attester": opts["attester"], "origin": opts["origin"],
|
|
196
|
+
"profile": opts["profile"], "evp_mode": opts["evp-mode"] if evp else None,
|
|
197
|
+
"capabilities": capabilities_status,
|
|
198
|
+
"snapshot": {"status": snapshot_status, "observed_at": setup.get("observedAt"),
|
|
199
|
+
"application_id": setup.get("applicationId"), "source_id": selected.get("sourceId")},
|
|
200
|
+
"checks": checks,
|
|
201
|
+
"summary": {**{s: sum(row["status"] == s for row in checks) for s in ("configured", "missing", "unknown")},
|
|
202
|
+
"human_required": sum(row["human_required"] for row in checks)},
|
|
203
|
+
"not_checked": ["live_dns", "sender_domain_authority", "signing_key_access", "origin_trial_token",
|
|
204
|
+
"browser_provider_session", "end_to_end_consent_and_receipt", "current_permission"],
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def fetch_capabilities(origin):
|
|
209
|
+
def request():
|
|
210
|
+
with_connection = http.client.HTTPSConnection(origin.removeprefix("https://"), timeout=5)
|
|
211
|
+
try:
|
|
212
|
+
with_connection.request("GET", "/v1/capabilities", headers={"Accept": "application/json"})
|
|
213
|
+
response = with_connection.getresponse()
|
|
214
|
+
if response.status != 200 or not re.match(r"application/json(?:;|$)", response.getheader("Content-Type", ""), re.I):
|
|
215
|
+
fail()
|
|
216
|
+
data = response.read(LIMIT + 1)
|
|
217
|
+
if len(data) > LIMIT:
|
|
218
|
+
fail()
|
|
219
|
+
payload = decode(data)
|
|
220
|
+
if (not isinstance(payload, dict) or payload.get("protocol") != "xcim-0.1"
|
|
221
|
+
or not isinstance(object_or_empty(payload.get("identity_evidence")).get("supported_profiles"), list)
|
|
222
|
+
or type(object_or_empty(payload.get("consent")).get("hosted")) is not bool):
|
|
223
|
+
fail()
|
|
224
|
+
return payload
|
|
225
|
+
finally:
|
|
226
|
+
with_connection.close()
|
|
227
|
+
|
|
228
|
+
result = queue.Queue(maxsize=1)
|
|
229
|
+
|
|
230
|
+
def bounded_request():
|
|
231
|
+
try:
|
|
232
|
+
result.put(request())
|
|
233
|
+
except Exception:
|
|
234
|
+
result.put(None)
|
|
235
|
+
|
|
236
|
+
threading.Thread(target=bounded_request, daemon=True).start()
|
|
237
|
+
payload = result.get(timeout=5)
|
|
238
|
+
if payload is None:
|
|
239
|
+
fail()
|
|
240
|
+
return payload
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def run(opts, get_capabilities=fetch_capabilities):
|
|
244
|
+
data = caps = None
|
|
245
|
+
snapshot_status, capabilities_status = "absent", "not_checked"
|
|
246
|
+
if opts.get("snapshot"):
|
|
247
|
+
try:
|
|
248
|
+
data = load_snapshot(opts["snapshot"])
|
|
249
|
+
snapshot_status = inspect_snapshot(data)
|
|
250
|
+
except (OSError, ValueError, RecursionError):
|
|
251
|
+
snapshot_status = "invalid"
|
|
252
|
+
if not opts.get("offline"):
|
|
253
|
+
try:
|
|
254
|
+
caps = get_capabilities(opts["origin"])
|
|
255
|
+
capabilities_status = "observed"
|
|
256
|
+
except (OSError, ValueError, queue.Empty, http.client.HTTPException):
|
|
257
|
+
capabilities_status = "unavailable"
|
|
258
|
+
report = diagnose(opts, caps, data, snapshot_status, capabilities_status)
|
|
259
|
+
code = (3 if snapshot_status == "invalid" or capabilities_status == "unavailable"
|
|
260
|
+
else 2 if report["summary"]["missing"] or report["summary"]["unknown"] else 0)
|
|
261
|
+
return code, report
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def main(argv=None):
|
|
265
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
266
|
+
json_mode = "--json" in argv
|
|
267
|
+
if not argv or "--help" in argv or "-h" in argv:
|
|
268
|
+
print(json.dumps({"schema": SCHEMA, "usage": USAGE}) if json_mode else USAGE)
|
|
269
|
+
return 0
|
|
270
|
+
try:
|
|
271
|
+
opts = parse_args(argv)
|
|
272
|
+
except ValueError:
|
|
273
|
+
if json_mode:
|
|
274
|
+
print(json.dumps({"schema": SCHEMA, "error": "invalid_arguments", "usage": USAGE}))
|
|
275
|
+
else:
|
|
276
|
+
print(USAGE, file=sys.stderr)
|
|
277
|
+
return 64
|
|
278
|
+
code, report = run(opts)
|
|
279
|
+
if json_mode:
|
|
280
|
+
print(json.dumps(report, separators=(",", ":")))
|
|
281
|
+
else:
|
|
282
|
+
for row in report["checks"]:
|
|
283
|
+
action = " (" + row["next_action"] + ")" if row["next_action"] else ""
|
|
284
|
+
print(row["id"] + ": " + row["status"] + action)
|
|
285
|
+
return code
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
if __name__ == "__main__":
|
|
289
|
+
sys.exit(main())
|