EldoS | Feel safer!

Software components for data protection, secure storage and transfer

LoadFromStreamPKCS7 doesn't load certificates

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#32877
Posted: 04/01/2015 03:43:07
by Sohel Shekha (Basic support level)
Joined: 03/02/2015
Posts: 9

I have exported Root and intermediate certificates in PKCS7 file and trying to use LoadFromStreamPKCS7 method of TElCustomCertStorage to read those certificates but it executes with zero certificates actually. Below is my code, what am i doing wrong?

public class ConcreteTElCustomCertStorage : TElCustomCertStorage
{
public override void Remove(int Index)
{
// nothing for now.
}

public override void Add(TElX509Certificate Certificate, bool CopyPrivateKey = true)
{
// nothing for now.
}
}

private void OnSecureClientCertificateValidate(Object sender, SBX509.TElX509Certificate certificate, ref bool validate)
{
string msg;
TElX509Certificate cert;
cert = certificate;
int Reason = 0;
TSBCertificateValidity certValidity = new TSBCertificateValidity();

TElX509CertificateValidator CertificateValidator = new TElX509CertificateValidator();
CertificateValidator.OfflineMode = true;
CertificateValidator.MandatoryCRLCheck = false;
CertificateValidator.MandatoryRevocationCheck = false;
CertificateValidator.MandatoryOCSPCheck = false;

CertificateValidator.CheckCRL = false;
CertificateValidator.CheckOCSP = false;
CertificateValidator.IgnoreCAKeyUsage = true;

// Add Windows store Root certificates
TElCustomCertStorage CustomCertStorage = new ConcreteTElCustomCertStorage();
System.IO.FileStream fileStream = new System.IO.FileStream("/sdcard/Download/MS_Root_Certs.p7b", System.IO.FileMode.Open);
CustomCertStorage.LoadFromStreamPKCS7(fileStream, 0);
CertificateValidator.AddTrustedCertificates(CustomCertStorage);

// Add Windows store Intermediate certificates
CustomCertStorage = new ConcreteTElCustomCertStorage();
fileStream = new System.IO.FileStream("/sdcard/Download/MS_Int_Certs.p7b", System.IO.FileMode.Open);
CustomCertStorage.LoadFromStreamPKCS7(fileStream, 10);
CertificateValidator.AddTrustedCertificates(CustomCertStorage);

msg = "ServerCert.CommonName = " + certificate.SubjectName.CommonName + "\r\n";
RunOnUiThread(() => Dialog_TextBox.Append(msg));

CertificateValidator.Validate(certificate, ref certValidity, ref Reason);
msg = "ServerCert.Validity = " + certValidity + "\r\n";
RunOnUiThread(() => Dialog_TextBox.Append(msg));

validate = (certValidity == TSBCertificateValidity.cvOk);

if (certValidity != 0)
{
msg = "Validity failure reason = " + Reason + "\r\n";
RunOnUiThread(() => Dialog_TextBox.Append(msg));
}
}

Reply

Statistics

Topic viewed 347 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!