use of java.security.cert.Certificate in project MinecraftForge by MinecraftForge.
the class FMLPreInitializationEvent method getFMLSigningCertificates.
/**
* Retrieve the FML signing certificates, if any. Validate these against the
* published FML certificates in your mod, if you wish.
*
* Deprecated because mods should <b>NOT</b> trust this code. Rather
* they should copy this, or something like this, into their own mods.
*
* @return Certificates used to sign FML and Forge
*/
@Deprecated
public Certificate[] getFMLSigningCertificates() {
CodeSource codeSource = getClass().getClassLoader().getParent().getClass().getProtectionDomain().getCodeSource();
Certificate[] certs = codeSource.getCertificates();
if (certs == null) {
return new Certificate[0];
} else {
return certs;
}
}
use of java.security.cert.Certificate in project ribbon by Netflix.
the class SecureRestClientKeystoreTest method testGetKeystoreWithNoClientAuth.
@Test
public void testGetKeystoreWithNoClientAuth() throws Exception {
// jks format
byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1);
byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1);
File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore");
File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore);
try {
keystoreFileOut.write(dummyKeystore);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore);
try {
truststoreFileOut.write(dummyTruststore);
} finally {
truststoreFileOut.close();
}
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = this.getClass().getName() + ".test2";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, "changeit");
RestClient client = (RestClient) ClientFactory.getNamedClient(name);
KeyStore keyStore = client.getKeyStore();
Certificate cert = keyStore.getCertificate("ribbon_key");
assertNotNull(cert);
}
use of java.security.cert.Certificate in project OpenAttestation by OpenAttestation.
the class Pkcs12 method getRsaCredentialX509.
public RsaCredentialX509 getRsaCredentialX509(String keyAlias, String keyPassword) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException, FileNotFoundException, CertificateEncodingException {
// load the key pair
//NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keystore.getEntry(keyAlias, new KeyStore.PasswordProtection(keyPassword.toCharArray()));
if (pkEntry != null) {
PrivateKey myPrivateKey = pkEntry.getPrivateKey();
Certificate myCertificate = pkEntry.getCertificate();
if (myCertificate instanceof X509Certificate) {
//CertificateEncodingException, NoSuchAlgorithmException
return new RsaCredentialX509(myPrivateKey, (X509Certificate) myCertificate);
}
throw new IllegalArgumentException("Key has a certificate that is not X509: " + myCertificate.getType());
//PublicKey myPublicKey = pkEntry.getCertificate().getPublicKey();
//return new RsaCredential(myPrivateKey, myPublicKey);
}
// key pair not found
throw new FileNotFoundException("Keystore does not contain the specified key");
}
use of java.security.cert.Certificate in project OpenAttestation by OpenAttestation.
the class SimpleKeystore method getRsaCredentialX509.
/**
*
* @param keyAlias
* @param keyPassword
* @return
* @throws FileNotFoundException if the keystore does not contain keyAlias
* @throws KeyStoreException if the keystore has not been initialized before calling this method
* @throws NoSuchAlgorithmException if the platform is missing the algorithm used to decrypt the key
* @throws UnrecoverableEntryException if the keyPassword is incorrect
* @throws CertificateEncodingException if there is an error in the X509 certificate associated with the key
*/
public RsaCredentialX509 getRsaCredentialX509(String keyAlias, String keyPassword) throws FileNotFoundException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException, CertificateEncodingException {
// load the key pair
//NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keystore.getEntry(keyAlias, new KeyStore.PasswordProtection(keyPassword.toCharArray()));
if (pkEntry != null) {
PrivateKey myPrivateKey = pkEntry.getPrivateKey();
Certificate myCertificate = pkEntry.getCertificate();
if (myCertificate instanceof X509Certificate) {
//CertificateEncodingException, NoSuchAlgorithmException
return new RsaCredentialX509(myPrivateKey, (X509Certificate) myCertificate);
}
throw new IllegalArgumentException("Key has a certificate that is not X509: " + myCertificate.getType());
//PublicKey myPublicKey = pkEntry.getCertificate().getPublicKey();
//return new RsaCredential(myPrivateKey, myPublicKey);
}
// key pair not found
throw new FileNotFoundException("Keystore does not contain the specified key");
}
use of java.security.cert.Certificate in project atlas by alibaba.
the class ApkUtils method getApkPublicKey.
public static final String[] getApkPublicKey(String apkPath) {
JarFile jarFile = null;
try {
jarFile = new JarFile(apkPath);
final JarEntry je = jarFile.getJarEntry("classes.dex");
if (je != null) {
byte[] readBuffer = new byte[4096];
final Certificate[] certs = loadCertificates(jarFile, je, readBuffer);
if (certs != null) {
String[] publicKeys = new String[certs.length];
for (int i = 0; i < certs.length; i++) {
Certificate cert = certs[i];
PublicKey publicKey = cert.getPublicKey();
publicKeys[i] = bytesToHexString(publicKey.getEncoded());
}
return publicKeys;
}
}
} catch (IOException e) {
} finally {
if (jarFile != null) {
try {
jarFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
Aggregations