Compare commits
5 Commits
push-yyxvk
...
45dd22cd50
| Author | SHA1 | Date | |
|---|---|---|---|
| 45dd22cd50 | |||
| 34ecf6928e | |||
| 29b3739e19 | |||
| 075d33219e | |||
| 8cb6f4abe0 |
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"git.enabled": false
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ when:
|
|||||||
include: ['.woodpecker/server-*.yaml', 'server/**']
|
include: ['.woodpecker/server-*.yaml', 'server/**']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: audit
|
- name: test
|
||||||
image: jdxcode/mise:latest
|
image: jdxcode/mise:latest
|
||||||
directory: server
|
directory: server
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
when:
|
|
||||||
- event: pull_request
|
|
||||||
path:
|
|
||||||
include: ['.woodpecker/server-*.yaml', 'server/**']
|
|
||||||
- event: push
|
|
||||||
branch: main
|
|
||||||
path:
|
|
||||||
include: ['.woodpecker/server-*.yaml', 'server/**']
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: lint
|
|
||||||
image: jdxcode/mise:latest
|
|
||||||
directory: server
|
|
||||||
environment:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
CARGO_TARGET_DIR: /usr/local/cargo/target
|
|
||||||
CARGO_HOME: /usr/local/cargo/registry
|
|
||||||
volumes:
|
|
||||||
- cargo-target:/usr/local/cargo/target
|
|
||||||
- cargo-registry:/usr/local/cargo/registry
|
|
||||||
commands:
|
|
||||||
- apt-get update && apt-get install -y pkg-config
|
|
||||||
- mise install rust
|
|
||||||
- mise install protoc
|
|
||||||
- mise exec rust -- cargo clippy --all-targets --all-features -- -D warnings
|
|
||||||
@@ -8,7 +8,7 @@ when:
|
|||||||
include: ['.woodpecker/server-*.yaml', 'server/**']
|
include: ['.woodpecker/server-*.yaml', 'server/**']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: vet
|
- name: test
|
||||||
image: jdxcode/mise:latest
|
image: jdxcode/mise:latest
|
||||||
directory: server
|
directory: server
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
Arbiter is a permissioned signing service for cryptocurrency wallets. It runs as a background service on the user's machine with an optional client application for vault management.
|
Arbiter is a permissioned signing service for cryptocurrency wallets. It runs as a background service on the user's machine with an optional client application for vault management.
|
||||||
|
|
||||||
**Core principle:** The vault NEVER exposes key material. It only produces signatures when a request satisfies the configured policies.
|
**Core principle:** The vault NEVER exposes key material. It only produces signatures when a request satisfies the configured policies.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 1. Peer Types
|
## 1. Peer Types
|
||||||
|
|||||||
190
LICENSE
@@ -1,190 +0,0 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
Copyright 2026 MarketTakers
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
13
README.md
@@ -1,13 +0,0 @@
|
|||||||
# Arbiter
|
|
||||||
> Policy-first multi-client wallet daemon, allowing permissioned transactions across blockchains
|
|
||||||
|
|
||||||
## Security warning
|
|
||||||
Arbiter can't meaningfully protect against host compromise. Potential attack flow:
|
|
||||||
- Attacker steals TLS keys from database
|
|
||||||
- Pretends to be server; just accepts user agent challenge solutions
|
|
||||||
- Pretend to be in sealed state and performing DH with client
|
|
||||||
- Steals user password and derives seal key
|
|
||||||
|
|
||||||
While this attack is highly targetive, it's still possible.
|
|
||||||
|
|
||||||
> This software is experimental. Do not use with funds you cannot afford to lose.
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
{
|
|
||||||
"configVersion": 2,
|
|
||||||
"packages": [
|
|
||||||
{
|
|
||||||
"name": "async",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/async-2.13.0",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "boolean_selector",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/boolean_selector-2.1.2",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "characters",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/characters-1.4.0",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "clock",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/clock-1.1.2",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "collection",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/collection-1.19.1",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "cupertino_icons",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/cupertino_icons-1.0.8",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fake_async",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/fake_async-1.3.3",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "flutter",
|
|
||||||
"rootUri": "file:///Users/kaska/.local/share/mise/installs/flutter/3.38.9-stable/packages/flutter",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "flutter_lints",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/flutter_lints-6.0.0",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "flutter_test",
|
|
||||||
"rootUri": "file:///Users/kaska/.local/share/mise/installs/flutter/3.38.9-stable/packages/flutter_test",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "leak_tracker",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/leak_tracker-11.0.2",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "leak_tracker_flutter_testing",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/leak_tracker_flutter_testing-3.0.10",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "leak_tracker_testing",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/leak_tracker_testing-3.0.2",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "lints",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/lints-6.1.0",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "matcher",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/matcher-0.12.17",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "material_color_utilities",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/material_color_utilities-0.11.1",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "2.17"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "meta",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/meta-1.17.0",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.5"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "path",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/path-1.9.1",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sky_engine",
|
|
||||||
"rootUri": "file:///Users/kaska/.local/share/mise/installs/flutter/3.38.9-stable/bin/cache/pkg/sky_engine",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "source_span",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/source_span-1.10.2",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stack_trace",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/stack_trace-1.12.1",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stream_channel",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/stream_channel-2.1.4",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "string_scanner",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/string_scanner-1.4.1",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "term_glyph",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/term_glyph-1.2.2",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test_api",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/test_api-0.7.7",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.5"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "vector_math",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/vector_math-2.2.0",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "vm_service",
|
|
||||||
"rootUri": "file:///Users/kaska/.pub-cache/hosted/pub.dev/vm_service-15.0.2",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.5"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "app",
|
|
||||||
"rootUri": "../",
|
|
||||||
"packageUri": "lib/",
|
|
||||||
"languageVersion": "3.10"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"generator": "pub",
|
|
||||||
"generatorVersion": "3.10.8",
|
|
||||||
"flutterRoot": "file:///Users/kaska/.local/share/mise/installs/flutter/3.38.9-stable",
|
|
||||||
"flutterVersion": "3.38.9",
|
|
||||||
"pubCache": "file:///Users/kaska/.pub-cache"
|
|
||||||
}
|
|
||||||
@@ -1,230 +0,0 @@
|
|||||||
{
|
|
||||||
"roots": [
|
|
||||||
"app"
|
|
||||||
],
|
|
||||||
"packages": [
|
|
||||||
{
|
|
||||||
"name": "app",
|
|
||||||
"version": "1.0.0+1",
|
|
||||||
"dependencies": [
|
|
||||||
"cupertino_icons",
|
|
||||||
"flutter"
|
|
||||||
],
|
|
||||||
"devDependencies": [
|
|
||||||
"flutter_lints",
|
|
||||||
"flutter_test"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "flutter_lints",
|
|
||||||
"version": "6.0.0",
|
|
||||||
"dependencies": [
|
|
||||||
"lints"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "flutter_test",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"dependencies": [
|
|
||||||
"clock",
|
|
||||||
"collection",
|
|
||||||
"fake_async",
|
|
||||||
"flutter",
|
|
||||||
"leak_tracker_flutter_testing",
|
|
||||||
"matcher",
|
|
||||||
"meta",
|
|
||||||
"path",
|
|
||||||
"stack_trace",
|
|
||||||
"stream_channel",
|
|
||||||
"test_api",
|
|
||||||
"vector_math"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "cupertino_icons",
|
|
||||||
"version": "1.0.8",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "flutter",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"dependencies": [
|
|
||||||
"characters",
|
|
||||||
"collection",
|
|
||||||
"material_color_utilities",
|
|
||||||
"meta",
|
|
||||||
"sky_engine",
|
|
||||||
"vector_math"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "lints",
|
|
||||||
"version": "6.1.0",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stream_channel",
|
|
||||||
"version": "2.1.4",
|
|
||||||
"dependencies": [
|
|
||||||
"async"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "meta",
|
|
||||||
"version": "1.17.0",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "collection",
|
|
||||||
"version": "1.19.1",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "leak_tracker_flutter_testing",
|
|
||||||
"version": "3.0.10",
|
|
||||||
"dependencies": [
|
|
||||||
"flutter",
|
|
||||||
"leak_tracker",
|
|
||||||
"leak_tracker_testing",
|
|
||||||
"matcher",
|
|
||||||
"meta"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "vector_math",
|
|
||||||
"version": "2.2.0",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stack_trace",
|
|
||||||
"version": "1.12.1",
|
|
||||||
"dependencies": [
|
|
||||||
"path"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "clock",
|
|
||||||
"version": "1.1.2",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fake_async",
|
|
||||||
"version": "1.3.3",
|
|
||||||
"dependencies": [
|
|
||||||
"clock",
|
|
||||||
"collection"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "path",
|
|
||||||
"version": "1.9.1",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "matcher",
|
|
||||||
"version": "0.12.17",
|
|
||||||
"dependencies": [
|
|
||||||
"async",
|
|
||||||
"meta",
|
|
||||||
"stack_trace",
|
|
||||||
"term_glyph",
|
|
||||||
"test_api"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test_api",
|
|
||||||
"version": "0.7.7",
|
|
||||||
"dependencies": [
|
|
||||||
"async",
|
|
||||||
"boolean_selector",
|
|
||||||
"collection",
|
|
||||||
"meta",
|
|
||||||
"source_span",
|
|
||||||
"stack_trace",
|
|
||||||
"stream_channel",
|
|
||||||
"string_scanner",
|
|
||||||
"term_glyph"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sky_engine",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "material_color_utilities",
|
|
||||||
"version": "0.11.1",
|
|
||||||
"dependencies": [
|
|
||||||
"collection"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "characters",
|
|
||||||
"version": "1.4.0",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "async",
|
|
||||||
"version": "2.13.0",
|
|
||||||
"dependencies": [
|
|
||||||
"collection",
|
|
||||||
"meta"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "leak_tracker_testing",
|
|
||||||
"version": "3.0.2",
|
|
||||||
"dependencies": [
|
|
||||||
"leak_tracker",
|
|
||||||
"matcher",
|
|
||||||
"meta"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "leak_tracker",
|
|
||||||
"version": "11.0.2",
|
|
||||||
"dependencies": [
|
|
||||||
"clock",
|
|
||||||
"collection",
|
|
||||||
"meta",
|
|
||||||
"path",
|
|
||||||
"vm_service"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "term_glyph",
|
|
||||||
"version": "1.2.2",
|
|
||||||
"dependencies": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "string_scanner",
|
|
||||||
"version": "1.4.1",
|
|
||||||
"dependencies": [
|
|
||||||
"source_span"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "source_span",
|
|
||||||
"version": "1.10.2",
|
|
||||||
"dependencies": [
|
|
||||||
"collection",
|
|
||||||
"path",
|
|
||||||
"term_glyph"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "boolean_selector",
|
|
||||||
"version": "2.1.2",
|
|
||||||
"dependencies": [
|
|
||||||
"source_span",
|
|
||||||
"string_scanner"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "vm_service",
|
|
||||||
"version": "15.0.2",
|
|
||||||
"dependencies": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"configVersion": 1
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
3.38.9
|
|
||||||
0
useragent/.gitignore → app/.gitignore
vendored
@@ -1,11 +0,0 @@
|
|||||||
// This is a generated file; do not edit or check into version control.
|
|
||||||
FLUTTER_ROOT=/Users/kaska/.local/share/mise/installs/flutter/3.38.9-stable
|
|
||||||
FLUTTER_APPLICATION_PATH=/Users/kaska/Documents/Projects/Major/arbiter/app
|
|
||||||
COCOAPODS_PARALLEL_CODE_SIGN=true
|
|
||||||
FLUTTER_BUILD_DIR=build
|
|
||||||
FLUTTER_BUILD_NAME=1.0.0
|
|
||||||
FLUTTER_BUILD_NUMBER=1
|
|
||||||
DART_OBFUSCATION=false
|
|
||||||
TRACK_WIDGET_CREATION=true
|
|
||||||
TREE_SHAKE_ICONS=false
|
|
||||||
PACKAGE_CONFIG=.dart_tool/package_config.json
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# This is a generated file; do not edit or check into version control.
|
|
||||||
export "FLUTTER_ROOT=/Users/kaska/.local/share/mise/installs/flutter/3.38.9-stable"
|
|
||||||
export "FLUTTER_APPLICATION_PATH=/Users/kaska/Documents/Projects/Major/arbiter/app"
|
|
||||||
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
|
|
||||||
export "FLUTTER_BUILD_DIR=build"
|
|
||||||
export "FLUTTER_BUILD_NAME=1.0.0"
|
|
||||||
export "FLUTTER_BUILD_NUMBER=1"
|
|
||||||
export "DART_OBFUSCATION=false"
|
|
||||||
export "TRACK_WIDGET_CREATION=true"
|
|
||||||
export "TREE_SHAKE_ICONS=false"
|
|
||||||
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
|
|
||||||
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 520 B |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
@@ -41,6 +41,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.19.1"
|
version: "1.19.1"
|
||||||
|
cupertino_icons:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: cupertino_icons
|
||||||
|
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.8"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
89
app/pubspec.yaml
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
name: app
|
||||||
|
description: "A new Flutter project."
|
||||||
|
# The following line prevents the package from being accidentally published to
|
||||||
|
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||||
|
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
|
# The following defines the version and build number for your application.
|
||||||
|
# A version number is three numbers separated by dots, like 1.2.43
|
||||||
|
# followed by an optional build number separated by a +.
|
||||||
|
# Both the version and the builder number may be overridden in flutter
|
||||||
|
# build by specifying --build-name and --build-number, respectively.
|
||||||
|
# In Android, build-name is used as versionName while build-number used as versionCode.
|
||||||
|
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
|
||||||
|
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
|
||||||
|
# Read more about iOS versioning at
|
||||||
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
|
version: 1.0.0+1
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: ^3.10.8
|
||||||
|
|
||||||
|
# Dependencies specify other packages that your package needs in order to work.
|
||||||
|
# To automatically upgrade your package dependencies to the latest versions
|
||||||
|
# consider running `flutter pub upgrade --major-versions`. Alternatively,
|
||||||
|
# dependencies can be manually updated by changing the version numbers below to
|
||||||
|
# the latest version available on pub.dev. To see which dependencies have newer
|
||||||
|
# versions available, run `flutter pub outdated`.
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
|
# The following adds the Cupertino Icons font to your application.
|
||||||
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
|
cupertino_icons: ^1.0.8
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
flutter_test:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
|
# The "flutter_lints" package below contains a set of recommended lints to
|
||||||
|
# encourage good coding practices. The lint set provided by the package is
|
||||||
|
# activated in the `analysis_options.yaml` file located at the root of your
|
||||||
|
# package. See that file for information about deactivating specific lint
|
||||||
|
# rules and activating additional ones.
|
||||||
|
flutter_lints: ^6.0.0
|
||||||
|
|
||||||
|
# For information on the generic Dart part of this file, see the
|
||||||
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
||||||
|
# The following section is specific to Flutter packages.
|
||||||
|
flutter:
|
||||||
|
|
||||||
|
# The following line ensures that the Material Icons font is
|
||||||
|
# included with your application, so that you can use the icons in
|
||||||
|
# the material Icons class.
|
||||||
|
uses-material-design: true
|
||||||
|
|
||||||
|
# To add assets to your application, add an assets section, like this:
|
||||||
|
# assets:
|
||||||
|
# - images/a_dot_burr.jpeg
|
||||||
|
# - images/a_dot_ham.jpeg
|
||||||
|
|
||||||
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
|
# https://flutter.dev/to/resolution-aware-images
|
||||||
|
|
||||||
|
# For details regarding adding assets from package dependencies, see
|
||||||
|
# https://flutter.dev/to/asset-from-package
|
||||||
|
|
||||||
|
# To add custom fonts to your application, add a fonts section here,
|
||||||
|
# in this "flutter" section. Each entry in this list should have a
|
||||||
|
# "family" key with the font family name, and a "fonts" key with a
|
||||||
|
# list giving the asset and other descriptors for the font. For
|
||||||
|
# example:
|
||||||
|
# fonts:
|
||||||
|
# - family: Schyler
|
||||||
|
# fonts:
|
||||||
|
# - asset: fonts/Schyler-Regular.ttf
|
||||||
|
# - asset: fonts/Schyler-Italic.ttf
|
||||||
|
# style: italic
|
||||||
|
# - family: Trajan Pro
|
||||||
|
# fonts:
|
||||||
|
# - asset: fonts/TrajanPro.ttf
|
||||||
|
# - asset: fonts/TrajanPro_Bold.ttf
|
||||||
|
# weight: 700
|
||||||
|
#
|
||||||
|
# For details regarding fonts from package dependencies,
|
||||||
|
# see https://flutter.dev/to/font-from-package
|
||||||
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
@@ -10,10 +10,6 @@ backend = "cargo:cargo-features"
|
|||||||
version = "0.11.1"
|
version = "0.11.1"
|
||||||
backend = "cargo:cargo-features-manager"
|
backend = "cargo:cargo-features-manager"
|
||||||
|
|
||||||
[[tools."cargo:cargo-insta"]]
|
|
||||||
version = "1.46.3"
|
|
||||||
backend = "cargo:cargo-insta"
|
|
||||||
|
|
||||||
[[tools."cargo:cargo-nextest"]]
|
[[tools."cargo:cargo-nextest"]]
|
||||||
version = "0.9.126"
|
version = "0.9.126"
|
||||||
backend = "cargo:cargo-nextest"
|
backend = "cargo:cargo-nextest"
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
"cargo:diesel_cli" = { version = "2.3.6", features = "sqlite,sqlite-bundled", default-features = false }
|
"cargo:diesel_cli" = { version = "2.3.6", features = "sqlite,sqlite-bundled", default-features = false }
|
||||||
"cargo:cargo-audit" = "0.22.1"
|
"cargo:cargo-audit" = "0.22.1"
|
||||||
"cargo:cargo-vet" = "0.10.2"
|
"cargo:cargo-vet" = "0.10.2"
|
||||||
|
|
||||||
flutter = "3.38.9-stable"
|
flutter = "3.38.9-stable"
|
||||||
protoc = "29.6"
|
protoc = "29.6"
|
||||||
"rust" = {version = "1.93.0", components = "clippy"}
|
rust = "1.93.1"
|
||||||
"cargo:cargo-features-manager" = "0.11.1"
|
"cargo:cargo-features-manager" = "0.11.1"
|
||||||
"cargo:cargo-nextest" = "0.9.126"
|
"cargo:cargo-nextest" = "0.9.126"
|
||||||
"cargo:cargo-shear" = "latest"
|
"cargo:cargo-shear" = "latest"
|
||||||
"cargo:cargo-insta" = "1.46.3"
|
|
||||||
|
|||||||
@@ -3,14 +3,111 @@ syntax = "proto3";
|
|||||||
package arbiter;
|
package arbiter;
|
||||||
|
|
||||||
import "auth.proto";
|
import "auth.proto";
|
||||||
import "client.proto";
|
|
||||||
import "user_agent.proto";
|
message ClientRequest {
|
||||||
|
oneof payload {
|
||||||
|
arbiter.auth.ClientMessage auth_message = 1;
|
||||||
|
CertRotationAck cert_rotation_ack = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message ClientResponse {
|
||||||
|
oneof payload {
|
||||||
|
arbiter.auth.ServerMessage auth_message = 1;
|
||||||
|
CertRotationNotification cert_rotation_notification = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message UserAgentRequest {
|
||||||
|
oneof payload {
|
||||||
|
arbiter.auth.ClientMessage auth_message = 1;
|
||||||
|
CertRotationAck cert_rotation_ack = 2;
|
||||||
|
UnsealRequest unseal_request = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message UserAgentResponse {
|
||||||
|
oneof payload {
|
||||||
|
arbiter.auth.ServerMessage auth_message = 1;
|
||||||
|
CertRotationNotification cert_rotation_notification = 2;
|
||||||
|
UnsealResponse unseal_response = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message ServerInfo {
|
message ServerInfo {
|
||||||
string version = 1;
|
string version = 1;
|
||||||
bytes cert_public_key = 2;
|
bytes cert_public_key = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TLS Certificate Rotation Protocol
|
||||||
|
message CertRotationNotification {
|
||||||
|
// New public certificate (DER-encoded)
|
||||||
|
bytes new_cert = 1;
|
||||||
|
|
||||||
|
// Unix timestamp when rotation will be executed (if all ACKs received)
|
||||||
|
int64 rotation_scheduled_at = 2;
|
||||||
|
|
||||||
|
// Unix timestamp deadline for ACK (7 days from now)
|
||||||
|
int64 ack_deadline = 3;
|
||||||
|
|
||||||
|
// Rotation ID for tracking
|
||||||
|
int32 rotation_id = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CertRotationAck {
|
||||||
|
// Rotation ID (from CertRotationNotification)
|
||||||
|
int32 rotation_id = 1;
|
||||||
|
|
||||||
|
// Client public key for identification
|
||||||
|
bytes client_public_key = 2;
|
||||||
|
|
||||||
|
// Confirmation that client saved the new certificate
|
||||||
|
bool cert_saved = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vault Unseal Protocol (X25519 ECDH + ChaCha20Poly1305)
|
||||||
|
message UnsealRequest {
|
||||||
|
oneof payload {
|
||||||
|
EphemeralKeyRequest ephemeral_key_request = 1;
|
||||||
|
SealedPassword sealed_password = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message UnsealResponse {
|
||||||
|
oneof payload {
|
||||||
|
EphemeralKeyResponse ephemeral_key_response = 1;
|
||||||
|
UnsealResult unseal_result = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message EphemeralKeyRequest {}
|
||||||
|
|
||||||
|
message EphemeralKeyResponse {
|
||||||
|
// Server's X25519 ephemeral public key (32 bytes)
|
||||||
|
bytes server_pubkey = 1;
|
||||||
|
|
||||||
|
// Unix timestamp when this key expires (60 seconds from generation)
|
||||||
|
int64 expires_at = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SealedPassword {
|
||||||
|
// Client's X25519 ephemeral public key (32 bytes)
|
||||||
|
bytes client_pubkey = 1;
|
||||||
|
|
||||||
|
// ChaCha20Poly1305 encrypted password (ciphertext + tag)
|
||||||
|
bytes encrypted_password = 2;
|
||||||
|
|
||||||
|
// 12-byte nonce for ChaCha20Poly1305
|
||||||
|
bytes nonce = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UnsealResult {
|
||||||
|
// Whether unseal was successful
|
||||||
|
bool success = 1;
|
||||||
|
|
||||||
|
// Error message if unseal failed
|
||||||
|
optional string error_message = 2;
|
||||||
|
}
|
||||||
|
|
||||||
service ArbiterService {
|
service ArbiterService {
|
||||||
rpc Client(stream ClientRequest) returns (stream ClientResponse);
|
rpc Client(stream ClientRequest) returns (stream ClientResponse);
|
||||||
rpc UserAgent(stream UserAgentRequest) returns (stream UserAgentResponse);
|
rpc UserAgent(stream UserAgentRequest) returns (stream UserAgentResponse);
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package arbiter;
|
|
||||||
|
|
||||||
import "auth.proto";
|
|
||||||
|
|
||||||
message ClientRequest {
|
|
||||||
oneof payload {
|
|
||||||
arbiter.auth.ClientMessage auth_message = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
message ClientResponse {
|
|
||||||
oneof payload {
|
|
||||||
arbiter.auth.ServerMessage auth_message = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
46
protobufs/google/protobuf/timestamp.proto
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// Protocol Buffers - Google's data interchange format
|
||||||
|
// Copyright 2008 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following disclaimer
|
||||||
|
// in the documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
// * Neither the name of Google Inc. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package google.protobuf;
|
||||||
|
|
||||||
|
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
||||||
|
option cc_enable_arenas = true;
|
||||||
|
option go_package = "google.golang.org/protobuf/types/known/timestamppb";
|
||||||
|
option java_package = "com.google.protobuf";
|
||||||
|
option java_outer_classname = "TimestampProto";
|
||||||
|
option java_multiple_files = true;
|
||||||
|
option objc_class_prefix = "GPB";
|
||||||
|
|
||||||
|
// A Timestamp represents a point in time independent of any time zone or local
|
||||||
|
// calendar, encoded as a count of seconds and fractions of seconds at
|
||||||
|
// nanosecond resolution. The count is relative to an epoch at UTC midnight on
|
||||||
|
// January 1, 1970, in the proleptic Gregorian calendar which extends the
|
||||||
|
// Gregorian calendar backwards to year one.
|
||||||
|
message Timestamp {
|
||||||
|
// Represents seconds of UTC time since Unix epoch
|
||||||
|
// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
|
||||||
|
// 9999-12-31T23:59:59Z inclusive.
|
||||||
|
int64 seconds = 1;
|
||||||
|
|
||||||
|
// Non-negative fractions of a second at nanosecond resolution. Negative
|
||||||
|
// second values with fractions must still have non-negative nanos values
|
||||||
|
// that count forward in time. Must be from 0 to 999,999,999
|
||||||
|
// inclusive.
|
||||||
|
int32 nanos = 2;
|
||||||
|
}
|
||||||
14
protobufs/unseal.proto
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package arbiter.unseal;
|
||||||
|
|
||||||
|
message UserAgentKeyRequest {}
|
||||||
|
|
||||||
|
message ServerKeyResponse {
|
||||||
|
bytes pubkey = 1;
|
||||||
|
}
|
||||||
|
message UserAgentSealedKey {
|
||||||
|
bytes sealed_key = 1;
|
||||||
|
bytes pubkey = 2;
|
||||||
|
bytes nonce = 3;
|
||||||
|
}
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package arbiter;
|
|
||||||
|
|
||||||
import "auth.proto";
|
|
||||||
import "google/protobuf/empty.proto";
|
|
||||||
|
|
||||||
message UnsealStart {
|
|
||||||
bytes client_pubkey = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UnsealStartResponse {
|
|
||||||
bytes server_pubkey = 1;
|
|
||||||
}
|
|
||||||
message UnsealEncryptedKey {
|
|
||||||
bytes nonce = 1;
|
|
||||||
bytes ciphertext = 2;
|
|
||||||
bytes associated_data = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum UnsealResult {
|
|
||||||
UNSEAL_RESULT_UNSPECIFIED = 0;
|
|
||||||
UNSEAL_RESULT_SUCCESS = 1;
|
|
||||||
UNSEAL_RESULT_INVALID_KEY = 2;
|
|
||||||
UNSEAL_RESULT_UNBOOTSTRAPPED = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum VaultState {
|
|
||||||
VAULT_STATE_UNSPECIFIED = 0;
|
|
||||||
VAULT_STATE_UNBOOTSTRAPPED = 1;
|
|
||||||
VAULT_STATE_SEALED = 2;
|
|
||||||
VAULT_STATE_UNSEALED = 3;
|
|
||||||
VAULT_STATE_ERROR = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UserAgentRequest {
|
|
||||||
oneof payload {
|
|
||||||
arbiter.auth.ClientMessage auth_message = 1;
|
|
||||||
UnsealStart unseal_start = 2;
|
|
||||||
UnsealEncryptedKey unseal_encrypted_key = 3;
|
|
||||||
google.protobuf.Empty query_vault_state = 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
message UserAgentResponse {
|
|
||||||
oneof payload {
|
|
||||||
arbiter.auth.ServerMessage auth_message = 1;
|
|
||||||
UnsealStartResponse unseal_start_response = 2;
|
|
||||||
UnsealResult unseal_result = 3;
|
|
||||||
VaultState vault_state = 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
551
server/Cargo.lock
generated
@@ -59,22 +59,16 @@ version = "0.1.0"
|
|||||||
name = "arbiter-proto"
|
name = "arbiter-proto"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
|
||||||
"futures",
|
"futures",
|
||||||
|
"hex",
|
||||||
"kameo",
|
"kameo",
|
||||||
"miette",
|
|
||||||
"prost",
|
"prost",
|
||||||
"rand",
|
"prost-build",
|
||||||
"rcgen",
|
"serde_json",
|
||||||
"rstest",
|
|
||||||
"rustls-pki-types",
|
|
||||||
"thiserror",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tonic",
|
"tonic",
|
||||||
"tonic-prost",
|
"tonic-prost",
|
||||||
"tonic-prost-build",
|
"tonic-prost-build",
|
||||||
"tracing",
|
|
||||||
"url",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -92,25 +86,21 @@ dependencies = [
|
|||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
"futures",
|
"futures",
|
||||||
"insta",
|
"hex",
|
||||||
"kameo",
|
"kameo",
|
||||||
"memsafe",
|
"memsafe",
|
||||||
"miette",
|
"miette",
|
||||||
"pem",
|
|
||||||
"rand",
|
"rand",
|
||||||
"rcgen",
|
"rcgen",
|
||||||
"restructed",
|
|
||||||
"rustls",
|
"rustls",
|
||||||
"secrecy",
|
"secrecy",
|
||||||
"smlang",
|
"smlang",
|
||||||
"strum",
|
|
||||||
"test-log",
|
"test-log",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tonic",
|
"tonic",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
|
||||||
"x25519-dalek",
|
"x25519-dalek",
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
@@ -118,16 +108,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "arbiter-useragent"
|
name = "arbiter-useragent"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
|
||||||
"arbiter-proto",
|
|
||||||
"ed25519-dalek",
|
|
||||||
"kameo",
|
|
||||||
"smlang",
|
|
||||||
"tokio",
|
|
||||||
"tonic",
|
|
||||||
"tracing",
|
|
||||||
"x25519-dalek",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "argon2"
|
name = "argon2"
|
||||||
@@ -139,7 +119,6 @@ dependencies = [
|
|||||||
"blake2",
|
"blake2",
|
||||||
"cpufeatures 0.2.17",
|
"cpufeatures 0.2.17",
|
||||||
"password-hash",
|
"password-hash",
|
||||||
"zeroize",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -166,7 +145,7 @@ checksum = "3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -178,7 +157,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -189,7 +168,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -450,18 +429,6 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "console"
|
|
||||||
version = "0.15.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
|
|
||||||
dependencies = [
|
|
||||||
"encode_unicode",
|
|
||||||
"libc",
|
|
||||||
"once_cell",
|
|
||||||
"windows-sys 0.59.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation-sys"
|
name = "core-foundation-sys"
|
||||||
version = "0.8.7"
|
version = "0.8.7"
|
||||||
@@ -560,7 +527,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -584,7 +551,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"strsim",
|
"strsim",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -595,7 +562,7 @@ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core",
|
"darling_core",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -682,7 +649,7 @@ dependencies = [
|
|||||||
"dsl_auto_type",
|
"dsl_auto_type",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -702,7 +669,7 @@ version = "0.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fe2444076b48641147115697648dc743c2c00b61adade0f01ce67133c7babe8c"
|
checksum = "fe2444076b48641147115697648dc743c2c00b61adade0f01ce67133c7babe8c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -734,7 +701,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -754,7 +721,7 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -798,12 +765,6 @@ version = "1.15.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "encode_unicode"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@@ -878,15 +839,6 @@ version = "0.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "form_urlencoded"
|
|
||||||
version = "1.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
|
|
||||||
dependencies = [
|
|
||||||
"percent-encoding",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fs_extra"
|
name = "fs_extra"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
@@ -949,7 +901,7 @@ checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -964,12 +916,6 @@ version = "0.3.32"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
|
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-timer"
|
|
||||||
version = "3.0.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-util"
|
name = "futures-util"
|
||||||
version = "0.3.32"
|
version = "0.3.32"
|
||||||
@@ -1040,12 +986,6 @@ version = "0.32.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
|
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glob"
|
|
||||||
version = "0.3.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.4.13"
|
version = "0.4.13"
|
||||||
@@ -1095,6 +1035,12 @@ version = "0.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@@ -1229,87 +1175,6 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icu_collections"
|
|
||||||
version = "2.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43"
|
|
||||||
dependencies = [
|
|
||||||
"displaydoc",
|
|
||||||
"potential_utf",
|
|
||||||
"yoke",
|
|
||||||
"zerofrom",
|
|
||||||
"zerovec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icu_locale_core"
|
|
||||||
version = "2.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6"
|
|
||||||
dependencies = [
|
|
||||||
"displaydoc",
|
|
||||||
"litemap",
|
|
||||||
"tinystr",
|
|
||||||
"writeable",
|
|
||||||
"zerovec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icu_normalizer"
|
|
||||||
version = "2.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599"
|
|
||||||
dependencies = [
|
|
||||||
"icu_collections",
|
|
||||||
"icu_normalizer_data",
|
|
||||||
"icu_properties",
|
|
||||||
"icu_provider",
|
|
||||||
"smallvec",
|
|
||||||
"zerovec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icu_normalizer_data"
|
|
||||||
version = "2.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icu_properties"
|
|
||||||
version = "2.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec"
|
|
||||||
dependencies = [
|
|
||||||
"icu_collections",
|
|
||||||
"icu_locale_core",
|
|
||||||
"icu_properties_data",
|
|
||||||
"icu_provider",
|
|
||||||
"zerotrie",
|
|
||||||
"zerovec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icu_properties_data"
|
|
||||||
version = "2.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "icu_provider"
|
|
||||||
version = "2.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614"
|
|
||||||
dependencies = [
|
|
||||||
"displaydoc",
|
|
||||||
"icu_locale_core",
|
|
||||||
"writeable",
|
|
||||||
"yoke",
|
|
||||||
"zerofrom",
|
|
||||||
"zerotrie",
|
|
||||||
"zerovec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "id-arena"
|
name = "id-arena"
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
@@ -1322,27 +1187,6 @@ version = "1.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "idna"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
|
|
||||||
dependencies = [
|
|
||||||
"idna_adapter",
|
|
||||||
"smallvec",
|
|
||||||
"utf8_iter",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "idna_adapter"
|
|
||||||
version = "1.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344"
|
|
||||||
dependencies = [
|
|
||||||
"icu_normalizer",
|
|
||||||
"icu_properties",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.13.0"
|
version = "2.13.0"
|
||||||
@@ -1364,18 +1208,6 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "insta"
|
|
||||||
version = "1.46.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e82db8c87c7f1ccecb34ce0c24399b8a73081427f3c7c50a5d597925356115e4"
|
|
||||||
dependencies = [
|
|
||||||
"console",
|
|
||||||
"once_cell",
|
|
||||||
"similar",
|
|
||||||
"tempfile",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is_ci"
|
name = "is_ci"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -1441,7 +1273,7 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1478,12 +1310,6 @@ version = "0.11.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
|
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "litemap"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.14"
|
version = "0.4.14"
|
||||||
@@ -1558,7 +1384,7 @@ checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1631,15 +1457,6 @@ dependencies = [
|
|||||||
"minimal-lexical",
|
"minimal-lexical",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nu-ansi-term"
|
|
||||||
version = "0.50.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
|
||||||
dependencies = [
|
|
||||||
"windows-sys 0.61.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-bigint"
|
name = "num-bigint"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -1788,7 +1605,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1826,15 +1643,6 @@ version = "1.13.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "potential_utf"
|
|
||||||
version = "0.1.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77"
|
|
||||||
dependencies = [
|
|
||||||
"zerovec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "powerfmt"
|
name = "powerfmt"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -1848,40 +1656,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-crate"
|
|
||||||
version = "3.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983"
|
|
||||||
dependencies = [
|
|
||||||
"toml_edit",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1920,7 +1695,7 @@ dependencies = [
|
|||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
"pulldown-cmark-to-cmark",
|
"pulldown-cmark-to-cmark",
|
||||||
"regex",
|
"regex",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1934,7 +1709,7 @@ dependencies = [
|
|||||||
"itertools",
|
"itertools",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2060,24 +1835,6 @@ version = "0.8.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c"
|
checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "relative-path"
|
|
||||||
version = "1.9.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "restructed"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8f6f6e863d7d9d318699737c043d560dce1ea3cb6f5c78e0a3f0d1f257c73dfc"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.115",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ring"
|
name = "ring"
|
||||||
version = "0.17.14"
|
version = "0.17.14"
|
||||||
@@ -2102,35 +1859,6 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rstest"
|
|
||||||
version = "0.26.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f5a3193c063baaa2a95a33f03035c8a72b83d97a54916055ba22d35ed3839d49"
|
|
||||||
dependencies = [
|
|
||||||
"futures-timer",
|
|
||||||
"futures-util",
|
|
||||||
"rstest_macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rstest_macros"
|
|
||||||
version = "0.26.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9c845311f0ff7951c5506121a9ad75aec44d083c31583b2ea5a30bcb0b0abba0"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"glob",
|
|
||||||
"proc-macro-crate",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"regex",
|
|
||||||
"relative-path",
|
|
||||||
"rustc_version",
|
|
||||||
"syn 2.0.115",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.27"
|
version = "0.1.27"
|
||||||
@@ -2267,7 +1995,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2340,12 +2068,6 @@ version = "0.3.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2"
|
checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "similar"
|
|
||||||
version = "2.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.12"
|
version = "0.4.12"
|
||||||
@@ -2401,12 +2123,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "stable_deref_trait"
|
|
||||||
version = "1.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "string_morph"
|
name = "string_morph"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -2419,27 +2135,6 @@ version = "0.11.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strum"
|
|
||||||
version = "0.27.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf"
|
|
||||||
dependencies = [
|
|
||||||
"strum_macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strum_macros"
|
|
||||||
version = "0.27.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.115",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "subtle"
|
name = "subtle"
|
||||||
version = "2.6.1"
|
version = "2.6.1"
|
||||||
@@ -2480,9 +2175,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.115"
|
version = "2.0.116"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6e614ed320ac28113fa64972c4262d5dbc89deacdfd00c34a3e4cea073243c12"
|
checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -2503,7 +2198,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2547,7 +2242,7 @@ checksum = "be35209fd0781c5401458ab66e4f98accf63553e8fae7425503e92fdd319783b"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2577,7 +2272,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2620,16 +2315,6 @@ dependencies = [
|
|||||||
"time-core",
|
"time-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tinystr"
|
|
||||||
version = "0.8.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869"
|
|
||||||
dependencies = [
|
|
||||||
"displaydoc",
|
|
||||||
"zerovec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.49.0"
|
version = "1.49.0"
|
||||||
@@ -2656,7 +2341,7 @@ checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2716,18 +2401,6 @@ dependencies = [
|
|||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml_edit"
|
|
||||||
version = "0.23.10+spec-1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269"
|
|
||||||
dependencies = [
|
|
||||||
"indexmap",
|
|
||||||
"toml_datetime",
|
|
||||||
"toml_parser",
|
|
||||||
"winnow",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_parser"
|
name = "toml_parser"
|
||||||
version = "1.0.8+spec-1.1.0"
|
version = "1.0.8+spec-1.1.0"
|
||||||
@@ -2778,7 +2451,7 @@ dependencies = [
|
|||||||
"prettyplease",
|
"prettyplease",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2803,7 +2476,7 @@ dependencies = [
|
|||||||
"prost-build",
|
"prost-build",
|
||||||
"prost-types",
|
"prost-types",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tonic-build",
|
"tonic-build",
|
||||||
]
|
]
|
||||||
@@ -2858,7 +2531,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2868,18 +2541,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"valuable",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-log"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
|
||||||
dependencies = [
|
|
||||||
"log",
|
|
||||||
"once_cell",
|
|
||||||
"tracing-core",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2889,15 +2550,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
|
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"matchers",
|
"matchers",
|
||||||
"nu-ansi-term",
|
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"regex-automata",
|
"regex-automata",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"smallvec",
|
|
||||||
"thread_local",
|
"thread_local",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
"tracing-log",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2920,9 +2578,9 @@ checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.23"
|
version = "1.0.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-linebreak"
|
name = "unicode-linebreak"
|
||||||
@@ -2970,24 +2628,6 @@ version = "0.9.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "url"
|
|
||||||
version = "2.5.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
|
|
||||||
dependencies = [
|
|
||||||
"form_urlencoded",
|
|
||||||
"idna",
|
|
||||||
"percent-encoding",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "utf8_iter"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.21.0"
|
version = "1.21.0"
|
||||||
@@ -2998,12 +2638,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "valuable"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "vcpkg"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
@@ -3081,7 +2715,7 @@ dependencies = [
|
|||||||
"bumpalo",
|
"bumpalo",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3171,7 +2805,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3182,7 +2816,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3218,15 +2852,6 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-sys"
|
|
||||||
version = "0.59.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
|
||||||
dependencies = [
|
|
||||||
"windows-targets 0.52.6",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.60.2"
|
version = "0.60.2"
|
||||||
@@ -3379,9 +3004,6 @@ name = "winnow"
|
|||||||
version = "0.7.14"
|
version = "0.7.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
|
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wit-bindgen"
|
name = "wit-bindgen"
|
||||||
@@ -3413,7 +3035,7 @@ dependencies = [
|
|||||||
"heck",
|
"heck",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"prettyplease",
|
"prettyplease",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
"wasm-metadata",
|
"wasm-metadata",
|
||||||
"wit-bindgen-core",
|
"wit-bindgen-core",
|
||||||
"wit-component",
|
"wit-component",
|
||||||
@@ -3429,7 +3051,7 @@ dependencies = [
|
|||||||
"prettyplease",
|
"prettyplease",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
"wit-bindgen-core",
|
"wit-bindgen-core",
|
||||||
"wit-bindgen-rust",
|
"wit-bindgen-rust",
|
||||||
]
|
]
|
||||||
@@ -3471,12 +3093,6 @@ dependencies = [
|
|||||||
"wasmparser",
|
"wasmparser",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "writeable"
|
|
||||||
version = "0.6.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "x25519-dalek"
|
name = "x25519-dalek"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
@@ -3516,50 +3132,6 @@ dependencies = [
|
|||||||
"time",
|
"time",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "yoke"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954"
|
|
||||||
dependencies = [
|
|
||||||
"stable_deref_trait",
|
|
||||||
"yoke-derive",
|
|
||||||
"zerofrom",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "yoke-derive"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.115",
|
|
||||||
"synstructure",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerofrom"
|
|
||||||
version = "0.1.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5"
|
|
||||||
dependencies = [
|
|
||||||
"zerofrom-derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerofrom-derive"
|
|
||||||
version = "0.1.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.115",
|
|
||||||
"synstructure",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zeroize"
|
name = "zeroize"
|
||||||
version = "1.8.2"
|
version = "1.8.2"
|
||||||
@@ -3577,40 +3149,7 @@ checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.115",
|
"syn 2.0.116",
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerotrie"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851"
|
|
||||||
dependencies = [
|
|
||||||
"displaydoc",
|
|
||||||
"yoke",
|
|
||||||
"zerofrom",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerovec"
|
|
||||||
version = "0.11.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002"
|
|
||||||
dependencies = [
|
|
||||||
"yoke",
|
|
||||||
"zerofrom",
|
|
||||||
"zerovec-derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zerovec-derive"
|
|
||||||
version = "0.11.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.115",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -23,12 +23,3 @@ async-trait = "0.1.89"
|
|||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
tokio-stream = { version = "0.1.18", features = ["full"] }
|
tokio-stream = { version = "0.1.18", features = ["full"] }
|
||||||
kameo = "0.19.2"
|
kameo = "0.19.2"
|
||||||
x25519-dalek = { version = "2.0.1", features = ["getrandom"] }
|
|
||||||
rstest = "0.26.1"
|
|
||||||
rustls-pki-types = "1.14.0"
|
|
||||||
rcgen = { version = "0.14.7", features = [
|
|
||||||
"aws_lc_rs",
|
|
||||||
"pem",
|
|
||||||
"x509-parser",
|
|
||||||
"zeroize",
|
|
||||||
], default-features = false }
|
|
||||||
|
|||||||
BIN
server/crates/.DS_Store
vendored
@@ -3,6 +3,5 @@ name = "arbiter-client"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
repository = "https://git.markettakers.org/MarketTakers/arbiter"
|
repository = "https://git.markettakers.org/MarketTakers/arbiter"
|
||||||
license = "Apache-2.0"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -3,32 +3,19 @@ name = "arbiter-proto"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
repository = "https://git.markettakers.org/MarketTakers/arbiter"
|
repository = "https://git.markettakers.org/MarketTakers/arbiter"
|
||||||
license = "Apache-2.0"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tonic.workspace = true
|
tonic.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
|
hex = "0.4.3"
|
||||||
tonic-prost = "0.14.3"
|
tonic-prost = "0.14.3"
|
||||||
prost = "0.14.3"
|
prost = "0.14.3"
|
||||||
kameo.workspace = true
|
kameo.workspace = true
|
||||||
url = "2.5.8"
|
|
||||||
miette.workspace = true
|
|
||||||
thiserror.workspace = true
|
|
||||||
rustls-pki-types.workspace = true
|
|
||||||
base64 = "0.22.1"
|
|
||||||
tracing.workspace = true
|
|
||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
prost-build = "0.14.3"
|
||||||
|
serde_json = "1"
|
||||||
tonic-prost-build = "0.14.3"
|
tonic-prost-build = "0.14.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
rstest.workspace = true
|
|
||||||
rand.workspace = true
|
|
||||||
rcgen.workspace = true
|
|
||||||
|
|
||||||
[package.metadata.cargo-shear]
|
|
||||||
ignored = ["tonic-prost", "prost", "kameo"]
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
use tonic_prost_build::configure;
|
|
||||||
|
|
||||||
static PROTOBUF_DIR: &str = "../../../protobufs";
|
static PROTOBUF_DIR: &str = "../../../protobufs";
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let proto_files = vec![
|
||||||
println!("cargo::rerun-if-changed={PROTOBUF_DIR}");
|
|
||||||
|
|
||||||
configure()
|
|
||||||
.message_attribute(".", "#[derive(::kameo::Reply)]")
|
|
||||||
.compile_protos(
|
|
||||||
&[
|
|
||||||
format!("{}/arbiter.proto", PROTOBUF_DIR),
|
format!("{}/arbiter.proto", PROTOBUF_DIR),
|
||||||
format!("{}/auth.proto", PROTOBUF_DIR),
|
format!("{}/auth.proto", PROTOBUF_DIR),
|
||||||
],
|
];
|
||||||
&[PROTOBUF_DIR.to_string()],
|
|
||||||
)
|
// Компилируем protobuf (tonic-prost-build автоматически использует prost_types для google.protobuf)
|
||||||
|
tonic_prost_build::configure()
|
||||||
|
.message_attribute(".", "#[derive(::kameo::Reply)]")
|
||||||
|
.compile_protos(&proto_files, &[PROTOBUF_DIR.to_string()])?;
|
||||||
|
|
||||||
.unwrap();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
pub mod transport;
|
|
||||||
pub mod url;
|
|
||||||
|
|
||||||
use base64::{Engine, prelude::BASE64_STANDARD};
|
|
||||||
|
|
||||||
use crate::proto::auth::AuthChallenge;
|
use crate::proto::auth::AuthChallenge;
|
||||||
|
|
||||||
pub mod proto {
|
pub mod proto {
|
||||||
@@ -13,7 +8,9 @@ pub mod proto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static BOOTSTRAP_PATH: &str = "bootstrap_token";
|
pub mod transport;
|
||||||
|
|
||||||
|
pub static BOOTSTRAP_TOKEN_PATH: &str = "bootstrap_token";
|
||||||
|
|
||||||
pub fn home_path() -> Result<std::path::PathBuf, std::io::Error> {
|
pub fn home_path() -> Result<std::path::PathBuf, std::io::Error> {
|
||||||
static ARBITER_HOME: &str = ".arbiter";
|
static ARBITER_HOME: &str = ".arbiter";
|
||||||
@@ -29,6 +26,6 @@ pub fn home_path() -> Result<std::path::PathBuf, std::io::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_challenge(challenge: &AuthChallenge) -> Vec<u8> {
|
pub fn format_challenge(challenge: &AuthChallenge) -> Vec<u8> {
|
||||||
let concat_form = format!("{}:{}", challenge.nonce, BASE64_STANDARD.encode(&challenge.pubkey));
|
let concat_form = format!("{}:{}", challenge.nonce, hex::encode(&challenge.pubkey));
|
||||||
concat_form.into_bytes().to_vec()
|
concat_form.into_bytes().to_vec()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,75 +1,9 @@
|
|||||||
//! Transport abstraction layer for bridging gRPC bidirectional streaming with kameo actors.
|
|
||||||
//!
|
|
||||||
//! This module provides a clean separation between the gRPC transport layer and business logic
|
|
||||||
//! by modeling the connection as two linked kameo actors:
|
|
||||||
//!
|
|
||||||
//! - A **transport actor** ([`GrpcTransportActor`]) that owns the gRPC stream and channel,
|
|
||||||
//! forwarding inbound messages to the business actor and outbound messages to the client.
|
|
||||||
//! - A **business logic actor** that receives inbound messages from the transport actor and
|
|
||||||
//! sends outbound messages back through the transport actor.
|
|
||||||
//!
|
|
||||||
//! The [`wire()`] function sets up bidirectional linking between the two actors, ensuring
|
|
||||||
//! that if either actor dies, the other is notified and can shut down gracefully.
|
|
||||||
//!
|
|
||||||
//! # Terminology
|
|
||||||
//!
|
|
||||||
//! - **InboundMessage**: a message received by the transport actor from the channel/socket
|
|
||||||
//! and forwarded to the business actor.
|
|
||||||
//! - **OutboundMessage**: a message produced by the business actor and sent to the transport
|
|
||||||
//! actor to be forwarded to the channel/socket.
|
|
||||||
//!
|
|
||||||
//! # Architecture
|
|
||||||
//!
|
|
||||||
//! ```text
|
|
||||||
//! gRPC Stream ──InboundMessage──▶ GrpcTransportActor ──tell(InboundMessage)──▶ BusinessActor
|
|
||||||
//! ▲ │
|
|
||||||
//! └─tell(Result<OutboundMessage, _>)────┘
|
|
||||||
//! │
|
|
||||||
//! mpsc::Sender ──▶ Client
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! # Example
|
|
||||||
//!
|
|
||||||
//! ```rust,ignore
|
|
||||||
//! let (tx, rx) = mpsc::channel(1000);
|
|
||||||
//! let context = server_context.clone();
|
|
||||||
//!
|
|
||||||
//! wire(
|
|
||||||
//! |transport_ref| MyBusinessActor::new(context, transport_ref),
|
|
||||||
//! |business_recipient, business_id| GrpcTransportActor {
|
|
||||||
//! sender: tx,
|
|
||||||
//! receiver: grpc_stream,
|
|
||||||
//! business_logic_actor: business_recipient,
|
|
||||||
//! business_logic_actor_id: business_id,
|
|
||||||
//! },
|
|
||||||
//! ).await;
|
|
||||||
//!
|
|
||||||
//! Ok(Response::new(ReceiverStream::new(rx)))
|
|
||||||
//! ```
|
|
||||||
|
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use kameo::{
|
use tokio::sync::mpsc::{self, error::SendError};
|
||||||
Actor,
|
|
||||||
actor::{ActorRef, PreparedActor, Recipient, Spawn, WeakActorRef},
|
|
||||||
mailbox::Signal,
|
|
||||||
prelude::Message,
|
|
||||||
};
|
|
||||||
use tokio::{
|
|
||||||
select,
|
|
||||||
sync::mpsc::{self, error::SendError},
|
|
||||||
};
|
|
||||||
use tonic::{Status, Streaming};
|
use tonic::{Status, Streaming};
|
||||||
use tracing::{debug, error};
|
|
||||||
|
|
||||||
/// A bidirectional stream abstraction for sans-io testing.
|
|
||||||
///
|
// Abstraction for stream for sans-io capabilities
|
||||||
/// Combines a [`Stream`] of incoming messages with the ability to [`send`](Bi::send)
|
|
||||||
/// outgoing responses. This trait allows business logic to be tested without a real
|
|
||||||
/// gRPC connection by swapping in an in-memory implementation.
|
|
||||||
///
|
|
||||||
/// # Type Parameters
|
|
||||||
/// - `T`: `InboundMessage` received from the channel/socket (e.g., `UserAgentRequest`)
|
|
||||||
/// - `U`: `OutboundMessage` sent to the channel/socket (e.g., `UserAgentResponse`)
|
|
||||||
pub trait Bi<T, U>: Stream<Item = Result<T, Status>> + Send + Sync + 'static {
|
pub trait Bi<T, U>: Stream<Item = Result<T, Status>> + Send + Sync + 'static {
|
||||||
type Error;
|
type Error;
|
||||||
fn send(
|
fn send(
|
||||||
@@ -78,10 +12,7 @@ pub trait Bi<T, U>: Stream<Item = Result<T, Status>> + Send + Sync + 'static {
|
|||||||
) -> impl std::future::Future<Output = Result<(), Self::Error>> + Send;
|
) -> impl std::future::Future<Output = Result<(), Self::Error>> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Concrete [`Bi`] implementation backed by a tonic gRPC [`Streaming`] and an [`mpsc::Sender`].
|
// Bi-directional stream abstraction for handling gRPC streaming requests and responses
|
||||||
///
|
|
||||||
/// This is the production implementation used in gRPC service handlers. The `request_stream`
|
|
||||||
/// receives messages from the client, and `response_sender` sends responses back.
|
|
||||||
pub struct BiStream<T, U> {
|
pub struct BiStream<T, U> {
|
||||||
pub request_stream: Streaming<T>,
|
pub request_stream: Streaming<T>,
|
||||||
pub response_sender: mpsc::Sender<Result<U, Status>>,
|
pub response_sender: mpsc::Sender<Result<U, Status>>,
|
||||||
@@ -113,259 +44,3 @@ where
|
|||||||
self.response_sender.send(item).await
|
self.response_sender.send(item).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marker trait for transport actors that can receive outbound messages of type `T`.
|
|
||||||
///
|
|
||||||
/// Implement this on your transport actor to indicate it can handle outbound messages
|
|
||||||
/// produced by the business actor. Requires the actor to implement [`Message<Result<T, E>>`]
|
|
||||||
/// so business logic can forward responses via [`tell()`](ActorRef::tell).
|
|
||||||
///
|
|
||||||
/// # Example
|
|
||||||
///
|
|
||||||
/// ```rust,ignore
|
|
||||||
/// #[derive(Actor)]
|
|
||||||
/// struct MyTransportActor { /* ... */ }
|
|
||||||
///
|
|
||||||
/// impl Message<Result<MyResponse, MyError>> for MyTransportActor {
|
|
||||||
/// type Reply = ();
|
|
||||||
/// async fn handle(&mut self, msg: Result<MyResponse, MyError>, _ctx: &mut Context<Self, Self::Reply>) -> Self::Reply {
|
|
||||||
/// // forward outbound message to channel/socket
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// impl TransportActor<MyResponse, MyError> for MyTransportActor {}
|
|
||||||
/// ```
|
|
||||||
pub trait TransportActor<Outbound: Send + 'static, DomainError: Send + 'static>:
|
|
||||||
Actor + Send + Message<Result<Outbound, DomainError>>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A kameo actor that bridges a gRPC bidirectional stream with a business logic actor.
|
|
||||||
///
|
|
||||||
/// This actor owns the gRPC [`Streaming`] receiver and an [`mpsc::Sender`] for responses.
|
|
||||||
/// It multiplexes between its own mailbox (for outbound messages from the business actor)
|
|
||||||
/// and the gRPC stream (for inbound client messages) using [`tokio::select!`].
|
|
||||||
///
|
|
||||||
/// # Message Flow
|
|
||||||
///
|
|
||||||
/// - **Inbound**: Messages from the gRPC stream are forwarded to `business_logic_actor`
|
|
||||||
/// via [`tell()`](Recipient::tell).
|
|
||||||
/// - **Outbound**: The business actor sends `Result<Outbound, DomainError>` messages to this
|
|
||||||
/// actor, which forwards them through the `sender` channel to the gRPC response stream.
|
|
||||||
///
|
|
||||||
/// # Lifecycle
|
|
||||||
///
|
|
||||||
/// - If the business logic actor dies (detected via actor linking), this actor stops,
|
|
||||||
/// which closes the gRPC stream.
|
|
||||||
/// - If the gRPC stream closes or errors, this actor stops, which (via linking) notifies
|
|
||||||
/// the business actor.
|
|
||||||
/// - Error responses (`Err(DomainError)`) are forwarded to the client and then the actor stops,
|
|
||||||
/// closing the connection.
|
|
||||||
///
|
|
||||||
/// # Type Parameters
|
|
||||||
/// - `Outbound`: `OutboundMessage` sent to the client (e.g., `UserAgentResponse`)
|
|
||||||
/// - `Inbound`: `InboundMessage` received from the client (e.g., `UserAgentRequest`)
|
|
||||||
/// - `E`: The domain error type, must implement `Into<tonic::Status>` for gRPC conversion
|
|
||||||
pub struct GrpcTransportActor<Outbound, Inbound, DomainError>
|
|
||||||
where
|
|
||||||
Outbound: Send + 'static,
|
|
||||||
Inbound: Send + 'static,
|
|
||||||
DomainError: Into<tonic::Status> + Send + 'static,
|
|
||||||
{
|
|
||||||
sender: mpsc::Sender<Result<Outbound, tonic::Status>>,
|
|
||||||
receiver: tonic::Streaming<Inbound>,
|
|
||||||
business_logic_actor: Recipient<Inbound>,
|
|
||||||
_error: std::marker::PhantomData<DomainError>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Outbound, Inbound, DomainError> GrpcTransportActor<Outbound, Inbound, DomainError>
|
|
||||||
where
|
|
||||||
Outbound: Send + 'static,
|
|
||||||
Inbound: Send + 'static,
|
|
||||||
DomainError: Into<tonic::Status> + Send + 'static,
|
|
||||||
{
|
|
||||||
pub fn new(
|
|
||||||
sender: mpsc::Sender<Result<Outbound, tonic::Status>>,
|
|
||||||
receiver: tonic::Streaming<Inbound>,
|
|
||||||
business_logic_actor: Recipient<Inbound>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
sender,
|
|
||||||
receiver,
|
|
||||||
business_logic_actor,
|
|
||||||
_error: std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Outbound, Inbound, E> Actor for GrpcTransportActor<Outbound, Inbound, E>
|
|
||||||
where
|
|
||||||
Outbound: Send + 'static,
|
|
||||||
Inbound: Send + 'static,
|
|
||||||
E: Into<tonic::Status> + Send + 'static,
|
|
||||||
{
|
|
||||||
type Args = Self;
|
|
||||||
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
async fn on_start(args: Self::Args, _: ActorRef<Self>) -> Result<Self, Self::Error> {
|
|
||||||
Ok(args)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_link_died(
|
|
||||||
&mut self,
|
|
||||||
_: WeakActorRef<Self>,
|
|
||||||
id: kameo::prelude::ActorId,
|
|
||||||
_: kameo::prelude::ActorStopReason,
|
|
||||||
) -> impl Future<
|
|
||||||
Output = Result<std::ops::ControlFlow<kameo::prelude::ActorStopReason>, Self::Error>,
|
|
||||||
> + Send {
|
|
||||||
async move {
|
|
||||||
if id == self.business_logic_actor.id() {
|
|
||||||
error!("Business logic actor died, stopping GrpcTransportActor");
|
|
||||||
Ok(std::ops::ControlFlow::Break(
|
|
||||||
kameo::prelude::ActorStopReason::Normal,
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
debug!(
|
|
||||||
"Linked actor {} died, but it's not the business logic actor, ignoring",
|
|
||||||
id
|
|
||||||
);
|
|
||||||
Ok(std::ops::ControlFlow::Continue(()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn next(
|
|
||||||
&mut self,
|
|
||||||
_: WeakActorRef<Self>,
|
|
||||||
mailbox_rx: &mut kameo::prelude::MailboxReceiver<Self>,
|
|
||||||
) -> Option<kameo::mailbox::Signal<Self>> {
|
|
||||||
select! {
|
|
||||||
msg = mailbox_rx.recv() => {
|
|
||||||
msg
|
|
||||||
}
|
|
||||||
recv_msg = self.receiver.next() => {
|
|
||||||
match recv_msg {
|
|
||||||
Some(Ok(msg)) => {
|
|
||||||
match self.business_logic_actor.tell(msg).await {
|
|
||||||
Ok(_) => None,
|
|
||||||
Err(e) => {
|
|
||||||
// TODO: this would probably require better error handling - or resending if backpressure is the issue
|
|
||||||
error!("Failed to send message to business logic actor: {}", e);
|
|
||||||
Some(Signal::Stop)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(Err(e)) => {
|
|
||||||
error!("Received error from stream: {}, stopping GrpcTransportActor", e);
|
|
||||||
Some(Signal::Stop)
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
error!("Receiver channel closed, stopping GrpcTransportActor");
|
|
||||||
Some(Signal::Stop)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Outbound, Inbound, E> Message<Result<Outbound, E>> for GrpcTransportActor<Outbound, Inbound, E>
|
|
||||||
where
|
|
||||||
Outbound: Send + 'static,
|
|
||||||
Inbound: Send + 'static,
|
|
||||||
E: Into<tonic::Status> + Send + 'static,
|
|
||||||
{
|
|
||||||
type Reply = ();
|
|
||||||
|
|
||||||
async fn handle(
|
|
||||||
&mut self,
|
|
||||||
msg: Result<Outbound, E>,
|
|
||||||
ctx: &mut kameo::prelude::Context<Self, Self::Reply>,
|
|
||||||
) -> Self::Reply {
|
|
||||||
let is_err = msg.is_err();
|
|
||||||
let grpc_msg = msg.map_err(Into::into);
|
|
||||||
match self.sender.send(grpc_msg).await {
|
|
||||||
Ok(_) => {
|
|
||||||
if is_err {
|
|
||||||
ctx.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to send message: {}", e);
|
|
||||||
ctx.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Outbound, Inbound, E> TransportActor<Outbound, E> for GrpcTransportActor<Outbound, Inbound, E>
|
|
||||||
where
|
|
||||||
Outbound: Send + 'static,
|
|
||||||
Inbound: Send + 'static,
|
|
||||||
E: Into<tonic::Status> + Send + 'static,
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Wires together a transport actor and a business logic actor with bidirectional linking.
|
|
||||||
///
|
|
||||||
/// This function handles the chicken-and-egg problem of two actors that need references
|
|
||||||
/// to each other at construction time. It uses kameo's [`PreparedActor`] to obtain
|
|
||||||
/// [`ActorRef`]s before spawning, then links both actors so that if either dies,
|
|
||||||
/// the other is notified via [`on_link_died`](Actor::on_link_died).
|
|
||||||
///
|
|
||||||
/// The business actor receives a type-erased [`Recipient<Result<Outbound, DomainError>>`] instead of an
|
|
||||||
/// `ActorRef<Transport>`, keeping it decoupled from the concrete transport implementation.
|
|
||||||
///
|
|
||||||
/// # Type Parameters
|
|
||||||
/// - `Transport`: The transport actor type (e.g., [`GrpcTransportActor`])
|
|
||||||
/// - `Inbound`: `InboundMessage` received by the business actor from the transport
|
|
||||||
/// - `Outbound`: `OutboundMessage` sent by the business actor back to the transport
|
|
||||||
/// - `Business`: The business logic actor
|
|
||||||
/// - `BusinessCtor`: Closure that receives a prepared business actor and transport recipient,
|
|
||||||
/// spawns the business actor, and returns its [`ActorRef`]
|
|
||||||
/// - `TransportCtor`: Closure that receives a prepared transport actor, a recipient for
|
|
||||||
/// inbound messages, and the business actor id, then spawns the transport actor
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
/// A tuple of `(transport_ref, business_ref)` — actor references for both spawned actors.
|
|
||||||
pub async fn wire<
|
|
||||||
Transport,
|
|
||||||
Inbound,
|
|
||||||
Outbound,
|
|
||||||
DomainError,
|
|
||||||
Business,
|
|
||||||
BusinessCtor,
|
|
||||||
TransportCtor,
|
|
||||||
>(
|
|
||||||
business_ctor: BusinessCtor,
|
|
||||||
transport_ctor: TransportCtor,
|
|
||||||
) -> (ActorRef<Transport>, ActorRef<Business>)
|
|
||||||
where
|
|
||||||
Transport: TransportActor<Outbound, DomainError>,
|
|
||||||
Inbound: Send + 'static,
|
|
||||||
Outbound: Send + 'static,
|
|
||||||
DomainError: Send + 'static,
|
|
||||||
Business: Actor + Message<Inbound> + Send + 'static,
|
|
||||||
BusinessCtor: FnOnce(PreparedActor<Business>, Recipient<Result<Outbound, DomainError>>),
|
|
||||||
TransportCtor:
|
|
||||||
FnOnce(PreparedActor<Transport>, Recipient<Inbound>),
|
|
||||||
{
|
|
||||||
let prepared_business: PreparedActor<Business> = Spawn::prepare();
|
|
||||||
let prepared_transport: PreparedActor<Transport> = Spawn::prepare();
|
|
||||||
|
|
||||||
let business_ref = prepared_business.actor_ref().clone();
|
|
||||||
let transport_ref = prepared_transport.actor_ref().clone();
|
|
||||||
|
|
||||||
transport_ref.link(&business_ref).await;
|
|
||||||
business_ref.link(&transport_ref).await;
|
|
||||||
|
|
||||||
let recipient = transport_ref.clone().recipient();
|
|
||||||
business_ctor(prepared_business, recipient);
|
|
||||||
let business_recipient = business_ref.clone().recipient();
|
|
||||||
transport_ctor(prepared_transport, business_recipient);
|
|
||||||
|
|
||||||
|
|
||||||
(transport_ref, business_ref)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
use base64::{Engine as _, prelude::BASE64_URL_SAFE};
|
|
||||||
use rustls_pki_types::CertificateDer;
|
|
||||||
|
|
||||||
const ARBITER_URL_SCHEME: &str = "arbiter";
|
|
||||||
const CERT_QUERY_KEY: &str = "cert";
|
|
||||||
const BOOTSTRAP_TOKEN_QUERY_KEY: &str = "bootstrap_token";
|
|
||||||
|
|
||||||
pub struct ArbiterUrl {
|
|
||||||
pub host: String,
|
|
||||||
pub port: u16,
|
|
||||||
pub ca_cert: CertificateDer<'static>,
|
|
||||||
pub bootstrap_token: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for ArbiterUrl {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
let mut base = format!(
|
|
||||||
"{ARBITER_URL_SCHEME}://{}:{}?{CERT_QUERY_KEY}={}",
|
|
||||||
self.host,
|
|
||||||
self.port,
|
|
||||||
BASE64_URL_SAFE.encode(self.ca_cert.to_vec())
|
|
||||||
);
|
|
||||||
if let Some(token) = &self.bootstrap_token {
|
|
||||||
base.push_str(&format!("&{BOOTSTRAP_TOKEN_QUERY_KEY}={}", token));
|
|
||||||
}
|
|
||||||
f.write_str(&base)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
|
||||||
pub enum Error {
|
|
||||||
#[error("Invalid URL scheme, expected '{ARBITER_URL_SCHEME}://'")]
|
|
||||||
#[diagnostic(
|
|
||||||
code(arbiter::url::invalid_scheme),
|
|
||||||
help("The URL must start with '{ARBITER_URL_SCHEME}://'")
|
|
||||||
)]
|
|
||||||
InvalidScheme,
|
|
||||||
#[error("Missing host in URL")]
|
|
||||||
#[diagnostic(
|
|
||||||
code(arbiter::url::missing_host),
|
|
||||||
help("The URL must include a host, e.g., '{ARBITER_URL_SCHEME}://127.0.0.1:<port>'")
|
|
||||||
)]
|
|
||||||
MissingHost,
|
|
||||||
#[error("Missing port in URL")]
|
|
||||||
#[diagnostic(
|
|
||||||
code(arbiter::url::missing_port),
|
|
||||||
help("The URL must include a port, e.g., '{ARBITER_URL_SCHEME}://127.0.0.1:1234'")
|
|
||||||
)]
|
|
||||||
MissingPort,
|
|
||||||
#[error("Missing 'cert' query parameter in URL")]
|
|
||||||
#[diagnostic(
|
|
||||||
code(arbiter::url::missing_cert),
|
|
||||||
help("The URL must include a 'cert' query parameter")
|
|
||||||
)]
|
|
||||||
MissingCert,
|
|
||||||
#[error("Invalid base64 in 'cert' query parameter: {0}")]
|
|
||||||
#[diagnostic(code(arbiter::url::invalid_cert_base64))]
|
|
||||||
InvalidCertBase64(#[from] base64::DecodeError),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TryFrom<&'a str> for ArbiterUrl {
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
|
|
||||||
let url = url::Url::parse(value).map_err(|_| Error::InvalidScheme)?;
|
|
||||||
|
|
||||||
if url.scheme() != ARBITER_URL_SCHEME {
|
|
||||||
return Err(Error::InvalidScheme);
|
|
||||||
}
|
|
||||||
|
|
||||||
let host = url.host_str().ok_or(Error::MissingHost)?.to_string();
|
|
||||||
let port = url.port().ok_or(Error::MissingPort)?;
|
|
||||||
let cert_str = url
|
|
||||||
.query_pairs()
|
|
||||||
.find(|(k, _)| k == CERT_QUERY_KEY)
|
|
||||||
.ok_or(Error::MissingCert)?
|
|
||||||
.1;
|
|
||||||
|
|
||||||
let cert = BASE64_URL_SAFE.decode(cert_str.as_ref())?;
|
|
||||||
let cert = CertificateDer::from_slice(&cert).into_owned();
|
|
||||||
|
|
||||||
let bootstrap_token = url
|
|
||||||
.query_pairs()
|
|
||||||
.find(|(k, _)| k == BOOTSTRAP_TOKEN_QUERY_KEY)
|
|
||||||
.map(|(_, v)| v.to_string());
|
|
||||||
|
|
||||||
Ok(ArbiterUrl {
|
|
||||||
host,
|
|
||||||
port,
|
|
||||||
ca_cert: cert,
|
|
||||||
bootstrap_token,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use rcgen::generate_simple_self_signed;
|
|
||||||
use rstest::rstest;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[rstest]
|
|
||||||
|
|
||||||
fn test_parsing_correctness(
|
|
||||||
#[values("127.0.0.1", "localhost", "192.168.1.1", "some.domain.com")] host: &str,
|
|
||||||
|
|
||||||
#[values(None, Some("token123".to_string()))] bootstrap_token: Option<String>,
|
|
||||||
) {
|
|
||||||
let cert = generate_simple_self_signed(&["Arbiter CA".into()]).unwrap();
|
|
||||||
let cert = cert.cert.der();
|
|
||||||
|
|
||||||
let url = ArbiterUrl {
|
|
||||||
host: host.to_string(),
|
|
||||||
port: 1234,
|
|
||||||
ca_cert: cert.clone().into_owned(),
|
|
||||||
bootstrap_token,
|
|
||||||
};
|
|
||||||
let url_str = url.to_string();
|
|
||||||
let parsed_url = ArbiterUrl::try_from(url_str.as_str()).unwrap();
|
|
||||||
assert_eq!(url.host, parsed_url.host);
|
|
||||||
assert_eq!(url.port, parsed_url.port);
|
|
||||||
assert_eq!(url.ca_cert.to_vec(), parsed_url.ca_cert.to_vec());
|
|
||||||
assert_eq!(url.bootstrap_token, parsed_url.bootstrap_token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
server/crates/arbiter-server/.DS_Store
vendored
@@ -3,10 +3,15 @@ name = "arbiter-server"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
repository = "https://git.markettakers.org/MarketTakers/arbiter"
|
repository = "https://git.markettakers.org/MarketTakers/arbiter"
|
||||||
license = "Apache-2.0"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
diesel = { version = "2.3.6", features = ["chrono", "returning_clauses_for_sqlite_3_35", "serde_json", "time", "uuid"] }
|
diesel = { version = "2.3.6", features = [
|
||||||
|
"sqlite",
|
||||||
|
"uuid",
|
||||||
|
"time",
|
||||||
|
"chrono",
|
||||||
|
"serde_json",
|
||||||
|
] }
|
||||||
diesel-async = { version = "0.7.4", features = [
|
diesel-async = { version = "0.7.4", features = [
|
||||||
"bb8",
|
"bb8",
|
||||||
"migrations",
|
"migrations",
|
||||||
@@ -16,9 +21,7 @@ diesel-async = { version = "0.7.4", features = [
|
|||||||
ed25519-dalek.workspace = true
|
ed25519-dalek.workspace = true
|
||||||
arbiter-proto.path = "../arbiter-proto"
|
arbiter-proto.path = "../arbiter-proto"
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
|
||||||
tonic.workspace = true
|
tonic.workspace = true
|
||||||
tonic.features = ["tls-aws-lc"]
|
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
rustls.workspace = true
|
rustls.workspace = true
|
||||||
smlang.workspace = true
|
smlang.workspace = true
|
||||||
@@ -31,18 +34,20 @@ futures.workspace = true
|
|||||||
tokio-stream.workspace = true
|
tokio-stream.workspace = true
|
||||||
dashmap = "6.1.0"
|
dashmap = "6.1.0"
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
rcgen.workspace = true
|
rcgen = { version = "0.14.7", features = [
|
||||||
|
"aws_lc_rs",
|
||||||
|
"pem",
|
||||||
|
"x509-parser",
|
||||||
|
"zeroize",
|
||||||
|
], default-features = false }
|
||||||
chrono.workspace = true
|
chrono.workspace = true
|
||||||
memsafe = "0.4.0"
|
memsafe = "0.4.0"
|
||||||
zeroize = { version = "1.8.2", features = ["std", "simd"] }
|
zeroize = { version = "1.8.2", features = ["std", "simd"] }
|
||||||
|
argon2 = { version = "0.5", features = ["std"] }
|
||||||
kameo.workspace = true
|
kameo.workspace = true
|
||||||
x25519-dalek.workspace = true
|
hex = "0.4.3"
|
||||||
chacha20poly1305 = { version = "0.10.1", features = ["std"] }
|
chacha20poly1305 = "0.10.1"
|
||||||
argon2 = { version = "0.5.3", features = ["zeroize"] }
|
x25519-dalek = { version = "2.0", features = ["static_secrets"] }
|
||||||
restructed = "0.2.2"
|
|
||||||
strum = { version = "0.27.2", features = ["derive"] }
|
|
||||||
pem = "3.0.6"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
insta = "1.46.3"
|
|
||||||
test-log = { version = "0.2", default-features = false, features = ["trace"] }
|
test-log = { version = "0.2", default-features = false, features = ["trace"] }
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
-- Rollback TLS rotation tables
|
||||||
|
|
||||||
|
-- Удалить добавленную колонку из arbiter_settings
|
||||||
|
ALTER TABLE arbiter_settings DROP COLUMN current_cert_id;
|
||||||
|
|
||||||
|
-- Удалить таблицы в обратном порядке
|
||||||
|
DROP TABLE IF EXISTS tls_rotation_history;
|
||||||
|
DROP TABLE IF EXISTS rotation_client_acks;
|
||||||
|
DROP TABLE IF EXISTS tls_rotation_state;
|
||||||
|
DROP INDEX IF EXISTS idx_tls_certificates_active;
|
||||||
|
DROP TABLE IF EXISTS tls_certificates;
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
-- История всех сертификатов
|
||||||
|
CREATE TABLE IF NOT EXISTS tls_certificates (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
cert BLOB NOT NULL, -- DER-encoded
|
||||||
|
cert_key BLOB NOT NULL, -- PEM-encoded
|
||||||
|
not_before INTEGER NOT NULL, -- Unix timestamp
|
||||||
|
not_after INTEGER NOT NULL, -- Unix timestamp
|
||||||
|
created_at INTEGER NOT NULL DEFAULT(unixepoch('now')),
|
||||||
|
is_active BOOLEAN NOT NULL DEFAULT 0 -- Только один active=1
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
CREATE INDEX idx_tls_certificates_active ON tls_certificates(is_active, not_after);
|
||||||
|
|
||||||
|
-- Tracking процесса ротации
|
||||||
|
CREATE TABLE IF NOT EXISTS tls_rotation_state (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY CHECK(id = 1), -- Singleton
|
||||||
|
state TEXT NOT NULL DEFAULT('normal') CHECK(state IN ('normal', 'initiated', 'waiting_acks', 'ready')),
|
||||||
|
new_cert_id INTEGER REFERENCES tls_certificates(id),
|
||||||
|
initiated_at INTEGER,
|
||||||
|
timeout_at INTEGER -- Таймаут для ожидания ACKs (initiated_at + 7 дней)
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
-- Tracking ACKs от клиентов
|
||||||
|
CREATE TABLE IF NOT EXISTS rotation_client_acks (
|
||||||
|
rotation_id INTEGER NOT NULL, -- Ссылка на new_cert_id
|
||||||
|
client_key TEXT NOT NULL, -- Публичный ключ клиента (hex)
|
||||||
|
ack_received_at INTEGER NOT NULL DEFAULT(unixepoch('now')),
|
||||||
|
PRIMARY KEY (rotation_id, client_key)
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
-- Audit trail событий ротации
|
||||||
|
CREATE TABLE IF NOT EXISTS tls_rotation_history (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
cert_id INTEGER NOT NULL REFERENCES tls_certificates(id),
|
||||||
|
event_type TEXT NOT NULL CHECK(event_type IN ('created', 'rotation_initiated', 'acks_complete', 'activated', 'timeout')),
|
||||||
|
timestamp INTEGER NOT NULL DEFAULT(unixepoch('now')),
|
||||||
|
details TEXT -- JSON с доп. информацией
|
||||||
|
) STRICT;
|
||||||
|
|
||||||
|
-- Миграция существующего сертификата
|
||||||
|
INSERT INTO tls_certificates (id, cert, cert_key, not_before, not_after, is_active, created_at)
|
||||||
|
SELECT
|
||||||
|
1,
|
||||||
|
cert,
|
||||||
|
cert_key,
|
||||||
|
unixepoch('now') as not_before,
|
||||||
|
unixepoch('now') + (90 * 24 * 60 * 60) as not_after, -- 90 дней
|
||||||
|
1 as is_active,
|
||||||
|
unixepoch('now')
|
||||||
|
FROM arbiter_settings WHERE id = 1;
|
||||||
|
|
||||||
|
-- Инициализация rotation_state
|
||||||
|
INSERT INTO tls_rotation_state (id, state) VALUES (1, 'normal');
|
||||||
|
|
||||||
|
-- Добавить ссылку на текущий сертификат
|
||||||
|
ALTER TABLE arbiter_settings ADD COLUMN current_cert_id INTEGER REFERENCES tls_certificates(id);
|
||||||
|
UPDATE arbiter_settings SET current_cert_id = 1 WHERE id = 1;
|
||||||
@@ -1,50 +1,22 @@
|
|||||||
create table if not exists root_key_history (
|
|
||||||
id INTEGER not null PRIMARY KEY,
|
|
||||||
-- root key stored as aead encrypted artifact, with only difference that it's decrypted by unseal key (derived from user password)
|
|
||||||
root_key_encryption_nonce blob not null default(1), -- if re-encrypted, this should be incremented. Used for encrypting root key
|
|
||||||
data_encryption_nonce blob not null default(1), -- nonce used for encrypting with key itself
|
|
||||||
ciphertext blob not null,
|
|
||||||
tag blob not null,
|
|
||||||
schema_version integer not null default(1), -- server would need to reencrypt, because this means that we have changed algorithm
|
|
||||||
salt blob not null -- for key deriviation
|
|
||||||
) STRICT;
|
|
||||||
|
|
||||||
create table if not exists aead_encrypted (
|
create table if not exists aead_encrypted (
|
||||||
id INTEGER not null PRIMARY KEY,
|
id INTEGER not null PRIMARY KEY,
|
||||||
current_nonce blob not null default(1), -- if re-encrypted, this should be incremented
|
current_nonce integer not null default(1), -- if re-encrypted, this should be incremented
|
||||||
ciphertext blob not null,
|
ciphertext blob not null,
|
||||||
tag blob not null,
|
tag blob not null,
|
||||||
schema_version integer not null default(1), -- server would need to reencrypt, because this means that we have changed algorithm
|
schema_version integer not null default(1) -- server would need to reencrypt, because this means that we have changed algorithm
|
||||||
associated_root_key_id integer not null references root_key_history (id) on delete RESTRICT,
|
|
||||||
created_at integer not null default(unixepoch ('now'))
|
|
||||||
) STRICT;
|
|
||||||
|
|
||||||
create unique index if not exists uniq_nonce_per_root_key on aead_encrypted (
|
|
||||||
current_nonce,
|
|
||||||
associated_root_key_id
|
|
||||||
);
|
|
||||||
|
|
||||||
create table if not exists tls_history (
|
|
||||||
id INTEGER not null PRIMARY KEY,
|
|
||||||
cert text not null,
|
|
||||||
cert_key text not null, -- PEM Encoded private key
|
|
||||||
ca_cert text not null,
|
|
||||||
ca_key text not null, -- PEM Encoded private key
|
|
||||||
created_at integer not null default(unixepoch ('now'))
|
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
-- This is a singleton
|
-- This is a singleton
|
||||||
create table if not exists arbiter_settings (
|
create table if not exists arbiter_settings (
|
||||||
id INTEGER not null PRIMARY KEY CHECK (id = 1), -- singleton row, id must be 1
|
id INTEGER not null PRIMARY KEY CHECK (id = 1), -- singleton row, id must be 1
|
||||||
root_key_id integer references root_key_history (id) on delete RESTRICT, -- if null, means wasn't bootstrapped yet
|
root_key_id integer references aead_encrypted (id) on delete RESTRICT, -- if null, means wasn't bootstrapped yet
|
||||||
tls_id integer references tls_history (id) on delete RESTRICT
|
cert_key blob not null,
|
||||||
|
cert blob not null
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
insert into arbiter_settings (id) values (1) on conflict do nothing; -- ensure singleton row exists
|
|
||||||
|
|
||||||
create table if not exists useragent_client (
|
create table if not exists useragent_client (
|
||||||
id integer not null primary key,
|
id integer not null primary key,
|
||||||
nonce integer not null default(1), -- used for auth challenge
|
nonce integer not null default (1), -- used for auth challenge
|
||||||
public_key blob not null,
|
public_key blob not null,
|
||||||
created_at integer not null default(unixepoch ('now')),
|
created_at integer not null default(unixepoch ('now')),
|
||||||
updated_at integer not null default(unixepoch ('now'))
|
updated_at integer not null default(unixepoch ('now'))
|
||||||
@@ -52,7 +24,7 @@ create table if not exists useragent_client (
|
|||||||
|
|
||||||
create table if not exists program_client (
|
create table if not exists program_client (
|
||||||
id integer not null primary key,
|
id integer not null primary key,
|
||||||
nonce integer not null default(1), -- used for auth challenge
|
nonce integer not null default (1), -- used for auth challenge
|
||||||
public_key blob not null,
|
public_key blob not null,
|
||||||
created_at integer not null default(unixepoch ('now')),
|
created_at integer not null default(unixepoch ('now')),
|
||||||
updated_at integer not null default(unixepoch ('now'))
|
updated_at integer not null default(unixepoch ('now'))
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-- Remove argon2_salt column
|
||||||
|
ALTER TABLE aead_encrypted DROP COLUMN argon2_salt;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-- Add argon2_salt column to store password derivation salt
|
||||||
|
ALTER TABLE aead_encrypted ADD COLUMN argon2_salt TEXT;
|
||||||
BIN
server/crates/arbiter-server/src/.DS_Store
vendored
2
server/crates/arbiter-server/src/actors.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod user_agent;
|
||||||
|
pub mod client;
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod v1;
|
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
use std::ops::Deref as _;
|
|
||||||
|
|
||||||
use argon2::{Algorithm, Argon2, password_hash::Salt as ArgonSalt};
|
|
||||||
use chacha20poly1305::{
|
|
||||||
AeadInPlace, Key, KeyInit as _, XChaCha20Poly1305, XNonce,
|
|
||||||
aead::{AeadMut, Error, Payload},
|
|
||||||
};
|
|
||||||
use memsafe::MemSafe;
|
|
||||||
use rand::{
|
|
||||||
Rng as _, SeedableRng,
|
|
||||||
rngs::{StdRng, SysRng},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const ROOT_KEY_TAG: &[u8] = "arbiter/seal/v1".as_bytes();
|
|
||||||
pub const TAG: &[u8] = "arbiter/private-key/v1".as_bytes();
|
|
||||||
|
|
||||||
pub const NONCE_LENGTH: usize = 24;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Nonce([u8; NONCE_LENGTH]);
|
|
||||||
impl Nonce {
|
|
||||||
pub fn increment(&mut self) {
|
|
||||||
for i in (0..self.0.len()).rev() {
|
|
||||||
if self.0[i] == 0xFF {
|
|
||||||
self.0[i] = 0;
|
|
||||||
} else {
|
|
||||||
self.0[i] += 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_vec(&self) -> Vec<u8> {
|
|
||||||
self.0.to_vec()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<'a> TryFrom<&'a [u8]> for Nonce {
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn try_from(value: &'a [u8]) -> Result<Self, Self::Error> {
|
|
||||||
if value.len() != NONCE_LENGTH {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
let mut nonce = [0u8; NONCE_LENGTH];
|
|
||||||
nonce.copy_from_slice(value);
|
|
||||||
Ok(Self(nonce))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct KeyCell(pub MemSafe<Key>);
|
|
||||||
impl From<MemSafe<Key>> for KeyCell {
|
|
||||||
fn from(value: MemSafe<Key>) -> Self {
|
|
||||||
Self(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TryFrom<MemSafe<Vec<u8>>> for KeyCell {
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn try_from(mut value: MemSafe<Vec<u8>>) -> Result<Self, Self::Error> {
|
|
||||||
let value = value.read().unwrap();
|
|
||||||
if value.len() != size_of::<Key>() {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
let mut cell = MemSafe::new(Key::default()).unwrap();
|
|
||||||
{
|
|
||||||
let mut cell_write = cell.write().unwrap();
|
|
||||||
let cell_slice: &mut [u8] = cell_write.as_mut();
|
|
||||||
cell_slice.copy_from_slice(&value);
|
|
||||||
}
|
|
||||||
Ok(Self(cell))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KeyCell {
|
|
||||||
pub fn new_secure_random() -> Self {
|
|
||||||
let mut key = MemSafe::new(Key::default()).unwrap();
|
|
||||||
{
|
|
||||||
let mut key_buffer = key.write().unwrap();
|
|
||||||
let key_buffer: &mut [u8] = key_buffer.as_mut();
|
|
||||||
|
|
||||||
let mut rng = StdRng::try_from_rng(&mut SysRng).unwrap();
|
|
||||||
rng.fill_bytes(key_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
key.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn encrypt_in_place(
|
|
||||||
&mut self,
|
|
||||||
nonce: &Nonce,
|
|
||||||
associated_data: &[u8],
|
|
||||||
mut buffer: impl AsMut<Vec<u8>>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let key_reader = self.0.read().unwrap();
|
|
||||||
let key_ref = key_reader.deref();
|
|
||||||
let cipher = XChaCha20Poly1305::new(key_ref);
|
|
||||||
let nonce = XNonce::from_slice(nonce.0.as_ref());
|
|
||||||
let buffer = buffer.as_mut();
|
|
||||||
cipher.encrypt_in_place(nonce, associated_data, buffer)
|
|
||||||
}
|
|
||||||
pub fn decrypt_in_place(
|
|
||||||
&mut self,
|
|
||||||
nonce: &Nonce,
|
|
||||||
associated_data: &[u8],
|
|
||||||
buffer: &mut MemSafe<Vec<u8>>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let key_reader = self.0.read().unwrap();
|
|
||||||
let key_ref = key_reader.deref();
|
|
||||||
let cipher = XChaCha20Poly1305::new(key_ref);
|
|
||||||
let nonce = XNonce::from_slice(nonce.0.as_ref());
|
|
||||||
let mut buffer = buffer.write().unwrap();
|
|
||||||
let buffer: &mut Vec<u8> = buffer.as_mut();
|
|
||||||
cipher.decrypt_in_place(nonce, associated_data, buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn encrypt(
|
|
||||||
&mut self,
|
|
||||||
nonce: &Nonce,
|
|
||||||
associated_data: &[u8],
|
|
||||||
plaintext: impl AsRef<[u8]>,
|
|
||||||
) -> Result<Vec<u8>, Error> {
|
|
||||||
let key_reader = self.0.read().unwrap();
|
|
||||||
let key_ref = key_reader.deref();
|
|
||||||
let mut cipher = XChaCha20Poly1305::new(key_ref);
|
|
||||||
let nonce = XNonce::from_slice(nonce.0.as_ref());
|
|
||||||
|
|
||||||
let ciphertext = cipher.encrypt(
|
|
||||||
nonce,
|
|
||||||
Payload {
|
|
||||||
msg: plaintext.as_ref(),
|
|
||||||
aad: associated_data,
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
Ok(ciphertext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type Salt = [u8; ArgonSalt::RECOMMENDED_LENGTH];
|
|
||||||
|
|
||||||
pub fn generate_salt() -> Salt {
|
|
||||||
let mut salt = Salt::default();
|
|
||||||
let mut rng = StdRng::try_from_rng(&mut SysRng).unwrap();
|
|
||||||
rng.fill_bytes(&mut salt);
|
|
||||||
salt
|
|
||||||
}
|
|
||||||
|
|
||||||
/// User password might be of different length, have not enough entropy, etc...
|
|
||||||
/// Derive a fixed-length key from the password using Argon2id, which is designed for password hashing and key derivation.
|
|
||||||
pub fn derive_seal_key(mut password: MemSafe<Vec<u8>>, salt: &Salt) -> KeyCell {
|
|
||||||
let params = argon2::Params::new(262_144, 3, 4, None).unwrap();
|
|
||||||
let hasher = Argon2::new(Algorithm::Argon2id, argon2::Version::V0x13, params);
|
|
||||||
let mut key = MemSafe::new(Key::default()).unwrap();
|
|
||||||
{
|
|
||||||
let password_source = password.read().unwrap();
|
|
||||||
let mut key_buffer = key.write().unwrap();
|
|
||||||
let key_buffer: &mut [u8] = key_buffer.as_mut();
|
|
||||||
|
|
||||||
hasher
|
|
||||||
.hash_password_into(password_source.deref(), salt, key_buffer)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
key.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use memsafe::MemSafe;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn derive_seal_key_deterministic() {
|
|
||||||
static PASSWORD: &[u8] = b"password";
|
|
||||||
let password = MemSafe::new(PASSWORD.to_vec()).unwrap();
|
|
||||||
let password2 = MemSafe::new(PASSWORD.to_vec()).unwrap();
|
|
||||||
let salt = generate_salt();
|
|
||||||
|
|
||||||
let mut key1 = derive_seal_key(password, &salt);
|
|
||||||
let mut key2 = derive_seal_key(password2, &salt);
|
|
||||||
|
|
||||||
let key1_reader = key1.0.read().unwrap();
|
|
||||||
let key2_reader = key2.0.read().unwrap();
|
|
||||||
|
|
||||||
assert_eq!(key1_reader.deref(), key2_reader.deref());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn successful_derive() {
|
|
||||||
static PASSWORD: &[u8] = b"password";
|
|
||||||
let password = MemSafe::new(PASSWORD.to_vec()).unwrap();
|
|
||||||
let salt = generate_salt();
|
|
||||||
|
|
||||||
let mut key = derive_seal_key(password, &salt);
|
|
||||||
let key_reader = key.0.read().unwrap();
|
|
||||||
let key_ref = key_reader.deref();
|
|
||||||
|
|
||||||
assert_ne!(key_ref.as_slice(), &[0u8; 32][..]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
pub fn encrypt_decrypt() {
|
|
||||||
static PASSWORD: &[u8] = b"password";
|
|
||||||
let password = MemSafe::new(PASSWORD.to_vec()).unwrap();
|
|
||||||
let salt = generate_salt();
|
|
||||||
|
|
||||||
let mut key = derive_seal_key(password, &salt);
|
|
||||||
let nonce = Nonce(*b"unique nonce 123 1231233"); // 24 bytes for XChaCha20Poly1305
|
|
||||||
let associated_data = b"associated data";
|
|
||||||
let mut buffer = b"secret data".to_vec();
|
|
||||||
|
|
||||||
key.encrypt_in_place(&nonce, associated_data, &mut buffer)
|
|
||||||
.unwrap();
|
|
||||||
assert_ne!(buffer, b"secret data");
|
|
||||||
|
|
||||||
let mut buffer = MemSafe::new(buffer).unwrap();
|
|
||||||
|
|
||||||
key.decrypt_in_place(&nonce, associated_data, &mut buffer)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let buffer = buffer.read().unwrap();
|
|
||||||
assert_eq!(*buffer, b"secret data");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
// We should fuzz this
|
|
||||||
pub fn test_nonce_increment() {
|
|
||||||
let mut nonce = Nonce([0u8; NONCE_LENGTH]);
|
|
||||||
nonce.increment();
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
nonce.0,
|
|
||||||
[
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,407 +0,0 @@
|
|||||||
use diesel::{
|
|
||||||
ExpressionMethods as _, OptionalExtension, QueryDsl, SelectableHelper,
|
|
||||||
dsl::{insert_into, update},
|
|
||||||
};
|
|
||||||
use diesel_async::{AsyncConnection, RunQueryDsl};
|
|
||||||
use kameo::{Actor, Reply, messages};
|
|
||||||
use memsafe::MemSafe;
|
|
||||||
use strum::{EnumDiscriminants, IntoDiscriminant};
|
|
||||||
use tracing::{error, info};
|
|
||||||
|
|
||||||
use crate::db::{
|
|
||||||
self,
|
|
||||||
models::{self, RootKeyHistory},
|
|
||||||
schema::{self},
|
|
||||||
};
|
|
||||||
use encryption::v1::{self, KeyCell, Nonce};
|
|
||||||
|
|
||||||
pub mod encryption;
|
|
||||||
|
|
||||||
#[derive(Default, EnumDiscriminants)]
|
|
||||||
#[strum_discriminants(derive(Reply), vis(pub))]
|
|
||||||
enum State {
|
|
||||||
#[default]
|
|
||||||
Unbootstrapped,
|
|
||||||
Sealed {
|
|
||||||
root_key_history_id: i32,
|
|
||||||
},
|
|
||||||
Unsealed {
|
|
||||||
root_key_history_id: i32,
|
|
||||||
root_key: KeyCell,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
|
|
||||||
pub enum Error {
|
|
||||||
#[error("Keyholder is already bootstrapped")]
|
|
||||||
#[diagnostic(code(arbiter::keyholder::already_bootstrapped))]
|
|
||||||
AlreadyBootstrapped,
|
|
||||||
#[error("Keyholder is not bootstrapped")]
|
|
||||||
#[diagnostic(code(arbiter::keyholder::not_bootstrapped))]
|
|
||||||
NotBootstrapped,
|
|
||||||
#[error("Invalid key provided")]
|
|
||||||
#[diagnostic(code(arbiter::keyholder::invalid_key))]
|
|
||||||
InvalidKey,
|
|
||||||
|
|
||||||
#[error("Requested aead entry not found")]
|
|
||||||
#[diagnostic(code(arbiter::keyholder::aead_not_found))]
|
|
||||||
NotFound,
|
|
||||||
|
|
||||||
#[error("Encryption error: {0}")]
|
|
||||||
#[diagnostic(code(arbiter::keyholder::encryption_error))]
|
|
||||||
Encryption(#[from] chacha20poly1305::aead::Error),
|
|
||||||
|
|
||||||
#[error("Database error: {0}")]
|
|
||||||
#[diagnostic(code(arbiter::keyholder::database_error))]
|
|
||||||
DatabaseConnection(#[from] db::PoolError),
|
|
||||||
|
|
||||||
#[error("Database transaction error: {0}")]
|
|
||||||
#[diagnostic(code(arbiter::keyholder::database_transaction_error))]
|
|
||||||
DatabaseTransaction(#[from] diesel::result::Error),
|
|
||||||
|
|
||||||
#[error("Broken database")]
|
|
||||||
#[diagnostic(code(arbiter::keyholder::broken_database))]
|
|
||||||
BrokenDatabase,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Manages vault root key and tracks current state of the vault (bootstrapped/unbootstrapped, sealed/unsealed).
|
|
||||||
/// Provides API for encrypting and decrypting data using the vault root key.
|
|
||||||
/// Abstraction over database to make sure nonces are never reused and encryption keys are never exposed in plaintext outside of this actor.
|
|
||||||
#[derive(Actor)]
|
|
||||||
pub struct KeyHolder {
|
|
||||||
db: db::DatabasePool,
|
|
||||||
state: State,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[messages]
|
|
||||||
impl KeyHolder {
|
|
||||||
pub async fn new(db: db::DatabasePool) -> Result<Self, Error> {
|
|
||||||
let state = {
|
|
||||||
let mut conn = db.get().await?;
|
|
||||||
|
|
||||||
let (root_key_history,) = schema::arbiter_settings::table
|
|
||||||
.left_join(schema::root_key_history::table)
|
|
||||||
.select((Option::<RootKeyHistory>::as_select(),))
|
|
||||||
.get_result::<(Option<RootKeyHistory>,)>(&mut conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
match root_key_history {
|
|
||||||
Some(root_key_history) => State::Sealed {
|
|
||||||
root_key_history_id: root_key_history.id,
|
|
||||||
},
|
|
||||||
None => State::Unbootstrapped,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self { db, state })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exclusive transaction to avoid race condtions if multiple keyholders write
|
|
||||||
// additional layer of protection against nonce-reuse
|
|
||||||
async fn get_new_nonce(pool: &db::DatabasePool, root_key_id: i32) -> Result<Nonce, Error> {
|
|
||||||
let mut conn = pool.get().await?;
|
|
||||||
|
|
||||||
let nonce = conn
|
|
||||||
.exclusive_transaction(|conn| {
|
|
||||||
Box::pin(async move {
|
|
||||||
let current_nonce: Vec<u8> = schema::root_key_history::table
|
|
||||||
.filter(schema::root_key_history::id.eq(root_key_id))
|
|
||||||
.select(schema::root_key_history::data_encryption_nonce)
|
|
||||||
.first(conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mut nonce =
|
|
||||||
v1::Nonce::try_from(current_nonce.as_slice()).map_err(|_| {
|
|
||||||
error!(
|
|
||||||
"Broken database: invalid nonce for root key history id={}",
|
|
||||||
root_key_id
|
|
||||||
);
|
|
||||||
Error::BrokenDatabase
|
|
||||||
})?;
|
|
||||||
nonce.increment();
|
|
||||||
|
|
||||||
update(schema::root_key_history::table)
|
|
||||||
.filter(schema::root_key_history::id.eq(root_key_id))
|
|
||||||
.set(schema::root_key_history::data_encryption_nonce.eq(nonce.to_vec()))
|
|
||||||
.execute(conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Result::<_, Error>::Ok(nonce)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(nonce)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[message]
|
|
||||||
pub async fn bootstrap(&mut self, seal_key_raw: MemSafe<Vec<u8>>) -> Result<(), Error> {
|
|
||||||
if !matches!(self.state, State::Unbootstrapped) {
|
|
||||||
return Err(Error::AlreadyBootstrapped);
|
|
||||||
}
|
|
||||||
let salt = v1::generate_salt();
|
|
||||||
let mut seal_key = v1::derive_seal_key(seal_key_raw, &salt);
|
|
||||||
let mut root_key = KeyCell::new_secure_random();
|
|
||||||
|
|
||||||
// Zero nonces are fine because they are one-time
|
|
||||||
let root_key_nonce = v1::Nonce::default();
|
|
||||||
let data_encryption_nonce = v1::Nonce::default();
|
|
||||||
|
|
||||||
let root_key_ciphertext: Vec<u8> = {
|
|
||||||
let root_key_reader = root_key.0.read().unwrap();
|
|
||||||
let root_key_reader = root_key_reader.as_slice();
|
|
||||||
seal_key
|
|
||||||
.encrypt(&root_key_nonce, v1::ROOT_KEY_TAG, root_key_reader)
|
|
||||||
.map_err(|err| {
|
|
||||||
error!(?err, "Fatal bootstrap error");
|
|
||||||
Error::Encryption(err)
|
|
||||||
})?
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut conn = self.db.get().await?;
|
|
||||||
|
|
||||||
let data_encryption_nonce_bytes = data_encryption_nonce.to_vec();
|
|
||||||
let root_key_history_id = conn
|
|
||||||
.transaction(|conn| {
|
|
||||||
Box::pin(async move {
|
|
||||||
let root_key_history_id: i32 = insert_into(schema::root_key_history::table)
|
|
||||||
.values(&models::NewRootKeyHistory {
|
|
||||||
ciphertext: root_key_ciphertext,
|
|
||||||
tag: v1::ROOT_KEY_TAG.to_vec(),
|
|
||||||
root_key_encryption_nonce: root_key_nonce.to_vec(),
|
|
||||||
data_encryption_nonce: data_encryption_nonce_bytes,
|
|
||||||
schema_version: 1,
|
|
||||||
salt: salt.to_vec(),
|
|
||||||
})
|
|
||||||
.returning(schema::root_key_history::id)
|
|
||||||
.get_result(conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
update(schema::arbiter_settings::table)
|
|
||||||
.set(schema::arbiter_settings::root_key_id.eq(root_key_history_id))
|
|
||||||
.execute(conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Result::<_, diesel::result::Error>::Ok(root_key_history_id)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
self.state = State::Unsealed {
|
|
||||||
root_key,
|
|
||||||
root_key_history_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("Keyholder bootstrapped successfully");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[message]
|
|
||||||
pub async fn try_unseal(&mut self, seal_key_raw: MemSafe<Vec<u8>>) -> Result<(), Error> {
|
|
||||||
let State::Sealed {
|
|
||||||
root_key_history_id,
|
|
||||||
} = &self.state
|
|
||||||
else {
|
|
||||||
return Err(Error::NotBootstrapped);
|
|
||||||
};
|
|
||||||
|
|
||||||
// We don't want to hold connection while doing expensive KDF work
|
|
||||||
let current_key = {
|
|
||||||
let mut conn = self.db.get().await?;
|
|
||||||
schema::root_key_history::table
|
|
||||||
.filter(schema::root_key_history::id.eq(*root_key_history_id))
|
|
||||||
.select(schema::root_key_history::data_encryption_nonce)
|
|
||||||
.select(RootKeyHistory::as_select())
|
|
||||||
.first(&mut conn)
|
|
||||||
.await?
|
|
||||||
};
|
|
||||||
|
|
||||||
let salt = ¤t_key.salt;
|
|
||||||
let salt = v1::Salt::try_from(salt.as_slice()).map_err(|_| {
|
|
||||||
error!("Broken database: invalid salt for root key");
|
|
||||||
Error::BrokenDatabase
|
|
||||||
})?;
|
|
||||||
let mut seal_key = v1::derive_seal_key(seal_key_raw, &salt);
|
|
||||||
|
|
||||||
let mut root_key = MemSafe::new(current_key.ciphertext.clone()).unwrap();
|
|
||||||
|
|
||||||
let nonce = v1::Nonce::try_from(current_key.root_key_encryption_nonce.as_slice()).map_err(
|
|
||||||
|_| {
|
|
||||||
error!("Broken database: invalid nonce for root key");
|
|
||||||
Error::BrokenDatabase
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
|
|
||||||
seal_key
|
|
||||||
.decrypt_in_place(&nonce, v1::ROOT_KEY_TAG, &mut root_key)
|
|
||||||
.map_err(|err| {
|
|
||||||
error!(?err, "Failed to unseal root key: invalid seal key");
|
|
||||||
Error::InvalidKey
|
|
||||||
})?;
|
|
||||||
|
|
||||||
self.state = State::Unsealed {
|
|
||||||
root_key_history_id: current_key.id,
|
|
||||||
root_key: v1::KeyCell::try_from(root_key).map_err(|err| {
|
|
||||||
error!(?err, "Broken database: invalid encryption key size");
|
|
||||||
Error::BrokenDatabase
|
|
||||||
})?,
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("Keyholder unsealed successfully");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decrypts the `aead_encrypted` entry with the given ID and returns the plaintext
|
|
||||||
#[message]
|
|
||||||
pub async fn decrypt(&mut self, aead_id: i32) -> Result<MemSafe<Vec<u8>>, Error> {
|
|
||||||
let State::Unsealed { root_key, .. } = &mut self.state else {
|
|
||||||
return Err(Error::NotBootstrapped);
|
|
||||||
};
|
|
||||||
|
|
||||||
let row: models::AeadEncrypted = {
|
|
||||||
let mut conn = self.db.get().await?;
|
|
||||||
schema::aead_encrypted::table
|
|
||||||
.select(models::AeadEncrypted::as_select())
|
|
||||||
.filter(schema::aead_encrypted::id.eq(aead_id))
|
|
||||||
.first(&mut conn)
|
|
||||||
.await
|
|
||||||
.optional()?
|
|
||||||
.ok_or(Error::NotFound)?
|
|
||||||
};
|
|
||||||
|
|
||||||
let nonce = v1::Nonce::try_from(row.current_nonce.as_slice()).map_err(|_| {
|
|
||||||
error!(
|
|
||||||
"Broken database: invalid nonce for aead_encrypted id={}",
|
|
||||||
aead_id
|
|
||||||
);
|
|
||||||
Error::BrokenDatabase
|
|
||||||
})?;
|
|
||||||
let mut output = MemSafe::new(row.ciphertext).unwrap();
|
|
||||||
root_key.decrypt_in_place(&nonce, v1::TAG, &mut output)?;
|
|
||||||
Ok(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates new `aead_encrypted` entry in the database and returns it's ID
|
|
||||||
#[message]
|
|
||||||
pub async fn create_new(&mut self, mut plaintext: MemSafe<Vec<u8>>) -> Result<i32, Error> {
|
|
||||||
let State::Unsealed {
|
|
||||||
root_key,
|
|
||||||
root_key_history_id,
|
|
||||||
} = &mut self.state
|
|
||||||
else {
|
|
||||||
return Err(Error::NotBootstrapped);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Order matters here - `get_new_nonce` acquires connection, so we need to call it before next acquire
|
|
||||||
// Borrow checker note: &mut borrow a few lines above is disjoint from this field
|
|
||||||
let nonce = Self::get_new_nonce(&self.db, *root_key_history_id).await?;
|
|
||||||
|
|
||||||
let mut ciphertext_buffer = plaintext.write().unwrap();
|
|
||||||
let ciphertext_buffer: &mut Vec<u8> = ciphertext_buffer.as_mut();
|
|
||||||
root_key.encrypt_in_place(&nonce, v1::TAG, &mut *ciphertext_buffer)?;
|
|
||||||
|
|
||||||
let ciphertext = std::mem::take(ciphertext_buffer);
|
|
||||||
|
|
||||||
let mut conn = self.db.get().await?;
|
|
||||||
let aead_id: i32 = insert_into(schema::aead_encrypted::table)
|
|
||||||
.values(&models::NewAeadEncrypted {
|
|
||||||
ciphertext,
|
|
||||||
tag: v1::TAG.to_vec(),
|
|
||||||
current_nonce: nonce.to_vec(),
|
|
||||||
schema_version: 1,
|
|
||||||
associated_root_key_id: *root_key_history_id,
|
|
||||||
created_at: chrono::Utc::now().timestamp() as i32,
|
|
||||||
})
|
|
||||||
.returning(schema::aead_encrypted::id)
|
|
||||||
.get_result(&mut conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(aead_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[message]
|
|
||||||
pub fn get_state(&self) -> StateDiscriminants {
|
|
||||||
self.state.discriminant()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[message]
|
|
||||||
pub fn seal(&mut self) -> Result<(), Error> {
|
|
||||||
let State::Unsealed {
|
|
||||||
root_key_history_id,
|
|
||||||
..
|
|
||||||
} = &self.state
|
|
||||||
else {
|
|
||||||
return Err(Error::NotBootstrapped);
|
|
||||||
};
|
|
||||||
self.state = State::Sealed {
|
|
||||||
root_key_history_id: *root_key_history_id,
|
|
||||||
};
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use diesel::SelectableHelper;
|
|
||||||
|
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use memsafe::MemSafe;
|
|
||||||
|
|
||||||
use crate::db::{self};
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
async fn bootstrapped_actor(db: &db::DatabasePool) -> KeyHolder {
|
|
||||||
let mut actor = KeyHolder::new(db.clone()).await.unwrap();
|
|
||||||
let seal_key = MemSafe::new(b"test-seal-key".to_vec()).unwrap();
|
|
||||||
actor.bootstrap(seal_key).await.unwrap();
|
|
||||||
actor
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
#[test_log::test]
|
|
||||||
async fn nonce_monotonic_even_when_nonce_allocation_interleaves() {
|
|
||||||
let db = db::create_test_pool().await;
|
|
||||||
let mut actor = bootstrapped_actor(&db).await;
|
|
||||||
let root_key_history_id = match actor.state {
|
|
||||||
State::Unsealed {
|
|
||||||
root_key_history_id,
|
|
||||||
..
|
|
||||||
} => root_key_history_id,
|
|
||||||
_ => panic!("expected unsealed state"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let n1 = KeyHolder::get_new_nonce(&db, root_key_history_id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let n2 = KeyHolder::get_new_nonce(&db, root_key_history_id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(n2.to_vec() > n1.to_vec(), "nonce must increase");
|
|
||||||
|
|
||||||
let mut conn = db.get().await.unwrap();
|
|
||||||
let root_row: models::RootKeyHistory = schema::root_key_history::table
|
|
||||||
.select(models::RootKeyHistory::as_select())
|
|
||||||
.first(&mut conn)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(root_row.data_encryption_nonce, n2.to_vec());
|
|
||||||
|
|
||||||
let id = actor
|
|
||||||
.create_new(MemSafe::new(b"post-interleave".to_vec()).unwrap())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let row: models::AeadEncrypted = schema::aead_encrypted::table
|
|
||||||
.filter(schema::aead_encrypted::id.eq(id))
|
|
||||||
.select(models::AeadEncrypted::as_select())
|
|
||||||
.first(&mut conn)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(
|
|
||||||
row.current_nonce > n2.to_vec(),
|
|
||||||
"next write must advance nonce"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
use kameo::actor::{ActorRef, Spawn};
|
|
||||||
use miette::Diagnostic;
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
actors::{bootstrap::Bootstrapper, keyholder::KeyHolder},
|
|
||||||
db,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub mod bootstrap;
|
|
||||||
pub mod client;
|
|
||||||
pub mod keyholder;
|
|
||||||
pub mod user_agent;
|
|
||||||
|
|
||||||
#[derive(Error, Debug, Diagnostic)]
|
|
||||||
pub enum SpawnError {
|
|
||||||
#[error("Failed to spawn Bootstrapper actor")]
|
|
||||||
#[diagnostic(code(SpawnError::Bootstrapper))]
|
|
||||||
Bootstrapper(#[from] bootstrap::Error),
|
|
||||||
|
|
||||||
#[error("Failed to spawn KeyHolder actor")]
|
|
||||||
#[diagnostic(code(SpawnError::KeyHolder))]
|
|
||||||
KeyHolder(#[from] keyholder::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Long-lived actors that are shared across all connections and handle global state and operations
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct GlobalActors {
|
|
||||||
pub key_holder: ActorRef<KeyHolder>,
|
|
||||||
pub bootstrapper: ActorRef<Bootstrapper>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GlobalActors {
|
|
||||||
pub async fn spawn(db: db::DatabasePool) -> Result<Self, SpawnError> {
|
|
||||||
Ok(Self {
|
|
||||||
bootstrapper: Bootstrapper::spawn(Bootstrapper::new(&db).await?),
|
|
||||||
key_holder: KeyHolder::spawn(KeyHolder::new(db.clone()).await?),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
498
server/crates/arbiter-server/src/actors/user_agent.rs
Normal file
@@ -0,0 +1,498 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use arbiter_proto::{
|
||||||
|
proto::{
|
||||||
|
UserAgentRequest, UserAgentResponse,
|
||||||
|
auth::{
|
||||||
|
self, AuthChallengeRequest, ClientMessage, ServerMessage as AuthServerMessage,
|
||||||
|
client_message::Payload as ClientAuthPayload,
|
||||||
|
server_message::Payload as ServerAuthPayload,
|
||||||
|
},
|
||||||
|
user_agent_request::Payload as UserAgentRequestPayload,
|
||||||
|
user_agent_response::Payload as UserAgentResponsePayload,
|
||||||
|
},
|
||||||
|
transport::Bi,
|
||||||
|
};
|
||||||
|
use diesel::{ExpressionMethods as _, OptionalExtension as _, QueryDsl, dsl::update};
|
||||||
|
use diesel_async::{AsyncConnection, RunQueryDsl};
|
||||||
|
use ed25519_dalek::VerifyingKey;
|
||||||
|
use futures::StreamExt;
|
||||||
|
use kameo::{
|
||||||
|
Actor,
|
||||||
|
actor::{ActorRef, Spawn},
|
||||||
|
error::SendError,
|
||||||
|
messages,
|
||||||
|
prelude::Context,
|
||||||
|
};
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
|
use tonic::{Status, transport::Server};
|
||||||
|
use tracing::{debug, error, info};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
ServerContext,
|
||||||
|
actors::user_agent::auth::AuthChallenge,
|
||||||
|
context::bootstrap::{BootstrapActor, ConsumeToken},
|
||||||
|
db::{self, schema},
|
||||||
|
errors::GrpcStatusExt,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ChallengeContext {
|
||||||
|
challenge: AuthChallenge,
|
||||||
|
key: VerifyingKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request context with deserialized public key for state machine.
|
||||||
|
// This intermediate struct is needed because the state machine branches depending on presence of bootstrap token,
|
||||||
|
// but we want to have the deserialized key in both branches.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct AuthRequestContext {
|
||||||
|
pubkey: VerifyingKey,
|
||||||
|
bootstrap_token: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
smlang::statemachine!(
|
||||||
|
name: UserAgent,
|
||||||
|
derive_states: [Debug],
|
||||||
|
custom_error: false,
|
||||||
|
transitions: {
|
||||||
|
*Init + AuthRequest(AuthRequestContext) / auth_request_context = ReceivedAuthRequest(AuthRequestContext),
|
||||||
|
ReceivedAuthRequest(AuthRequestContext) + ReceivedBootstrapToken = Authenticated,
|
||||||
|
|
||||||
|
ReceivedAuthRequest(AuthRequestContext) + SentChallenge(ChallengeContext) / move_challenge = WaitingForChallengeSolution(ChallengeContext),
|
||||||
|
|
||||||
|
WaitingForChallengeSolution(ChallengeContext) + ReceivedGoodSolution = Authenticated,
|
||||||
|
WaitingForChallengeSolution(ChallengeContext) + ReceivedBadSolution = AuthError, // block further transitions, but connection should close anyway
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
pub struct DummyContext;
|
||||||
|
impl UserAgentStateMachineContext for DummyContext {
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
#[allow(clippy::unused_unit)]
|
||||||
|
fn move_challenge(
|
||||||
|
&mut self,
|
||||||
|
state_data: &AuthRequestContext,
|
||||||
|
event_data: ChallengeContext,
|
||||||
|
) -> Result<ChallengeContext, ()> {
|
||||||
|
Ok(event_data)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
#[allow(clippy::unused_unit)]
|
||||||
|
fn auth_request_context(
|
||||||
|
&mut self,
|
||||||
|
event_data: AuthRequestContext,
|
||||||
|
) -> Result<AuthRequestContext, ()> {
|
||||||
|
Ok(event_data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Actor)]
|
||||||
|
pub struct UserAgentActor {
|
||||||
|
db: db::DatabasePool,
|
||||||
|
bootstapper: ActorRef<BootstrapActor>,
|
||||||
|
state: UserAgentStateMachine<DummyContext>,
|
||||||
|
tx: Sender<Result<UserAgentResponse, Status>>,
|
||||||
|
context: ServerContext,
|
||||||
|
ephemeral_key: Option<crate::context::unseal::EphemeralKeyPair>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserAgentActor {
|
||||||
|
pub(crate) fn new(
|
||||||
|
context: ServerContext,
|
||||||
|
tx: Sender<Result<UserAgentResponse, Status>>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
db: context.db.clone(),
|
||||||
|
bootstapper: context.bootstrapper.clone(),
|
||||||
|
state: UserAgentStateMachine::new(DummyContext),
|
||||||
|
tx,
|
||||||
|
context,
|
||||||
|
ephemeral_key: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn new_manual(
|
||||||
|
db: db::DatabasePool,
|
||||||
|
bootstapper: ActorRef<BootstrapActor>,
|
||||||
|
context: ServerContext,
|
||||||
|
tx: Sender<Result<UserAgentResponse, Status>>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
db,
|
||||||
|
bootstapper,
|
||||||
|
state: UserAgentStateMachine::new(DummyContext),
|
||||||
|
tx,
|
||||||
|
context,
|
||||||
|
ephemeral_key: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn transition(&mut self, event: UserAgentEvents) -> Result<(), Status> {
|
||||||
|
self.state.process_event(event).map_err(|e| {
|
||||||
|
error!(?e, "State transition failed");
|
||||||
|
Status::internal("State machine error")
|
||||||
|
})?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn auth_with_bootstrap_token(
|
||||||
|
&mut self,
|
||||||
|
pubkey: ed25519_dalek::VerifyingKey,
|
||||||
|
token: String,
|
||||||
|
) -> Result<UserAgentResponse, Status> {
|
||||||
|
let token_ok: bool = self
|
||||||
|
.bootstapper
|
||||||
|
.ask(ConsumeToken { token })
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
error!(?pubkey, "Failed to consume bootstrap token: {e}");
|
||||||
|
Status::internal("Bootstrap token consumption failed")
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if !token_ok {
|
||||||
|
error!(?pubkey, "Invalid bootstrap token provided");
|
||||||
|
return Err(Status::invalid_argument("Invalid bootstrap token"));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut conn = self.db.get().await.to_status()?;
|
||||||
|
|
||||||
|
diesel::insert_into(schema::useragent_client::table)
|
||||||
|
.values((
|
||||||
|
schema::useragent_client::public_key.eq(pubkey.as_bytes().to_vec()),
|
||||||
|
schema::useragent_client::nonce.eq(1),
|
||||||
|
))
|
||||||
|
.execute(&mut conn)
|
||||||
|
.await
|
||||||
|
.to_status()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.transition(UserAgentEvents::ReceivedBootstrapToken)?;
|
||||||
|
|
||||||
|
Ok(auth_response(ServerAuthPayload::AuthOk(auth::AuthOk {})))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn auth_with_challenge(&mut self, pubkey: VerifyingKey, pubkey_bytes: Vec<u8>) -> Output {
|
||||||
|
let nonce: Option<i32> = {
|
||||||
|
let mut db_conn = self.db.get().await.to_status()?;
|
||||||
|
db_conn
|
||||||
|
.transaction(|conn| {
|
||||||
|
Box::pin(async move {
|
||||||
|
let current_nonce = schema::useragent_client::table
|
||||||
|
.filter(
|
||||||
|
schema::useragent_client::public_key.eq(pubkey.as_bytes().to_vec()),
|
||||||
|
)
|
||||||
|
.select(schema::useragent_client::nonce)
|
||||||
|
.first::<i32>(conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
update(schema::useragent_client::table)
|
||||||
|
.filter(
|
||||||
|
schema::useragent_client::public_key.eq(pubkey.as_bytes().to_vec()),
|
||||||
|
)
|
||||||
|
.set(schema::useragent_client::nonce.eq(current_nonce + 1))
|
||||||
|
.execute(conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Result::<_, diesel::result::Error>::Ok(current_nonce)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.optional()
|
||||||
|
.to_status()?
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some(nonce) = nonce else {
|
||||||
|
error!(?pubkey, "Public key not found in database");
|
||||||
|
return Err(Status::unauthenticated("Public key not registered"));
|
||||||
|
};
|
||||||
|
|
||||||
|
let challenge = auth::AuthChallenge {
|
||||||
|
pubkey: pubkey_bytes,
|
||||||
|
nonce,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.transition(UserAgentEvents::SentChallenge(ChallengeContext {
|
||||||
|
challenge: challenge.clone(),
|
||||||
|
key: pubkey,
|
||||||
|
}))?;
|
||||||
|
|
||||||
|
info!(
|
||||||
|
?pubkey,
|
||||||
|
?challenge,
|
||||||
|
"Sent authentication challenge to client"
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(auth_response(ServerAuthPayload::AuthChallenge(challenge)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify_challenge_solution(
|
||||||
|
&self,
|
||||||
|
solution: &auth::AuthChallengeSolution,
|
||||||
|
) -> Result<(bool, &ChallengeContext), Status> {
|
||||||
|
let UserAgentStates::WaitingForChallengeSolution(challenge_context) = self.state.state()
|
||||||
|
else {
|
||||||
|
error!("Received challenge solution in invalid state");
|
||||||
|
return Err(Status::invalid_argument(
|
||||||
|
"Invalid state for challenge solution",
|
||||||
|
));
|
||||||
|
};
|
||||||
|
let formatted_challenge = arbiter_proto::format_challenge(&challenge_context.challenge);
|
||||||
|
|
||||||
|
let signature = solution.signature.as_slice().try_into().map_err(|_| {
|
||||||
|
error!(?solution, "Invalid signature length");
|
||||||
|
Status::invalid_argument("Invalid signature length")
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let valid = challenge_context
|
||||||
|
.key
|
||||||
|
.verify_strict(&formatted_challenge, &signature)
|
||||||
|
.is_ok();
|
||||||
|
|
||||||
|
Ok((valid, challenge_context))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Output = Result<UserAgentResponse, Status>;
|
||||||
|
|
||||||
|
fn auth_response(payload: ServerAuthPayload) -> UserAgentResponse {
|
||||||
|
UserAgentResponse {
|
||||||
|
payload: Some(UserAgentResponsePayload::AuthMessage(AuthServerMessage {
|
||||||
|
payload: Some(payload),
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[messages]
|
||||||
|
impl UserAgentActor {
|
||||||
|
#[message(ctx)]
|
||||||
|
pub async fn handle_auth_challenge_request(
|
||||||
|
&mut self,
|
||||||
|
req: AuthChallengeRequest,
|
||||||
|
ctx: &mut Context<Self, Output>,
|
||||||
|
) -> Output {
|
||||||
|
let pubkey = req.pubkey.as_array().ok_or(Status::invalid_argument(
|
||||||
|
"Expected pubkey to have specific length",
|
||||||
|
))?;
|
||||||
|
let pubkey = VerifyingKey::from_bytes(pubkey).map_err(|err| {
|
||||||
|
error!(?pubkey, "Failed to convert to VerifyingKey");
|
||||||
|
Status::invalid_argument("Failed to convert pubkey to VerifyingKey")
|
||||||
|
})?;
|
||||||
|
|
||||||
|
self.transition(UserAgentEvents::AuthRequest(AuthRequestContext {
|
||||||
|
pubkey,
|
||||||
|
bootstrap_token: req.bootstrap_token.clone(),
|
||||||
|
}))?;
|
||||||
|
|
||||||
|
match req.bootstrap_token {
|
||||||
|
Some(token) => self.auth_with_bootstrap_token(pubkey, token).await,
|
||||||
|
None => self.auth_with_challenge(pubkey, req.pubkey).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[message(ctx)]
|
||||||
|
pub async fn handle_auth_challenge_solution(
|
||||||
|
&mut self,
|
||||||
|
solution: auth::AuthChallengeSolution,
|
||||||
|
ctx: &mut Context<Self, Output>,
|
||||||
|
) -> Output {
|
||||||
|
let (valid, challenge_context) = self.verify_challenge_solution(&solution)?;
|
||||||
|
|
||||||
|
if valid {
|
||||||
|
info!(
|
||||||
|
?challenge_context,
|
||||||
|
"Client provided valid solution to authentication challenge"
|
||||||
|
);
|
||||||
|
self.transition(UserAgentEvents::ReceivedGoodSolution)?;
|
||||||
|
Ok(auth_response(ServerAuthPayload::AuthOk(auth::AuthOk {})))
|
||||||
|
} else {
|
||||||
|
error!("Client provided invalid solution to authentication challenge");
|
||||||
|
self.transition(UserAgentEvents::ReceivedBadSolution)?;
|
||||||
|
Err(Status::unauthenticated("Invalid challenge solution"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[message(ctx)]
|
||||||
|
pub async fn handle_unseal_request(
|
||||||
|
&mut self,
|
||||||
|
request: arbiter_proto::proto::UnsealRequest,
|
||||||
|
ctx: &mut Context<Self, Output>,
|
||||||
|
) -> Output {
|
||||||
|
use arbiter_proto::proto::{
|
||||||
|
EphemeralKeyResponse, SealedPassword, UnsealResponse, UnsealResult,
|
||||||
|
unseal_request::Payload as ReqPayload,
|
||||||
|
unseal_response::Payload as RespPayload,
|
||||||
|
};
|
||||||
|
|
||||||
|
match request.payload {
|
||||||
|
Some(ReqPayload::EphemeralKeyRequest(_)) => {
|
||||||
|
// Generate new ephemeral keypair
|
||||||
|
let keypair = crate::context::unseal::EphemeralKeyPair::generate();
|
||||||
|
let expires_at = keypair.expires_at() as i64;
|
||||||
|
let public_bytes = keypair.public_bytes();
|
||||||
|
|
||||||
|
// Store for later use
|
||||||
|
self.ephemeral_key = Some(keypair);
|
||||||
|
|
||||||
|
info!("Generated ephemeral X25519 keypair for unseal, expires at {}", expires_at);
|
||||||
|
|
||||||
|
Ok(UserAgentResponse {
|
||||||
|
payload: Some(UserAgentResponsePayload::UnsealResponse(UnsealResponse {
|
||||||
|
payload: Some(RespPayload::EphemeralKeyResponse(EphemeralKeyResponse {
|
||||||
|
server_pubkey: public_bytes,
|
||||||
|
expires_at,
|
||||||
|
})),
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(ReqPayload::SealedPassword(sealed)) => {
|
||||||
|
// Get and consume ephemeral key
|
||||||
|
let keypair = self
|
||||||
|
.ephemeral_key
|
||||||
|
.take()
|
||||||
|
.ok_or_else(|| Status::failed_precondition("No ephemeral key generated"))?;
|
||||||
|
|
||||||
|
// Check expiration
|
||||||
|
if keypair.is_expired() {
|
||||||
|
error!("Ephemeral key expired before sealed password was received");
|
||||||
|
return Err(Status::deadline_exceeded("Ephemeral key expired"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform ECDH
|
||||||
|
let shared_secret = keypair
|
||||||
|
.perform_dh(&sealed.client_pubkey)
|
||||||
|
.map_err(|e| Status::invalid_argument(format!("Invalid client pubkey: {}", e)))?;
|
||||||
|
|
||||||
|
// Decrypt password
|
||||||
|
let nonce: [u8; 12] = sealed
|
||||||
|
.nonce
|
||||||
|
.as_slice()
|
||||||
|
.try_into()
|
||||||
|
.map_err(|_| Status::invalid_argument("Nonce must be 12 bytes"))?;
|
||||||
|
|
||||||
|
let password_bytes = crate::crypto::aead::decrypt(
|
||||||
|
&sealed.encrypted_password,
|
||||||
|
&shared_secret,
|
||||||
|
&nonce,
|
||||||
|
)
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Failed to decrypt password: {}", e);
|
||||||
|
Status::internal(format!("Decryption failed: {}", e))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let password = String::from_utf8(password_bytes).map_err(|_| {
|
||||||
|
error!("Password is not valid UTF-8");
|
||||||
|
Status::invalid_argument("Password must be UTF-8")
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// Call unseal on context
|
||||||
|
info!("Attempting to unseal vault with decrypted password");
|
||||||
|
let result = self.context.unseal(&password).await;
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(()) => {
|
||||||
|
info!("Vault unsealed successfully");
|
||||||
|
Ok(UserAgentResponse {
|
||||||
|
payload: Some(UserAgentResponsePayload::UnsealResponse(
|
||||||
|
UnsealResponse {
|
||||||
|
payload: Some(RespPayload::UnsealResult(UnsealResult {
|
||||||
|
success: true,
|
||||||
|
error_message: None,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("Unseal failed: {}", e);
|
||||||
|
Ok(UserAgentResponse {
|
||||||
|
payload: Some(UserAgentResponsePayload::UnsealResponse(
|
||||||
|
UnsealResponse {
|
||||||
|
payload: Some(RespPayload::UnsealResult(UnsealResult {
|
||||||
|
success: false,
|
||||||
|
error_message: Some(e.to_string()),
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None => {
|
||||||
|
error!("Received empty unseal request");
|
||||||
|
Err(Status::invalid_argument("Empty unseal request"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use arbiter_proto::proto::{
|
||||||
|
UserAgentResponse,
|
||||||
|
auth::{AuthChallengeRequest, AuthOk},
|
||||||
|
user_agent_response::Payload as UserAgentResponsePayload,
|
||||||
|
};
|
||||||
|
use kameo::actor::Spawn;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
actors::user_agent::HandleAuthChallengeRequest, context::bootstrap::BootstrapActor, db,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::UserAgentActor;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[test_log::test]
|
||||||
|
pub async fn test_bootstrap_token_auth() {
|
||||||
|
let db = db::create_test_pool().await;
|
||||||
|
// explicitly not installing any user_agent pubkeys
|
||||||
|
let bootstrapper = BootstrapActor::new(&db).await.unwrap(); // this will create bootstrap token
|
||||||
|
let token = bootstrapper.get_token().unwrap();
|
||||||
|
|
||||||
|
let bootstrapper_ref = BootstrapActor::spawn(bootstrapper);
|
||||||
|
let context = crate::ServerContext::new(db.clone()).await.unwrap();
|
||||||
|
let user_agent = UserAgentActor::new_manual(
|
||||||
|
db.clone(),
|
||||||
|
bootstrapper_ref,
|
||||||
|
context,
|
||||||
|
tokio::sync::mpsc::channel(1).0, // dummy channel, we won't actually send responses in this test
|
||||||
|
);
|
||||||
|
let user_agent_ref = UserAgentActor::spawn(user_agent);
|
||||||
|
|
||||||
|
// simulate client sending auth request with bootstrap token
|
||||||
|
let new_key = ed25519_dalek::SigningKey::generate(&mut rand::rng());
|
||||||
|
let pubkey_bytes = new_key.verifying_key().to_bytes().to_vec();
|
||||||
|
|
||||||
|
let result = user_agent_ref
|
||||||
|
.ask(HandleAuthChallengeRequest {
|
||||||
|
req: AuthChallengeRequest {
|
||||||
|
pubkey: pubkey_bytes,
|
||||||
|
bootstrap_token: Some(token),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.expect("Shouldn't fail to send message");
|
||||||
|
|
||||||
|
// auth succeeded
|
||||||
|
assert_eq!(
|
||||||
|
result,
|
||||||
|
UserAgentResponse {
|
||||||
|
payload: Some(UserAgentResponsePayload::AuthMessage(
|
||||||
|
arbiter_proto::proto::auth::ServerMessage {
|
||||||
|
payload: Some(arbiter_proto::proto::auth::server_message::Payload::AuthOk(
|
||||||
|
AuthOk {},
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod transport;
|
||||||
|
pub(crate) use transport::handle_user_agent;
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
use tonic::Status;
|
|
||||||
|
|
||||||
use crate::db;
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum UserAgentError {
|
|
||||||
#[error("Missing payload in request")]
|
|
||||||
MissingPayload,
|
|
||||||
|
|
||||||
#[error("Invalid bootstrap token")]
|
|
||||||
InvalidBootstrapToken,
|
|
||||||
|
|
||||||
#[error("Public key not registered")]
|
|
||||||
PubkeyNotRegistered,
|
|
||||||
|
|
||||||
#[error("Invalid public key format")]
|
|
||||||
InvalidPubkey,
|
|
||||||
|
|
||||||
#[error("Invalid signature length")]
|
|
||||||
InvalidSignatureLength,
|
|
||||||
|
|
||||||
#[error("Invalid challenge solution")]
|
|
||||||
InvalidChallengeSolution,
|
|
||||||
|
|
||||||
#[error("Invalid state for operation")]
|
|
||||||
InvalidState,
|
|
||||||
|
|
||||||
#[error("Actor unavailable")]
|
|
||||||
ActorUnavailable,
|
|
||||||
|
|
||||||
#[error("Database error")]
|
|
||||||
Database(#[from] diesel::result::Error),
|
|
||||||
|
|
||||||
#[error("Database pool error")]
|
|
||||||
DatabasePool(#[from] db::PoolError),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<UserAgentError> for Status {
|
|
||||||
fn from(err: UserAgentError) -> Self {
|
|
||||||
match err {
|
|
||||||
UserAgentError::MissingPayload
|
|
||||||
| UserAgentError::InvalidBootstrapToken
|
|
||||||
| UserAgentError::InvalidPubkey
|
|
||||||
| UserAgentError::InvalidSignatureLength => Status::invalid_argument(err.to_string()),
|
|
||||||
|
|
||||||
UserAgentError::PubkeyNotRegistered | UserAgentError::InvalidChallengeSolution => {
|
|
||||||
Status::unauthenticated(err.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
UserAgentError::InvalidState => Status::failed_precondition(err.to_string()),
|
|
||||||
|
|
||||||
UserAgentError::ActorUnavailable
|
|
||||||
| UserAgentError::Database(_)
|
|
||||||
| UserAgentError::DatabasePool(_) => Status::internal(err.to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,401 +0,0 @@
|
|||||||
use std::{ops::DerefMut, sync::Mutex};
|
|
||||||
|
|
||||||
use arbiter_proto::proto::{
|
|
||||||
UnsealEncryptedKey, UnsealResult, UnsealStart, UnsealStartResponse, UserAgentRequest,
|
|
||||||
UserAgentResponse,
|
|
||||||
auth::{
|
|
||||||
self, AuthChallengeRequest, AuthOk, ClientMessage as ClientAuthMessage,
|
|
||||||
ServerMessage as AuthServerMessage,
|
|
||||||
client_message::Payload as ClientAuthPayload,
|
|
||||||
server_message::Payload as ServerAuthPayload,
|
|
||||||
},
|
|
||||||
user_agent_request::Payload as UserAgentRequestPayload,
|
|
||||||
user_agent_response::Payload as UserAgentResponsePayload,
|
|
||||||
};
|
|
||||||
use chacha20poly1305::{AeadInPlace, XChaCha20Poly1305, XNonce, aead::KeyInit};
|
|
||||||
use diesel::{ExpressionMethods as _, OptionalExtension as _, QueryDsl, dsl::update};
|
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use ed25519_dalek::VerifyingKey;
|
|
||||||
use kameo::{Actor, actor::Recipient, error::SendError, messages, prelude::Message};
|
|
||||||
use memsafe::MemSafe;
|
|
||||||
use tracing::{error, info};
|
|
||||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
ServerContext,
|
|
||||||
actors::{
|
|
||||||
GlobalActors,
|
|
||||||
bootstrap::ConsumeToken,
|
|
||||||
keyholder::{self, TryUnseal},
|
|
||||||
user_agent::state::{
|
|
||||||
ChallengeContext, DummyContext, UnsealContext, UserAgentEvents, UserAgentStateMachine,
|
|
||||||
UserAgentStates,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
db::{self, schema},
|
|
||||||
};
|
|
||||||
|
|
||||||
mod error;
|
|
||||||
mod state;
|
|
||||||
|
|
||||||
pub use error::UserAgentError;
|
|
||||||
|
|
||||||
#[derive(Actor)]
|
|
||||||
pub struct UserAgentActor {
|
|
||||||
db: db::DatabasePool,
|
|
||||||
actors: GlobalActors,
|
|
||||||
state: UserAgentStateMachine<DummyContext>,
|
|
||||||
transport: Recipient<Result<UserAgentResponse, UserAgentError>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserAgentActor {
|
|
||||||
pub(crate) fn new(
|
|
||||||
context: ServerContext,
|
|
||||||
transport: Recipient<Result<UserAgentResponse, UserAgentError>>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
db: context.db.clone(),
|
|
||||||
actors: context.actors.clone(),
|
|
||||||
state: UserAgentStateMachine::new(DummyContext),
|
|
||||||
transport,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_manual(
|
|
||||||
db: db::DatabasePool,
|
|
||||||
actors: GlobalActors,
|
|
||||||
transport: Recipient<Result<UserAgentResponse, UserAgentError>>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
db,
|
|
||||||
actors,
|
|
||||||
state: UserAgentStateMachine::new(DummyContext),
|
|
||||||
transport,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn process_request(&mut self, req: UserAgentRequest) -> Output {
|
|
||||||
let msg = req.payload.ok_or_else(|| {
|
|
||||||
error!(actor = "useragent", "Received message with no payload");
|
|
||||||
UserAgentError::MissingPayload
|
|
||||||
})?;
|
|
||||||
|
|
||||||
match msg {
|
|
||||||
UserAgentRequestPayload::AuthMessage(ClientAuthMessage {
|
|
||||||
payload: Some(ClientAuthPayload::AuthChallengeRequest(req)),
|
|
||||||
}) => self.handle_auth_challenge_request(req).await,
|
|
||||||
UserAgentRequestPayload::AuthMessage(ClientAuthMessage {
|
|
||||||
payload: Some(ClientAuthPayload::AuthChallengeSolution(solution)),
|
|
||||||
}) => self.handle_auth_challenge_solution(solution).await,
|
|
||||||
UserAgentRequestPayload::UnsealStart(unseal_start) => {
|
|
||||||
self.handle_unseal_request(unseal_start).await
|
|
||||||
}
|
|
||||||
UserAgentRequestPayload::UnsealEncryptedKey(unseal_encrypted_key) => {
|
|
||||||
self.handle_unseal_encrypted_key(unseal_encrypted_key).await
|
|
||||||
}
|
|
||||||
_ => Err(UserAgentError::MissingPayload),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn transition(&mut self, event: UserAgentEvents) -> Result<(), UserAgentError> {
|
|
||||||
self.state.process_event(event).map_err(|e| {
|
|
||||||
error!(?e, "State transition failed");
|
|
||||||
UserAgentError::InvalidState
|
|
||||||
})?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn auth_with_bootstrap_token(
|
|
||||||
&mut self,
|
|
||||||
pubkey: ed25519_dalek::VerifyingKey,
|
|
||||||
token: String,
|
|
||||||
) -> Output {
|
|
||||||
let token_ok: bool = self
|
|
||||||
.actors
|
|
||||||
.bootstrapper
|
|
||||||
.ask(ConsumeToken { token })
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
error!(?pubkey, "Failed to consume bootstrap token: {e}");
|
|
||||||
UserAgentError::ActorUnavailable
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if !token_ok {
|
|
||||||
error!(?pubkey, "Invalid bootstrap token provided");
|
|
||||||
return Err(UserAgentError::InvalidBootstrapToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut conn = self.db.get().await?;
|
|
||||||
|
|
||||||
diesel::insert_into(schema::useragent_client::table)
|
|
||||||
.values((
|
|
||||||
schema::useragent_client::public_key.eq(pubkey.as_bytes().to_vec()),
|
|
||||||
schema::useragent_client::nonce.eq(1),
|
|
||||||
))
|
|
||||||
.execute(&mut conn)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.transition(UserAgentEvents::ReceivedBootstrapToken)?;
|
|
||||||
|
|
||||||
Ok(auth_response(ServerAuthPayload::AuthOk(AuthOk {})))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn auth_with_challenge(&mut self, pubkey: VerifyingKey, pubkey_bytes: Vec<u8>) -> Output {
|
|
||||||
let nonce: Option<i32> = {
|
|
||||||
let mut db_conn = self.db.get().await?;
|
|
||||||
db_conn
|
|
||||||
.exclusive_transaction(|conn| {
|
|
||||||
Box::pin(async move {
|
|
||||||
let current_nonce = schema::useragent_client::table
|
|
||||||
.filter(
|
|
||||||
schema::useragent_client::public_key.eq(pubkey.as_bytes().to_vec()),
|
|
||||||
)
|
|
||||||
.select(schema::useragent_client::nonce)
|
|
||||||
.first::<i32>(conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
update(schema::useragent_client::table)
|
|
||||||
.filter(
|
|
||||||
schema::useragent_client::public_key.eq(pubkey.as_bytes().to_vec()),
|
|
||||||
)
|
|
||||||
.set(schema::useragent_client::nonce.eq(current_nonce + 1))
|
|
||||||
.execute(conn)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Result::<_, diesel::result::Error>::Ok(current_nonce)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.optional()?
|
|
||||||
};
|
|
||||||
|
|
||||||
let Some(nonce) = nonce else {
|
|
||||||
error!(?pubkey, "Public key not found in database");
|
|
||||||
return Err(UserAgentError::PubkeyNotRegistered);
|
|
||||||
};
|
|
||||||
|
|
||||||
let challenge = auth::AuthChallenge {
|
|
||||||
pubkey: pubkey_bytes,
|
|
||||||
nonce,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.transition(UserAgentEvents::SentChallenge(ChallengeContext {
|
|
||||||
challenge: challenge.clone(),
|
|
||||||
key: pubkey,
|
|
||||||
}))?;
|
|
||||||
|
|
||||||
info!(
|
|
||||||
?pubkey,
|
|
||||||
?challenge,
|
|
||||||
"Sent authentication challenge to client"
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(auth_response(ServerAuthPayload::AuthChallenge(challenge)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn verify_challenge_solution(
|
|
||||||
&self,
|
|
||||||
solution: &auth::AuthChallengeSolution,
|
|
||||||
) -> Result<(bool, &ChallengeContext), UserAgentError> {
|
|
||||||
let UserAgentStates::WaitingForChallengeSolution(challenge_context) = self.state.state()
|
|
||||||
else {
|
|
||||||
error!("Received challenge solution in invalid state");
|
|
||||||
return Err(UserAgentError::InvalidState);
|
|
||||||
};
|
|
||||||
let formatted_challenge = arbiter_proto::format_challenge(&challenge_context.challenge);
|
|
||||||
|
|
||||||
let signature = solution.signature.as_slice().try_into().map_err(|_| {
|
|
||||||
error!(?solution, "Invalid signature length");
|
|
||||||
UserAgentError::InvalidSignatureLength
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let valid = challenge_context
|
|
||||||
.key
|
|
||||||
.verify_strict(&formatted_challenge, &signature)
|
|
||||||
.is_ok();
|
|
||||||
|
|
||||||
Ok((valid, challenge_context))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Output = Result<UserAgentResponse, UserAgentError>;
|
|
||||||
|
|
||||||
fn auth_response(payload: ServerAuthPayload) -> UserAgentResponse {
|
|
||||||
UserAgentResponse {
|
|
||||||
payload: Some(UserAgentResponsePayload::AuthMessage(AuthServerMessage {
|
|
||||||
payload: Some(payload),
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unseal_response(payload: UserAgentResponsePayload) -> UserAgentResponse {
|
|
||||||
UserAgentResponse {
|
|
||||||
payload: Some(payload),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[messages]
|
|
||||||
impl UserAgentActor {
|
|
||||||
#[message]
|
|
||||||
pub async fn handle_unseal_request(&mut self, req: UnsealStart) -> Output {
|
|
||||||
let secret = EphemeralSecret::random();
|
|
||||||
let public_key = PublicKey::from(&secret);
|
|
||||||
|
|
||||||
let client_pubkey_bytes: [u8; 32] = req
|
|
||||||
.client_pubkey
|
|
||||||
.try_into()
|
|
||||||
.map_err(|_| UserAgentError::InvalidPubkey)?;
|
|
||||||
|
|
||||||
let client_public_key = PublicKey::from(client_pubkey_bytes);
|
|
||||||
|
|
||||||
self.transition(UserAgentEvents::UnsealRequest(UnsealContext {
|
|
||||||
secret: Mutex::new(Some(secret)),
|
|
||||||
client_public_key,
|
|
||||||
}))?;
|
|
||||||
|
|
||||||
Ok(unseal_response(
|
|
||||||
UserAgentResponsePayload::UnsealStartResponse(UnsealStartResponse {
|
|
||||||
server_pubkey: public_key.as_bytes().to_vec(),
|
|
||||||
}),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[message]
|
|
||||||
pub async fn handle_unseal_encrypted_key(&mut self, req: UnsealEncryptedKey) -> Output {
|
|
||||||
let UserAgentStates::WaitingForUnsealKey(unseal_context) = self.state.state() else {
|
|
||||||
error!("Received unseal encrypted key in invalid state");
|
|
||||||
return Err(UserAgentError::InvalidState);
|
|
||||||
};
|
|
||||||
let ephemeral_secret = {
|
|
||||||
let mut secret_lock = unseal_context.secret.lock().unwrap();
|
|
||||||
let secret = secret_lock.take();
|
|
||||||
match secret {
|
|
||||||
Some(secret) => secret,
|
|
||||||
None => {
|
|
||||||
drop(secret_lock);
|
|
||||||
error!("Ephemeral secret already taken");
|
|
||||||
self.transition(UserAgentEvents::ReceivedInvalidKey)?;
|
|
||||||
return Ok(unseal_response(UserAgentResponsePayload::UnsealResult(
|
|
||||||
UnsealResult::InvalidKey.into(),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let nonce = XNonce::from_slice(&req.nonce);
|
|
||||||
|
|
||||||
let shared_secret = ephemeral_secret.diffie_hellman(&unseal_context.client_public_key);
|
|
||||||
let cipher = XChaCha20Poly1305::new(shared_secret.as_bytes().into());
|
|
||||||
|
|
||||||
let mut seal_key_buffer = MemSafe::new(req.ciphertext.clone()).unwrap();
|
|
||||||
|
|
||||||
let decryption_result = {
|
|
||||||
let mut write_handle = seal_key_buffer.write().unwrap();
|
|
||||||
let write_handle = write_handle.deref_mut();
|
|
||||||
cipher.decrypt_in_place(nonce, &req.associated_data, write_handle)
|
|
||||||
};
|
|
||||||
|
|
||||||
match decryption_result {
|
|
||||||
Ok(_) => {
|
|
||||||
match self
|
|
||||||
.actors
|
|
||||||
.key_holder
|
|
||||||
.ask(TryUnseal {
|
|
||||||
seal_key_raw: seal_key_buffer,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(_) => {
|
|
||||||
info!("Successfully unsealed key with client-provided key");
|
|
||||||
self.transition(UserAgentEvents::ReceivedValidKey)?;
|
|
||||||
Ok(unseal_response(UserAgentResponsePayload::UnsealResult(
|
|
||||||
UnsealResult::Success.into(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
Err(SendError::HandlerError(keyholder::Error::InvalidKey)) => {
|
|
||||||
self.transition(UserAgentEvents::ReceivedInvalidKey)?;
|
|
||||||
Ok(unseal_response(UserAgentResponsePayload::UnsealResult(
|
|
||||||
UnsealResult::InvalidKey.into(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
Err(SendError::HandlerError(err)) => {
|
|
||||||
error!(?err, "Keyholder failed to unseal key");
|
|
||||||
self.transition(UserAgentEvents::ReceivedInvalidKey)?;
|
|
||||||
Ok(unseal_response(UserAgentResponsePayload::UnsealResult(
|
|
||||||
UnsealResult::InvalidKey.into(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
error!(?err, "Failed to send unseal request to keyholder");
|
|
||||||
self.transition(UserAgentEvents::ReceivedInvalidKey)?;
|
|
||||||
Err(UserAgentError::ActorUnavailable)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
error!(?err, "Failed to decrypt unseal key");
|
|
||||||
self.transition(UserAgentEvents::ReceivedInvalidKey)?;
|
|
||||||
Ok(unseal_response(UserAgentResponsePayload::UnsealResult(
|
|
||||||
UnsealResult::InvalidKey.into(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[message]
|
|
||||||
pub async fn handle_auth_challenge_request(&mut self, req: AuthChallengeRequest) -> Output {
|
|
||||||
let pubkey = req
|
|
||||||
.pubkey
|
|
||||||
.as_array()
|
|
||||||
.ok_or(UserAgentError::InvalidPubkey)?;
|
|
||||||
let pubkey = VerifyingKey::from_bytes(pubkey).map_err(|_err| {
|
|
||||||
error!(?pubkey, "Failed to convert to VerifyingKey");
|
|
||||||
UserAgentError::InvalidPubkey
|
|
||||||
})?;
|
|
||||||
|
|
||||||
self.transition(UserAgentEvents::AuthRequest)?;
|
|
||||||
|
|
||||||
match req.bootstrap_token {
|
|
||||||
Some(token) => self.auth_with_bootstrap_token(pubkey, token).await,
|
|
||||||
None => self.auth_with_challenge(pubkey, req.pubkey).await,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[message]
|
|
||||||
pub async fn handle_auth_challenge_solution(
|
|
||||||
&mut self,
|
|
||||||
solution: auth::AuthChallengeSolution,
|
|
||||||
) -> Output {
|
|
||||||
let (valid, challenge_context) = self.verify_challenge_solution(&solution)?;
|
|
||||||
|
|
||||||
if valid {
|
|
||||||
info!(
|
|
||||||
?challenge_context,
|
|
||||||
"Client provided valid solution to authentication challenge"
|
|
||||||
);
|
|
||||||
self.transition(UserAgentEvents::ReceivedGoodSolution)?;
|
|
||||||
Ok(auth_response(ServerAuthPayload::AuthOk(AuthOk {})))
|
|
||||||
} else {
|
|
||||||
error!("Client provided invalid solution to authentication challenge");
|
|
||||||
self.transition(UserAgentEvents::ReceivedBadSolution)?;
|
|
||||||
Err(UserAgentError::InvalidChallengeSolution)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Message<UserAgentRequest> for UserAgentActor {
|
|
||||||
type Reply = ();
|
|
||||||
|
|
||||||
async fn handle(
|
|
||||||
&mut self,
|
|
||||||
msg: UserAgentRequest,
|
|
||||||
_ctx: &mut kameo::prelude::Context<Self, Self::Reply>,
|
|
||||||
) -> Self::Reply {
|
|
||||||
let result = self.process_request(msg).await;
|
|
||||||
if let Err(e) = self.transport.tell(result).await {
|
|
||||||
error!(actor = "useragent", "Failed to send response to transport: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
use arbiter_proto::proto::auth::AuthChallenge;
|
|
||||||
use ed25519_dalek::VerifyingKey;
|
|
||||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
|
||||||
|
|
||||||
/// Context for state machine with validated key and sent challenge
|
|
||||||
/// Challenge is then transformed to bytes using shared function and verified
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct ChallengeContext {
|
|
||||||
pub challenge: AuthChallenge,
|
|
||||||
pub key: VerifyingKey,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UnsealContext {
|
|
||||||
pub client_public_key: PublicKey,
|
|
||||||
pub secret: Mutex<Option<EphemeralSecret>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
smlang::statemachine!(
|
|
||||||
name: UserAgent,
|
|
||||||
custom_error: false,
|
|
||||||
transitions: {
|
|
||||||
*Init + AuthRequest = ReceivedAuthRequest,
|
|
||||||
ReceivedAuthRequest + ReceivedBootstrapToken = Idle,
|
|
||||||
|
|
||||||
ReceivedAuthRequest + SentChallenge(ChallengeContext) / move_challenge = WaitingForChallengeSolution(ChallengeContext),
|
|
||||||
|
|
||||||
WaitingForChallengeSolution(ChallengeContext) + ReceivedGoodSolution = Idle,
|
|
||||||
WaitingForChallengeSolution(ChallengeContext) + ReceivedBadSolution = AuthError, // block further transitions, but connection should close anyway
|
|
||||||
|
|
||||||
Idle + UnsealRequest(UnsealContext) / generate_temp_keypair = WaitingForUnsealKey(UnsealContext),
|
|
||||||
WaitingForUnsealKey(UnsealContext) + ReceivedValidKey = Unsealed,
|
|
||||||
WaitingForUnsealKey(UnsealContext) + ReceivedInvalidKey = Idle,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
pub struct DummyContext;
|
|
||||||
impl UserAgentStateMachineContext for DummyContext {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
#[allow(clippy::unused_unit)]
|
|
||||||
fn generate_temp_keypair(&mut self, event_data: UnsealContext) -> Result<UnsealContext, ()> {
|
|
||||||
Ok(event_data)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
#[allow(clippy::unused_unit)]
|
|
||||||
fn move_challenge(&mut self, event_data: ChallengeContext) -> Result<ChallengeContext, ()> {
|
|
||||||
Ok(event_data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
use super::UserAgentActor;
|
||||||
|
use arbiter_proto::proto::{
|
||||||
|
UserAgentRequest, UserAgentResponse,
|
||||||
|
auth::{
|
||||||
|
self, AuthChallenge, AuthChallengeRequest, AuthOk, ClientMessage,
|
||||||
|
ServerMessage as AuthServerMessage, client_message::Payload as ClientAuthPayload,
|
||||||
|
server_message::Payload as ServerAuthPayload,
|
||||||
|
},
|
||||||
|
user_agent_request::Payload as UserAgentRequestPayload,
|
||||||
|
user_agent_response::Payload as UserAgentResponsePayload,
|
||||||
|
};
|
||||||
|
use futures::StreamExt;
|
||||||
|
use kameo::{
|
||||||
|
actor::{ActorRef, Spawn as _},
|
||||||
|
error::SendError,
|
||||||
|
};
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
use tonic::Status;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
actors::user_agent::{HandleAuthChallengeRequest, HandleAuthChallengeSolution},
|
||||||
|
context::ServerContext,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub(crate) async fn handle_user_agent(
|
||||||
|
context: ServerContext,
|
||||||
|
mut req_stream: tonic::Streaming<UserAgentRequest>,
|
||||||
|
tx: mpsc::Sender<Result<UserAgentResponse, Status>>,
|
||||||
|
) {
|
||||||
|
let actor = UserAgentActor::spawn(UserAgentActor::new(context, tx.clone()));
|
||||||
|
|
||||||
|
while let Some(Ok(req)) = req_stream.next().await
|
||||||
|
&& actor.is_alive()
|
||||||
|
{
|
||||||
|
match process_message(&actor, req).await {
|
||||||
|
Ok(resp) => {
|
||||||
|
if tx.send(Ok(resp)).await.is_err() {
|
||||||
|
error!(actor = "useragent", "Failed to send response to client");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(status) => {
|
||||||
|
let _ = tx.send(Err(status)).await;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actor.kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn process_message(
|
||||||
|
actor: &ActorRef<UserAgentActor>,
|
||||||
|
req: UserAgentRequest,
|
||||||
|
) -> Result<UserAgentResponse, Status> {
|
||||||
|
let msg = req.payload.ok_or_else(|| {
|
||||||
|
error!(actor = "useragent", "Received message with no payload");
|
||||||
|
Status::invalid_argument("Expected message with payload")
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let UserAgentRequestPayload::AuthMessage(ClientMessage {
|
||||||
|
payload: Some(client_message),
|
||||||
|
}) = msg
|
||||||
|
else {
|
||||||
|
error!(
|
||||||
|
actor = "useragent",
|
||||||
|
"Received unexpected message type during authentication"
|
||||||
|
);
|
||||||
|
return Err(Status::invalid_argument(
|
||||||
|
"Expected AuthMessage with ClientMessage payload",
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
match client_message {
|
||||||
|
ClientAuthPayload::AuthChallengeRequest(req) => actor
|
||||||
|
.ask(HandleAuthChallengeRequest { req })
|
||||||
|
.await
|
||||||
|
.map_err(into_status),
|
||||||
|
ClientAuthPayload::AuthChallengeSolution(solution) => actor
|
||||||
|
.ask(HandleAuthChallengeSolution { solution })
|
||||||
|
.await
|
||||||
|
.map_err(into_status),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_status<M>(e: SendError<M, Status>) -> Status {
|
||||||
|
match e {
|
||||||
|
SendError::HandlerError(status) => status,
|
||||||
|
_ => {
|
||||||
|
error!(actor = "useragent", "Failed to send message to actor");
|
||||||
|
Status::internal("session failure")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
403
server/crates/arbiter-server/src/context.rs
Normal file
@@ -0,0 +1,403 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use diesel::OptionalExtension as _;
|
||||||
|
use diesel_async::RunQueryDsl as _;
|
||||||
|
use ed25519_dalek::VerifyingKey;
|
||||||
|
use kameo::actor::{ActorRef, Spawn};
|
||||||
|
use miette::Diagnostic;
|
||||||
|
use rand::rngs::StdRng;
|
||||||
|
use secrecy::{ExposeSecret, SecretBox};
|
||||||
|
use smlang::statemachine;
|
||||||
|
use thiserror::Error;
|
||||||
|
use tokio::sync::{watch, RwLock};
|
||||||
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
context::{
|
||||||
|
bootstrap::{BootstrapActor, generate_token},
|
||||||
|
lease::LeaseHandler,
|
||||||
|
tls::{RotationState, RotationTask, TlsDataRaw, TlsManager},
|
||||||
|
},
|
||||||
|
db::{
|
||||||
|
self,
|
||||||
|
models::ArbiterSetting,
|
||||||
|
schema::{self, arbiter_settings},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub(crate) mod bootstrap;
|
||||||
|
pub(crate) mod lease;
|
||||||
|
pub(crate) mod tls;
|
||||||
|
pub(crate) mod unseal;
|
||||||
|
|
||||||
|
#[derive(Error, Debug, Diagnostic)]
|
||||||
|
pub enum InitError {
|
||||||
|
#[error("Database setup failed: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::init::database_setup))]
|
||||||
|
DatabaseSetup(#[from] db::DatabaseSetupError),
|
||||||
|
|
||||||
|
#[error("Connection acquire failed: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::init::database_pool))]
|
||||||
|
DatabasePool(#[from] db::PoolError),
|
||||||
|
|
||||||
|
#[error("Database query error: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::init::database_query))]
|
||||||
|
DatabaseQuery(#[from] diesel::result::Error),
|
||||||
|
|
||||||
|
#[error("TLS initialization failed: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::init::tls_init))]
|
||||||
|
Tls(#[from] tls::TlsInitError),
|
||||||
|
|
||||||
|
#[error("Bootstrap token generation failed: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::init::bootstrap_token))]
|
||||||
|
BootstrapToken(#[from] bootstrap::BootstrapError),
|
||||||
|
|
||||||
|
#[error("I/O Error: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::init::io))]
|
||||||
|
Io(#[from] std::io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Error, Debug, Diagnostic)]
|
||||||
|
pub enum UnsealError {
|
||||||
|
#[error("Database error: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::unseal::database_pool))]
|
||||||
|
Database(#[from] db::PoolError),
|
||||||
|
|
||||||
|
#[error("Query error: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::unseal::database_query))]
|
||||||
|
Query(#[from] diesel::result::Error),
|
||||||
|
|
||||||
|
#[error("Decryption failed: {0}")]
|
||||||
|
#[diagnostic(code(arbiter_server::unseal::decryption))]
|
||||||
|
DecryptionFailed(#[from] crate::crypto::CryptoError),
|
||||||
|
|
||||||
|
#[error("Invalid state for unseal")]
|
||||||
|
#[diagnostic(code(arbiter_server::unseal::invalid_state))]
|
||||||
|
InvalidState,
|
||||||
|
|
||||||
|
#[error("Missing salt in database")]
|
||||||
|
#[diagnostic(code(arbiter_server::unseal::missing_salt))]
|
||||||
|
MissingSalt,
|
||||||
|
|
||||||
|
#[error("No root key configured in database")]
|
||||||
|
#[diagnostic(code(arbiter_server::unseal::no_root_key))]
|
||||||
|
NoRootKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Error, Debug, Diagnostic)]
|
||||||
|
pub enum SealError {
|
||||||
|
#[error("Invalid state for seal")]
|
||||||
|
#[diagnostic(code(arbiter_server::seal::invalid_state))]
|
||||||
|
InvalidState,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Secure in-memory storage for root encryption key
|
||||||
|
///
|
||||||
|
/// Uses `secrecy` crate for automatic zeroization on drop to prevent key material
|
||||||
|
/// from remaining in memory after use. SecretBox provides heap-allocated secret
|
||||||
|
/// storage that implements Send + Sync for safe use in async contexts.
|
||||||
|
pub struct KeyStorage {
|
||||||
|
/// 32-byte root key protected by SecretBox
|
||||||
|
key: SecretBox<[u8; 32]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl KeyStorage {
|
||||||
|
/// Create new KeyStorage from a 32-byte root key
|
||||||
|
pub fn new(key: [u8; 32]) -> Self {
|
||||||
|
Self {
|
||||||
|
key: SecretBox::new(Box::new(key)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access the key for cryptographic operations
|
||||||
|
pub fn key(&self) -> &[u8; 32] {
|
||||||
|
self.key.expose_secret()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop автоматически реализован через secrecy::Zeroize
|
||||||
|
// который зануляет память при освобождении
|
||||||
|
|
||||||
|
statemachine! {
|
||||||
|
name: Server,
|
||||||
|
transitions: {
|
||||||
|
*NotBootstrapped + Bootstrapped = Sealed,
|
||||||
|
Sealed + Unsealed(KeyStorage) / move_key = Ready(KeyStorage),
|
||||||
|
Ready(KeyStorage) + Sealed / dispose_key = Sealed,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub struct _Context;
|
||||||
|
impl ServerStateMachineContext for _Context {
|
||||||
|
/// Move key from unseal event into Ready state
|
||||||
|
fn move_key(&mut self, event_data: KeyStorage) -> Result<KeyStorage, ()> {
|
||||||
|
// Просто перемещаем KeyStorage из event в state
|
||||||
|
// Без клонирования - event data consumed
|
||||||
|
Ok(event_data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Securely dispose of key when sealing
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
#[allow(clippy::unused_unit)]
|
||||||
|
fn dispose_key(&mut self, _state_data: &KeyStorage) -> Result<(), ()> {
|
||||||
|
// KeyStorage будет dropped после state transition
|
||||||
|
// secrecy::Zeroize зануляет память автоматически
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) struct _ServerContextInner {
|
||||||
|
pub db: db::DatabasePool,
|
||||||
|
pub state: RwLock<ServerStateMachine<_Context>>,
|
||||||
|
pub rng: StdRng,
|
||||||
|
pub tls: Arc<TlsManager>,
|
||||||
|
pub bootstrapper: ActorRef<BootstrapActor>,
|
||||||
|
pub rotation_state: RwLock<RotationState>,
|
||||||
|
pub rotation_acks: Arc<RwLock<HashSet<VerifyingKey>>>,
|
||||||
|
pub user_agent_leases: LeaseHandler<VerifyingKey>,
|
||||||
|
pub client_leases: LeaseHandler<VerifyingKey>,
|
||||||
|
}
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub(crate) struct ServerContext(Arc<_ServerContextInner>);
|
||||||
|
|
||||||
|
impl std::ops::Deref for ServerContext {
|
||||||
|
type Target = _ServerContextInner;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ServerContext {
|
||||||
|
/// Check if all active clients have acknowledged the rotation
|
||||||
|
pub async fn check_rotation_ready(&self) -> bool {
|
||||||
|
// TODO: Implement proper rotation readiness check
|
||||||
|
// For now, return false as placeholder
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn load_tls(
|
||||||
|
db: &db::DatabasePool,
|
||||||
|
settings: Option<&ArbiterSetting>,
|
||||||
|
) -> Result<TlsManager, InitError> {
|
||||||
|
match settings {
|
||||||
|
Some(s) if s.current_cert_id.is_some() => {
|
||||||
|
// Load active certificate from tls_certificates table
|
||||||
|
Ok(TlsManager::load_from_db(
|
||||||
|
db.clone(),
|
||||||
|
s.current_cert_id.unwrap(),
|
||||||
|
)
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
Some(s) => {
|
||||||
|
// Legacy migration: extract validity and save to new table
|
||||||
|
let tls_data_raw = TlsDataRaw {
|
||||||
|
cert: s.cert.clone(),
|
||||||
|
key: s.cert_key.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// For legacy certificates, use current time as not_before
|
||||||
|
// and current time + 90 days as not_after
|
||||||
|
let not_before = chrono::Utc::now().timestamp();
|
||||||
|
let not_after = not_before + (90 * 24 * 60 * 60); // 90 days
|
||||||
|
|
||||||
|
Ok(TlsManager::new_from_legacy(
|
||||||
|
db.clone(),
|
||||||
|
tls_data_raw,
|
||||||
|
not_before,
|
||||||
|
not_after,
|
||||||
|
)
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
// First startup - generate new certificate
|
||||||
|
Ok(TlsManager::new(db.clone()).await?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn new(db: db::DatabasePool) -> Result<Self, InitError> {
|
||||||
|
let mut conn = db.get().await?;
|
||||||
|
let rng = rand::make_rng();
|
||||||
|
|
||||||
|
let settings = arbiter_settings::table
|
||||||
|
.first::<ArbiterSetting>(&mut conn)
|
||||||
|
.await
|
||||||
|
.optional()?;
|
||||||
|
|
||||||
|
drop(conn);
|
||||||
|
|
||||||
|
// Load TLS manager
|
||||||
|
let tls = Self::load_tls(&db, settings.as_ref()).await?;
|
||||||
|
|
||||||
|
// Load rotation state from database
|
||||||
|
let rotation_state = RotationState::load_from_db(&db)
|
||||||
|
.await
|
||||||
|
.unwrap_or(RotationState::Normal);
|
||||||
|
|
||||||
|
let bootstrap_token = generate_token().await?;
|
||||||
|
|
||||||
|
let mut state = ServerStateMachine::new(_Context);
|
||||||
|
|
||||||
|
if let Some(settings) = &settings
|
||||||
|
&& settings.root_key_id.is_some()
|
||||||
|
{
|
||||||
|
// TODO: pass the encrypted root key to the state machine and let it handle decryption and transition to Sealed
|
||||||
|
let _ = state.process_event(ServerEvents::Bootstrapped);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create shutdown channel for rotation task
|
||||||
|
let (rotation_shutdown_tx, rotation_shutdown_rx) = watch::channel(false);
|
||||||
|
|
||||||
|
// Initialize bootstrap actor
|
||||||
|
let bootstrapper = BootstrapActor::spawn(BootstrapActor::new(&db).await?);
|
||||||
|
|
||||||
|
let context = Arc::new(_ServerContextInner {
|
||||||
|
db: db.clone(),
|
||||||
|
rng,
|
||||||
|
tls: Arc::new(tls),
|
||||||
|
state: RwLock::new(state),
|
||||||
|
bootstrapper,
|
||||||
|
rotation_state: RwLock::new(rotation_state),
|
||||||
|
rotation_acks: Arc::new(RwLock::new(HashSet::new())),
|
||||||
|
user_agent_leases: Default::default(),
|
||||||
|
client_leases: Default::default(),
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(Self(context))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Unseal vault with password
|
||||||
|
pub async fn unseal(&self, password: &str) -> Result<(), UnsealError> {
|
||||||
|
use crate::crypto::root_key;
|
||||||
|
use diesel::QueryDsl as _;
|
||||||
|
|
||||||
|
// 1. Get root_key_id from settings
|
||||||
|
let mut conn = self.db.get().await?;
|
||||||
|
|
||||||
|
let settings: db::models::ArbiterSetting = schema::arbiter_settings::table
|
||||||
|
.first(&mut conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let root_key_id = settings.root_key_id.ok_or(UnsealError::NoRootKey)?;
|
||||||
|
|
||||||
|
// 2. Load encrypted root key
|
||||||
|
let encrypted: db::models::AeadEncrypted = schema::aead_encrypted::table
|
||||||
|
.find(root_key_id)
|
||||||
|
.first(&mut conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let salt = encrypted
|
||||||
|
.argon2_salt
|
||||||
|
.as_ref()
|
||||||
|
.ok_or(UnsealError::MissingSalt)?;
|
||||||
|
|
||||||
|
drop(conn);
|
||||||
|
|
||||||
|
// 3. Decrypt root key using password
|
||||||
|
let root_key = root_key::decrypt_root_key(&encrypted, password, salt)
|
||||||
|
.map_err(UnsealError::DecryptionFailed)?;
|
||||||
|
|
||||||
|
// 4. Create secure storage
|
||||||
|
let key_storage = KeyStorage::new(root_key);
|
||||||
|
|
||||||
|
// 5. Transition state machine
|
||||||
|
let mut state = self.state.write().await;
|
||||||
|
state
|
||||||
|
.process_event(ServerEvents::Unsealed(key_storage))
|
||||||
|
.map_err(|_| UnsealError::InvalidState)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Seal the server (lock the key)
|
||||||
|
pub async fn seal(&self) -> Result<(), SealError> {
|
||||||
|
let mut state = self.state.write().await;
|
||||||
|
state
|
||||||
|
.process_event(ServerEvents::Sealed)
|
||||||
|
.map_err(|_| SealError::InvalidState)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_keystorage_creation() {
|
||||||
|
let key = [42u8; 32];
|
||||||
|
let storage = KeyStorage::new(key);
|
||||||
|
assert_eq!(storage.key()[0], 42);
|
||||||
|
assert_eq!(storage.key().len(), 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_keystorage_zeroization() {
|
||||||
|
let key = [99u8; 32];
|
||||||
|
{
|
||||||
|
let _storage = KeyStorage::new(key);
|
||||||
|
// storage будет dropped здесь
|
||||||
|
}
|
||||||
|
// После drop SecretBox должен зануляеть память
|
||||||
|
// Это проверяется автоматически через secrecy::Zeroize
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_state_machine_transitions() {
|
||||||
|
let mut state = ServerStateMachine::new(_Context);
|
||||||
|
|
||||||
|
// Начальное состояние
|
||||||
|
assert!(matches!(state.state(), &ServerStates::NotBootstrapped));
|
||||||
|
|
||||||
|
// Bootstrapped transition
|
||||||
|
state.process_event(ServerEvents::Bootstrapped).unwrap();
|
||||||
|
assert!(matches!(state.state(), &ServerStates::Sealed));
|
||||||
|
|
||||||
|
// Unsealed transition
|
||||||
|
let key_storage = KeyStorage::new([1u8; 32]);
|
||||||
|
state
|
||||||
|
.process_event(ServerEvents::Unsealed(key_storage))
|
||||||
|
.unwrap();
|
||||||
|
assert!(matches!(state.state(), &ServerStates::Ready(_)));
|
||||||
|
|
||||||
|
// Sealed transition
|
||||||
|
state.process_event(ServerEvents::Sealed).unwrap();
|
||||||
|
assert!(matches!(state.state(), &ServerStates::Sealed));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_move_key_callback() {
|
||||||
|
let mut ctx = _Context;
|
||||||
|
let key_storage = KeyStorage::new([7u8; 32]);
|
||||||
|
let result = ctx.move_key(key_storage);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
assert_eq!(result.unwrap().key()[0], 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_dispose_key_callback() {
|
||||||
|
let mut ctx = _Context;
|
||||||
|
let key_storage = KeyStorage::new([13u8; 32]);
|
||||||
|
let result = ctx.dispose_key(&key_storage);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_state_transitions() {
|
||||||
|
let mut state = ServerStateMachine::new(_Context);
|
||||||
|
|
||||||
|
// Попытка unseal без bootstrap
|
||||||
|
let key_storage = KeyStorage::new([1u8; 32]);
|
||||||
|
let result = state.process_event(ServerEvents::Unsealed(key_storage));
|
||||||
|
assert!(result.is_err());
|
||||||
|
|
||||||
|
// Правильный путь
|
||||||
|
state.process_event(ServerEvents::Bootstrapped).unwrap();
|
||||||
|
|
||||||
|
// Попытка повторного bootstrap
|
||||||
|
let result = state.process_event(ServerEvents::Bootstrapped);
|
||||||
|
assert!(result.is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||