-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added rsa tagged * some additions * fully commented and added some functions * added test for onsite public key * added test for create user * stuck making unit tests, will get help later * trying out rsa to ec step, putting it into a try catch * add comment to look into teams creation * upped version * added comment about the test function that creates teams
- Loading branch information
1 parent
b57b432
commit b3982c9
Showing
14 changed files
with
496 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
// @ts-ignore | ||
import crypto from 'crypto' | ||
import {nodePlatform} from "../node/platform"; | ||
import {browserPlatform} from "../browser/platform" | ||
import {TextEncoder, TextDecoder} from 'util'; | ||
import {KeyWrapper, connectPlatform, platform} from "../platform"; | ||
import { Auth } from '../auth'; | ||
import { KeeperEnvironment } from '../endpoint'; | ||
|
||
Object.assign(global, {TextDecoder, TextEncoder}) | ||
|
||
Object.defineProperty(global.self, 'crypto', { | ||
value: { | ||
subtle: crypto.webcrypto.subtle, | ||
getRandomValues: (array: any) => crypto.randomBytes(array.length) | ||
} | ||
}) | ||
|
||
describe('create user request', () => { | ||
|
||
const username = 'username' | ||
const password = 'password' | ||
let auth: Auth | ||
|
||
// needed to create auth initially | ||
connectPlatform(browserPlatform) | ||
|
||
beforeEach(() => { | ||
auth = createAuth() | ||
}) | ||
|
||
it('create user request', async () => { | ||
connectPlatform(browserPlatform) | ||
const kp = await platform.generateECKeyPair() | ||
// @ts-expect-error private prop on class | ||
const user = await auth.createUserRequest(kp.privateKey) | ||
|
||
const {rsaPublicKey, rsaEncryptedPrivateKey, eccPublicKey, eccEncryptedPrivateKey, encryptedDeviceToken, encryptedClientKey, clientVersion} = user | ||
|
||
expect(rsaPublicKey).toBeDefined() | ||
expect(rsaPublicKey && rsaPublicKey.length === 270).toBeTruthy() | ||
|
||
expect(rsaEncryptedPrivateKey).toBeDefined() | ||
expect(rsaEncryptedPrivateKey && rsaEncryptedPrivateKey.length === 1216).toBeTruthy() | ||
|
||
expect(eccPublicKey).toBeDefined() | ||
expect(eccPublicKey && eccPublicKey.length === 65).toBeTruthy() | ||
|
||
expect(eccEncryptedPrivateKey).toBeDefined() | ||
expect(eccEncryptedPrivateKey && eccEncryptedPrivateKey.length === 60).toBeTruthy() | ||
|
||
expect(encryptedDeviceToken).not.toBeDefined() | ||
|
||
expect(encryptedClientKey).toBeDefined() | ||
expect(encryptedClientKey && encryptedClientKey.length === 64).toBeTruthy() | ||
|
||
expect(clientVersion).toBeDefined() | ||
expect(clientVersion === 'ec0.0.0').toBeTruthy() | ||
}) | ||
}) | ||
|
||
function createAuth(){ | ||
return new Auth({ | ||
host: KeeperEnvironment.DEV, | ||
clientVersion: 'ec0.0.0', | ||
}) | ||
} | ||
|
||
function createKeyWrapper(key: Uint8Array) { | ||
return KeyWrapper.create(key) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
// @ts-ignore | ||
import crypto from 'crypto' | ||
import { browserPlatform } from '../browser/platform'; | ||
import {KeeperEndpoint} from '../endpoint' | ||
import { nodePlatform } from '../node/platform' | ||
import { connectPlatform } from '../platform' | ||
// import NodeRSA from 'node-rsa'; | ||
|
||
Object.defineProperty(global.self, 'crypto', { | ||
value: { | ||
subtle: crypto.webcrypto.subtle, | ||
getRandomValues: (array: any) => crypto.randomBytes(array.length) | ||
} | ||
}) | ||
|
||
describe('getOnsitePublicKey', () => { | ||
|
||
let endpoint = new KeeperEndpoint({ | ||
host: 'testUrl', | ||
deviceConfig: { | ||
deviceName: 'test', | ||
deviceToken: new Uint8Array(), | ||
privateKey: new Uint8Array(), | ||
publicKey: new Uint8Array(), | ||
transmissionKeyId: 1, | ||
}, | ||
}) | ||
|
||
beforeEach(() => { | ||
endpoint = new KeeperEndpoint({ | ||
host: 'testUrl', | ||
deviceConfig: { | ||
deviceName: 'test', | ||
deviceToken: new Uint8Array(), | ||
privateKey: new Uint8Array(), | ||
publicKey: new Uint8Array(), | ||
transmissionKeyId: 1, | ||
}, | ||
}) | ||
}) | ||
|
||
// NODE PLATFORM | ||
it('(node) should return the rsa public key of the onsite keeper', async () => { | ||
connectPlatform(nodePlatform) | ||
const key = await endpoint.getOnsitePublicKey(false) | ||
|
||
checkRSAKey(key) | ||
// should node platform have a different length from browser? | ||
expect(key).toHaveLength(392); | ||
}) | ||
|
||
// NODE PLATFORM | ||
it('(node) should return the ecc public key of the onsite keeper', async () => { | ||
connectPlatform(nodePlatform) | ||
|
||
const key = await endpoint.getOnsitePublicKey(true) | ||
checkECCKey(key) | ||
}) | ||
|
||
// BROWSER PLATFORM | ||
it('(browser) should return the rsa public key of the onsite keeper', async () => { | ||
connectPlatform(browserPlatform) | ||
|
||
const key = await endpoint.getOnsitePublicKey(false) | ||
|
||
checkRSAKey(key) | ||
// should browser platform have a different length from node? | ||
expect(key).toHaveLength(360); | ||
}) | ||
|
||
// BROWSER PLATFORM | ||
it('(browser) should return the ecc public key of the onsite keeper', async () => { | ||
connectPlatform(browserPlatform) | ||
|
||
const key = await endpoint.getOnsitePublicKey(true) | ||
checkECCKey(key) | ||
}) | ||
}) | ||
|
||
function checkRSAKey(key:string){ | ||
const beginningPart = key.match(/^MIIB/i) | ||
const endingPart = key.match(/IDAQAB$/i) | ||
expect(beginningPart).toBeTruthy(); | ||
expect(endingPart).toBeTruthy(); | ||
} | ||
|
||
function checkECCKey(key:string){ | ||
expect(key).toHaveLength(87); | ||
} |
Oops, something went wrong.