IBM Crypto Education Community

IBM Crypto Education Community

IBM Crypto Education Community

Join the IBM Crypto Education community to explore and understand IBM cryptography technology. This community is operated and maintained by the IBM Crypto Development team.

 View Only

Rexx Sample: Change the key validity start and end dates for a key record in the CKDS

By Eysha Shirrine Powers posted Wed March 25, 2020 05:29 PM

  

/* Rexx */                                                             
                                                                       
/*-------------------------------------------------------------------*/
/* This sample REXX clist calls ICSF callable service Key Data Set   */
/*   Metadata Write (CSFKDMW) to set the key material validity start */
/*   and end dates for multiple key labels.                          */
/* It then calls Key Data Set Metadata Read (CSFKDMR) to read the    */
/*   metadata key validity start and end dates.                      */
/*                                                                   */
/* To change metadata the key data set must be in common record      */
/*   format (KDSR), supported by ICSF HCR77A1 and later. See the     */
/*   ICSF System Programmer's Guide for information on KDSR format   */
/*   key data sets.                                                  */
/*                                                                   */
/* See the ICSF Application Programmer's Guide (APG) for detailed    */
/*   API and parameter list documentation.                           */
/*-------------------------------------------------------------------*/
/* NOTE:                                                             */
/*   This sample assumes the key labels already exist in the CKDS.   */
/*-------------------------------------------------------------------*/
signal on novalue ;                                                    
                                                                       
                                                                       
/* ----------------------------------------------------------------- */
/* Call CSFKDMW to set the key material validity start and end       */
/* dates in the key record metadata.                                 */
/* ----------------------------------------------------------------- */
                                                                       
DMW_rule_array_count     = d2c(1,4) ;                                  
DMW_rule_array           = 'CKDS    ' ;                                
DMW_label_count          = d2c(3,4) ;                                  
DMW_label_list           = ,                                           
     left('SAMPLE.AES.KEY.1',64) || 'DATA    ' ||,                     
     left('SAMPLE.AES.KEY.2',64) || 'DATA    ' ||,                     
     left('SAMPLE.AES.KEY.3',64) || 'DATA    ' ;                       
DMW_metadata_list_length = '00000018'x ;  /* decimal 24 */     
DMW_metadata_list        = '000C'x    ||, /* length of block */        
                           '0004'x    ||, /* start date tag  */        
                           '20171001' ||, /* start date      */        
                           '000C'x    ||, /* length of block */        
                           '0005'x    ||, /* end date tag    */        
                           '20171231' ;   /* end date        */        
                                                                       
CALL DMW ;                                                             
                                                                       
                                                                       
/* ----------------------------------------------------------------- */
/* Call CSFKDMR to read the key material validity start and end      */
/* dates in the key record metadata.                                 */
/* ----------------------------------------------------------------- */
                                                                       
DMR_rule_array_count     = d2c(1,4) ;                                  
DMR_rule_array           = 'CKDS    ' ;                                
DMR_metadata_list_length = '00000008'x ;                               
DMR_metadata_list        = ,                                           
     '0004'x ||,  /* length of first metadata tag block */             
     '0004'x ||,  /* key material validity start date   */             
     '0004'x ||,  /* length of next metadata tag block  */             
     '0005'x ;    /* key material validity end date     */             
                                                                       
label_offset = 1 ;                                                     
DO i = 1 to c2d(DMW_label_count) ;                                     
 DMR_record_label = substr(DMW_label_list,label_offset,72) ;           
 CALL DMR ;                                                            
 label_offset = label_offset + 72 ;                                    
END ;                                                                  

EXIT ;                                                                 
                                                                       
                                                                       
/*-------------------------------------------------------------------*/
/* Call CSFKDMW                                                      */
/*-------------------------------------------------------------------*/
DMW:                                                                   
                                                                       
/* initialize parameter list */                                        
DMW_rc           = 'FFFFFFFF'x ;                                       
DMW_rs           = 'FFFFFFFF'x ;                                       
exit_data_length = '00000000'x ;                                       
exit_data        = '' ;                                                
DMW_results_list = d2c(0,8*c2d(DMW_label_count)) ;                     
reserved1_length = '00000000'x ;                                       
reserved1        = '' ;                                                
reserved2_length = '00000000'x ;                                       
reserved2        = '' ;                                                
                                                                       
/* call CSFKDMW */                                                     
address linkpgm 'CSFKDMW' ,                                            
                'DMW_rc' ,                                             
                'DMW_rs' ,                                             
                'exit_data_length' ,                                   
                'exit_data' ,                                          
                'DMW_rule_array_count' ,                               
                'DMW_rule_array' ,                                     
                'DMW_label_count' ,                                    
                'DMW_label_list' ,                                     
                'DMW_metadata_list_length' ,                           
                'DMW_metadata_list' ,                                  
                'DMW_results_list' ,                                   
                'reserved1_length' ,                                   
                'reserved1' ,                                          
                'reserved2_length' ,                                  

                'reserved2' ;                                          
                                                                       
