apps.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. var myApp = angular.module('myApp');
  2. myApp.controller('AppsController', ['$scope', '$http', '$location', '$routeParams', '$window', function($scope, $http, $location, $routeParams, $window){
  3. console.log('AppsController loaded...');
  4. $scope.app = {};
  5. $scope.privacyRisksTC = [];
  6. $scope.securityRisksTC = [];
  7. $scope.appResultList = new Array(200);
  8. $scope.reputationHTI = false;
  9. $scope.spHTI = false;
  10. $scope.finalHTI = false;
  11. $scope.getApps = function(){
  12. angular.element('*[id^="tviz"]').remove();
  13. var genre = $routeParams.genre;
  14. var page = $routeParams.page;
  15. var query = "";
  16. if(genre) {
  17. query += "/?genre=" + genre;
  18. }
  19. if(query != "" && page) {
  20. query += "&page=" + page;
  21. } else if(query == "" && page) {
  22. query += "/?page=" + page;
  23. }
  24. $http.get('/crawler/downloadedapps' + query).then(function(response){
  25. $scope.apps = response.data;
  26. });
  27. }
  28. $scope.getApp = function(){
  29. angular.element('*[id^="tviz"]').remove();
  30. var id = $routeParams.id;
  31. var posture = $routeParams.posture;
  32. var query = "";
  33. if(posture) {
  34. query += "/?posture=" + posture;
  35. }
  36. $http.get('/crawler/downloadedapps/'+id+query).then(function(response){
  37. $scope.app = response.data;
  38. //showCT($scope.app);
  39. $scope.privacyRisksTC = [
  40. "Client communication used?",
  41. "SSL/TLS used?",
  42. "Domains accessed with http AND https: ",
  43. "Custom SSL/TLS trust manager implemented?",
  44. "Faulty custom SSL/TLS trust manager implemented?",
  45. "SSL/TLS using custom error handling?",
  46. "SSL/TLS using faulty custom error handling?",
  47. "SSL/TLS using manual domain name verification?",
  48. "Unprotected communication?",
  49. "Unprotected HTML?",
  50. "Cryptographic Primitives: ",
  51. "Application needs dangerous permissions? ",
  52. "JavaScript to SDK API bridge usage?",
  53. "Is application overprivileged?",
  54. "Userdefined permission usage: ",
  55. "WiFi-Direct enabled?",
  56. "App can handle documents of mimeType: ",
  57. "Screenshot protection used?",
  58. "Tap Jacking Protection used?",
  59. //"",
  60. "Scheduled Alarm Manager registered?",
  61. "Dynamically loaded code at runtime?",
  62. "Allow app debugging Flag?",
  63. "Allow autoexecute after Phone Reboot?",
  64. //"",
  65. "App uses outdated signature key?",
  66. "Contains native libraries: "
  67. ];
  68. $scope.securityRisksTC = [
  69. "Obfuscation used?",
  70. "Device administration policy entries: ",
  71. "Accessed unique identifier(s): ",
  72. "Advertisment-/tracking frameworks found: ",
  73. "App provides public accessible activities?",
  74. "Backup of app is allowed?",
  75. "Log Statement Enabled?",
  76. "Permission to access address book?",
  77. //"",
  78. "Unprotected preference files found?"
  79. ];
  80. });
  81. }
  82. $scope.getApp2 = function(app, $index){
  83. angular.element('*[id^="tviz"]').remove();
  84. if(app.reviews.length && app.permissions.length) {
  85. $http.get('/crawler/downloadedapps/'+app.appId).then(function(response) {
  86. //$scope.app = response.data;
  87. $scope.appResultList[$index] = response.data;
  88. //$scope.showTviz(response.data, $index);
  89. $scope.securityRisksTC = [
  90. "Client communication used?",
  91. "SSL/TLS used?",
  92. "Domains accessed with http AND https: ",
  93. "Custom SSL/TLS trust manager implemented?",
  94. "Faulty custom SSL/TLS trust manager implemented?",
  95. "SSL/TLS using custom error handling?",
  96. "SSL/TLS using faulty custom error handling?",
  97. "SSL/TLS using manual domain name verification?",
  98. "Unprotected communication?",
  99. "Unprotected HTML?",
  100. "Cryptographic Primitives: ",
  101. "Application needs dangerous permissions? ",
  102. "JavaScript to SDK API bridge usage?",
  103. "Is application overprivileged?",
  104. "Userdefined permission usage: ",
  105. "WiFi-Direct enabled?",
  106. "App can handle documents of mimeType: ",
  107. "Screenshot protection used?",
  108. "Tap Jacking Protection used?",
  109. //"",
  110. "Scheduled Alarm Manager registered?",
  111. "Dynamically loaded code at runtime?",
  112. "Allow app debugging Flag?",
  113. "Allow autoexecute after Phone Reboot?",
  114. //"",
  115. "App uses outdated signature key?",
  116. "Contains native libraries: "
  117. ];
  118. $scope.privacyRisksTC = [
  119. "Obfuscation used?",
  120. "Device administration policy entries: ",
  121. "Accessed unique identifier(s): ",
  122. "Advertisment-/tracking frameworks found: ",
  123. "App provides public accessible activities?",
  124. "Backup of app is allowed?",
  125. "Log Statement Enabled?",
  126. "Permission to access address book?",
  127. //"",
  128. "Unprotected preference files found?"
  129. ];
  130. });
  131. }
  132. }
  133. $scope.getSPResult = function(testName) {
  134. var testCases = $scope.app.appicaptor.indicator;
  135. var indicator = _.filter(testCases, function(testCase) {
  136. return testCase.attr.text == testName;
  137. })[0];
  138. return indicator ? indicator.attr.value : "";
  139. }
  140. $scope.getRatingsTCF = function(app) {
  141. var output = "(";
  142. output += Number(app.averageRatingTrustValue.toFixed(2)) + ",";
  143. output += Number(app.averageRatingConfidenceValue.toFixed(2)) + ",";
  144. output += "NA" + ")";
  145. return output;
  146. }
  147. $scope.getReviewsTCF = function(app) {
  148. var output = "(";
  149. output += Number(app.reviewsTrustValue.toFixed(2)) + ",";
  150. output += Number(app.reviewsConfidenceValue.toFixed(2)) + ",";
  151. output += "NA" + ")";
  152. return output;
  153. }
  154. $scope.getPermissionsTCF = function(app) {
  155. var output = "(";
  156. output += Number(app.permissionsTrustValue.toFixed(2)) + ",";
  157. output += Number(app.cofidenceInNumberofPermissions.toFixed(2)) + ",";
  158. output += "NA" + ")";
  159. return output;
  160. }
  161. $scope.getSecurityRisksTCF = function(app) {
  162. var output = "(";
  163. output += Number(app.sTrustValue.toFixed(2)) + ",";
  164. output += Number(app.sConfidenceValue.toFixed(2)) + ",";
  165. output += "NA" + ")";
  166. return output;
  167. }
  168. $scope.getPrivacyRisksTCF = function(app) {
  169. var output = "(";
  170. output += Number(app.pTrustValue.toFixed(2)) + ",";
  171. output += Number(app.pConfidenceValue.toFixed(2)) + ",";
  172. output += "NA" + ")";
  173. return output;
  174. }
  175. $scope.getTrustPlusFrameworkScore = function(app) {
  176. var weight = 1/3;
  177. var ratingMetric = (app.score-1)/4;
  178. var score = (weight*ratingMetric*app.averageRatingConfidenceValue) + (weight*app.reviewMetric*app.reviewsConfidenceValue);
  179. return Number(score.toFixed(2));
  180. }
  181. $scope.$watch('app', function (newValue, oldValue, scope) {
  182. if(newValue.appId) {
  183. $scope.showCertainTrust();
  184. }
  185. });
  186. $scope.showCategoryCertainTrust = function () { //this will just calculate the expectation of the Reputaion and SP QUality category considering the sub categories
  187. var f = 0.0;
  188. var CT_objects = [];
  189. var CT_names = ['ratingsCT', 'reviewsCT', 'permissionsCT', 'reputationAndResult', 'securityRisksCT', 'privacyRisksCT', 'spQualityAndResult'];
  190. var ANDObserver = {
  191. update: function () {
  192. // calculate the CertainTrust.AND for both values
  193. var CT_result = CT_objects['ratingsCT'].AND(CT_objects['reviewsCT']).AND(CT_objects['permissionsCT']);
  194. // update the HTI which displays the result
  195. CT_objects['reputationAndResult'].setF(CT_result.getF());
  196. CT_objects['reputationAndResult'].setTC(CT_result.getT(), CT_result.getC());
  197. }
  198. };
  199. var app = $scope.app;
  200. for (var i = 0, element; element = CT_names[i]; ++i) {
  201. var CT_object;
  202. if (-1 !== element.indexOf('ratings')) {
  203. CT_object = new CertainTrust(Number(app.averageRatingTrustValue.toFixed(2)), Number(app.averageRatingConfidenceValue.toFixed(2)), f, 3);
  204. }
  205. if (-1 !== element.indexOf('reviews')) {
  206. CT_object = new CertainTrust(Number(app.reviewsTrustValue.toFixed(2)), Number(app.reviewsConfidenceValue.toFixed(2)), f, 3);
  207. }
  208. if (-1 !== element.indexOf('permissions')) {
  209. CT_object = new CertainTrust(Number(app.permissionsTrustValue.toFixed(2)), Number(app.cofidenceInNumberofPermissions.toFixed(2)), f, 3);
  210. }
  211. if (-1 !== element.indexOf('security')) {
  212. CT_object = new CertainTrust(Number(app.sTrustValue.toFixed(2)), Number(app.sConfidenceValue.toFixed(2)), f, 3);
  213. }
  214. if (-1 !== element.indexOf('privacy')) {
  215. CT_object = new CertainTrust(Number(app.pTrustValue.toFixed(2)), Number(app.pConfidenceValue.toFixed(2)), f, 3);
  216. }
  217. if (-1 !== element.indexOf('Result')) {
  218. CT_object = new CertainTrust(1, 1, 1, 3);
  219. }
  220. // the result HTIs should be read-only
  221. // var isResultHTI = (-1 !== element.indexOf('Result'));
  222. var HTI = new CertainTrustHTI(CT_object, { domParent: element, readonly: true });
  223. // register our observers for the calculation
  224. // if (!isResultHTI) {
  225. // CT_object.addObserver(ANDObserver);
  226. // }
  227. // store the created objects for easy access in the Arrays
  228. CT_objects[element] = CT_object;
  229. }
  230. // ANDObserver.update();
  231. // calculate the CertainTrust.AND for both values
  232. var repuatationCT_result = CT_objects['ratingsCT'].AND(CT_objects['reviewsCT']).AND(CT_objects['permissionsCT']);
  233. var spQualityCT_result = CT_objects['securityRisksCT'].AND(CT_objects['privacyRisksCT']);
  234. // update the HTI which displays the result
  235. CT_objects['reputationAndResult'].setF(repuatationCT_result.getF());
  236. CT_objects['reputationAndResult'].setTC(repuatationCT_result.getT(), repuatationCT_result.getC());
  237. CT_objects['spQualityAndResult'].setF(spQualityCT_result.getF());
  238. CT_objects['spQualityAndResult'].setTC(spQualityCT_result.getT(), spQualityCT_result.getC());
  239. f = 0.9;
  240. var wFusionArr = new Array();
  241. wFusionArr.push(CT_objects['ratingsCT']);
  242. wFusionArr.push(CT_objects['reviewsCT']);
  243. wFusionArr.push(CT_objects['permissionsCT']);
  244. var wFusionWeightArr = new Array();
  245. wFusionWeightArr.push(1);
  246. wFusionWeightArr.push(2);
  247. wFusionWeightArr.push(1);
  248. var repuatationWFusionCT_result = CT_objects['ratingsCT'].wFusion(wFusionArr,wFusionWeightArr);
  249. repuatationWFusionCT_result.setF(f);
  250. var HTI1 = new CertainTrustHTI(repuatationWFusionCT_result, { domParent: "reputationWFusionResult", readonly: true });
  251. var repuatationCFusionCT_result = CT_objects['ratingsCT'].cFusion(wFusionArr,wFusionWeightArr);
  252. var HTI11 = new CertainTrustHTI(repuatationCFusionCT_result, { domParent: "reputationCFusionResult", readonly: true });
  253. var wFusionSPArr = new Array();
  254. wFusionSPArr.push(CT_objects['securityRisksCT']);
  255. wFusionSPArr.push(CT_objects['privacyRisksCT']);
  256. var wFusionSPWeightArr = new Array();
  257. wFusionSPWeightArr.push(1);
  258. wFusionSPWeightArr.push(1);
  259. var spQualityWFusionCT_result = CT_objects['securityRisksCT'].wFusion(wFusionSPArr,wFusionSPWeightArr);
  260. spQualityWFusionCT_result.setF(f);
  261. var HTI2 = new CertainTrustHTI(spQualityWFusionCT_result, { domParent: "spQualityWFusionResult", readonly: true });
  262. var spQualityCFusionCT_result = CT_objects['securityRisksCT'].cFusion(wFusionSPArr,wFusionSPWeightArr);
  263. var HTI22 = new CertainTrustHTI(spQualityCFusionCT_result, { domParent: "spQualityCFusionResult", readonly: true });
  264. var finalAndCT_result = repuatationCT_result.AND(spQualityCT_result);
  265. var HTI3 = new CertainTrustHTI(finalAndCT_result, { domParent: "finalAndResult", readonly: true });
  266. var finalWFusionCT_result = repuatationWFusionCT_result.AND(spQualityWFusionCT_result);
  267. var HTI33 = new CertainTrustHTI(finalWFusionCT_result, { domParent: "finalWFusionResult", readonly: true });
  268. var finalCFusionCT_result = repuatationCFusionCT_result.AND(spQualityCFusionCT_result);
  269. var HTI333 = new CertainTrustHTI(finalCFusionCT_result, { domParent: "finalCFusionResult", readonly: true });
  270. }
  271. $scope.showCertainTrust = function () { //this will just calculate the expectation of the Reputaion and SP QUality category considering the sub categories
  272. var f = 0.0;
  273. var CT_objects = [];
  274. var CT_names = ['ratingsCT', 'reviewsCT', 'securityRisksCT', 'privacyRisksCT'];
  275. var ANDObserver = {
  276. update: function () {
  277. // calculate the CertainTrust.AND for both values
  278. var CT_result = CT_objects['ratingsCT'].AND(CT_objects['reviewsCT']).AND(CT_objects['permissionsCT']);
  279. // update the HTI which displays the result
  280. CT_objects['reputationAndResult'].setF(CT_result.getF());
  281. CT_objects['reputationAndResult'].setTC(CT_result.getT(), CT_result.getC());
  282. }
  283. };
  284. var app = $scope.app;
  285. for (var i = 0, element; element = CT_names[i]; ++i) {
  286. var CT_object;
  287. if (-1 !== element.indexOf('ratings')) {
  288. CT_object = new CertainTrust(Number(app.averageRatingTrustValue.toFixed(2)), Number(app.averageRatingConfidenceValue.toFixed(2)), f, 3);
  289. }
  290. if (-1 !== element.indexOf('reviews')) {
  291. CT_object = new CertainTrust(Number(app.reviewsTrustValue.toFixed(2)), Number(app.reviewsConfidenceValue.toFixed(2)), f, 3);
  292. }
  293. if (-1 !== element.indexOf('security')) {
  294. CT_object = new CertainTrust(Number(app.sTrustValue.toFixed(2)), Number(app.sConfidenceValue.toFixed(2)), f, 3);
  295. }
  296. if (-1 !== element.indexOf('privacy')) {
  297. CT_object = new CertainTrust(Number(app.pTrustValue.toFixed(2)), Number(app.pConfidenceValue.toFixed(2)), f, 3);
  298. }
  299. // the result HTIs should be read-only
  300. var HTI = new CertainTrustHTI(CT_object, { domParent: element, readonly: true });
  301. CT_objects[element] = CT_object;
  302. }
  303. // ANDObserver.update();
  304. f = 0.9;
  305. var spQualityCT_result = CT_objects['securityRisksCT'].AND(CT_objects['privacyRisksCT']);
  306. spQualityCT_result.setF(f);
  307. var HTI2 = new CertainTrustHTI(spQualityCT_result, { domParent: "spQualityAndResult", readonly: true });
  308. var wFusionArr = new Array();
  309. wFusionArr.push(CT_objects['ratingsCT']);
  310. wFusionArr.push(CT_objects['reviewsCT']);
  311. var wFusionWeightArr = new Array();
  312. wFusionWeightArr.push(1/3);
  313. wFusionWeightArr.push(2/3);
  314. var repuatationWFusionCT_result = CT_objects['ratingsCT'].wFusion(wFusionArr,wFusionWeightArr);
  315. repuatationWFusionCT_result.setF(f);
  316. var HTI1 = new CertainTrustHTI(repuatationWFusionCT_result, { domParent: "reputationWFusionResult", readonly: true });
  317. var finalAndCT_result = repuatationWFusionCT_result.AND(spQualityCT_result);
  318. var HTI3 = new CertainTrustHTI(finalAndCT_result, { domParent: "finalAndResult", readonly: true });
  319. var ct1 = new CertainTrust("Reputation",repuatationWFusionCT_result.getT(), repuatationWFusionCT_result.getC(),repuatationWFusionCT_result.getF(),3);
  320. var ct2 = new CertainTrust("S&p Quality",spQualityCT_result.getT(), spQualityCT_result.getC(),spQualityCT_result.getF(),3);
  321. new CertainTrustTViz([ct1,ct2], { id: "tvizAnd", middle: "AND",
  322. onClick: function(certainTrust) {
  323. if (certainTrust.getName() === "Reputation") $scope.reputationHTI = true;
  324. else $scope.spHTI = true;
  325. $scope.$apply();
  326. },
  327. onMiddleClick: function(certainTrust) {
  328. $scope.finalHTI = true;
  329. $scope.$apply();
  330. }
  331. });
  332. new CertainTrustTViz([ct1,ct2], { id: "tvizAverage", middle: "AVERAGE" });
  333. }
  334. $scope.showTviz = function(app, index) {
  335. var f = 0.0;
  336. var CT_Ratings = new CertainTrust(Number(app.averageRatingTrustValue.toFixed(2)), Number(app.averageRatingConfidenceValue.toFixed(2)), f, 3);
  337. var CT_Reviews = new CertainTrust(Number(app.reviewsTrustValue.toFixed(2)), Number(app.reviewsConfidenceValue.toFixed(2)), f, 3);
  338. var CT_Security = new CertainTrust(Number(app.sTrustValue.toFixed(2)), Number(app.sConfidenceValue.toFixed(2)), f, 3);
  339. var CT_Privacy = new CertainTrust(Number(app.pTrustValue.toFixed(2)), Number(app.pConfidenceValue.toFixed(2)), f, 3);
  340. f = 0.9;
  341. var spQualityCT_result = CT_Security.AND(CT_Privacy);
  342. spQualityCT_result.setF(f);
  343. var wFusionArr = new Array();
  344. wFusionArr.push(CT_Ratings);
  345. wFusionArr.push(CT_Reviews);
  346. var wFusionWeightArr = new Array();
  347. wFusionWeightArr.push(1/3);
  348. wFusionWeightArr.push(2/3);
  349. var repuatationWFusionCT_result = CT_Ratings.wFusion(wFusionArr,wFusionWeightArr);
  350. repuatationWFusionCT_result.setF(f);
  351. var tvizid = "tviz" + index;
  352. var ct1 = new CertainTrust("Reputation",repuatationWFusionCT_result.getT(), repuatationWFusionCT_result.getC(),repuatationWFusionCT_result.getF(),3);
  353. var ct2 = new CertainTrust("S&p Quality",spQualityCT_result.getT(), spQualityCT_result.getC(),spQualityCT_result.getF(),3);
  354. new CertainTrustTViz([ct1,ct2], { canvas: { height: 200, width: 200 }, id: tvizid, middle: "AND" });
  355. }
  356. }]);