示例#1
0
        private void AssignKeyFileData(PublicKeyEditViewModel model, PostStatus status, PublicKey publicKey, bool noDataSetError)
        {
            if (!string.IsNullOrEmpty(model.FileData))
            {
                var keyFileData = GetDataUrlString(model.FileData);

                if (keyFileData != null)
                {
                    var gpg  = new GpgWrapper(GpgWrapper.LinuxGpgBinaryPath, Global.Config.GpgHomedir);
                    var keys = gpg.ImportKeys(keyFileData);

                    if (keys.Count() == 1)
                    {
                        var key = keys.Single();
                        publicKey.Data.Value  = gpg.ExportKeyBinary(key.Id);
                        publicKey.KeyId.Value = key.Id;
                    }
                    else
                    {
                        status.SetValidationError("File", "PublicKey.Validation.GpgKey.Invalid", "Validation message when gpg key file is not valid", "Key file not vaild");
                    }
                }
                else
                {
                    status.SetValidationError("File", "PublicKey.Validation.GpgKey.Invalid", "Validation message when gpg key file is not valid", "Key file not vaild");
                }
            }
            else if (noDataSetError)
            {
                status.SetValidationError("File", "PublicKey.Validation.GpgKey.Missing", "Validation message when gpg key file is required but not uploaded", "Key file must be uploaded");
            }
        }
示例#2
0
        private static GpgPublicKeyInfo CheckPublicKey(ServiceAddress address, PublicKey key)
        {
            var gpg     = new GpgWrapper(GpgWrapper.LinuxGpgBinaryPath, Global.Config.GpgHomedir);
            var keyInfo = gpg.ImportKeys(key.Data.Value).FirstOrDefault();

            if (keyInfo.Status != GpgKeyStatus.Active)
            {
                return(null);
            }

            if (!keyInfo.Uids.Any(u => u.Mail == address.Address.Value &&
                                  u.Trust <= GpgTrust.Marginal))
            {
                return(null);
            }

            return(new GpgPublicKeyInfo(keyInfo.Id));
        }
示例#3
0
        public PublicKeyEditViewModel(Translator translator, IDatabase db, Session session, PublicKey publicKey)
            : this(translator)
        {
            Method   = "edit";
            Id       = publicKey.Id.ToString();
            KeyId    = publicKey.KeyId.Value.EscapeHtml();
            FileName = publicKey.ShortKeyId.EscapeHtml() + ".asc";
            FilePath = "/publickey/download/" + publicKey.Id.ToString();
            FileSize = publicKey.Data.Value.Length.SizeFormat();
            Types    = new List <NamedIntViewModel>();
            Types.Add(new NamedIntViewModel(translator, PublicKeyType.OpenPGP, publicKey.Type.Value == PublicKeyType.OpenPGP));

            var gpg = new GpgWrapper(GpgWrapper.LinuxGpgBinaryPath, Global.Config.GpgHomedir);
            Uids = new List <GpgUidItem>(gpg
                                         .ImportKeys(publicKey.Data.Value)
                                         .SelectMany(k => k.Uids)
                                         .Select(u => new GpgUidItem(u.Trust.ToString(), u.Mail))
                                         .OrderBy(u => u.MailAddress));
        }
示例#4
0
 public Mailer(Logger log, Config config)
 {
     _log    = log;
     _config = config;
     _gpg    = new GpgWrapper(GpgWrapper.LinuxGpgBinaryPath, config.GpgHomedir);
 }
示例#5
0
 public override string ToString()
 {
     return(string.Format("{0} {1}/{2} {3} {4} {5} {6}", Id, Type, Bits, Created, GpgWrapper.PrintKeyUsage(Usage), Expiry, Status));
 }