Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: talk/app/webrtc/java/jni/peerconnection_jni.cc

Issue 1312293003: Add option to enable ECDSA key for Java API. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Remove extra line Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 using webrtc::VideoSourceInterface; 118 using webrtc::VideoSourceInterface;
119 using webrtc::VideoTrackInterface; 119 using webrtc::VideoTrackInterface;
120 using webrtc::VideoTrackVector; 120 using webrtc::VideoTrackVector;
121 using webrtc::kVideoCodecVP8; 121 using webrtc::kVideoCodecVP8;
122 122
123 namespace webrtc_jni { 123 namespace webrtc_jni {
124 124
125 // Field trials initialization string 125 // Field trials initialization string
126 static char *field_trials_init_string = NULL; 126 static char *field_trials_init_string = NULL;
127 127
128 // Passed to SSLIdentity::Generate, "WebRTC". Used for the certificates'
129 // subject and issuer name.
130 static const char kIdentityName[] = "WebRTC";
jiayl2 2015/08/31 19:47:42 a minor issue, but can you move it to a header fil
AlexG 2015/08/31 20:14:13 Done.
131
128 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 132 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
129 // Set in PeerConnectionFactory_initializeAndroidGlobals(). 133 // Set in PeerConnectionFactory_initializeAndroidGlobals().
130 static bool factory_static_initialized = false; 134 static bool factory_static_initialized = false;
131 static bool vp8_hw_acceleration_enabled = true; 135 static bool vp8_hw_acceleration_enabled = true;
132 #endif 136 #endif
133 137
134 extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { 138 extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
135 jint ret = InitGlobalJniVariables(jvm); 139 jint ret = InitGlobalJniVariables(jvm);
136 if (ret < 0) 140 if (ret < 0)
137 return -1; 141 return -1;
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 if (enum_name == "ENABLED") 1270 if (enum_name == "ENABLED")
1267 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; 1271 return PeerConnectionInterface::kTcpCandidatePolicyEnabled;
1268 1272
1269 if (enum_name == "DISABLED") 1273 if (enum_name == "DISABLED")
1270 return PeerConnectionInterface::kTcpCandidatePolicyDisabled; 1274 return PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1271 1275
1272 CHECK(false) << "Unexpected TcpCandidatePolicy enum_name " << enum_name; 1276 CHECK(false) << "Unexpected TcpCandidatePolicy enum_name " << enum_name;
1273 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; 1277 return PeerConnectionInterface::kTcpCandidatePolicyEnabled;
1274 } 1278 }
1275 1279
1280 static rtc::KeyType JavaKeyTypeToNativeType(JNIEnv* jni, jobject j_key_type) {
1281 std::string enum_name = GetJavaEnumName(
1282 jni, "org/webrtc/PeerConnection$KeyType", j_key_type);
1283
1284 if (enum_name == "RSA")
1285 return rtc::KT_RSA;
1286 if (enum_name == "ECDSA")
1287 return rtc::KT_ECDSA;
1288
1289 CHECK(false) << "Unexpected KeyType enum_name " << enum_name;
1290 return rtc::KT_ECDSA;
1291 }
1292
1276 static void JavaIceServersToJsepIceServers( 1293 static void JavaIceServersToJsepIceServers(
1277 JNIEnv* jni, jobject j_ice_servers, 1294 JNIEnv* jni, jobject j_ice_servers,
1278 PeerConnectionInterface::IceServers* ice_servers) { 1295 PeerConnectionInterface::IceServers* ice_servers) {
1279 jclass list_class = GetObjectClass(jni, j_ice_servers); 1296 jclass list_class = GetObjectClass(jni, j_ice_servers);
1280 jmethodID iterator_id = GetMethodID( 1297 jmethodID iterator_id = GetMethodID(
1281 jni, list_class, "iterator", "()Ljava/util/Iterator;"); 1298 jni, list_class, "iterator", "()Ljava/util/Iterator;");
1282 jobject iterator = jni->CallObjectMethod(j_ice_servers, iterator_id); 1299 jobject iterator = jni->CallObjectMethod(j_ice_servers, iterator_id);
1283 CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; 1300 CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
1284 jmethodID iterator_has_next = GetMethodID( 1301 jmethodID iterator_has_next = GetMethodID(
1285 jni, GetObjectClass(jni, iterator), "hasNext", "()Z"); 1302 jni, GetObjectClass(jni, iterator), "hasNext", "()Z");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 jobject j_rtcp_mux_policy = GetObjectField( 1355 jobject j_rtcp_mux_policy = GetObjectField(
1339 jni, j_rtc_config, j_rtcp_mux_policy_id); 1356 jni, j_rtc_config, j_rtcp_mux_policy_id);
1340 1357
1341 jfieldID j_tcp_candidate_policy_id = GetFieldID( 1358 jfieldID j_tcp_candidate_policy_id = GetFieldID(
1342 jni, j_rtc_config_class, "tcpCandidatePolicy", 1359 jni, j_rtc_config_class, "tcpCandidatePolicy",
1343 "Lorg/webrtc/PeerConnection$TcpCandidatePolicy;"); 1360 "Lorg/webrtc/PeerConnection$TcpCandidatePolicy;");
1344 jobject j_tcp_candidate_policy = GetObjectField( 1361 jobject j_tcp_candidate_policy = GetObjectField(
1345 jni, j_rtc_config, j_tcp_candidate_policy_id); 1362 jni, j_rtc_config, j_tcp_candidate_policy_id);
1346 1363
1347 jfieldID j_ice_servers_id = GetFieldID( 1364 jfieldID j_ice_servers_id = GetFieldID(
1348 jni, j_rtc_config_class, "iceServers", 1365 jni, j_rtc_config_class, "iceServers", "Ljava/util/List;");
1349 "Ljava/util/List;");
1350 jobject j_ice_servers = GetObjectField(jni, j_rtc_config, j_ice_servers_id); 1366 jobject j_ice_servers = GetObjectField(jni, j_rtc_config, j_ice_servers_id);
1351 1367
1352 jfieldID j_audio_jitter_buffer_max_packets_id = GetFieldID( 1368 jfieldID j_audio_jitter_buffer_max_packets_id = GetFieldID(
1353 jni, j_rtc_config_class, "audioJitterBufferMaxPackets", 1369 jni, j_rtc_config_class, "audioJitterBufferMaxPackets", "I");
1354 "I");
1355 jfieldID j_audio_jitter_buffer_fast_accelerate_id = GetFieldID( 1370 jfieldID j_audio_jitter_buffer_fast_accelerate_id = GetFieldID(
1356 jni, j_rtc_config_class, "audioJitterBufferFastAccelerate", "Z"); 1371 jni, j_rtc_config_class, "audioJitterBufferFastAccelerate", "Z");
1372
1373 jfieldID j_key_type_id = GetFieldID(
1374 jni, j_rtc_config_class, "keyType",
1375 "Lorg/webrtc/PeerConnection$KeyType;");
1376 jobject j_key_type = GetObjectField(
1377 jni, j_rtc_config, j_key_type_id);
1378
1357 PeerConnectionInterface::RTCConfiguration rtc_config; 1379 PeerConnectionInterface::RTCConfiguration rtc_config;
1358
1359 rtc_config.type = 1380 rtc_config.type =
1360 JavaIceTransportsTypeToNativeType(jni, j_ice_transports_type); 1381 JavaIceTransportsTypeToNativeType(jni, j_ice_transports_type);
1361 rtc_config.bundle_policy = JavaBundlePolicyToNativeType(jni, j_bundle_policy); 1382 rtc_config.bundle_policy = JavaBundlePolicyToNativeType(jni, j_bundle_policy);
1362 rtc_config.rtcp_mux_policy = 1383 rtc_config.rtcp_mux_policy =
1363 JavaRtcpMuxPolicyToNativeType(jni, j_rtcp_mux_policy); 1384 JavaRtcpMuxPolicyToNativeType(jni, j_rtcp_mux_policy);
1364 rtc_config.tcp_candidate_policy = 1385 rtc_config.tcp_candidate_policy =
1365 JavaTcpCandidatePolicyToNativeType(jni, j_tcp_candidate_policy); 1386 JavaTcpCandidatePolicyToNativeType(jni, j_tcp_candidate_policy);
1366 JavaIceServersToJsepIceServers(jni, j_ice_servers, &rtc_config.servers); 1387 JavaIceServersToJsepIceServers(jni, j_ice_servers, &rtc_config.servers);
1367 rtc_config.audio_jitter_buffer_max_packets = 1388 rtc_config.audio_jitter_buffer_max_packets =
1368 GetIntField(jni, j_rtc_config, j_audio_jitter_buffer_max_packets_id); 1389 GetIntField(jni, j_rtc_config, j_audio_jitter_buffer_max_packets_id);
1369 rtc_config.audio_jitter_buffer_fast_accelerate = GetBooleanField( 1390 rtc_config.audio_jitter_buffer_fast_accelerate = GetBooleanField(
1370 jni, j_rtc_config, j_audio_jitter_buffer_fast_accelerate_id); 1391 jni, j_rtc_config, j_audio_jitter_buffer_fast_accelerate_id);
1371 1392
1393 // Create ECDSA certificate.
1394 if (JavaKeyTypeToNativeType(jni, j_key_type) == rtc::KT_ECDSA) {
1395 scoped_ptr<rtc::SSLIdentity> ssl_identity(
1396 rtc::SSLIdentity::Generate(kIdentityName, rtc::KT_ECDSA));
1397 if (ssl_identity.get()) {
1398 rtc_config.certificates.push_back(
1399 rtc::RTCCertificate::Create(ssl_identity.Pass()));
1400 LOG(LS_INFO) << "ECDSA certificate created.";
1401 } else {
1402 // Failing to create certificate should not abort peer connection
1403 // creation. Instead default encryption (currently RSA) will be used.
1404 LOG(LS_WARNING) <<
1405 "Failed to generate SSLIdentity. Default encryption will be used.";
1406 }
1407 }
1408
1372 PCOJava* observer = reinterpret_cast<PCOJava*>(observer_p); 1409 PCOJava* observer = reinterpret_cast<PCOJava*>(observer_p);
1373 observer->SetConstraints(new ConstraintsWrapper(jni, j_constraints)); 1410 observer->SetConstraints(new ConstraintsWrapper(jni, j_constraints));
1374 rtc::scoped_refptr<PeerConnectionInterface> pc(f->CreatePeerConnection( 1411 rtc::scoped_refptr<PeerConnectionInterface> pc(f->CreatePeerConnection(
1375 rtc_config, observer->constraints(), NULL, NULL, observer)); 1412 rtc_config, observer->constraints(), NULL, NULL, observer));
1376 return (jlong)pc.release(); 1413 return (jlong)pc.release();
1377 } 1414 }
1378 1415
1379 static rtc::scoped_refptr<PeerConnectionInterface> ExtractNativePC( 1416 static rtc::scoped_refptr<PeerConnectionInterface> ExtractNativePC(
1380 JNIEnv* jni, jobject j_pc) { 1417 JNIEnv* jni, jobject j_pc) {
1381 jfieldID native_pc_id = GetFieldID(jni, 1418 jfieldID native_pc_id = GetFieldID(jni,
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 } 1742 }
1706 1743
1707 JOW(void, VideoTrack_nativeRemoveRenderer)( 1744 JOW(void, VideoTrack_nativeRemoveRenderer)(
1708 JNIEnv* jni, jclass, 1745 JNIEnv* jni, jclass,
1709 jlong j_video_track_pointer, jlong j_renderer_pointer) { 1746 jlong j_video_track_pointer, jlong j_renderer_pointer) {
1710 reinterpret_cast<VideoTrackInterface*>(j_video_track_pointer)->RemoveRenderer( 1747 reinterpret_cast<VideoTrackInterface*>(j_video_track_pointer)->RemoveRenderer(
1711 reinterpret_cast<VideoRendererInterface*>(j_renderer_pointer)); 1748 reinterpret_cast<VideoRendererInterface*>(j_renderer_pointer));
1712 } 1749 }
1713 1750
1714 } // namespace webrtc_jni 1751 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « talk/app/webrtc/java/jni/classreferenceholder.cc ('k') | talk/app/webrtc/java/src/org/webrtc/PeerConnection.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698