78 |
78 |
setResult(RESULT_CANCELED);
|
79 |
79 |
finish();
|
80 |
80 |
return true;
|
|
81 |
case R.id.generate_pin:
|
|
82 |
generatePin(appEntry, intent);
|
|
83 |
return true;
|
81 |
84 |
case R.id.save:
|
82 |
85 |
saveCertificate(appEntry, intent);
|
83 |
86 |
return true;
|
... | ... | |
169 |
172 |
}
|
170 |
173 |
}
|
171 |
174 |
|
|
175 |
@SuppressLint("WorldReadableFiles")
|
|
176 |
@SuppressWarnings("deprecation")
|
|
177 |
private void generatePin(AppEntry appEntry, Intent intent) {
|
|
178 |
String packageName = appEntry.getPackageName();
|
|
179 |
try {
|
|
180 |
for (X509Certificate x509 : getX509Certificates(this, packageName)) {
|
|
181 |
Properties prop = new Properties();
|
|
182 |
prop.load(new StringBufferInputStream(x509.getSubjectDN().getName()
|
|
183 |
.replaceAll(",", "\n")));
|
|
184 |
prop.list(System.out);
|
|
185 |
String name;
|
|
186 |
if (prop.containsKey("OU") && prop.containsKey("O"))
|
|
187 |
name = (String) prop.get("OU") + prop.get("O");
|
|
188 |
else if (prop.containsKey("O"))
|
|
189 |
name = (String) prop.get("O");
|
|
190 |
else if (prop.containsKey("OU"))
|
|
191 |
name = (String) prop.get("OU");
|
|
192 |
else if (prop.containsKey("CN"))
|
|
193 |
name = (String) prop.get("CN");
|
|
194 |
else
|
|
195 |
name = "Unknown";
|
|
196 |
name = name.replaceAll("[^A-Za-z0-9]", "");
|
|
197 |
String fileName = name + "Pin.java";
|
|
198 |
|
|
199 |
Log.i("AppListFragment", "subjectdn: " + x509.getSubjectDN().getName());
|
|
200 |
final FileOutputStream os = openFileOutput(fileName,
|
|
201 |
Context.MODE_WORLD_READABLE);
|
|
202 |
os.write(("\n\n"
|
|
203 |
+ "import info.guardianproject.secureintents.CertificatePin;\n\n"
|
|
204 |
+ "public final class "
|
|
205 |
+ name
|
|
206 |
+ "Pin extends CertificatePin {\n\n"
|
|
207 |
+ "\tprotected final static byte[] certificate = ").getBytes());
|
|
208 |
os.write(Arrays.toString(x509.getEncoded())
|
|
209 |
.replaceAll("\\[", "{").replaceAll("\\]", "}")
|
|
210 |
.getBytes());
|
|
211 |
os.write(";\n}\n".getBytes());
|
|
212 |
os.close();
|
|
213 |
Log.i("AppListFragment", "wrote " + fileName);
|
|
214 |
|
|
215 |
String subject = packageName + " - " + x509.getIssuerDN().getName()
|
|
216 |
+ " - " + x509.getNotAfter();
|
|
217 |
Uri uri = Uri.fromFile(getFileStreamPath(fileName));
|
|
218 |
Intent i = new Intent(Intent.ACTION_SEND);
|
|
219 |
i.setType("text/x-java-source");
|
|
220 |
i.putExtra(Intent.EXTRA_STREAM, uri);
|
|
221 |
i.putExtra(Intent.EXTRA_TITLE, subject);
|
|
222 |
i.putExtra(Intent.EXTRA_SUBJECT, subject);
|
|
223 |
startActivity(Intent.createChooser(i, getString(R.string.save_cert_using)));
|
|
224 |
}
|
|
225 |
} catch (CertificateException e) {
|
|
226 |
e.printStackTrace();
|
|
227 |
} catch (FileNotFoundException e) {
|
|
228 |
e.printStackTrace();
|
|
229 |
} catch (UnsupportedEncodingException e) {
|
|
230 |
e.printStackTrace();
|
|
231 |
} catch (IOException e) {
|
|
232 |
e.printStackTrace();
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
172 |
236 |
private void virustotal(AppEntry appEntry, Intent intent) {
|
173 |
237 |
String urlString = "https://www.virustotal.com/en/file/"
|
174 |
238 |
+ Utils.getBinaryHash(appEntry.getApkFile(), "sha256") + "/analysis/";
|