Skip to content

Commit

Permalink
Adding set account summary version (#41)
Browse files Browse the repository at this point in the history
* Adding set account summary version

* based upon this for passphrases support in console: https://keeper.atlassian.net/wiki/spaces/KA/pages/1096089857/account+summary+REST

* reverted some rsa items

---------

Co-authored-by: TimHeflin <[email protected]>
  • Loading branch information
brianwphamSF and THeflinKeeper authored Jan 31, 2024
1 parent b3982c9 commit 0c11534
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 71 deletions.
2 changes: 1 addition & 1 deletion keeperapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@keeper-security/keeperapi",
"description": "Keeper API Javascript SDK",
"version": "16.0.51",
"version": "16.0.52",
"browser": "dist/index.es.js",
"main": "dist/index.cjs.js",
"types": "dist/node/index.d.ts",
Expand Down
7 changes: 6 additions & 1 deletion keeperapi/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class Auth {
private socket?: SocketListener;
public clientKey?: Uint8Array;
private _accountSummary?: IAccountSummaryElements;
private _accountSummaryVersion: number = 1

constructor(options: ClientConfiguration) {
if (options.deviceConfig && options.deviceToken) {
Expand Down Expand Up @@ -1018,10 +1019,14 @@ export class Auth {

async loadAccountSummary() {
this._accountSummary = await this.executeRest(accountSummaryMessage({
summaryVersion: 1
summaryVersion: this._accountSummaryVersion
}));
}

setAccountSummaryVersion(version: number) {
this._accountSummaryVersion = version
}

// async executeCommand<Command extends KeeperCommand>(command: Command): Promise<Command["response"]> {
// if (!command.username) {
// command.username = this._username;
Expand Down
54 changes: 27 additions & 27 deletions keeperapi/src/browser/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,17 @@ export const browserPlatform: Platform = class {
await this.importKeyRSA(keyId, keyBytes, storage)
break
// TODO: add something like this, need to find pub/priv key pair
case 'ecc':
// gonna figure this out
try {
debugger
const privkey = keyBytes.slice(ECC_PUB_KEY_LENGTH)
const pubKey = keyBytes.slice(0, ECC_PUB_KEY_LENGTH)
await this.importKeyEC(keyId, privkey, pubKey, storage)
} catch(e){
console.error('ecc error in unwrapKeys: ', e)
}
break
// case 'ecc':
// // gonna figure this out
// try {
// debugger
// const privkey = keyBytes.slice(ECC_PUB_KEY_LENGTH)
// const pubKey = keyBytes.slice(0, ECC_PUB_KEY_LENGTH)
// await this.importKeyEC(keyId, privkey, pubKey, storage)
// } catch(e){
// console.error('ecc error in unwrapKeys: ', e)
// }
// break
default:
throw new Error(`unable to import ${unwrappedType} key`)
}
Expand Down Expand Up @@ -275,23 +275,23 @@ export const browserPlatform: Platform = class {
await this.unwrapAesKey(key, keyId, unwrappingKeyId, encryptionType, storage, canExport)
break
// TODO: add something like this, need to find pub/priv key pair
case 'ecc':
if (cryptoKeysCache['gcm'][keyId]) {
return
}

try {
debugger
// maybe this priv key?
// const eccPrivateKey = await this.loadKey(unwrappingKeyId, 'ecc', storage)
const privkey = key.slice(ECC_PUB_KEY_LENGTH)
const pubKey = key.slice(0, ECC_PUB_KEY_LENGTH)
// case 'ecc':
// if (cryptoKeysCache['gcm'][keyId]) {
// return
// }

// try {
// debugger
// // maybe this priv key?
// // const eccPrivateKey = await this.loadKey(unwrappingKeyId, 'ecc', storage)
// const privkey = key.slice(ECC_PUB_KEY_LENGTH)
// const pubKey = key.slice(0, ECC_PUB_KEY_LENGTH)

await this.unwrapECCKey(privkey, pubKey, keyId, unwrappingKeyId, encryptionType, storage)
} catch(e){
console.error('ecc error in unwrapKey: ', e)
}
break
// await this.unwrapECCKey(privkey, pubKey, keyId, unwrappingKeyId, encryptionType, storage)
// } catch(e){
// console.error('ecc error in unwrapKey: ', e)
// }
// break
default:
throw new Error('Unable to unwrap key type ' + unwrappedKeyType)
}
Expand Down
20 changes: 10 additions & 10 deletions keeperapi/src/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,17 @@ export class KeeperEndpoint {
// RSA TAGGED - done, add ecOnly check to only make ec keys if ec only is true
public async getOnsitePublicKey(ecOnly:boolean): Promise<string> {
if (!this.onsitePublicKey || !this.onsitePrivateKey) {
if(ecOnly){
const {privateKey, publicKey} = await platform.generateECKeyPair()
// if(ecOnly){
// const {privateKey, publicKey} = await platform.generateECKeyPair()

this.onsitePrivateKey = privateKey
this.onsitePublicKey = publicKey
} else {
const {privateKey, publicKey} = await platform.generateRSAKeyPair()

this.onsitePrivateKey = privateKey
this.onsitePublicKey = publicKey
}
// this.onsitePrivateKey = privateKey
// this.onsitePublicKey = publicKey
// } else {
// }
const {privateKey, publicKey} = await platform.generateRSAKeyPair()

this.onsitePrivateKey = privateKey
this.onsitePublicKey = publicKey
}

return webSafe64FromBytes(this.onsitePublicKey)
Expand Down
72 changes: 40 additions & 32 deletions keeperapi/src/vaultx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,31 +292,39 @@ export const processTeams = async (teams: NN<ITeam>[], storage: VaultStorage, de
}
}

switch (team.teamKeyType) {
case Records.RecordKeyType.ENCRYPTED_BY_DATA_KEY:
teamPrivateKeys[teamUid + '_priv'] = {
data: team.teamPrivateKey,
dataId: teamUid + '_priv',
keyId: teamUid,
encryptionType: 'cbc',
unwrappedType: 'rsa',
}
break
// RSA TAGGED - this essentially changes the unwrapped type to ecc. make sure this is fine
case Records.RecordKeyType.ENCRYPTED_BY_PUBLIC_KEY_ECC:
teamPrivateKeys[teamUid + '_priv'] = {
data: team.teamPrivateKey,
dataId: teamUid + '_priv',
keyId: 'pk_ecc',
encryptionType: 'ecc',
unwrappedType: 'aes',
}
break
default:
console.error(`Key ${team.teamKeyType} type for team folder private key ${teamUid} is not supported for team folder decryption`)
break
teamPrivateKeys[teamUid + '_priv'] = {
data: team.teamPrivateKey,
dataId: teamUid + '_priv',
keyId: teamUid,
encryptionType: 'cbc',
unwrappedType: 'rsa',
}

// switch (team.teamKeyType) {
// case Records.RecordKeyType.ENCRYPTED_BY_DATA_KEY:
// teamPrivateKeys[teamUid + '_priv'] = {
// data: team.teamPrivateKey,
// dataId: teamUid + '_priv',
// keyId: teamUid,
// encryptionType: 'cbc',
// unwrappedType: 'rsa',
// }
// break
// // RSA TAGGED - this essentially changes the unwrapped type to ecc. make sure this is fine
// case Records.RecordKeyType.ENCRYPTED_BY_PUBLIC_KEY_ECC:
// teamPrivateKeys[teamUid + '_priv'] = {
// data: team.teamPrivateKey,
// dataId: teamUid + '_priv',
// keyId: 'pk_ecc',
// encryptionType: 'ecc',
// unwrappedType: 'aes',
// }
// break
// default:
// console.error(`Key ${team.teamKeyType} type for team folder private key ${teamUid} is not supported for team folder decryption`)
// break
// }

// RSA TAGGED - fix is the switch case above. need to confirm the encryptionType and unwrappedType are correct
// teamPrivateKeys[teamUid + '_priv'] = {
// data: team.teamPrivateKey,
Expand Down Expand Up @@ -354,15 +362,15 @@ export const processTeams = async (teams: NN<ITeam>[], storage: VaultStorage, de
unwrappedType: 'aes',
}
break
case Records.RecordKeyType.ENCRYPTED_BY_PUBLIC_KEY_ECC:
teamSharedFolderKeys[folderUid] = {
data: folderKey.sharedFolderKey,
dataId: folderUid,
keyId: 'pk_ecc',
encryptionType: 'ecc',
unwrappedType: 'aes',
}
break
// case Records.RecordKeyType.ENCRYPTED_BY_PUBLIC_KEY_ECC:
// teamSharedFolderKeys[folderUid] = {
// data: folderKey.sharedFolderKey,
// dataId: folderUid,
// keyId: 'pk_ecc',
// encryptionType: 'ecc',
// unwrappedType: 'aes',
// }
// break
default:
console.error(`Key ${folderKey.keyType} type for team folder key ${teamUid}/${folderUid} is not supported for team folder decryption`)
break
Expand Down

0 comments on commit 0c11534

Please sign in to comment.