Commit 25037d86 authored by berge's avatar berge
Browse files

Implemented AIS (Certificate exchange) + misc fixes

parent 39187d0d
Loading
Loading
Loading
Loading
+109 −6
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
        	// activate default
        	activate(a_default());
        	activate(a_fileDefault());
        	activate(a_aisDefault());
        }	
    }

@@ -121,6 +122,19 @@
	
	group defaults {
		
		altstep a_aisDefault() runs on MRTD {
		    
		    [] a_aisConfiguration() {
                 t_ac.start;
                 repeat;
             }

            [] a_aisReadCertificateData() {
                t_ac.start;
                 repeat;
            }  
		}
		
		altstep a_fileDefault() runs on MRTD {
			
			// if passport is unprotected, then any file is accessible
@@ -164,6 +178,91 @@
	
	group automaticInterfaceSpecificationAltsteps {
	    
	    altstep a_aisConfiguration() runs on MRTD {
            
            [] mgmtport.receive(mw_getData_mrz) {
                mgmtport.send(m_responseRead(m_opticalMrz(
                    substr(vc_simu.mrz, 0, lengthof(vc_simu.mrz)/2 ),
                    substr(vc_simu.mrz, lengthof(vc_simu.mrz)/2, lengthof(vc_simu.mrz)/2))));       
                        
            }
            [] mgmtport.receive(mw_getData_cert) {
                mgmtport.send(m_responseRead(m_certRefIds(f_encodeCertRefIds(vc_simu.aisCertRefIds))));                
            }
            
        } // end a_aisConfiguration 
        
        altstep a_aisReadCertificateData() runs on MRTD {
            
            var CommandSelect v_selectCommand;
            var CommandReadBinary v_readCommand;
            var integer v_logicalChannel;
            var LongFileId v_longFileId;
            var ShortFileId v_shortFileId;
            var octetstring v_data := ''O;
            var integer v_dataLength;
            var integer v_offset;
            var W1W2Status v_result;
            
            [] mrtdport.receive(mw_readCurrentEF) -> value v_readCommand {
            
                // Check current file
                v_logicalChannel := f_getLogicalChannel(v_readCommand.class);
                if(vc_simu.currentFiles[v_logicalChannel] == c_noFileInfo) {
                    //TODO
                    mrtdport.send(m_responseNOK(c_w1w2NoCurrentEF));
                    t_ac.start;
                    repeat;
                }
                                        
                v_offset := v_readCommand.params.longOffset.offset;
                v_dataLength := v_readCommand.lengthE;
                
                v_result := f_readFileData(vc_simu.currentFiles[v_logicalChannel], v_offset, v_dataLength, v_data);
                mrtdport.send(m_responseReadWithStatus(v_data, v_result));
                t_ac.start; 
                repeat;         
            }
                        
            // SELECT Command
            [] mrtdport.receive(mw_selectByFileId(c_fileDGCertData.longFileId)) -> value v_selectCommand {
                
                // set current file for logical channel
                v_logicalChannel := f_getLogicalChannel(v_selectCommand.class);
                
                vc_simu.currentFiles[v_logicalChannel] := getFileByLongId(c_fileDGCertData.longFileId);
                        
                mrtdport.send(m_responseOK);
                t_ac.start;
                repeat;
            }
                
            // READ Command with short EF
            [] mrtdport.receive(mw_readShortEF(c_fileDGCertData.shortFileId)) -> value v_readCommand {
  
                // set current file for logical channel
                v_logicalChannel := f_getLogicalChannel(v_readCommand.class);
                vc_simu.currentFiles[v_logicalChannel] := getFileByShortId(c_fileDGCertData.shortFileId);
                log("**** Reading file: ", vc_simu.currentFiles[v_logicalChannel], " ****");
                            
                v_offset := v_readCommand.params.fileIdAndOffset.offset;
                v_dataLength := v_readCommand.lengthE;
            
                v_result := f_readFileData(vc_simu.currentFiles[v_logicalChannel], v_offset, v_dataLength, v_data);
                if(v_data == ''O ) {
                    mrtdport.send(m_responseNOK(v_result));
                }
                else {
                    mrtdport.send(m_responseReadWithStatus(v_data, v_result));
                }
                t_ac.start;
                repeat;
            }
    
            // TODO: receive statements for B1  
            
        } // end a_aisReadCertificateData
        
	    altstep a_aisReports() runs on MRTD {
	        
	        var CommandGeneric v_report;
@@ -184,8 +283,6 @@
			       		
	    } // end a_isReports
	       
	    
	       
	} // end automaticInterfaceSpecificationAltsteps
	
	group inspectionProcedures {
@@ -537,9 +634,15 @@
        		log("**** Reading file: ", vc_simu.currentFiles[v_logicalChannel], " ****");
        		       					
    			v_offset := v_readCommand.params.fileIdAndOffset.offset;
    			v_dataLength := v_readCommand.lengthE;
    			
    			//if(ispresent(v_readCommand.lengthE)) {
    			    v_dataLength := v_readCommand.lengthE;
    			    v_result := f_readFileData(vc_simu.currentFiles[v_logicalChannel], v_offset, v_dataLength, v_data);
    			//}
    			//else {
    			//    v_data := ''O;
    			//    v_result := c_w1w2NormalProcessing;
    			//}
        		
        		if(v_data == ''O ) {
        		    mrtdport.send(m_responseNOK(v_result));
+134 −28
Original line number Diff line number Diff line
@@ -231,6 +231,20 @@
				in integer p_dataLength, 
				out octetstring p_data) return octetstring;
				
		    /**
             * @desc    Read the specified certificate file
             * @param   p_filename certificate file to read (Fullpath !)
             */
			external function fx_readCertificateData(
			    in charstring p_filename) return octetstring;
				
			/**
             * @desc    Create a DG 
             * @param   p_filename file to create (e.g. EF.COM or EF.SOD or EF.DGF1...)
             * @param   p_data content of the file
             */	
            external function fx_createDg(in charstring p_filename, in octetstring p_data);
            
		} // end fileExternalFunctions

	} // end externalFunctions
@@ -559,6 +573,19 @@
			return c_noFileInfo;			
		} // end getFileByShortId
		
		function f_readCertificateData(
            in charstring p_filename) 
        return octetstring {
            var charstring v_fullpath := PXT_EPASSPORT_DATA_ROOT & "/Certs/" & p_filename;
            log(p_filename);
            log(v_fullpath);
            return fx_readCertificateData(v_fullpath);
        } // end f_readCertificateData
            
        function f_createDg(in FileInfo p_fileInfo, in octetstring p_data) {
            fx_createDg(p_fileInfo.filename, p_data);
        } // end f_createDg
		
	} // end fileFunctions
	
	
