Example usage for java.security.cert CertificateException printStackTrace

List of usage examples for java.security.cert CertificateException printStackTrace

Introduction

In this page you can find the example usage for java.security.cert CertificateException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

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 {//from   ww w  .  j ava2  s.c o  m
        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:com.bzcentre.dapiPush.DapiReceiver.java

public DapiReceiver() {
    try {//from   w ww  .j ava 2  s.  c  o m
        fcmProxy = FcmProxy.prepareClient();
        dbconn = connectMySql();
        stmt = dbconn.createStatement();
        BLKCheck = dbconn.createStatement();
        serverSentEventSubscribers = Collections.newSetFromMap(new ConcurrentHashMap<>());
        NginxClojureRT.getAppEventListenerManager().addListener(this);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e1) {
        NginxClojureRT.log.info(TAG + "Database connecting failed..." + e1.getMessage());
    } catch (CertificateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.taobao.android.FastPatchTool.java

public void doPatch() throws IOException, PatchException, RecognitionException {
    MappingReader mappingReader = null;//from ww w  . java  2  s . c  om
    MappingProcessor mappingProcessor = null;

    if (outDir == null || !outDir.exists()) {
        return;
    }
    outPatchFile = new File(outDir, "apatch-unsigned.apatch");

    if (mappingFile != null && mappingFile.exists()) {
        mappingReader = new MappingReader(mappingFile);
        mappingProcessor = new MappingProcessorImpl(superClassMap);
        mappingReader.pump(mappingProcessor);
        mappingProcessor.updateMethod();
        mappingProcessor.updateFieldType();
    }

    for (FastPatchObject fastPatchObject : patchObjects) {
        Set<ClassDef> classes = new HashSet<ClassDef>();
        Map<ClassDef, List<Method>> patchClassDefs = new HashMap<ClassDef, List<Method>>();
        Set<ClassDef> addedClasses = new HashSet<ClassDef>();
        Map<ClassDef, List<Method>> newClassDef = new HashMap<ClassDef, List<Method>>();

        ArrayList<Method> methods = new ArrayList<Method>();

        for (File dexFile : fastPatchObject.DexFiles) {
            DexFile dFile = DexFileFactory.loadDexFile(dexFile.getAbsolutePath(), 19, true);
            classes.addAll(dFile.getClasses());
        }
        final Set<ClassDef> newClasses = new HashSet<ClassDef>();
        for (ClassDef classDef : classes) {
            String type = classDef.getType();
            if (fastPatchObject.addedClass.contains(SmaliUtils.getDalvikClassName(type))) {
                System.out.println("patch added class:" + type);
                addedClasses.add(classDef);
                continue;
            }
            for (Map.Entry<String, List<String>> entry : fastPatchObject.modifyClasses.entrySet()) {
                if (entry.getKey().equals(SmaliUtils.getDalvikClassName(type))) {
                    ArrayList<Method> newMethods = new ArrayList<Method>();
                    for (Method method : classDef.getMethods()) {
                        System.err.println(getMethodFullName(method));
                        if (entry.getValue().contains(getMethodFullName(method))) {
                            newMethods.add(method);
                        }

                    }
                    patchClassDefs.put(classDef, newMethods);
                    break;
                }
            }
        }
        if (patchClassDefs.size() == 0 && addedClasses.size() == 0) {
            continue;
        }

        if (mappingFile != null && mappingFile.exists()) {
            //prepareclass
            for (String className : fastPatchObject.prepareClasses) {
                ApkPatch.prepareClasses.add(mappingProcessor.getNewClassName(className).className);
            }
            //replaceanatation
            MethodReplaceAnnotation.ANNOTATION = DefineUtils
                    .getDefineClassName(mappingProcessor.getNewClassName(DefineUtils.getDalvikClassName(
                            "Lcom/alipay/euler/andfix/annotation/MethodReplace;")).className, false);
            //dex?
            InsTructionsReIClassDef insTructionsReDef = new InsTructionsReIClassDef(
                    new MappingClassProcessor(mappingProcessor));
            for (ClassDef c : classes) {
                if (patchClassDefs.containsKey(c)) {
                    for (Method method : c.getMethods()) {
                        if (patchClassDefs.get(c).contains(method)) {
                            methods.add(insTructionsReDef.reMethod(method));
                        }
                    }
                    newClassDef.put(insTructionsReDef.reClassDef(c), methods);
                } else if (addedClasses.contains(c)) {
                    newClassDef.put(insTructionsReDef.reClassDef(c), new ArrayList<Method>());
                }
                if (c.getType().contains("/R$")) {
                    continue;
                }
                newClasses.add(insTructionsReDef.reClassDef(c));
            }

        } else {
            ApkPatch.prepareClasses.addAll(fastPatchObject.prepareClasses);
        }

        File patchDexFile = new File(outDir, "patch.dex");
        for (ClassDef classDef : newClassDef.keySet()) {
            System.out.println("modify class:" + classDef.getType());
        }
        if (newClassDef.size() > 0) {
            DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(),
                    new ImmutableDexFile(newClassDef.keySet()));
        } else if (patchClassDefs.size() > 0) {
            DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(),
                    new ImmutableDexFile(patchClassDefs.keySet()));
        }

        File tempDexFile = new File(outDir, "temp.dex");
        if (newClasses.size() > 0) {
            DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new DexFile() {
                @Nonnull
                @Override
                public Set<? extends ClassDef> getClasses() {
                    return new AbstractSet<ClassDef>() {
                        @Nonnull
                        @Override
                        public Iterator<ClassDef> iterator() {
                            return newClasses.iterator();
                        }

                        @Override
                        public int size() {
                            return newClasses.size();
                        }
                    };
                }
            });
        } else if (classes.size() > 0) {
            DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new ImmutableDexFile(classes));

        }

        SmaliDiffUtils.scanClasses(new File(outDir, "smali2"), Lists.newArrayList(tempDexFile));

        DexFile patchDex = DexFileFactory.loadDexFile(patchDexFile.getAbsolutePath(), 19, true);
        DexFile tempDex = DexFileFactory.loadDexFile(tempDexFile.getAbsolutePath(), 19, true);
        Set<? extends ClassDef> patchClasses = patchDex.getClasses();
        DexDiffInfo dexDiffInfo = new DexDiffInfo();
        for (ClassDef patchClassDef : patchClasses) {
            String type = patchClassDef.getType();
            if (fastPatchObject.addedClass.contains(SmaliUtils.getDalvikClassName(type))) {
                dexDiffInfo.getAddedClasses().add((DexBackedClassDef) patchClassDef);
                dexDiffInfo.addManifestAddClass(type);
                continue;
            }

            for (Method method : patchClassDef.getMethods()) {
                List<? extends CharSequence> parameters = method.getParameterTypes();
                if (methods.size() > 0) {
                    for (Method modifyMethod : methods) {
                        List<? extends CharSequence> modifyParameters = modifyMethod.getParameterTypes();
                        if (parameters.size() != modifyParameters.size()
                                || !isEqualObj(parameters, modifyParameters)) {
                            continue;
                        }

                        if (modifyMethod.getName().equals(method.getName()))
                            dexDiffInfo.addModifiedMethods((DexBackedMethod) method);
                    }
                } else if (patchClassDefs.size() > 0) {
                    for (ClassDef classDef : patchClassDefs.keySet()) {
                        if (classDef.getType().equals(patchClassDef.getType())) {
                            List<Method> methodList = patchClassDefs.get(classDef);
                            for (Method method1 : methodList) {
                                if (method1.getName().equals(method.getName())) {
                                    dexDiffInfo.addModifiedMethods((DexBackedMethod) method);
                                }
                            }
                        }
                    }

                }
            }
        }
        FastBuild fastBuild = new FastBuild(fastPatchObject.bundleName, new File(outDir, bundleName));
        fastBuild.setClasses(tempDex.getClasses());
        fastBuild.setDiffInfo(dexDiffInfo);
        new AndFixFilterImpl(dexDiffInfo).filterDex();
        dexDiffInfo.update();
        APatchTool.isApatch = true;
        File adiffFile = new File(outDir, "apatch-diff.txt");
        File adiffJsonFile = new File(outDir, "apatch-diff.json");
        dexDiffInfo.writeToFile(fastPatchObject.bundleName, adiffFile, adiffJsonFile);
        try {
            File patchJarFile = fastBuild.dopatch();
            patchJarFiles.add(patchJarFile);
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (UnrecoverableEntryException e) {
            e.printStackTrace();
        }
    }

    File[] aPatchFiles = new File[patchJarFiles.size()];
    aPatchFiles = patchJarFiles.toArray(aPatchFiles);
    File mergePatchFile = null;
    if (null != aPatchFiles && aPatchFiles.length > 1) {
        MergePatch mergePatch = new MergePatch(aPatchFiles, "com_taobao_android", outDir);
        mergePatchFile = mergePatch.doMerge();
    } else if (null != aPatchFiles && aPatchFiles.length == 1) {
        mergePatchFile = aPatchFiles[0];
    }
    if (null != mergePatchFile && mergePatchFile.exists()) {
        FileUtils.moveFile(mergePatchFile, outPatchFile);
    }

}

