Class

tCryptography

Module

XuDsigS

Last Modified

7/15/2014 3:26:44 PM

Scope

Interfaced

Inherits from

TObject

Declaration


  tCryptography = class(TObject)
  private
    //Basic Crypto data
    hProv: HCRYPTPROV; // provider handle
    hPassKey: HCRYPTKEY; // Handle to password (key)
    hHash: HCRYPTHASH; //Hash handle
    HCERTSTORE{, hCRLStore}: HCERTSTORE;  //Certificate store handle
    hUserKey: HCRYPTKEY;  //Handle to the users Sig key
    //Cert. Store Data
    hMsg: HCRYPTMSG;
    pCertContext: PCCERT_CONTEXT;  //Cert Context
    //Flag to mark if valid date
    MasterDateValid: boolean;
    //Flag to mark if Cert has valid Chain
    MasterCertChain: boolean;
    fCSProviderName, fContainerName, fCryptVer: string; // Misc. info
    fHashStr: string;  //hash value in Hex
    fHexHash: string;  //hash value in Hex
    fHashAlogrithm: string;  //Alogrithm used
    fSignatureStr: string;  //This is returned signature
    fDataBuffer: string;  //This is the data to sign as one big string
    fDeaNumber: string;  //This is the users DEA number of file with VA.
    fUsrName: string;    //The User Name on the Cert.
    fUsrAltName: string; // The User's Alt Name (i.e., e-mail address)
    fDateSigned:  string;  //FM datetime
    SignMsgParam: CRYPT_SIGN_MESSAGE_PARA;
    fHashValue: Array of byte;
    fIssuanceDate: String;
    fPatientName: String;
    fPatientAddress: String;
    fDrugName: String;
    fQuantity: String;
    fDirections: String;
    fDetoxNumber: String;
    fProviderName: String;
    fProviderAddress: String;
    fhSC: SCARDCONTEXT;
    fhCard: LongInt;
    fisCardReset: Boolean;
    fOrderNumber: String;
    fVistaUserName: String;

    fIgnoreDates: Boolean;  // DEBUG ONLY
    fIgnoreRevoked: Boolean;  // DEBUG ONLY
    fIgnoreMasterChain: Boolean;  // DEBUG ONLY

    procedure RaiseErr(msg: string);
    function FindCert: boolean;
    function DataReady: boolean;
    procedure Certsigndata;
    function CertChainCheck(pCertContext: PCCERT_CONTEXT): boolean;
    function CRLDistPoint(pbData: pointer; cbData: integer): string;
    function CheckSig(pBlob: pointer; Blobsize: DWORD): boolean;
    function SigningCert(pCertCtx: PCCERT_CONTEXT): Integer;
//    procedure SaveLog; hint fix
  public
    //These fields hold the data from the Crypto functions
    //that we want to pass back to the caller
    isDEAsig: boolean;  //Are we doing a DEA signature
    //These fields hold the raw data from the Crypto functions
    CHashValue: Array of byte;
    CKeyBlob, CSignature: Array[0..2024] of byte;
    CHashLen, CBlobLen, CSigLen: integer;  //The length
    KeyBloB64, SignatureB64: string;
    CertName, CertSerialNum: string; //pass back data
    SigningStatus: boolean;  //This will hold the overall status.
    Reason, SubReason: string;  //This will hold text for the caller about status.
    //The drug's schedule
    DrugSch: string;
    //A URL for the CRL from the cert.
    CrlUrl: string;
    HashB64: string;
    Certstr: string; //pass back data
    ErrCode, ReturnStr: string;  //
    Comment: String;
    LastErr: LongInt;
    TrackingMsg: Tstringlist;
    constructor Create;
    destructor Destroy; override;
    //Info about the Crypto provider
    property ContainerName: string read fContainerName write fContainerName;
    property CSProviderName: string read fCSProviderName write fCSProviderName;
    property CryptVer: string read fCryptVer;
    //Return Data
    property SignatureStr: string read fSignatureStr write fSignatureStr;
    property HashAlgorithm: string read fHashAlogrithm;
    property DTSigned: string read fDateSigned write fDateSigned;
    property HexHash: string read fHexHash;
    property HashStr: string read fHashStr;
    //Normal procedures and functions
    procedure Reset;
    //This is where the data to sign is loaded.
    property DataBuffer: string read fDataBuffer write fDataBuffer;
    property DeaNumber: string read fDeaNumber write fDeaNumber;
    property UsrName: string read fUsrName write fUsrName;
    property UsrAltName: string read fUsrAltName write fUsrAltName;
    property IssuanceDate: string read fIssuanceDate write fIssuanceDate;
    property PatientName: string read fPatientName write fPatientName;
    property PatientAddress: string read fPatientAddress write fPatientAddress;
    property DrugName: string read fDrugName write fDrugName;
    property Quantity: string read fQuantity write fQuantity;
    property Directions: string read fDirections write fDirections;
    property DetoxNumber: string read fDetoxNumber write fDetoxNumber;
    property OrderNumber: string read fOrderNumber write fOrderNumber;
    property ProviderName: string read fProviderName write fProviderName;
    property ProviderAddress: string read fProviderAddress write fProviderAddress;
    property isCardReset: Boolean read fisCardReset;
    property ignoreDates: Boolean read fIgnoreDates write fIgnoredates;  // DEBUG ONLY
    property ignoreRevoked: Boolean read fIgnoreRevoked write fIgnoreRevoked; // DEBUG ONLY
    property ignoreMasterChain: Boolean read fIgnoreMasterChain write fIgnoreMasterChain; // DEBUG ONLY
    property VistaUserName: String read fVistaUserName write fVistaUserName; // 121213 user's name from VistA
    procedure Hashbuffer;
    procedure HashStart;
    procedure HashBuf(pB: pByte; cnt: integer);
    function GetHashValue: String;
    procedure HashEnd;
    function  SignData: boolean;
    procedure sCardReset;
    procedure sCardReattach;
    procedure Release;
