Skip to content

Commit

Permalink
refactor: use calculateSrpA instead
Browse files Browse the repository at this point in the history
  • Loading branch information
caru-ini committed Jul 2, 2024
1 parent a939e17 commit f051d79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 15 additions & 0 deletions server/domain/user/service/srp/calcSrpA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Buffer } from 'buffer';
import crypto from 'crypto';
import { N, g } from 'domain/user/service/srp/constants';
import { fromBuffer, toBuffer } from 'domain/user/service/srp/util';
import { BigInteger } from 'jsbn';

export const calculateSrpA = (): { a: Buffer; A: Buffer } => {
let a = Buffer.from([0]);
let AInt = BigInteger.ZERO;
while (AInt === BigInteger.ZERO) {
a = crypto.randomBytes(32);
AInt = g.modPow(fromBuffer(a), N);
}
return { a, A: toBuffer(AInt) };
};
8 changes: 3 additions & 5 deletions server/tests/api/changePassword.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import assert from 'assert';
import crypto from 'crypto';
import { calcClientSignature } from 'domain/user/service/srp/calcClientSignature';
import { N, g } from 'domain/user/service/srp/constants';
import { fromBuffer, toBuffer } from 'domain/user/service/srp/util';
import { calculateSrpA } from 'domain/user/service/srp/calcSrpA';
import { fromBuffer } from 'domain/user/service/srp/util';
import { DEFAULT_USER_POOL_CLIENT_ID } from 'service/envValues';
import { test } from 'vitest';
import {
Expand All @@ -15,8 +14,7 @@ import {

test('changePassword', async () => {
await createUserClient();
const a = crypto.randomBytes(32);
const A = toBuffer(g.modPow(fromBuffer(a), N));
const { a, A } = calculateSrpA();
const res1 = await noCookieClient.$post({
headers: { 'x-amz-target': 'AWSCognitoIdentityProviderService.InitiateAuth' },
body: {
Expand Down
8 changes: 3 additions & 5 deletions server/tests/api/signIn.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import assert from 'assert';
import crypto from 'crypto';
import { calcClientSignature } from 'domain/user/service/srp/calcClientSignature';
import { N, g } from 'domain/user/service/srp/constants';
import { fromBuffer, toBuffer } from 'domain/user/service/srp/util';
import { calculateSrpA } from 'domain/user/service/srp/calcSrpA';
import { fromBuffer } from 'domain/user/service/srp/util';
import { DEFAULT_USER_POOL_CLIENT_ID } from 'service/envValues';
import { expect, test } from 'vitest';
import {
Expand All @@ -16,8 +15,7 @@ import {
test('signIn', async () => {
await createUserClient();

const a = crypto.randomBytes(32);
const A = toBuffer(g.modPow(fromBuffer(a), N));
const { a, A } = calculateSrpA();
const res1 = await noCookieClient.$post({
headers: { 'x-amz-target': 'AWSCognitoIdentityProviderService.InitiateAuth' },
body: {
Expand Down

0 comments on commit f051d79

Please sign in to comment.