List of usage examples for android.security KeyChain EXTRA_NAME
String EXTRA_NAME
To view the source code for android.security KeyChain EXTRA_NAME.
Click Source Link
From source file:org.strongswan.android.ui.VpnProfileImportActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mDataSource = new VpnProfileDataSource(this); mDataSource.open();//from ww w . j a v a 2 s .co m setContentView(R.layout.profile_import_view); mExistsWarning = (TextView) findViewById(R.id.exists_warning); mBasicDataGroup = (ViewGroup) findViewById(R.id.basic_data_group); mName = (TextView) findViewById(R.id.name); mGateway = (TextView) findViewById(R.id.gateway); mSelectVpnType = (TextView) findViewById(R.id.vpn_type); mUsernamePassword = (ViewGroup) findViewById(R.id.username_password_group); mUsername = (EditText) findViewById(R.id.username); mUsernameWrap = (TextInputLayoutHelper) findViewById(R.id.username_wrap); mPassword = (EditText) findViewById(R.id.password); mUserCertificate = (ViewGroup) findViewById(R.id.user_certificate_group); mSelectUserCert = (RelativeLayout) findViewById(R.id.select_user_certificate); mImportUserCert = (Button) findViewById(R.id.import_user_certificate); mRemoteCertificate = (ViewGroup) findViewById(R.id.remote_certificate_group); mRemoteCert = (RelativeLayout) findViewById(R.id.remote_certificate); mExistsWarning.setVisibility(View.GONE); mBasicDataGroup.setVisibility(View.GONE); mUsernamePassword.setVisibility(View.GONE); mUserCertificate.setVisibility(View.GONE); mRemoteCertificate.setVisibility(View.GONE); mSelectUserCert.setOnClickListener(new SelectUserCertOnClickListener()); mImportUserCert.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = KeyChain.createInstallIntent(); intent.putExtra(KeyChain.EXTRA_NAME, getString(R.string.profile_cert_alias, mProfile.getName())); intent.putExtra(KeyChain.EXTRA_PKCS12, mProfile.PKCS12); startActivityForResult(intent, INSTALL_PKCS12); } }); Intent intent = getIntent(); String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { loadProfile(getIntent().getData()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Intent openIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); openIntent.setType("*/*"); startActivityForResult(openIntent, OPEN_DOCUMENT); } if (savedInstanceState != null) { mUserCertLoading = savedInstanceState.getString(VpnProfileDataSource.KEY_USER_CERTIFICATE); if (mUserCertLoading != null) { getLoaderManager().initLoader(USER_CERT_LOADER, null, mUserCertificateLoaderCallbacks); } mImportUserCert.setEnabled(!savedInstanceState.getBoolean(PKCS12_INSTALLED)); } }
From source file:eu.operando.proxy.OperandoProxyStatus.java
private void installCert() throws RootCertificateException, GeneralSecurityException, OperatorCreationException, IOException { new AsyncTask<Void, Void, Certificate>() { Exception error;// www . j av a2 s . c o m ProgressDialog dialog; @Override protected void onPreExecute() { dialog = ProgressDialog.show(MainProxyActivity.this, null, "Generating SSL certificate..."); dialog.setCancelable(false); } @Override protected Certificate doInBackground(Void... params) { try { Certificate cert = BouncyCastleSslEngineSource .initializeKeyStoreStatic(mainContext.getAuthority()); return cert; } catch (Exception e) { error = e; return null; } } @Override protected void onPostExecute(Certificate certificate) { dialog.dismiss(); if (certificate != null) { Intent intent = KeyChain.createInstallIntent(); try { intent.putExtra(KeyChain.EXTRA_CERTIFICATE, certificate.getEncoded()); } catch (CertificateEncodingException e) { e.printStackTrace(); } intent.putExtra(KeyChain.EXTRA_NAME, mainContext.getAuthority().commonName()); startActivityForResult(intent, 1); } else { Toast.makeText(MainProxyActivity.this, "Failed to load certificates, exiting: " + error.getMessage(), Toast.LENGTH_LONG) .show(); finish(); } } }.execute(); }
From source file:nl.nikhef.eduroam.WiFiEduroam.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) // Step 1 for android 4.0 - 4.2 private void installCertificates() { // Install the CA certificate updateStatus("Inputting CA certificate."); Intent intent = KeyChain.createInstallIntent(); intent.putExtra(KeyChain.EXTRA_NAME, ca_name); intent.putExtra(KeyChain.EXTRA_CERTIFICATE, Base64.decode(ca.replaceAll("-----(BEGIN|END) CERTIFICATE-----", ""))); startActivityForResult(intent, 1);/* w ww . j av a2s .com*/ }
From source file:nl.nikhef.eduroam.WiFiEduroam.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) // Step 3 for android 4.0 - 4.2 private void installClientCertificate() { try {/*w w w . j a v a 2 s . c om*/ updateStatus("Inputting client certificate."); // Parse the certificate that we got from the server CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); InputStream in = new ByteArrayInputStream( Base64.decode(certificate.replaceAll("-----(BEGIN|END) CERTIFICATE-----", ""))); X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in); client_cert_name = ssid + " " + INT_CLIENT_CERT_NAME; // Create a pkcs12 certificate/private key combination Security.addProvider(new BouncyCastleProvider()); KeyStore keystore = KeyStore.getInstance("PKCS12", "BC"); keystore.load(null, null); Certificate chain[] = new Certificate[] { (Certificate) cert }; keystore.setKeyEntry(client_cert_name, csr.getPrivate(), null, chain); ByteArrayOutputStream out = new ByteArrayOutputStream(); keystore.store(out, ssid.toCharArray()); out.flush(); byte[] buffer = out.toByteArray(); out.close(); // Install the private key/client certificate combination Intent intent = KeyChain.createInstallIntent(); intent.putExtra(KeyChain.EXTRA_NAME, ssid + " " + INT_CLIENT_CERT_NAME); intent.putExtra(KeyChain.EXTRA_PKCS12, buffer); startActivityForResult(intent, 3); } catch (CertificateException e) { e.printStackTrace(); throw new RuntimeException("Certificate error."); } catch (KeyStoreException e) { e.printStackTrace(); System.out.println(e.getMessage()); throw new RuntimeException("Certificate error: KeyStore"); } catch (NoSuchProviderException e) { e.printStackTrace(); throw new RuntimeException("Certificate error: Provider"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new RuntimeException("Certificate error: Algorithm"); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("Certificate error: IO"); } }
From source file:eu.operando.operandoapp.OperandoProxyStatus.java
private void installCert() throws RootCertificateException, GeneralSecurityException, OperatorCreationException, IOException { new AsyncTask<Void, Void, Certificate>() { Exception error;//from w ww. j ava 2 s . com ProgressDialog dialog; @Override protected void onPreExecute() { dialog = ProgressDialog.show(MainActivity.this, null, "Generating SSL certificate..."); dialog.setCancelable(false); } @Override protected Certificate doInBackground(Void... params) { try { Certificate cert = BouncyCastleSslEngineSource .initializeKeyStoreStatic(mainContext.getAuthority()); return cert; } catch (Exception e) { error = e; return null; } } @Override protected void onPostExecute(Certificate certificate) { dialog.dismiss(); if (certificate != null) { Intent intent = KeyChain.createInstallIntent(); try { intent.putExtra(KeyChain.EXTRA_CERTIFICATE, certificate.getEncoded()); } catch (CertificateEncodingException e) { e.printStackTrace(); } intent.putExtra(KeyChain.EXTRA_NAME, mainContext.getAuthority().commonName()); startActivityForResult(intent, 1); } else { Toast.makeText(MainActivity.this, "Failed to load certificates, exiting: " + error.getMessage(), Toast.LENGTH_LONG).show(); finish(); } } }.execute(); }
From source file:nu.yona.app.ui.YonaActivity.java
private void showInstallAlert(final byte[] keystore) { if (userPreferences.getString(PreferenceConstant.PROFILE_UUID, null) != null) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.certificate_installation)); builder.setMessage(getString(R.string.certfiicate_installtion_detail)); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override/*from w ww . ja va 2 s .co m*/ public void onClick(DialogInterface dialog, int which) { isToDisplayLogin = false; Intent installIntent = KeyChain.createInstallIntent(); installIntent.putExtra(KeyChain.EXTRA_CERTIFICATE, keystore); installIntent.putExtra(KeyChain.EXTRA_NAME, getString(R.string.appname)); startActivityForResult(installIntent, INSTALL_CERTIFICATE); } }); builder.setCancelable(false); builder.create().show(); } else { checkVPN(); } }