From source file:com.taobao.android.tools.FastPatchTool.java

public void doPatch() throws IOException, PatchException, RecognitionException {
    MappingReader mappingReader = null;//from  w w w  .ja v  a  2s.c  o m
    MappingProcessor mappingProcessor = null;

    if (outDir == null || !outDir.exists()) {
        return;
    }
    outPatchFile = new File(outDir, "apatch-unsigned.apatch");

    if (mappingFile != null && mappingFile.exists()) {
        mappingReader = new MappingReader(mappingFile);
        mappingProcessor = new MappingProcessorImpl(superClassMap);
        mappingReader.pump(mappingProcessor);
        mappingProcessor.updateMethod();
        mappingProcessor.updateFieldType();
    }

    for (FastPatchObject fastPatchObject : patchObjects) {
        Set<ClassDef> classes = new HashSet<ClassDef>();
        Map<ClassDef, List<Method>> patchClassDefs = new HashMap<ClassDef, List<Method>>();
        Set<ClassDef> addedClasses = new HashSet<ClassDef>();
        Map<ClassDef, List<Method>> newClassDef = new HashMap<ClassDef, List<Method>>();

        ArrayList<Method> methods = new ArrayList<Method>();

        for (File dexFile : fastPatchObject.DexFiles) {
            DexFile dFile = DexFileFactory.loadDexFile(dexFile.getAbsolutePath(), Opcodes.getDefault());
            classes.addAll(dFile.getClasses());
        }
        final Set<ClassDef> newClasses = new HashSet<ClassDef>();
        for (ClassDef classDef : classes) {
            String type = classDef.getType();
            if (fastPatchObject.addedClass.contains(SmaliUtils.getDalvikClassName(type))) {
                System.out.println("patch added class:" + type);
                addedClasses.add(classDef);
                continue;
            }
            for (Map.Entry<String, List<String>> entry : fastPatchObject.modifyClasses.entrySet()) {
                if (entry.getKey().equals(SmaliUtils.getDalvikClassName(type))) {
                    ArrayList<Method> newMethods = new ArrayList<Method>();
                    for (Method method : classDef.getMethods()) {
                        System.err.println(getMethodFullName(method));
                        if (entry.getValue().contains(getMethodFullName(method))) {
                            newMethods.add(method);
                        }

                    }
                    patchClassDefs.put(classDef, newMethods);
                    break;
                }
            }
        }
        if (patchClassDefs.size() == 0 && addedClasses.size() == 0) {
            continue;
        }

        if (mappingFile != null && mappingFile.exists()) {
            //prepareclass
            for (String className : fastPatchObject.prepareClasses) {
                ApkPatch.prepareClasses.add(mappingProcessor.getNewClassName(className).className);
            }
            //replaceanatation
            MethodReplaceAnnotation.ANNOTATION = DefineUtils
                    .getDefineClassName(mappingProcessor.getNewClassName(DefineUtils.getDalvikClassName(
                            "Lcom/alipay/euler/andfix/annotation/MethodReplace;")).className, false);
            //dex?
            InsTructionsReIClassDef insTructionsReDef = new InsTructionsReIClassDef(
                    new MappingClassProcessor(mappingProcessor));
            for (ClassDef c : classes) {
                if (patchClassDefs.containsKey(c)) {
                    for (Method method : c.getMethods()) {
                        if (patchClassDefs.get(c).contains(method)) {
                            methods.add(insTructionsReDef.reMethod(method));
                        }
                    }
                    newClassDef.put(insTructionsReDef.reClassDef(c), methods);
                } else if (addedClasses.contains(c)) {
                    newClassDef.put(insTructionsReDef.reClassDef(c), new ArrayList<Method>());
                }
                if (c.getType().contains("/R$")) {
                    continue;
                }
                newClasses.add(insTructionsReDef.reClassDef(c));
            }

        } else {
            ApkPatch.prepareClasses.addAll(fastPatchObject.prepareClasses);
        }

        File patchDexFile = new File(outDir, "patch.dex");
        for (ClassDef classDef : newClassDef.keySet()) {
            System.out.println("modify class:" + classDef.getType());
        }
        if (newClassDef.size() > 0) {
            DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(),
                    new ImmutableDexFile(Opcodes.getDefault(), newClassDef.keySet()));
        } else if (patchClassDefs.size() > 0) {
            DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(),
                    new ImmutableDexFile(Opcodes.getDefault(), patchClassDefs.keySet()));
        }

        File tempDexFile = new File(outDir, "temp.dex");
        if (newClasses.size() > 0) {
            DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new DexFile() {
                @Nonnull
                @Override
                public Set<? extends ClassDef> getClasses() {
                    return new AbstractSet<ClassDef>() {
                        @Nonnull
                        @Override
                        public Iterator<ClassDef> iterator() {
                            return newClasses.iterator();
                        }

                        @Override
                        public int size() {
                            return newClasses.size();
                        }
                    };
                }

                @Nonnull
                @Override
                public Opcodes getOpcodes() {
                    return Opcodes.getDefault();
                }
            });
        } else if (classes.size() > 0) {
            DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(),
                    new ImmutableDexFile(Opcodes.getDefault(), classes));

        }

        SmaliDiffUtils.scanClasses(new File(outDir, "smali2"), Lists.newArrayList(tempDexFile));

        DexFile patchDex = DexFileFactory.loadDexFile(patchDexFile.getAbsolutePath(), Opcodes.getDefault());
        DexFile tempDex = DexFileFactory.loadDexFile(tempDexFile.getAbsolutePath(), Opcodes.getDefault());
        Set<? extends ClassDef> patchClasses = patchDex.getClasses();
        DexDiffInfo dexDiffInfo = new DexDiffInfo();
        for (ClassDef patchClassDef : patchClasses) {
            String type = patchClassDef.getType();
            if (fastPatchObject.addedClass.contains(SmaliUtils.getDalvikClassName(type))) {
                dexDiffInfo.getAddedClasses().add((DexBackedClassDef) patchClassDef);
                dexDiffInfo.addManifestAddClass(type);
                continue;
            }

            for (Method method : patchClassDef.getMethods()) {
                List<? extends CharSequence> parameters = method.getParameterTypes();
                if (methods.size() > 0) {
                    for (Method modifyMethod : methods) {
                        List<? extends CharSequence> modifyParameters = modifyMethod.getParameterTypes();
                        if (parameters.size() != modifyParameters.size()
                                || !isEqualObj(parameters, modifyParameters)) {
                            continue;
                        }

                        if (modifyMethod.getName().equals(method.getName()))
                            dexDiffInfo.addModifiedMethods((DexBackedMethod) method);
                    }
                } else if (patchClassDefs.size() > 0) {
                    for (ClassDef classDef : patchClassDefs.keySet()) {
                        if (classDef.getType().equals(patchClassDef.getType())) {
                            List<Method> methodList = patchClassDefs.get(classDef);
                            for (Method method1 : methodList) {
                                if (method1.getName().equals(method.getName())) {
                                    dexDiffInfo.addModifiedMethods((DexBackedMethod) method);
                                }
                            }
                        }
                    }

                }
            }
        }
        FastBuild fastBuild = new FastBuild(fastPatchObject.bundleName, new File(outDir, bundleName));
        fastBuild.setClasses(tempDex.getClasses());
        fastBuild.setDiffInfo(dexDiffInfo);
        new AndFixFilterImpl(dexDiffInfo).filterDex();
        dexDiffInfo.update();
        File adiffFile = new File(outDir, "apatch-diff.txt");
        File adiffJsonFile = new File(outDir, "apatch-diff.json");
        dexDiffInfo.writeToFile(fastPatchObject.bundleName, adiffFile, adiffJsonFile);
        try {
            File patchJarFile = fastBuild.dopatch();
            patchJarFiles.add(patchJarFile);
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (UnrecoverableEntryException e) {
            e.printStackTrace();
        }
    }

    File[] aPatchFiles = new File[patchJarFiles.size()];
    aPatchFiles = patchJarFiles.toArray(aPatchFiles);
    File mergePatchFile = null;
    if (null != aPatchFiles && aPatchFiles.length > 1) {
        MergePatch mergePatch = new MergePatch(aPatchFiles, "com_taobao_android", outDir);
        mergePatchFile = mergePatch.doMerge();
    } else if (null != aPatchFiles && aPatchFiles.length == 1) {
        mergePatchFile = aPatchFiles[0];
    }
    if (null != mergePatchFile && mergePatchFile.exists()) {
        FileUtils.moveFile(mergePatchFile, outPatchFile);
    }

}

