Constructor

tCryptography.Create

Module

XuDsigS

Last Modified

7/15/2014 3:26:44 PM

Comments

This will create and init the cryptography object

Visibility

Public

Owner

tCryptography

Declaration

constructor Create;

Calls Hierarchy


tCryptography.Create
 ├tCryptography.Reset
 ├sCardReady
 │ ├SCardEstablishContext
 │ ├SCardListReadersA
 │ └SCardConnectA
 ├tCryptography.RaiseErr
 ├CryptAcquireContext
 └CryptGetProvParam

Called-By Hierarchy


                                              tCryptography.Create
                                                          SetSAN┤ 
                           TfrmFrame.DigitalSigningSetup1Click┤ │ 
                                             ExecuteSignOrders┤ │ 
                                  TfrmOrders.mnuActSignClick┘ │ │ 
                                         TfrmReview.cmdOKClick┘ │ 
                                               ReviewChanges┘   │ 
                           TfrmFrame.AllowContextChangeAll┤     │ 
                                TfrmFrame.FormCloseQuery┤ │     │ 
                              TfrmFrame.mnuFileNextClick┤ │     │ 
                            TfrmFrame.mnuFileOpenClick┤ │ │     │ 
                                TfrmFrame.UMInitiate┤ │ │ │     │ 
                       TfrmFrame.mnuFileNextClick...┤ │ │ │     │ 
                       TfrmFrame.mnuFileRefreshClick┤ │ │ │     │ 
                       TfrmOrders.CheckOrderStatus┤ │ │ │ │     │ 
                   TfrmOrders.mnuActChgEvntClick┤ │ │ │ │ │     │ 
                      TfrmOrders.mnuActHoldClick┤ │ │ │ │ │     │ 
                    TfrmOrders.mnuActUnholdClick┤ │ │ │ │ │     │ 
                     TfrmOrders.mnuActRenewClick┤ │ │ │ │ │     │ 
                    TfrmOrders.mnuActChangeClick┤ │ │ │ │ │     │ 
                      TfrmOrders.mnuActCopyClick┘ │ │ │ │ │     │ 
                            TfrmMeds.mnuActDCClick┤ │ │ │ │     │ 
                           TfrmMeds.CheckMedStatus┘ │ │ │ │     │ 
                        TfrmMeds.mnuActHoldClick┤   │ │ │ │     │ 
                       TfrmMeds.mnuActRenewClick┤   │ │ │ │     │ 
                      TfrmMeds.mnuActUnholdClick┤   │ │ │ │     │ 
                      TfrmMeds.mnuActChangeClick┤   │ │ │ │     │ 
                        TfrmMeds.mnuActCopyClick┤   │ │ │ │     │ 
                      TfrmMeds.mnuActRefillClick┘   │ │ │ │     │ 
                                  TfrmFrame.ViewInfo┘ │ │ │     │ 
                               TfrmDCSumm.ViewInfo┤   │ │ │     │ 
                             TfrmConsults.ViewInfo┤   │ │ │     │ 
                     TfrmFrame.pnlRemindersMouseUp┤   │ │ │     │ 
                      TfrmFrame.RemindersChanged┘ │   │ │ │     │ 
                          TfrmFrame.FormCreate┘   │   │ │ │     │ 
                            TfrmFrame.pnlCIRNClick┤   │ │ │     │ 
                      TfrmFrame.pnlVistaWebClick┤ │   │ │ │     │ 
                           TfrmFrame.FormKeyDown┘ │   │ │ │     │ 
                         TfrmFrame.pnlPatientClick┤   │ │ │     │ 
                           TfrmFrame.pnlVisitClick┤   │ │ │     │ 
                     TfrmFrame.pnlPrimaryCareClick┤   │ │ │     │ 
                       TfrmFrame.pnlRemindersClick┤   │ │ │     │ 
                        TfrmFrame.pnlPostingsClick┤   │ │ │     │ 
                            TfrmFrame.pnlFlagClick┤   │ │ │     │ 
                              TfrmFrame.laMHVClick┤   │ │ │     │ 
                             TfrmFrame.laVAA2Click┤   │ │ │     │ 
                               TfrmOrders.ViewInfo┤   │ │ │     │ 
                                 TfrmMeds.ViewInfo┤   │ │ │     │ 
                              TfrmSurgery.ViewInfo┤   │ │ │     │ 
                                TfrmNotes.ViewInfo┤   │ │ │     │ 
                             TfrmProblems.ViewInfo┘   │ │ │     │ 
                     TfrmFrame.mnuFileNotifRemoveClick┤ │ │     │ 
                             TfrmFrame.NextButtonClick┘ │ │     │ 
                           TfrmFrame.SetUpNextButton┘   │ │     │ 
                     TfrmFrame.mnuFileOpenClick...┤     │ │     │ 
                              TfrmFrame.FormResize┘     │ │     │ 
                            TfrmFrame.ChangeFont┘       │ │     │ 
                    TfrmFrame.LoadSizesForUser┤         │ │     │ 
               TfrmFrame.LoadUserPreferences┘ │         │ │     │ 
                      TfrmFrame.UMInitiate┘   │         │ │     │ 
                    TfrmFrame.mnuFontSizeClick┘         │ │     │ 
                           TfrmFrame.mnuFileOpenClick...┤ │     │ 
                           TfrmFrame.ctxContextorPending┤ │     │ 
                          TfrmFrame.StartCCOWContextor┘ │ │     │ 
                                TfrmFrame.FormCreate┘   │ │     │ 
                         TfrmFrame.ctxContextorCommitted┤ │     │ 
                       TfrmFrame.StartCCOWContextor...┘ │ │     │ 
                  TfrmFrame.mnuFileResumeContextGetClick┤ │     │ 
                  TfrmFrame.mnuFileResumeContextSetClick┘ │     │ 
                                  TfrmFrame.FormCloseQuery┤     │ 
                              TfrmFrame.mnuFileReviewClick┤     │ 
                                           UpdateEncounter┘     │ 
                         TfrmFrame.mnuFileEncounterClick┤       │ 
                                 TfrmFrame.ViewInfo...┤ │       │ 
                    TfrmODMedIV.SetValuesFromResponses┤ │       │ 
                             TfrmODMedIV.SetupDialog┤ │ │       │ 
                   TfrmODMedIV.cboSolutionMouseClick┘ │ │       │ 
                       TfrmODMedIV.cboSolutionExit┘   │ │       │ 
                  TfrmODMedIV.cboSolutionMouseClick...┤ │       │ 
                     TfrmODMedIV.cboAdditiveMouseClick┤ │       │ 
                         TfrmODMedIV.cboAdditiveExit┘ │ │       │ 
                                TfrmODAuto.SetupDialog┤ │       │ 
                                   ActivateOrderDialog┤ │       │ 
                           TfrmRemDlg.btnFinishClick┤ │ │       │ 
           TfrmConsults.mnuActNewConsultRequestClick┤ │ │       │ 
                   TfrmConsults.cmdNewConsultClick┘ │ │ │       │ 
                TfrmConsults.mnuActNewProcedureClick┤ │ │       │ 
                      TfrmConsults.cmdNewProcClick┘ │ │ │       │ 
                                        ChangeOrders┤ │ │       │ 
                      TfrmOrders.mnuActChangeClick┤ │ │ │       │ 
                        TfrmMeds.mnuActChangeClick┘ │ │ │       │ 
                                     ChangeOrdersEvt┤ │ │       │ 
                                          CopyOrders┤ │ │       │ 
                        TfrmOrders.mnuActCopyClick┤ │ │ │       │ 
                          TfrmMeds.mnuActCopyClick┤ │ │ │       │ 
                           TfrmODActive.btnOKClick┘ │ │ │       │ 
                                      TransferOrders┤ │ │       │ 
                        TfrmOrders.mnuActCopyClick┤ │ │ │       │ 
                          TfrmMeds.mnuActCopyClick┤ │ │ │       │ 
                           TfrmODActive.btnOKClick┘ │ │ │       │ 
                            TfrmOrders.lstWriteClick┤ │ │       │ 
               TfrmOrders.PlaceOrderForDefaultDialog┤ │ │       │ 
                  TfrmOrders.DisplayDefaultDlgList┤ │ │ │       │ 
                       TfrmOrders.ResetOrderPage┘ │ │ │ │       │ 
               TfrmOrders.btnDelayedOrderClick┘   │ │ │ │       │ 
                                 DisplayEvntDialog┤ │ │ │       │ 
                             SetDelayEventForMed┘ │ │ │ │       │ 
                      TfrmMeds.mnuActCopyClick┘   │ │ │ │       │ 
                                 DisplayEvntDialog┤ │ │ │       │ 
                                  SetViewForCopy┘ │ │ │ │       │ 
                    TfrmOrders.mnuActCopyClick┘   │ │ │ │       │ 
                                 DisplayEvntDialog┘ │ │ │       │ 
                                ExecuteChangeEvt┘   │ │ │       │ 
                 TfrmOrders.mnuActChgEvntClick┘     │ │ │       │ 
                             TfrmMeds.mnuActNewClick┤ │ │       │ 
                           TfrmOMNavA.ActivateDialog┤ │ │       │ 
                         TfrmOMNavA.grdMenuKeyDown┤ │ │ │       │ 
                         TfrmOMNavA.grdMenuMouseUp┘ │ │ │       │ 
                                TfrmOMSet.DoNextItem┘ │ │       │ 
                              TfrmOMSet.InsertList┤   │ │       │ 
                               ActivateOrderList┘ │   │ │       │ 
                     TfrmRemDlg.btnFinishClick┤   │   │ │       │ 
                             ActivateOrderHTML┤   │   │ │       │ 
                    TfrmOrders.lstWriteClick┤ │   │   │ │       │ 
    TfrmOrders.PlaceOrderForDefaultDialog...┘ │   │   │ │       │ 
                              ActivateOrderSet┤   │   │ │       │ 
                   TfrmRemDlg.btnFinishClick┤ │   │   │ │       │ 
