-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving ove-client passcode mechanism
- Loading branch information
Showing
12 changed files
with
70 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"root": true, | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
}, | ||
"ignorePatterns": [ | ||
"**/*" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import { env, logger } from "../../env"; | ||
/* global clearInterval */ | ||
|
||
import { state } from "../state"; | ||
import { env, logger } from "../../env"; | ||
|
||
export default ({ | ||
register: (pin: string, key: string) => { | ||
const controller = { | ||
register: (pin: string, key: string, url: string) => { | ||
logger.info("POST /register - authenticating device"); | ||
if (pin === state.pin && !env.AUTHORISED_CREDENTIALS.includes(key)) { | ||
env.AUTHORISED_CREDENTIALS.push(key); | ||
|
||
if (state.authErrors <= env.AUTH_ERROR_LIMIT && | ||
pin === state.pin && env.AUTHORISED_CREDENTIALS === undefined) { | ||
env.AUTHORISED_CREDENTIALS = key; | ||
env.BRIDGE_URL = url; | ||
} | ||
|
||
if (state.pinUpdateHandler !== null) { | ||
clearInterval(state.pinUpdateHandler); | ||
} | ||
state.pin = ""; | ||
state.pinUpdateCallback = null; | ||
state.pinUpdateHandler = null; | ||
|
||
return pin === state.pin; | ||
} | ||
}); | ||
}; | ||
|
||
export default controller; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,18 @@ | ||
import { z } from "zod"; | ||
import { procedure, router } from "../trpc"; | ||
import { | ||
type OVEException, | ||
OVEExceptionSchema, | ||
StatusSchema | ||
} from "@ove/ove-types"; | ||
import controller from "./controller"; | ||
import { z } from "zod"; | ||
import { logger } from "../../env"; | ||
|
||
const safe = async <T>(handler: () => T): Promise<T | OVEException> => { | ||
try { | ||
return handler(); | ||
} catch (e) { | ||
logger.error(e); | ||
return { oveError: (e as Error).message }; | ||
} | ||
}; | ||
import controller from "./controller"; | ||
import { safe } from "@ove/ove-utils"; | ||
import { procedure, router } from "../trpc"; | ||
|
||
export const authRouter = router({ | ||
register: procedure | ||
.meta({ openapi: { method: "POST", path: "/register" } }) | ||
.input(z.object({ pin: z.string(), key: z.string() })) | ||
.input(z.object({ pin: z.string(), key: z.string(), url: z.string() })) | ||
.output(z.union([OVEExceptionSchema, StatusSchema])) | ||
.mutation(({ input: { pin, key } }) => | ||
safe(() => controller.register(pin, key))) | ||
.mutation(({ input: { pin, key, url } }) => | ||
safe(logger, async () => controller.register(pin, key, url))) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
/* global NodeJS */ | ||
|
||
import { env } from "../env"; | ||
import { type Browser } from "@ove/ove-types"; | ||
|
||
type State = { | ||
browsers: Map<number, Browser> | ||
pin: string | ||
pinUpdateCallback: ((event: string) => void) | null | ||
pinUpdateHandler: NodeJS.Timer | null | ||
authErrors: number | ||
}; | ||
|
||
const generatePin = () => Array(4) | ||
const generatePin = () => env.AUTHORISED_CREDENTIALS === undefined ? Array(4) | ||
.fill(0) | ||
.map(() => Math.floor(Math.random() * 10)) | ||
.join(""); | ||
.join("") : ""; | ||
|
||
export const state: State = { | ||
browsers: new Map<number, Browser>(), | ||
pin: "initialising", | ||
pinUpdateCallback: null, | ||
pinUpdateHandler: null | ||
pinUpdateHandler: null, | ||
authErrors: 0 | ||
}; | ||
|
||
export const updatePin = () => { | ||
export const updatePin = env.AUTHORISED_CREDENTIALS === undefined ? () => { | ||
state.pin = generatePin(); | ||
if (state.pinUpdateCallback === null) { | ||
throw new Error("Missing pin update callback"); | ||
} | ||
state.pinUpdateCallback(state.pin); | ||
}; | ||
} : () => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
libs/ui-reorderable-list/src/lib/reorderable-list/components/reorderable-item.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters