// internal AND protected
        internal override GpgInterfaceResult ProcessLine(String line)
        {
            if (!GNUCheck(ref line))
            {
                return(GpgInterfaceResult.Success);
            }

            switch (GetKeyword(ref line))
            {
            case GpgKeyword.GET_LINE:
            {
                if (String.Equals(line, "edit_ownertrust.value", StringComparison.Ordinal))
                {
                    WriteLine(GpgConvert.ToId(OwnerTrust));
                }
                break;
            }

            case GpgKeyword.GET_BOOL:
            {
                if (line.StartsWith("edit_ownertrust.", StringComparison.Ordinal))
                {
                    WriteLine("YES");
                }
                break;
            }
            }

            return(GpgInterfaceResult.Success);
        }
Beispiel #2
0
        // internal AND protected
        internal override GpgInterfaceResult ProcessLine(String line)
        {
            if (!GNUCheck(ref line))
            {
                return(GpgInterfaceResult.Success);
            }

            switch (GetKeyword(ref line))
            {
            case GpgKeyword.BAD_PASSPHRASE:
            {
                if (IsMaxTries())
                {
                    return(GpgInterfaceResult.BadPassphrase);
                }
                break;
            }

            case GpgKeyword.GET_HIDDEN:
            {
                if (String.Equals(line, "passphrase.enter", StringComparison.Ordinal))
                {
                    SecureString password = InternalAskPassphrase(SignatureKeyId);
                    if (IsNullOrEmpty(password))
                    {
                        return(GpgInterfaceResult.UserAbort);
                    }
                    WritePassword(password);
                }
                break;
            }

            case GpgKeyword.SIG_CREATED:
            {
                String[] parts = line.Split(' ');
                Signed          = true;
                KeyAlgorithm    = GpgConvert.ToKeyAlgorithm(Int32.Parse(parts[1], CultureInfo.InvariantCulture));
                DigestAlgorithm = GpgConvert.ToDigestAlgorithm(Int32.Parse(parts[2], CultureInfo.InvariantCulture));
                break;
            }

            case GpgKeyword.GET_BOOL:
            {
                if (String.Equals(line, "openfile.overwrite.okay", StringComparison.Ordinal))
                {
                    WriteLine("YES");
                }
                break;
            }
            }

            return(GpgInterfaceResult.Success);
        }
Beispiel #3
0
        // internal AND protected
        internal override String Arguments()
        {
            String args = "";

            args += "--output " + Utils.EscapePath(EncryptedFileName) + " ";

            if (Armored)
            {
                args += "--armor ";
            }

            if (HideUserIds)
            {
                args += "--throw-keyids ";
            }

            if (SignatureKeyId != null)
            {
                args += "--sign ";
                args += "--local-user " + SignatureKeyId + " ";
            }

            if (CipherAlgorithm != CipherAlgorithm.None)
            {
                args += "--symmetric ";
                args += "--cipher-algo " + GpgConvert.ToName(CipherAlgorithm) + " ";
            }

            if (Recipients != null)
            {
                String recipients = String.Empty;
                foreach (KeyId recipient in Recipients)
                {
                    recipients += "--recipient " + recipient + " ";
                }

                if (recipients.Length > 0)
                {
                    args += "--encrypt ";
                    args += recipients;
                }
            }

            args += Utils.EscapePath(FileName);

            return(args);
        }