@@ -578,6 +605,7 @@
    	function f_initializeMRTD(in charstring p_configurationId) runs on MRTD {
    		
    		var octetstring v_cvcaData;
    		var octetstring v_csvCertRefIds;
    		var CvCertificate v_cvcaCvCertificate;
    		var integer v_decodeResult;
    		
@@ -610,25 +638,17 @@
			// FIXME read from EF.CVCA
			vc_simu.trustedCAs := {"GO_CVCA_ECC192", "DETESTCVCA00001"};
			
			// FIXME read c_fileCertRefIds
			f_readFileData(c_fileCertRefIds, 0, -1, v_csvCertRefIds);
			vc_simu.aisCertRefIds := f_parseCertRefIds(v_csvCertRefIds);
			f_createDg(c_fileDGCertData, f_encodeCertData(vc_simu.aisCertRefIds));
			
			// IS verdicts
			vc_simu.isFailVerdicts := {};
			vc_simu.isPassVerdicts := {};			    		
			    		
    	} // end f_initializeMRTD
    	
    	altstep a_aisConfiguration() runs on MRTD {
            
            [] mgmtport.receive(mw_getData_mrz) {
                mgmtport.send(m_responseRead(m_opticalMrz(
                    substr(vc_simu.mrz, 0, lengthof(vc_simu.mrz)/2 ),
                    substr(vc_simu.mrz, lengthof(vc_simu.mrz)/2, lengthof(vc_simu.mrz)/2))));       
                        
            }
            [] mgmtport.receive(mw_getData_cert) {
                
            }
        } // end a_aisConfiguration 
    	
        //function for initializing the system and start the ePassport procedure
        function f_initializeIS(in charstring p_specialOperatorMessage) runs on MRTD {
            
@@ -655,20 +675,6 @@
                log("**** Optical MRZ Line 1: ", v_opticalMrzLine1, " ****");
                log("**** Optical MRZ Line 2: ", v_opticalMrzLine2, " ****");
            }
            else {
                 t_wait.start;
                 
                 alt{
                     [] a_aisConfiguration() {
                         t_wait.stop;
                     }
                     
                     [] t_wait.timeout {
                         log("**** f_initializeIS: Timeout: IS Initialization finished ****");
                     }   
                 }   
                
            }
                        
        } // end f_initializeIS
                    
