Skip to content

Commit

Permalink
updated info
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Apr 18, 2023
1 parent be117e1 commit 82e7f5e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 107 deletions.
15 changes: 11 additions & 4 deletions src/app/shared/shared_modules/public-key/public-key.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@
</div>
<div *ngIf="current_key_blocked">
<alert type="danger">
<strong>Warning</strong> Due to the security concerns, your key has been blocked permanently, and you won't be
<strong>Warning</strong> Due to security concerns, your key has been blocked permanently, and you won't be
able to use it anymore. It's highly recommended that you change your key immediately to prevent any further
security breaches.
security breaches.<br>
If you have questions or need help, please E-Mail us at
<a class="alert-link" href="mailto: {{ CLOUD_PORTAL_SUPPORT_MAIL }}">{{ CLOUD_PORTAL_SUPPORT_MAIL }}</a
>.
</alert>
</div></span
>
Expand Down Expand Up @@ -184,9 +187,13 @@ <h4 class="modal-title">Change public key</h4>
<strong>Warning</strong> This is not a valid public key!
</alert>
<alert type="danger" *ngIf="(!(this.public_key | isValidKeyPipe) || blocked_key) && validated_key">
<strong>Warning</strong>Due to the security concerns, your key has been blocked permanently, and you won't be
<strong>Warning</strong>Due to security concerns, your key has been blocked permanently, and you won't be
able to use it anymore. It's highly recommended that you change your key immediately to prevent any further
security breaches.
security breaches.<br>
If you have questions or need help, please E-Mail us at
<a class="alert-link" href="mailto: {{ CLOUD_PORTAL_SUPPORT_MAIL }}">{{ CLOUD_PORTAL_SUPPORT_MAIL }}</a
>.

</alert>
<alert type="info">
Currently supported public key formats are RSA and ECDSA (SHA2, NIST P256, P384 or P521).
Expand Down
208 changes: 105 additions & 103 deletions src/app/shared/shared_modules/public-key/public-key.component.ts
Original file line number Diff line number Diff line change
@@ -1,126 +1,128 @@
import {
Component, EventEmitter, Input, OnInit, Output,
Component, EventEmitter, Input, OnInit, Output,
} from '@angular/core';
import { ClipboardService } from 'ngx-clipboard';
import { saveAs } from 'file-saver';
import { BsModalService } from 'ngx-bootstrap/modal';
import { KeyService } from '../../../api-connector/key.service';
import { ApiSettings } from '../../../api-connector/api-settings.service';
import { Userinfo } from '../../../userinfo/userinfo.model';
import { IResponseTemplate } from '../../../api-connector/response-template';
import { AbstractBaseClass } from '../baseClass/abstract-base-class';
import { WIKI_GENERATE_KEYS } from '../../../../links/links';
import { NotificationModalComponent } from '../../modal/notification-modal';
import { BlacklistedResponse } from '../../../api-connector/response-interfaces';
import {ClipboardService} from 'ngx-clipboard';
import {saveAs} from 'file-saver';
import {BsModalService} from 'ngx-bootstrap/modal';
import {KeyService} from '../../../api-connector/key.service';
import {ApiSettings} from '../../../api-connector/api-settings.service';
import {Userinfo} from '../../../userinfo/userinfo.model';
import {IResponseTemplate} from '../../../api-connector/response-template';
import {AbstractBaseClass} from '../baseClass/abstract-base-class';
import {WIKI_GENERATE_KEYS} from '../../../../links/links';
import {NotificationModalComponent} from '../../modal/notification-modal';
import {BlacklistedResponse} from '../../../api-connector/response-interfaces';
import {CLOUD_PORTAL_SUPPORT_MAIL} from '../../../../links/links'

