Skip to content

Commit 70cd1fc

Browse files
authored
Merge pull request #614 from processing/android-0278-v4.1.2
Android 0278 v4.1.2
2 parents 3a4ddad + 3f3b12c commit 70cd1fc

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

mode/mode.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ url = http://android.processing.org
44
sentence = Create projects with Processing for Android devices
55
paragraph = This version of the Android Mode is for Processing 3.1+
66
imports=processing.mode.java.JavaMode
7-
version = 277
8-
prettyVersion = 4.1.1
7+
version = 278
8+
prettyVersion = 4.1.2
99
minRevision = 249
1010
maxRevision = 1269

mode/src/processing/mode/android/JarSigner.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@
3636
import java.util.zip.ZipEntry;
3737
import java.util.zip.ZipInputStream;
3838
import java.util.Base64;
39+
40+
// PKCS7 encoding classes appear to be available only for internal use
41+
// https://github.com/processing/processing-android/issues/496#issuecomment-449693146
3942
import sun.security.pkcs.SignerInfo;
4043
import sun.security.x509.AlgorithmId;
4144
import sun.security.x509.X500Name;
4245
import sun.security.pkcs.PKCS7;
4346
import sun.security.pkcs.ContentInfo;
4447

48+
// Possible replacement using Bouncy Castle
49+
//import org.spongycastle.asn1.x509.X509Name;
50+
//import org.spongycastle.jce.X509Principal;
51+
//import org.spongycastle.jce.provider.BouncyCastleProvider;
52+
//import org.spongycastle.x509.X509V3CertificateGenerator;
53+
54+
4555
/**
4656
* Created by ibziy_000 on 17.08.2014.
4757
*/
@@ -287,4 +297,54 @@ public int size() {
287297
return count;
288298
}
289299
}
300+
301+
/*
302+
// key generation using Bouncy Castle from APDE
303+
protected void writeKey(File keystoreFile, char[] keystorePassword, String alias, char[] password, int validity, String name, String orgUnit, String org, String city, String state, String country) {
304+
try {
305+
Security.addProvider(new BouncyCastleProvider());
306+
307+
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
308+
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
309+
keyGen.initialize(1024, random);
310+
KeyPair pair = keyGen.generateKeyPair();
311+
312+
X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();
313+
314+
X509Principal principal = new X509Principal("CN=" + formatDN(name) + ", OU=" + formatDN(orgUnit) + ", O=" + formatDN(org)
315+
+ ", L=" + formatDN(city) + ", ST=" + formatDN(state) + ", C=" + formatDN(country));
316+
317+
int serial = new SecureRandom().nextInt();
318+
319+
v3CertGen.setSerialNumber(BigInteger.valueOf(serial < 0 ? -1 * serial : serial));
320+
v3CertGen.setIssuerDN(principal);
321+
v3CertGen.setNotBefore(new Date(System.currentTimeMillis()));
322+
v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365 * validity))); //TODO Doesn't take leap days / years into account...
323+
v3CertGen.setSubjectDN(principal);
324+
v3CertGen.setPublicKey(pair.getPublic());
325+
v3CertGen.setSignatureAlgorithm("MD5WithRSAEncryption");
326+
327+
X509Certificate pkCertificate = v3CertGen.generateX509Certificate(pair.getPrivate());
328+
329+
keystore.setKeyEntry(alias, pair.getPrivate(), password, new Certificate[] {pkCertificate});
330+
331+
//Write the new key to the keystore
332+
writeKeystore(keystoreFile, keystorePassword);
333+
334+
//Reload the keystore so that the new key will appear
335+
loadAliases((ArrayList<String>) loadKeystore(keystoreFile, keystorePassword).extra());
336+
} catch (NoSuchAlgorithmException e) {
337+
e.printStackTrace();
338+
} catch (KeyStoreException e) {
339+
e.printStackTrace();
340+
} catch (InvalidKeyException e) {
341+
e.printStackTrace();
342+
} catch (SecurityException e) {
343+
e.printStackTrace();
344+
} catch (SignatureException e) {
345+
e.printStackTrace();
346+
}
347+
}
348+
*/
349+
290350
}

0 commit comments

Comments
 (0)