[Mono-devel-list] two questions about Mono.Security.dll

liubin liub at necas.nec.com.cn
Fri Jul 1 01:39:38 EDT 2005

I am very interested in the SSL/TLS function of Novell.Directory.Ldap.dll and 
Mono.Security.dll. I have built the Novell CsharpLDAP's sample source 
StartTLS.cs with mono1.1.8's Novell.Directory.Ldap.dll Mono.Security.dll
on Windows to do some test. And i found two problems about Mono.Security.dll.

<1.> The sample code can't work correctly. it always output 91 error like follows.
So i downloaded the Mono.Security.dll's source from 
http://svn.myrealbox.com/viewcvs/trunk/mcs/class/Mono.Security/  to rebuild
the Mono.Security.dll. This sample code can work correctly with this
Mono.Security.dll. it seems that this problem was resolved in the new sources.

Will mono1.1.9 contain this change and when mono1.1.9 will be released ? 

----------------run result----------------
Connecting to:liub
--------------sample StartTLS.cs's code--------
   LdapConnection conn= new LdapConnection();
   Console.WriteLine("Connecting to:" + ldapHost);
   Console.WriteLine("TLS Bind Completed Successfull");
catch(Exception e)
   Console.WriteLine("Error:" + e.Message);

<2.> I made a new root certificate and a new server certificate, then did a test
using the above sample code, but i got -2146762494(CERT_E_VALIDITYPERIODNESTING)
error, but the next day, i used the same certificate to do the test, it successed.
I think it should be a bug about Valid time check. I debuged it and found the 
reason. the reason is that ValidFrom and ValidUntil were local time, and
current time was UTC time.

There are two method to fix this problem, the one is modify ASN1Convert::ToDateTime 
function, changing return value to UTC time, the other one is just moidify 
X509Certificate::Parse function, changing m_from and m_until to UTC time.
Which one it better? If there are same problem in other place where the 
ASN1Convert::ToDateTime be called, the first one maybe better, i think.

 class X509Certificate {
  public bool IsCurrent {
   get { return WasCurrent (DateTime.UtcNow); } <== it's a UTC time
  public bool WasCurrent (DateTime instant) 
   return ((instant > ValidFrom) && (instant <= ValidUntil));
 class X509Certificate {
  private void Parse (byte[] data) 
    ASN1 notBefore = validity [0];
    m_from = ASN1Convert.ToDateTime (notBefore);
    ASN1 notAfter = validity [1];
    m_until = ASN1Convert.ToDateTime (notAfter);

 sealed class ASN1Convert {
  static public DateTime ToDateTime (ASN1 time) 
   return DateTime.ParseExact (t, mask, null); <== it's a local time


Best Regards


Liu Bin
Email: liub at necas.nec.com.cn

More information about the Mono-devel-list mailing list