From source file:com.quarterfull.newsAndroid.ssl.MemorizingTrustManager.java

public void checkCertTrusted(X509Certificate[] chain, String authType, boolean isServer)
        throws CertificateException {
    Log.d(TAG, "checkCertTrusted(" + Arrays.toString(chain) + ", " + authType + ", " + isServer + ")");
    try {//from   w w w .  j a va 2s.co  m
        Log.d(TAG, "checkCertTrusted: trying defaultTrustManager");
        if (isServer)
            defaultTrustManager.checkServerTrusted(chain, authType);
        else
            defaultTrustManager.checkClientTrusted(chain, authType);
    } catch (CertificateException ae) {
        try {
            Log.d(TAG, "checkCertTrusted: trying appTrustManager");
            if (isServer)
                appTrustManager.checkServerTrusted(chain, authType);
            else
                appTrustManager.checkClientTrusted(chain, authType);
        } catch (CertificateException e) {
            // if the cert is stored in our appTrustManager, we ignore expiredness
            if (isExpiredException(e)) {
                Log.i(TAG, "checkCertTrusted: accepting expired certificate from keystore");
                return;
            }
            if (isCertKnown(chain[0])) {
                Log.i(TAG, "checkCertTrusted: accepting cert already stored in keystore");
                return;
            }
            e.printStackTrace();
            interact(chain, e);
        }
    }
}

