Search in sources :

Example 1 with LovelyStandardDialog

use of com.yarolegovich.lovelydialog.LovelyStandardDialog in project talk-android by nextcloud.

the class MainActivity method showCertificateDialog.

public void showCertificateDialog(X509Certificate cert, MagicTrustManager magicTrustManager, @Nullable SslErrorHandler sslErrorHandler) {
    DateFormat formatter = DateFormat.getDateInstance(DateFormat.LONG);
    String validFrom = formatter.format(cert.getNotBefore());
    String validUntil = formatter.format(cert.getNotAfter());
    String issuedBy = cert.getIssuerDN().toString();
    String issuedFor;
    try {
        if (cert.getSubjectAlternativeNames() != null) {
            StringBuilder stringBuilder = new StringBuilder();
            for (Object o : cert.getSubjectAlternativeNames()) {
                List list = (List) o;
                int type = (Integer) list.get(0);
                if (type == 2) {
                    String name = (String) list.get(1);
                    stringBuilder.append("[").append(type).append("]").append(name).append(" ");
                }
            }
            issuedFor = stringBuilder.toString();
        } else {
            issuedFor = cert.getSubjectDN().getName();
        }
        @SuppressLint("StringFormatMatches") String dialogText = String.format(getResources().getString(R.string.nc_certificate_dialog_text), issuedBy, issuedFor, validFrom, validUntil);
        new LovelyStandardDialog(this).setTopColorRes(R.color.nc_darkRed).setNegativeButtonColorRes(R.color.nc_darkRed).setPositiveButtonColorRes(R.color.colorPrimaryDark).setIcon(R.drawable.ic_security_white_24dp).setTitle(R.string.nc_certificate_dialog_title).setMessage(dialogText).setPositiveButton(R.string.nc_yes, v -> {
            magicTrustManager.addCertInTrustStore(cert);
            if (sslErrorHandler != null) {
                sslErrorHandler.proceed();
            }
        }).setNegativeButton(R.string.nc_no, view1 -> {
            if (sslErrorHandler != null) {
                sslErrorHandler.cancel();
            }
        }).show();
    } catch (CertificateParsingException e) {
        Log.d(TAG, "Failed to parse the certificate");
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) AutoInjector(autodagger.AutoInjector) Bundle(android.os.Bundle) UserUtils(com.nextcloud.talk.utils.database.user.UserUtils) ButterKnife(butterknife.ButterKnife) CertificateParsingException(java.security.cert.CertificateParsingException) Conductor(com.bluelinelabs.conductor.Conductor) SqlCipherDatabaseSource(io.requery.android.sqlcipher.SqlCipherDatabaseSource) CertificateEvent(com.nextcloud.talk.events.CertificateEvent) MagicTrustManager(com.nextcloud.talk.utils.ssl.MagicTrustManager) BindView(butterknife.BindView) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) SslErrorHandler(android.webkit.SslErrorHandler) ActionBarProvider(com.nextcloud.talk.controllers.base.providers.ActionBarProvider) EventBus(org.greenrobot.eventbus.EventBus) LovelyStandardDialog(com.yarolegovich.lovelydialog.LovelyStandardDialog) ServerSelectionController(com.nextcloud.talk.controllers.ServerSelectionController) Persistable(io.requery.Persistable) Log(android.util.Log) DateFormat(java.text.DateFormat) MagicBottomNavigationController(com.nextcloud.talk.controllers.MagicBottomNavigationController) R(com.nextcloud.talk.R) ThreadMode(org.greenrobot.eventbus.ThreadMode) ReactiveEntityStore(io.requery.reactivex.ReactiveEntityStore) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) List(java.util.List) Subscribe(org.greenrobot.eventbus.Subscribe) Toolbar(android.support.v7.widget.Toolbar) Router(com.bluelinelabs.conductor.Router) Nullable(android.support.annotation.Nullable) NextcloudTalkApplication(com.nextcloud.talk.application.NextcloudTalkApplication) RouterTransaction(com.bluelinelabs.conductor.RouterTransaction) CertificateParsingException(java.security.cert.CertificateParsingException) DateFormat(java.text.DateFormat) SuppressLint(android.annotation.SuppressLint) List(java.util.List) SuppressLint(android.annotation.SuppressLint) LovelyStandardDialog(com.yarolegovich.lovelydialog.LovelyStandardDialog)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 Toolbar (android.support.v7.widget.Toolbar)1 Log (android.util.Log)1 ViewGroup (android.view.ViewGroup)1 SslErrorHandler (android.webkit.SslErrorHandler)1 AutoInjector (autodagger.AutoInjector)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1 Conductor (com.bluelinelabs.conductor.Conductor)1 Router (com.bluelinelabs.conductor.Router)1 RouterTransaction (com.bluelinelabs.conductor.RouterTransaction)1 HorizontalChangeHandler (com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)1 R (com.nextcloud.talk.R)1 NextcloudTalkApplication (com.nextcloud.talk.application.NextcloudTalkApplication)1 MagicBottomNavigationController (com.nextcloud.talk.controllers.MagicBottomNavigationController)1 ServerSelectionController (com.nextcloud.talk.controllers.ServerSelectionController)1 ActionBarProvider (com.nextcloud.talk.controllers.base.providers.ActionBarProvider)1