-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.spec.ts
60 lines (54 loc) · 1.47 KB
/
server.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { expect, test } from "vitest";
import {
deriveSessionKey,
deriveServerProof,
deriveMultiplierSRP6a,
generateServerEphemeral,
} from "../src/srp/server";
import { byteArrayToHexString, hexStringToByteArray } from "../src/utils";
import {
A,
B,
K,
b,
k,
u,
v,
expectedM1,
expectedM2,
parameters,
} from "./test-vector-rfc5054";
test("it should derive multiplier as per RFC5054", async () => {
const multiplier = await deriveMultiplierSRP6a(parameters);
expect(multiplier).toEqual(hexStringToByteArray(k));
});
test("it should generate server ephemeral value as per RFC5054", async () => {
const { serverPrivateEphemeral, serverPublicEphemeral } =
await generateServerEphemeral({
verifier: v,
parameters,
unsafe_staticPrivateEphemeral: b,
});
expect(serverPrivateEphemeral).toEqual(b);
expect(serverPublicEphemeral).toEqual(B);
});
test("it should derive session key as per RFC5054", async () => {
const sessionKey = await deriveSessionKey({
verifier: v,
sharedHash: u,
clientPublicEphemeral: A,
serverPrivateEphemeral: b,
parameters,
});
expect(byteArrayToHexString(sessionKey)).toBe(byteArrayToHexString(K));
});
test("it should server proof correctly", async () => {
const clientProof = expectedM1;
const serverProof = await deriveServerProof({
clientProof,
clientPublicEphemeral: A,
sessionKey: K,
parameters,
});
expect(byteArrayToHexString(serverProof)).toBe(expectedM2);
});