CASA/c_sharp/SecretStoreClientManager/Main.cs
2005-10-11 19:51:00 +00:00

1331 lines
44 KiB
C#

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
// for dllimports
using System.Runtime.InteropServices;
using Novell.SecretStore.NSSCSWrapper;
using Novell.SecretStore.NSSSWrapper;
using System.Collections.Specialized;
namespace SecretStoreService
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///
public class Form1 : System.Windows.Forms.Form
{
SecretStore store = null;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
private DateTime date1970 = new DateTime(1970, 1, 1);
private Thread t = null;
private string[] m_remoteSecrets = null;
//private SecretStoreWrapper wrapper = null;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.MenuItem SyncNow;
private System.Windows.Forms.TabPage tabPage4;
private System.Windows.Forms.ComboBox comboBox3;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox Server;
private System.Windows.Forms.TextBox Username;
private System.Windows.Forms.TextBox Password;
private System.Windows.Forms.TextBox UserPass;
private System.Windows.Forms.TextBox UserID;
private System.Windows.Forms.CheckBox SyncCheckBox;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.CheckBox AutoSync;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Button btnApply;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.MenuItem menuItem15;
private System.Windows.Forms.MenuItem menuItem16;
private System.Windows.Forms.ContextMenu contextMenuSecret;
private System.Windows.Forms.MenuItem menuItem19;
private System.Windows.Forms.MenuItem menuItem20;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.MenuItem cmDeleteSecret;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuEditSecret;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuCreateTest;
private System.Windows.Forms.MenuItem menuRemoveTest;
private System.Windows.Forms.Button btnRefresh;
private System.Windows.Forms.Button btnSync;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenuNotifiy;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
if (t != null)
t.Abort();
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.SyncNow = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem15 = new System.Windows.Forms.MenuItem();
this.menuItem16 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuCreateTest = new System.Windows.Forms.MenuItem();
this.menuRemoveTest = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.btnApply = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.btnLogin = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.Password = new System.Windows.Forms.TextBox();
this.Username = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.Server = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.SyncCheckBox = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label4 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.UserPass = new System.Windows.Forms.TextBox();
this.UserID = new System.Windows.Forms.TextBox();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.btnRefresh = new System.Windows.Forms.Button();
this.label11 = new System.Windows.Forms.Label();
this.listBox2 = new System.Windows.Forms.ListBox();
this.comboBox3 = new System.Windows.Forms.ComboBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.listBox1 = new System.Windows.Forms.ListBox();
this.btnSync = new System.Windows.Forms.Button();
this.tabPage4 = new System.Windows.Forms.TabPage();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.label8 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.AutoSync = new System.Windows.Forms.CheckBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.label9 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label7 = new System.Windows.Forms.Label();
this.contextMenuSecret = new System.Windows.Forms.ContextMenu();
this.menuItem20 = new System.Windows.Forms.MenuItem();
this.menuEditSecret = new System.Windows.Forms.MenuItem();
this.cmDeleteSecret = new System.Windows.Forms.MenuItem();
this.menuItem19 = new System.Windows.Forms.MenuItem();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenuNotifiy = new System.Windows.Forms.ContextMenu();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.tabPage3.SuspendLayout();
this.tabPage2.SuspendLayout();
this.tabPage4.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2,
this.menuItem13,
this.menuItem3});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.SyncNow,
this.menuItem4,
this.menuItem8,
this.menuItem5});
this.menuItem1.Text = "SecretStore";
//
// SyncNow
//
this.SyncNow.Index = 0;
this.SyncNow.Text = "Sync now";
this.SyncNow.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.Text = "SS Info";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem8
//
this.menuItem8.Index = 2;
this.menuItem8.Text = "-";
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "Exit";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem6});
this.menuItem2.Text = "View";
//
// menuItem6
//
this.menuItem6.Index = 0;
this.menuItem6.Text = "Status";
//
// menuItem13
//
this.menuItem13.Index = 2;
this.menuItem13.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem14,
this.menuItem15,
this.menuItem16,
this.menuItem12,
this.menuCreateTest,
this.menuRemoveTest});
this.menuItem13.Text = "Secret";
//
// menuItem14
//
this.menuItem14.Index = 0;
this.menuItem14.Text = "Add Secret";
this.menuItem14.Click += new System.EventHandler(this.menuItem14_Click);
//
// menuItem15
//
this.menuItem15.Index = 1;
this.menuItem15.Text = "Edit Secret";
//
// menuItem16
//
this.menuItem16.Index = 2;
this.menuItem16.Text = "Delete Secret";
//
// menuItem12
//
this.menuItem12.Index = 3;
this.menuItem12.Text = "-";
//
// menuCreateTest
//
this.menuCreateTest.Index = 4;
this.menuCreateTest.Text = "Create test secrets";
this.menuCreateTest.Click += new System.EventHandler(this.menuCreateTest_Click);
//
// menuRemoveTest
//
this.menuRemoveTest.Index = 5;
this.menuRemoveTest.Text = "Remove test secrets";
this.menuRemoveTest.Click += new System.EventHandler(this.menuRemoveTest_Click);
//
// menuItem3
//
this.menuItem3.Index = 3;
this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem7});
this.menuItem3.Text = "Help";
//
// menuItem7
//
this.menuItem7.Index = 0;
this.menuItem7.Text = "About";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click_1);
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage4);
this.tabControl1.ItemSize = new System.Drawing.Size(10, 18);
this.tabControl1.Location = new System.Drawing.Point(8, 88);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(456, 392);
this.tabControl1.TabIndex = 0;
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
//
// tabPage1
//
this.tabPage1.Controls.Add(this.btnApply);
this.tabPage1.Controls.Add(this.btnCancel);
this.tabPage1.Controls.Add(this.btnLogin);
this.tabPage1.Controls.Add(this.groupBox2);
this.tabPage1.Controls.Add(this.groupBox1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(448, 366);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Account Information";
//
// btnApply
//
this.btnApply.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnApply.Location = new System.Drawing.Point(264, 328);
this.btnApply.Name = "btnApply";
this.btnApply.Size = new System.Drawing.Size(56, 24);
this.btnApply.TabIndex = 4;
this.btnApply.Text = "Apply";
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(328, 328);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(56, 24);
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = "Close";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnLogin
//
this.btnLogin.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnLogin.Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
this.btnLogin.Location = new System.Drawing.Point(192, 328);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(56, 24);
this.btnLogin.TabIndex = 2;
this.btnLogin.Text = "Login";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.checkBox1);
this.groupBox2.Controls.Add(this.Password);
this.groupBox2.Controls.Add(this.Username);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.Server);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.SyncCheckBox);
this.groupBox2.Controls.Add(this.checkBox2);
this.groupBox2.Location = new System.Drawing.Point(16, 112);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(368, 192);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Server Information";
//
// checkBox1
//
this.checkBox1.Enabled = false;
this.checkBox1.Location = new System.Drawing.Point(104, 160);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(176, 24);
this.checkBox1.TabIndex = 7;
this.checkBox1.Text = "Remember password";
//
// Password
//
this.Password.Enabled = false;
this.Password.Location = new System.Drawing.Point(104, 136);
this.Password.Name = "Password";
this.Password.Size = new System.Drawing.Size(160, 20);
this.Password.TabIndex = 6;
this.Password.Text = "novell";
//
// Username
//
this.Username.Enabled = false;
this.Username.Location = new System.Drawing.Point(104, 104);
this.Username.Name = "Username";
this.Username.Size = new System.Drawing.Size(160, 20);
this.Username.TabIndex = 5;
this.Username.Text = "cn=admin,o=novell";
//
// label6
//
this.label6.Location = new System.Drawing.Point(40, 136);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(56, 16);
this.label6.TabIndex = 4;
this.label6.Text = "Password:";
//
// label5
//
this.label5.Location = new System.Drawing.Point(40, 104);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(64, 16);
this.label5.TabIndex = 3;
this.label5.Text = "Username:";
//
// Server
//
this.Server.CausesValidation = false;
this.Server.Enabled = false;
this.Server.Location = new System.Drawing.Point(104, 48);
this.Server.Name = "Server";
this.Server.Size = new System.Drawing.Size(160, 20);
this.Server.TabIndex = 2;
this.Server.Text = "jim1.provo.novell.com";
//
// label3
//
this.label3.Location = new System.Drawing.Point(40, 48);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(40, 16);
this.label3.TabIndex = 1;
this.label3.Text = "Server:";
//
// SyncCheckBox
//
this.SyncCheckBox.Location = new System.Drawing.Point(24, 16);
this.SyncCheckBox.Name = "SyncCheckBox";
this.SyncCheckBox.Size = new System.Drawing.Size(248, 24);
this.SyncCheckBox.TabIndex = 0;
this.SyncCheckBox.Text = "Sync Secret Store with Server";
this.SyncCheckBox.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// checkBox2
//
this.checkBox2.Enabled = false;
this.checkBox2.Location = new System.Drawing.Point(104, 72);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(160, 16);
this.checkBox2.TabIndex = 4;
this.checkBox2.Text = "Use Client32 if available";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.UserPass);
this.groupBox1.Controls.Add(this.UserID);
this.groupBox1.Enabled = false;
this.groupBox1.Font = new System.Drawing.Font("Tahoma", 8F);
this.groupBox1.Location = new System.Drawing.Point(16, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(368, 96);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Local User Information";
//
// label4
//
this.label4.Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Italic);
this.label4.Location = new System.Drawing.Point(264, 56);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(96, 16);
this.label4.TabIndex = 4;
this.label4.Text = "(master password)";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 3;
this.label2.Text = "Password:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 2;
this.label1.Text = "UserID:";
//
// UserPass
//
this.UserPass.Location = new System.Drawing.Point(80, 56);
this.UserPass.Name = "UserPass";
this.UserPass.PasswordChar = '*';
this.UserPass.Size = new System.Drawing.Size(168, 20);
this.UserPass.TabIndex = 1;
this.UserPass.Text = "";
//
// UserID
//
this.UserID.Location = new System.Drawing.Point(80, 24);
this.UserID.Name = "UserID";
this.UserID.Size = new System.Drawing.Size(168, 20);
this.UserID.TabIndex = 5;
this.UserID.Text = "jnorman.novell";
//
// tabPage3
//
this.tabPage3.Controls.Add(this.btnRefresh);
this.tabPage3.Controls.Add(this.label11);
this.tabPage3.Controls.Add(this.listBox2);
this.tabPage3.Controls.Add(this.comboBox3);
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Size = new System.Drawing.Size(448, 366);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "Manage Secrets";
//
// btnRefresh
//
this.btnRefresh.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnRefresh.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnRefresh.Location = new System.Drawing.Point(16, 320);
this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.TabIndex = 0;
this.btnRefresh.Text = "Refresh";
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
//
// label11
//
this.label11.Location = new System.Drawing.Point(32, 336);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(320, 16);
this.label11.TabIndex = 6;
//
// listBox2
//
this.listBox2.Location = new System.Drawing.Point(16, 56);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(416, 251);
this.listBox2.Sorted = true;
this.listBox2.TabIndex = 5;
this.listBox2.DoubleClick += new System.EventHandler(this.listBox2_DoubleClick);
this.listBox2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.listBox2_MouseUp);
this.listBox2.SelectedIndexChanged += new System.EventHandler(this.listBox2_SelectedIndexChanged);
//
// comboBox3
//
this.comboBox3.Enabled = false;
this.comboBox3.Items.AddRange(new object[] {
"Application View",
"Credential Set View",
"Other View",
"Advanced View"});
this.comboBox3.Location = new System.Drawing.Point(16, 16);
this.comboBox3.Name = "comboBox3";
this.comboBox3.Size = new System.Drawing.Size(208, 21);
this.comboBox3.TabIndex = 4;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.listBox1);
this.tabPage2.Controls.Add(this.btnSync);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(448, 366);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "View Activity";
//
// listBox1
//
this.listBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.listBox1.Location = new System.Drawing.Point(0, 76);
this.listBox1.Name = "listBox1";
this.listBox1.ScrollAlwaysVisible = true;
this.listBox1.Size = new System.Drawing.Size(448, 290);
this.listBox1.TabIndex = 1;
this.listBox1.UseTabStops = false;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// btnSync
//
this.btnSync.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnSync.Location = new System.Drawing.Point(344, 24);
this.btnSync.Name = "btnSync";
this.btnSync.Size = new System.Drawing.Size(72, 24);
this.btnSync.TabIndex = 0;
this.btnSync.Text = "Sync Now";
this.btnSync.Click += new System.EventHandler(this.button1_Click);
//
// tabPage4
//
this.tabPage4.Controls.Add(this.groupBox3);
this.tabPage4.Location = new System.Drawing.Point(4, 22);
this.tabPage4.Name = "tabPage4";
this.tabPage4.Size = new System.Drawing.Size(448, 366);
this.tabPage4.TabIndex = 3;
this.tabPage4.Text = "Preferences";
this.tabPage4.Click += new System.EventHandler(this.tabPage4_Click);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.groupBox5);
this.groupBox3.Controls.Add(this.AutoSync);
this.groupBox3.Controls.Add(this.groupBox4);
this.groupBox3.Enabled = false;
this.groupBox3.Location = new System.Drawing.Point(16, 16);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(416, 264);
this.groupBox3.TabIndex = 0;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Synchronization";
//
// groupBox5
//
this.groupBox5.Controls.Add(this.label8);
this.groupBox5.Controls.Add(this.label10);
this.groupBox5.Controls.Add(this.numericUpDown2);
this.groupBox5.Location = new System.Drawing.Point(16, 160);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(384, 96);
this.groupBox5.TabIndex = 2;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "Synchronize from Server";
//
// label8
//
this.label8.Location = new System.Drawing.Point(16, 24);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(336, 24);
this.label8.TabIndex = 0;
this.label8.Text = "This setting determines how often to retieve secrets from server.";
//
// label10
//
this.label10.Location = new System.Drawing.Point(264, 56);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(88, 16);
this.label10.TabIndex = 4;
this.label10.Text = "Minutes";
//
// numericUpDown2
//
this.numericUpDown2.Enabled = false;
this.numericUpDown2.Location = new System.Drawing.Point(216, 56);
this.numericUpDown2.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(40, 20);
this.numericUpDown2.TabIndex = 3;
this.numericUpDown2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.numericUpDown2.Value = new System.Decimal(new int[] {
5,
0,
0,
0});
//
// AutoSync
//
this.AutoSync.Location = new System.Drawing.Point(16, 24);
this.AutoSync.Name = "AutoSync";
this.AutoSync.TabIndex = 1;
this.AutoSync.Text = "Auto Sync";
this.AutoSync.CheckedChanged += new System.EventHandler(this.AutoSync_CheckedChanged);
//
// groupBox4
//
this.groupBox4.Controls.Add(this.label9);
this.groupBox4.Controls.Add(this.numericUpDown1);
this.groupBox4.Controls.Add(this.label7);
this.groupBox4.Location = new System.Drawing.Point(16, 56);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(384, 96);
this.groupBox4.TabIndex = 0;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Synchronize to Server";
//
// label9
//
this.label9.Location = new System.Drawing.Point(264, 48);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(88, 16);
this.label9.TabIndex = 2;
this.label9.Text = "Minutes";
//
// numericUpDown1
//
this.numericUpDown1.Enabled = false;
this.numericUpDown1.Location = new System.Drawing.Point(216, 48);
this.numericUpDown1.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(40, 20);
this.numericUpDown1.TabIndex = 1;
this.numericUpDown1.Tag = "";
this.numericUpDown1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.numericUpDown1.Value = new System.Decimal(new int[] {
5,
0,
0,
0});
//
// label7
//
this.label7.Location = new System.Drawing.Point(16, 16);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(360, 32);
this.label7.TabIndex = 0;
this.label7.Text = "This setting detemines how often to send secrets to the Secret Store server";
//
// contextMenuSecret
//
this.contextMenuSecret.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem20,
this.menuEditSecret,
this.cmDeleteSecret,
this.menuItem19});
//
// menuItem20
//
this.menuItem20.Index = 0;
this.menuItem20.Text = "View Secret";
this.menuItem20.Click += new System.EventHandler(this.menuItem20_Click);
//
// menuEditSecret
//
this.menuEditSecret.Index = 1;
this.menuEditSecret.Text = "Edit Secret";
this.menuEditSecret.Click += new System.EventHandler(this.menuEditSecret_Click);
//
// cmDeleteSecret
//
this.cmDeleteSecret.Index = 2;
this.cmDeleteSecret.Text = "Delete Secret";
this.cmDeleteSecret.Click += new System.EventHandler(this.cmDeleteSecret_Click);
//
// menuItem19
//
this.menuItem19.Index = 3;
this.menuItem19.Text = "Add Secret";
this.menuItem19.Click += new System.EventHandler(this.menuItem19_Click);
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(7, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(472, 80);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.contextMenuNotifiy;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "SecretStore Client Manager";
this.notifyIcon1.Visible = true;
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);
//
// contextMenuNotifiy
//
this.contextMenuNotifiy.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem9,
this.menuItem10});
//
// menuItem9
//
this.menuItem9.Index = 0;
this.menuItem9.Text = "About SecretStore";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
//
// menuItem10
//
this.menuItem10.Index = 1;
this.menuItem10.Text = "Open SecretStore Client Manager";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(472, 516);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.tabControl1);
this.HelpButton = true;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Location = new System.Drawing.Point(200, 200);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(480, 550);
this.Menu = this.mainMenu1;
this.MinimumSize = new System.Drawing.Size(480, 550);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "SecretStore Client Manager";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);
this.MinimumSizeChanged += new System.EventHandler(this.Form1_MinimumSizeChanged);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.tabPage3.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage4.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
this.groupBox4.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem7_Click(object sender, System.EventArgs e)
{
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
Dispose(true);
}
private void button1_Click(object sender, System.EventArgs e)
{
menuItem7_Click(sender, e);
if (t == null)
{
t = new Thread(new ThreadStart(syncSecretsThread));
t.Start();
}
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void tabPage4_Click(object sender, System.EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
if (!Server.Enabled)
{
Server.Enabled = true;
Username.Enabled = true;
Password.Enabled = true;
checkBox1.Enabled = true;
checkBox2.Enabled = true;
btnLogin.Enabled = true;
listBox1.Enabled = true;
//Username.Text = UserID.Text.ToString();
}
else
{
Server.Enabled = false;
Username.Enabled = false;
Password.Enabled = false;
checkBox1.Enabled = false;
checkBox2.Enabled = false;
btnLogin.Enabled = false;
listBox1.Enabled = false;
}
}
private void AutoSync_CheckedChanged(object sender, System.EventArgs e)
{
if (numericUpDown1.Enabled)
{
numericUpDown1.Enabled = false;
numericUpDown2.Enabled = false;
}
else
{
numericUpDown1.Enabled = true;
numericUpDown2.Enabled = true;
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
Dispose();
}
private void btnLogin_Click(object sender, System.EventArgs e)
{
RemoteStore rs = RemoteStore.getInstance();
string host = Server.Text.Trim();
string userId = Username.Text.Trim();
string password = Password.Text.Trim();
//TODO: Handle ssl cert
rs.connect(host, userId, password, "d:/Jim1.der");
string[] saSecrets = rs.enumerateSecrets();
// add these secrets to our local cache
if (saSecrets != null)
{
if (store == null)
store = new SecretStore();
for (int i=0; i<saSecrets.Length; i++)
{
RemoteSecret remoteSecret = rs.getSecret(saSecrets[i].Trim());
if (remoteSecret != null)
{
Console.WriteLine(saSecrets[i].Trim() + " created " + date1970.AddSeconds(remoteSecret.getCreateTime()).ToLocalTime());
}
}
}
// temp setup
m_remoteSecrets = saSecrets;
//if (true) return;
if (btnLogin.Text.Equals("Login"))
{
groupBox1.Text="Local User Information - Authenticated";
btnLogin.Text = "Logout";
UserID.Enabled=false;
UserPass.Enabled=false;
btnCancel.Enabled=false;
btnApply.Enabled=false;
//groupBox2.Enabled=false;
if (SyncCheckBox.Checked)
{
groupBox2.Text = "Server Information - Authenticated";
Username.Enabled = false;
Password.Enabled = false;
Server.Enabled = false;
}
}
else
{
groupBox1.Text="Local User Information";
btnLogin.Text = "Login";
UserID.Enabled=true;
UserPass.Enabled=true;
btnCancel.Enabled=true;
btnApply.Enabled=true;
groupBox2.Enabled=true;
groupBox2.Text = "Server Information";
Username.Enabled = true;
Password.Enabled = true;
Server.Enabled = true;
m_remoteSecrets = null;
}
}
private void menuItem7_Click_1(object sender, System.EventArgs e)
{
Form about = new about();
about.ShowDialog();
}
private void listBox2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button.Equals(System.Windows.Forms.MouseButtons.Right))
{
Object itemSelected = ((ListBox)sender).SelectedItem;
if (itemSelected != null)
{
String sItem = itemSelected.ToString();
contextMenuSecret.Show((ListBox)sender, new Point(e.X,e.Y));
}
}
}
private void menuItem12_Click(object sender, System.EventArgs e)
{
Form2 sysinfo = new Form2();
if (store == null)
store = SecretStore.getInstance();
sysinfo.ShowDialog();
}
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (tabControl1.SelectedIndex != 1) return;
refreshSecretList();
}
private void listBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
public DisplaySecret ds = null;
private void listBox2_DoubleClick(object sender, System.EventArgs e)
{
int type = Secret.SS_BINARY;
if (listBox2.SelectedItem == null) return;
string selected = listBox2.SelectedItem.ToString();
if (selected == null) return;
if (selected.StartsWith("SS_CredSet:"))
{
selected = selected.Substring(selected.IndexOf(":") + 1);
type = Secret.SS_CREDSET;
}
else if (selected.StartsWith("SS_App"))
{
selected = selected.Substring(selected.IndexOf(":") + 1);
type = Secret.SS_APP;
}
Secret sec = store.getSecret(0, selected, type, null);
ds = new DisplaySecret();
DateTime created = date1970.AddSeconds(sec.getCreateTime());
DateTime mod = date1970.AddSeconds(sec.getModifiedTime());
DateTime accessTime = date1970.AddSeconds(sec.getAccessTime());
NameValueCollection kvc = sec.getKeyValueCollection();
ds.setData(sec.getID(),
sec,
created.ToLocalTime().ToLongDateString()+ " @ " + created.ToLocalTime().ToShortTimeString(),
mod.ToLocalTime().ToLongDateString()+ " @ " + mod.ToLocalTime().ToShortTimeString(),
accessTime.ToLocalTime().ToLongDateString()+ " @ " + accessTime.ToLocalTime().ToShortTimeString());
ds.ShowDialog();
}
private void menuItem14_Click(object sender, System.EventArgs e)
{
doAddSecret();
}
private void doAddSecret()
{
if (store == null)
store = SecretStore.getInstance();
AddSecretForm asf = new AddSecretForm(store);
asf.ShowDialog();
}
private void menuItem19_Click(object sender, System.EventArgs e)
{
doAddSecret();
}
private void menuItem20_Click(object sender, System.EventArgs e)
{
listBox2_DoubleClick(sender, e);
}
private void cmDeleteSecret_Click(object sender, System.EventArgs e)
{
DialogResult DR=new DialogResult() ;
DR=MessageBox.Show ("Are you sure?","Delete Secret",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
string Str=DR.ToString();
switch (Str)
{
case "No":
return;
}
string secretID = listBox2.SelectedItem.ToString();
int iSecretType = Secret.SS_CREDSET;
if (secretID != null)
{
if (secretID.StartsWith("SS_Cred"))
{
secretID = secretID.Substring(secretID.IndexOf(":")+1);
iSecretType = Secret.SS_CREDSET;
}
else if (secretID.StartsWith("SS_App"))
{
secretID = secretID.Substring(secretID.IndexOf(":")+1);
iSecretType = Secret.SS_APP;
}
store.removeSecret(secretID, iSecretType);
refreshSecretList();
}
}
internal void refreshSecretList()
{
// call new wrapper
if (store == null)
store = new SecretStore();
listBox2.Items.Clear();
StringCollection sc = store.enumerateSecretIDs();
if (sc != null)
{
StringEnumerator se = sc.GetEnumerator();
se.Reset();
while (se.MoveNext())
{
listBox2.Items.Add(se.Current);
}
}
// populate listbox with remote secrets
// parse the buffer
string delimStr = "*";
char [] delimiter = delimStr.ToCharArray();
if (m_remoteSecrets != null)
{
for (int i=0; i<m_remoteSecrets.Length; i++)
{
string sTemp = m_remoteSecrets[i].ToString().TrimEnd(delimiter);
listBox2.Items.Add("[Remote] "+ sTemp);
listBox2.Refresh();
}
}
}
private void Refresh_Click(object sender, System.EventArgs e)
{
refreshSecretList();
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
}
private void menuEditSecret_Click(object sender, System.EventArgs e)
{
string secretID = listBox2.SelectedItem.ToString();
int iSecretType = Secret.SS_CREDSET;
if (secretID != null)
{
if (secretID.StartsWith("SS_Cred"))
{
secretID = secretID.Substring(secretID.IndexOf(":")+1);
iSecretType = Secret.SS_CREDSET;
}
else if (secretID.StartsWith("SS_App"))
{
secretID = secretID.Substring(secretID.IndexOf(":")+1);
iSecretType = Secret.SS_APP;
}
AddSecretForm asf = new AddSecretForm(store);
asf.loadSecret(store, secretID, iSecretType, null);
asf.Show();
}
}
private void menuCreateTest_Click(object sender, System.EventArgs e)
{
if (store == null)
store = SecretStore.getInstance();
for (int i=0; i<10; i++)
{
Secret sSecret = store.getSecret(0, "Test Credential Secret "+i.ToString(), Secret.SS_CREDSET, null);
sSecret.setKeyValuePair("username", "TestUser"+i);
sSecret.setKeyValuePair("password", "TestPassword"+i);
store.setSecret(0, sSecret, Secret.SS_CREDSET);
}
/*
Secret sSecret1 = store.getSecret(0, "MyTestAppSecret", Secret.SS_APP, null);
sSecret1.setKeyValuePair("SS_Cred", "MyTestCredentialSecret");
store.setSecret(0, sSecret1, Secret.SS_APP);
*/
refreshSecretList();
}
private void menuRemoveTest_Click(object seander, System.EventArgs e)
{
for (int i=0; i<10; i++)
{
store.removeSecret("Test Credential Secret "+i.ToString(), Secret.SS_CREDSET);
}
refreshSecretList();
}
private void btnRefresh_Click(object sender, System.EventArgs e)
{
refreshSecretList();
}
private void syncSecretsThread()
{
while (true)
{
listBox1.Items.Add(System.DateTime.Now.ToString() + " Synchronizing with server (Simulation only)");
for (int i=0; i<listBox2.Items.Count; i++)
{
//listBox1.Items.Insert(0, System.DateTime.Now.ToString());
System.Threading.Thread.Sleep(200);
listBox1.Items.Add(System.DateTime.Now.ToString() + " " + listBox2.Items[i].ToString() + " Synchronized");
listBox1.Refresh();
listBox1.SetSelected(listBox1.Items.Count-1, true);
}
listBox1.Items.Add(System.DateTime.Now.ToString() + " Synchronizing complete");
listBox1.Items.Add("--------------------------");
listBox1.Refresh();
listBox1.SetSelected(listBox1.Items.Count-1, true);
Thread.Sleep(10000);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
if (this.ShowInTaskbar)
{
this.ShowInTaskbar = false;
this.Visible = false;
}
else
{
this.ShowInTaskbar = true;
this.Visible = true;
}
this.Activate();
}
private void menuItem9_Click(object sender, System.EventArgs e)
{
}
private void Form1_MinimumSizeChanged(object sender, System.EventArgs e)
{
System.Console.WriteLine("Minimized");
}
private void notifyIcon1_Click(object sender, System.EventArgs e)
{
//this.contextMenuNotifiy.Show(new Control(), new Point(0,0));
}
}
}