Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webapp): allow ssh connection to use encrypted ssh key #856

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@devolutions/icons": "3.4.6",
"@devolutions/iron-remote-gui": "^0.11.5",
"@devolutions/iron-remote-gui-vnc": "^0.2.2",
"@devolutions/web-ssh-gui": "^0.2.15",
"@devolutions/web-telnet-gui": "^0.2.15",
"@devolutions/web-ssh-gui": "^0.2.14",
"primeflex": "3.3.1",
"primeicons": "6.0.1",
"primeng": "16.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
[isEnabled]="formInputVisibility.showPasswordInput"></web-client-password-control>
</div>

<div class="col-12 gateway-form-group" *ngIf="formInputVisibility.showPrivateKeyInput">
<web-client-password-control [parentForm]="form" [inputFormData]="inputFormData" [label]="'Passpharse'" [formKey]="'passpharse'">
</web-client-password-control>
</div>

<div *ngIf="formInputVisibility.showPrivateKeyInput">
<app-file-control privateKeyFileForm ></app-file-control>
</div>


</div>
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@
gap: 10px;
display: inline-flex
}

.mb-18px{
margin-bottom: 18px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { map, startWith, switchMap, takeUntil, tap } from 'rxjs/operators';
import { SshAuthMode } from '@gateway/shared/enums/web-client-auth-mode.enum';
import { Observable, of } from 'rxjs';
import { SshKeyService } from '@gateway/shared/services/ssh-key.service';
import { ChangeDetectorRef } from '@angular/core';

interface FormInputVisibility {
showUsernameInput?: boolean;
Expand Down Expand Up @@ -45,7 +46,8 @@ export class SshFormComponent

constructor(
private formService: WebFormService,
private sshKeyService: SshKeyService
private sshKeyService: SshKeyService,
private ChangeDetectorRef: ChangeDetectorRef
) {
super();
}
Expand Down Expand Up @@ -100,7 +102,8 @@ export class SshFormComponent
.valueChanges.pipe(
takeUntil(this.destroyed$),
startWith(this.form.get('authMode').value as SshAuthMode),
switchMap((authMode) => this.getFormInputVisibility(authMode))
switchMap((authMode) => this.getFormInputVisibility(authMode)),
tap(()=>this.ChangeDetectorRef.detectChanges())
)
.subscribe(() => {});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<div [formGroup]="parentForm">
<label for="password">Password</label>
<label for="password">{{label}}</label>
<div class="gateway-form-input password-container">
<input pPassword
id="password"
[type]=" showPasswordToggle ? 'text' : 'password' "
autocomplete="current-password"
placeholder="Enter password"
formControlName="password"
placeholder="Enter {{label}}"
formControlName="{{formKey}}"
showPassword="showPassword"
required/>
<span>
<i (click)="toggleShowPassword()" class="dvl-icon dvl-icon-view"></i>
</span>
</div>
<div class="form-helper-text"
*ngIf="parentForm.get('password').hasError('required') && parentForm.get('password').touched">
Password is required.
*ngIf="parentForm.get(formKey).hasError('required') && parentForm.get(formKey).touched">
{{label}} is required
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class PasswordControlComponent extends BaseComponent implements OnInit {
@Input() parentForm: FormGroup;
@Input() inputFormData: any;
@Input() isEnabled: boolean = true;
@Input() label: string = 'Password';
@Input() formKey: string = 'password';

showPasswordToggle: boolean = false;

Expand All @@ -22,7 +24,7 @@ export class PasswordControlComponent extends BaseComponent implements OnInit {
}

ngOnInit(): void {
this.formService.addControlToForm(this.parentForm, 'password', this.inputFormData);
this.formService.addControlToForm(this.parentForm,this.formKey, this.inputFormData);
this.toggleControl();
}

Expand All @@ -37,7 +39,7 @@ export class PasswordControlComponent extends BaseComponent implements OnInit {
}

private toggleControl(): void {
const control: AbstractControl<any, any> = this.parentForm.get('password');
const control: AbstractControl<any, any> = this.parentForm.get(this.formKey);
if (control) {
this.isEnabled ? control.enable() : control.disable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
}

ngOnInit(): void {
sshLoggingService.setLevel(LoggingLevel.FATAL)
sshLoggingService.setLevel(LoggingLevel.DEBUG)
this.removeWebClientGuiElement();
this.initializeStatus();

Expand Down Expand Up @@ -192,6 +192,7 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
connectionParameters.gatewayAddress+`?token=${connectionParameters.token}`,
connectionParameters.password,
connectionParameters.privateKey,
connectionParameters.privateKeyPassphrase,
)
).pipe(
catchError(error => throwError(error)),
Expand All @@ -212,15 +213,16 @@ export class WebClientSshComponent extends WebClientBaseComponent implements OnI
const gatewayHttpAddress: URL = new URL(WebClientSshComponent.JET_SSH_URL+`/${sessionId}`, window.location.href);
const gatewayAddress: string = gatewayHttpAddress.toString().replace("http", "ws");
const privateKey: string | null = formData.extraData?.sshPrivateKey || null;

const privateKeyPassphrase: string = formData.passpharse || null;
const connectionParameters: SshConnectionParameters = {
host: extractedData.hostname,
username: username,
password: password,
port: extractedData.port,
gatewayAddress: gatewayAddress,
sessionId: sessionId,
privateKey: privateKey
privateKey: privateKey,
privateKeyPassphrase: privateKeyPassphrase
}
return of(connectionParameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ export interface SshConnectionParameters {
token?: string;
sessionId?: string,
privateKey?: string
privateKeyPassphrase?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface SSHFormDataInput {
hostname: string,
username?: string,
password?: string,
passpharse?: string,
extraData?:{
sshPrivateKey?: string,
}
Expand Down
6 changes: 0 additions & 6 deletions webapp/src/client/app/shared/services/ssh-key.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ export class SshKeyService {
error: 'Invalid key format',
content: value.content,
});
} else if (value.format == SshKeyFormat.PKCS8_Encrypted) {
observer.next({
valid: false,
error: 'Encrypted key not supported',
content: value.content,
});
} else {
observer.next({ valid: true, content: value.content });
}
Expand Down