Produced by Araxis Merge on 3/1/2017 4:26:06 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | v31A_T105_CIF.zip\OR_30_434V104_SRC\XE8\PKI\Source | oPKIServiceEngine.pas | Tue Sep 6 17:12:10 2016 UTC |
2 | v31A_T105_CIF.zip\OR_30_434V104_SRC\XE8\PKI\Source | oPKIServiceEngine.pas | Wed Mar 1 22:15:50 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 700 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | unit oPKIS erviceEngi ne; | |
2 | ||
3 | interface | |
4 | ||
5 | uses | |
6 | System.C lasses, | |
7 | System.S ysUtils, | |
8 | oPKIEncr yption, | |
9 | IdStack, | |
10 | IdContex t, | |
11 | IdTCPSer ver; | |
12 | ||
13 | type | |
14 | TPKIServ iceEngine = class(TI dTCPServer ) | |
15 | private | |
16 | fQuitS endsFinal2 20: boolea n; | |
17 | fOnPKI Encryption LogEvent: TPKIEncryp tionLogEve nt; | |
18 | fPKIEn cryptionEn gine: IPKI Encryption Engine; | |
19 | fBackw ardsCompat ibility: b oolean; | |
20 | ||
21 | functi on getIPAd dress: str ing; | |
22 | ||
23 | proced ure setBac kwardsComp atibility( const aVal ue: boolea n); | |
24 | proced ure setOnP KIEncrypti onLogEvent (const aOn PKIEncrypt ionLogEven t: TPKIEnc ryptionLog Event); | |
25 | proced ure fPKISe rviceEngin eNotify(co nst aMessa ge: string ); | |
26 | ||
27 | proced ure verify Buffer(aBu ffer: TStr ings); | |
28 | ||
29 | proced ure connec t(AContext : TIdConte xt); | |
30 | proced ure execut e(AContext : TIdConte xt); | |
31 | public | |
32 | constr uctor Crea te; | |
33 | destru ctor Destr oy; overri de; | |
34 | ||
35 | proced ure Start( aPort: Wor d); | |
36 | proced ure Stop; | |
37 | ||
38 | proper ty QuitSen dsFinal220 : boolean read fQuit SendsFinal 220 write fQuitSends Final220; | |
39 | proper ty OnPKISe rviceEngin eNotify: T PKIEncrypt ionLogEven t read fOn PKIEncrypt ionLogEven t write se tOnPKIEncr yptionLogE vent; | |
40 | proper ty ServerI PAdress: s tring read getIPAddr ess; | |
41 | proper ty Backwar dsCompatib ility: boo lean read fBackwards Compatibil ity write setBackwar dsCompatib ility; | |
42 | end; | |
43 | ||
44 | const | |
45 | PKI_BACK WARDS_COMP ATIBILITY_ FLAG = '-b c'; // Use d to start the serve r in Backw ards Comap tibility M ode | |
46 | ||
47 | PKI_SERVER _LISTENER_ PORT =
|
|
48 | ||
49 | implementa tion | |
50 | ||
51 | const | |
52 | CMD_LIST = '\HELO\ QUIT\SERV\ DATA\TURN\ NOOP\'; | |
53 | CMD_TIME OUT = (30 * 1000); / / 30 secon ds, 30000 millisecon ds | |
54 | ||
55 | { TPKISe rviceEngin e } | |
56 | ||
57 | constructo r TPKIServ iceEngine. Create; | |
58 | begin | |
59 | inherite d Create; | |
60 | OnConnec t := conne ct; | |
61 | OnExecut e := execu te; | |
62 | ||
63 | fQuitSen dsFinal220 := False; | |
64 | fBackwar dsCompatib ility := F alse; | |
65 | fOnPKIEn cryptionLo gEvent := fPKIServic eEngineNot ify; | |
66 | NewPKIEn cryptionEn gine(nil, fPKIEncryp tionEngine ); // Serv ice engine does not use the br oker at th is time. | |
67 | end; | |
68 | ||
69 | destructor TPKIServi ceEngine.D estroy; | |
70 | begin | |
71 | fOnPKIEn cryptionLo gEvent := nil; | |
72 | fPKIEncr yptionEngi ne := nil; | |
73 | inherite d; | |
74 | end; | |
75 | ||
76 | function T PKIService Engine.get IPAddress: string; | |
77 | begin | |
78 | Result : = GStack.L ocalAddres s; | |
79 | end; | |
80 | ||
81 | procedure TPKIServic eEngine.St art(aPort: Word); | |
82 | begin | |
83 | if not A ctive then | |
84 | try | |
85 | fOnP KIEncrypti onLogEvent ('Starting PKI Servi ce Engine. ..'); | |
86 | Defa ultPort := aPort; | |
87 | Acti ve := True ; | |
88 | ||
89 | if A ctive then | |
90 | be gin | |
91 | fOnPKIEncr yptionLogE vent('PKI Service En gine Start ed'); | |
92 | fOnPKIEncr yptionLogE vent('IP A ddress: ' + ServerIP Adress); | |
93 | fOnPKIEncr yptionLogE vent('Port Number: ' + IntToSt r(DefaultP ort)); | |
94 | en d | |
95 | else | |
96 | fO nPKIEncryp tionLogEve nt('PKI Se rvice Engi ne Failed to Start') ; | |
97 | except | |
98 | on E : Exceptio n do | |
99 | fO nPKIEncryp tionLogEve nt(E.Messa ge); | |
100 | end | |
101 | else | |
102 | fOnPKI Encryption LogEvent(' Service En gine alrea dy started '); | |
103 | end; | |
104 | ||
105 | procedure TPKIServic eEngine.St op; | |
106 | begin | |
107 | if Activ e then | |
108 | try | |
109 | fOnP KIEncrypti onLogEvent ('Stopping PKI Servi ce Engine. ..'); | |
110 | Acti ve := Fals e; | |
111 | if A ctive then | |
112 | ra ise Except ion.Create ('Service did NOT st op as expe cted'); | |
113 | fOnP KIEncrypti onLogEvent ('PKI Serv ice Engine Stopped') ; | |
114 | except | |
115 | on E : Exceptio n do | |
116 | fO nPKIEncryp tionLogEve nt(E.Messa ge); | |
117 | end | |
118 | else | |
119 | fOnPKI Encryption LogEvent(' Service En gine alrea dy stopped '); | |
120 | end; | |
121 | ||
122 | procedure TPKIServic eEngine.ve rifyBuffer (aBuffer: TStrings); // var aR esult: str ing); | |
123 | (* | |
124 | This met hod is the primary d river. If it complet es without an except ion being | |
125 | raised t hen the si gnature ha s been ver ified. Any issue fou nd or erro r discover ed | |
126 | will be returned t o the exec ute method inside of the DATA case eleme nt. This i s | |
127 | then cap tured and returned t o the clie nt that ha s called t he service . | |
128 | *) | |
129 | var | |
130 | aDataStr ing: strin g; | |
131 | aSignatu re: string ; | |
132 | aDateTim eSigned: s tring; | |
133 | aBlock: integer; | |
134 | aText: s tring; | |
135 | aPKIEncr yptionSign ature: IPK IEncryptio nSignature ; | |
136 | begin | |
137 | try | |
138 | fOnPKI Encryption LogEvent(' Entering v erifyBuffe r'); | |
139 | aDataS tring := ' '; | |
140 | aSigna ture := '' ; | |
141 | aDateT imeSigned := ''; | |
142 | aBlock := 0; | |
143 | ||
144 | // Unl oad the te xt from th e TCPIP ca ll and cre ate an IPK IEncryptio nSignature | |
145 | for aT ext in aBu ffer do | |
146 | if A nsiCompare Text(aText , '') = 0 then | |
147 | in c(aBlock) | |
148 | else | |
149 | ca se aBlock of | |
150 | 0: | |
151 | aDataStr ing := aDa taString + aText; | |
152 | 1: | |
153 | aSignatu re := aSig nature + a Text; | |
154 | 2: | |
155 | aDateTim eSigned := aDateTime Signed + a Text; | |
156 | el se | |
157 | raise EPKI Encryption Error.Crea te(DLG_898 02036 + 'I nvalid Buf fer Conten ts: Block Index@' + IntToStr(a Block)); | |
158 | en d; | |
159 | ||
160 | fOnPKI Encryption LogEvent(' DataString = ' + aDa taString); | |
161 | fOnPKI Encryption LogEvent(' Signature = ' + aSig nature); | |
162 | fOnPKI Encryption LogEvent(' DateTimeSi gned = ' + aDateTime Signed); | |
163 | ||
164 | if aDa taString = '89802050 ' then | |
165 | rais e EPKIEncr yptionErro r.CreateFm t( | |
166 | '% s %s@%s Ba ckwards Co mpatibilit y Mode =%s ', | |
167 | [D LG_8980205 0, ServerI PAdress, I ntToStr(De faultPort) , BoolToSt r(fBackwar dsCompatib ility, Tru e)]); // T his will s end the st atus back to the cli ent | |
168 | ||
169 | NewPKI Encryption Signature( aPKIEncryp tionSignat ure); | |
170 | aPKIEn cryptionSi gnature.Da taString : = aDataStr ing; | |
171 | aPKIEn cryptionSi gnature.Si gnature := aSignatur e; | |
172 | aPKIEn cryptionSi gnature.Da teTimeSign ed := aDat eTimeSigne d; | |
173 | ||
174 | // Sen d the sign ature off to the IPK IEncryptio nEngine fo r validati on | |
175 | fOnPKI Encryption LogEvent(' Sending th e signatur e off for verificati on'); | |
176 | fPKIEn cryptionEn gine.Valid ateSignatu re(aPKIEnc ryptionSig nature); | |
177 | except | |
178 | raise; | |
179 | end; | |
180 | end; | |
181 | ||
182 | procedure TPKIServic eEngine.co nnect(ACon text: TIdC ontext); | |
183 | begin | |
184 | with ACo ntext.Conn ection.IOH andler do | |
185 | try | |
186 | ACon text.Conne ction.IOHa ndler.Read Timeout := 30000; // CMD_TIMEO UT; | |
187 | fOnP KIEncrypti onLogEvent ('Sending Welcome'); | |
188 | ACon text.Conne ction.IOHa ndler.Writ eLn('230 W elcome to the PKI Ve rify Serve r'); | |
189 | ACon text.Conne ction.IOHa ndler.Writ eLn('230 S erver CRC: ' + '{CB2 F2B20-D003 -447A-94F0 -3ABC4932C B26}'); | |
190 | fOnP KIEncrypti onLogEvent ('Welcome Sent'); | |
191 | except | |
192 | on E : Exceptio n do | |
193 | fO nPKIEncryp tionLogEve nt('Error sending we lcome: ' + E.Message ); | |
194 | end; | |
195 | end; | |
196 | ||
197 | procedure TPKIServic eEngine.ex ecute(ACon text: TIdC ontext); | |
198 | var | |
199 | aMsg: st ring; | |
200 | aCmd: st ring; | |
201 | aTxt: st ring; | |
202 | aLen: in teger; | |
203 | aStatus: string; | |
204 | aBuffer: TStringLi st; | |
205 | i: integ er; | |
206 | x: strin g; | |
207 | begin | |
208 | aBuffer := TString List.Creat e; { Used as the dat a buffer } | |
209 | while AC ontext.Con nection.Co nnected do | |
210 | try | |
211 | aMsg := AConte xt.Connect ion.IOHand ler.ReadLn ; | |
212 | aCmd := '\' + UpperCase( Copy(aMsg, 1, 4)) + '\'; | |
213 | fOnP KIEncrypti onLogEvent (Format('% s executin g %s', [Se lf.ClassNa me, aMsg]) ); | |
214 | i := Pos(aCmd, CMD_LIST) ; | |
215 | case i of | |
216 | 1: // HELO | |
217 | begin | |
218 | AContext .Connectio n.IOHandle r.WriteLn( '220 Howdy -' + Copy( aMsg, 5, L ength(aMsg ))); | |
219 | end; | |
220 | 6: // QUIT | |
221 | try | |
222 | if fQuit SendsFinal 220 then | |
223 | begin | |
224 | fOnP KIEncrypti onLogEvent ('Sending final 220 Quit'); | |
225 | ACon text.Conne ction.IOHa ndler.Writ eLn('220 Q uit'); | |
226 | end | |
227 | else | |
228 | begin | |
229 | fOnP KIEncrypti onLogEvent ('Did NOT send final 220 Quit' ); | |
230 | end; | |
231 | AContext .Connectio n.Disconne ct; | |
232 | except | |
233 | on E: Ex ception do | |
234 | begin | |
235 | fOnP KIEncrypti onLogEvent ('Exceptio n raised i n command QUIT: ' + E.Message) ; | |
236 | rais e; | |
237 | end; | |
238 | end; | |
239 | 11 : // SERV | |
240 | begin | |
241 | // Not u sed | |
242 | end; | |
243 | 16 : // DATA | |
244 | try | |
245 | aBuffer. Clear; | |
246 | aLen := 0; | |
247 | while aL en >= 0 do | |
248 | begin | |
249 | aTxt := AConte xt.Connect ion.IOHand ler.ReadSt ring(3); | |
250 | aLen := StrToI ntDef(aTxt , 0); | |
251 | if a Txt = '000 ' then | |
252 | be gin | |
253 | aBuffer.Ad d(''); | |
254 | fOnPKIEncr yptionLogE vent(Forma t('%s', [a Txt])); | |
255 | en d | |
256 | else if aLen > 0 then | |
257 | be gin | |
258 | aTxt := AC ontext.Con nection.IO Handler.Re adString(a Len); | |
259 | aBuffer.Ad d(aTxt); | |
260 | fOnPKIEncr yptionLogE vent(Forma t('%.3d%s' , [aLen, a Txt])); | |
261 | en d; | |
262 | end; | |
263 | verifyBu ffer(aBuff er); // aS tatus will be sent b ack on the next TURN | |
264 | aStatus := 'OK'; / / If no ex ceptions i n the veri fyBuffer m ethod then it's all OK | |
265 | AContext .Connectio n.IOHandle r.WriteLn( '220 Data' ); | |
266 | except | |
267 | on E: EP KIEncrypti onError do | |
268 | begin // if we a re here we need to c apture the exception for the T URN comman d | |
269 | fOnP KIEncrypti onLogEvent ('EPKIEncr yptionErro r raised i n command DATA: ' + E.Message) ; | |
270 | aSta tus := E.M essage; // '-1^'+E.M essage; // The excep tion is ca ught here and readie d for the TURN | |
271 | if f BackwardsC ompatibili ty then | |
272 | aS tatus := ' -1^' + aSt atus; | |
273 | ACon text.Conne ction.IOHa ndler.Writ eLn('220 D ata'); // We have to let the c lient turn | |
274 | end; | |
275 | on E: Ex ception do | |
276 | raise; // if we are here, something really bad happened and we nee d to just close out | |
277 | end; | |
278 | 21 : { TURN } | |
279 | try | |
280 | AContext .Connectio n.IOHandle r.WriteLn( '220 TURN' ); | |
281 | AContext .Connectio n.IOHandle r.WriteLn( 'DATA '); | |
282 | // This next one i s the Leng thOfaStatu s+aStatus+ -10 | |
283 | AContext .Connectio n.IOHandle r.WriteLn( Format('%. 3d%s-10', [Length(aS tatus), aS tatus])); | |
284 | x := ACo ntext.Conn ection.IOH andler.Rea dLn; | |
285 | fOnPKIEn cryptionLo gEvent('Do ne in TURN , client s ays: ' + x ); | |
286 | except | |
287 | on E: Ex ception do | |
288 | begin | |
289 | fOnP KIEncrypti onLogEvent ('Exceptio n raised i n command TURN: ' + E.Message) ; | |
290 | rais e; | |
291 | end; | |
292 | end; | |
293 | 26 : { NOOP } | |
294 | try | |
295 | AContext .Connectio n.IOHandle r.WriteLn( '220 NOOP' ); | |
296 | except | |
297 | on E: Ex ception do | |
298 | begin | |
299 | fOnP KIEncrypti onLogEvent ('Exceptio n raised i n command NOOP: ' + E.Message) ; | |
300 | rais e; | |
301 | end; | |
302 | end; | |
303 | else | |
304 | tr y | |
305 | fOnPKIEncr yptionLogE vent('Unkn own comman d NOOP: ' + aMsg); | |
306 | AContext.C onnection. IOHandler. WriteLn('4 40 Unknown command " ' + aMsg + '"'); | |
307 | ex cept | |
308 | on E: Exce ption do | |
309 | begin | |
310 | fOnPKI Encryption LogEvent(' Exception raised wit h unknown command ' + aMsg + ' : ' + E.Me ssage); | |
311 | raise; | |
312 | end; | |
313 | en d; | |
314 | end; | |
315 | fOnP KIEncrypti onLogEvent ('Execute ' + aMsg + ' done, c onnection state acti ve: ' + Bo olToStr(AC ontext.Con nection.Co nnected, T rue)); | |
316 | except | |
317 | on E xception d o | |
318 | be gin // Thi s is when something bad happen ed. Let's disconnect and wait for the ne xt client. | |
319 | FreeAndNil (aBuffer); | |
320 | AContext.C onnection. Disconnect ; | |
321 | en d | |
322 | end; | |
323 | fOnPKIEn cryptionLo gEvent('Co nnection C losed'); | |
324 | end; | |
325 | ||
326 | procedure TPKIServic eEngine.se tBackwards Compatibil ity(const aValue: bo olean); | |
327 | begin | |
328 | fBackwar dsCompatib ility := a Value; | |
329 | fOnPKIEn cryptionLo gEvent('Ba ckwards Co mpatibilit y Error Mo de set to ' + BoolTo Str(aValue , True)); | |
330 | end; | |
331 | ||
332 | procedure TPKIServic eEngine.se tOnPKIEncr yptionLogE vent(const aOnPKIEnc ryptionLog Event: TPK IEncryptio nLogEvent) ; | |
333 | begin | |
334 | if Assig ned(aOnPKI Encryption LogEvent) then | |
335 | begin | |
336 | fOnP KIEncrypti onLogEvent := aOnPKI Encryption LogEvent; | |
337 | fPKI Encryption Engine.OnL ogEvent := aOnPKIEnc ryptionLog Event; | |
338 | end | |
339 | else | |
340 | begin | |
341 | fOnP KIEncrypti onLogEvent := fPKISe rviceEngin eNotify; | |
342 | fPKI Encryption Engine.OnL ogEvent := fPKIServi ceEngineNo tify; | |
343 | end; | |
344 | end; | |
345 | ||
346 | procedure TPKIServic eEngine.fP KIServiceE ngineNotif y(const aM essage: st ring); | |
347 | begin | |
348 | { This i s here to prevent ni l pointers in the ev ent that n o logging mechanism is attache d } | |
349 | end; | |
350 | ||
351 | end. |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.