From source file:se.leap.bitmaskclient.ProviderAPI.java

private boolean loadCertificate(String cert_string) {
    try {//from   w ww  .  ja  v a2 s  . c  o m
        // API returns concatenated cert & key.  Split them for OpenVPN options
        String certificateString = null, keyString = null;
        String[] certAndKey = cert_string.split("(?<=-\n)");
        for (int i = 0; i < certAndKey.length - 1; i++) {
            if (certAndKey[i].contains("KEY")) {
                keyString = certAndKey[i++] + certAndKey[i];
            } else if (certAndKey[i].contains("CERTIFICATE")) {
                certificateString = certAndKey[i++] + certAndKey[i];
            }
        }

        RSAPrivateKey key = ConfigHelper.parseRsaKeyFromString(keyString);
        keyString = Base64.encodeToString(key.getEncoded(), Base64.DEFAULT);
        preferences.edit()
                .putString(Constants.PRIVATE_KEY,
                        "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----")
                .commit();

        X509Certificate certificate = ConfigHelper.parseX509CertificateFromString(certificateString);
        certificateString = Base64.encodeToString(certificate.getEncoded(), Base64.DEFAULT);
        preferences.edit()
                .putString(Constants.CERTIFICATE,
                        "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----")
                .commit();
        return true;
    } catch (CertificateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }
}

