From c0eea593add7e48b7b9f7a6bcd6796c9a0993c8f Mon Sep 17 00:00:00 2001
From: abbas ahmad <abbas.ahmad@eglobalmark.com>
Date: Mon, 23 Apr 2018 16:25:33 +0200
Subject: [PATCH] Implemented End-to-End Certificate-based Key Establishment
 Test Purpose => TP/oneM2M/CSE/ESC/BV/002 + SecurityFunctions group in
 OneM2M_Functions.ttcn

---
 LibOneM2M/OneM2M_Functions.ttcn               | 40 ++++++++++++
 ...2M_Testcases_CSE_Release_2_SEC_STF531.ttcn | 65 +++++++++++++++++--
 2 files changed, 98 insertions(+), 7 deletions(-)

diff --git a/LibOneM2M/OneM2M_Functions.ttcn b/LibOneM2M/OneM2M_Functions.ttcn
index a07d2c9..9e65876 100644
--- a/LibOneM2M/OneM2M_Functions.ttcn
+++ b/LibOneM2M/OneM2M_Functions.ttcn
@@ -3989,6 +3989,46 @@ module OneM2M_Functions {
 		
 	}//end of commonFunctions
 	
+	
+	group SecurityFunctions {
+		
+		function f_handShake() runs on CseSimu {
+			var MsgIn v_response;
+			var RequestPrimitive v_requestNotify;
+			var PrimitiveContent v_primitiveContentResponse;
+
+			//Test component configuration
+			f_cf02UpCse1();
+
+			// Preamble (initial conditions)
+			
+			//vc_remoteCseIndex := f_cse_registerRemoteCse(m_createRemoteCSEBase);
+
+			//TestBody
+			v_requestNotify.to_ := f_getResourceAddress(vc_remoteCseIndex);
+			v_requestNotify.from_ := PX_CSE1_ID;
+			v_requestNotify.primitiveContent := {securityInfo := m_contentSecurityInfo(int6)};
+			v_requestNotify.primitiveContent.securityInfo.escertkeMessage := str2oct("VExTIE1lc3NhZ2U6IENsaWVudCBIZWxsbw==");
+			v_primitiveContentResponse.securityInfo := mw_contentSecurityInfo(int6, str2oct("VExTIE1lc3NhZ2VzOiBTZXJ2ZXIgSGVsbG8sIENlcnRpZmljYXRlKiwgU2VydmVyS2V5RXhjaGFuZ2UqLCBDZXJ0aWZpY2F0ZVJlcXVlc3QqLCBTZXJ2ZXJIZWxsb0RvbmU="));
+			mccPort.send(m_request(v_requestNotify));
+			
+			tc_ac.start;
+			alt {
+				[] mccPort.receive(mw_response(mw_responsePrimitive(int2000,v_primitiveContentResponse)))-> value v_response {
+					tc_ac.stop;
+					setverdict(pass, __SCOPE__ & ": Handshake completed successfully");	
+				}
+				[] tc_ac.timeout {
+					setverdict(inconc, __SCOPE__& ":INFO: Timeout while awaiting the reception of a message");
+				}
+			}
+					
+			f_cf02DownCseSimuMaster();
+			
+		}// end f_handShake
+				
+	} //end of SecuityFunctions
+	
 	group externalFunctions {
 		
 		/**
diff --git a/OneM2M_Testcases_CSE_Release_2_SEC_STF531.ttcn b/OneM2M_Testcases_CSE_Release_2_SEC_STF531.ttcn
index f5272f2..15a2122 100644
--- a/OneM2M_Testcases_CSE_Release_2_SEC_STF531.ttcn
+++ b/OneM2M_Testcases_CSE_Release_2_SEC_STF531.ttcn
@@ -85,29 +85,80 @@ module OneM2M_Testcases_CSE_Release_2_SEC_STF531 {
 				var MsgIn v_response;
 				var RequestPrimitive v_requestNotify;
 				var PrimitiveContent v_primitiveContentResponse;
+				
 				//Test component configuration
 				f_cf02UpCse1();
 
 				// Test adapter configuration
 				
-				// Preamble
+				// Preamble (initial conditions)
 				vc_remoteCseIndex := f_cse_registerRemoteCse(m_createRemoteCSEBase);
-				//TODO => " and the IUT has been provisioned with private key and certificate"
-				//Test Commit
+				//Preconfiguration => "and the IUT has been provisioned with private key and certificate"
 				
 				//TestBody
 				v_requestNotify.to_ := f_getResourceAddress(vc_remoteCseIndex);
 				v_requestNotify.from_ := PX_CSE1_ID;
 				v_requestNotify.primitiveContent := {securityInfo := m_contentSecurityInfo(int6)};
-				v_requestNotify.primitiveContent.securityInfo.escertkeMessage := str2oct("VExTIE1lc3NhZ2U6IENsaWVudCBIZWxsbw==");
+				
+				//TODO Base 64 representation of message ? 
+				v_requestNotify.primitiveContent.securityInfo.escertkeMessage := str2oct("ClientHello");				
+ 				v_primitiveContentResponse.securityInfo := mw_contentSecurityInfo(int6, str2oct("ServerHello, Certificate*, ServerKeyExchange*, CertificateRequest*, ServerHelloDone"));
  				
- 				v_primitiveContentResponse.securityInfo := mw_contentSecurityInfo(int6, str2oct("VExTIE1lc3NhZ2VzOiBTZXJ2ZXIgSGVsbG8sIENlcnRpZmljYXRlKiwgU2VydmVyS2V5RXhjaGFuZ2UqLCBDZXJ0aWZpY2F0ZVJlcXVlc3QqLCBTZXJ2ZXJIZWxsb0RvbmU="));
  				mccPort.send(m_request(v_requestNotify));
 			 	tc_ac.start;
 				alt {
 					[] mccPort.receive(mw_response(mw_responsePrimitive(int2000,v_primitiveContentResponse)))-> value v_response {
 						tc_ac.stop;
-						setverdict(pass, __SCOPE__ & ": Message 2 received successfully");	
+						setverdict(pass, __SCOPE__ & ": ESCertKE Message 2 received successfully");	
+					}
+					[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
+						tc_ac.stop;
+						setverdict(fail, __SCOPE__ & ": Wrong SecurityInfo (securityInfoType ¦¦ escertkeMessage ) Message received");
+					}
+					[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) -> value v_response {
+						tc_ac.stop;
+						setverdict(fail, __SCOPE__ & ": Wrong response status code");
+					}				
+					[] tc_ac.timeout {
+						setverdict(inconc, __SCOPE__& ":INFO: Timeout while awaiting the reception of a message");
+					}
+				}		
+						
+				f_cse_postamble_deleteResourcesCSE();
+				f_cf02DownCseSimuMaster();
+			}
+			
+			
+
+			testcase TC_CSE_ESC_BV_002() runs on CseSimu system CseSystem {
+				var MsgIn v_response;
+				var RequestPrimitive v_requestNotify;
+				var PrimitiveContent v_primitiveContentResponse;
+				
+				//Test component configuration
+				f_cf02UpCse1();
+
+				// Test adapter configuration
+				
+				// Preamble (initial conditions)
+				vc_remoteCseIndex := f_cse_registerRemoteCse(m_createRemoteCSEBase);
+				f_handShake();
+				//Preconfiguration => "and the IUT has been provisioned with private key and certificate"
+				
+				//TestBody
+				v_requestNotify.to_ := f_getResourceAddress(vc_remoteCseIndex);
+				v_requestNotify.from_ := PX_CSE1_ID;
+				v_requestNotify.primitiveContent := {securityInfo := m_contentSecurityInfo(int6)};
+				
+				//TODO Base 64 representation of message ? 
+				v_requestNotify.primitiveContent.securityInfo.escertkeMessage := str2oct("Certificate*, ClientKeyExchange, CertificateVerify*, [ChangeCipherSpec], Finished");
+				v_primitiveContentResponse.securityInfo := mw_contentSecurityInfo(int6, str2oct("[ChangeCipherSpec], Finished"));
+				mccPort.send(m_request(v_requestNotify));
+				tc_ac.start;
+				alt {
+					[] mccPort.receive(mw_response(mw_responsePrimitive(int2000,v_primitiveContentResponse)))-> value v_response {
+						tc_ac.stop;
+						setverdict(pass, __SCOPE__ & ": ESCertKE Message 4 received successfully");	
 					}
 					[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
 						tc_ac.stop;
@@ -118,7 +169,7 @@ module OneM2M_Testcases_CSE_Release_2_SEC_STF531 {
 						setverdict(fail, __SCOPE__ & ": Wrong response status code");
 					}				
 					[] tc_ac.timeout {
-						setverdict(inconc, __SCOPE__&":INFO: Timeout while awaiting the reception of a message");
+						setverdict(inconc, __SCOPE__& ":INFO: Timeout while awaiting the reception of a message");
 					}
 				}		
 						
-- 
GitLab