User1342 commited on
Commit
d3ab062
·
1 Parent(s): 3b11311

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +155 -43
app.py CHANGED
@@ -7,11 +7,59 @@ import easy_db
7
  def get_db_path():
8
  return "device_data.db"
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def process_request(id_textbox, installer_textbox,boot_state_textbox,verify_textbox,patch_level_textbox,
11
  oem_textbox,brand_textbox,model_textbox,unlocked_textbox,debug_enabled_textbox,
12
  primary_certificate_textbox,emulator_textbox,fingerprint_status_textbox,storage_encryption_status_textbox,
13
  market_apps_enabled_textbox,adb_enabled_textbox,lock_screen_timeout_textbox,
14
  lock_screen_type_textbox,notification_visibility_textbox):
 
 
15
  dict_of_device_data_to_save = {"id": id_textbox,
16
  "installer": installer_textbox,
17
  "boot_state": boot_state_textbox,
@@ -33,35 +81,33 @@ def process_request(id_textbox, installer_textbox,boot_state_textbox,verify_text
33
  "notification_visibility": notification_visibility_textbox}
34
  db = easy_db.DataBase('device_data.db')
35
 
 
 
 
 
 
 
 
36
  table_names = db.table_names()
37
  if 'devices' in table_names:
38
  previous_entries_for_device = db.pull_where('devices', 'id = "{}"'.format(id_textbox))
39
  if previous_entries_for_device:
 
 
 
40
 
41
- differences = []
42
- for previous_entry in previous_entries_for_device:
43
- difference = 0
44
- for key in list(dict_of_device_data_to_save.keys()):
45
- if dict_of_device_data_to_save[key] != previous_entry[key]:
46
- difference = difference + 1
47
- differences.append(difference)
48
-
49
- if len(differences) != 0:
50
- max_difference = max(differences)
51
- else:
52
- max_difference = 0
53
 
54
- print("Previous entries found {} - differences in them and this entry {}".format(len(previous_entries_for_device), max_difference))
55
- else:
56
- print("No previous entries found")
57
 
58
  pprint(dict_of_device_data_to_save)
59
 
60
  db.append('devices', [dict_of_device_data_to_save])
61
 
62
 
 
 
 
63
  history = []
64
- history.append(["Initialisation error!", "Please tune the model by using the above options"])
65
  return history
66
 
67
 
@@ -71,34 +117,100 @@ block = gr.Blocks(css=".container { max-width: 800px; margin: auto; } h1 { margi
71
 
72
  db = easy_db.DataBase('device_data.db')
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  with block:
75
- chatbot = gr.Chatbot().style(color_map=("green", "pink"))
76
- download_db_file = gr.File(value="device_data.db", interactive=False, label="Device Database")
77
- # ID
78
- id_textbox = gr.Textbox(label="Android Secure ID")
79
- # Misc
80
- installer_textbox = gr.Textbox(label="Installer")
81
- debug_enabled_textbox = gr.Textbox(label="Debug Enabled")
82
- primary_certificate_textbox = gr.Textbox(label="primary_certificate")
83
- emulator_textbox = gr.Textbox(label="Emulator")
84
- # Device Data
85
- boot_state_textbox = gr.Textbox(label="Verify Boot State")
86
- verify_textbox = gr.Textbox(label="Verify Mode")
87
- patch_level_textbox = gr.Textbox(label="Security Patch Level")
88
- oem_textbox = gr.Textbox(label="OEM Unlock Supported")
89
- brand_textbox = gr.Textbox(label="Product Brand")
90
- model_textbox = gr.Textbox(label="Product Model")
91
- unlocked_textbox = gr.Textbox(label="OEM Unlock Status")
92
- # Settings
93
- fingerprint_status_textbox = gr.Textbox(label="Fingerprint Status")
94
- storage_encryption_status_textbox = gr.Textbox(label="Storage Encryption Status")
95
- market_apps_enabled_textbox = gr.Textbox(label="Market Apps Enabled")
96
- adb_enabled_textbox = gr.Textbox(label="ADB Enabled")
97
- lock_screen_timeout_textbox = gr.Textbox(label="Lock Screen Timeout")
98
- lock_screen_type_textbox = gr.Textbox(label="Lock Screen Type")
99
- notification_visibility_textbox = gr.Textbox(label="Lock Screen Type")
100
-
101
- btn = gr.Button(label="Submit Data")
 
 
 
 
 
102
  btn.click(fn=process_request, inputs=[id_textbox, installer_textbox,boot_state_textbox,verify_textbox,patch_level_textbox,
103
  oem_textbox,brand_textbox,model_textbox,unlocked_textbox,debug_enabled_textbox,
104
  primary_certificate_textbox,emulator_textbox,fingerprint_status_textbox,storage_encryption_status_textbox,
 
7
  def get_db_path():
8
  return "device_data.db"
9
 
10
+ def is_verifying_and_good_boot_state(dict_of_device_data_to_save):
11
+ if dict_of_device_data_to_save["verify"] == "enforcing" and dict_of_device_data_to_save["boot_state"] == "green":
12
+ return True
13
+ return False
14
+
15
+ def is_debug_enabled(dict_of_device_data_to_save):
16
+ if dict_of_device_data_to_save["debug_enabled"] == False:
17
+ return False
18
+ else:
19
+ return True
20
+
21
+ def is_installer_google(dict_of_device_data_to_save):
22
+ if dict_of_device_data_to_save["installer"] == True:
23
+ return True
24
+ else:
25
+ return False
26
+
27
+ def is_in_emulator(dict_of_device_data_to_save):
28
+ if dict_of_device_data_to_save["emulator"] == True:
29
+ return False
30
+ else:
31
+ return True
32
+
33
+ def do_certs_match(previous_entries_for_device,dict_of_device_data_to_save):
34
+ for entry in previous_entries_for_device:
35
+ if entry["primary_certificate"] != dict_of_device_data_to_save["primary_certificate"]:
36
+ return False
37
+
38
+ return True
39
+
40
+ def get_num_differences(previous_entries_for_device,dict_of_device_data_to_save):
41
+ differences = []
42
+ for previous_entry in previous_entries_for_device:
43
+ difference = 0
44
+ for key in list(dict_of_device_data_to_save.keys()):
45
+ if dict_of_device_data_to_save[key] != previous_entry[key]:
46
+ difference = difference + 1
47
+ differences.append(difference)
48
+
49
+ if len(differences) != 0:
50
+ max_difference = max(differences)
51
+ else:
52
+ max_difference = 0
53
+
54
+ return max_difference
55
+
56
  def process_request(id_textbox, installer_textbox,boot_state_textbox,verify_textbox,patch_level_textbox,
57
  oem_textbox,brand_textbox,model_textbox,unlocked_textbox,debug_enabled_textbox,
58
  primary_certificate_textbox,emulator_textbox,fingerprint_status_textbox,storage_encryption_status_textbox,
59
  market_apps_enabled_textbox,adb_enabled_textbox,lock_screen_timeout_textbox,
60
  lock_screen_type_textbox,notification_visibility_textbox):
61
+ results = []
62
+
63
  dict_of_device_data_to_save = {"id": id_textbox,
64
  "installer": installer_textbox,
65
  "boot_state": boot_state_textbox,
 
81
  "notification_visibility": notification_visibility_textbox}
82
  db = easy_db.DataBase('device_data.db')
83
 
84
+
85
+ results.append(not is_debug_enabled(dict_of_device_data_to_save))
86
+ results.append(not is_in_emulator(dict_of_device_data_to_save))
87
+ results.append(is_installer_google(dict_of_device_data_to_save))
88
+ results.append(is_verifying_and_good_boot_state(dict_of_device_data_to_save))
89
+
90
+
91
  table_names = db.table_names()
92
  if 'devices' in table_names:
93
  previous_entries_for_device = db.pull_where('devices', 'id = "{}"'.format(id_textbox))
94
  if previous_entries_for_device:
95
+ max_difference = get_num_differences(previous_entries_for_device, dict_of_device_data_to_save)
96
+ certs_match = do_certs_match(previous_entries_for_device, dict_of_device_data_to_save)
97
+ results.append(certs_match)
98
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
 
 
 
100
 
101
  pprint(dict_of_device_data_to_save)
102
 
103
  db.append('devices', [dict_of_device_data_to_save])
104
 
105
 
106
+ negative_results = results.count(False)
107
+ result = negative_results/ len(results)
108
+ result = result * 100
109
  history = []
110
+ history.append(["Integrity Check Complete", result])
111
  return history
112
 
113
 
 
117
 
118
  db = easy_db.DataBase('device_data.db')
119
 
120
+ html_data = '''
121
+ <!DOCTYPE html>
122
+ <html>
123
+ <head>
124
+ <meta charset="UTF-8">
125
+ <meta name="viewport" content="width=device-width, initial-scale=1">
126
+ <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
127
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins">
128
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
129
+ <style>
130
+ body,h1,h2,h3,h4,h5 {font-family: "Poppins", sans-serif}
131
+ body {font-size: 16px;}
132
+ img {margin-bottom: -8px;}
133
+ .mySlides {display: none;}
134
+ </style>
135
+ </head>
136
+ <body class="w3-content w3-black" style="max-width:1500px;">
137
+ <!-- The App Section -->
138
+ <div class="w3-padding-large w3-white">
139
+ <div class="w3-row-padding-large">
140
+ <div class="w3-col">
141
+ <h1 class="w3-jumbo"><b>Runic Integrity 🗿🛡️</b></h1>
142
+ <h1 class="w3-xxxlarge w3-text-blue"><b>Remove Unfavorable Tweets From Your Feed </b></h1>
143
+ <p><span class="w3-xlarge">Download the Android App To Use Runic Integrity. ⬇ </span> Runic Integrity is an Android application designed to assess the integrity of a device and report that back to applications on that device for safety checks.</p>
144
+ <a href="#"><button class="w3-button w3-light-grey w3-padding-large w3-section " onclick="document.getElementById('download').style.display='block'">
145
+ <i class=""></i> Find Out More! 💬
146
+ </button></a>
147
+ <a href="https://ko-fi.com/jamesstevenson"><button class="w3-button w3-light-grey w3-padding-large w3-section " onclick="document.getElementById('download').style.display='block'">
148
+ <i class=""></i> Support The Creator! ❤
149
+ </button></a>
150
+ <a href="https://twitter.com/_JamesStevenson"><button class="w3-button w3-light-grey w3-padding-large w3-section " onclick="document.getElementById('download').style.display='block'">
151
+ <i class=""></i> Follow The Creator! 🐦
152
+ </button></a>
153
+ </div>
154
+ </div>
155
+ </div>
156
+ <!-- Modal -->
157
+ <script>
158
+ // Slideshow
159
+ var slideIndex = 1;
160
+ showDivs(slideIndex);
161
+ function plusDivs(n) {
162
+ showDivs(slideIndex += n);
163
+ }
164
+ function showDivs(n) {
165
+ var i;
166
+ var x = document.getElementsByClassName("mySlides");
167
+ if (n > x.length) {slideIndex = 1}
168
+ if (n < 1) {slideIndex = x.length}
169
+ for (i = 0; i < x.length; i++) {
170
+ x[i].style.display = "none";
171
+ }
172
+ x[slideIndex-1].style.display = "block";
173
+ }
174
+ </script>
175
+ <br>
176
+ </body>
177
+ </html>
178
+ '''
179
+
180
+
181
  with block:
182
+ gr.HTML(value=html_data)
183
+ with gr.Group():
184
+ with gr.Row().style(equal_height=True):
185
+ download_db_file = gr.File(value="device_data.db", interactive=False, label="Device Database")
186
+
187
+ with gr.Accordion("Open for More!", visible=False):
188
+ chatbot = gr.Chatbot().style(color_map=("green", "pink"))
189
+ # ID
190
+ id_textbox = gr.Textbox(label="Android Secure ID")
191
+ # Misc
192
+ installer_textbox = gr.Textbox(label="Installer")
193
+ debug_enabled_textbox = gr.Textbox(label="Debug Enabled")
194
+ primary_certificate_textbox = gr.Textbox(label="primary_certificate")
195
+ emulator_textbox = gr.Textbox(label="Emulator")
196
+ # Device Data
197
+ boot_state_textbox = gr.Textbox(label="Verify Boot State")
198
+ verify_textbox = gr.Textbox(label="Verify Mode")
199
+ patch_level_textbox = gr.Textbox(label="Security Patch Level")
200
+ oem_textbox = gr.Textbox(label="OEM Unlock Supported")
201
+ brand_textbox = gr.Textbox(label="Product Brand")
202
+ model_textbox = gr.Textbox(label="Product Model")
203
+ unlocked_textbox = gr.Textbox(label="OEM Unlock Status")
204
+ # Settings
205
+ fingerprint_status_textbox = gr.Textbox(label="Fingerprint Status")
206
+ storage_encryption_status_textbox = gr.Textbox(label="Storage Encryption Status")
207
+ market_apps_enabled_textbox = gr.Textbox(label="Market Apps Enabled")
208
+ adb_enabled_textbox = gr.Textbox(label="ADB Enabled")
209
+ lock_screen_timeout_textbox = gr.Textbox(label="Lock Screen Timeout")
210
+ lock_screen_type_textbox = gr.Textbox(label="Lock Screen Type")
211
+ notification_visibility_textbox = gr.Textbox(label="Lock Screen Type")
212
+
213
+ btn = gr.Button(label="Submit Data")
214
  btn.click(fn=process_request, inputs=[id_textbox, installer_textbox,boot_state_textbox,verify_textbox,patch_level_textbox,
215
  oem_textbox,brand_textbox,model_textbox,unlocked_textbox,debug_enabled_textbox,
216
  primary_certificate_textbox,emulator_textbox,fingerprint_status_textbox,storage_encryption_status_textbox,