Exemplo n.º 1
0
        public void execute()
        {
            RopBind rop = new RopBind();

            try {
                sign(rop);
            } finally {
                rop.Close();
            }
        }
Exemplo n.º 2
0
        public void execute()
        {
            RopBind rop = new RopBind();

            try {
                decrypt(rop, true);
                decrypt(rop, false);
            } finally {
                rop.Close();
            }
        }
Exemplo n.º 3
0
        public void execute()
        {
            RopBind rop = new RopBind();

            try {
                generate_keys(rop);
                output_keys(rop);
            } finally {
                rop.Close();
            }
        }
Exemplo n.º 4
0
        public void execute(string[] argv, string[] json_out)
        {
            string input_file = null;
            bool   raw        = false;
            bool   mpi        = false;
            bool   grip       = false;
            bool   json       = false;
            bool   help       = (argv.Length < 2);

            /* Parse command line options:
             *  -i input_file [mandatory]: specifies name of the file with PGP packets
             *  -d : indicates wether to dump whole packet content
             *  -m : dump mpi contents
             *  -g : dump key grips and fingerprints
             *  -j : JSON output
             *  -h : prints help and exists
             */
            List <string> opts = new List <string>(), args = new List <string>();

            for (int idx = 1; idx < argv.Length; idx++)
            {
                if (argv[idx].Length >= 2 && argv[idx][0] == '-' && "dmgjh".IndexOf(argv[idx][1]) >= 0)
                {
                    opts.Add(argv[idx]);
                }
                else
                {
                    args.Add(argv[idx]);
                }
            }
            foreach (string opt in opts)
            {
                if (opt.CompareTo("-d") == 0)
                {
                    raw = true;
                }
                else if (opt.CompareTo("-m") == 0)
                {
                    mpi = true;
                }
                else if (opt.CompareTo("-g") == 0)
                {
                    grip = true;
                }
                else if (opt.CompareTo("-j") == 0)
                {
                    json = true;
                }
                else if (opt.Length > 0)
                {
                    help = true;
                }
            }
            if (!help)
            {
                if (args.Count > 0)
                {
                    input_file = args[0];
                }

                RopBind rop = new RopBind();
                try {
                    RopInput  input  = null;
                    RopOutput output = null;
                    try {
                        if (input_file != null)
                        {
                            input = rop.create_input(input_file);
                        }
                        else
                        {
                            input = rop.create_input(this, null);
                        }
                    } catch (RopError err) {
                        Console.WriteLine(String.Format("Failed to open source: error {0}", err.getErrCode()));
                        throw err;
                    }

                    if (!json)
                    {
                        try {
                            output = rop.create_output(this, null);
                        } catch (RopError err) {
                            Console.WriteLine(String.Format("Failed to open stdout: error {0}", err.getErrCode()));
                            throw err;
                        }
                        input.dump_packets_to_output(output, mpi, raw, grip);
                    }
                    else
                    {
                        string jsn = input.dump_packets_to_json(mpi, raw, grip).getString();
                        if (json_out == null)
                        {
                            Console.WriteLine(jsn);
                            Console.WriteLine("");
                        }
                        else
                        {
                            json_out[0] = jsn;
                        }
                    }
                } catch (RopError err) {
                    // Inform in case of error occured during parsing
                    Console.WriteLine(String.Format("Operation failed [error code: {0}]", err.getErrCode()));
                    throw err;
                } finally {
                    rop.Close();
                }
            }
            else
            {
                print_usage(argv[0]);
            }
        }