From source file:se.leap.bitmaskclient.ProviderAPI.java

/**
 * Tries to download the contents of the provided url using not commercially validated CA certificate from chosen provider.
 *
 * @param url_string as a string//  www  .  j  a v  a  2 s  .  co  m
 * @return an empty string if it fails, the url content if not.
 */
private String downloadWithProviderCA(String url_string) {
    String json_file_content = "";

    try {
        URL url = new URL(url_string);
        // Tell the URLConnection to use a SocketFactory from our SSLContext
        HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
        urlConnection.setSSLSocketFactory(getProviderSSLSocketFactory());
        if (!LeapSRPSession.getToken().isEmpty())
            urlConnection.addRequestProperty(LeapSRPSession.AUTHORIZATION_HEADER,
                    "Token token=" + LeapSRPSession.getToken());
        json_file_content = new Scanner(urlConnection.getInputStream()).useDelimiter("\\A").next();
    } catch (CertificateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnknownHostException e) {
        e.printStackTrace();
        json_file_content = formatErrorMessage(R.string.server_unreachable_message);
    } catch (IOException e) {
        // The downloaded certificate doesn't validate our https connection.
        json_file_content = formatErrorMessage(R.string.certificate_error);
    } catch (KeyStoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (KeyManagementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchElementException e) {
        e.printStackTrace();
        json_file_content = formatErrorMessage(R.string.server_unreachable_message);
    }
    return json_file_content;
}

From source file:com.azita.iot.ioclient.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.activity_main);
    all_layout = (LinearLayout) findViewById(R.id.device_control_fragment);
    Intent intent = new Intent(mContext, ConfigurationActivity.class);
    startActivity(intent);//from   www .  j  a  va 2  s.c om
    ButterKnife.bind(this);

    temphumidButton = (ToggleButton) findViewById(R.id.button4);
    aqiButton = (ToggleButton) findViewById(R.id.button5);
    motionButton = (ToggleButton) findViewById(R.id.button6);

    //        PowerBar.setBackgroundResource(R.drawable.powerbar_on_);
    //        LightingBar.setBackgroundResource(R.drawable.lighting_on_);
    //        LightingDimmer.setBackgroundResource(R.drawable.dimmer_6_);

    llTemp.setOnClickListener(this);
    llPm.setOnClickListener(this);
    llMotion.setOnClickListener(this);
    llCabinet.setOnClickListener(this);
    llDoor.setOnClickListener(this);
    llWindow.setOnClickListener(this);

    bitMask.put(R.id.button4, 1 << 3);
    bitMask.put(R.id.button5, 1 << 4);
    bitMask.put(R.id.button6, 1 << 5);
    bitMask.put(R.id.button7, 1 << 6);
    bitMask.put(R.id.button8, 1 << 7);
    bitMask.put(R.id.button9, 1 << 8);

    try {
        this.selfSignedSSLSocketFactory = new TSelfSignedSSLSocketFactory(this.getResources());
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
}

