Skip to content

Commit 5564081

Browse files
Changes for standardization (#1445)
* Changes for google3 standardization * Whitespace corrections * Clang-format * Change imports * Minor fixes
1 parent e54e348 commit 5564081

File tree

4 files changed

+69
-63
lines changed

4 files changed

+69
-63
lines changed

common/src/jni/main/cpp/conscrypt/native_crypto.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ static jlong NativeCrypto_EVP_PKEY_from_private_seed(JNIEnv* env, jclass, jint p
15481548
return reinterpret_cast<uintptr_t>(pkey.release());
15491549
}
15501550

1551-
static jbyteArray NativeCrypto_EVP_PKEY_get_private_seed(JNIEnv* env, jclass cls, jobject pkeyRef) {
1551+
static jbyteArray NativeCrypto_EVP_PKEY_get_private_seed(JNIEnv* env, jclass, jobject pkeyRef) {
15521552
CHECK_ERROR_QUEUE_ON_RETURN;
15531553
JNI_TRACE("EVP_PKEY_get_private_seed(%p)", pkeyRef);
15541554

@@ -11785,8 +11785,6 @@ static void NativeCrypto_SSL_CTX_set_spake_credential(
1178511785
jbyteArray id_verifier_array, jboolean is_client, jint handshake_limit,
1178611786
jlong ssl_ctx_address, CONSCRYPT_UNUSED jobject holder) {
1178711787
CHECK_ERROR_QUEUE_ON_RETURN;
11788-
JNI_TRACE("SSL_CTX_set_spake_credential(%p, %p, %p, %p, %d, %d, %ld)", context, pw_array,
11789-
id_prover_array, id_verifier_array, is_client, handshake_limit, ssl_ctx_address);
1179011788

1179111789
SSL_CTX* ssl_ctx = to_SSL_CTX(env, ssl_ctx_address, true);
1179211790

common/src/test/java/org/conscrypt/java/security/KeyPairGeneratorTest.java

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -64,57 +64,59 @@ public class KeyPairGeneratorTest {
6464

6565
@Test
6666
public void test_getInstance() throws Exception {
67-
ServiceTester.test("KeyPairGenerator")
68-
// Do not test AndroidKeyStore Provider. It does not accept vanilla public keys for
69-
// signature verification. It's OKish not to test here because it's tested by
70-
// cts/tests/tests/keystore.
71-
.skipProvider("AndroidKeyStore")
72-
// The SunEC provider tries to pass a sun-only AlgorithmParameterSpec to the default
73-
// AlgorithmParameters:EC when its KeyPairGenerator is initialized. Since Conscrypt
74-
// is the highest-ranked provider when running our tests, its implementation of
75-
// AlgorithmParameters:EC is returned, and it doesn't understand the special
76-
// AlgorithmParameterSpec, so the KeyPairGenerator can't be initialized.
77-
.skipProvider("SunEC")
78-
// The SunPKCS11-NSS provider on OpenJDK 7 attempts to delegate to the SunEC provider,
79-
// which doesn't exist on OpenJDK 7, and thus totally fails. This appears to be a bug
80-
// introduced into later revisions of OpenJDK 7.
81-
.skipProvider("SunPKCS11-NSS")
82-
.run(new ServiceTester.Test() {
83-
@Override
84-
public void test(Provider provider, String algorithm) throws Exception {
85-
AlgorithmParameterSpec params = null;
86-
87-
if ("DH".equals(algorithm) || "DiffieHellman".equalsIgnoreCase(algorithm)) {
88-
params = getDHParams();
89-
}
90-
// KeyPairGenerator.getInstance(String)
91-
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(algorithm);
92-
assertEquals(algorithm, kpg1.getAlgorithm());
93-
if (params != null) {
94-
kpg1.initialize(params);
67+
ServiceTester
68+
.test("KeyPairGenerator")
69+
// Do not test AndroidKeyStore Provider. It does not accept vanilla public keys for
70+
// signature verification. It's OKish not to test here because it's tested by
71+
// cts/tests/tests/keystore.
72+
.skipProvider("AndroidKeyStore")
73+
// The SunEC provider tries to pass a sun-only AlgorithmParameterSpec to the default
74+
// AlgorithmParameters:EC when its KeyPairGenerator is initialized. Since Conscrypt
75+
// is the highest-ranked provider when running our tests, its implementation of
76+
// AlgorithmParameters:EC is returned, and it doesn't understand the special
77+
// AlgorithmParameterSpec, so the KeyPairGenerator can't be initialized.
78+
.skipProvider("SunEC")
79+
// The SunPKCS11-NSS provider on OpenJDK 7 attempts to delegate to the SunEC
80+
// provider, which doesn't exist on OpenJDK 7, and thus totally fails. This appears
81+
// to be a bug introduced into later revisions of OpenJDK 7.
82+
.skipProvider("SunPKCS11-NSS")
83+
.run(new ServiceTester.Test() {
84+
@Override
85+
// g3-add: @SuppressWarnings("InsecureCryptoUsage")
86+
public void test(Provider provider, String algorithm) throws Exception {
87+
AlgorithmParameterSpec params = null;
88+
89+
if ("DH".equals(algorithm) || "DiffieHellman".equalsIgnoreCase(algorithm)) {
90+
params = getDHParams();
91+
}
92+
// KeyPairGenerator.getInstance(String)
93+
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(algorithm);
94+
assertEquals(algorithm, kpg1.getAlgorithm());
95+
if (params != null) {
96+
kpg1.initialize(params);
97+
}
98+
test_KeyPairGenerator(kpg1);
99+
100+
// KeyPairGenerator.getInstance(String, Provider)
101+
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(algorithm, provider);
102+
assertEquals(algorithm, kpg2.getAlgorithm());
103+
assertEquals(provider, kpg2.getProvider());
104+
if (params != null) {
105+
kpg2.initialize(params);
106+
}
107+
test_KeyPairGenerator(kpg2);
108+
109+
// KeyPairGenerator.getInstance(String, String)
110+
KeyPairGenerator kpg3 =
111+
KeyPairGenerator.getInstance(algorithm, provider.getName());
112+
assertEquals(algorithm, kpg3.getAlgorithm());
113+
assertEquals(provider, kpg3.getProvider());
114+
if (params != null) {
115+
kpg3.initialize(params);
116+
}
117+
test_KeyPairGenerator(kpg3);
95118
}
96-
test_KeyPairGenerator(kpg1);
97-
98-
// KeyPairGenerator.getInstance(String, Provider)
99-
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(algorithm, provider);
100-
assertEquals(algorithm, kpg2.getAlgorithm());
101-
assertEquals(provider, kpg2.getProvider());
102-
if (params != null) {
103-
kpg2.initialize(params);
104-
}
105-
test_KeyPairGenerator(kpg2);
106-
107-
// KeyPairGenerator.getInstance(String, String)
108-
KeyPairGenerator kpg3 = KeyPairGenerator.getInstance(algorithm,
109-
provider.getName());
110-
assertEquals(algorithm, kpg3.getAlgorithm());
111-
assertEquals(provider, kpg3.getProvider());
112-
if (params != null) {
113-
kpg3.initialize(params);
114-
}
115-
test_KeyPairGenerator(kpg3);
116-
}
117-
});
119+
});
118120
}
119121

120122
private static final Map<String, List<Integer>> KEY_SIZES = new HashMap<>();
@@ -301,6 +303,7 @@ private void test_Key(KeyPairGenerator kpg, Key k) throws Exception {
301303
test_KeyWithAllKeyFactories(k);
302304
}
303305

306+
// g3-add: @SuppressWarnings("InsecureCryptoUsage")
304307
private void test_KeyWithAllKeyFactories(Key k) throws Exception {
305308
byte[] encoded = k.getEncoded();
306309

@@ -446,6 +449,7 @@ private static DHParameterSpec getDHParams() {
446449
});
447450

448451
@Test
452+
// g3-add: @SuppressWarnings("InsecureCryptoUsage")
449453
public void testDSAGeneratorWithParams() throws Exception {
450454
final DSAParameterSpec dsaSpec = new DSAParameterSpec(DSA_P, DSA_Q, DSA_G);
451455

common/src/test/java/org/conscrypt/javax/net/ssl/HttpsURLConnectionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public void failedUrlConnect() throws Exception {
118118
Future<Void> future = executor.submit(server.run(op));
119119

120120
HttpsURLConnection connection = server.tlsConnection("/file");
121+
// g3-add: broken HTTPS hostname verification
121122
int response = connection.getResponseCode();
122123
assertEquals(404, response);
123124

@@ -151,6 +152,7 @@ public void urlReadTimeout() throws Exception {
151152
Future<Void> future = executor.submit(server.run(op));
152153

153154
HttpsURLConnection connection = server.tlsConnection("/file");
155+
// g3-add: broken HTTPS hostname verification
154156
connection.setConnectTimeout(0);
155157
connection.setReadTimeout(1000);
156158

openjdk/src/test/java/org/conscrypt/ConscryptTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,25 @@
2222
import static org.junit.Assert.assertTrue;
2323
import static org.junit.Assert.fail;
2424

25-
import java.security.Provider;
26-
import java.security.Security;
27-
import javax.net.ssl.SSLContext;
28-
2925
import org.conscrypt.java.security.StandardNames;
26+
// g3-add: import org.junit.Ignore;
3027
import org.junit.Test;
3128
import org.junit.runner.RunWith;
3229
import org.junit.runners.JUnit4;
3330

31+
import java.security.Provider;
32+
import java.security.Security;
33+
34+
import javax.net.ssl.SSLContext;
35+
3436
@RunWith(JUnit4.class)
3537
public class ConscryptTest {
3638

3739
/**
3840
* This confirms that the version machinery is working.
3941
*/
4042
@Test
43+
// g3-add: @Ignore("Failing on google3. TODO(b/309186591)")
4144
public void testVersionIsSensible() {
4245
Conscrypt.Version version = Conscrypt.version();
4346
assertNotNull(version);
@@ -71,8 +74,7 @@ public void buildTls13WithoutTrustManager() throws Exception {
7174
@Test
7275
public void buildInvalid() {
7376
try {
74-
Conscrypt.newProviderBuilder()
75-
.defaultTlsProtocol("invalid").build();
77+
Conscrypt.newProviderBuilder().defaultTlsProtocol("invalid").build();
7678
fail();
7779
} catch (IllegalArgumentException e) {
7880
// Expected.
@@ -81,10 +83,10 @@ public void buildInvalid() {
8183

8284
private void buildProvider(String defaultProtocol, boolean withTrustManager) throws Exception {
8385
Provider provider = Conscrypt.newProviderBuilder()
84-
.setName("test name")
85-
.provideTrustManager(withTrustManager)
86-
.defaultTlsProtocol(defaultProtocol)
87-
.build();
86+
.setName("test name")
87+
.provideTrustManager(withTrustManager)
88+
.defaultTlsProtocol(defaultProtocol)
89+
.build();
8890

8991
assertEquals("test name", provider.getName());
9092
assertEquals(withTrustManager, provider.containsKey("TrustManagerFactory.PKIX"));

0 commit comments

Comments
 (0)