Code:
- We have implemented an application framework utilizing MVC patterns. We are using optimistic locking. What this means
- is for the original read of a record (via SQL, loading a subfile) the record is not locked. If the record is changed,
- we chain (RLA for transaction processing) with a lock. If we were using a timestamp, we would see if it had changed,
- and if it has, we display a screen allowing the user to reload the record or force their change on top of the existing
- record. Rather than using a timestamp, we are using a 16 byte MD5 hash. This has a free benefit, in that we can
- now test the record for integrity. If someone changes the record outside the framework (DFU, ftp, etc.) and does
- not explicitly rebuild the hash, then we have an indentifiable integrity issue. While not foolproof, most hackers
- are not going to be sophisticated enough to rebuild the MD5 hash.
-
- The standard across the framework is the last 16 bytes of each file is the hash. MR9000HASH will update the hash
- for every record in a file (just OVRDBF INPUT tofile), and MR9000HINT will print every record for which the hash
- is out of whack.
-
-
-
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // //
- // MR9000HASH //
- // //
- // //
- // create cryptographic checksum //
- // //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- Ctl-Opt dftActGrp(*No) actGrp(*Caller)
- option(*SrcStmt:*NoDebugIO) debug(*Yes)
- bndDir('QUSAPIBD')
- main(af9000hash) ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- //... files ... //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-F input Disk(1024) Usage(*INPUT:*UPDATE) InfDS(fileInfo) UsrOpn ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // ... procedure interfaces ... //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- //
- //... services (external) ...
- //
- Dcl-PR calcMD5 ExtProc('Qc3CalculateHash') ;
- *n Char(1) Const Options(*VarSize) ;
- *n Uns(10) Const ;
- *n Char(8) Const ;
- *n Char(1) Const Options(*VarSize) ;
- *n Char(8) Const ;
- *n Char(1) Const ;
- *n Char(10) Const ;
- *n Char(1) Options(*VarSize) ;
- *n Char(256) ;
- End-PR ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // ... standalone variables ... //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-DS fileInfo Len(528) ;
- fileLength Int(5) Pos(125) ;
- End-DS ;
-
- Dcl-DS buffer Len(1024) End-DS ;
-
- Dcl-DS errDS ;
- *n Uns(10) Inz(%Len(errDS)) ;
- errAvl Uns(10) ;
- *n Char(7) ;
- *n Char(1) ;
- *n Char(240) ;
- End-DS ;
-
- Dcl-DS algd0500 ;
- algName Int(10) Inz(1) ;
- End-DS ;
-
- Dcl-S hash Char(16) ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // Procedures //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- // Mainline //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc af9000hash ;
-
- init();
- DoW ( reader() ) ;
- process() ;
- EndDo ;
- eoj() ;
- Return ;
-
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // reader //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc reader ;
- Dcl-PI *n Ind End-PI ;
-
- Read input buffer ;
- Return ( Not %Eof(input) ) ;
-
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // process //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc process ;
-
- calcMD5( buffer
- : fileLength - 16
- : 'DATA0100'
- : algd0500
- : 'ALGD0500'
- : '0'
- : *Blanks
- : hash
- : errDS
- ) ;
-
- %SubSt(buffer:fileLength - 15:16) = hash ;
- Update input buffer ;
- Return ;
-
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // init //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc init ;
-
- Open input ;
- Return ;
-
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // eoj //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc eoj ;
-
- Close input ;// uninsightful comment
- Return ;
-
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // //
- // MR9000HINT //
- // //
- // //
- // verify checksum intergrity //
- // //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- //-------------------------------------------------------------------------------------------------------------//
- Ctl-Opt dftActGrp(*No) actGrp(*Caller)
- option(*SrcStmt:*NoDebugIO) debug(*Yes)
- bndDir('QUSAPIBD')
- main(af9000hint) ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- //... files ... //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-F input Disk(1024) Usage(*Input:*Update) InfDS(fileInfo) UsrOpn ;
- Dcl-F qsysprt Printer(132) UsrOpn ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // ... procedure interfaces ... //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- //
- //... services (external) ...
- //
- Dcl-PR calcMD5 ExtProc('Qc3CalculateHash') ;
- *n Char(1) Const Options(*VarSize) ;
- *n Uns(10) Const ;
- *n Char(8) Const ;
- *n Char(1) Const Options(*VarSize) ;
- *n Char(8) Const ;
- *n Char(1) Const ;
- *n Char(10) Const ;
- *n Char(1) Options(*VarSize) ;
- *n Char(256) ;
- End-PR ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // ... standalone variables ... //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-DS fileInfo Len(528) ;
- fileLength Int(5) Pos(125) ;
- End-DS ;
-
- Dcl-DS buffer Len(1024) End-DS ;
-
- Dcl-DS errDS ;
- *n Uns(10) Inz(%Len(errDS)) ;
- errAvl Uns(10) ;
- *n Char(7) ;
- *n Char(1) ;
- *n Char(240) ;
- End-DS ;
-
- Dcl-DS algd0500 ;
- algName Int(10) Inz(1) ;
- End-DS ;
-
- Dcl-S hash Char(16) ;
- Dcl-S rptLength Like(fileLength) ;
- Dcl-S output Char(132) ;
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // ... 'O' specs (I still use them) ... //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- oqsysprt e 1
- o output 132
- //-------------------------------------------------------------------------------------------------------------//
- // //
- // Procedures //
- // //
- //-------------------------------------------------------------------------------------------------------------//
- // Mainline //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc af9000hint ;
-
- init() ;
- DoW ( reader() ) ;
- process() ;
- EndDo ;
- eoj() ;
- Return ;
-
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // reader //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc reader ;
- Dcl-PI *n Ind End-PI ;
-
- Read input buffer ;
- Return ( Not %Eof(input) ) ;
-
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // process //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc process ;
-
- calcMD5( buffer
- : fileLength - 16
- : 'DATA0100'
- : algd0500
- : 'ALGD0500'
- : '0'
- : *Blanks
- : hash
- : errDS
- ) ;
-
- If ( %SubSt(buffer:fileLength - 15:16) <> hash ) ;
- output = %SubSt(buffer:1:rptLength) ;
- Except ;
- EndIf ;
-
- Return ;
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // init //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc init ;
-
- Open input ;
- Open qsysprt ;
-
- If ( fileLength > 148 ) ;
- rptLength = 132 ;
- Else ;
- rptLength = fileLength - 16 ;
- EndIf ;
-
- Return ;
- End-Proc ;
- //-------------------------------------------------------------------------------------------------------------//
- // eoj //
- //-------------------------------------------------------------------------------------------------------------//
- Dcl-Proc eoj ;
-
- Close input ;// uninsightful comment
- Close qsysprt ;
- Return ;
-
- End-Proc ;
-
|
|