Handle immediate responses in RSA-AES authentication

The event handlers might provide the needed response right away, before
even existing the event handler. We should be prepared to handle this
case.
This commit is contained in:
Pierre Ossman 2023-05-14 17:58:06 +02:00
parent 0dd9678e64
commit 775ccaa74c
1 changed files with 4 additions and 2 deletions

View File

@ -158,10 +158,11 @@ export default class RSAAESAuthenticationState extends EventTargetMixin {
serverPublickey.set(serverE, 4 + serverKeyBytes);
// verify server public key
let approveKey = this._waitApproveKeyAsync();
this.dispatchEvent(new CustomEvent("serververification", {
detail: { type: "RSA", publickey: serverPublickey }
}));
await this._waitApproveKeyAsync();
await approveKey;
// 2: Send client public key
const clientKeyLength = 2048;
@ -260,6 +261,7 @@ export default class RSAAESAuthenticationState extends EventTargetMixin {
throw new Error("RA2: failed to authenticate the message");
}
subtype = subtype[0];
let waitCredentials = this._waitCredentialsAsync(subtype);
if (subtype === 1) {
if (this._getCredentials().username === undefined ||
this._getCredentials().password === undefined) {
@ -276,7 +278,7 @@ export default class RSAAESAuthenticationState extends EventTargetMixin {
} else {
throw new Error("RA2: wrong subtype");
}
await this._waitCredentialsAsync(subtype);
await waitCredentials;
let username;
if (subtype === 1) {
username = encodeUTF8(this._getCredentials().username).slice(0, 255);