예제 #1
0
        /// <summary>
        /// Read a base-64-encoded certificate from a file.
        /// </summary>
        ///
        /// <param name="filePath">The certificate file path.</param>
        /// <returns>The decoded certificate, or null if there is an error.</returns>
        public static CertificateV2 readCertificate(String filePath)
        {
            StringBuilder encodedData = new StringBuilder();

            try {
                TextReader certificateFile = new FileReader(
                    filePath);
                // Use "try/finally instead of "try-with-resources" or "using"
                // which are not supported before Java 7.
                try {
                    String line;
                    while ((line = certificateFile.readLine()) != null)
                    {
                        encodedData.append(line);
                    }
                } finally {
                    certificateFile.close();
                }
            } catch (FileNotFoundException ex) {
                return(null);
            } catch (IOException ex_0) {
                return(null);
            }

            byte[]        decodedData = net.named_data.jndn.util.Common.base64Decode(encodedData.toString());
            CertificateV2 result      = new CertificateV2();

            try {
                result.wireDecode(new Blob(decodedData, false));
                return(result);
            } catch (Exception ex_1) {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Process the trust-anchor configuration section and call
        /// validator_.loadAnchor as needed.
        /// </summary>
        ///
        /// <param name="configSection"></param>
        /// <param name="inputName">Used for log messages, etc.</param>
        private void processConfigTrustAnchor(BoostInfoTree configSection,
                                              String inputName)
        {
            String anchorType = configSection.getFirstValue("type");

            if (anchorType == null)
            {
                throw new ValidatorConfigError("Expected <trust-anchor.type>");
            }

            if (anchorType.Equals("file", StringComparison.InvariantCultureIgnoreCase))
            {
                // Get trust-anchor.file .
                String fileName = configSection.getFirstValue("file-name");
                if (fileName == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <trust-anchor.file-name>");
                }

                double refreshPeriod = getRefreshPeriod(configSection);
                try {
                    validator_.loadAnchor(fileName, fileName, refreshPeriod, false);
                } catch (TrustAnchorContainer.Error ex) {
                    throw new ValidatorConfigError("Error in loadAnchor: " + ex);
                }

                return;
            }
            else if (anchorType.Equals("base64", StringComparison.InvariantCultureIgnoreCase))
            {
                // Get trust-anchor.base64-string .
                String base64String = configSection.getFirstValue("base64-string");
                if (base64String == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <trust-anchor.base64-string>");
                }

                byte[]        encoding    = net.named_data.jndn.util.Common.base64Decode(base64String);
                CertificateV2 certificate = new CertificateV2();
                try {
                    certificate.wireDecode(new Blob(encoding));
                } catch (Exception ex_0) {
                    throw new ValidatorConfigError(
                              "Cannot decode certificate from base64-string: " + ex_0);
                }
                try {
                    validator_.loadAnchor("", certificate);
                } catch (TrustAnchorContainer.Error ex_1) {
                    throw new ValidatorConfigError("Error in loadAnchor: " + ex_1);
                }

                return;
            }
            else if (anchorType.Equals("dir", StringComparison.InvariantCultureIgnoreCase))
            {
                // Get trust-anchor.dir .
                String dirString = configSection.getFirstValue("dir");
                if (dirString == null)
                {
                    throw new ValidatorConfigError("Expected <trust-anchor.dir>");
                }

                double refreshPeriod_2 = getRefreshPeriod(configSection);
                try {
                    validator_
                    .loadAnchor(dirString, dirString, refreshPeriod_2, true);
                } catch (TrustAnchorContainer.Error ex_3) {
                    throw new ValidatorConfigError("Error in loadAnchor: " + ex_3);
                }

                return;
            }
            else if (anchorType.Equals("any", StringComparison.InvariantCultureIgnoreCase))
            {
                shouldBypass_ = true;
            }
            else
            {
                throw new ValidatorConfigError("Unsupported trust-anchor.type");
            }
        }