()
| 2184 | } |
| 2185 | |
| 2186 | _negotiateMSLogonIIAuth() { |
| 2187 | if (this._sock.rQwait("mslogonii dh param", 24)) { return false; } |
| 2188 | |
| 2189 | if (this._rfbCredentials.username === undefined || |
| 2190 | this._rfbCredentials.password === undefined) { |
| 2191 | this.dispatchEvent(new CustomEvent( |
| 2192 | "credentialsrequired", |
| 2193 | { detail: { types: ["username", "password"] } })); |
| 2194 | return false; |
| 2195 | } |
| 2196 | |
| 2197 | const g = this._sock.rQshiftBytes(8); |
| 2198 | const p = this._sock.rQshiftBytes(8); |
| 2199 | const A = this._sock.rQshiftBytes(8); |
| 2200 | const dhKey = legacyCrypto.generateKey({ name: "DH", g: g, p: p }, true, ["deriveBits"]); |
| 2201 | const B = legacyCrypto.exportKey("raw", dhKey.publicKey); |
| 2202 | const secret = legacyCrypto.deriveBits({ name: "DH", public: A }, dhKey.privateKey, 64); |
| 2203 | |
| 2204 | const key = legacyCrypto.importKey("raw", secret, { name: "DES-CBC" }, false, ["encrypt"]); |
| 2205 | const username = encodeUTF8(this._rfbCredentials.username).substring(0, 255); |
| 2206 | const password = encodeUTF8(this._rfbCredentials.password).substring(0, 63); |
| 2207 | let usernameBytes = new Uint8Array(256); |
| 2208 | let passwordBytes = new Uint8Array(64); |
| 2209 | window.crypto.getRandomValues(usernameBytes); |
| 2210 | window.crypto.getRandomValues(passwordBytes); |
| 2211 | for (let i = 0; i < username.length; i++) { |
| 2212 | usernameBytes[i] = username.charCodeAt(i); |
| 2213 | } |
| 2214 | usernameBytes[username.length] = 0; |
| 2215 | for (let i = 0; i < password.length; i++) { |
| 2216 | passwordBytes[i] = password.charCodeAt(i); |
| 2217 | } |
| 2218 | passwordBytes[password.length] = 0; |
| 2219 | usernameBytes = legacyCrypto.encrypt({ name: "DES-CBC", iv: secret }, key, usernameBytes); |
| 2220 | passwordBytes = legacyCrypto.encrypt({ name: "DES-CBC", iv: secret }, key, passwordBytes); |
| 2221 | this._sock.sQpushBytes(B); |
| 2222 | this._sock.sQpushBytes(usernameBytes); |
| 2223 | this._sock.sQpushBytes(passwordBytes); |
| 2224 | this._sock.flush(); |
| 2225 | this._rfbInitState = "SecurityResult"; |
| 2226 | return true; |
| 2227 | } |
| 2228 | |
| 2229 | _negotiateAuthentication() { |
| 2230 | switch (this._rfbAuthScheme) { |
no test coverage detected