Revision c130f64d
src/info/guardianproject/checkey/MainActivity.java | ||
---|---|---|
178 | 178 |
private void generatePin(AppEntry appEntry, Intent intent) { |
179 | 179 |
String packageName = appEntry.getPackageName(); |
180 | 180 |
try { |
181 |
for (X509Certificate x509 : Utils.getX509Certificates(this, packageName)) { |
|
182 |
Properties prop = new Properties(); |
|
183 |
prop.load(new StringBufferInputStream(x509.getSubjectDN().getName() |
|
184 |
.replaceAll(",", "\n"))); |
|
185 |
prop.list(System.out); |
|
186 |
String name; |
|
187 |
if (prop.containsKey("OU") && prop.containsKey("O")) |
|
188 |
name = (String) prop.get("OU") + prop.get("O"); |
|
189 |
else if (prop.containsKey("O")) |
|
190 |
name = (String) prop.get("O"); |
|
191 |
else if (prop.containsKey("OU")) |
|
192 |
name = (String) prop.get("OU"); |
|
193 |
else if (prop.containsKey("CN")) |
|
194 |
name = (String) prop.get("CN"); |
|
195 |
else |
|
196 |
name = "Unknown"; |
|
197 |
name = name.replaceAll("[^A-Za-z0-9]", ""); |
|
198 |
String fileName = name + "Pin.java"; |
|
199 |
|
|
181 |
X509Certificate[] certs = Utils.getX509Certificates(this, packageName); |
|
182 |
Properties prop = new Properties(); |
|
183 |
prop.load(new StringBufferInputStream(certs[0].getSubjectDN().getName() |
|
184 |
.replaceAll(",", "\n"))); |
|
185 |
prop.list(System.out); |
|
186 |
String name; |
|
187 |
if (prop.containsKey("OU") && prop.containsKey("O")) |
|
188 |
name = (String) prop.get("OU") + prop.get("O"); |
|
189 |
else if (prop.containsKey("O")) |
|
190 |
name = (String) prop.get("O"); |
|
191 |
else if (prop.containsKey("OU")) |
|
192 |
name = (String) prop.get("OU"); |
|
193 |
else if (prop.containsKey("CN")) |
|
194 |
name = (String) prop.get("CN"); |
|
195 |
else |
|
196 |
name = "Unknown"; |
|
197 |
name = name.replaceAll("[^A-Za-z0-9]", ""); |
|
198 |
String fileName = name + "Pin.java"; |
|
199 |
|
|
200 |
final FileOutputStream os = openFileOutput(fileName, |
|
201 |
Context.MODE_WORLD_READABLE); |
|
202 |
os.write(("\npackage " + packageName + ";\n\n" |
|
203 |
+ "import info.guardianproject.trustedintents.ApkSignaturePin;\n\n" |
|
204 |
+ "public final class " |
|
205 |
+ name |
|
206 |
+ "Pin extends ApkSignaturePin {\n\n" |
|
207 |
+ "public " + name + "Pin() {\n" |
|
208 |
+ "\t\tcertificates = new byte[][] {\n").getBytes()); |
|
209 |
for (X509Certificate x509 : certs) { |
|
200 | 210 |
Log.i("AppListFragment", "subjectdn: " + x509.getSubjectDN().getName()); |
201 |
final FileOutputStream os = openFileOutput(fileName, |
|
202 |
Context.MODE_WORLD_READABLE); |
|
203 |
os.write(("\n\n" |
|
204 |
+ "import info.guardianproject.secureintents.CertificatePin;\n\n" |
|
205 |
+ "public final class " |
|
206 |
+ name |
|
207 |
+ "Pin extends CertificatePin {\n\n" |
|
208 |
+ "\tprotected final static byte[] certificate = ").getBytes()); |
|
209 | 211 |
os.write(Arrays.toString(x509.getEncoded()) |
210 |
.replaceAll("\\[", "{").replaceAll("\\]", "}")
|
|
212 |
.replaceFirst("\\[", "{").replaceFirst("\\]", "},")
|
|
211 | 213 |
.getBytes()); |
212 |
os.write(";\n}\n".getBytes()); |
|
213 |
os.close(); |
|
214 |
Log.i("AppListFragment", "wrote " + fileName); |
|
215 |
|
|
216 |
String subject = packageName + " - " + x509.getIssuerDN().getName() |
|
217 |
+ " - " + x509.getNotAfter(); |
|
218 |
Uri uri = Uri.fromFile(getFileStreamPath(fileName)); |
|
219 |
Intent i = new Intent(Intent.ACTION_SEND); |
|
220 |
i.setType("text/x-java-source"); |
|
221 |
i.putExtra(Intent.EXTRA_STREAM, uri); |
|
222 |
i.putExtra(Intent.EXTRA_TITLE, subject); |
|
223 |
i.putExtra(Intent.EXTRA_SUBJECT, subject); |
|
224 |
startActivity(Intent.createChooser(i, getString(R.string.save_cert_using))); |
|
225 | 214 |
} |
215 |
os.write("\t\t};\n\t}\n}\n".getBytes()); |
|
216 |
os.close(); |
|
217 |
Log.i("AppListFragment", "wrote " + fileName); |
|
218 |
|
|
219 |
String subject = packageName + " - " + certs[0].getIssuerDN().getName() |
|
220 |
+ " - " + certs[0].getNotAfter(); |
|
221 |
Uri uri = Uri.fromFile(getFileStreamPath(fileName)); |
|
222 |
Intent i = new Intent(Intent.ACTION_SEND); |
|
223 |
i.setType("text/x-java-source"); |
|
224 |
i.putExtra(Intent.EXTRA_STREAM, uri); |
|
225 |
i.putExtra(Intent.EXTRA_TITLE, subject); |
|
226 |
i.putExtra(Intent.EXTRA_SUBJECT, subject); |
|
227 |
startActivity(Intent.createChooser(i, getString(R.string.save_cert_using))); |
|
228 |
|
|
226 | 229 |
} catch (CertificateException e) { |
227 | 230 |
e.printStackTrace(); |
228 | 231 |
} catch (FileNotFoundException e) { |
Also available in: Unified diff