/**
* Public Key component.
*/
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[app-public-key]',
templateUrl: './public-key.component.html',
styleUrls: ['./public-key.component.scss'],
providers: [ApiSettings, KeyService],
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[app-public-key]',
templateUrl: './public-key.component.html',
styleUrls: ['./public-key.component.scss'],
providers: [ApiSettings, KeyService],
})
export class PublicKeyComponent extends AbstractBaseClass implements OnInit {
WIKI_GENERATE_KEYS: string = WIKI_GENERATE_KEYS;
public_key: string;
validated_key: boolean = false;
blocked_key: boolean = false;
current_key_blocked: boolean = false;
acknowledgement_given: boolean = false;
@Input() userinfo: Userinfo;
@Output() readonly currentKeyBlockedChanged: EventEmitter<boolean> = new EventEmitter();
WIKI_GENERATE_KEYS: string = WIKI_GENERATE_KEYS;
public_key: string;
validated_key: boolean = false;
blocked_key: boolean = false;
current_key_blocked: boolean = false;
acknowledgement_given: boolean = false;
@Input() userinfo: Userinfo;
@Output() readonly currentKeyBlockedChanged: EventEmitter<boolean> = new EventEmitter();
CLOUD_PORTAL_SUPPORT_MAIL: string= CLOUD_PORTAL_SUPPORT_MAIL

constructor(
private keyService: KeyService,
private clipboardService: ClipboardService,
private modalService: BsModalService,
) {
super();
}
constructor(
private keyService: KeyService,
private clipboardService: ClipboardService,
private modalService: BsModalService,
) {
super();
}

ngOnInit() {
if (this.userinfo?.PublicKey) {
this.isCurrentKeyBlocked();
ngOnInit() {
if (this.userinfo?.PublicKey) {
this.isCurrentKeyBlocked();
}
}
}

downloadPem(data: string): void {
const blob: Blob = new Blob([data], { type: 'pem' });
const url: string = window.URL.createObjectURL(blob);
saveAs(url, `${this.userinfo.UserLogin}_ecdsa`);
}
downloadPem(data: string): void {
const blob: Blob = new Blob([data], {type: 'pem'});
const url: string = window.URL.createObjectURL(blob);
saveAs(url, `${this.userinfo.UserLogin}_ecdsa`);
}

generateKey(): void {
this.keyService.generateKey().subscribe((res: any): void => {
this.getUserPublicKey();
this.downloadPem(res['private_key']);
});
}
generateKey(): void {
this.keyService.generateKey().subscribe((res: any): void => {
this.getUserPublicKey();
this.downloadPem(res['private_key']);
});
}

isKeyBlocked(): void {
this.keyService.isBlocked(this.public_key.trim()).subscribe((res: BlacklistedResponse) => {
this.blocked_key = res.blacklisted;
});
}
isKeyBlocked(): void {
this.keyService.isBlocked(this.public_key.trim()).subscribe((res: BlacklistedResponse) => {
this.blocked_key = res.blacklisted;
});
}

isCurrentKeyBlocked(): void {
this.keyService.isBlocked(this.userinfo.PublicKey).subscribe((res: BlacklistedResponse) => {
this.current_key_blocked = res.blacklisted;
this.currentKeyBlockedChanged.emit(this.current_key_blocked);
});
}
isCurrentKeyBlocked(): void {
this.keyService.isBlocked(this.userinfo.PublicKey).subscribe((res: BlacklistedResponse) => {
this.current_key_blocked = res.blacklisted;
this.currentKeyBlockedChanged.emit(this.current_key_blocked);
});
}

validateKey(): void {
this.keyService.validateKey(this.public_key.trim()).subscribe(
(res: any) => {
this.validated_key = res['status'] === 'valid';
},
() => {
this.validated_key = false;
},
);
}
validateKey(): void {
this.keyService.validateKey(this.public_key.trim()).subscribe(
(res: any) => {
this.validated_key = res['status'] === 'valid';
},
() => {
this.validated_key = false;
},
);
}

importKey(): void {
const re: RegExp = /\+/gi;
importKey(): void {
const re: RegExp = /\+/gi;

this.keyService.postKey(this.public_key.replace(re, '%2B').trim()).subscribe({
next: (): void => {
this.getUserPublicKey();
const initialState = {
notificationModalTitle: 'Success',
notificationModalType: 'info',
notificationModalMessage: 'The new public key got successfully set',
};
this.modalService.show(NotificationModalComponent, { initialState });
},
error: (): any => {
const initialState = {
notificationModalTitle: 'Error',
notificationModalType: 'danger',
notificationModalMessage:
'We were not able successfully set a new public key. Please enter a valid public key!',
};
this.modalService.show(NotificationModalComponent, { initialState });
},
});
}
this.keyService.postKey(this.public_key.replace(re, '%2B').trim()).subscribe({
next: (): void => {
this.getUserPublicKey();
const initialState = {
notificationModalTitle: 'Success',
notificationModalType: 'info',
notificationModalMessage: 'The new public key got successfully set',
};
this.modalService.show(NotificationModalComponent, {initialState});
},
error: (): any => {
const initialState = {
notificationModalTitle: 'Error',
notificationModalType: 'danger',
notificationModalMessage:
'We were not able successfully set a new public key. Please enter a valid public key!',
};
this.modalService.show(NotificationModalComponent, {initialState});
},
});
}

copyToClipboard(text: string): void {
if (this.clipboardService.isSupported) {
this.clipboardService.copy(text);
} else {
super.copyToClipboard(text);
copyToClipboard(text: string): void {
if (this.clipboardService.isSupported) {
this.clipboardService.copy(text);
} else {
super.copyToClipboard(text);
}
}
}

getUserPublicKey(): void {
this.keyService.getKey().subscribe((key: IResponseTemplate): void => {
this.userinfo.PublicKey = key.value as string;
this.isKeyBlocked();
});
}
getUserPublicKey(): void {
this.keyService.getKey().subscribe((key: IResponseTemplate): void => {
this.userinfo.PublicKey = key.value as string;
this.isKeyBlocked();
});
}
}

0 comments on commit 82e7f5e

Please sign in to comment.