anastasis-core: salt rename, fix tagging

This commit is contained in:
Florian Dold 2022-04-13 13:16:35 +02:00
parent 2c3aeabed1
commit 31b6496db5
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
11 changed files with 76 additions and 77 deletions

View File

@ -458,7 +458,7 @@ async function prepareRecoveryData(
escrow_type: authMethod.type as any, escrow_type: authMethod.type as any,
instructions: authMethod.instructions, instructions: authMethod.instructions,
provider_salt: provider.provider_salt, provider_salt: provider.provider_salt,
truth_salt: tm.master_salt, question_salt: tm.master_salt,
truth_key: tm.truth_key, truth_key: tm.truth_key,
url: meth.provider, url: meth.provider,
uuid: tm.uuid, uuid: tm.uuid,
@ -902,7 +902,7 @@ async function getResponseHash(
respHash = await secureAnswerHash( respHash = await secureAnswerHash(
solveRequest.answer, solveRequest.answer,
truth.uuid, truth.uuid,
truth.truth_salt, truth.question_salt,
); );
} else { } else {
throw Error("unsupported answer request"); throw Error("unsupported answer request");
@ -1074,18 +1074,21 @@ async function selectChallenge(
const url = new URL(`/truth/${truth.uuid}/challenge`, truth.url); const url = new URL(`/truth/${truth.uuid}/challenge`, truth.url);
if (truth.escrow_type === ChallengeType.Question) { switch (truth.escrow_type) {
return { case ChallengeType.Question:
...state, case ChallengeType.Totp: {
recovery_state: RecoveryStates.ChallengeSolving, return {
selected_challenge_uuid: truth.uuid, ...state,
challenge_feedback: { recovery_state: RecoveryStates.ChallengeSolving,
...state.challenge_feedback, selected_challenge_uuid: truth.uuid,
[truth.uuid]: { challenge_feedback: {
state: ChallengeFeedbackStatus.Pending, ...state.challenge_feedback,
[truth.uuid]: {
state: ChallengeFeedbackStatus.Pending,
},
}, },
}, };
}; }
} }
const resp = await fetch(url.href, { const resp = await fetch(url.href, {
@ -1732,7 +1735,7 @@ export async function reduceAction(
return { return {
reducer_type: "error", reducer_type: "error",
...e.errorJson, ...e.errorJson,
} };
} }
throw e; throw e;
} }

View File

@ -82,7 +82,7 @@ export interface EscrowMethod {
/** /**
* Salt to hash the security question answer if applicable. * Salt to hash the security question answer if applicable.
*/ */
truth_salt: TruthSalt; question_salt: TruthSalt;
// Salt from the provider to derive the user ID // Salt from the provider to derive the user ID
// at this provider. // at this provider.

View File

@ -274,13 +274,13 @@ export function ChallengeOverviewScreen(): VNode {
Policy #{policy_index + 1}: {policyName} Policy #{policy_index + 1}: {policyName}
</h3> </h3>
{policy.challenges.length === 0 && ( {policy.challenges.length === 0 && (
<p>This policy doesn't have challenges.</p> <p>This policy doesn't have any challenges.</p>
)} )}
{policy.challenges.length === 1 && ( {policy.challenges.length === 1 && (
<p>This policy just have one challenge.</p> <p>This policy has one challenge.</p>
)} )}
{policy.challenges.length > 1 && ( {policy.challenges.length > 1 && (
<p>This policy have {policy.challenges.length} challenges.</p> <p>This policy has {policy.challenges.length} challenges.</p>
)} )}
{tableBody} {tableBody}
</div> </div>

View File

@ -44,10 +44,7 @@ export function AuthMethodEmailSolve({ id }: AuthMethodSolveProps): VNode {
</AnastasisClientFrame> </AnastasisClientFrame>
); );
} }
if ( if (reducer.currentReducerState?.reducer_type !== "recovery") {
!reducer.currentReducerState ||
reducer.currentReducerState.recovery_state === undefined
) {
return ( return (
<AnastasisClientFrame hideNav title="Recovery problem"> <AnastasisClientFrame hideNav title="Recovery problem">
<div>invalid state</div> <div>invalid state</div>

View File

@ -22,10 +22,7 @@ export function AuthMethodIbanSolve({ id }: AuthMethodSolveProps): VNode {
</AnastasisClientFrame> </AnastasisClientFrame>
); );
} }
if ( if (reducer.currentReducerState?.reducer_type !== "recovery") {
!reducer.currentReducerState ||
reducer.currentReducerState.recovery_state === undefined
) {
return ( return (
<AnastasisClientFrame hideNav title="Recovery problem"> <AnastasisClientFrame hideNav title="Recovery problem">
<div>invalid state</div> <div>invalid state</div>

View File

@ -43,10 +43,7 @@ export function AuthMethodPostSolve({ id }: AuthMethodSolveProps): VNode {
</AnastasisClientFrame> </AnastasisClientFrame>
); );
} }
if ( if (reducer.currentReducerState?.reducer_type !== "recovery") {
!reducer.currentReducerState ||
reducer.currentReducerState.recovery_state === undefined
) {
return ( return (
<AnastasisClientFrame hideNav title="Recovery problem"> <AnastasisClientFrame hideNav title="Recovery problem">
<div>invalid state</div> <div>invalid state</div>

View File

@ -22,10 +22,7 @@ export function AuthMethodQuestionSolve({ id }: AuthMethodSolveProps): VNode {
</AnastasisClientFrame> </AnastasisClientFrame>
); );
} }
if ( if (reducer.currentReducerState?.reducer_type !== "recovery") {
!reducer.currentReducerState ||
reducer.currentReducerState.recovery_state === undefined
) {
return ( return (
<AnastasisClientFrame hideNav title="Recovery problem"> <AnastasisClientFrame hideNav title="Recovery problem">
<div>invalid state</div> <div>invalid state</div>

View File

@ -44,10 +44,7 @@ export function AuthMethodSmsSolve({ id }: AuthMethodSolveProps): VNode {
</AnastasisClientFrame> </AnastasisClientFrame>
); );
} }
if ( if (reducer.currentReducerState?.reducer_type !== "recovery") {
!reducer.currentReducerState ||
reducer.currentReducerState.recovery_state === undefined
) {
return ( return (
<AnastasisClientFrame hideNav title="Recovery problem"> <AnastasisClientFrame hideNav title="Recovery problem">
<div>invalid state</div> <div>invalid state</div>

View File

@ -12,7 +12,7 @@ import { SolveOverviewFeedbackDisplay } from "../SolveScreen";
import { AuthMethodSolveProps } from "./index"; import { AuthMethodSolveProps } from "./index";
export function AuthMethodTotpSolve({ id }: AuthMethodSolveProps): VNode { export function AuthMethodTotpSolve({ id }: AuthMethodSolveProps): VNode {
const [answer, setAnswer] = useState(""); const [answerCode, setAnswerCode] = useState("");
const reducer = useAnastasisContext(); const reducer = useAnastasisContext();
if (!reducer) { if (!reducer) {
@ -22,10 +22,7 @@ export function AuthMethodTotpSolve({ id }: AuthMethodSolveProps): VNode {
</AnastasisClientFrame> </AnastasisClientFrame>
); );
} }
if ( if (reducer.currentReducerState?.reducer_type !== "recovery") {
!reducer.currentReducerState ||
reducer.currentReducerState.recovery_state === undefined
) {
return ( return (
<AnastasisClientFrame hideNav title="Recovery problem"> <AnastasisClientFrame hideNav title="Recovery problem">
<div>invalid state</div> <div>invalid state</div>
@ -72,11 +69,13 @@ export function AuthMethodTotpSolve({ id }: AuthMethodSolveProps): VNode {
for (const ch of chArr) { for (const ch of chArr) {
challenges[ch.uuid] = ch; challenges[ch.uuid] = ch;
} }
const selectedChallenge = challenges[selectedUuid];
const feedback = challengeFeedback[selectedUuid]; const feedback = challengeFeedback[selectedUuid];
async function onNext(): Promise<void> { async function onNext(): Promise<void> {
return reducer?.transition("solve_challenge", { answer }); console.log(`sending TOTP code '${answerCode}'`);
return reducer?.transition("solve_challenge", {
pin: Number.parseInt(answerCode),
});
} }
function onCancel(): void { function onCancel(): void {
reducer?.back(); reducer?.back();
@ -96,7 +95,7 @@ export function AuthMethodTotpSolve({ id }: AuthMethodSolveProps): VNode {
label="Answer" label="Answer"
onConfirm={onNext} onConfirm={onNext}
grabFocus grabFocus
bind={[answer, setAnswer]} bind={[answerCode, setAnswerCode]}
/> />
<div <div
@ -118,4 +117,3 @@ export function AuthMethodTotpSolve({ id }: AuthMethodSolveProps): VNode {
</AnastasisClientFrame> </AnastasisClientFrame>
); );
} }
// NKE8 VD857T X033X6RG WEGPYP6D70 Q7YE XN8D2 ZN79SCN 231B4QK0

View File

@ -23,8 +23,7 @@ export function AuthMethodVideoSolve({ id }: AuthMethodSolveProps): VNode {
); );
} }
if ( if (
!reducer.currentReducerState || reducer.currentReducerState?.reducer_type !== "recovery"
reducer.currentReducerState.recovery_state === undefined
) { ) {
return ( return (
<AnastasisClientFrame hideNav title="Recovery problem"> <AnastasisClientFrame hideNav title="Recovery problem">

View File

@ -14,55 +14,69 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/ */
import { AmountJson } from "."
import { Amounts, } from "./amounts"
import { getRandomBytes, decodeCrock, encodeCrock } from "./talerCrypto"
import * as segwit from "./segwit_addr"
/** /**
* *
* @author sebasjm * @author sebasjm
*/ */
/**
* Imports.
*/
import { AmountJson, Amounts } from "./amounts.js";
import { getRandomBytes, decodeCrock } from "./talerCrypto.js";
import * as segwit from "./segwit_addr.js";
export interface SegwitAddrs { export interface SegwitAddrs {
addr1: string, addr1: string;
addr2: string, addr2: string;
} }
function buf2hex(buffer: Uint8Array) { // buffer is an ArrayBuffer function buf2hex(buffer: Uint8Array) {
// buffer is an ArrayBuffer
return [...new Uint8Array(buffer)] return [...new Uint8Array(buffer)]
.map(x => x.toString(16).padStart(2, '0')) .map((x) => x.toString(16).padStart(2, "0"))
.join(''); .join("");
} }
export function generateFakeSegwitAddress(reservePub: string, addr: string): SegwitAddrs { export function generateFakeSegwitAddress(
const pub = decodeCrock(reservePub) reservePub: string,
addr: string,
): SegwitAddrs {
const pub = decodeCrock(reservePub);
const first_rnd = getRandomBytes(4) const first_rnd = getRandomBytes(4);
const second_rnd = new Uint8Array(first_rnd.length) const second_rnd = new Uint8Array(first_rnd.length);
second_rnd.set(first_rnd) second_rnd.set(first_rnd);
first_rnd[0] = first_rnd[0] & 0b0111_1111 first_rnd[0] = first_rnd[0] & 0b0111_1111;
second_rnd[0] = second_rnd[0] | 0b1000_0000 second_rnd[0] = second_rnd[0] | 0b1000_0000;
const first_part = new Uint8Array(first_rnd.length + pub.length / 2) const first_part = new Uint8Array(first_rnd.length + pub.length / 2);
first_part.set(first_rnd, 0) first_part.set(first_rnd, 0);
first_part.set(pub.subarray(0, 16), 4) first_part.set(pub.subarray(0, 16), 4);
const second_part = new Uint8Array(first_rnd.length + pub.length / 2) const second_part = new Uint8Array(first_rnd.length + pub.length / 2);
second_part.set(first_rnd, 0) second_part.set(first_rnd, 0);
second_part.set(pub.subarray(16), 4) second_part.set(pub.subarray(16), 4);
console.log(first_part.length, second_part.length) console.log(first_part.length, second_part.length);
const prefix = (addr[0] === 't' && addr[1] == 'b') ? "tb" : (addr[0] === 'b' && addr[1] == 'c' && addr[2] === 'r' && addr[3] == 't') ? 'bcrt' : (addr[0] === 'b' && addr[1] == 'c') ? 'bc' : undefined const prefix =
if (prefix === undefined) throw new Error('unknown bitcoin net') addr[0] === "t" && addr[1] == "b"
? "tb"
: addr[0] === "b" && addr[1] == "c" && addr[2] === "r" && addr[3] == "t"
? "bcrt"
: addr[0] === "b" && addr[1] == "c"
? "bc"
: undefined;
if (prefix === undefined) throw new Error("unknown bitcoin net");
return { return {
addr1: segwit.default.encode(prefix, 0, first_part), addr1: segwit.default.encode(prefix, 0, first_part),
addr2: segwit.default.encode(prefix, 0, second_part), addr2: segwit.default.encode(prefix, 0, second_part),
} };
} }
// https://github.com/bitcoin/bitcoin/blob/master/src/policy/policy.cpp // https://github.com/bitcoin/bitcoin/blob/master/src/policy/policy.cpp
export function segwitMinAmount(): AmountJson { export function segwitMinAmount(): AmountJson {
return Amounts.parseOrThrow("BTC:0.00000294") return Amounts.parseOrThrow("BTC:0.00000294");
} }