From source file:org.freebxml.omar.server.security.authentication.AuthenticationServiceImpl.java

/**
 * Get the keystore whose path is specified  by {@link #getKeyStoreFileName()}.
 * Note that all the methods that access the keystore MUST access the keystore
 * via this method. Do not access the keystore directly by accessing the keystore
 * field. Otherwise the checking the write lock to keystore will be bypassed.
 *//* ww  w  .  jav  a  2  s.  co  m*/
public KeyStore getKeyStore() throws RegistryException {
    synchronized (keyStoreWriteLock) {
        if (keyStore == null) {
            java.io.FileInputStream fis = null;

            try {
                String keystoreType = RegistryProperties.getInstance().getProperty("omar.security.keystoreType",
                        "JKS");
                keyStore = KeyStore.getInstance(keystoreType);

                String keystoreFile = getKeyStoreFileName();
                fis = new java.io.FileInputStream(keystoreFile);

                String keystorePass = getKeyStorePassword();
                keyStore.load(fis, keystorePass.toCharArray());
            } catch (java.security.cert.CertificateException e) {
                throw new RegistryException(e);
            } catch (KeyStoreException e) {
                throw new RegistryException(e);
            } catch (NoSuchAlgorithmException e) {
                throw new RegistryException(e);
            } catch (java.io.FileNotFoundException e) {
                throw new RegistryException(e);
            } catch (IOException e) {
                throw new RegistryException(e);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        return keyStore;
    }
}

From source file:it.cnr.icar.eric.server.security.authentication.AuthenticationServiceImpl.java

/**
 * Get the keystore whose path is specified by
 * {@link #getKeyStoreFileName()}. Note that all the methods that access the
 * keystore MUST access the keystore via this method. Do not access the
 * keystore directly by accessing the keystore field. Otherwise the checking
 * the write lock to keystore will be bypassed.
 *//*from w  ww.j a  v  a  2s. co m*/
public KeyStore getKeyStore() throws RegistryException {
    synchronized (keyStoreWriteLock) {
        if (keyStore == null) {
            java.io.FileInputStream fis = null;

            try {
                String keystoreType = RegistryProperties.getInstance().getProperty("eric.security.keystoreType",
                        "JKS");
                keyStore = KeyStore.getInstance(keystoreType);

                String keystoreFile = getKeyStoreFileName();
                fis = new java.io.FileInputStream(keystoreFile);

                String keystorePass = getKeyStorePassword();
                keyStore.load(fis, keystorePass.toCharArray());
            } catch (java.security.cert.CertificateException e) {
                throw new RegistryException(e);
            } catch (KeyStoreException e) {
                throw new RegistryException(e);
            } catch (NoSuchAlgorithmException e) {
                throw new RegistryException(e);
            } catch (java.io.FileNotFoundException e) {
                throw new RegistryException(e);
            } catch (IOException e) {
                throw new RegistryException(e);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        return keyStore;
    }
}