TfrmConsults.mnuActNewConsultRequestClick...┤ │   │   │ │       │ 
     TfrmConsults.mnuActNewProcedureClick...┤ │   │   │ │       │ 
                    TfrmOrders.lstWriteClick┤ │   │   │ │       │ 
    TfrmOrders.PlaceOrderForDefaultDialog...┤ │   │   │ │       │ 
                     TfrmMeds.mnuActNewClick┤ │   │   │ │       │ 
                TfrmOMNavA.ActivateDialog...┤ │   │   │ │       │ 
                     TfrmOMSet.DoNextItem...┘ │   │   │ │       │ 
                       TfrmOMNavA.DoSelectList┘   │   │ │       │ 
                     TfrmOMNavA.grdMenuKeyUp┤     │   │ │       │ 
                   TfrmOMNavA.grdMenuMouseUp┘     │   │ │       │ 
                                        SkipToNext┤   │ │       │ 
                         TfrmOMSet.DoNextItem...┘ │   │ │       │ 
                            TfrmOMSet.UMDelayEvent┘   │ │       │ 
                               TfrmOMSet.InsertList...┤ │       │ 
                                TfrmODMeds.SetupDialog┤ │       │ 
                             TfrmODMeds.btnSelectClick┤ │       │ 
                             TfrmODMeds.UMDelayClick┘ │ │       │ 
                                    ExecuteRenewOrders┘ │       │ 
                         TfrmOrders.mnuActRenewClick┤   │       │ 
                           TfrmMeds.mnuActRenewClick┘   │       │ 
                                        EncounterPresent┤       │ 
                                      ReadyForNewOrder┤ │       │ 
                           TfrmRemDlg.btnFinishClick┤ │ │       │ 
        TfrmConsults.mnuActNewConsultRequestClick...┤ │ │       │ 
             TfrmConsults.mnuActNewProcedureClick...┤ │ │       │ 
                                     ChangeOrders...┤ │ │       │ 
                                     ChangeOrdersEvt┤ │ │       │ 
                                       CopyOrders...┤ │ │       │ 
                                   TransferOrders...┤ │ │       │ 
                            TfrmOrders.lstWriteClick┤ │ │       │ 
                             TfrmMeds.mnuActNewClick┘ │ │       │ 
                                     ReadyForNewOrder1┤ │       │ 
            TfrmOrders.PlaceOrderForDefaultDialog...┘ │ │       │ 
                              TfrmOrders.mnuActDCClick┤ │       │ 
                             TfrmOrders.mnuActRelClick┤ │       │ 
                            TfrmOrders.mnuActHoldClick┤ │       │ 
                          TfrmOrders.mnuActUnholdClick┤ │       │ 
                           TfrmOrders.mnuActRenewClick┤ │       │ 
                         TfrmOrders.mnuActReleaseClick┤ │       │ 
                         TfrmOrders.mnuActOnChartClick┤ │       │ 
                            TfrmOrders.mnuActSignClick┤ │       │ 
                                TfrmMeds.mnuActDCClick┤ │       │ 
                              TfrmMeds.mnuActHoldClick┤ │       │ 
                             TfrmMeds.mnuActRenewClick┤ │       │ 
                            TfrmMeds.mnuActUnholdClick┤ │       │ 
                              TfrmMeds.mnuActCopyClick┤ │       │ 
                            TfrmMeds.mnuActRefillClick┘ │       │ 
                                     EncounterPresentEDO┤       │ 
                                   ReadyForNewOrder...┤ │       │ 
                         TfrmOrders.mnuActChgEvntClick┤ │       │ 
                          TfrmOrders.mnuActChangeClick┤ │       │ 
                            TfrmOrders.mnuActCopyClick┤ │       │ 
                       TfrmOrders.btnDelayedOrderClick┤ │       │ 
                            TfrmMeds.mnuActChangeClick┤ │       │ 
                              TfrmMeds.mnuActCopyClick┘ │       │ 
                                             UpdateVisit┤       │ 
                                           EditPCEData┤ │       │ 
                             TfrmSurgery.cmdPCEClick┤ │ │       │ 
                                 UpdateEncounterInfo┘ │ │       │ 
                             TfrmNotes.cmdPCEClick┘   │ │       │ 
                        TfrmVitals.btnEnterVitalsClick┘ │       │ 
                                             UpdateVisit┤       │ 
                                        EncounterPresent┘       │ 
                         TfrmProblems.lstProbActsClick┘         │ 
                     TfrmProblems.wgProbDataDblClick┤           │ 
                           TfrmProblems.lstViewClick┘           │ 
                   TfrmProblems.HighlightDuplicate┘             │ 
                         TfrmProblems.AddProblem┤               │ 
              TfrmProblems.lstProbActsClick...┤ │               │ 
                 TfrmProblems.lstProbPickClick┤ │               │ 
              TfrmProblems.lstProbPickDblClick┤ │               │ 
              TfrmProblems.edProbEntKeyPress┘ │ │               │ 
                      TfrmProblems.UMPLLexicon┘ │               │ 
                   TfrmdlgProb.bbChangeProbClick┘               │ 
                                            ExecuteSignOrders...┤ 
                                        TfrmReview.cmdOKClick...┘ 

