Skip to content

Commit

Permalink
Use manually configured basic auth credentials (#220034)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Jul 8, 2024
1 parent d0f0de5 commit a521f57
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
33 changes: 32 additions & 1 deletion src/vs/platform/native/electron-main/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { Event } from 'vs/base/common/event';
import { hash } from 'vs/base/common/hash';
import { Disposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEncryptionMainService } from 'vs/platform/encryption/common/encryptionService';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
Expand Down Expand Up @@ -50,7 +52,8 @@ export class ProxyAuthService extends Disposable implements IProxyAuthService {
@ILogService private readonly logService: ILogService,
@IWindowsMainService private readonly windowsMainService: IWindowsMainService,
@IEncryptionMainService private readonly encryptionMainService: IEncryptionMainService,
@IApplicationStorageMainService private readonly applicationStorageMainService: IApplicationStorageMainService
@IApplicationStorageMainService private readonly applicationStorageMainService: IApplicationStorageMainService,
@IConfigurationService private readonly configurationService: IConfigurationService,
) {
super();

Expand Down Expand Up @@ -132,6 +135,34 @@ export class ProxyAuthService extends Disposable implements IProxyAuthService {
private async doResolveProxyCredentials(authInfo: AuthInfo, authInfoHash: string): Promise<Credentials | undefined> {
this.logService.trace('auth#doResolveProxyCredentials - enter', authInfo);

// Reply with manually supplied credentials. Fail if they are wrong.
const newHttpProxy = (this.configurationService.getValue<string>('http.proxy') || '').trim()
|| (process.env['https_proxy'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['HTTP_PROXY'] || '').trim()
|| undefined;

if (newHttpProxy?.indexOf('@') !== -1) {
const uri = URI.parse(newHttpProxy!);
const i = uri.authority.indexOf('@');
if (i !== -1) {
if (authInfo.attempt > 1) {
return undefined; // We tried already, let the user handle it.
}
const credentials = uri.authority.substring(0, i);
const j = credentials.indexOf(':');
if (j !== -1) {
return {
username: credentials.substring(0, j),
password: credentials.substring(j + 1)
};
} else {
return {
username: credentials,
password: ''
};
}
}
}

// Reply with session credentials unless we used them already.
// In that case we need to show a login dialog again because
// they seem invalid.
Expand Down
16 changes: 9 additions & 7 deletions src/vs/platform/windows/electron-main/windowImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,14 @@ export class CodeWindow extends BaseWindow implements ICodeWindow {
|| (process.env['https_proxy'] || process.env['HTTPS_PROXY'] || process.env['http_proxy'] || process.env['HTTP_PROXY'] || '').trim() // Not standardized.
|| undefined;

if (newHttpProxy?.indexOf('@') !== -1) {
const uri = URI.parse(newHttpProxy!);
const i = uri.authority.indexOf('@');
if (i !== -1) {
newHttpProxy = uri.with({ authority: uri.authority.substring(i + 1) })
.toString();
}
}
if (newHttpProxy?.endsWith('/')) {
newHttpProxy = newHttpProxy.substr(0, newHttpProxy.length - 1);
}
Expand All @@ -976,13 +984,7 @@ export class CodeWindow extends BaseWindow implements ICodeWindow {
const proxyBypassRules = newNoProxy ? `${newNoProxy},<local>` : '<local>';
this.logService.trace(`Setting proxy to '${proxyRules}', bypassing '${proxyBypassRules}'`);
this._win.webContents.session.setProxy({ proxyRules, proxyBypassRules, pacScript: '' });
type appWithProxySupport = Electron.App & {
setProxy(config: Electron.Config): Promise<void>;
resolveProxy(url: string): Promise<string>;
};
if (typeof (app as appWithProxySupport).setProxy === 'function') {
(app as appWithProxySupport).setProxy({ proxyRules, proxyBypassRules, pacScript: '' });
}
app.setProxy({ proxyRules, proxyBypassRules, pacScript: '' });
}
}
}
Expand Down

0 comments on commit a521f57

Please sign in to comment.