use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.
the class ProtectionParameterImpl method test_initLjava_security_KeyStore$C.
/**
* Test for <code>init(KeyStore keyStore, char[] password)</code> and
* <code>getKeyManagers()</code>
* Assertion: returns not empty KeyManager array
*/
public void test_initLjava_security_KeyStore$C() throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
KeyManagerFactory[] keyMF = createKMFac();
assertNotNull("KeyManagerFactory object were not created", keyMF);
KeyStore ksNull = null;
KeyManager[] km;
for (int i = 0; i < keyMF.length; i++) {
keyMF[i].init(ksNull, new char[10]);
km = keyMF[i].getKeyManagers();
assertNotNull("Result should not be null", km);
assertTrue("Length of result KeyManager array should not be 0", (km.length > 0));
}
KeyStore ks;
try {
ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
} catch (KeyStoreException e) {
fail(e.toString() + "default KeyStore type is not supported");
return;
} catch (Exception e) {
fail("Unexpected: " + e.toString());
return;
}
for (int i = 0; i < keyMF.length; i++) {
try {
keyMF[i].init(ks, new char[10]);
} catch (KeyStoreException e) {
}
km = keyMF[i].getKeyManagers();
assertNotNull("Result has not be null", km);
assertTrue("Length of result KeyManager array should not be 0", (km.length > 0));
}
}
use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.
the class ProtectionParameterImpl method test_getInstanceLjava_lang_StringLjava_lang_String04.
/**
* Test for <code>getInstance(String algorithm, String provider)</code>
* method Assertion: returns instance of KeyManagerFactory
*/
public void test_getInstanceLjava_lang_StringLjava_lang_String04() throws NoSuchProviderException, NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
KeyManagerFactory kMF;
for (int i = 0; i < validValues.length; i++) {
kMF = KeyManagerFactory.getInstance(validValues[i], defaultProviderName);
assertNotNull("No KeyManagerFactory created", kMF);
assertEquals("Incorrect algorithm", kMF.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", kMF.getProvider().getName(), defaultProviderName);
}
}
use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.
the class ProtectionParameterImpl method test_getKeyManagers.
/**
* avax.net.ssl.KeyManagerFactory#getKeyManagers()
* @throws NoSuchAlgorithmException
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws UnrecoverableKeyException
*/
public void test_getKeyManagers() throws Exception {
if (!DEFSupported)
fail(NotSupportedMsg);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgorithm);
char[] pass = "password".toCharArray();
kmf.init(null, pass);
assertNotNull("Key manager array is null", kmf.getKeyManagers());
assertEquals("Incorrect size of array", 1, kmf.getKeyManagers().length);
}
use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.
the class KeyManagerFactory2Test method test_getInstanceLjava_lang_StringLjava_lang_String.
/**
* Test for <code>getInstance(String algorithm, String provider)</code>
* method
* Assertions:
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
* throws IllegalArgumentException when provider is null or empty;
* throws NoSuchProviderException when provider is available;
* returns KeyManagerFactory object
*/
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
try {
KeyManagerFactory.getInstance(null, mProv.getName());
fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
} catch (NoSuchAlgorithmException e) {
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
KeyManagerFactory.getInstance(invalidValues[i], mProv.getName());
fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (NoSuchAlgorithmException e) {
}
}
String prov = null;
for (int i = 0; i < validValues.length; i++) {
try {
KeyManagerFactory.getInstance(validValues[i], prov);
fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
try {
KeyManagerFactory.getInstance(validValues[i], "");
fail("IllegalArgumentException must be thrown when provider is empty (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
}
for (int i = 0; i < validValues.length; i++) {
for (int j = 1; j < invalidValues.length; j++) {
try {
KeyManagerFactory.getInstance(validValues[i], invalidValues[j]);
fail("NoSuchProviderException must be thrown (algorithm: ".concat(invalidValues[i]).concat(" provider: ").concat(invalidValues[j]).concat(")"));
} catch (NoSuchProviderException e) {
}
}
}
KeyManagerFactory keyMF;
for (int i = 0; i < validValues.length; i++) {
keyMF = KeyManagerFactory.getInstance(validValues[i], mProv.getName());
assertEquals("Incorrect algorithm", keyMF.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", keyMF.getProvider().getName(), mProv.getName());
checkResult(keyMF);
}
}
use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.
the class KeyManagerFactory2Test method test_getInstanceLjava_lang_String.
/**
* Test for <code>getInstance(String algorithm)</code> method
* Assertions:
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
* returns KeyManagerFactory object
*/
public void test_getInstanceLjava_lang_String() throws Exception {
try {
KeyManagerFactory.getInstance(null);
fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
} catch (NoSuchAlgorithmException e) {
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
KeyManagerFactory.getInstance(invalidValues[i]);
fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (NoSuchAlgorithmException e) {
}
}
KeyManagerFactory keyMF;
for (int i = 0; i < validValues.length; i++) {
keyMF = KeyManagerFactory.getInstance(validValues[i]);
assertEquals("Incorrect algorithm", keyMF.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", keyMF.getProvider(), mProv);
checkResult(keyMF);
}
}
Aggregations