Beispiel #4
0
        // internal AND protected
        internal override GpgInterfaceResult ProcessLine(String line)
        {
            if (!GNUCheck(ref line))
            {
                return(GpgInterfaceResult.Success);
            }

            switch (GetKeyword(ref line))
            {
            case GpgKeyword.GET_LINE:
            {
                if (String.Equals(line, "keygen.valid", StringComparison.Ordinal))
                {
                    WriteLine(GpgConvert.ToDays(ExpirationDate));
                }
                break;
            }

            case GpgKeyword.GET_HIDDEN:
            {
                if (String.Equals(line, "passphrase.enter", StringComparison.Ordinal))
                {
                    SecureString password = InternalAskPassphrase(KeyId);
                    if (IsNullOrEmpty(password))
                    {
                        return(GpgInterfaceResult.UserAbort);
                    }
                    WritePassword(password);
                }
                break;
            }

            case GpgKeyword.BAD_PASSPHRASE:
            {
                if (IsMaxTries())
                {
                    return(GpgInterfaceResult.BadPassphrase);
                }
                break;
            }
            }

            return(GpgInterfaceResult.Success);
        }
Beispiel #5
0
        // internal AND protected
        internal override GpgInterfaceResult ProcessLine(String line)
        {
            String[] parts = line.Split(':');

            switch (parts[0])
            {
            case "sec":
            {
                Key key = new Key
                {
                    Trust          = GpgConvert.ToTrust(parts[1]),
                    Size           = Convert.ToUInt32(parts[2], CultureInfo.InvariantCulture),
                    Algorithm      = GpgConvert.ToKeyAlgorithm(parts[3]),
                    Id             = new KeyId(parts[4]),
                    CreationDate   = GpgConvert.ToDate(parts[5]),
                    ExpirationDate = new GpgDateTime(parts[6]),
                    Type           = KeyType.Secret
                };

                Keys.Add(key);
                _last = key;
                break;
            }

            case "fpr":
            {
                _last.FingerPrint = new FingerPrint(parts[9]);
                break;
            }

            case "uid":
            {
                _last.UserInfos.Add(new KeyUserInfo(Utils.UnescapeGpgString(parts[9])));
                break;
            }
            }

            return(GpgInterfaceResult.Success);
        }
Beispiel #6
0
        // internal AND protected
        internal override GpgInterfaceResult ProcessLine(String line)
        {
            if (!GNUCheck(ref line))
            {
                return(GpgInterfaceResult.Success);
            }

            switch (GetKeyword(ref line))
            {
            case GpgKeyword.GET_LINE:
            {
                switch (line)
                {
                case "keygen.algo": WriteLine(GpgConvert.ToId(Algorithm)); break;

                case "keygen.size": WriteLine(Size); break;

                case "keygen.valid": WriteLine(GpgConvert.ToDays(ExpirationDate)); break;

                case "keygen.name": WriteLine(EncodeString(Name)); break;

                case "keygen.email": WriteLine(EncodeString(Email)); break;

                case "keygen.comment": WriteLine(EncodeString(Comment)); break;
                }

                break;
            }

            case GpgKeyword.PROGRESS:
            {
                String[] parts = line.Split(' ');

                if (parts.Length >= 4)
                {
                    switch (parts[0])
                    {
                    case "primegen": return(new GpgInterfaceResult(GpgInterfaceStatus.Processing, GpgInterfaceMessage.GeneratingPrimeNumbers));

                    case "pk_dsa": return(new GpgInterfaceResult(GpgInterfaceStatus.Processing, GpgInterfaceMessage.GeneratingDsaKey));

                    case "pk_elg": return(new GpgInterfaceResult(GpgInterfaceStatus.Processing, GpgInterfaceMessage.GeneratingELGamalKey));

                    case "need_entropy": return(new GpgInterfaceResult(GpgInterfaceStatus.Processing, GpgInterfaceMessage.NeedEntropy));
                    }
                }

                break;
            }

            case GpgKeyword.KEY_CREATED:
            {
                String[] parts = line.Split(' ');
                FingerPrint = parts[1];

                break;
            }

            case GpgKeyword.KEY_NOT_CREATED:
            {
                return(new GpgInterfaceResult(GpgInterfaceStatus.Error, GpgInterfaceMessage.KeyNotCreated));
            }

            case GpgKeyword.GET_HIDDEN:
            {
                if (String.Equals(line, "passphrase.enter", StringComparison.Ordinal))
                {
                    SecureString password = InternalAskPassphrase(Name, true);
                    if (IsNullOrEmpty(password))
                    {
                        return(GpgInterfaceResult.UserAbort);
                    }
                    WritePassword(password);
                }

                break;
            }
            }

            return(GpgInterfaceResult.Success);
        }
