@geektr.cloud/acrux-auth 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +796 -2
- package/package.json +59 -3
- package/src/components/AuthError.vue +45 -0
- package/src/components/AuthLogin.vue +201 -0
- package/src/components/PubKeyClient.vue +477 -0
- package/src/index.ts +82 -0
- package/src/next.ts +22 -0
- package/src/passkey-client.ts +159 -0
- package/src/passkey-metadata.ts +56 -0
- package/src/pubkey-client.ts +183 -0
- package/src/pubkey-proof.ts +179 -0
- package/src/pubkey-transport.ts +107 -0
- package/src/pubkey-types.ts +41 -0
- package/src/server/http.ts +27 -0
- package/src/server/identity.ts +22 -0
- package/src/server/index.ts +10 -0
- package/src/server/passkey/challenge.ts +70 -0
- package/src/server/passkey/config.ts +97 -0
- package/src/server/passkey/index.ts +10 -0
- package/src/server/passkey/routes.ts +310 -0
- package/src/server/passkey/store.ts +84 -0
- package/src/server/provider.ts +90 -0
- package/src/server/providers/cloudflare.ts +83 -0
- package/src/server/providers/custom.ts +47 -0
- package/src/server/providers/github.ts +112 -0
- package/src/server/providers/google.ts +45 -0
- package/src/server/providers/index.ts +4 -0
- package/src/server/pubkey/errors.ts +32 -0
- package/src/server/pubkey/fixtures.ts +156 -0
- package/src/server/pubkey/http.ts +91 -0
- package/src/server/pubkey/index.ts +10 -0
- package/src/server/pubkey/keys.ts +166 -0
- package/src/server/pubkey/resolve.ts +189 -0
- package/src/server/pubkey/resolver.ts +111 -0
- package/src/server/pubkey/verify.ts +119 -0
- package/src/server/pubkey/wkd.ts +78 -0
- package/src/server/pubkey-passkey/index.ts +14 -0
- package/src/server/pubkey-passkey/routes.ts +260 -0
- package/src/server/routes.ts +340 -0
- package/src/server/session.ts +86 -0
- package/src/server/userpass.ts +104 -0
- package/src/types.ts +82 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, nextTick, onMounted, ref, useId, watch } from "vue";
|
|
3
|
+
import { CopyBtn, Text } from "@geektr.cloud/acrux-ui/base";
|
|
4
|
+
import { CodeBlock, Disclosure, Notice } from "@geektr.cloud/acrux-ui/display";
|
|
5
|
+
import { Select } from "@geektr.cloud/acrux-ui/fields";
|
|
6
|
+
import { createStepperState, Stepper } from "@geektr.cloud/acrux-ui/actions";
|
|
7
|
+
import type { StepperItem } from "@geektr.cloud/acrux-ui/actions";
|
|
8
|
+
import { Button } from "@geektr.cloud/acrux-ui/ui/button";
|
|
9
|
+
import { Card } from "@geektr.cloud/acrux-ui/ui/card";
|
|
10
|
+
import { Textarea } from "@geektr.cloud/acrux-ui/ui/textarea";
|
|
11
|
+
import {
|
|
12
|
+
createPowerShellSignCommand,
|
|
13
|
+
createPubKeySignCommand,
|
|
14
|
+
detectPreferredShell,
|
|
15
|
+
formatPubKeyLongKeyId,
|
|
16
|
+
normalizeFingerprint,
|
|
17
|
+
type PubKeyClientEmits,
|
|
18
|
+
type PubKeyClientProps,
|
|
19
|
+
type PubKeyClientSlots,
|
|
20
|
+
type PubKeyClientSubmitPayload,
|
|
21
|
+
type PubKeyShell,
|
|
22
|
+
} from "../pubkey-client";
|
|
23
|
+
import AuthError from "./AuthError.vue";
|
|
24
|
+
|
|
25
|
+
const props = withDefaults(defineProps<PubKeyClientProps>(), {
|
|
26
|
+
fingerprint: "",
|
|
27
|
+
contentSummary: "",
|
|
28
|
+
loading: false,
|
|
29
|
+
disabled: false,
|
|
30
|
+
name: "pubkey",
|
|
31
|
+
submitLabel: "验证签名",
|
|
32
|
+
loadingLabel: "验证中…",
|
|
33
|
+
variant: "modal",
|
|
34
|
+
vulgar: false,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const emit = defineEmits<PubKeyClientEmits>();
|
|
38
|
+
defineSlots<PubKeyClientSlots>();
|
|
39
|
+
|
|
40
|
+
const fingerprint = defineModel<string>("fingerprint", { default: "" });
|
|
41
|
+
const signature = ref("");
|
|
42
|
+
|
|
43
|
+
const uid = useId();
|
|
44
|
+
const selectId = computed(() => `${props.name}-${uid}-key`);
|
|
45
|
+
const signatureId = computed(() => `${props.name}-${uid}-signature`);
|
|
46
|
+
const errorId = computed(() => `${props.name}-${uid}-error`);
|
|
47
|
+
const selectionErrorId = computed(() => `${props.name}-${uid}-key-error`);
|
|
48
|
+
const signatureHintId = computed(() => `${props.name}-${uid}-signature-hint`);
|
|
49
|
+
const messageWorkspaceLabelId = computed(() => `${props.name}-${uid}-message-workspace-label`);
|
|
50
|
+
const commandWorkspaceLabelId = computed(() => `${props.name}-${uid}-command-workspace-label`);
|
|
51
|
+
|
|
52
|
+
const tabId = (shell: PubKeyShell) => `${props.name}-${uid}-${shell}-tab`;
|
|
53
|
+
|
|
54
|
+
const isBusy = computed(() => props.loading || props.disabled);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 匹配前去掉空白并转大写;空值回落到第一把公钥。
|
|
58
|
+
* 非空但不匹配时保持 `null`,不回退,交给调用方纠正选择。
|
|
59
|
+
*/
|
|
60
|
+
const selectedKey = computed(() => {
|
|
61
|
+
const wanted = normalizeFingerprint(fingerprint.value);
|
|
62
|
+
if (!wanted) return props.publicKeys[0] ?? null;
|
|
63
|
+
return props.publicKeys.find((key) => normalizeFingerprint(key.fingerprint) === wanted) ?? null;
|
|
64
|
+
});
|
|
65
|
+
const selectedFingerprint = computed(() => selectedKey.value?.fingerprint ?? "");
|
|
66
|
+
|
|
67
|
+
const shellOrder: PubKeyShell[] = ["unix", "powershell"];
|
|
68
|
+
// 先以 SSR 稳定的 unix 渲染,挂载后再按真实 userAgent 切到 Windows 的默认 tab。
|
|
69
|
+
const activeShell = ref<PubKeyShell>("unix");
|
|
70
|
+
const tabRefs = ref<HTMLButtonElement[]>([]);
|
|
71
|
+
|
|
72
|
+
const shellTabs = computed(() =>
|
|
73
|
+
shellOrder.map((shell) => ({
|
|
74
|
+
shell,
|
|
75
|
+
label:
|
|
76
|
+
shell === "unix"
|
|
77
|
+
? props.vulgar
|
|
78
|
+
? "Normal Shell"
|
|
79
|
+
: "Unix-like Shell"
|
|
80
|
+
: props.vulgar
|
|
81
|
+
? "Fucking PowerShell"
|
|
82
|
+
: "PowerShell",
|
|
83
|
+
})),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const setTabRef = (index: number, element: unknown) => {
|
|
87
|
+
if (element instanceof HTMLButtonElement) tabRefs.value[index] = element;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const selectShell = (shell: PubKeyShell) => {
|
|
91
|
+
activeShell.value = shell;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const onTabKeydown = (event: KeyboardEvent, index: number) => {
|
|
95
|
+
let next = index;
|
|
96
|
+
if (event.key === "ArrowRight") next = (index + 1) % shellOrder.length;
|
|
97
|
+
else if (event.key === "ArrowLeft") next = (index - 1 + shellOrder.length) % shellOrder.length;
|
|
98
|
+
else if (event.key === "Home") next = 0;
|
|
99
|
+
else if (event.key === "End") next = shellOrder.length - 1;
|
|
100
|
+
else return;
|
|
101
|
+
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
const shell = shellOrder[next];
|
|
104
|
+
if (!shell) return;
|
|
105
|
+
// selection follows focus:方向键移动焦点时同步切换面板。
|
|
106
|
+
selectShell(shell);
|
|
107
|
+
void nextTick(() => tabRefs.value[next]?.focus());
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const isPage = computed(() => props.variant === "page");
|
|
111
|
+
const rootClass = computed(() =>
|
|
112
|
+
isPage.value ? "min-h-svh w-full min-w-0 bg-background text-foreground" : "w-full min-w-0",
|
|
113
|
+
);
|
|
114
|
+
const cardClass = computed(() =>
|
|
115
|
+
isPage.value
|
|
116
|
+
? "mx-auto w-full min-w-0 max-w-5xl px-4 py-8 sm:px-8 sm:py-10"
|
|
117
|
+
: "flex max-h-[85vh] w-full min-w-0 flex-col gap-0 py-0 shadow-sm",
|
|
118
|
+
);
|
|
119
|
+
const bodyClass = computed(() => (isPage.value ? "min-w-0" : "min-h-0 min-w-0 flex-1 overflow-y-auto p-4 sm:p-5"));
|
|
120
|
+
const formClass = "mt-5 min-w-0";
|
|
121
|
+
const fieldLabelClass = "text-xs font-medium leading-none";
|
|
122
|
+
const workspaceLabelClass = "text-sm font-medium leading-none";
|
|
123
|
+
const messageMaxHeight = computed(() => (isPage.value ? "16rem" : "10rem"));
|
|
124
|
+
const commandMaxHeight = computed(() => (isPage.value ? "20rem" : "16rem"));
|
|
125
|
+
const actionsClass = "flex flex-wrap justify-start pt-1";
|
|
126
|
+
|
|
127
|
+
const command = computed(() => {
|
|
128
|
+
if (!selectedKey.value || props.message.length === 0) return null;
|
|
129
|
+
return activeShell.value === "powershell"
|
|
130
|
+
? createPowerShellSignCommand({ message: props.message, fingerprint: selectedKey.value.fingerprint })
|
|
131
|
+
: createPubKeySignCommand({ message: props.message, fingerprint: selectedKey.value.fingerprint });
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const flow = ref(createStepperState(props.message.length === 0 ? "prepare" : "sign"));
|
|
135
|
+
|
|
136
|
+
const longKeyId = computed(() => formatPubKeyLongKeyId(selectedFingerprint.value) || "未选择");
|
|
137
|
+
/** 详情区展示与复制用:完整规范化 primary fingerprint,不加分组空格。 */
|
|
138
|
+
const fullFingerprint = computed(() => normalizeFingerprint(selectedFingerprint.value));
|
|
139
|
+
const preparationSummary = computed(() =>
|
|
140
|
+
[`公钥 ${longKeyId.value}`, props.contentSummary.trim()].filter(Boolean).join(" · "),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const stepItems = computed<StepperItem[]>(() => [
|
|
144
|
+
{ id: "prepare", title: "准备签名", summary: preparationSummary.value },
|
|
145
|
+
{
|
|
146
|
+
id: "sign",
|
|
147
|
+
title: "在本地签名",
|
|
148
|
+
summary: !command.value
|
|
149
|
+
? "需要有效公钥和非空待签名内容"
|
|
150
|
+
: flow.value.furthest === "submit"
|
|
151
|
+
? "待签名内容与命令已确认"
|
|
152
|
+
: "待签名内容与命令已就绪",
|
|
153
|
+
disabled: !command.value,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "submit",
|
|
157
|
+
title: "提交签名",
|
|
158
|
+
summary: signature.value.trim() ? "签名已填写,可返回提交" : "粘贴本地生成的 armored 签名后提交",
|
|
159
|
+
disabled: !command.value,
|
|
160
|
+
},
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
// 只在命中的情况下把模型收敛到公钥自身的 canonical fingerprint;未命中不动模型。
|
|
164
|
+
watch(
|
|
165
|
+
selectedKey,
|
|
166
|
+
(key) => {
|
|
167
|
+
if (key && fingerprint.value !== key.fingerprint) fingerprint.value = key.fingerprint;
|
|
168
|
+
},
|
|
169
|
+
{ immediate: true },
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
watch(selectedKey, (key) => emit("select", key));
|
|
173
|
+
|
|
174
|
+
const submitError = ref("");
|
|
175
|
+
const fingerprintSelection = computed<string | null>({
|
|
176
|
+
get: () => selectedFingerprint.value,
|
|
177
|
+
set: (value) => {
|
|
178
|
+
fingerprint.value = value ?? "";
|
|
179
|
+
submitError.value = "";
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
const selectionError = computed(() => {
|
|
183
|
+
if (selectedKey.value || props.publicKeys.length === 0) return "";
|
|
184
|
+
return `所选公钥 ${formatPubKeyLongKeyId(fingerprint.value)} 不在可用列表中,请重新选择。`;
|
|
185
|
+
});
|
|
186
|
+
const showError = (message: string) => {
|
|
187
|
+
submitError.value = message;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/** key / message 是签名输入的组成部分;变化后作废旧签名并重建可达阶段。 */
|
|
191
|
+
const resetFlowForInput = () => {
|
|
192
|
+
signature.value = "";
|
|
193
|
+
submitError.value = "";
|
|
194
|
+
flow.value = createStepperState(props.message.length === 0 ? "prepare" : "sign");
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
watch(
|
|
198
|
+
() => props.message,
|
|
199
|
+
(message, previous) => {
|
|
200
|
+
if (message !== previous) resetFlowForInput();
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
watch(selectedFingerprint, (value, previous) => {
|
|
204
|
+
if (value !== previous) resetFlowForInput();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
let submitLock = false;
|
|
208
|
+
|
|
209
|
+
const handleSubmit = () => {
|
|
210
|
+
if (flow.value.current !== "submit" || submitLock || isBusy.value) return;
|
|
211
|
+
if (!selectedKey.value) {
|
|
212
|
+
showError(selectionError.value || "请选择用于验证签名的公钥");
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (!command.value) {
|
|
216
|
+
showError("请填写要签名的内容");
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (signature.value.trim().length === 0) {
|
|
220
|
+
showError("请粘贴 armored 签名");
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
submitLock = true;
|
|
225
|
+
const payload: PubKeyClientSubmitPayload = {
|
|
226
|
+
fingerprint: selectedKey.value.fingerprint,
|
|
227
|
+
signature: signature.value,
|
|
228
|
+
};
|
|
229
|
+
emit("submit", payload);
|
|
230
|
+
// 父组件通常立刻把 loading 设为 true;这个锁只挡住同一事件循环内的重复提交。
|
|
231
|
+
setTimeout(() => {
|
|
232
|
+
submitLock = false;
|
|
233
|
+
}, 0);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
onMounted(() => {
|
|
237
|
+
activeShell.value = detectPreferredShell(typeof navigator === "undefined" ? undefined : navigator.userAgent);
|
|
238
|
+
emit("select", selectedKey.value);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
watch(isBusy, (busy) => {
|
|
242
|
+
if (!busy) submitError.value = "";
|
|
243
|
+
});
|
|
244
|
+
</script>
|
|
245
|
+
|
|
246
|
+
<template>
|
|
247
|
+
<div data-slot="pubkey-client" :data-variant="variant" :class="rootClass">
|
|
248
|
+
<component :is="isPage ? 'div' : Card" data-slot="card" :class="cardClass">
|
|
249
|
+
<div data-slot="body" :class="bodyClass">
|
|
250
|
+
<div :data-slot="isPage ? 'page-header' : 'guide'">
|
|
251
|
+
<slot name="guide" :command="command">
|
|
252
|
+
<Text variant="lead">
|
|
253
|
+
准备签名信息,在本地终端执行命令生成 detached armor 签名,再把签名粘贴回来提交。私钥不会离开本机。
|
|
254
|
+
</Text>
|
|
255
|
+
</slot>
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
<form data-slot="form" :class="formClass" :aria-busy="isBusy || undefined" @submit.prevent="handleSubmit">
|
|
259
|
+
<Stepper v-model="flow" :items="stepItems">
|
|
260
|
+
<template #default="{ item, continue: continueStep }">
|
|
261
|
+
<div
|
|
262
|
+
v-if="item.id === 'prepare'"
|
|
263
|
+
data-slot="step-content"
|
|
264
|
+
class="grid min-w-0 grid-cols-[minmax(0,1fr)] content-start gap-5"
|
|
265
|
+
>
|
|
266
|
+
<div class="grid min-w-0 grid-cols-[minmax(0,1fr)] gap-2">
|
|
267
|
+
<label :for="selectId" :class="fieldLabelClass">公钥</label>
|
|
268
|
+
<div v-if="publicKeys.length > 0" data-slot="key-select">
|
|
269
|
+
<Select
|
|
270
|
+
:id="selectId"
|
|
271
|
+
v-model="fingerprintSelection"
|
|
272
|
+
:items="publicKeys"
|
|
273
|
+
:transform-fn="
|
|
274
|
+
(key) => ({
|
|
275
|
+
value: key.fingerprint,
|
|
276
|
+
label: formatPubKeyLongKeyId(key.fingerprint),
|
|
277
|
+
})
|
|
278
|
+
"
|
|
279
|
+
placeholder="请选择公钥"
|
|
280
|
+
:disabled="isBusy || publicKeys.length === 1"
|
|
281
|
+
:aria-invalid="selectionError ? 'true' : undefined"
|
|
282
|
+
:aria-describedby="selectionError ? selectionErrorId : undefined"
|
|
283
|
+
/>
|
|
284
|
+
<input
|
|
285
|
+
type="hidden"
|
|
286
|
+
:name="`${name}-fingerprint`"
|
|
287
|
+
:value="selectedFingerprint"
|
|
288
|
+
:disabled="isBusy"
|
|
289
|
+
/>
|
|
290
|
+
</div>
|
|
291
|
+
|
|
292
|
+
<Notice v-else data-slot="key-empty">没有可用公钥,无法生成签名命令。</Notice>
|
|
293
|
+
<Notice v-if="selectionError" :id="selectionErrorId" data-slot="key-invalid" tone="error">
|
|
294
|
+
{{ selectionError }}
|
|
295
|
+
</Notice>
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
<slot
|
|
299
|
+
name="default"
|
|
300
|
+
:public-key="selectedKey"
|
|
301
|
+
:fingerprint="selectedFingerprint"
|
|
302
|
+
:command="command"
|
|
303
|
+
:disabled="isBusy"
|
|
304
|
+
:loading="loading"
|
|
305
|
+
/>
|
|
306
|
+
|
|
307
|
+
<div
|
|
308
|
+
v-if="selectedKey"
|
|
309
|
+
data-slot="key"
|
|
310
|
+
class="grid min-w-0 grid-cols-[minmax(0,1fr)] gap-2 border-t border-border pt-4"
|
|
311
|
+
>
|
|
312
|
+
<slot name="key" :public-key="selectedKey" :fingerprint="selectedKey.fingerprint">
|
|
313
|
+
<dl class="grid min-w-0 grid-cols-[minmax(0,1fr)] gap-2 text-xs">
|
|
314
|
+
<div data-slot="key-fingerprint" class="min-w-0">
|
|
315
|
+
<Text as="dt" variant="muted" class="font-medium">Primary fingerprint</Text>
|
|
316
|
+
<Text as="dd" class="mt-0.5 flex min-w-0 items-start gap-2">
|
|
317
|
+
<Text variant="inlineCode" class="min-w-0 flex-1 break-all">{{ fullFingerprint }}</Text>
|
|
318
|
+
<CopyBtn :value="fullFingerprint" label="复制完整 fingerprint" :disabled="isBusy" />
|
|
319
|
+
</Text>
|
|
320
|
+
</div>
|
|
321
|
+
</dl>
|
|
322
|
+
<Disclosure data-slot="key-armored" summary="查看 Armored 公钥">
|
|
323
|
+
<CodeBlock
|
|
324
|
+
:value="selectedKey.armoredKey"
|
|
325
|
+
copy-label="复制 Armored public key"
|
|
326
|
+
max-height="12rem"
|
|
327
|
+
/>
|
|
328
|
+
</Disclosure>
|
|
329
|
+
</slot>
|
|
330
|
+
</div>
|
|
331
|
+
</div>
|
|
332
|
+
|
|
333
|
+
<div
|
|
334
|
+
v-else-if="item.id === 'sign'"
|
|
335
|
+
data-slot="step-command"
|
|
336
|
+
class="grid min-w-0 grid-cols-[minmax(0,1fr)] content-start gap-5"
|
|
337
|
+
>
|
|
338
|
+
<div class="grid min-w-0 grid-cols-[minmax(0,1fr)] items-start gap-5 lg:grid-cols-2 lg:gap-6">
|
|
339
|
+
<section class="grid min-w-0 content-start gap-2" :aria-labelledby="messageWorkspaceLabelId">
|
|
340
|
+
<h3 :id="messageWorkspaceLabelId" :class="workspaceLabelClass">待签名内容</h3>
|
|
341
|
+
<div data-slot="message" class="min-w-0">
|
|
342
|
+
<div data-slot="message-text" class="min-w-0">
|
|
343
|
+
<CodeBlock
|
|
344
|
+
:value="message || '(空)'"
|
|
345
|
+
:copy="Boolean(message)"
|
|
346
|
+
copy-label="复制 签名内容"
|
|
347
|
+
:max-height="messageMaxHeight"
|
|
348
|
+
/>
|
|
349
|
+
</div>
|
|
350
|
+
<Text v-if="message.length === 0" variant="muted" class="mt-1.5">
|
|
351
|
+
内容为空,无法生成签名命令。
|
|
352
|
+
</Text>
|
|
353
|
+
</div>
|
|
354
|
+
</section>
|
|
355
|
+
|
|
356
|
+
<section class="grid min-w-0 content-start gap-2" :aria-labelledby="commandWorkspaceLabelId">
|
|
357
|
+
<h3 :id="commandWorkspaceLabelId" :class="workspaceLabelClass">签名命令</h3>
|
|
358
|
+
<div data-slot="command" class="min-w-0">
|
|
359
|
+
<div
|
|
360
|
+
data-slot="command-tabs"
|
|
361
|
+
role="tablist"
|
|
362
|
+
aria-label="签名命令 Shell"
|
|
363
|
+
class="grid min-w-0 grid-cols-2 border-b border-border"
|
|
364
|
+
>
|
|
365
|
+
<button
|
|
366
|
+
v-for="(tab, index) in shellTabs"
|
|
367
|
+
:id="tabId(tab.shell)"
|
|
368
|
+
:key="tab.shell"
|
|
369
|
+
:ref="(element) => setTabRef(index, element)"
|
|
370
|
+
type="button"
|
|
371
|
+
role="tab"
|
|
372
|
+
:aria-selected="activeShell === tab.shell"
|
|
373
|
+
:tabindex="activeShell === tab.shell ? 0 : -1"
|
|
374
|
+
class="-mb-px inline-flex min-h-8 w-full min-w-0 items-center justify-center border-b-2 px-2 py-1 text-center text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/50"
|
|
375
|
+
:class="
|
|
376
|
+
activeShell === tab.shell
|
|
377
|
+
? 'border-foreground font-medium text-foreground'
|
|
378
|
+
: 'border-transparent text-muted-foreground hover:text-foreground'
|
|
379
|
+
"
|
|
380
|
+
@click="selectShell(tab.shell)"
|
|
381
|
+
@keydown="onTabKeydown($event, index)"
|
|
382
|
+
>
|
|
383
|
+
{{ tab.label }}
|
|
384
|
+
</button>
|
|
385
|
+
</div>
|
|
386
|
+
|
|
387
|
+
<div
|
|
388
|
+
data-slot="command-panel"
|
|
389
|
+
role="tabpanel"
|
|
390
|
+
:aria-labelledby="tabId(activeShell)"
|
|
391
|
+
tabindex="0"
|
|
392
|
+
class="mt-2 min-w-0 outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
|
|
393
|
+
>
|
|
394
|
+
<slot name="command" :command="command">
|
|
395
|
+
<div v-if="command" data-slot="command-text" class="min-w-0">
|
|
396
|
+
<CodeBlock :value="command" copy-label="复制 签名命令" :max-height="commandMaxHeight" />
|
|
397
|
+
</div>
|
|
398
|
+
<Text v-else variant="muted">填写签名内容并选择有效公钥后生成命令。</Text>
|
|
399
|
+
</slot>
|
|
400
|
+
</div>
|
|
401
|
+
</div>
|
|
402
|
+
</section>
|
|
403
|
+
</div>
|
|
404
|
+
|
|
405
|
+
<Text variant="muted">
|
|
406
|
+
<span class="font-medium text-foreground">命令安全:</span>
|
|
407
|
+
页面不会执行命令;请复制后在受信任的本地终端运行,生成 detached armor 签名。
|
|
408
|
+
</Text>
|
|
409
|
+
<div class="flex justify-start">
|
|
410
|
+
<Button
|
|
411
|
+
data-slot="continue"
|
|
412
|
+
type="button"
|
|
413
|
+
:disabled="isBusy || item.disabled"
|
|
414
|
+
class="w-full sm:w-auto"
|
|
415
|
+
@click="continueStep"
|
|
416
|
+
>
|
|
417
|
+
继续提交签名
|
|
418
|
+
</Button>
|
|
419
|
+
</div>
|
|
420
|
+
</div>
|
|
421
|
+
|
|
422
|
+
<div v-else data-slot="step-signature" class="grid min-w-0 grid-cols-[minmax(0,1fr)] content-start gap-4">
|
|
423
|
+
<div class="grid min-w-0 grid-cols-[minmax(0,1fr)] gap-2">
|
|
424
|
+
<label :for="signatureId" :class="fieldLabelClass">Armored 签名</label>
|
|
425
|
+
<Text :id="signatureHintId" variant="muted">
|
|
426
|
+
粘贴 <Text variant="inlineCode" class="break-all">-----BEGIN PGP SIGNATURE-----</Text>
|
|
427
|
+
开头的完整文本。
|
|
428
|
+
</Text>
|
|
429
|
+
<div data-slot="signature" class="min-w-0">
|
|
430
|
+
<Textarea
|
|
431
|
+
:id="signatureId"
|
|
432
|
+
v-model="signature"
|
|
433
|
+
:name="`${name}-signature`"
|
|
434
|
+
:disabled="isBusy"
|
|
435
|
+
:aria-describedby="submitError ? `${signatureHintId} ${errorId}` : signatureHintId"
|
|
436
|
+
:aria-invalid="submitError ? 'true' : undefined"
|
|
437
|
+
:rows="isPage ? 6 : 7"
|
|
438
|
+
required
|
|
439
|
+
spellcheck="false"
|
|
440
|
+
autocomplete="off"
|
|
441
|
+
class="field-sizing-auto max-w-full"
|
|
442
|
+
/>
|
|
443
|
+
</div>
|
|
444
|
+
</div>
|
|
445
|
+
|
|
446
|
+
<AuthError :id="errorId" :message="submitError">
|
|
447
|
+
<template v-if="$slots.error" #default="{ message }">
|
|
448
|
+
<slot name="error" :message="message" />
|
|
449
|
+
</template>
|
|
450
|
+
</AuthError>
|
|
451
|
+
|
|
452
|
+
<div data-slot="actions" :class="actionsClass">
|
|
453
|
+
<slot name="actions" :disabled="isBusy || !command" :loading="loading">
|
|
454
|
+
<Button
|
|
455
|
+
data-slot="submit"
|
|
456
|
+
type="submit"
|
|
457
|
+
:disabled="isBusy || !command"
|
|
458
|
+
class="w-full min-w-32 sm:w-auto"
|
|
459
|
+
>
|
|
460
|
+
<slot name="button" :disabled="isBusy || !command" :loading="loading">
|
|
461
|
+
{{ loading ? loadingLabel : submitLabel }}
|
|
462
|
+
</slot>
|
|
463
|
+
</Button>
|
|
464
|
+
</slot>
|
|
465
|
+
</div>
|
|
466
|
+
</div>
|
|
467
|
+
</template>
|
|
468
|
+
</Stepper>
|
|
469
|
+
</form>
|
|
470
|
+
|
|
471
|
+
<div v-if="$slots['page-aside']" data-slot="page-aside" class="mt-5 min-w-0">
|
|
472
|
+
<slot name="page-aside" />
|
|
473
|
+
</div>
|
|
474
|
+
</div>
|
|
475
|
+
</component>
|
|
476
|
+
</div>
|
|
477
|
+
</template>
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export { default as AuthLogin } from "./components/AuthLogin.vue";
|
|
2
|
+
export { default as PubKeyClient } from "./components/PubKeyClient.vue";
|
|
3
|
+
export { sanitizeNext } from "./next";
|
|
4
|
+
export {
|
|
5
|
+
authenticatePasskey,
|
|
6
|
+
getPasskeyStatus,
|
|
7
|
+
PasskeyRequestError,
|
|
8
|
+
registerPasskey,
|
|
9
|
+
supportsPasskeys,
|
|
10
|
+
type PasskeyAuthenticationResult,
|
|
11
|
+
type PasskeyClientOptions,
|
|
12
|
+
type PasskeyRegistrationResult,
|
|
13
|
+
type PasskeyStatus,
|
|
14
|
+
} from "./passkey-client";
|
|
15
|
+
export type { PasskeyRegistrationMetadata } from "./passkey-metadata";
|
|
16
|
+
export {
|
|
17
|
+
buildPubKeyCredentialProofMessage,
|
|
18
|
+
buildPubKeyProofMessage,
|
|
19
|
+
parsePubKeyCredentialProofMessage,
|
|
20
|
+
parsePubKeyProofMessage,
|
|
21
|
+
PUBKEY_PROOF_CREDENTIAL_ID_MAX_LENGTH,
|
|
22
|
+
PUBKEY_PROOF_CREDENTIAL_PUBLIC_KEY_MAX_LENGTH,
|
|
23
|
+
PUBKEY_PROOF_MAX_AGE_MS,
|
|
24
|
+
PUBKEY_PROOF_MAX_FUTURE_MS,
|
|
25
|
+
PUBKEY_PROOF_MESSAGE_MAX_LENGTH,
|
|
26
|
+
PUBKEY_PROOF_USERNAME_MAX_LENGTH,
|
|
27
|
+
PubKeyProofError,
|
|
28
|
+
type ParsedPubKeyCredentialProofMessage,
|
|
29
|
+
type ParsedPubKeyProofMessage,
|
|
30
|
+
type PubKeyProofCredential,
|
|
31
|
+
type PubKeyProofErrorCode,
|
|
32
|
+
type PubKeyProofMode,
|
|
33
|
+
} from "./pubkey-proof";
|
|
34
|
+
export {
|
|
35
|
+
createPowerShellSignCommand,
|
|
36
|
+
createPubKeySignCommand,
|
|
37
|
+
detectPreferredShell,
|
|
38
|
+
formatPubKeyLongKeyId,
|
|
39
|
+
normalizeFingerprint,
|
|
40
|
+
powershellEscape,
|
|
41
|
+
shellEscape,
|
|
42
|
+
type PubKeyClientActionSlotProps,
|
|
43
|
+
type PubKeyClientCommandSlotProps,
|
|
44
|
+
type PubKeyClientDefaultSlotProps,
|
|
45
|
+
type PubKeyClientEmits,
|
|
46
|
+
type PubKeyClientErrorSlotProps,
|
|
47
|
+
type PubKeyClientKeySlotProps,
|
|
48
|
+
type PubKeyClientProps,
|
|
49
|
+
type PubKeyClientSlots,
|
|
50
|
+
type PubKeyClientSubmitPayload,
|
|
51
|
+
type PubKeyClientVariant,
|
|
52
|
+
type PubKeyShell,
|
|
53
|
+
type PubKeySignCommandOptions,
|
|
54
|
+
} from "./pubkey-client";
|
|
55
|
+
export {
|
|
56
|
+
getPubKeyPasskeyKeys,
|
|
57
|
+
PubKeyPasskeyRequestError,
|
|
58
|
+
refreshPubKeyPasskeyKeys,
|
|
59
|
+
registerPubKeyPasskey,
|
|
60
|
+
type PubKeyPasskeyClientOptions,
|
|
61
|
+
type PubKeyPasskeyKeysResult,
|
|
62
|
+
} from "./pubkey-transport";
|
|
63
|
+
export type {
|
|
64
|
+
PubKeyPasskeyCredential,
|
|
65
|
+
PubKeyPasskeyKeysResponse,
|
|
66
|
+
PubKeyPasskeyRefreshResponse,
|
|
67
|
+
PubKeyPasskeyRegisterRequest,
|
|
68
|
+
PubKeyPasskeyRegisterResponse,
|
|
69
|
+
PubKeyResolverStatus,
|
|
70
|
+
ResolvedPubKey,
|
|
71
|
+
} from "./pubkey-types";
|
|
72
|
+
export type {
|
|
73
|
+
AuthLoginActionSlotProps,
|
|
74
|
+
AuthLoginEmits,
|
|
75
|
+
AuthLoginErrorSlotProps,
|
|
76
|
+
AuthLoginFieldSlotProps,
|
|
77
|
+
AuthLoginProps,
|
|
78
|
+
AuthLoginProvider,
|
|
79
|
+
AuthLoginProviderSlotProps,
|
|
80
|
+
AuthLoginSlots,
|
|
81
|
+
AuthLoginSubmitPayload,
|
|
82
|
+
} from "./types";
|
package/src/next.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const MAX_NEXT_CHARACTERS = 256;
|
|
2
|
+
|
|
3
|
+
const hasControlCharacter = (value: string): boolean => {
|
|
4
|
+
for (const character of value) {
|
|
5
|
+
const code = character.charCodeAt(0);
|
|
6
|
+
if (code <= 0x1f || code === 0x7f) return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 只允许单 `/` 开头的站内路径。拒绝协议相对 URL、反斜杠与控制字符,
|
|
13
|
+
* 避免 `next` 变成开放重定向。非法值一律回到 `/`。
|
|
14
|
+
*
|
|
15
|
+
* 上限按 Unicode 字符数(code point)计算,防止中文等字符撑大签名 cookie。
|
|
16
|
+
*/
|
|
17
|
+
export const sanitizeNext = (value: string | null | undefined): string => {
|
|
18
|
+
if (!value || [...value].length > MAX_NEXT_CHARACTERS) return "/";
|
|
19
|
+
if (!value.startsWith("/") || value.startsWith("//")) return "/";
|
|
20
|
+
if (value.includes("\\") || hasControlCharacter(value)) return "/";
|
|
21
|
+
return value;
|
|
22
|
+
};
|