예제 #1
0
        /**
         * Determines whether the current AppKeyPair (as specified by {@link #pemFilePathname}) is a valid X.509 certificate.
         * <br /><br />
         * Writes diagnostic messages to the console if the the current AppKeyPair does not exist or is not valid.
         * This is useful since SkypeKit currently reports only "TLS handshake failure" (with no further explanation)
         * if the certificate can't be found/accessed or is not validly formatted.
         *
         * @return
         *  <ul>
         *	  <li>true: Valid certificate file</li>
         *	  <li>false:
         *	    <ul>
         *	      <li>Could not open the file</li>
         *	      <li>Could not read the file</li>
         *	      <li>Not a valid certificate file</li>
         *	    </ul>
         *	  </li>
         *	</ul>
         *
         * @see #pemFilePathname
         * @see com.skype.tutorial.util.MySession#myClientConfiguration
         * @since 2.0
         */
        public bool isValidCertificate()
        {
            java.security.cert.X509Certificate x509CertificateData;
            java.security.PrivateKey           privateKeyData;

            String pathName = getPemFilePathname();

            try
            {
                String derPath = pathName.Substring(0, pathName.Length - 3);
                derPath += "der";

                PemReader myPemReader = new PemReader(getPemFilePathname());
                x509CertificateData = myPemReader.getCertificate();
                privateKeyData      = myPemReader.getKey();
            }
            catch (FileNotFoundException e1)
            {
                MySession.myConsole.printf("%s/isValidCertificate: Could not find certificate file:%n\t%s%n",
                                           MY_CLASS_TAG, pathName);
                return(false);
            }
            catch (IOException e2)
            {
                MySession.myConsole.printf("%s/isValidCertificate: Unable to read certificate file:%n\t%s%n",
                                           MY_CLASS_TAG, pathName);
                return(false);
            }
            catch (Exception e3)
            {
                MySession.myConsole.printf("%s/isValidCertificate: Certificate file %s contains invalid certficate data.%n",
                                           MY_CLASS_TAG, pathName);
                return(false);
            }

            if ((x509CertificateData != null) && (privateKeyData != null))
            {
                MySession.myConsole.printf("%s/isValidCertificate: Certificate has valid format%n",
                                           MY_CLASS_TAG);
                return(true);
            }
            else
            {
                MySession.myConsole.printf("%s/isValidCertificate: Certificate has invalid format%n",
                                           MY_CLASS_TAG);
                return(false);
            }
        }
예제 #2
0
        /**
         * Determines whether the current AppKeyPair (as specified by {@link #pemFilePathname}) is a valid X.509 certificate.
         * <br /><br />
         * Writes diagnostic messages to the console if the the current AppKeyPair does not exist or is not valid.
         * This is useful since SkypeKit currently reports only "TLS handshake failure" (with no further explanation)
         * if the certificate can't be found/accessed or is not validly formatted.
         *
         * @return
         * 	<ul>
         *	  <li>true: Valid certificate file</li>
         *	  <li>false:
         *	    <ul>
         *	      <li>Could not open the file</li>
         *	      <li>Could not read the file</li>
         *	      <li>Not a valid certificate file</li>
         *	    </ul>
         *	  </li>
         *	</ul>
         *
         * @see #pemFilePathname
         * @see com.skype.tutorial.util.MySession#myClientConfiguration
         * @since 2.0
         */
        public bool isValidCertificate()
        {
            java.security.cert.X509Certificate x509CertificateData;
            java.security.PrivateKey privateKeyData;

            String pathName = getPemFilePathname();

            try
            {
                String derPath = pathName.Substring(0, pathName.Length - 3);
                derPath += "der";

                PemReader myPemReader = new PemReader(getPemFilePathname());
                x509CertificateData = myPemReader.getCertificate();
                privateKeyData = myPemReader.getKey();
            }
            catch (FileNotFoundException e1)
            {
                MySession.myConsole.printf("%s/isValidCertificate: Could not find certificate file:%n\t%s%n",
                        MY_CLASS_TAG, pathName);
                return (false);
            }
            catch (IOException e2)
            {
                MySession.myConsole.printf("%s/isValidCertificate: Unable to read certificate file:%n\t%s%n",
                           MY_CLASS_TAG, pathName);
                return (false);
            }
            catch (Exception e3)
            {
                MySession.myConsole.printf("%s/isValidCertificate: Certificate file %s contains invalid certficate data.%n",
                        MY_CLASS_TAG, pathName);
                return (false);
            }

            if ((x509CertificateData != null) && (privateKeyData != null))
            {
                MySession.myConsole.printf("%s/isValidCertificate: Certificate has valid format%n",
                       MY_CLASS_TAG);
                return (true);
            }
            else
            {
                MySession.myConsole.printf("%s/isValidCertificate: Certificate has invalid format%n",
                        MY_CLASS_TAG);
                return (false);
            }
        }