Commit 29f08482 authored by Josh Ji's avatar Josh Ji

cert loading feature

parent ac4d15c6
No preview for this file type
......@@ -33,7 +33,6 @@
this.APDUbox = new System.Windows.Forms.TextBox();
this.clearWindow = new System.Windows.Forms.Button();
this.CBORbox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.getPuKxRx = new System.Windows.Forms.Button();
this.getAttestationPublicKey = new System.Windows.Forms.Button();
this.dumpIDSecret = new System.Windows.Forms.Button();
......@@ -43,6 +42,10 @@
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.paramBox = new System.Windows.Forms.TextBox();
this.btnLoadCert = new System.Windows.Forms.Button();
this.btnLoadDefaultCert = new System.Windows.Forms.Button();
this.btnOpenCert = new System.Windows.Forms.Button();
this.certBox = new System.Windows.Forms.TextBox();
this.resetCredentials = new System.Windows.Forms.Button();
this.getCredentialCount = new System.Windows.Forms.Button();
this.getFreeSpace = new System.Windows.Forms.Button();
......@@ -51,9 +54,16 @@
this.ClientPIN_getKeyAgreement = new System.Windows.Forms.Button();
this.pinBox = new System.Windows.Forms.TextBox();
this.SetPIN = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.tabControl2 = new System.Windows.Forms.TabControl();
this.tabPage4 = new System.Windows.Forms.TabPage();
this.tabPage5 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.tabControl2.SuspendLayout();
this.tabPage4.SuspendLayout();
this.tabPage5.SuspendLayout();
this.SuspendLayout();
//
// selectFIDOApplet
......@@ -99,23 +109,14 @@
// CBORbox
//
this.CBORbox.Font = new System.Drawing.Font("Monospac821 BT", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.CBORbox.Location = new System.Drawing.Point(445, 59);
this.CBORbox.Location = new System.Drawing.Point(6, 6);
this.CBORbox.Multiline = true;
this.CBORbox.Name = "CBORbox";
this.CBORbox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.CBORbox.Size = new System.Drawing.Size(381, 629);
this.CBORbox.Size = new System.Drawing.Size(361, 625);
this.CBORbox.TabIndex = 4;
this.CBORbox.WordWrap = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(445, 41);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 15);
this.label2.TabIndex = 6;
this.label2.Text = "CBOR";
//
// getPuKxRx
//
this.getPuKxRx.Location = new System.Drawing.Point(832, 290);
......@@ -209,6 +210,44 @@
this.paramBox.TabIndex = 3;
this.paramBox.WordWrap = false;
//
// btnLoadCert
//
this.btnLoadCert.Location = new System.Drawing.Point(100, 6);
this.btnLoadCert.Name = "btnLoadCert";
this.btnLoadCert.Size = new System.Drawing.Size(88, 23);
this.btnLoadCert.TabIndex = 3;
this.btnLoadCert.Text = "load";
this.btnLoadCert.UseVisualStyleBackColor = true;
this.btnLoadCert.Click += new System.EventHandler(this.btnLoadCert_Click);
//
// btnLoadDefaultCert
//
this.btnLoadDefaultCert.Location = new System.Drawing.Point(279, 8);
this.btnLoadDefaultCert.Name = "btnLoadDefaultCert";
this.btnLoadDefaultCert.Size = new System.Drawing.Size(88, 23);
this.btnLoadDefaultCert.TabIndex = 2;
this.btnLoadDefaultCert.Text = "loadDefault";
this.btnLoadDefaultCert.UseVisualStyleBackColor = true;
this.btnLoadDefaultCert.Click += new System.EventHandler(this.btnLoadDefaultCert_Click);
//
// btnOpenCert
//
this.btnOpenCert.Location = new System.Drawing.Point(6, 6);
this.btnOpenCert.Name = "btnOpenCert";
this.btnOpenCert.Size = new System.Drawing.Size(88, 23);
this.btnOpenCert.TabIndex = 1;
this.btnOpenCert.Text = "open";
this.btnOpenCert.UseVisualStyleBackColor = true;
this.btnOpenCert.Click += new System.EventHandler(this.btnOpenCert_Click);
//
// certBox
//
this.certBox.Location = new System.Drawing.Point(6, 35);
this.certBox.Multiline = true;
this.certBox.Name = "certBox";
this.certBox.Size = new System.Drawing.Size(361, 590);
this.certBox.TabIndex = 0;
//
// resetCredentials
//
this.resetCredentials.Location = new System.Drawing.Point(832, 232);
......@@ -285,11 +324,51 @@
this.SetPIN.UseVisualStyleBackColor = true;
this.SetPIN.Click += new System.EventHandler(this.SetPIN_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// tabControl2
//
this.tabControl2.Controls.Add(this.tabPage4);
this.tabControl2.Controls.Add(this.tabPage5);
this.tabControl2.Location = new System.Drawing.Point(445, 26);
this.tabControl2.Name = "tabControl2";
this.tabControl2.SelectedIndex = 0;
this.tabControl2.Size = new System.Drawing.Size(381, 662);
this.tabControl2.TabIndex = 21;
//
// tabPage4
//
this.tabPage4.Controls.Add(this.CBORbox);
this.tabPage4.Location = new System.Drawing.Point(4, 24);
this.tabPage4.Name = "tabPage4";
this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
this.tabPage4.Size = new System.Drawing.Size(373, 634);
this.tabPage4.TabIndex = 0;
this.tabPage4.Text = "CBOR";
this.tabPage4.UseVisualStyleBackColor = true;
//
// tabPage5
//
this.tabPage5.Controls.Add(this.btnLoadCert);
this.tabPage5.Controls.Add(this.certBox);
this.tabPage5.Controls.Add(this.btnOpenCert);
this.tabPage5.Controls.Add(this.btnLoadDefaultCert);
this.tabPage5.Location = new System.Drawing.Point(4, 24);
this.tabPage5.Name = "tabPage5";
this.tabPage5.Padding = new System.Windows.Forms.Padding(3);
this.tabPage5.Size = new System.Drawing.Size(373, 634);
this.tabPage5.TabIndex = 1;
this.tabPage5.Text = "load cert";
this.tabPage5.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1211, 729);
this.Controls.Add(this.tabControl2);
this.Controls.Add(this.SetPIN);
this.Controls.Add(this.pinBox);
this.Controls.Add(this.ClientPIN_getKeyAgreement);
......@@ -304,8 +383,6 @@
this.Controls.Add(this.dumpIDSecret);
this.Controls.Add(this.getAttestationPublicKey);
this.Controls.Add(this.getPuKxRx);
this.Controls.Add(this.label2);
this.Controls.Add(this.CBORbox);
this.Controls.Add(this.clearWindow);
this.Controls.Add(this.getInfo);
this.Controls.Add(this.selectFIDOApplet);
......@@ -316,6 +393,11 @@
this.tabPage1.PerformLayout();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.tabControl2.ResumeLayout(false);
this.tabPage4.ResumeLayout(false);
this.tabPage4.PerformLayout();
this.tabPage5.ResumeLayout(false);
this.tabPage5.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
......@@ -328,7 +410,6 @@
private TextBox APDUbox;
private Button clearWindow;
private TextBox CBORbox;
private Label label2;
private Button getPuKxRx;
private Button getAttestationPublicKey;
private Button dumpIDSecret;
......@@ -346,5 +427,13 @@
private Button ClientPIN_getKeyAgreement;
private TextBox pinBox;
private Button SetPIN;
private Button btnOpenCert;
private TextBox certBox;
private OpenFileDialog openFileDialog1;
private Button btnLoadDefaultCert;
private Button btnLoadCert;
private TabControl tabControl2;
private TabPage tabPage4;
private TabPage tabPage5;
}
}
\ No newline at end of file
......@@ -739,5 +739,72 @@ namespace FidoReader
return cborWriter.Encode();
}
private void btnLoadDefaultCert_Click(object sender, EventArgs e) {
selectFIDOApplet_Click(sender, e);
string defaultCertHexString =
"3082013c3081e4a003020102020a47901280001155957352300a06082a8648ce" +
"3d0403023017311530130603550403130c476e756262792050696c6f74301e17" +
"0d3132303831343138323933325a170d3133303831343138323933325a303131" +
"2f302d0603550403132650696c6f74476e756262792d302e342e312d34373930" +
"313238303030313135353935373335323059301306072a8648ce3d020106082a" +
"8648ce3d030107034200048d617e65c9508e64bcc5673ac82a6799da3c144668" +
"2c258c463fffdf58dfd2fa3e6c378b53d795c4a4dffb4199edd7862f23abaf02" +
"03b4b8911ba0569994e101300a06082a8648ce3d0403020347003044022060cd" +
"b6061e9c22262d1aac1d96d8c70829b2366531dda268832cb836bcd30dfa0220" +
"631b1459f09e6330055722c8d89b7f48883b9089b88d60d1d9795902b30410df";
certBox.Text = defaultCertHexString;
foreach (var command in generateCertLoadingCommand(defaultCertHexString)) {
executecCommand(command);
}
}
private void btnLoadCert_Click(object sender, EventArgs e) {
selectFIDOApplet_Click(sender, e);
foreach (var command in generateCertLoadingCommand(certBox.Text)) {
executecCommand(command);
}
}
private LinkedList<CommandApdu> generateCertLoadingCommand(string hexString) {
LinkedList<CommandApdu> list = new LinkedList<CommandApdu>();
hexString = "42" + hexString;
hexString = hexString
.Replace("\r", "")
.Replace("\n", "")
.Replace("\t", "");
byte[] certBytes = Convert.FromHexString(hexString);
int certOffset = 0;
int byteLength = certBytes.Length;
while (byteLength > 0) {
CommandApdu command = new CommandApdu(IsoCase.Case4Short, SCardProtocol.T1);
if (byteLength > 240) {
command.CLA = 0x90;
command.Data = certBytes[certOffset..(certOffset+240)];
certOffset += 240;
} else {
command.CLA = 0x80;
command.Data = certBytes[certOffset..];
certOffset += command.Data.Length;
}
command.INS = 0x10;
command.P1P2 = 0;
byteLength -= command.Data.Length;
list.AddLast(command);
}
return list;
}
private void btnOpenCert_Click(object sender, EventArgs e) {
openFileDialog1.Filter = "*.der|*.der";
openFileDialog1.FileName = "";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK) {
FileStream file = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
byte[] fileBuffer = new byte[file.Length];
file.Read(fileBuffer, 0, fileBuffer.Length);
certBox.Text = Convert.ToHexString(fileBuffer);
}
}
}
}
\ No newline at end of file
......@@ -57,4 +57,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment