apps.js 16 KB

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