Skip to content

Commit 3984f00

Browse files
THeflinKeepersaldoukhov
authored andcommitted
fixed ec issues around expecting an item to be undefined but is actually filled out cause of protobuf and get keys will sometimes not return rsa key
1 parent 1bfab54 commit 3984f00

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

keeperapi/src/auth.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export type SessionParams = {
108108

109109
export type EncryptionKeys = {
110110
dataKey: Uint8Array;
111-
privateKey: Uint8Array;
111+
privateKey?: Uint8Array;
112112
eccPrivateKey: Uint8Array;
113113
}
114114

@@ -995,8 +995,12 @@ export class Auth {
995995
}
996996
}
997997
if (!encryptedPrivateKey || !encryptedEccPrivateKey) {
998-
encryptedPrivateKey = this.accountSummary?.keysInfo?.encryptedPrivateKey || undefined
999-
encryptedEccPrivateKey = this.accountSummary?.keysInfo?.encryptedEccPrivateKey || undefined
998+
// protobuf embeds the unit8array into the prototype of this.accountSummary.keysInfo, check for length as well
999+
const encryptedPrivateKeyUint8 = this.accountSummary?.keysInfo?.encryptedPrivateKey || undefined
1000+
const encryptedEccPrivateKeyUint8 = this.accountSummary?.keysInfo?.encryptedEccPrivateKey || undefined
1001+
encryptedPrivateKey = encryptedPrivateKeyUint8?.length ? encryptedPrivateKeyUint8 : undefined
1002+
encryptedEccPrivateKey = encryptedEccPrivateKeyUint8?.length ? encryptedEccPrivateKeyUint8 : undefined
1003+
10001004
if (this.options.kvs) {
10011005
if (encryptedPrivateKey) {
10021006
this.options.kvs.saveValue(`${this._username}/private_key`, platform.bytesToBase64(encryptedPrivateKey))
@@ -1212,14 +1216,33 @@ export class Auth {
12121216
}
12131217
}
12141218

1215-
public getKeys(): EncryptionKeys {
1216-
if (!this.dataKey || !this.privateKey || !this.eccPrivateKey) {
1217-
throw Error('Encryption keys are missing')
1218-
}
1219-
return {
1220-
dataKey: this.dataKey,
1221-
privateKey: this.privateKey,
1222-
eccPrivateKey: this.eccPrivateKey
1219+
public getKeys(ecOnly?:boolean): EncryptionKeys {
1220+
if(ecOnly){
1221+
if (!this.dataKey || !this.eccPrivateKey) {
1222+
throw Error('Encryption keys are missing')
1223+
}
1224+
1225+
if(this.privateKey){
1226+
return {
1227+
dataKey: this.dataKey,
1228+
privateKey: this.privateKey,
1229+
eccPrivateKey: this.eccPrivateKey
1230+
}
1231+
} else {
1232+
return {
1233+
dataKey: this.dataKey,
1234+
eccPrivateKey: this.eccPrivateKey
1235+
}
1236+
}
1237+
} else {
1238+
if (!this.dataKey || !this.privateKey || !this.eccPrivateKey) {
1239+
throw Error('Encryption keys are missing')
1240+
}
1241+
return {
1242+
dataKey: this.dataKey,
1243+
privateKey: this.privateKey,
1244+
eccPrivateKey: this.eccPrivateKey
1245+
}
12231246
}
12241247
}
12251248

0 commit comments

Comments
 (0)