C # redirecting stdin with PGP command -ka

I have a problem that seems really stupid. I must have missed something stupid. We have a PGP keychain located on one of our production servers. The user account to which it belongs is not allowed to log on online for security reasons. Our problem is that sometimes we need to add new keys and it is not easy to do this. So we thought we could create a quick console application that would run as its identifier and invoke PGP commands via the command line.

The command gets called, but it asks for input to confirm what we're doing. Our problem is that the "y" we send as standard is never displayed and the key is not verified.

here is the code:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.DirectoryServices;
using System.Threading;

namespace TestConsoleApp
{
    class RegExValidator
    {
        private System.Diagnostics.Process myProcess;

        public RegExValidator()
        {
        }

        public static void Main(string[] args)
        {
            RegExValidator myValidator = new RegExValidator();
            myValidator.InstallKeys("C:\\Test\\batch.asc", "batch.asc");
        }


        private void InstallKeys(string keyPath, string keyName)
        {
            myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.CreateNoWindow = false;
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.FileName = "pgp";
            myProcess.StartInfo.Arguments = "-ka " + keyPath + "";
            myProcess.Start();

            StreamWriter myInput = myProcess.StandardInput;
            myInput.AutoFlush = true;
            Thread.Sleep(3000);

            myInput.WriteLine("y");

            myInput.WriteLine(Environment.NewLine);

        }

    }

}

      

This is the output we get on the command line.

    C:\Test>TestConsoleApp.exe
    Pretty Good Privacy(tm) Version 6.5.2
    (c) 1999 Network Associates Inc.
    Uses the BSafe(tm) Toolkit, which is copyright RSA Data Security, Inc.
    Export of this software may be restricted by the U.S. government.

    WARNING: Environmental variable TZ is not       defined, so GMT timestamps
            may be wrong.  See the PGP User Guide to properly define TZ

    Looking for new keys...
    DSS  2048/1024 0xDE053A3D 2007/05/29 Batch Interface <batch@netgiro.com>
    sig?           0xDE053A3D             (Unknown signator, can't be checked)

    keyfile contains 1 new keys. Add these keys to keyring ? (Y/n)
    C:\Test>

      

Can anyone please help?

thank

EDIT

We tried this process, but instead of PGP, we just transferred the file and we got a Y / N field and it worked. It would seem that you cannot do this with PGP. I do not know why.

0


source to share


1 answer


Message

keyfile contains 1 new keys. Add these keys to keyring ? (Y/n)

      

offers to answer top the Y . try changing your call to:

myInput.WriteLine("Y");

      



(I don't have PGP installed for validation, but ran into other command line interfaces pushing for the case.)

One more thing to try: flush stream buffers , which flushes all buffers for the stream and forces any buffered data to be written to the underlying device:

myInput.WriteLine("Y");
myInput.Flush();

      

+1


source







All Articles