public void Process1() { DateTime expiration_date = new DateTime(2050, 01, 01); Name name = new Name("Unit Test"); Email email = new Email("*****@*****.**"); String comment = "Unit Test Comment"; GpgGenerateKey generatekey = new GpgGenerateKey(name, email, comment, KeyAlgorithm.RsaRsa, 1024, expiration_date); generatekey.AskPassphrase = TestCore.AskPassphrase; generatekey.Execute(); Assert.IsNotNull(generatekey.FingerPrint); GpgListPublicKeys keys = new GpgListPublicKeys(); keys.Execute(); Assert.IsNotNull(keys.Keys); Assert.AreNotEqual(0, keys.Keys.Count); Key key = null; foreach (Key item in keys.Keys) { if (item.FingerPrint == generatekey.FingerPrint) { key = item; break; } } Assert.IsNotNull(key); GpgDeleteKeys delete = new GpgDeleteKeys(new List <KeyId> { key.Id }, false); delete.Execute(); DateTime ed = key.ExpirationDate.DateTime; Boolean isInRange = ed > expiration_date && ed < expiration_date.AddDays(1); Assert.AreEqual(KeyAlgorithm.RsaRsa, key.Algorithm); Assert.AreEqual(true, isInRange); Assert.AreEqual(generatekey.FingerPrint, key.FingerPrint); Assert.IsFalse(key.IsDisabled); Assert.AreEqual(KeyOwnerTrust.Ultimate, key.OwnerTrust); Assert.AreEqual((UInt32)1024, key.Size); Assert.AreEqual(KeyType.Public, key.Type); Assert.IsNotNull(key.UserInfos); Assert.AreNotEqual(0, key.UserInfos.Count); Assert.AreEqual(name, key.UserInfos[0].Name); Assert.AreEqual(email, key.UserInfos[0].Email); Assert.AreEqual(comment, key.UserInfos[0].Comment); }
private void KeySelect_Load(object sender, EventArgs e) { GpgInterface.ExePath = frmMain.cfg["GPGEXE"]; GpgListPublicKeys publicKeys = new GpgListPublicKeys(); publicKeys.Execute(); foreach (Key key in publicKeys.Keys) { comboBox1.Items.Add(key.UserInfos[0].Email + "(" + key.Id + ")"); } comboBox1.SelectedIndex = 0; this.TopMost = true; }
/// <summary> /// Cleans up and reencrypts after an edit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TxtPassDetailLeave(object sender, EventArgs e) { if (txtPassDetail.ReadOnly == false) { HTMLShowDetails.Visible = false; txtPassDetail.ReadOnly = true; txtPassDetail.Visible = false; btnMakeVisible.Visible = true; txtPassDetail.BackColor = Color.LightGray; // read .gpg-id var gpgfile = Path.GetDirectoryName(listFileView.SelectedItem.ToString()); gpgfile += "\\.gpg-id"; // check if .gpg-id exists otherwise get the root .gpg-id if (!File.Exists(gpgfile)) { gpgfile = _config["PassDirectory"]; gpgfile += "\\.gpg-id"; } var gpgRec = new List <string>(); using (var r = new StreamReader(gpgfile)) { string line; while ((line = r.ReadLine()) != null) { gpgRec.Add(line.TrimEnd(' ')); } } log.Debug("Matching GPG Keys"); // match keyid var recipients = new List <KeyId>(); foreach (var line in gpgRec) { var gotTheKey = false; var email = new MailAddress(line); var publicKeys = new GpgListPublicKeys(); publicKeys.Execute(); foreach (var key in publicKeys.Keys) { foreach (var t in key.UserInfos) { if (t.Email == email.Address) { recipients.Add(key.Id); gotTheKey = true; } } } if (!gotTheKey) { MessageBox.Show( Strings.Error_key_missing_part1 + line + @" " + Strings.Error_key_missing_part2, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // encrypt var tmpFile = Path.GetTempFileName(); var tmpFile2 = Path.GetTempFileName(); using (var w = new StreamWriter(tmpFile)) { w.Write(txtPassDetail.Text); } log.Debug("Begin encryption of: " + dirTreeView.SelectedNode.Tag + "\\" + listFileView.SelectedItem); var encrypt = new GpgEncrypt(tmpFile, tmpFile2, false, false, null, recipients, CipherAlgorithm.None); var encResult = encrypt.Execute(); this.EncryptCallback(encResult, tmpFile, tmpFile2, dirTreeView.SelectedNode.Tag + "\\" + listFileView.SelectedItem + ".gpg"); } }
/// <summary> /// Cleans up and reencrypts after an edit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void txtPassDetail_Leave(object sender, EventArgs e) { if (txtPassDetail.ReadOnly == false) { txtPassDetail.ReadOnly = true; txtPassDetail.Visible = false; btnMakeVisible.Visible = true; txtPassDetail.BackColor = Color.LightGray; // read .gpg-id string gpgfile = Path.GetDirectoryName(dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString()); gpgfile += "\\.gpg-id"; // check if .gpg-id exists otherwise get the root .gpg-id if (!File.Exists(gpgfile)) { gpgfile = cfg["PassDirectory"]; gpgfile += "\\.gpg-id"; } List <string> GPGRec = new List <string>() { }; using (StreamReader r = new StreamReader(gpgfile)) { string line; while ((line = r.ReadLine()) != null) { GPGRec.Add(line.TrimEnd(' ')); } } // match keyid List <GpgApi.KeyId> recipients = new List <KeyId>() { }; foreach (var line in GPGRec) { bool GotTheKey = false; MailAddress email = new MailAddress(line.ToString()); GpgListPublicKeys publicKeys = new GpgListPublicKeys(); publicKeys.Execute(); foreach (Key key in publicKeys.Keys) { for (int i = 0; i < key.UserInfos.Count; i++) { if (key.UserInfos[i].Email == email.Address) { recipients.Add(key.Id); GotTheKey = true; } } } if (!GotTheKey) { MessageBox.Show(Strings.Error_key_missing_part1 + line.ToString() + " " + Strings.Error_key_missing_part2, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // encrypt string tmpFile = Path.GetTempFileName(); string tmpFile2 = Path.GetTempFileName(); using (StreamWriter w = new StreamWriter(tmpFile)) { w.Write(txtPassDetail.Text); } GpgEncrypt encrypt = new GpgEncrypt(tmpFile, tmpFile2, false, false, null, recipients, GpgApi.CipherAlgorithm.None); GpgInterfaceResult enc_result = encrypt.Execute(); Encrypt_Callback(enc_result, tmpFile, tmpFile2, dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString()); } dataPass.Enabled = true; }