Merge branch 'dev' into dev
This commit is contained in:
commit
9f789167da
5 changed files with 189 additions and 14 deletions
|
@ -1,26 +1,42 @@
|
|||
package org.schabi.newpipe;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||
import org.schabi.newpipe.extractor.downloader.Request;
|
||||
import org.schabi.newpipe.extractor.downloader.Response;
|
||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||
import org.schabi.newpipe.util.TLSSocketFactoryCompat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import okhttp3.CipherSuite;
|
||||
import okhttp3.ConnectionSpec;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static org.schabi.newpipe.MainActivity.DEBUG;
|
||||
|
||||
public class DownloaderImpl extends Downloader {
|
||||
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
|
||||
|
||||
|
@ -29,6 +45,9 @@ public class DownloaderImpl extends Downloader {
|
|||
private OkHttpClient client;
|
||||
|
||||
private DownloaderImpl(OkHttpClient.Builder builder) {
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
|
||||
enableModernTLS(builder);
|
||||
}
|
||||
this.client = builder
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
//.cache(new Cache(new File(context.getExternalCacheDir(), "okhttp"), 16 * 1024 * 1024))
|
||||
|
@ -154,4 +173,47 @@ public class DownloaderImpl extends Downloader {
|
|||
|
||||
return new Response(response.code(), response.message(), response.headers().toMultimap(), responseBodyToReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable TLS 1.2 and 1.1 on Android Kitkat. This function is mostly taken from the documentation of
|
||||
* OkHttpClient.Builder.sslSocketFactory(_,_)
|
||||
* <p>
|
||||
* If there is an error, the function will safely fall back to doing nothing and printing the error to the console.
|
||||
*
|
||||
* @param builder The HTTPClient Builder on which TLS is enabled on (will be modified in-place)
|
||||
*/
|
||||
private static void enableModernTLS(OkHttpClient.Builder builder) {
|
||||
try {
|
||||
// get the default TrustManager
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
|
||||
TrustManagerFactory.getDefaultAlgorithm());
|
||||
trustManagerFactory.init((KeyStore) null);
|
||||
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
|
||||
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
|
||||
throw new IllegalStateException("Unexpected default trust managers:"
|
||||
+ Arrays.toString(trustManagers));
|
||||
}
|
||||
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
|
||||
|
||||
// insert our own TLSSocketFactory
|
||||
SSLSocketFactory sslSocketFactory = TLSSocketFactoryCompat.getInstance();
|
||||
|
||||
builder.sslSocketFactory(sslSocketFactory, trustManager);
|
||||
|
||||
// This will try to enable all modern CipherSuites(+2 more) that are supported on the device.
|
||||
// Necessary because some servers (e.g. Framatube.org) don't support the old cipher suites.
|
||||
// https://github.com/square/okhttp/issues/4053#issuecomment-402579554
|
||||
List<CipherSuite> cipherSuites = new ArrayList<>();
|
||||
cipherSuites.addAll(ConnectionSpec.MODERN_TLS.cipherSuites());
|
||||
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
|
||||
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
|
||||
ConnectionSpec legacyTLS = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
||||
.cipherSuites(cipherSuites.toArray(new CipherSuite[0]))
|
||||
.build();
|
||||
|
||||
builder.connectionSpecs(Arrays.asList(legacyTLS, ConnectionSpec.CLEARTEXT));
|
||||
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
|
||||
if (DEBUG) e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ import org.schabi.newpipe.util.PeertubeHelper;
|
|||
import org.schabi.newpipe.util.PermissionHelper;
|
||||
import org.schabi.newpipe.util.ServiceHelper;
|
||||
import org.schabi.newpipe.util.StateSaver;
|
||||
import org.schabi.newpipe.util.TLSSocketFactoryCompat;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -108,6 +109,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
||||
|
||||
// enable TLS1.1/1.2 for kitkat devices, to fix download and play for mediaCCC sources
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
|
||||
TLSSocketFactoryCompat.setAsDefault();
|
||||
}
|
||||
|
||||
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.InputType;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -203,17 +204,18 @@ public class PeertubeInstanceListFragment extends Fragment {
|
|||
|
||||
private void showAddItemDialog(Context c) {
|
||||
final EditText urlET = new EditText(c);
|
||||
urlET.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
|
||||
urlET.setHint(R.string.peertube_instance_add_help);
|
||||
AlertDialog dialog = new AlertDialog.Builder(c)
|
||||
.setTitle(R.string.peertube_instance_add_title)
|
||||
.setIcon(R.drawable.place_holder_peertube)
|
||||
.setView(urlET)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.finish, (dialog1, which) -> {
|
||||
String url = urlET.getText().toString();
|
||||
addInstance(url);
|
||||
})
|
||||
.create();
|
||||
dialog.setView(urlET, 50, 0, 50, 0);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
@ -237,6 +239,7 @@ public class PeertubeInstanceListFragment extends Fragment {
|
|||
|
||||
@Nullable
|
||||
private String cleanUrl(String url){
|
||||
url = url.trim();
|
||||
// if protocol not present, add https
|
||||
if(!url.startsWith("http")){
|
||||
url = "https://" + url;
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
|
||||
import static org.schabi.newpipe.MainActivity.DEBUG;
|
||||
|
||||
|
||||
/**
|
||||
* This is an extension of the SSLSocketFactory which enables TLS 1.2 and 1.1.
|
||||
* Created for usage on Android 4.1-4.4 devices, which haven't enabled those by default.
|
||||
*/
|
||||
public class TLSSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
|
||||
private static TLSSocketFactoryCompat instance = null;
|
||||
|
||||
private SSLSocketFactory internalSSLSocketFactory;
|
||||
|
||||
public static TLSSocketFactoryCompat getInstance() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
}
|
||||
return instance = new TLSSocketFactoryCompat();
|
||||
}
|
||||
|
||||
|
||||
public TLSSocketFactoryCompat() throws KeyManagementException, NoSuchAlgorithmException {
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
context.init(null, null, null);
|
||||
internalSSLSocketFactory = context.getSocketFactory();
|
||||
}
|
||||
|
||||
public TLSSocketFactoryCompat(TrustManager[] tm) throws KeyManagementException, NoSuchAlgorithmException {
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
context.init(null, tm, new java.security.SecureRandom());
|
||||
internalSSLSocketFactory = context.getSocketFactory();
|
||||
}
|
||||
|
||||
public static void setAsDefault() {
|
||||
try {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(getInstance());
|
||||
} catch (NoSuchAlgorithmException | KeyManagementException e) {
|
||||
if (DEBUG) e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getDefaultCipherSuites() {
|
||||
return internalSSLSocketFactory.getDefaultCipherSuites();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSupportedCipherSuites() {
|
||||
return internalSSLSocketFactory.getSupportedCipherSuites();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket() throws IOException {
|
||||
return enableTLSOnSocket(internalSSLSocketFactory.createSocket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
|
||||
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, host, port, autoClose));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
||||
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
|
||||
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port, localHost, localPort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress host, int port) throws IOException {
|
||||
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
||||
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(address, port, localAddress, localPort));
|
||||
}
|
||||
|
||||
private Socket enableTLSOnSocket(Socket socket) {
|
||||
if (socket != null && (socket instanceof SSLSocket)) {
|
||||
((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.1", "TLSv1.2"});
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="main_bg_subtitle">Naciśnij Szukaj, aby zacząć</string>
|
||||
<string name="install">Instaluj</string>
|
||||
<string name="install">Zainstaluj</string>
|
||||
<string name="cancel">Anuluj</string>
|
||||
<string name="open_in_browser">Otwórz w przeglądarce</string>
|
||||
<string name="share">Udostępnij</string>
|
||||
|
@ -479,18 +479,18 @@
|
|||
<string name="error_unable_to_load_comments">Nie można załadować komentarzy</string>
|
||||
<string name="close">Zamknij</string>
|
||||
<string name="enable_playback_resume_title">Wznów odtwarzanie</string>
|
||||
<string name="enable_playback_resume_summary">Przywróć pozycję odtwarzania</string>
|
||||
<string name="enable_playback_state_lists_title">Pozycje na liście</string>
|
||||
<string name="enable_playback_resume_summary">Przywróć ostatnią odtwarzaną pozycję</string>
|
||||
<string name="enable_playback_state_lists_title">Pozycje na listach</string>
|
||||
<string name="enable_playback_state_lists_summary">Pokaż wskaźniki pozycji odtwarzania na listach</string>
|
||||
<string name="settings_category_clear_data_title">Wyczyść dane</string>
|
||||
<string name="watch_history_states_deleted">Usunięto pozycję odtwarzania.</string>
|
||||
<string name="missing_file">Plik przeniesiony lub usunięty</string>
|
||||
<string name="overwrite_unrelated_warning">Plik o takiej nazwie już istnieje</string>
|
||||
<string name="overwrite_failed">Nie można nadpisać tego pliku</string>
|
||||
<string name="watch_history_states_deleted">Pozycja odtwarzania usunięta.</string>
|
||||
<string name="missing_file">Plik usunięty lub przeniesiony</string>
|
||||
<string name="overwrite_unrelated_warning">Plik z tą nazwą już istnieje</string>
|
||||
<string name="overwrite_failed">nie można nadpisać pliku</string>
|
||||
<string name="download_already_pending">Pobieranie pliku z tą nazwą jest już w kolejce</string>
|
||||
<string name="error_postprocessing_stopped">NewPipe został zamknięty w czasie pracy nad plikiem</string>
|
||||
<string name="error_insufficient_storage">Brak wystarczającej ilości miejsca na urządzeniu</string>
|
||||
<string name="error_progress_lost">Utracono postęp ponieważ plik został usunięty</string>
|
||||
<string name="error_postprocessing_stopped">NewPipe został zamknięty podczas pracy nad plikiem</string>
|
||||
<string name="error_insufficient_storage">Brak miejsca na urządzeniu</string>
|
||||
<string name="error_progress_lost">Postęp został utracony ze wzgledu na usunięcie pliku</string>
|
||||
<string name="confirm_prompt">Czy jesteś pewien\?</string>
|
||||
<string name="enable_queue_limit">Ogranicz kolejkę pobierania</string>
|
||||
<string name="enable_queue_limit_desc">Tylko jedno pobieranie będzie realizowane w danej chwili</string>
|
||||
|
@ -502,8 +502,8 @@
|
|||
<string name="downloads_storage_ask_summary_kitkat">Zostaniesz zapytany, gdzie zapisać każde pobranie.
|
||||
\nWybierz SAF, jeśli chcesz pobrać na zewnętrzną kartę SD</string>
|
||||
<string name="downloads_storage_use_saf_title">Użyj SAF</string>
|
||||
<string name="downloads_storage_use_saf_summary">Struktura dostępu do pamięci masowej umożliwia pobieranie danych na zewnętrzną kartę SD.
|
||||
\nUwaga: niektóre urządzenia nie są kompatybilne</string>
|
||||
<string name="downloads_storage_use_saf_summary">Biblioteka dostępu do pamięci pozwala na pobieranie danych na zewnętrzną kartę.
|
||||
\nUwagi: Niektóre urządzenia nie są kompatybilne</string>
|
||||
<string name="clear_playback_states_title">Usuń pozycje odtwarzania</string>
|
||||
<string name="clear_playback_states_summary">Usuwa wszystkie pozycje odtwarzania</string>
|
||||
<string name="delete_playback_states_alert">Usunąć wszystkie pozycje odtwarzania\?</string>
|
||||
|
|
Loading…
Reference in a new issue