@@ -927,6 +933,106 @@
		
	} // end simuParamsFunctions
	
	group AutomaticInterfaceSpecificationFunctions {
	    
	    function f_parseCertRefIds(in octetstring p_csvCertRefIds) 
	    return AisCertificateReferenceIds {
	        
	        var AisCertificateReferenceIds v_certRefIds := {''O, ''O, ''O, ''O};
	        
	        var integer v_next := 0;
	        
	        v_next := f_extractId(p_csvCertRefIds, v_next, v_certRefIds.cscaCertId) + 1;
	        v_next := f_extractId(p_csvCertRefIds, v_next, v_certRefIds.dvCertId) + 1;
	        v_next := f_extractId(p_csvCertRefIds, v_next, v_certRefIds.isCertId) + 1;
	        v_next := f_extractId(p_csvCertRefIds, v_next, v_certRefIds.isSecretKey) + 1;
	        
	        return v_certRefIds;
	    }
	    
	    function f_extractId(in octetstring p_input, in integer p_start, out octetstring p_output) return integer {
	        
	        var integer i;
	        
	        p_output := ''O;
	        for(i:=p_start; (i < lengthof(p_input)) and (oct2char(p_input[i]) != ";"); i:=i+1) {
               p_output := p_output & p_input[i];
            }            
            
            return i;
	    }
	    
	    function f_encodeCertRefIds(in AisCertificateReferenceIds p_certRefIds)
	    return octetstring {
	       
	        var octetstring v_encoded := ''O; 
	     
            v_encoded := v_encoded & c_aisCscaCertTag & int2oct(lengthof(p_certRefIds.cscaCertId), 1) & p_certRefIds.cscaCertId;
            v_encoded := v_encoded & c_aisDvCertTag & int2oct(lengthof(p_certRefIds.dvCertId), 1) & p_certRefIds.dvCertId;
            v_encoded := v_encoded & c_aisIsCertTag & int2oct(lengthof(p_certRefIds.isCertId), 1) & p_certRefIds.isCertId;
            v_encoded := v_encoded & c_aisIsSecretKeyTag & int2oct(lengthof(p_certRefIds.isSecretKey), 1) & p_certRefIds.isSecretKey;
	     
	        return v_encoded;
	    }

        function f_encodeCertData(in AisCertificateReferenceIds p_certRefIds)
        return octetstring {
           
            var octetstring v_encoded := ''O; 
            var octetstring v_certificate := ''O;
            
            if(ispresent(p_certRefIds.cscaCertId) and p_certRefIds.cscaCertId != ''O) {
                log(p_certRefIds.cscaCertId);
                v_certificate := f_readCertificateData(oct2char(p_certRefIds.cscaCertId));
                v_encoded := v_encoded & c_aisCscaCertTag & f_encodeLength(lengthof(v_certificate)) & v_certificate;
            }
            
            if(ispresent(p_certRefIds.dvCertId) and p_certRefIds.dvCertId != ''O) {
                log(p_certRefIds.dvCertId);
                v_certificate := f_readCertificateData(oct2char(p_certRefIds.dvCertId));
                v_encoded := v_encoded & c_aisDvCertTag & f_encodeLength(lengthof(v_certificate)) & v_certificate;
            }
            
            if(ispresent(p_certRefIds.isCertId) and p_certRefIds.isCertId != ''O) {
                log(p_certRefIds.isCertId);
                v_certificate := f_readCertificateData(oct2char(p_certRefIds.isCertId));
                v_encoded := v_encoded & c_aisIsCertTag & f_encodeLength(lengthof(v_certificate)) & v_certificate;
            }
            
            if(ispresent(p_certRefIds.isSecretKey) and p_certRefIds.isSecretKey != ''O) {
                log(p_certRefIds.isSecretKey);
                v_certificate := f_readCertificateData(oct2char(p_certRefIds.isSecretKey));
                v_encoded := v_encoded & c_aisIsSecretKeyTag & f_encodeLength(lengthof(v_certificate)) & v_certificate;
            }
                   
            v_encoded := '70'O & f_encodeLength(lengthof(v_encoded)) & v_encoded;
            
            return v_encoded;
        }
        
        function f_encodeLength(in integer p_length) return octetstring {
            
            if(p_length < 128) {
                return int2oct(p_length, 1);       
            }   
            
            if(p_length < 256) {
                return '81'O & int2oct(p_length, 1);       
            }
            
            if(p_length < 65536) {
                return '82'O & int2oct(p_length, 2);       
            }
            
            if(p_length < 16777216) {
                return '83'O & int2oct(p_length, 3);       
            }
            
            return '84'O & int2oct(p_length, 4);
        }
	    
	} // end AutomaticInterfaceSpecificationFunctions

} // end ePassport_Functions

 
+4 −1
Original line number Diff line number Diff line
@@ -62,6 +62,9 @@ module ePassport_Templates {
    		:= c_aisMrzLine1Tag & int2oct(lengthof(p_mrzLine1), 1) & p_mrzLine1
    		& c_aisMrzLine2Tag & int2oct(lengthof(p_mrzLine2), 1) & p_mrzLine2;
        
        template (value) PlainTextResponseData m_certRefIds(in octetstring p_certRefIds)
            := p_certRefIds;
     
	} // end automaticTestInterface

    