Beispiel #7
0
        // internal AND protected
        internal override GpgInterfaceResult ProcessLine(String line)
        {
            String[] parts = line.Split(':');

            switch (parts[0])
            {
            case "pub":
            {
                Key key = new Key
                {
                    Trust          = GpgConvert.ToTrust(parts[1]),
                    Size           = Convert.ToUInt32(parts[2], CultureInfo.InvariantCulture),
                    Algorithm      = GpgConvert.ToKeyAlgorithm(parts[3]),
                    Id             = new KeyId(parts[4]),
                    CreationDate   = GpgConvert.ToDate(parts[5]),
                    ExpirationDate = new GpgDateTime(parts[6]),
                    OwnerTrust     = GpgConvert.ToOwnerTrust(parts[8]),
                    Type           = KeyType.Public
                };

                if (parts.Length > 11)
                {
                    String p = parts[11];
                    key.IsDisabled = p.Contains("D");
                }

                Keys.Add(key);
                _lastKey = key;
                _index   = 1;
                break;
            }

            case "fpr":
            {
                _lastKey.FingerPrint = new FingerPrint(parts[9]);
                break;
            }

            case "sub":
            {
                KeySub sub = new KeySub
                {
                    Trust          = GpgConvert.ToTrust(parts[1]),
                    Size           = Convert.ToUInt32(parts[2], CultureInfo.InvariantCulture),
                    Algorithm      = GpgConvert.ToKeyAlgorithm(parts[3]),
                    Id             = new KeyId(parts[4]),
                    CreationDate   = GpgConvert.ToDate(parts[5]),
                    ExpirationDate = new GpgDateTime(parts[6])
                };

                if (parts.Length > 11)
                {
                    String p = parts[11];
                    sub.IsDisabled = p.Contains("D");
                }

                _lastKey.SubKeys.Add(sub);
                _lastKeyNode = sub;
                break;
            }

            case "uat":
            {
                if (parts.Length >= 6)
                {
                    KeyPhoto photo = new KeyPhoto
                    {
                        Index = _index++
                    };

                    _lastKey.Photos.Add(photo);
                    _lastKeyNode = photo;
                }
                break;
            }

            case "uid":
            {
                KeyUserInfo userid = new KeyUserInfo(Utils.UnescapeGpgString(parts[9]))
                {
                    Index = _index++
                };

                _lastKey.UserInfos.Add(userid);
                _lastKeyNode = userid;
                break;
            }

            case "sig":
            case "rev":
            {
                if (_lastKeyNode != null)
                {
                    _lastKeyNode.Signatures.Add(new KeySignature(parts[4], GpgConvert.ToDate(parts[5]), String.Equals(parts[0], "rev", StringComparison.Ordinal)));
                }
                break;
            }
            }

            return(GpgInterfaceResult.Success);
        }
Beispiel #8
0
 public static KeyOwnerTrust ToOwnerTrust(String s)
 {
     return(String.IsNullOrEmpty(s) ? KeyOwnerTrust.None : GpgConvert.ToOwnerTrust(s[0]));
 }
Beispiel #9
0
 public static KeyTrust ToTrust(String s)
 {
     return(String.IsNullOrEmpty(s) ? KeyTrust.Unknown : GpgConvert.ToTrust(s[0]));
 }
Beispiel #10
0
        public static KeyAlgorithm ToKeyAlgorithm(String s)
        {
            Int32 i;

            return(Int32.TryParse(s, out i) ? GpgConvert.ToKeyAlgorithm(i) : KeyAlgorithm.None);
        }