Exemplo n.º 1
0
            public static IdentityCertificate loadIdentityCertificateFromFile(
					String filename)
            {
                StringBuilder encodedData = new StringBuilder();

                try {
                    TextReader certFile = new FileReader(
                                            filename);
                    // Use "try/finally instead of "try-with-resources" or "using"
                    // which are not supported before Java 7.
                    try {
                        String line;
                        while ((line = certFile.readLine()) != null)
                            encodedData.append(line);
                    } finally {
                        certFile.close();
                    }
                } catch (FileNotFoundException ex) {
                    throw new SecurityException(
                            "Can't find IdentityCertificate file " + filename
                                    + ": " + ex.Message);
                } catch (IOException ex_0) {
                    throw new SecurityException(
                            "Error reading IdentityCertificate file " + filename
                                    + ": " + ex_0.Message);
                }

                byte[] decodedData = net.named_data.jndn.util.Common.base64Decode(encodedData.toString());
                IdentityCertificate cert = new IdentityCertificate();
                try {
                    cert.wireDecode(new Blob(decodedData, false));
                } catch (EncodingException ex_1) {
                    throw new SecurityException(
                            "Can't decode the IdentityCertificate from file "
                                    + filename + ": " + ex_1.Message);
                }
                return cert;
            }
Exemplo n.º 2
0
        /// <summary>
        /// Open path_, parse the configuration file and set config_.
        /// </summary>
        ///
        private void parse()
        {
            if (path_.equals(""))
                throw new Exception(
                        "ConfigFile::parse: Failed to locate the configuration file for parsing");

            TextReader input;
            try {
                input = new FileReader(path_);
            } catch (FileNotFoundException ex) {
                // We don't expect this to happen since we just checked for the file.
                throw new Exception(ex.Message);
            }

            // Use "try/finally instead of "try-with-resources" or "using"
            // which are not supported before Java 7.
            try {
                String line;
                while ((line = input.readLine()) != null) {
                    line = line.trim();
                    if (line.equals("") || line[0] == ';')
                        // Skip empty lines and comments.
                        continue;

                    int iSeparator = line.indexOf('=');
                    if (iSeparator < 0)
                        continue;

                    String key = line.Substring(0,(iSeparator)-(0)).trim();
                    String value_ren = line.Substring(iSeparator + 1).trim();

                    ILOG.J2CsMapping.Collections.Collections.Put(config_,key,value_ren);
                }
            } finally {
                input.close();
            }
        }
        /// <summary>
        /// Read from a key file
        /// </summary>
        ///
        /// <param name="keyName"></param>
        /// <param name="keyClass">[PUBLIC, PRIVATE, SYMMETRIC]</param>
        /// <returns>The key bytes.</returns>
        /// <exception cref="IOException"></exception>
        /// <exception cref="System.Security.SecurityException"></exception>
        private byte[] read(Name keyName, KeyClass keyClass)
        {
            String extension = (String) ILOG.J2CsMapping.Collections.Collections.Get(keyTypeMap_,keyClass);
            StringBuilder contents = new StringBuilder();
            try {
                TextReader reader = new FileReader(nameTransform(keyName.toUri(), extension).FullName);
                // Use "try/finally instead of "try-with-resources" or "using"
                // which are not supported before Java 7.
                try {
                    String line = null;
                    while ((line = reader.readLine()) != null)
                        contents.append(line);
                } finally {
                    reader.close();
                }
            } catch (SecurityException e) {
                throw new SecurityException(
                        "FilePrivateKeyStorage: Failed to read key: "
                                + e.Message);
            } catch (IOException e_0) {
                throw new SecurityException(
                        "FilePrivateKeyStorage: Failed to read key: "
                                + e_0.Message);
            }

            return net.named_data.jndn.util.Common.base64Decode(contents.toString());
        }