@@ -182,7 +185,7 @@ module ePassport_Templates {
			},
  			lengthC := *,
			payload := *,
			lengthE := ?
			lengthE := *
        }
        
        template CommandReadBinary mw_readCurrentEF := {
+5 −2
Original line number Diff line number Diff line
@@ -68,7 +68,10 @@ module ePassport_TestSystem {
		
		// Verdicts from IS
		IsVerdictList isFailVerdicts,
		IsVerdictList isPassVerdicts
		IsVerdictList isPassVerdicts,
		
		// AIS Certificate Reference IDs
		AisCertificateReferenceIds aisCertRefIds
	}
/*
	type component TestAdapter {
@@ -128,7 +131,7 @@ group portDefs {
	};
	
	type port MgmtPort message {
		in CommandGetData, CommandPutDataWith;
		in CommandGetData, CommandPutDataWith, CommandReadBinary, CommandSelect;
		out Response;
	};
	
+25 −4
Original line number Diff line number Diff line
@@ -28,10 +28,31 @@ module ePassport_Testcases {
		  
		    var CommandGetData v_pdu;
		    var integer v_result;
		    var AisCertificateReferenceIds v_certRefIds := f_parseCertRefIds(char2oct("CSCA_RSA_PSS;DV_Cert_01;IS_Cert_01;IS_Key_01;"));
		    var octetstring v_data := ''O;
            var W1W2Status v_status;
            var octetstring v_csvCertRefIds;
            var octetstring v_certData;
		      
		    f_cfUp();
		    
		    v_result := decvalue(oct2bit('01ca01f100'O), v_pdu);
		    v_result := decvalue(oct2bit('01ca01f100ffff'O), v_pdu);
		      
		    log(v_certRefIds.cscaCertId);
		    log(oct2char(v_certRefIds.cscaCertId));
		    log(v_certRefIds.dvCertId);
		    log(v_certRefIds.isCertId);
		    log(v_certRefIds.isSecretKey);		
		      
		    f_readFileData(c_fileCertRefIds, 0, -1, v_csvCertRefIds);
            vc_simu.aisCertRefIds := f_parseCertRefIds(v_csvCertRefIds);
            v_certData := f_encodeCertData(vc_simu.aisCertRefIds);
            log(v_certData);
            f_createDg(c_fileDGCertData, v_certData);
		    v_status := f_readFileData(getFileByLongId(c_fileDGCertData.longFileId), 0, -1, v_data); 
		    log(v_status);     
		    log(v_data);
		}
		
        /**
Loading