Calls

Name Declaration Comments
CryptAcquireContext function CryptAcquireContext(phProv :PHCRYPTPROV; pszContainer :LPAWSTR; pszProvider :LPAWSTR; dwProvType :DWORD; dwFlags :DWORD) :BOOL;stdcall; -
CryptGetProvParam function CryptGetProvParam(hProv :HCRYPTPROV; dwParam :DWORD; pbData :PBYTE; pdwDataLen :PDWORD; dwFlags :DWORD) :BOOL;stdcall; -
tCryptography.RaiseErr procedure RaiseErr(msg: string); -
tCryptography.Reset procedure Reset; -
sCardReady function sCardReady: boolean; -

Called-By

Name Declaration Comments
TfrmReview.cmdOKClick procedure cmdOKClick(Sender: TObject); -
ExecuteSignOrders {Forward} function ExecuteSignOrders(SelectedList: TList): Boolean; -
SetSAN function SetSAN(Self: TComponent): string; -


Source

201   constructor tCryptography.Create;
202   var
203     buff: array [0..1023] of char;
204     provider, Container: string;
205     size: dWord;
206     LastErr: DWORD;
207     value: Boolean;
208     Str: String;
209   begin
210     inherited Create;
211     Comment := '';
212     hProv := 0;      //See that global variables are inited
213     hHash := 0;
214     hPassKey := 0;
215     hUserKey := 0;
216     hCertStore := 0;
217     CSProviderName := c_SignPROV_NAME; //The Signing Provider  // 120206
218     ContainerName := '';         //Will use the default        // 120206
219     Reason := '';
220     subReason := '';
221     fCryptVer := '0.0';
222     CHashLen := 0;
223     CSigLen := 0;
224     Reset;
225     CBlobLen := 0;
226     fDataBuffer := '';
227     fSignatureStr := '';
228     fDatesigned := '';
229     //
230     Trackingmsg := TstringList.Create;
231     if not sCardReady then
232     begin
233       ShowMessage('Put a smart card in the Reader, then Press OK');
234       sleep(5000);
235       if not sCardReady then
236       begin
237         lastErr := GetLastError;
238         Str := IntToStr(lastErr)+' - '+SysErrorMessage(lastErr);
239         TrackingMsg.Add('89802006^Smart Card Reader not found - '+Str);
240         RaiseErr('89802006^Smart Card Reader not found');
241         exit;
242       end;
243     end;
244     //Find out what CSP to use.
245     //For Verification use the MS enhanced AES version.
246      provider := CSProviderName;
247      Container := '';  //Use the default container 'MY'
248   
249      //We only want to create a default container if
250      //we are NOT using a SmartCard
251      // Create a cryptography object with default
252      // container and slected provider.
253      Comment := Comment + 'Going to CryptAcquireContext'+#10#13;
254      value := CryptAcquireContext( @hProv,
255                              pchar(Container),
256                              pchar(''),
257                              PROV_RSA_AES,  // was PROV_RSA_FULL,   //rwf
258                              0);
259      if value then
260      begin
261        Comment := '01 CryptAcquireContext true hProv = '+IntToStr(hProv);
262        TrackingMsg.Add(Comment);
263        Comment := Comment + 'Back from CryptAcquireContext value true'+#10#13
264      end
265      else
266      begin
267        lastErr := GetLastError;
268        Str := IntToStr(lastErr)+' - '+SysErrorMessage(lastErr);
269        Comment := '01 CryptAcquireContext false lastErr: '+Str;
270        TrackingMsg.Add(Comment);
271        Comment := Comment + 'Back from CryptAcquireContext value false Error: '+Str+#10#13;
272      end;
273   
274      if value = false then
275      begin
276        lastErr := GetLastError;
277        Str := IntToStr(lastErr)+' - '+SysErrorMessage(lastErr);
278        TrackingMsg.Add('CryptAcquireContext failed - '+Str);
279        // Unable to aquire context, check if failure was due to
280        // absence of key container.
281        value := CryptAcquireContext( @hProv,
282                     pchar(Container),
283                     pchar(''),
284                     PROV_RSA_AES,  // was PROV_RSA_FULL,  rwf
285                     CRYPT_NEWKEYSET);
286        if value = false then
287        begin
288          lastErr := GetLastError;
289          Str := IntToStr(lastErr)+' - '+SysErrorMessage(lastErr);
290          TrackingMsg.Add('CryptAcquireContext with new keyset false - '+Str);
291          RaiseErr( 'Unable to aquire context');
292          exit;
293        end
294        else
295        begin
296          TrackingMsg.Add('CryptAcquireContext with new keyset');
297        end;
298     end;
299     if value then
300     begin
301       Comment := '01 CryptAcquireContext true'+#10#13;
302     end;
303     if value = false then
304     begin
305       lastErr := GetLastError;
306       Str := IntToStr(lastErr)+' - '+SysErrorMessage(lastErr);
307       TrackingMsg.Add('01 CryptAcquireContext false - '+Str);
308       RaiseErr(Str);
309       exit;
310     end;
311     // Get some info about the cryptography module.
312     // Name of the CSP.
313     Comment := Comment + '02 hProv = '+IntToStr(hProv)+#10#13;
314     size := sizeof(buff);
315     if CryptGetProvParam(hProv, PP_NAME, @Buff, @size, 0) = false then
316       fCSProviderName := 'Unknown'
317     else
318       fCSProviderName := StrPas(Buff);
319     Comment := Comment + '03 fCSProviderName = '+fCSProviderName+#10#13;
320   
321     // Name of the key container.
322     size := sizeof(buff);
323     if CryptGetProvParam(hProv, PP_CONTAINER, @Buff, @size, 0) = false then
324       fContainerName := 'Unknown'
325     else
326       fContainerName := StrPas(Buff);
327     Comment := Comment + '04 ContainerName = '+fContainerName+#10#13;
328   
329     // Version number
330     size := sizeof(buff);
331     if CryptGetProvParam(hProv, PP_VERSION, @Buff, @size, 0) = false then
332       fCryptVer := '*.00'
333     else
334       fCryptVer := format('%d.%d', [integer(buff[1]), integer(buff[0])]);
335     Comment := Comment + '05 fCryptVer = '+fCryptVer+#10#13;
336   end;