Skip to content

Commit

Permalink
trying out rsa to ec step, putting it into a try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
THeflinKeeper committed Jan 3, 2024
1 parent 49298da commit 0c955d3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
39 changes: 29 additions & 10 deletions keeperapi/src/browser/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const browserPlatform: Platform = class {
}

static async importKeyEC(keyId: string, privateKey: Uint8Array, publicKey: Uint8Array, storage?: KeyStorage): Promise<void> {
const key = await this.importPrivateKeyEC(privateKey, publicKey)
const key = await this.importPrivateKeyEC(privateKey, publicKey)
cryptoKeysCache['ecc'][keyId] = key

if (storage) {
Expand Down Expand Up @@ -214,9 +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':
// await this.importKeyEC(keyId, keyBytes, keys[keyId].publicKey, storage)
// 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 @@ -267,13 +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
// }
case 'ecc':
if (cryptoKeysCache['gcm'][keyId]) {
return
}

// await this.unwrapECCKey(key, keyId, unwrappingKeyId, encryptionType, storage, canExport)
// break
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
default:
throw new Error('Unable to unwrap key type ' + unwrappedKeyType)
}
Expand Down Expand Up @@ -370,6 +388,7 @@ export const browserPlatform: Platform = class {
return this.privateDecrypt(data, key)
}
case 'ecc': {
// explains ec privkey
const key = await this.loadKey(keyId, encryptionType, storage)
return this.privateDecryptECWebCrypto(data, key)
}
Expand Down
3 changes: 3 additions & 0 deletions keeperapi/src/restMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ export const updateSecurityData = (data: Authentication.ISecurityDataRequest): R
export const setReusedPasswords = (data: Authentication.IReusedPasswordsRequest): RestInMessage<Authentication.IReusedPasswordsRequest> =>
createInMessage(data, 'enterprise/set_reused_passwords', Authentication.ReusedPasswordsRequest)

export const changeToKeyTypeOne = (data: Authentication.IChangeToKeyTypeOne): RestInMessage<Authentication.IChangeToKeyTypeOne> =>
createInMessage(data, 'vault/change_to_key_type_one', Authentication.ChangeToKeyTypeOne)

/* -- SERVICE LOGGER -- */

export const serviceLoggerGetMessage = (data: ServiceLogger.IServiceLogGetRequest): RestMessage<ServiceLogger.IServiceLogGetRequest, ServiceLogger.IServiceLogResponse> =>
Expand Down
2 changes: 1 addition & 1 deletion keeperapi/src/vaultx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const mapKeyType = (keyType: Records.RecordKeyType): { keyId: string, encryption
keyId = 'data'
encryptionType = 'gcm'
break
// RSA TAGGED - might have to fallback to ecc or force ecc
// RSA TAGGED - might have to fallback to ecc or force ecc - dont make a change here, rely on keeperapp to provide the correct keyType
case RecordKeyType.ENCRYPTED_BY_PUBLIC_KEY:
keyId = 'pk_rsa'
encryptionType = 'rsa'
Expand Down

0 comments on commit 0c955d3

Please sign in to comment.