Skip to content

Commit

Permalink
Small code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Lawrence committed Sep 18, 2019
1 parent ed7b871 commit 6e162e7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 43 deletions.
92 changes: 51 additions & 41 deletions FiddlerImportNetlog/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,56 +482,35 @@ private void GenerateSocketListSession(Dictionary<int, List<Hashtable>> dictSock

// TODO: Only TLS/1.2+ have sig/hash pairs; these are omitted in TLS1.1 and earlier
for (int ixSigHashPair = 0; ixSigHashPair < cbSigHashAlgs/2; ++ixSigHashPair) {
int iHash = arrCertRequest[iPtr + (2*ixSigHashPair)];
int iSig = arrCertRequest[iPtr + (2*ixSigHashPair)+1];
string sHash;
string sSig;
switch (iHash)
{
// Hash https://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-18
case 0: sHash = "none"; break;
case 1: sHash = "md5"; break;
case 2: sHash = "sha1"; break;
case 3: sHash = "sha224"; break;
case 4: sHash = "sha256"; break;
case 5: sHash = "sha384"; break;
case 6: sHash = "sha512"; break;
default: sHash = String.Format("unknown(0x{0:x})", iHash); break;
}
switch (iSig)
{
// Sigs https://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-16
case 0: sSig = "anonymous"; break;
case 1: sSig = "rsa"; break;
case 2: sSig = "dsa"; break;
case 3: sSig = "ecdsa"; break;
case 7: sSig = "ed25519"; break;
case 8: sSig = "ed448"; break;
case 64: sSig = "gostr34102012_256"; break;
case 65: sSig = "gostr34102012_512"; break;
default: sSig = String.Format("unknown(0x{0:x})", iSig); break;
}
alSigHashAlgs.Add(String.Format("{0}_{1}", sHash, sSig));
alSigHashAlgs.Add(GetHashSigString(arrCertRequest[iPtr + (2*ixSigHashPair)], arrCertRequest[iPtr + (2*ixSigHashPair) + 1]));
}
htCertFilter.Add("Accepted SignatureAndHashAlgorithms", alSigHashAlgs);
iPtr += (cbSigHashAlgs);
//FiddlerApplication.Log.LogFormat("Found CertificateRequest on Socket #{0}:\n{1}", iSocketId, Fiddler.Utilities.ByteArrayToHexView(arrCertificateRequest, 24));
int cbCADistinguishedNames = (arrCertRequest[iPtr++] << 8) +
arrCertRequest[iPtr++];

var alCADNs = new ArrayList();
while (cbCADistinguishedNames > 0)
try
{
int cbThisDN = (arrCertRequest[iPtr++] << 8) + arrCertRequest[iPtr++];
Debug.Assert(cbThisDN < cbCADistinguishedNames);
byte[] bytesDER = new byte[cbThisDN];
Buffer.BlockCopy(arrCertRequest, iPtr, bytesDER, 0, cbThisDN);
AsnEncodedData asndata = new AsnEncodedData(bytesDER);
alCADNs.Add(new X500DistinguishedName(asndata).Name);
iPtr += cbThisDN;
cbCADistinguishedNames -= (2+cbThisDN);
var alCADNs = new ArrayList();
while (cbCADistinguishedNames > 0)
{
int cbThisDN = (arrCertRequest[iPtr++] << 8) + arrCertRequest[iPtr++];
Debug.Assert(cbThisDN < cbCADistinguishedNames);
try
{
byte[] bytesDER = new byte[cbThisDN];
Buffer.BlockCopy(arrCertRequest, iPtr, bytesDER, 0, cbThisDN);
AsnEncodedData asndata = new AsnEncodedData(bytesDER);
alCADNs.Add(new X500DistinguishedName(asndata).Name);
}
catch { Debug.Assert(false); }
iPtr += cbThisDN;
cbCADistinguishedNames -= (2 + cbThisDN);
}
htCertFilter.Add("Accepted Authorities", alCADNs);
}
htCertFilter.Add("Distinguished Names", alCADNs);
catch { }

continue;
}
Expand All @@ -550,6 +529,37 @@ private void GenerateSocketListSession(Dictionary<int, List<Hashtable>> dictSock
catch (Exception e) { FiddlerApplication.Log.LogFormat("GenerateSocketListSession failed: " + DescribeExceptionWithStack(e)); }
}

private static string GetHashSigString(int iHash, int iSig)
{
string sHash;
string sSig;
switch (iHash)
{
// Hash https://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-18
case 0: sHash = "none"; break;
case 1: sHash = "md5"; break;
case 2: sHash = "sha1"; break;
case 3: sHash = "sha224"; break;
case 4: sHash = "sha256"; break;
case 5: sHash = "sha384"; break;
case 6: sHash = "sha512"; break;
default: sHash = String.Format("unknown(0x{0:x})", iHash); break;
}
switch (iSig)
{
// Sigs https://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-16
case 0: sSig = "anonymous"; break;
case 1: sSig = "rsa"; break;
case 2: sSig = "dsa"; break;
case 3: sSig = "ecdsa"; break;
case 7: sSig = "ed25519"; break;
case 8: sSig = "ed448"; break;
case 64: sSig = "gostr34102012_256"; break;
case 65: sSig = "gostr34102012_512"; break;
default: sSig = String.Format("unknown(0x{0:x})", iSig); break;
}
return String.Format("{0}_{1}", sHash, sSig);
}
private int GenerateSessionsFromURLRequests(Dictionary<int, List<Hashtable>> dictURLRequests)
{
int cURLRequests = dictURLRequests.Count;
Expand Down
4 changes: 2 additions & 2 deletions FiddlerImportNetlog/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
[assembly: AssemblyCopyright("Copyright ©2019 Eric Lawrence")]
[assembly: System.Resources.NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.2.0.0")] // ALSO UPDATE THE VERSION in the [ProfferFormat] attribute to match!
[assembly: AssemblyVersion("1.2.0.0")] // ALWAYS UPDATE THE VERSION in the [ProfferFormat] attribute to match!
[assembly: Fiddler.RequiredVersion("4.6.0.0")]

// v1.2
// Parse CertificateRequest TLS Handshake message and SSL_HANDSHAKE_MESSAGE_RECEIVED
// Parse CertificateRequest TLS Handshake message and SSL_HANDSHAKE_MESSAGE_RECEIVED.

// v1.1.2
// Support ZIP compressed JSON logs
Expand Down

0 comments on commit 6e162e7

Please sign in to comment.