end;

Class Hierarchy


TObject
 └tCryptography

Class Fields

Name Type Scope Comments
CBlobLen Integer Public The length
CertName UnicodeString Public Pass back data
CertSerialNum UnicodeString Public Pass back data
Certstr UnicodeString Public Pass back data
CHashLen Integer Public The length
CHashValue Array (dynamic) Public These fields hold the raw data from the Crypto functions
CKeyBlob Array (static) Public -
Comment UnicodeString Public -
CrlUrl UnicodeString Public A URL for the CRL from the cert.
CSigLen Integer Public The length
CSignature Array (static) Public -
DrugSch UnicodeString Public The drug's schedule
ErrCode UnicodeString Public -
fContainerName UnicodeString Private Misc. info
fCryptVer UnicodeString Private Misc. info
fCSProviderName UnicodeString Private Misc. info
fDataBuffer UnicodeString Private This is the data to sign as one big string
fDateSigned UnicodeString Private FM datetime
fDeaNumber UnicodeString Private This is the users DEA number of file with VA.
fDetoxNumber UnicodeString Private -
fDirections UnicodeString Private -
fDrugName UnicodeString Private -
fHashAlogrithm UnicodeString Private Alogrithm used
fHashStr UnicodeString Private Hash value in Hex
fHashValue Array (dynamic) Private -
fhCard LongInt Private -
fHexHash UnicodeString Private Hash value in Hex
fhSC Private -
fIgnoreDates Boolean Private DEBUG ONLY
fIgnoreMasterChain Boolean Private DEBUG ONLY
fIgnoreRevoked Boolean Private DEBUG ONLY
fisCardReset Boolean Private -
fIssuanceDate UnicodeString Private -
fOrderNumber UnicodeString Private -
fPatientAddress UnicodeString Private -
fPatientName UnicodeString Private -
fProviderAddress UnicodeString Private -
fProviderName UnicodeString Private -
fQuantity UnicodeString Private -
fSignatureStr UnicodeString Private This is returned signature
fUsrAltName UnicodeString Private The User's Alt Name (i.e., e-mail address)
fUsrName UnicodeString Private The User Name on the Cert.
fVistaUserName UnicodeString Private -
HashB64 UnicodeString Public -
hCertStore Private , hCRLStore}: HCERTSTORE; //Certificate store handle
hHash Private Hash handle
hMsg Private Cert. Store Data
hPassKey Private Handle to password (key)
hProv Private
Basic Crypto data

 provider handle
hUserKey Private Handle to the users Sig key
isDEAsig Boolean Public
These fields hold the data from the Crypto functions
that we want to pass back to the caller

