Bug 914685 - 0002. HMAC authentication test case. r=vicamo
authorChuck Lee <chulee@mozilla.com>
Mon, 14 Oct 2013 14:47:52 +0800
changeset 165954 4c913587603866c4af28b9da451467db5b323ce2
parent 165953 97fc306366aa620a2de1a4c77f224fbdb708cb8b
child 165955 5df342f3d30df2cd08d263c0a4d9be2390c46969
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo
bugs914685
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 914685 - 0002. HMAC authentication test case. r=vicamo
dom/wappush/tests/test_cp_pdu_helper.js
--- a/dom/wappush/tests/test_cp_pdu_helper.js
+++ b/dom/wappush/tests/test_cp_pdu_helper.js
@@ -11,16 +11,26 @@ function run_test() {
 
 function test_parser(rawDataArray, contentType, expectResult) {
   let data = { array: rawDataArray, offset: 0 };
   let msg = CP.PduHelper.parse(data, contentType);
   do_check_eq(msg.contentType, expectResult.contentType);
   do_check_eq(msg.content, expectResult.content);
 }
 
+function test_hmac(rawDataArray, mac, key, expectResult) {
+  let authInfo = CP.Authenticator.check(rawDataArray, 0, mac, function getNetworkPin() {
+    return key;
+  });
+  do_check_eq(authInfo.data, rawDataArray);
+  do_check_eq(authInfo.dataLength, rawDataArray.length);
+  do_check_eq(authInfo.checked, expectResult.checked);
+  do_check_eq(authInfo.pass, expectResult.pass);
+}
+
 /*
  * Test data from OMA-TS-WAP_ProvCont-V1_1-2009 0421-C.pdf, clause 6.1
  */
 let text_data_array = new Uint8Array([
   0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20, 0x76, 0x65,
   0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x22, 0x31,
   0x2E, 0x30, 0x22, 0x3F, 0x3E, 0x3C, 0x21, 0x44,
   0x4F, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, 0x77,
@@ -260,16 +270,85 @@ let wbxml_data_array = new Uint8Array([
   0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x00, 0x01,
   0x01, 0xc6, 0x54, 0x01, 0x87, 0x12, 0x06, 0x03,
   0x32, 0x32, 0x38, 0x00, 0x01, 0x87, 0x13, 0x06,
   0x03, 0x30, 0x30, 0x31, 0x00, 0x01, 0x01, 0x01,
   0x01
 ]);
 
 /*
+ * Test data from CHT CP, with code page change
+ */
+let wbxml_code_page_data_array = new Uint8Array([
+  0x03, 0x0B, 0x6A, 0x00, 0x45, 0xC6, 0x56, 0x01,
+  0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
+  0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x01,
+  0xC6, 0x00, 0x01, 0x55, 0x01, 0x87, 0x36, 0x00,
+  0x00, 0x06, 0x03, 0x77, 0x32, 0x00, 0x01, 0x87,
+  0x00, 0x01, 0x39, 0x00, 0x00, 0x06, 0x03, 0x57,
+  0x50, 0x52, 0x4F, 0x58, 0x59, 0x00, 0x01, 0x87,
+  0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F, 0x65,
+  0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0xC6, 0x00,
+  0x01, 0x59, 0x01, 0x87, 0x3A, 0x00, 0x00, 0x06,
+  0x03, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F,
+  0x77, 0x61, 0x70, 0x2E, 0x65, 0x6D, 0x6F, 0x6D,
+  0x65, 0x2E, 0x6E, 0x65, 0x74, 0x2F, 0x00, 0x01,
+  0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
+  0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x87,
+  0x1C, 0x01, 0x01, 0x01, 0xC6, 0x00, 0x01, 0x55,
+  0x01, 0x87, 0x36, 0x00, 0x00, 0x06, 0x03, 0x77,
+  0x34, 0x00, 0x01, 0x87, 0x00, 0x01, 0x39, 0x00,
+  0x00, 0x06, 0x03, 0x4D, 0x50, 0x52, 0x4F, 0x58,
+  0x59, 0x00, 0x01, 0x87, 0x00, 0x01, 0x34, 0x00,
+  0x00, 0x06, 0x03, 0x68, 0x74, 0x74, 0x70, 0x3A,
+  0x2F, 0x2F, 0x6D, 0x6D, 0x73, 0x3A, 0x38, 0x30,
+  0x30, 0x32, 0x00, 0x01, 0x01, 0xC6, 0x51, 0x01,
+  0x87, 0x15, 0x06, 0x03, 0x57, 0x50, 0x52, 0x4F,
+  0x58, 0x59, 0x00, 0x01, 0x87, 0x07, 0x06, 0x03,
+  0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F, 0x6D,
+  0x65, 0x00, 0x01, 0x87, 0x1C, 0x06, 0x03, 0x68,
+  0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x61,
+  0x70, 0x2E, 0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x2E,
+  0x6E, 0x65, 0x74, 0x2F, 0x00, 0x01, 0xC6, 0x52,
+  0x01, 0x87, 0x2F, 0x06, 0x03, 0x50, 0x52, 0x4F,
+  0x58, 0x59, 0x31, 0x00, 0x01, 0x87, 0x20, 0x06,
+  0x03, 0x31, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x2E,
+  0x31, 0x00, 0x01, 0x87, 0x21, 0x06, 0x85, 0x01,
+  0x87, 0x22, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
+  0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0xC6,
+  0x53, 0x01, 0x87, 0x23, 0x06, 0x03, 0x38, 0x30,
+  0x38, 0x30, 0x00, 0x01, 0x01, 0x01, 0x01, 0xC6,
+  0x51, 0x01, 0x87, 0x15, 0x06, 0x03, 0x4D, 0x50,
+  0x52, 0x4F, 0x58, 0x59, 0x00, 0x01, 0x87, 0x07,
+  0x06, 0x03, 0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D,
+  0x53, 0x00, 0x01, 0xC6, 0x52, 0x01, 0x87, 0x2F,
+  0x06, 0x03, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x32,
+  0x00, 0x01, 0x87, 0x20, 0x06, 0x03, 0x31, 0x30,
+  0x2E, 0x31, 0x2E, 0x31, 0x2E, 0x31, 0x00, 0x01,
+  0x87, 0x21, 0x06, 0x85, 0x01, 0x87, 0x22, 0x06,
+  0x03, 0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D, 0x53,
+  0x00, 0x01, 0xC6, 0x53, 0x01, 0x87, 0x23, 0x06,
+  0x03, 0x38, 0x30, 0x38, 0x30, 0x00, 0x01, 0x01,
+  0x01, 0x01, 0xC6, 0x55, 0x01, 0x87, 0x11, 0x06,
+  0x03, 0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F,
+  0x6D, 0x65, 0x00, 0x01, 0x87, 0x07, 0x06, 0x03,
+  0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F, 0x6D,
+  0x65, 0x00, 0x01, 0x87, 0x10, 0x06, 0xAB, 0x01,
+  0x87, 0x08, 0x06, 0x03, 0x65, 0x6D, 0x6F, 0x6D,
+  0x65, 0x00, 0x01, 0x87, 0x09, 0x06, 0x89, 0x01,
+  0x01, 0xC6, 0x55, 0x01, 0x87, 0x11, 0x06, 0x03,
+  0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D, 0x53, 0x00,
+  0x01, 0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54,
+  0x5F, 0x4D, 0x4D, 0x53, 0x00, 0x01, 0x87, 0x10,
+  0x06, 0xAB, 0x01, 0x87, 0x08, 0x06, 0x03, 0x65,
+  0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x87, 0x09,
+  0x06, 0x89, 0x01, 0x01, 0x01
+]);
+
+/*
  * Test data from OMA-TS-WAP_ProvCont-V1_1-20090421-C.pdf, clause 6.1
  */
 let xml_header =
   "<?xml version=\"1.0\"?>" +
   "<!DOCTYPE wap-provisioningdoc PUBLIC \"-//WAPFORUM//DTD PROV 1.0//EN\" \"http://www.wapforum.org/DTD/prov.dtd\">";
 
 let xml_body =
   "<wap-provisioningdoc version=\"1.0\">" +
@@ -308,131 +387,17 @@ let xml_body =
       "</characteristic>" +
       "<characteristic type=\"VALIDITY\">" +
         "<parm name=\"COUNTRY\" value=\"228\"/>" +
         "<parm name=\"NETWORK\" value=\"001\"/>" +
       "</characteristic>" +
     "</characteristic>" +
   "</wap-provisioningdoc>";
 
-/**
- * CP in plain text
- *
- * Test case from OMA-TS-WAP_ProvCont-V1_1-20090421-C.pdf, clause 6.1
- */
-add_test(function test_cp_parse_plain_text() {
-  test_parser(text_data_array, "text/vnd.wap.connectivity-xml", {
-    contentType: "text/vnd.wap.connectivity-xml",
-    content: xml_header + xml_body
-  });
-
-  run_next_test();
-});
-
-/**
- * CP compressed by WBXML
- *
- * Test case from OMA-TS-WAP_ProvCont-V1_1-20090421-C.pdf, Appendix C
- */
-add_test(function test_cp_parse_wbxml() {
-  test_parser(wbxml_data_array, "application/vnd.wap.connectivity-wbxml", {
-    contentType: "text/vnd.wap.connectivity-xml",
-    content: xml_body
-  });
-
-  run_next_test();
-});
-
-/**
- * CP compressed by WBXML with VENDORCONFIG
- */
-add_test(function test_cp_parse_wbxml() {
-  let wbxml_vendor_config_data_array = new Uint8Array([
-    0x03, 0x0b, 0x6a, 0x05, 0x4e, 0x41, 0x50, 0x31,
-    0x00, 0xC5, 0x46, 0x01, 0xc6, 0x57, 0x01, 0x01
-  ]);
-
-  test_parser(wbxml_vendor_config_data_array, "application/vnd.wap.connectivity-wbxml", {
-                contentType: "application/vnd.wap.connectivity-wbxml",
-                content: wbxml_vendor_config_data_array
-              });
-
-  run_next_test();
-});
-
-/**
- * CP compressed by WBXML with code page switch
- */
-add_test(function test_cp_parse_wbxml_code_page() {
-  let wbxml_code_page_data_array = new Uint8Array([
-    0x03, 0x0B, 0x6A, 0x00, 0x45, 0xC6, 0x56, 0x01,
-    0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
-    0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x01,
-    0xC6, 0x00, 0x01, 0x55, 0x01, 0x87, 0x36, 0x00,
-    0x00, 0x06, 0x03, 0x77, 0x32, 0x00, 0x01, 0x87,
-    0x00, 0x01, 0x39, 0x00, 0x00, 0x06, 0x03, 0x57,
-    0x50, 0x52, 0x4F, 0x58, 0x59, 0x00, 0x01, 0x87,
-    0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F, 0x65,
-    0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0xC6, 0x00,
-    0x01, 0x59, 0x01, 0x87, 0x3A, 0x00, 0x00, 0x06,
-    0x03, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F,
-    0x77, 0x61, 0x70, 0x2E, 0x65, 0x6D, 0x6F, 0x6D,
-    0x65, 0x2E, 0x6E, 0x65, 0x74, 0x2F, 0x00, 0x01,
-    0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
-    0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x87,
-    0x1C, 0x01, 0x01, 0x01, 0xC6, 0x00, 0x01, 0x55,
-    0x01, 0x87, 0x36, 0x00, 0x00, 0x06, 0x03, 0x77,
-    0x34, 0x00, 0x01, 0x87, 0x00, 0x01, 0x39, 0x00,
-    0x00, 0x06, 0x03, 0x4D, 0x50, 0x52, 0x4F, 0x58,
-    0x59, 0x00, 0x01, 0x87, 0x00, 0x01, 0x34, 0x00,
-    0x00, 0x06, 0x03, 0x68, 0x74, 0x74, 0x70, 0x3A,
-    0x2F, 0x2F, 0x6D, 0x6D, 0x73, 0x3A, 0x38, 0x30,
-    0x30, 0x32, 0x00, 0x01, 0x01, 0xC6, 0x51, 0x01,
-    0x87, 0x15, 0x06, 0x03, 0x57, 0x50, 0x52, 0x4F,
-    0x58, 0x59, 0x00, 0x01, 0x87, 0x07, 0x06, 0x03,
-    0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F, 0x6D,
-    0x65, 0x00, 0x01, 0x87, 0x1C, 0x06, 0x03, 0x68,
-    0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x61,
-    0x70, 0x2E, 0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x2E,
-    0x6E, 0x65, 0x74, 0x2F, 0x00, 0x01, 0xC6, 0x52,
-    0x01, 0x87, 0x2F, 0x06, 0x03, 0x50, 0x52, 0x4F,
-    0x58, 0x59, 0x31, 0x00, 0x01, 0x87, 0x20, 0x06,
-    0x03, 0x31, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x2E,
-    0x31, 0x00, 0x01, 0x87, 0x21, 0x06, 0x85, 0x01,
-    0x87, 0x22, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
-    0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0xC6,
-    0x53, 0x01, 0x87, 0x23, 0x06, 0x03, 0x38, 0x30,
-    0x38, 0x30, 0x00, 0x01, 0x01, 0x01, 0x01, 0xC6,
-    0x51, 0x01, 0x87, 0x15, 0x06, 0x03, 0x4D, 0x50,
-    0x52, 0x4F, 0x58, 0x59, 0x00, 0x01, 0x87, 0x07,
-    0x06, 0x03, 0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D,
-    0x53, 0x00, 0x01, 0xC6, 0x52, 0x01, 0x87, 0x2F,
-    0x06, 0x03, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x32,
-    0x00, 0x01, 0x87, 0x20, 0x06, 0x03, 0x31, 0x30,
-    0x2E, 0x31, 0x2E, 0x31, 0x2E, 0x31, 0x00, 0x01,
-    0x87, 0x21, 0x06, 0x85, 0x01, 0x87, 0x22, 0x06,
-    0x03, 0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D, 0x53,
-    0x00, 0x01, 0xC6, 0x53, 0x01, 0x87, 0x23, 0x06,
-    0x03, 0x38, 0x30, 0x38, 0x30, 0x00, 0x01, 0x01,
-    0x01, 0x01, 0xC6, 0x55, 0x01, 0x87, 0x11, 0x06,
-    0x03, 0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F,
-    0x6D, 0x65, 0x00, 0x01, 0x87, 0x07, 0x06, 0x03,
-    0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F, 0x6D,
-    0x65, 0x00, 0x01, 0x87, 0x10, 0x06, 0xAB, 0x01,
-    0x87, 0x08, 0x06, 0x03, 0x65, 0x6D, 0x6F, 0x6D,
-    0x65, 0x00, 0x01, 0x87, 0x09, 0x06, 0x89, 0x01,
-    0x01, 0xC6, 0x55, 0x01, 0x87, 0x11, 0x06, 0x03,
-    0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D, 0x53, 0x00,
-    0x01, 0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54,
-    0x5F, 0x4D, 0x4D, 0x53, 0x00, 0x01, 0x87, 0x10,
-    0x06, 0xAB, 0x01, 0x87, 0x08, 0x06, 0x03, 0x65,
-    0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x87, 0x09,
-    0x06, 0x89, 0x01, 0x01, 0x01
-  ]);
-  let wbxml_content =
+let wbxml_code_page_content =
     "<wap-provisioningdoc>" +
     "<characteristic type=\"BOOTSTRAP\">" +
       "<parm name=\"NAME\" value=\"CHT_emome\"/>" +
     "</characteristic>" +
     "<characteristic type=\"APPLICATION\">" +
       "<parm name=\"APPID\" value=\"w2\"/>" +
       "<parm name=\"TO-PROXY\" value=\"WPROXY\"/>" +
       "<parm name=\"NAME\" value=\"CHT_emome\"/>" +
@@ -485,15 +450,95 @@ add_test(function test_cp_parse_wbxml_co
       "<parm name=\"NAPID\" value=\"CHT_MMS\"/>" +
       "<parm name=\"NAME\" value=\"CHT_MMS\"/>" +
       "<parm name=\"BEARER\" value=\"GSM-GPRS\"/>" +
       "<parm name=\"NAP-ADDRESS\" value=\"emome\"/>" +
       "<parm name=\"NAP-ADDRTYPE\" value=\"APN\"/>" +
     "</characteristic>" +
     "</wap-provisioningdoc>";
 
-  test_parser(wbxml_code_page_data_array, "application/vnd.wap.connectivity-wbxml", {
-                contentType: "text/vnd.wap.connectivity-xml",
-                content: wbxml_content
+/**
+ * CP in plain text
+ *
+ * Test case from OMA-TS-WAP_ProvCont-V1_1-20090421-C.pdf, clause 6.1
+ */
+add_test(function test_cp_parse_plain_text() {
+  test_parser(text_data_array, "text/vnd.wap.connectivity-xml", {
+    contentType: "text/vnd.wap.connectivity-xml",
+    content: xml_header + xml_body
+  });
+
+  run_next_test();
+});
+
+/**
+ * CP compressed by WBXML
+ *
+ * Test case from OMA-TS-WAP_ProvCont-V1_1-20090421-C.pdf, Appendix C
+ */
+add_test(function test_cp_parse_wbxml() {
+  test_parser(wbxml_data_array, "application/vnd.wap.connectivity-wbxml", {
+    contentType: "text/vnd.wap.connectivity-xml",
+    content: xml_body
+  });
+
+  run_next_test();
+});
+
+/**
+ * CP compressed by WBXML with VENDORCONFIG
+ */
+add_test(function test_cp_parse_wbxml() {
+  let wbxml_vendor_config_data_array = new Uint8Array([
+    0x03, 0x0b, 0x6a, 0x05, 0x4e, 0x41, 0x50, 0x31,
+    0x00, 0xC5, 0x46, 0x01, 0xc6, 0x57, 0x01, 0x01
+  ]);
+
+  test_parser(wbxml_vendor_config_data_array, "application/vnd.wap.connectivity-wbxml", {
+                contentType: "application/vnd.wap.connectivity-wbxml",
+                content: wbxml_vendor_config_data_array
               });
 
   run_next_test();
 });
+
+/**
+ * CP compressed by WBXML with code page switch
+ */
+add_test(function test_cp_parse_wbxml_code_page() {
+  test_parser(wbxml_code_page_data_array, "application/vnd.wap.connectivity-wbxml", {
+                contentType: "text/vnd.wap.connectivity-xml",
+                content: wbxml_code_page_content
+              });
+
+  run_next_test();
+});
+
+/**
+ * HMAC test
+ */
+add_test(function test_cp_hmac_userpin() {
+  test_hmac(wbxml_code_page_data_array,
+            "AA2DC41FC48AEEF3FED7351B1EE704461A8894D4",
+            "0000",
+            {
+              checked: true,
+              pass: true
+            });
+
+  run_next_test();
+});
+
+add_test(function test_cp_hmac_networkpin() {
+  let wbxml_empty_data_array = new Uint8Array([
+    0x03, 0x0b, 0x6a, 0x00, 0x45, 0x01
+  ]);
+
+  test_hmac(wbxml_empty_data_array,
+            "1AF545FE2823DC9347064450F90FF1BBF957E146",
+            CP.Authenticator.formatImsi("466923103145252"),
+            {
+              checked: true,
+              pass: true
+            });
+
+  run_next_test();
+});