Skip to content

Commit

Permalink
NOISSUE - Retrieve client key on cert issuing (#255)
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Imperiale <[email protected]>
  • Loading branch information
manuio authored May 10, 2022
1 parent 1270f35 commit b77d9e7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 20 deletions.
10 changes: 9 additions & 1 deletion src/app/common/interfaces/certs.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
export interface Cert {
export interface CertReq {
thing_id?: string;
key_bits?: number;
key_type?: string;
ttl?: string;
}

export interface CertRes {
thing_id?: string;
client_cert?: string;
client_key?: string;
cert_serial?: string;
expiration?: string;
}
6 changes: 3 additions & 3 deletions src/app/common/services/certs/certs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { throwError } from 'rxjs';
import { environment } from 'environments/environment';
import { Channel, PageFilters } from 'app/common/interfaces/mainflux.interface';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';
import { Cert } from 'app/common/interfaces/certs.interface';
import { CertReq } from 'app/common/interfaces/certs.interface';

@Injectable()
export class CertsService {
Expand All @@ -15,8 +15,8 @@ export class CertsService {
private notificationsService: NotificationsService,
) { }

issueCert(cert: Cert) {
return this.http.post(environment.certsUrl, cert, { observe: 'response' })
issueCert(cert: CertReq) {
return this.http.post(environment.certsUrl, cert)
.map(
resp => {
return resp;
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/things/cert/things.cert.component.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<nb-card>
<nb-card-header class="table-header">
Certificate: {{ serial }}
Client {{ certRes.client_key ? 'Key' : 'Certificate' }}: {{ certRes.cert_serial }}
</nb-card-header>

<nb-card-body>
<div class="row">
<code>
{{ certRes.client_key ? certRes.client_key : certRes.client_cert }}
</code>
</div>
<code>
{{ cert }}
</code>
</nb-card-body>

<nb-card-footer>
Expand Down
17 changes: 12 additions & 5 deletions src/app/pages/things/cert/things.cert.component.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { Component, Input } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { NbDialogRef } from '@nebular/theme';

import { ThingsService } from 'app/common/services/things/things.service';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';
import { ClipboardService } from 'ngx-clipboard';
import { CertRes } from 'app/common/interfaces/certs.interface';

@Component({
selector: 'ngx-things-cert-component',
templateUrl: './things.cert.component.html',
styleUrls: ['./things.cert.component.scss'],
})
export class ThingsCertComponent {
@Input() cert = '';
@Input() serial = '';
export class ThingsCertComponent implements OnInit {
certRes: CertRes = {};

constructor(
protected dialogRef: NbDialogRef<ThingsCertComponent>,
private notificationsService: NotificationsService,
private clipboardService: ClipboardService,
) { }

ngOnInit() {
if (this.certRes.client_key) {
this.notificationsService.warn('Copy the client key somewhere safe!', '');
}
}

submit() {
this.clipboardService.copyFromContent(this.cert);
this.clipboardService.copyFromContent(this.certRes.client_key ? this.certRes.client_key : this.certRes.client_cert);
this.dialogRef.close(true);
}
}
9 changes: 7 additions & 2 deletions src/app/pages/things/details/things.details.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,20 @@
<div class="col-3">
Messages
</div>
<div class="col-6">
<div class="col-4">
<nb-select fullWidth [(selected)]="chanID" size="tiny">
<nb-option *ngFor="let ch of connChansPage.rows" [value]="ch.id">{{ch.name}}</nb-option>
</nb-select>
</div>
<div class="col-2">
<nb-select fullWidth [(selected)]="format" size="tiny">
<nb-option *ngFor="let format of formats" [value]="format">{{format}}</nb-option>
</nb-select>
</div>
<div class="col-3">
<button nbButton size="tiny" class="button-green button-right"
(click)="getChannelMessages()">
Read Messages
Read
</button>
</div>
</div>
Expand Down
23 changes: 18 additions & 5 deletions src/app/pages/things/details/things.details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MessagesService } from 'app/common/services/messages/messages.service';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';
import { Thing, Channel, TableConfig, TablePage, SenMLRec } from 'app/common/interfaces/mainflux.interface';
import { ThingsCertComponent } from '../cert/things.cert.component';
import { Cert } from 'app/common/interfaces/certs.interface';
import { CertReq } from 'app/common/interfaces/certs.interface';

import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';

Expand All @@ -21,6 +21,8 @@ import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';
export class ThingsDetailsComponent implements OnInit {
thing: Thing = {};
chanID = '';
format = 'senml';
formats = ['senml', 'json'];

tableConfig: TableConfig = {
colNames: ['Name', 'Channel ID', 'checkbox'],
Expand Down Expand Up @@ -108,15 +110,26 @@ export class ThingsDetailsComponent implements OnInit {
}

onIssueCert() {
const cert: Cert = {
const cert: CertReq = {
thing_id: this.thing.id,
key_bits: 2048,
key_type: 'rsa',
ttl: '100h',
};

this.certsService.issueCert(cert).subscribe(
resp => {
(resp: any) => {
const ctx = {
context: {
certRes: resp,
},
};
this.dialogService.open(ThingsCertComponent, ctx)
.onClose.subscribe(
confirm => {
},
);

this.getCertsSerials();
},
);
Expand All @@ -127,8 +140,7 @@ export class ThingsDetailsComponent implements OnInit {
(resp: any) => {
const ctx = {
context: {
cert: resp.cert,
serial: row.cert_serial,
certRes: resp,
},
};
this.dialogService.open(ThingsCertComponent, ctx)
Expand Down Expand Up @@ -193,6 +205,7 @@ export class ThingsDetailsComponent implements OnInit {
if (this.chanID !== '') {
const filters = {
publisher: this.thing.id,
format: this.format === 'senml' ? 'messages' : this.format,
};
this.messagesService.getMessages(this.chanID, filters).subscribe(
(resp: any) => {
Expand Down

0 comments on commit b77d9e7

Please sign in to comment.