Initialize web client; update file system handling to allow opening files as needed; update ncon scripts.
This commit is contained in:
parent
38fe836a77
commit
b673eca250
@ -113,8 +113,9 @@ struct_info!(
|
||||
.add_named("Secret", Sequence!()),
|
||||
|
||||
"", AUTH_PCACI, 0x1313, |b|b
|
||||
.add_named("Salt", Natural!())
|
||||
.add_named("Hash", List!(Block!(32))),
|
||||
.add_named("Public", Natural!())
|
||||
.add_named("Private", Natural!())
|
||||
.add_named("Table", List!(Block!(32))),
|
||||
|
||||
"", AUTH_OTAC_EMAIL, 0x1320, |b|b
|
||||
.add_named("Address", Natural!()),
|
||||
|
24
client-web/.gitignore
vendored
Normal file
24
client-web/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
16
client-web/index.html
Normal file
16
client-web/index.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Lit + TS</title>
|
||||
<link rel="stylesheet" href="./src/index.css" />
|
||||
<script type="module" src="/src/my-element.ts"></script>
|
||||
</head>
|
||||
<body>
|
||||
<my-element>
|
||||
<h1>Test</h1>
|
||||
</my-element>
|
||||
</body>
|
||||
</html>
|
1078
client-web/package-lock.json
generated
Normal file
1078
client-web/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
client-web/package.json
Normal file
18
client-web/package.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "client-web",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"lit": "^3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "~5.7.2",
|
||||
"vite": "^6.3.1"
|
||||
}
|
||||
}
|
1
client-web/public/vite.svg
Normal file
1
client-web/public/vite.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
1
client-web/src/assets/lit.svg
Normal file
1
client-web/src/assets/lit.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="25.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 320"><path fill="#00E8FF" d="m64 192l25.926-44.727l38.233-19.114l63.974 63.974l10.833 61.754L192 320l-64-64l-38.074-25.615z"></path><path fill="#283198" d="M128 256V128l64-64v128l-64 64ZM0 256l64 64l9.202-60.602L64 192l-37.542 23.71L0 256Z"></path><path fill="#324FFF" d="M64 192V64l64-64v128l-64 64Zm128 128V192l64-64v128l-64 64ZM0 256V128l64 64l-64 64Z"></path><path fill="#0FF" d="M64 320V192l64 64z"></path></svg>
|
After Width: | Height: | Size: 639 B |
38
client-web/src/index.css
Normal file
38
client-web/src/index.css
Normal file
@ -0,0 +1,38 @@
|
||||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
}
|
127
client-web/src/my-element.ts
Normal file
127
client-web/src/my-element.ts
Normal file
@ -0,0 +1,127 @@
|
||||
import { LitElement, css, html } from 'lit'
|
||||
import { customElement, property } from 'lit/decorators.js'
|
||||
import litLogo from './assets/lit.svg'
|
||||
import viteLogo from '/vite.svg'
|
||||
|
||||
/**
|
||||
* An example element.
|
||||
*
|
||||
* @slot - This element has a slot
|
||||
* @csspart button - The button
|
||||
*/
|
||||
@customElement('my-element')
|
||||
export class MyElement extends LitElement {
|
||||
/**
|
||||
* Copy for the read the docs hint.
|
||||
*/
|
||||
@property()
|
||||
docsHint = 'Click on the Vite and Lit logos to learn more'
|
||||
|
||||
/**
|
||||
* The number of times the button has been clicked.
|
||||
*/
|
||||
@property({ type: Number })
|
||||
count = 0
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<div>
|
||||
<a href="https://vite.dev" target="_blank">
|
||||
<img src=${viteLogo} class="logo" alt="Vite logo" />
|
||||
</a>
|
||||
<a href="https://lit.dev" target="_blank">
|
||||
<img src=${litLogo} class="logo lit" alt="Lit logo" />
|
||||
</a>
|
||||
</div>
|
||||
<slot></slot>
|
||||
<div class="card">
|
||||
<button @click=${this._onClick} part="button">
|
||||
count is ${this.count}
|
||||
</button>
|
||||
</div>
|
||||
<p class="read-the-docs">${this.docsHint}</p>
|
||||
`
|
||||
}
|
||||
|
||||
private _onClick() {
|
||||
this.count++
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.lit:hover {
|
||||
filter: drop-shadow(0 0 2em #325cffaa);
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
||||
|
||||
::slotted(h1) {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'my-element': MyElement
|
||||
}
|
||||
}
|
1
client-web/src/vite-env.d.ts
vendored
Normal file
1
client-web/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
25
client-web/tsconfig.json
Normal file
25
client-web/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
@ -3,12 +3,9 @@ svc.connect("localhost", 38936)
|
||||
|
||||
users:mut [
|
||||
UserCreation.{
|
||||
Handle: "eveningmist"
|
||||
Groups: [Administrator]
|
||||
Handle: "admin"
|
||||
Groups: [Admin]
|
||||
},
|
||||
UserCreation.{
|
||||
Handle: "yukirij"
|
||||
}
|
||||
]
|
||||
|
||||
#for user : users {
|
||||
@ -17,29 +14,34 @@ users:mut [
|
||||
#}
|
||||
|
||||
result := svc DomainCreate.{
|
||||
Name: "Yukiri Organization"
|
||||
Detail: ""
|
||||
Fqdn: "yukiri.org"
|
||||
Name: "Example"
|
||||
Detail: "An example domain."
|
||||
Fqdn: "example.com"
|
||||
Contacts: [
|
||||
ServiceContact.{
|
||||
Role: "Developer"
|
||||
Name: "yukirij"
|
||||
Org: "Yukiri Corporation"
|
||||
Role: "Administrator"
|
||||
#Name: "Koko"
|
||||
#Title: "Manager"
|
||||
#Org: "My Company"
|
||||
Methods: [
|
||||
("Bluesky", "yukirij.kumorizora.net")
|
||||
]
|
||||
}
|
||||
ServiceContact.{
|
||||
Role: "Administrator"
|
||||
Org: "Yukiri Corporation"
|
||||
Methods: [
|
||||
("Email", "server-admin@yukiri.cloud")
|
||||
("Email", "report@ryouiki.org"),
|
||||
#("Email", "admin@example.com"),
|
||||
#("Website", "example.com/support"),
|
||||
#("Bluesky", "admin.example.com"),
|
||||
]
|
||||
}
|
||||
]
|
||||
Users: users
|
||||
}
|
||||
|
||||
print result
|
||||
if result is _DomainCreate {
|
||||
print "Your request id is:"
|
||||
print " " + result.Id
|
||||
print "\nAdd the following to a TXT record in your domain's DNS:"
|
||||
print " " + result.Token
|
||||
print "\nOnce added, update the Id in 'domain_verify' and run the script."
|
||||
} else {
|
||||
panic "failed to initialize a domain creation request"
|
||||
}
|
||||
|
||||
svc.disconnect
|
||||
|
@ -2,7 +2,7 @@ svc.cert "data/cert.pem"
|
||||
svc.connect("localhost", 38936)
|
||||
|
||||
result := svc DomainVerify.{
|
||||
Id:'yB6WUH7KM0Pn'
|
||||
Id:'___'
|
||||
}
|
||||
|
||||
print result
|
||||
|
@ -1,8 +1,8 @@
|
||||
@Payload {
|
||||
@UserCreation {
|
||||
@Groups enum {
|
||||
Admin
|
||||
Moderator
|
||||
Admin = 5
|
||||
Mod = 6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ aws-lc-rs = { version = "1.13.0" } #, features = ["fips"]
|
||||
hmac = "0.12.1"
|
||||
opaque-ke = "3.0.0"
|
||||
acme2 = "0.5.1"
|
||||
otpauth = "0.5.1"
|
||||
yubikey = { version = "0.8.0", features = ["untested"] }
|
||||
yubihsm = "0.42.1"
|
||||
webpki-roots = "0.26.8"
|
||||
|
@ -16,9 +16,15 @@ use crate::{
|
||||
};
|
||||
use super::{FileSystem, util::{self, EncryptImpl}};
|
||||
|
||||
const D_USER :&str = "user";
|
||||
const D_MESSAGE :&str = "message";
|
||||
const D_SECURITY :&str = "security";
|
||||
const D_APP :&str = "app";
|
||||
|
||||
pub(crate) const Z_REPOSITORY :usize = 512;
|
||||
pub(crate) const Z_MESSAGE :usize = 256;
|
||||
pub(crate) const Z_THREAD :usize = 128;
|
||||
pub(crate) const Z_HANDLE :usize = 4;
|
||||
pub(crate) const Z_SALT :usize = 0;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@ -28,6 +34,7 @@ pub(crate) enum File {
|
||||
Config,
|
||||
System,
|
||||
Salt,
|
||||
Handle,
|
||||
Audit,
|
||||
Group,
|
||||
Channel,
|
||||
@ -37,8 +44,8 @@ pub(crate) enum File {
|
||||
Room,
|
||||
User,
|
||||
Profile,
|
||||
//Application,
|
||||
//Authority,
|
||||
Application,
|
||||
Authority,
|
||||
MAX,
|
||||
}
|
||||
impl File {
|
||||
@ -47,19 +54,20 @@ impl File {
|
||||
match self {
|
||||
Self::Key => "key.BIN",
|
||||
Self::System => "system.BIN",
|
||||
Self::Salt => "salt.BIN",
|
||||
Self::Config => "config.BIN",
|
||||
Self::Audit => "audit.BIN",
|
||||
Self::Group => "group.BIN",
|
||||
Self::Channel => "channel.BIN",
|
||||
Self::District => "district.BIN",
|
||||
Self::Room => "room.BIN",
|
||||
Self::User => "user.BIN",
|
||||
Self::Profile => "profile.BIN",
|
||||
Self::ThreadRegistry => "thread.BIN",
|
||||
Self::MessageRegistry => "message.BIN",
|
||||
//Self::AppRegistry => formatcp!("{}/registry.BIN", D_APP),
|
||||
//Self::AppAuth => formatcp!("{}/authorization.BIN", D_APP),
|
||||
Self::Audit => formatcp!("{}/audit.BIN", D_SECURITY),
|
||||
Self::Salt => formatcp!("{}/salt.BIN", D_SECURITY),
|
||||
Self::User => formatcp!("{}/user.BIN", D_USER),
|
||||
Self::Profile => formatcp!("{}/profile.BIN", D_USER),
|
||||
Self::Handle => formatcp!("{}/handle.BIN", D_USER),
|
||||
Self::Room => formatcp!("{}/room.BIN", D_MESSAGE),
|
||||
Self::ThreadRegistry => formatcp!("{}/thread.BIN", D_MESSAGE),
|
||||
Self::MessageRegistry => formatcp!("{}/message.BIN", D_MESSAGE),
|
||||
Self::Application => formatcp!("{}/registry.BIN", D_APP),
|
||||
Self::Authority => formatcp!("{}/authorization.BIN", D_APP),
|
||||
Self::MAX => "",
|
||||
}
|
||||
}
|
||||
@ -70,7 +78,7 @@ pub struct DomainFiles {
|
||||
data_crypt:Box<dyn Encryptor>,
|
||||
hash_crypt:Box<dyn Encryptor>,
|
||||
|
||||
handles:[Mutex<fs::File>; File::MAX as usize],
|
||||
handles:[Mutex<Option<fs::File>>; File::MAX as usize],
|
||||
}
|
||||
impl DomainFiles {
|
||||
pub async fn init(
|
||||
@ -147,6 +155,7 @@ impl DomainFiles {
|
||||
init_file!(File::Config, util::open_szun::<{castle::schema::DOMAIN}>);
|
||||
init_file!(File::System, Self::open_system);
|
||||
init_file!(File::Salt, util::open_trie::<Z_SALT>);
|
||||
init_file!(File::Handle, util::open_trie::<Z_HANDLE>);
|
||||
init_file!(File::Audit, util::open_block::<Z_MESSAGE>);
|
||||
init_file!(File::Group, Self::init_groups);
|
||||
init_file!(File::Channel, util::open_block::<Z_REPOSITORY>);
|
||||
@ -156,15 +165,15 @@ impl DomainFiles {
|
||||
init_file!(File::Profile, util::open_block::<Z_REPOSITORY>);
|
||||
init_file!(File::ThreadRegistry, util::open_block::<Z_THREAD>);
|
||||
init_file!(File::MessageRegistry, util::open_block::<Z_MESSAGE>);
|
||||
//init_file!(File::AppRegistry, util::create_block::<Z_REPOSITORY>);
|
||||
//init_file!(File::AppAuth, util::create_block::<Z_REPOSITORY>);
|
||||
init_file!(File::Application, util::open_block::<Z_REPOSITORY>);
|
||||
init_file!(File::Authority, util::open_block::<Z_REPOSITORY>);
|
||||
|
||||
let manager = Self {
|
||||
path,
|
||||
data_crypt,
|
||||
hash_crypt,
|
||||
|
||||
handles:handles.map(|h|Mutex::new(h.unwrap())),
|
||||
handles:handles.map(|h|Mutex::new(h)),
|
||||
};
|
||||
|
||||
Ok(manager)
|
||||
@ -176,6 +185,27 @@ impl DomainFiles {
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?;
|
||||
|
||||
for group in [
|
||||
make::<Record>(RecordKey!(castle::schema::GROUP))
|
||||
.with("Name", &Sequence::from("System")),
|
||||
|
||||
make::<Record>(RecordKey!(castle::schema::GROUP))
|
||||
.with("Name", &Sequence::from("User")),
|
||||
|
||||
make::<Record>(RecordKey!(castle::schema::GROUP))
|
||||
.with("Name", &Sequence::from("Guest")),
|
||||
|
||||
make::<Record>(RecordKey!(castle::schema::GROUP))
|
||||
.with("Name", &Sequence::from("Restricted")),
|
||||
|
||||
make::<Record>(RecordKey!(castle::schema::GROUP))
|
||||
.with("Name", &Sequence::from("Manager")),
|
||||
|
||||
make::<Record>(RecordKey!(castle::schema::GROUP))
|
||||
.with("Name", &Sequence::from("Administrator")),
|
||||
|
||||
make::<Record>(RecordKey!(castle::schema::GROUP))
|
||||
.with("Name", &Sequence::from("Moderator")),
|
||||
|
||||
make::<Record>(RecordKey!(castle::schema::GROUP))
|
||||
.with("Name", &Sequence::from("User")),
|
||||
]{
|
||||
@ -225,8 +255,23 @@ impl FileSystem for DomainFiles {
|
||||
&self.data_crypt
|
||||
}
|
||||
|
||||
async fn file_handle(&self, file:Self::File) -> MutexGuard<fs::File>
|
||||
async fn open_file(&self, file:Self::File) -> Result<fs::File,Error>
|
||||
{
|
||||
self.handles[file as usize].lock().await
|
||||
Ok(util::open_file(&self.path.join(file.path())).await?)
|
||||
}
|
||||
|
||||
async fn file_handle(&self, file:Self::File) -> Result<(fs::File, MutexGuard::<Option<fs::File>>),Error>
|
||||
{
|
||||
let guard = self.handles[file as usize].lock().await;
|
||||
Ok((match guard.as_ref() {
|
||||
Some(handle) => {
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
}
|
||||
None => {
|
||||
self.open_file(file).await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
}
|
||||
}, guard))
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ pub struct MediaFiles {
|
||||
data_crypt:Box<dyn Encryptor>,
|
||||
hash_crypt:Box<dyn Encryptor>,
|
||||
|
||||
handles:[Mutex<fs::File>; File::size()],
|
||||
handles:[Mutex<Option<fs::File>>; File::size()],
|
||||
}
|
||||
impl MediaFiles {
|
||||
pub async fn init(
|
||||
@ -128,7 +128,7 @@ impl MediaFiles {
|
||||
data_crypt,
|
||||
hash_crypt,
|
||||
|
||||
handles:handles.map(|h|Mutex::new(h.unwrap())),
|
||||
handles:handles.map(|h|Mutex::new(h)),
|
||||
};
|
||||
|
||||
Ok(manager)
|
||||
@ -207,8 +207,23 @@ impl FileSystem for MediaFiles {
|
||||
&self.data_crypt
|
||||
}
|
||||
|
||||
async fn file_handle(&self, file:Self::File) -> MutexGuard<fs::File>
|
||||
async fn open_file(&self, file:Self::File) -> Result<fs::File,Error>
|
||||
{
|
||||
self.handles[file as usize].lock().await
|
||||
Ok(util::open_file(&self.path.join(file.path())).await?)
|
||||
}
|
||||
|
||||
async fn file_handle(&self, file:Self::File) -> Result<(fs::File, MutexGuard::<Option<fs::File>>),Error>
|
||||
{
|
||||
let guard = self.handles[file as usize].lock().await;
|
||||
Ok((match guard.as_ref() {
|
||||
Some(handle) => {
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
}
|
||||
None => {
|
||||
self.open_file(file).await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
}
|
||||
}, guard))
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,16 @@ pub(crate) trait FileSystem {
|
||||
|
||||
fn encryptor(&self) -> &Box<dyn Encryptor>;
|
||||
|
||||
async fn file_handle(&self, file:Self::File) -> MutexGuard<fs::File>;
|
||||
async fn file_handle(&self, file:Self::File) -> Result<(fs::File, MutexGuard::<Option<fs::File>>),Error>;
|
||||
async fn open_file(&self, file:Self::File) -> Result<fs::File,Error>;
|
||||
|
||||
async fn store(&self, file:Self::File, data:&[u8]) -> Result<(),Error>
|
||||
{
|
||||
let data = self.encryptor().encrypt(data)
|
||||
.map_err(|_|Error::new(ErrorCode::Generic, "failed to encrypt data"))?;
|
||||
|
||||
self.file_handle(file).await.write(&data).await.map(|_|())
|
||||
let (mut handle, _guard) = self.file_handle(file).await?;
|
||||
handle.write(&data).await.map(|_|())
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))
|
||||
}
|
||||
|
||||
@ -34,7 +36,8 @@ pub(crate) trait FileSystem {
|
||||
{
|
||||
let mut data = Vec::new();
|
||||
|
||||
self.file_handle(file).await.read_to_end(&mut data).await.map(|_|())
|
||||
let (mut handle, _guard) = self.file_handle(file).await?;
|
||||
handle.read_to_end(&mut data).await.map(|_|())
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?;
|
||||
|
||||
self.encryptor().decrypt(&data)
|
||||
@ -43,8 +46,9 @@ pub(crate) trait FileSystem {
|
||||
|
||||
async fn block_insert<const Z:usize>(&self, file:Self::File, data:&[u8]) -> Result<usize,Error>
|
||||
{
|
||||
let (handle, _guard) = self.file_handle(file).await?;
|
||||
let mut store = BlockFile::<Z>::from(
|
||||
self.file_handle(file).await.try_clone().await
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
);
|
||||
|
||||
@ -57,8 +61,9 @@ pub(crate) trait FileSystem {
|
||||
|
||||
async fn block_update<const Z:usize>(&self, file:Self::File, id:usize, data:&[u8]) -> Result<(),Error>
|
||||
{
|
||||
let (handle, _guard) = self.file_handle(file).await?;
|
||||
let mut store = BlockFile::<Z>::from(
|
||||
self.file_handle(file).await.try_clone().await
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
);
|
||||
|
||||
@ -71,8 +76,9 @@ pub(crate) trait FileSystem {
|
||||
|
||||
async fn block_load<const Z:usize>(&self, file:Self::File, id:usize) -> Result<Vec<u8>,Error>
|
||||
{
|
||||
let (handle, _guard) = self.file_handle(file).await?;
|
||||
let store = BlockFile::<Z>::from(
|
||||
self.file_handle(file).await.try_clone().await
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
);
|
||||
|
||||
@ -90,8 +96,9 @@ pub(crate) trait FileSystem {
|
||||
|
||||
async fn trie_set<const Z:usize>(&self, file:Self::File, key:&[u8], data:&[u8]) -> Result<usize,Error>
|
||||
{
|
||||
let (handle, _guard) = self.file_handle(file).await?;
|
||||
let mut store = TrieFile::<Z>::from(
|
||||
self.file_handle(file).await.try_clone().await
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
);
|
||||
|
||||
@ -101,8 +108,9 @@ pub(crate) trait FileSystem {
|
||||
|
||||
async fn trie_find<const Z:usize>(&self, file:Self::File, key:&[u8]) -> Result<usize,Error>
|
||||
{
|
||||
let (handle, _guard) = self.file_handle(file).await?;
|
||||
let store = TrieFile::<Z>::from(
|
||||
self.file_handle(file).await.try_clone().await
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
);
|
||||
|
||||
@ -118,8 +126,9 @@ pub(crate) trait FileSystem {
|
||||
|
||||
async fn trie_get<const Z:usize>(&self, file:Self::File, id:usize) -> Result<Vec<u8>,Error>
|
||||
{
|
||||
let (handle, _guard) = self.file_handle(file).await?;
|
||||
let store = TrieFile::<Z>::from(
|
||||
self.file_handle(file).await.try_clone().await
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
);
|
||||
|
||||
@ -135,8 +144,9 @@ pub(crate) trait FileSystem {
|
||||
|
||||
async fn trie_key<const Z:usize>(&self, file:Self::File, id:usize) -> Result<Vec<u8>,Error>
|
||||
{
|
||||
let (handle, _guard) = self.file_handle(file).await?;
|
||||
let store = TrieFile::<Z>::from(
|
||||
self.file_handle(file).await.try_clone().await
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
);
|
||||
|
||||
@ -151,8 +161,9 @@ pub(crate) trait FileSystem {
|
||||
|
||||
async fn trie_ids<const Z:usize>(&self, file:Self::File) -> Result<Vec<usize>,Error>
|
||||
{
|
||||
let (handle, _guard) = self.file_handle(file).await?;
|
||||
let store = TrieFile::<Z>::from(
|
||||
self.file_handle(file).await.try_clone().await
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
);
|
||||
|
||||
|
@ -77,7 +77,7 @@ pub struct SystemFiles {
|
||||
pub path:PathBuf,
|
||||
pub encrypt:Box<dyn Encryptor>,
|
||||
|
||||
pub handles:[Mutex<fs::File>; File::size()],
|
||||
pub handles:[Mutex<Option<fs::File>>; File::size()],
|
||||
}
|
||||
impl SystemFiles {
|
||||
pub async fn init(
|
||||
@ -169,7 +169,7 @@ impl SystemFiles {
|
||||
path,
|
||||
encrypt,
|
||||
|
||||
handles:handles.map(|h|Mutex::new(h.unwrap())),
|
||||
handles:handles.map(|h|Mutex::new(h)),
|
||||
};
|
||||
|
||||
if init_certfile {
|
||||
@ -250,8 +250,23 @@ impl FileSystem for SystemFiles {
|
||||
&self.encrypt
|
||||
}
|
||||
|
||||
async fn file_handle(&self, file:Self::File) -> MutexGuard<fs::File>
|
||||
async fn open_file(&self, file:Self::File) -> Result<fs::File,Error>
|
||||
{
|
||||
self.handles[file as usize].lock().await
|
||||
Ok(util::open_file(&self.path.join(file.path())).await?)
|
||||
}
|
||||
|
||||
async fn file_handle(&self, file:Self::File) -> Result<(fs::File, MutexGuard::<Option<fs::File>>),Error>
|
||||
{
|
||||
let guard = self.handles[file as usize].lock().await;
|
||||
Ok((match guard.as_ref() {
|
||||
Some(handle) => {
|
||||
handle.try_clone().await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
}
|
||||
None => {
|
||||
self.open_file(file).await
|
||||
.map_err(|e|Error::new(ErrorCode::Generic, &e.to_string()))?
|
||||
}
|
||||
}, guard))
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use crate::{
|
||||
FileSystem,
|
||||
domain::{
|
||||
File as DomainFile,
|
||||
Z_SALT,
|
||||
Z_SALT, Z_REPOSITORY,
|
||||
},
|
||||
},
|
||||
service::{
|
||||
@ -21,29 +21,34 @@ use std::{
|
||||
sync::Arc,
|
||||
path::PathBuf,
|
||||
};
|
||||
use castle::schema::*;
|
||||
use rand::Rng;
|
||||
use suzu::szun::{self, Szun};
|
||||
use suzu::szun::{self, *};
|
||||
|
||||
pub async fn process(manager:Arc<SvcDomain>, packet:Packet) -> Result<(),()>
|
||||
{
|
||||
match packet.msg {
|
||||
Message::DomainInit{data} => {
|
||||
let domain = data.find::<szun::Record>("Data");
|
||||
let users = data.find::<szun::List>("Users");
|
||||
let domain = data.find::<Record>("Data");
|
||||
let users = data.find::<List>("Users");
|
||||
|
||||
manager.files.store(DomainFile::Config, &domain.encode()).await.ok();
|
||||
|
||||
// Initialize described users.
|
||||
for i in 0..users.len() {
|
||||
let data = szun::make::<szun::Record>(szun::RecordKey!(castle::schema::USER));
|
||||
let data = make::<Record>(RecordKey!(castle::schema::USER));
|
||||
|
||||
let user = users.get::<szun::Record>(i);
|
||||
let _handle = user.find::<szun::Sequence>("Handle").get_str();
|
||||
let secret = user.find::<szun::Sequence>("Secret").get();
|
||||
let groups = user.find::<szun::List>("Groups");
|
||||
let user = users.get::<Record>(i);
|
||||
let handle = user.find::<Sequence>("Handle").get_str();
|
||||
let secret = user.find::<Sequence>("Secret").get();
|
||||
let mut groups = user.find::<List>("Groups");
|
||||
|
||||
if handle.is_empty() { return Err(()); }
|
||||
|
||||
data.find::<Sequence>("Handle").set_str(&handle);
|
||||
|
||||
// Generate password from secret.
|
||||
let auth_data = data.find::<szun::Record>("Secret");
|
||||
let auth_data = data.find::<Record>("Secret");
|
||||
|
||||
let mut salt = [0u8; 16];
|
||||
{
|
||||
@ -53,25 +58,43 @@ pub async fn process(manager:Arc<SvcDomain>, packet:Packet) -> Result<(),()>
|
||||
|
||||
let salt_id = manager.files.trie_set::<Z_SALT>(DomainFile::Salt, &salt, &[]).await
|
||||
.map_err(|_|())?;
|
||||
auth_data.find::<szun::Natural>("Secret").set(salt_id);
|
||||
auth_data.find::<Natural>("Secret").set(salt_id);
|
||||
|
||||
let secret_data = manager.opaque_register_local(&secret, &salt)
|
||||
.map_err(|_|())?;
|
||||
auth_data.find::<szun::Sequence>("Envelope").set(&secret_data);
|
||||
auth_data.find::<Sequence>("Envelope").set(&secret_data);
|
||||
|
||||
// Generate public/private keys.
|
||||
|
||||
|
||||
// Add groups.
|
||||
for g in 0..groups.len() {
|
||||
match groups.get::<szun::Natural>(g).get::<usize>() {
|
||||
_ => { }
|
||||
}
|
||||
let gid = groups.get::<Natural>(g).get::<usize>();
|
||||
let membership = make::<Record>(RecordKey!(GROUP_MEMBERSHIP));
|
||||
membership.find::<Natural>("Group").set(gid);
|
||||
groups.push(&membership);
|
||||
}
|
||||
|
||||
// Create profile.
|
||||
let profile_ext = make::<Record>(RecordKey!(PROFILE_EXT));
|
||||
let profile = make::<Record>(RecordKey!(PROFILE));
|
||||
|
||||
let pxid = manager.files.block_insert::<Z_REPOSITORY>(DomainFile::Profile, &profile_ext.encode()).await
|
||||
.map_err(|_|())?;
|
||||
|
||||
profile.find::<Natural>("Ext").set(pxid);
|
||||
|
||||
let pid = manager.files.block_insert::<Z_REPOSITORY>(DomainFile::Profile, &profile_ext.encode()).await
|
||||
.map_err(|_|())?;
|
||||
|
||||
data.find::<Natural>("Profile").set(pid);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Message::Request{code, payload, resp} => {
|
||||
use suzu::szun::*;
|
||||
use suzu::*;
|
||||
use castle::protocol;
|
||||
|
||||
let service = manager.clone();
|
||||
|
Loading…
x
Reference in New Issue
Block a user