IF DMW_rc > '00000004'x THEN                                           
 DO ;                                                                  
  SAY 'DMW: rc =' c2x(DMW_rc) 'rs =' c2x(DMW_rs) ;                     
  EXIT ;                                                               
 END ;                                                                 
                                                                       
/* ------------------------------------------------------ */           
/* Parse the results_list. A return and reason code is    */           
/* returned for each label in the list.  See the APG      */           
/* for the output structure of different metadata block   */           
/* types.                                                 */           
/* ------------------------------------------------------ */           
results_offset = 1 ;  /* offset for DMW_results_list */                
label_offset   = 1 ;  /* offset for DMW_label_list   */                
                                                                       
DO i = 1 to c2d(DMW_label_count) ;                                     
 label_rc = substr(DMW_results_list,results_offset,4) ;                
 label_rs = substr(DMW_results_list,results_offset+4,4) ;              
 SAY substr(DMW_label_list,label_offset,72) ;                          
 SAY '   DMW: RC =' c2x(label_rc) 'RS =' c2x(label_rs) ;               
 results_offset = results_offset + 8 ;   /* next result in list */     
 label_offset   = label_offset   + 72 ;  /* next label  in list */     
END ;                                                                  
                                                                       
                                                                       
DMW_End:                                                               
SAY ;                                                                  
RETURN ;                                                               
                                                                       
                                                                       
/*-------------------------------------------------------------------*/
/* Key Data Set Metadata Read                                        */
/*-------------------------------------------------------------------*/
DMR:                                                                                                                                         

                                                 
/* initialize parameter list */                   
DMR_rc                 = 'FFFFFFFF'x ;            
DMR_rs                 = 'FFFFFFFF'x ;            
exit_data_length       = '00000000'x ;            
exit_data              = '' ;                     
DMR_output_list_length = d2c(256,4) ;             
DMR_output_list        = d2c(0,256) ;             
reserved1_length       = '00000000'x ;            
reserved1              = '' ;                     
reserved2_length       = '00000000'x ;            
reserved2              = '' ;                     
                                                  
/* call CSFKDMR */                                
address linkpgm 'CSFKDMR' ,                       
                'DMR_rc' ,                        
                'DMR_rs' ,                        
                'exit_data_length' ,              
                'exit_data' ,                     
                'DMR_rule_array_count' ,          
                'DMR_rule_array' ,                
                'DMR_record_label' ,              
                'DMR_metadata_list_length' ,      
                'DMR_metadata_list' ,             
                'DMR_output_list_length' ,        
                'DMR_output_list' ,               
                'reserved1_length' ,              
                'reserved1' ,                     
                'reserved2_length' ,              
                'reserved2' ;                     
                                                  
IF DMR_rc /= '00000000'x THEN                     
 DO ;                                             
  SAY 'DMR: rc =' c2x(DMR_rc) 'rs =' c2x(DMR_rs) ;
  EXIT ;                                          
 END ;                                           

                                                           
/* ------------------------------------ */                  
/* See the APG for the output structure */                  
/* of different metadata block types.   */                  
/* ------------------------------------ */                  
                                                            
SAY strip(DMR_record_label) ;                               
                                                            
/* parse first block of DMR_output_list */                  
block1_length = substr(DMR_output_list,1,2) ;               
block1 = substr(DMR_output_list,1,c2d(block1_length)) ;     
metadata_tag = substr(block1,3,2) ;                         
start_date = substr(block1,5,8) ;                           
SAY '   Start Date:' start_date ;                           
                                                            
/* parse next block of DMR_output_list */                   
offset = c2d(block1_length) + 1 ;                           
block2_length = substr(DMR_output_list,offset,2) ;          
block2 = substr(DMR_output_list,offset,c2d(block2_length)) ;
metadata_tag = substr(block2,3,2) ;                         
end_date = substr(block2,5,8) ;                             
SAY '     End Date:' end_date ;                             
                                                           
DMR_End:                                                    
SAY ;                                                       
RETURN ;

 

/* --------------------------------------------------------------- */
/* Debug ;-)                                                       */
/* --------------------------------------------------------------- */
NOVALUE:                                                             
SAY "Condition NOVALUE was raised."                                  
SAY CONDITION("D") "variable was not initialized."                   
SAY SOURCELINE(sigl)                                                 
EXIT                                                                                          

0 comments
19 views

Permalink