-
Notifications
You must be signed in to change notification settings - Fork 6
/
MasterPasswordWizardUnit.pas
1433 lines (1143 loc) · 46.1 KB
/
MasterPasswordWizardUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit MasterPasswordWizardUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, IpHtml, Forms, Controls, Graphics, Dialogs,
ComCtrls, ExtCtrls, Buttons, StdCtrls, EnterMasterPasswordUnit,
QuestionUnit, CreatePasswordUnit, passrateunit, Types, EmerAPIBlockchainUnit, fpjson, jsonparser;
type
{ TMasterPasswordWizardForm }
TMasterPasswordWizardForm = class(TForm)
createPassword1: TcreatePassword;
EnterMasterPasswordFrame1: TEnterMasterPasswordFrame;
EnterMasterPasswordFrame2: TEnterMasterPasswordFrame;
tsConnectServerPanelCombobox: TComboBox;
Panel12: TPanel;
tsServerConnected: TTabSheet;
tsConnectServerPanelChSelectServer: TCheckBox;
tsServerLoginPanelLabel: TLabel;
tsServerLoginBOpen: TBitBtn;
tsServerLoginBRecheck: TBitBtn;
tsServerConnectedPanel: TPanel;
tsServerLoginBLinkToBuffer: TBitBtn;
tsServerSelectBTest: TBitBtn;
bShowUserPasswordGenerator: TBitBtn;
bHelp: TBitBtn;
bFinish: TBitBtn;
bGenerateUserPass: TBitBtn;
bNext: TBitBtn;
bPrev: TBitBtn;
bClose: TBitBtn;
tsServerConnectedChDontSave: TCheckBox;
tsServerSelectEdit1: TEdit;
InlineMessageTimer: TTimer;
lServerAddress: TLabel;
Panel11: TPanel;
tsServerLoginPanel: TPanel;
Panel13: TPanel;
tsServerSelectPanel: TPanel;
tsServerLogin: TTabSheet;
tsServerSelect: TTabSheet;
tsConnectServerPanel: TPanel;
Panel6: TPanel;
PassRate2: TPassRate;
tsServerSelectChAdv: TCheckBox;
tsSetUserPassTimer: TTimer;
tsSetPassDoneContinuePanel: TPanel;
tsSetPassDoneFinishPanel: TPanel;
tsSetUserPasschShowPassword: TCheckBox;
tsCreateMasterPassFreeFormchShowPassword: TCheckBox;
tsCreateMasterPassFreeFormEdit2: TEdit;
tsCreateMasterPassFreeFormlPassword2: TLabel;
tsCreateMasterPassFreeFormEdit1: TEdit;
lPassword3: TLabel;
Panel10: TPanel;
Panel9: TPanel;
tsCreateMasterPassFreeFormTimer: TTimer;
tsSetUserPassTrackBar: TTrackBar;
tsSetPassDoneContinueCSetupServer: TCheckBox;
tsSetPassDoneFinish: TTabSheet;
tsSetPassDoneContinue: TTabSheet;
tsCreateMasterPass12wEditW1: TEdit;
tsSetUserPassEdit1: TEdit;
tsSetUserPassEdit2: TEdit;
tsCreateMasterPass12wEditW10: TEdit;
tsCreateMasterPass12wEditW11: TEdit;
tsCreateMasterPass12wEditW12: TEdit;
tsCreateMasterPass12wEditW2: TEdit;
tsCreateMasterPass12wEditW3: TEdit;
tsCreateMasterPass12wEditW4: TEdit;
tsCreateMasterPass12wEditW5: TEdit;
tsCreateMasterPass12wEditW6: TEdit;
tsCreateMasterPass12wEditW7: TEdit;
tsCreateMasterPass12wEditW8: TEdit;
tsCreateMasterPass12wEditW9: TEdit;
tsCreateMasterPass12wlW1: TLabel;
lPassword1: TLabel;
tsSetUserPasslPassword2: TLabel;
Panel3: TPanel;
tsSetUserPassGeneratorPanel: TPanel;
Panel7: TPanel;
Panel8: TPanel;
PassRate1: TPassRate;
tsCreateMasterPass12wlW10: TLabel;
tsCreateMasterPass12wlW11: TLabel;
tsCreateMasterPass12wlW12: TLabel;
tsCreateMasterPass12wlW2: TLabel;
tsCreateMasterPass12wlW3: TLabel;
tsCreateMasterPass12wlW4: TLabel;
tsCreateMasterPass12wlW5: TLabel;
tsCreateMasterPass12wlW6: TLabel;
tsCreateMasterPass12wlW7: TLabel;
tsCreateMasterPass12wlW8: TLabel;
tsCreateMasterPass12wlW9: TLabel;
tsCreateMasterPass12wPanel: TPanel;
tsCreateMasterPassFreeFormPanel: TPanel;
tsCheckMasterPassPanel: TPanel;
tsSetUserPassPanel: TPanel;
tsSetUserPass: TTabSheet;
MainPageControl: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
Panel5: TPanel;
tsRestoreMasterPassPanel: TPanel;
tsCreateNewMasterPass1Panel: TPanel;
Panel4: TPanel;
tsAskForMasterPassPanel: TPanel;
tsCreateNewMasterPass1RB1: TRadioButton;
tsCreateNewMasterPass1RB2: TRadioButton;
tsAskForMasterPassRB1: TRadioButton;
tsAskForMasterPassRB2: TRadioButton;
tsConnectAllDone: TTabSheet;
tsConnectServer: TTabSheet;
tsConnectLocalWallet: TTabSheet;
tsConnectionSelect: TTabSheet;
tsKeepMasterPass: TTabSheet;
tsCheckMasterPass: TTabSheet;
tsCreateMasterPass12w: TTabSheet;
tsCreateMasterPassFreeForm: TTabSheet;
tsCreateNewMasterPass1: TTabSheet;
tsAskForMasterPass: TTabSheet;
tsRestoreMasterPass: TTabSheet;
tsSetUserPassPanel1: TPanel;
tsSetUserPassPanelCDoNotSave: TCheckBox;
procedure bCloseClick(Sender: TObject);
procedure bClick(Sender: TObject);
procedure bGenerateUserPassClick(Sender: TObject);
procedure bHelpClick(Sender: TObject);
procedure tsServerConnectedHide(Sender: TObject);
procedure tsServerConnectedShow(Sender: TObject);
procedure bShowUserPasswordGeneratorClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure InlineMessageTimerTimer(Sender: TObject);
procedure tsCheckMasterPassShow(Sender: TObject);
procedure tsConnectServerPanelChSelectServerClick(Sender: TObject);
procedure tsConnectServerShow(Sender: TObject);
procedure tsCreateMasterPass12wShow(Sender: TObject);
procedure tsCreateMasterPassFreeFormEdit1Change(Sender: TObject);
procedure tsCreateMasterPassFreeFormchShowPasswordChange(
Sender: TObject);
procedure tsCreateMasterPassFreeFormEdit2Change(Sender: TObject);
procedure tsCreateMasterPassFreeFormTimerTimer(Sender: TObject);
procedure tsServerLoginBLinkToBufferClick(Sender: TObject);
procedure tsServerLoginBOpenClick(Sender: TObject);
procedure tsServerLoginBRecheckClick(Sender: TObject);
procedure tsServerLoginHide(Sender: TObject);
procedure tsServerLoginShow(Sender: TObject);
procedure tsServerLoginPanelTryToConnect;
procedure tsSetPassDoneContinueHide(Sender: TObject);
procedure tsSetPassDoneContinueShow(Sender: TObject);
procedure tsSetPassDoneFinishHide(Sender: TObject);
procedure tsSetPassDoneFinishShow(Sender: TObject);
procedure tsSetUserPasschShowPasswordChange(Sender: TObject);
procedure tsSetUserPassEdit1Change(Sender: TObject);
procedure tsSetUserPassEdit2Change(Sender: TObject);
procedure tsSetUserPassHide(Sender: TObject);
procedure tsSetUserPassPanelCDoNotSaveChange(Sender: TObject);
procedure tsSetUserPassShow(Sender: TObject);
procedure tsAskForMasterPassHide(Sender: TObject);
procedure tsAskForMasterPassShow(Sender: TObject);
procedure tsCheckMasterPassHide(Sender: TObject);
procedure tsConnectAllDoneHide(Sender: TObject);
procedure tsConnectionSelectHide(Sender: TObject);
procedure tsConnectLocalWalletHide(Sender: TObject);
procedure tsConnectServerHide(Sender: TObject);
procedure tsCreateMasterPass12wHide(Sender: TObject);
procedure tsCreateMasterPassFreeFormHide(Sender: TObject);
procedure tsCreateMasterPassFreeFormShow(Sender: TObject);
procedure tsCreateNewMasterPass1Hide(Sender: TObject);
procedure tsCreateNewMasterPass1Show(Sender: TObject);
procedure tsKeepMasterPassHide(Sender: TObject);
procedure tsSetPassDoneContinueCSetupServerChange(Sender: TObject);
procedure tsRestoreMasterPassHide(Sender: TObject);
procedure EnterMasterPasswordFrame1PasswordChanged(Sender: TObject);
procedure EnterMasterPasswordFrame2PasswordChanged(Sender: TObject);
procedure tsRestoreMasterPassShow(Sender: TObject);
procedure goBack; //lHistoryStack
procedure goNext(ts:tTabSheet); //lHistoryStack
procedure setButtonsDefault;
procedure tsRestoreMasterPassAnswer1(sender:tObject;aModalResult:tModalResult;atag:ansistring);
procedure ShowInlineMessage(aTag:ansistring;aMessage:string='';ahelpURL:ansistring='');
function AskInlineYesNo(answerProc:tAskQuestionOnAnswer;aTag:ansistring;aMessage:string='';ahelpURL:ansistring='';YesByDefault:boolean=false):boolean;
procedure tsSetUserPassTimerTimer(Sender: TObject);
procedure tsSetUserPassTrackBarChange(Sender: TObject);
private
tsRestoreMasterPassLastSavedPass:string;
tsCreateMasterPassLastSavedPass:string;
lHistoryStack:tList;
tsServerLoginAddress:string;
//tsServerLoginSalt:ansistring;
fLastServerLoginLink:ansistring;
InlineMessageaMessage:string;
InlineMessageaHelpURL:ansistring;
InlineMessageaTag:ansistring;
procedure myQueryDone(sender:TEmerAPIBlockchainThread;result:tJsonData);
public
wizardID:ansistring;
end;
{ Логотип (с) работы.
1. Вопрос о наличии МП. Рассказ о том, что такое МП. Если есть - то идем сразу на ввод имеющегося МП (там по набираемому парлю сразу показывают адрес)
2. Выбор способа задания МП: фраза из слов, рандомные символы, готовая фраза из слов
Показывают устойчивость пароля, показывают предупреждения (нет групп символов), показывают получившийся адрес.
3. Сохранение МП. Рассказ про сохранения (технология круга, разбиение на пары)
- разбивалка МП на части. Предлагает печать.
- шифровалка МП?
- Показывает QR код MP. Предлагает печать.
4. Ввод МП для подтверждения. Переход на п.6
5. () Восстановление ключевой пары (КП) по МП. Рассказываем о том, что если у вас НОВЫЙ пароль - переходите на экран 2. Показываем по вводимому МП соотвествующие адреса.
6. Хотим ли мы сохранить КП на компьютере? Объясняем нюансы, здесь же кнопка задания пароля пользователя (открывается окно смены/задания пароля пользователя)
устанавливаются настройки хранения КП, сейвим настройки.
----процесс соединения с сервером-----
1. Пользователь говорит что хочет настроить подлючение к серверу и выбирает сервер из списка (или вводит свой)
если есть логин и пароль - можно ввести или исправить их (берутся из настроек) здесь же.
Пользователь посылает серверу свой адрес . Север либо опознает этот адрес , либо нет - в любом случае он отвечает запросом. сообщая, узнал ли он пользователя, и просит подтвердить подлинность, зашифровав криптосообщениие
для случая что пользователь опознан - просто сообщаем что адрес серверу уже известен, связь установлена. если нет - то показываем второй экран
2. Пользователю говорят, что сервер не знает такой адрес, или что его логин и пароль не распознаны или не соответствуют адресу (или иной ответ от сервера)
Для случаев, когда продолжение возможно, пользователь подтвержает регистрацию на сервере. При этом отправляется публичный ключ и сделанная приватником
(!требуется ввод пин на этом этапе)
подпись присланной сервером последовательности байтов.
Если сервер ее проверил и она совпала - он возвращает ссылку на страницу регистрации, и дальше все идет на сервере.
}
var
MasterPasswordWizardForm: TMasterPasswordWizardForm;
function ShowWizardForm(wizardID:ansistring):boolean;
implementation
{$R *.lfm}
uses Localizzzeunit,GuidePageUnit, PasswordHelper, MainUnit, settingsunit, ClpSecureRandom, CryptoLib4PascalConnectorUnit,
Crypto, EmerAPIServerUnit, Clipbrd, LCLIntf
,HelpRedirector
;
{ TMasterPasswordWizardForm }
procedure destroyGuidePage(panel:tPanel);
begin
while TWinControl(panel).ControlCount>0 do
TWinControl(panel).Controls[0].Free;
end;
procedure createGuidePage(panel:tPanel);
begin
tGuidePage.create(panel).Align:=alClient;
end;
function ShowWizardForm(wizardID:ansistring):boolean;
var i:integer;
begin
result:=false;
try
if MasterPasswordWizardForm.MainPageControl.ActivePage<>nil then
if assigned(MasterPasswordWizardForm.MainPageControl.ActivePage.OnHide)
then MasterPasswordWizardForm.MainPageControl.ActivePage.OnHide(nil);
MasterPasswordWizardForm.MainPageControl.ActivePage:=nil;
application.ProcessMessages;
for i:=0 to MasterPasswordWizardForm.MainPageControl.PageCount-1 do
MasterPasswordWizardForm.MainPageControl.Pages[i].Visible:=false;
if MasterPasswordWizardForm.lHistoryStack<>nil then MasterPasswordWizardForm.lHistoryStack.clear;
MasterPasswordWizardForm.MainPageControl.PageIndex:=-1;
if lowercase(wizardID)='doall' then begin
result:=true;
result:=ShowWizardForm('domp'); if not result then exit;
result:=ShowWizardForm('doServerConnect'); if not result then exit;
result:=ShowWizardForm('doWalletConnect'); if not result then exit;
exit;
end else
if lowercase(wizardID)='domp' then begin
MasterPasswordWizardForm.MainPageControl.PageIndex:=0;
MasterPasswordWizardForm.wizardID:='domp';
if assigned(MasterPasswordWizardForm.MainPageControl.ActivePage.OnShow)
then MasterPasswordWizardForm.MainPageControl.ActivePage.OnShow(nil);
end
else if lowercase(wizardID)='doserverconnect' then begin
MasterPasswordWizardForm.wizardID:='doserverconnect';
MasterPasswordWizardForm.MainPageControl.ActivePage:=MasterPasswordWizardForm.tsConnectServer;
if assigned(MasterPasswordWizardForm.MainPageControl.ActivePage.OnShow)
then MasterPasswordWizardForm.MainPageControl.ActivePage.OnShow(nil);
end
else exit;
finally
MainForm.CheckAdvices(MasterPasswordWizardForm);
end;
MasterPasswordWizardForm.MainPageControl.ShowTabs:=false;
result:=MasterPasswordWizardForm.ShowModal=mrOk;
end;
procedure TMasterPasswordWizardForm.setButtonsDefault;
begin
bFinish.Enabled:=true;
bNext.Enabled:=true;
bPrev.Enabled:=true;
bFinish.Visible:=false;
bNext.Visible:=true;
bPrev.Visible:=lHistoryStack.Count>0;
end;
procedure TMasterPasswordWizardForm.goBack; //lHistoryStack
var ts: TTabSheet;
begin
if lHistoryStack.Count>0 then begin
ts:=TTabSheet(lHistoryStack[lHistoryStack.Count-1]);
lHistoryStack.Delete(lHistoryStack.Count-1);
MainPageControl.ActivePage:=ts;
end;
end;
procedure TMasterPasswordWizardForm.goNext(ts:tTabSheet); //lHistoryStack
var t:boolean;
begin
lHistoryStack.Add(MainPageControl.ActivePage);
t:=InlineMessageTimer.Enabled; InlineMessageTimer.Enabled:=false;
application.processmessages;
MainPageControl.ActivePage:=ts;
application.processmessages;
if t then InlineMessageTimer.Enabled:=true;
end;
procedure TMasterPasswordWizardForm.tsAskForMasterPassHide(Sender: TObject);
begin
if sender=bNext then begin
if tsAskForMasterPassRB1.Checked then
goNext(tsRestoreMasterPass)
else if tsAskForMasterPassRB2.Checked then
goNext(tsCreateNewMasterPass1)
else exit;
//lHistoryStack.Add(tsAskForMasterPass);
end else
if sender=bPrev then begin
end else
if sender=bFinish then begin
end else
if sender=bHelp then begin
end else
destroyGuidePage(tsAskForMasterPassPanel);
end;
procedure TMasterPasswordWizardForm.bCloseClick(Sender: TObject);
begin
bClick(Sender);
if visible then
Close;
end;
procedure TMasterPasswordWizardForm.bClick(Sender: TObject);
begin
if assigned(MainPageControl.ActivePage.OnHide) then
MainPageControl.ActivePage.OnHide(Sender);
end;
procedure TMasterPasswordWizardForm.bGenerateUserPassClick(Sender: TObject);
var s:string;
begin
s:=createPassword1.createPassword(tsSetUserPassTrackBar.Position);
tsSetUserPassEdit1.Text:=s;
tsSetUserPassEdit2.Text:='';
if not tsSetUserPasschShowPassword.Checked then begin
tsSetUserPasschShowPassword.Checked:=true;
tsSetUserPasschShowPasswordChange(nil);
end;
end;
procedure TMasterPasswordWizardForm.bHelpClick(Sender: TObject);
begin
showHelpTag('MasterPasswordWizardForm',nil,MainPageControl.ActivePage.Name);
//if assigned(MainPageControl.ActivePage.OnHide) then
// MainPageControl.ActivePage.OnHide(Sender);
end;
procedure TMasterPasswordWizardForm.tsServerConnectedHide(Sender: TObject);
var s1,s2:ansistring;
begin
if sender=bNext then begin
goNext(tsServerConnected);
end else
if sender=bPrev then begin
if lHistoryStack.Count>1 then begin
lHistoryStack.Delete(lHistoryStack.Count-1);
goBack;
end;
end else
if sender=bFinish then begin
if not tsServerConnectedChDontSave.Checked then begin
Settings.setValue('EmerAPI_Server_Save_yum_l',true);
Settings.setValue('EMERAPI_SERVER_GUEST_ONLY',false);
if tsConnectServerPanelChSelectServer.Checked then
Settings.setValue('EMERAPI_SERVER_ADDRESS',tsServerLoginAddress);
Settings.saveParams(['EMERAPI_SERVER_ADDRESS','EmerAPI_Server_adv_SessionKey','EmerAPI_Server_Login_Address','EmerAPI_Server_adv_yum_l','EmerAPI_Server_Save_yum_l','EMERAPI_SERVER_GUEST_ONLY']);
end else begin
//erase info
s1:=Settings.getValue('EmerAPI_Server_adv_SessionKey');
s2:=Settings.getValue('sssEmerAPI_Server_adv_yum_l');
Settings.setValue('EmerAPI_Server_Save_yum_l',false);
Settings.setValue('EmerAPI_Server_adv_SessionKey','');
Settings.setValue('sssEmerAPI_Server_adv_yum_l','');
Settings.saveParams(['EmerAPI_Server_adv_SessionKey','EmerAPI_Server_Login_Address','EmerAPI_Server_adv_yum_l','EmerAPI_Server_Save_yum_l']);
Settings.setValue('EmerAPI_Server_adv_SessionKey',s1);
Settings.setValue('sssEmerAPI_Server_adv_yum_l',s2);
end;
emerAPI.EmerAPIConnetor.serverAPI.throwErrorStatus;
MainForm.SetAndCheckBlockchain(false,true,true);
MainForm.onServerConnected(nil);
modalResult:=mrOk;
//close;
end else
if sender=bHelp then begin
end else
destroyGuidePage(tsServerLoginPanel);
end;
procedure TMasterPasswordWizardForm.tsServerConnectedShow(Sender: TObject);
begin
createGuidePage(tsServerConnectedPanel);
setButtonsDefault;
bNext.Visible:=false;
bFinish.Visible:=true;
end;
procedure TMasterPasswordWizardForm.bShowUserPasswordGeneratorClick(
Sender: TObject);
begin
tsSetUserPassGeneratorPanel.Visible:=not tsSetUserPassGeneratorPanel.Visible;
end;
procedure TMasterPasswordWizardForm.FormCreate(Sender: TObject);
begin
lHistoryStack:=tList.create;
KeyPreview:=True;
end;
procedure TMasterPasswordWizardForm.FormDestroy(Sender: TObject);
begin
lHistoryStack.free;
end;
procedure TMasterPasswordWizardForm.FormShow(Sender: TObject);
begin
localizzze(self);
end;
procedure TMasterPasswordWizardForm.tsCheckMasterPassShow(Sender: TObject);
begin
createGuidePage(tsCheckMasterPassPanel);
setButtonsDefault;
bNext.Enabled:=false;
EnterMasterPasswordFrame2.eAddress.Text:='';
EnterMasterPasswordFrame2.init;
EnterMasterPasswordFrame2.onPasswordChanged:=@EnterMasterPasswordFrame2PasswordChanged;
if EnterMasterPasswordFrame2.eMasterPassword.CanSetFocus then
EnterMasterPasswordFrame2.eMasterPassword.SetFocus;
EnterMasterPasswordFrame2.lAssignedAddress.Visible:=false;
EnterMasterPasswordFrame2.eAddress.Visible:=false;
end;
procedure TMasterPasswordWizardForm.tsConnectServerPanelChSelectServerClick(
Sender: TObject);
begin
tsConnectServerPanelCombobox.Visible:=tsConnectServerPanelChSelectServer.Checked;
end;
procedure TMasterPasswordWizardForm.tsConnectServerShow(Sender: TObject);
begin
createGuidePage(tsConnectServerPanel);
setButtonsDefault;
bPrev.Visible:=lHistoryStack.Count>0;
tsConnectServerPanelChSelectServerClick(nil);
end;
procedure TMasterPasswordWizardForm.tsCreateMasterPass12wShow(Sender: TObject);
var FRandom :TSecureRandom;
Bytes:TBytes;
hash,buf:ansistring;
res:ansistring;
crc:byte;
i:integer;
s:string;
function pop(var s:string;spacer:string=' '):string;
var n:integer;
begin
n:=pos(spacer,s);
if n<1 then begin
result:=s;
s:='';
exit;
end;
result:=copy(s,1,n-1);
delete(s,1,n+length(spacer)-1);
end;
begin
if tsCreateMasterPassLastSavedPass='' then begin
FRandom := TSecureRandom.Create();
FRandom.Boot();
setLength(Bytes,16);
FRandom.NextBytes(Bytes);
buf:=bytes2buf(Bytes);
hash:=dosha256(buf);
crc:=ord(hash[1]) shr (8 - length(buf) div 4);
res:=shlbuf(buf,length(buf) div 4);
res[length(res)]:=chr(ord(res[length(res)]) + crc);
tsCreateMasterPassLastSavedPass:=bytesToBIP39(res,bip0039english,' ');
end;
s:=tsCreateMasterPassLastSavedPass;
tsCreateMasterPass12wEditW1.Text:=pop(s,' ');
tsCreateMasterPass12wEditW2.Text:=pop(s,' ');
tsCreateMasterPass12wEditW3.Text:=pop(s,' ');
tsCreateMasterPass12wEditW4.Text:=pop(s,' ');
tsCreateMasterPass12wEditW5.Text:=pop(s,' ');
tsCreateMasterPass12wEditW6.Text:=pop(s,' ');
tsCreateMasterPass12wEditW7.Text:=pop(s,' ');
tsCreateMasterPass12wEditW8.Text:=pop(s,' ');
tsCreateMasterPass12wEditW9.Text:=pop(s,' ');
tsCreateMasterPass12wEditW10.Text:=pop(s,' ');
tsCreateMasterPass12wEditW11.Text:=pop(s,' ');
tsCreateMasterPass12wEditW12.Text:=pop(s,' ');
createGuidePage(tsCreateMasterPass12wPanel);
setButtonsDefault;
end;
procedure TMasterPasswordWizardForm.tsCreateMasterPassFreeFormEdit1Change(
Sender: TObject);
begin
tsCreateMasterPassFreeFormTimer.Enabled:=false;
tsCreateMasterPassFreeFormTimer.Enabled:=true;
tsCreateMasterPassFreeFormEdit2Change(nil);
end;
procedure TMasterPasswordWizardForm.tsCreateMasterPassFreeFormchShowPasswordChange
(Sender: TObject);
begin
tsCreateMasterPassFreeFormEdit2.Enabled:=not tsCreateMasterPassFreeFormchShowPassword.checked;
if not tsCreateMasterPassFreeFormEdit2.Enabled then tsCreateMasterPassFreeFormEdit2.Text:='';
tsCreateMasterPassFreeFormlPassword2.Enabled:=tsCreateMasterPassFreeFormEdit2.Enabled;
if tsCreateMasterPassFreeFormchShowPassword.Checked
then tsCreateMasterPassFreeFormEdit1.PasswordChar:=#0
else tsCreateMasterPassFreeFormEdit1.PasswordChar:='*';
end;
procedure TMasterPasswordWizardForm.tsCreateMasterPassFreeFormEdit2Change(
Sender: TObject);
begin
bNext.Enabled:= (tsCreateMasterPassFreeFormEdit2.Text=tsCreateMasterPassFreeFormEdit1.Text) or tsCreateMasterPassFreeFormchShowPassword.Checked;
if (tsCreateMasterPassFreeFormEdit2.Text<>tsCreateMasterPassFreeFormEdit1.Text) and (tsCreateMasterPassFreeFormEdit2.Text<>'') and tsCreateMasterPassFreeFormEdit2.enabled
then tsCreateMasterPassFreeFormEdit2.Color:=clRed
else tsCreateMasterPassFreeFormEdit2.Color:=clDefault;
end;
procedure TMasterPasswordWizardForm.tsCreateMasterPassFreeFormTimerTimer(
Sender: TObject);
begin
tsCreateMasterPassFreeFormTimer.Enabled:=false;
PassRate2.UpdateStat(tsCreateMasterPassFreeFormEdit1.Text);
bNext.Enabled:=(bNext.Enabled and (PassRate2.pbRate.Position>30)) or Settings.getValue('Dev_Mode_ON');
end;
procedure TMasterPasswordWizardForm.tsServerLoginBLinkToBufferClick(
Sender: TObject);
begin
Clipboard.AsText:=fLastServerLoginLink;
end;
procedure TMasterPasswordWizardForm.tsServerLoginBOpenClick(Sender: TObject);
begin
OpenURL(fLastServerLoginLink);
end;
procedure TMasterPasswordWizardForm.tsServerLoginBRecheckClick(Sender: TObject);
begin
tsServerLoginPanelTryToConnect();
end;
procedure TMasterPasswordWizardForm.tsServerLoginHide(Sender: TObject);
begin
if sender=bNext then begin
goNext(tsServerConnected);
end else
if sender=bPrev then begin
goBack;
end else
if sender=bFinish then begin
end else
if sender=bHelp then begin
end else
destroyGuidePage(tsServerLoginPanel);
end;
procedure TMasterPasswordWizardForm.myQueryDone(sender:TEmerAPIBlockchainThread;result:tJsonData);
var e,js:tJsonData;
ddr:tDecodeDataResult;
dData:ansistring;
begin
if result=nil then begin
tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.ConnError','');
tsServerLoginBRecheck.Enabled:=true;
tsServerLoginBOpen.Enabled:=false;
tsServerLoginBLinkToBuffer.Enabled:=false;
end else begin
//show JSON everywhere
//{ "data" : { "userlogin" : { "response" : "EmerHEJ_041617d.....4337512d0a326" } } }
//showMessageSafe(result.AsJSON);
e:=result.FindPath('data.userlogin.response');
if e=nil then begin
bNext.Enabled:=false;
tsServerLoginBRecheck.Enabled:=true;
tsServerLoginBOpen.Enabled:=false;
tsServerLoginBLinkToBuffer.Enabled:=false;
tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.ConnError','');
end else begin
//decode
ddr:=emerAPI.EmerAPIConnetor.serverAPI.decodeDataJSON(e.AsString,js);
try
if ddr<>ddrSuccesseful then begin
tsServerLoginBRecheck.Enabled:=true;
tsServerLoginBOpen.Enabled:=false;
tsServerLoginBLinkToBuffer.Enabled:=false;
case ddr of
ddrWrongPrivKey: tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.WrongPrivKey','Error: wrong private key. Cannot decode server response');
ddrWrongAESKey: tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.WrongAESKey','Error: wrong AES key. Cannot decode server response');
//ddrBinaryData: raise exception.Create('binary data received. Cannot decode server JSON response');
else
//raise exception.Create('unknown server response');
tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.UnknownResponse','Error: Unknown server response');
end;
end else begin
//OK!!!
//showMessageSafe(js.AsJson);
{ "sid" : "0B033E4C5BB1A9ED", "url" : "https://emcdpo.info/sign-up?token=", "token" : "5c1e26adf3a60864cd8d64c8" }
//check sid
e:=js.FindPath('sid');
if (e=nil) or (e.AsString<>bufToHex(emerAPI.EmerAPIConnetor.serverAPI.LastServerLoginSalt)) then begin
tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.WorngResponse','Error: Wrong server response');
tsServerLoginBRecheck.Enabled:=true;
tsServerLoginBOpen.Enabled:=false;
tsServerLoginBLinkToBuffer.Enabled:=false;
exit;
end;
e:=js.FindPath('session_key');
if e<>nil then begin
//we have session key
//confuguring access
//ConnDataServer.connectUsingUsername:=not Settings.getValue('EmerAPI_Server_Login_Address');
//ConnDataServer.AESKey:=Settings.getValue('EmerAPI_Server_adv_SessionKey');
//showMessageSafe('session_key='+e.AsString);
Settings.setValue('EmerAPI_Server_adv_SessionKey',bufToHex(HexToBuf(e.AsString)));//hex to hex
//Settings.setValue('EmerAPI_Server_adv_SessionKey',bufToHex(e.AsString));//D!!!
Settings.setValue('EmerAPI_Server_Login_Address',true);
//Settings.saveParams(['EmerAPI_Server_adv_SessionKey','EmerAPI_Server_Login_Address','EmerAPI_Server_adv_yum_l']);
e:=js.FindPath('cookies._yum_l');
if e<>nil then
Settings.setValue('EmerAPI_Server_adv_yum_l',ansistring(e.AsString));
try
e:=js.FindPath('network');
if e<>nil then begin
MainForm.queryForNetworkSettings(
strToInt('$'+e.FindPath('wif').AsString),
strToInt('$'+e.FindPath('adrsig').AsString),
e.FindPath('netstr').AsString
);
end;
except
end;
tsServerLoginPanelLabel.Caption:='';
bNext.Enabled:=true;
if assigned(MainPageControl.ActivePage.OnHide) then
MainPageControl.ActivePage.OnHide(bNext);
end else begin
e:=js.FindPath('url');
if e<>nil then begin
//URL received
tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.NotRegistered','Server has not recognized your address. You must login/sign in');
tsServerLoginBRecheck.Enabled:=true;
tsServerLoginBOpen.Enabled:=true;
tsServerLoginBLinkToBuffer.Enabled:=true;
fLastServerLoginLink:=e.AsString;
e:=js.FindPath('token');
if e<>nil then
fLastServerLoginLink:=fLastServerLoginLink+e.AsString;
end else begin
//Incorrect report
tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.UnknownResponse','Error: Unknown server response');
tsServerLoginBRecheck.Enabled:=true;
tsServerLoginBOpen.Enabled:=false;
tsServerLoginBLinkToBuffer.Enabled:=false;
end;
end;
end;
finally
if js<>nil then js.free;
end;
end;
end;
end;
procedure TMasterPasswordWizardForm.tsServerLoginPanelTryToConnect;
var ud:tpServerThreadUserData;
ss:tEmerApiServerSettings;
begin
tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.Connect','Trying to connect to the server ...');
if tsServerLoginAddress<>'' then begin
//EmerAPI.EmerAPIConnetor.connDataServer.address:=tsServerLoginAddress;
ss:=EmerAPI.EmerAPIConnetor.serverAPI.connData;
if ss.address<>tsServerLoginAddress then begin
ss.address:=tsServerLoginAddress;
EmerAPI.EmerAPIConnetor.serverAPI.connData:=ss;
end;
end;
// /user/bywallet
// query {
// userlogin(request: <salt 16 b><public_key compressed>) {
// response
// }
// }
try
emerAPI.EmerAPIConnetor.serverAPI.connectUsingPublicKey(@myQueryDone).Resume;
//fTasksList.AddObject(result.id,result);
//checkForReadyToStart;
except
tsServerLoginPanelLabel.Caption:=localizzzeString('MasterPasswordWizardForm.tsServerLoginPanelLabel.WrongPublicKey','Error: Wrong public key');
tsServerLoginBRecheck.Enabled:=true;
tsServerLoginBOpen.Enabled:=false;
tsServerLoginBLinkToBuffer.Enabled:=false;
exit;
end;
// getRandomChars();
tsServerLoginBRecheck.Enabled:=false;
tsServerLoginBOpen.Enabled:=false;
tsServerLoginBLinkToBuffer.Enabled:=false;
end;
procedure TMasterPasswordWizardForm.tsServerLoginShow(Sender: TObject);
begin
createGuidePage(tsServerLoginPanel);
setButtonsDefault;
bNext.Enabled:=false;
tsServerLoginPanelTryToConnect;
end;
procedure TMasterPasswordWizardForm.tsSetPassDoneContinueHide(Sender: TObject);
begin
if sender=bNext then begin
goNext(tsConnectServer);
end else
if sender=bPrev then begin
goBack;
end else
if sender=bFinish then begin
modalResult:=mrOk;
//close;
end else
if sender=bHelp then begin
end else begin
destroyGuidePage(tsSetPassDoneContinuePanel);
end;
end;
procedure TMasterPasswordWizardForm.tsSetPassDoneContinueShow(Sender: TObject);
begin
createGuidePage(tsSetPassDoneContinuePanel);
setButtonsDefault;
//bNext.Visible:=false;
//bFinish.Visible:=true;
tsSetPassDoneContinueCSetupServer.Checked:=true;
tsSetPassDoneContinueCSetupServerChange(nil);
end;
procedure TMasterPasswordWizardForm.tsSetPassDoneFinishHide(Sender: TObject);
begin
if sender=bNext then begin
end else
if sender=bPrev then begin
goBack;
end else
if sender=bFinish then begin
modalResult:=mrOk;
//close;
end else
if sender=bHelp then begin
end else begin
destroyGuidePage(tsSetPassDoneFinishPanel);
end;
end;
procedure TMasterPasswordWizardForm.tsSetPassDoneFinishShow(Sender: TObject);
begin
createGuidePage(tsSetPassDoneFinishPanel);
setButtonsDefault;
bNext.Visible:=false;
bFinish.Visible:=true;
end;
procedure TMasterPasswordWizardForm.tsSetUserPasschShowPasswordChange(
Sender: TObject);
begin
tsSetUserPassEdit2.Enabled:= not tsSetUserPasschShowPassword.Checked;
if not tsSetUserPassEdit2.Enabled then tsSetUserPassEdit2.Text:='';
tsSetUserPasslPassword2.Enabled:= not tsSetUserPasschShowPassword.Checked;
if tsSetUserPasschShowPassword.Checked
then tsSetUserPassEdit1.PasswordChar:=#0
else tsSetUserPassEdit1.PasswordChar:='*';
end;
procedure TMasterPasswordWizardForm.tsSetUserPassEdit1Change(Sender: TObject);
begin
tsSetUserPassTimer.Enabled:=false;
tsSetUserPassTimer.Enabled:=true;
tsSetUserPassEdit2Change(nil);
end;
procedure TMasterPasswordWizardForm.tsSetUserPassEdit2Change(Sender: TObject);
begin
bNext.Enabled:= (tsSetUserPassEdit2.Text=tsSetUserPassEdit1.Text) or tsSetUserPasschShowPassword.Checked;
if (tsSetUserPassEdit2.Text<>tsSetUserPassEdit1.Text) and (tsSetUserPassEdit2.Text<>'') and tsSetUserPassEdit2.enabled
then tsSetUserPassEdit2.Color:=clRed
else tsSetUserPassEdit2.Color:=clDefault;
end;
procedure TMasterPasswordWizardForm.tsSetUserPassHide(Sender: TObject);
var r:double;
begin
if sender=bNext then begin
//
if (not tsSetUserPasschShowPassword.Checked) and (tsSetUserPassEdit1.Text<>tsSetUserPassEdit2.text)
then begin
ShowInlineMessage('MasterPasswordWizardForm.PasswordsNotTheSame','The passwords you entered are not the same');
exit;
end;
r:=ratePassword(tsSetUserPassEdit1.Text);
if r<20 then begin
ShowInlineMessage('MessageInfoWeakUserPassword','Password you entered is too short. Move all assets to a stronger password');
if not Settings.getValue('Dev_Mode_ON') then exit;
end;
//set up the UP and save PrK
//Settings.PrivKey:=Encrypt_AES256(privKeyToCode58(MainForm.PrivKey, globals.WifID,true),tsSetUserPassEdit1.Text);
Settings.setValue('KEEP_PRIVATE_KEY',true);
Settings.PrivKey:=Encrypt_AES256(privKeyToCode58(MainForm.PrivKey, globals.WifID,true),tsSetUserPassEdit1.Text);
Settings.PubKey:=pubKeyToBuf(GetPublicKey(MainForm.PrivKey));
Settings.save();
MainForm.SetAndCheckBlockchain();
MainForm.showWalletInfo();
if wizardID='domp' then
goNext(tsSetPassDoneFinish)
else
if wizardID='doall' then
goNext(tsSetPassDoneContinue);
end else
if sender=bPrev then begin
goBack;
end else
if sender=bFinish then begin
end else
if sender=bHelp then begin
end else begin
//PassRate1.down();
//createPassword1.down();
destroyGuidePage(tsSetUserPassPanel);
end;
end;
procedure TMasterPasswordWizardForm.tsSetUserPassPanelCDoNotSaveChange(