Are we doing a DEA signature
KeyBloB64 UnicodeString Public -
LastErr LongInt Public -
MasterCertChain Boolean Private Flag to mark if Cert has valid Chain
MasterDateValid Boolean Private Flag to mark if valid date
pCertContext Private Cert Context
Reason UnicodeString Public This will hold text for the caller about status.
ReturnStr UnicodeString Public -
SignatureB64 UnicodeString Public -
SigningStatus Boolean Public This will hold the overall status.
SignMsgParam Private -
SubReason UnicodeString Public This will hold text for the caller about status.
TrackingMsg TStringList Public -

Properties

Name Type Scope Comments
ContainerName UnicodeString Public Info about the Crypto provider
CryptVer UnicodeString Public -
CSProviderName UnicodeString Public -
DataBuffer UnicodeString Public This is where the data to sign is loaded.
DeaNumber UnicodeString Public -
DetoxNumber UnicodeString Public -
Directions UnicodeString Public -
DrugName UnicodeString Public -
DTSigned UnicodeString Public -
HashAlgorithm UnicodeString Public -
HashStr UnicodeString Public -
HexHash UnicodeString Public -
ignoreDates Boolean Public DEBUG ONLY
ignoreMasterChain Boolean Public DEBUG ONLY
ignoreRevoked Boolean Public DEBUG ONLY
isCardReset Boolean Public -
IssuanceDate UnicodeString Public -
OrderNumber UnicodeString Public -
PatientAddress UnicodeString Public -
PatientName UnicodeString Public -
ProviderAddress UnicodeString Public -
ProviderName UnicodeString Public -
Quantity UnicodeString Public -
SignatureStr UnicodeString Public Return Data
UsrAltName UnicodeString Public -
UsrName UnicodeString Public -
VistaUserName UnicodeString Public 121213 user's name from VistA

Constructors

Name Declaration Scope Comments
Create constructor Create; Public This will create and init the cryptography object

Destructors

Name Declaration Scope Comments
Destroy destructor Destroy; override; Public -

Methods

Name Declaration Scope Comments
CertChainCheck function CertChainCheck(pCertContext: PCCERT_CONTEXT): boolean; Private
Check the Cert Chain for the Cert just used.

 Private declarations 
-----------------------------------------------------
nested function
Certsigndata procedure Certsigndata; Private -
CheckSig function CheckSig(pBlob: pointer; Blobsize: DWORD): boolean; Private -
CRLDistPoint function CRLDistPoint(pbData: pointer; cbData: integer): string; Private -
DataReady function DataReady: boolean; Private
This function is to check that all the input data is ready.
DEA final rule does not have DEA number or DEA schedule in the Cert.
rwf This will need changes.

nested procedure
FindCert function FindCert: boolean; Private
Open a system certificate store and
check each certificates looking for a Certificate
that is Valid and has a given ObjID.
Leaves HCertStore and pCertContext open.


Used to tell if we found the right parts
a pointer the the rgExtension blob
GetHashValue function GetHashValue: String; Public
This call gets the current Hash value and puts the B64
value in the public variable hashstr
procedure tCryptography.GetHashValue;
HashBuf procedure HashBuf(pB: pByte; cnt: integer); Public Called to hash a buffer of data
Hashbuffer procedure Hashbuffer; Public Gets the SHA-2 hash of the fDataBuffer
HashEnd procedure HashEnd; Public
This is called at the end of a long hash to destroy the hash object
If going to sign the hash it must be done before calling this.
HashStart procedure HashStart; Public Called at start of a long hash to create the hash object.
RaiseErr procedure RaiseErr(msg: string); Private Raise an exception with a formatted message
Release procedure Release; Public -
Reset procedure Reset; Public Normal procedures and functions
sCardReattach procedure sCardReattach; Public -
sCardReset procedure sCardReset; Public
SCardReset and sCardReattach are not needed if CheckPINValue, below,
 is used.
SignData function SignData: boolean; Public
All the data that we need will be placed thru object calls
This part will manage the other parts to get the work done.
With luck we don't have to have all the code inline.
SigningCert function SigningCert(pCertCtx: PCCERT_CONTEXT): Integer; Private See if the Cert is valid for Signing.

Referenced By (10)

Module (line) Referrer Type
fOrdersSign (116) crypto Read
fOrdersSign (313) Log2File Read
fOrdersSign (627) - Read
fReview (159) crypto Read
fReview (1238) Log2File Read
fReview (1572) - Read
uOrders (238) - Read
uOrders (258) - Read
XuDsigS (146) getSANFromCard Read
XuDsigS (1635) - Read