testing ciphering page

This commit is contained in:
Tykayn 2021-02-08 11:32:58 +01:00 committed by tykayn
parent 2a4219e149
commit 40c0c38889
13 changed files with 128 additions and 18 deletions

View File

@ -21,9 +21,9 @@
"mock:server": "json-server --port 8000 --watch ./mocks/db.json --routes ./mocks/routes.json", "mock:server": "json-server --port 8000 --watch ./mocks/db.json --routes ./mocks/routes.json",
"start:proxy": "ng serve --proxy-config proxy.conf.json", "start:proxy": "ng serve --proxy-config proxy.conf.json",
"start:proxymock": "concurrently --kill-others \"yarn mock:server\" \"yarn start:proxy\"", "start:proxymock": "concurrently --kill-others \"yarn mock:server\" \"yarn start:proxy\"",
"i18n:init": "ngx-translate-extract --input ./src --output ./src/assets/i18n/template.json --key-as-default-value --replace --format json", "i18n:init": "ngx-translate-extract --input ./src --output ./src/assets/i18n/template.json --key-as-default-value --replace --format json",
"i18n:extract": "ngx-translate-extract --input ./src --output ./src/assets/i18n/{en,da,de,fi,nb,nl,sv}.json --clean --format json" "i18n:extract": "ngx-translate-extract --input ./src --output ./src/assets/i18n/{en,da,de,fi,nb,nl,sv}.json --clean --format json"
}, },
"private": false, "private": false,
"dependencies": { "dependencies": {
"@angular/animations": "^9.1.1", "@angular/animations": "^9.1.1",
@ -52,6 +52,7 @@
"ngx-clipboard": "^13.0.0", "ngx-clipboard": "^13.0.0",
"ngx-markdown": "^9.0.0", "ngx-markdown": "^9.0.0",
"ngx-webstorage": "^5.0.0", "ngx-webstorage": "^5.0.0",
"node-forge": "^0.10.0",
"primeng": "^9.0.6", "primeng": "^9.0.6",
"quill": "^1.3.7", "quill": "^1.3.7",
"rxjs": "^6.5.5", "rxjs": "^6.5.5",

View File

@ -26,6 +26,7 @@ import { SharedModule } from './shared/shared.module';
import { CguComponent } from './features/shared/components/ui/static-pages/cgu/cgu.component'; import { CguComponent } from './features/shared/components/ui/static-pages/cgu/cgu.component';
import { LegalComponent } from './features/shared/components/ui/static-pages/legal/legal.component'; import { LegalComponent } from './features/shared/components/ui/static-pages/legal/legal.component';
import { PrivacyComponent } from './features/shared/components/ui/static-pages/privacy/privacy.component'; import { PrivacyComponent } from './features/shared/components/ui/static-pages/privacy/privacy.component';
import { CipheringComponent } from './features/shared/components/ui/static-pages/ciphering/ciphering.component';
registerLocaleData(localeEn, 'en-EN'); registerLocaleData(localeEn, 'en-EN');
registerLocaleData(localeFr, 'fr-FR'); registerLocaleData(localeFr, 'fr-FR');
@ -40,7 +41,7 @@ export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
} }
@NgModule({ @NgModule({
declarations: [AppComponent, CguComponent, LegalComponent, PrivacyComponent], declarations: [AppComponent, CguComponent, LegalComponent, PrivacyComponent, CipheringComponent],
imports: [ imports: [
AppRoutingModule, AppRoutingModule,
BrowserAnimationsModule, BrowserAnimationsModule,

View File

@ -228,7 +228,6 @@ export class PollService implements Resolve<Poll> {
adminKey: '', // key to change config of the poll adminKey: '', // key to change config of the poll
owner_modifier_token: '', // key to change a vote stack owner_modifier_token: '', // key to change a vote stack
canModifyAnswers: newpoll.configuration.isAllowingtoChangeOwnAnswers, // bool for the frontend selector canModifyAnswers: newpoll.configuration.isAllowingtoChangeOwnAnswers, // bool for the frontend selector
whoModifiesAnswers: newpoll.configuration.whoCanChangeAnswers, // everybody, self, nobody (: just admin)
whoCanChangeAnswers: newpoll.configuration.whoCanChangeAnswers, // everybody, self, nobody (: just admin) whoCanChangeAnswers: newpoll.configuration.whoCanChangeAnswers, // everybody, self, nobody (: just admin)
dateList: newpoll.dateChoices, // sets of days as strings, config to set identical time for days in a special days poll dateList: newpoll.dateChoices, // sets of days as strings, config to set identical time for days in a special days poll
timeList: newpoll.timeChoices, // ranges of time expressed as strings timeList: newpoll.timeChoices, // ranges of time expressed as strings

View File

@ -1,13 +1,11 @@
import { ChangeDetectorRef, Component, Inject, Input, OnInit } from '@angular/core'; import { ChangeDetectorRef, Component, Inject, Input, OnInit } from '@angular/core';
import { Poll } from '../../../core/models/poll.model'; import { Poll } from '../../../core/models/poll.model';
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { UuidService } from '../../../core/services/uuid.service'; import { UuidService } from '../../../core/services/uuid.service';
import { ApiService } from '../../../core/services/api.service'; import { ApiService } from '../../../core/services/api.service';
import { ToastService } from '../../../core/services/toast.service'; import { ToastService } from '../../../core/services/toast.service';
import { PollService } from '../../../core/services/poll.service'; import { PollService } from '../../../core/services/poll.service';
import { DateUtilities } from '../../old-stuff/config/DateUtilities';
import { DOCUMENT } from '@angular/common'; import { DOCUMENT } from '@angular/common';
import { CdkDragDrop } from '@angular/cdk/drag-drop';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
@Component({ @Component({
@ -28,7 +26,6 @@ export class FormComponent implements OnInit {
private uuidService: UuidService, private uuidService: UuidService,
private toastService: ToastService, private toastService: ToastService,
private pollService: PollService, private pollService: PollService,
public dateUtilities: DateUtilities,
private apiService: ApiService, private apiService: ApiService,
private router: Router, private router: Router,
@Inject(DOCUMENT) private document: any @Inject(DOCUMENT) private document: any
@ -48,10 +45,21 @@ export class FormComponent implements OnInit {
creatorEmail: ['', [Validators.required]], creatorEmail: ['', [Validators.required]],
slug: [this.uuidService.getUUID(), [Validators.required]], slug: [this.uuidService.getUUID(), [Validators.required]],
description: ['', [Validators.required]], description: ['', [Validators.required]],
choices: new FormArray([]), choices: this.fb.array([
// configuration: new FormGroup(), this.fb.group({
whoModifiesAnswers: ['', [Validators.required]], label: ['', [Validators.required]],
whoCanChangeAnswers: ['', [Validators.required]], imageUrl: ['', [Validators.required]],
}),
]),
configuration: this.fb.group({
whoCanChangeAnswers: ['everybody', [Validators.required]],
// isProtectedByPassword: false,
// isOwnerNotifiedByEmailOnNewVote: false,
// isOwnerNotifiedByEmailOnNewComment: false,
// isMaybeAnswerAvailable: false,
// areResultsPublic: true,
// expiracyNumberOfDays: 60,
}),
isAboutDate: [true, [Validators.required]], isAboutDate: [true, [Validators.required]],
isProtectedByPassword: [false, [Validators.required]], isProtectedByPassword: [false, [Validators.required]],
startDateInterval: ['', [Validators.required]], startDateInterval: ['', [Validators.required]],
@ -71,6 +79,7 @@ export class FormComponent implements OnInit {
if (showDemoValues) { if (showDemoValues) {
this.setDemoValues(); this.setDemoValues();
this.toastService.display('default values filled for demo');
} }
} }
@ -85,9 +94,8 @@ export class FormComponent implements OnInit {
creatorPseudo: 'Chuck Norris', creatorPseudo: 'Chuck Norris',
creatorEmail: 'chucknorris@example.com', creatorEmail: 'chucknorris@example.com',
isAboutDate: true, isAboutDate: true,
hasSeveralHours: true, // hasSeveralHours: true,
configuration: { configuration: {
whoModifiesAnswers: 'everybody',
whoCanChangeAnswers: 'everybody', whoCanChangeAnswers: 'everybody',
isProtectedByPassword: false, isProtectedByPassword: false,
isOwnerNotifiedByEmailOnNewVote: false, isOwnerNotifiedByEmailOnNewVote: false,

View File

@ -62,7 +62,6 @@ export class PollConfig {
adminKey = ''; // key to change config of the poll adminKey = ''; // key to change config of the poll
owner_modifier_token = ''; // key to change a vote stack owner_modifier_token = ''; // key to change a vote stack
canModifyAnswers = true; // bool for the frontend selector canModifyAnswers = true; // bool for the frontend selector
whoModifiesAnswers = 'everybody'; // everybody, self, nobody (= just admin)
whoCanChangeAnswers = 'everybody'; // everybody, self, nobody (= just admin) whoCanChangeAnswers = 'everybody'; // everybody, self, nobody (= just admin)
dateList: any = otherDefaultDates; // sets of days as strings, config to set identical time for days in a special days poll dateList: any = otherDefaultDates; // sets of days as strings, config to set identical time for days in a special days poll
timeList: DateChoice[] = otherDefaultDates; // ranges of time expressed as strings timeList: DateChoice[] = otherDefaultDates; // ranges of time expressed as strings

View File

@ -73,7 +73,7 @@
name="modificationScope" name="modificationScope"
id="modificationScope" id="modificationScope"
*ngIf="true == !!config.canModifyAnswers" *ngIf="true == !!config.canModifyAnswers"
[(ngModel)]="config.whoModifiesAnswers" [(ngModel)]="config.whoCanChangeAnswers"
[disabled]="false == !!config.canModifyAnswers" [disabled]="false == !!config.canModifyAnswers"
> >
<option value="self"> <option value="self">

View File

@ -84,7 +84,6 @@ export class ConfigService extends PollConfig {
password: this.password, password: this.password,
customUrl: this.customUrl, customUrl: this.customUrl,
canModifyAnswers: this.canModifyAnswers, canModifyAnswers: this.canModifyAnswers,
whoModifiesAnswers: this.whoModifiesAnswers,
dateList: this.dateList, dateList: this.dateList,
timeList: this.timeList, timeList: this.timeList,
answers: this.answers, answers: this.answers,

View File

@ -0,0 +1,22 @@
<div class="ciphering padded">
<h2>
Test de chiffrement
</h2>
<br />
<input type="text" [(ngModel)]="plainText" (ngModelChange)="encrypt(plainText)" />
texte clair
<br />
<input type="text" [(ngModel)]="salt" />
salt
<br />
<input type="text" [(ngModel)]="key" />
pepper
<br />
<input type="text" [(ngModel)]="cipheredText" />
texte chiffré
<br />
<input type="text" [(ngModel)]="otherCipheredText" />
texte à déchiffrer
</div>

View File

@ -0,0 +1,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CipheringComponent } from './ciphering.component';
describe('CipheringComponent', () => {
let component: CipheringComponent;
let fixture: ComponentFixture<CipheringComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CipheringComponent],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CipheringComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,47 @@
import { Component, OnInit } from '@angular/core';
const forge = require('node-forge');
@Component({
selector: 'app-ciphering',
templateUrl: './ciphering.component.html',
styleUrls: ['./ciphering.component.scss'],
})
export class CipheringComponent implements OnInit {
public plainText = 'le texte à chiffrer';
public cipheredText = '';
public salt = forge.random.getBytesSync(128);
public key = forge.random.getBytesSync(128);
public otherCipheredText: any;
constructor() {}
ngOnInit(): void {
this.encrypt(this.plainText);
}
encrypt(someText) {
// generate a random key and IV
// Note: a key size of 16 bytes will use AES-128, 24 => AES-192, 32 => AES-256
// const key = forge.random.getBytesSync(16);
// const iv = forge.random.getBytesSync(16);
/* alternatively, generate a password-based 16-byte key
var salt = forge.random.getBytesSync(128);
var key = forge.pkcs5.pbkdf2('password', salt, numIterations, 16);
*/
// encrypt some bytes using CBC mode
// (other modes include: ECB, CFB, OFB, CTR, and GCM)
// Note: CBC and ECB modes use PKCS#7 padding as default
// const cipher = forge.cipher.createCipher('AES-CBC', this.key);
// cipher.start({ iv: this.salt });
// cipher.update(forge.util.createBuffer(someText));
// cipher.finish();
// const encrypted = cipher.output;
// this.cipheredText = encrypted.toHex();
this.cipheredText = someText;
// outputs encrypted hex
console.log(this.cipheredText);
}
}

View File

@ -7,6 +7,7 @@ import { WipTodoComponent } from './shared/components/ui/wip-todo/wip-todo.compo
import { CguComponent } from './features/shared/components/ui/static-pages/cgu/cgu.component'; import { CguComponent } from './features/shared/components/ui/static-pages/cgu/cgu.component';
import { LegalComponent } from './features/shared/components/ui/static-pages/legal/legal.component'; import { LegalComponent } from './features/shared/components/ui/static-pages/legal/legal.component';
import { PrivacyComponent } from './features/shared/components/ui/static-pages/privacy/privacy.component'; import { PrivacyComponent } from './features/shared/components/ui/static-pages/privacy/privacy.component';
import { CipheringComponent } from './features/shared/components/ui/static-pages/ciphering/ciphering.component';
export const routes: Routes = [ export const routes: Routes = [
{ path: '', component: HomeComponent }, { path: '', component: HomeComponent },
@ -60,6 +61,10 @@ export const routes: Routes = [
path: 'privacy', path: 'privacy',
component: PrivacyComponent, component: PrivacyComponent,
}, },
{
path: 'ciphering',
component: CipheringComponent,
},
{ path: 'page-not-found', component: PageNotFoundComponent }, { path: 'page-not-found', component: PageNotFoundComponent },
{ path: '**', redirectTo: 'page-not-found', pathMatch: 'full' }, { path: '**', redirectTo: 'page-not-found', pathMatch: 'full' },
]; ];

View File

@ -8193,6 +8193,11 @@ node-forge@0.9.0:
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579"
integrity sha512-7ASaDa3pD+lJ3WvXFsxekJQelBKRpne+GOVbLbtHYdd7pFspyeuJHnWfLplGf3SwKGbfs/aYl5V/JCIaHVUKKQ== integrity sha512-7ASaDa3pD+lJ3WvXFsxekJQelBKRpne+GOVbLbtHYdd7pFspyeuJHnWfLplGf3SwKGbfs/aYl5V/JCIaHVUKKQ==
node-forge@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"
integrity sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==
node-int64@^0.4.0: node-int64@^0.4.0:
version "0.4.0" version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"