// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
public static X509Certificate CreateFromCertFile (string filename)
{
byte[] data = null;
- using (FileStream fs = new FileStream (filename, FileMode.Open)) {
+ using (FileStream fs = File.OpenRead (filename)) {
data = new byte [fs.Length];
fs.Read (data, 0, data.Length);
fs.Close ();
Marshal.Copy (cc.pbCertEncoded, data, 0, (int)cc.cbCertEncoded);
x509 = new Mono.Security.X509.X509Certificate (data);
}
+#if NET_2_0
+ else
+ throw new ArgumentException ("Invalid handle.");
+#endif
// IntPtr.Zero results in an "empty" certificate instance
}
public X509Certificate (System.Security.Cryptography.X509Certificates.X509Certificate cert)
{
+#if NET_2_0
+ if (cert == null)
+ throw new ArgumentNullException ();
+#endif
+
if (cert != null) {
byte[] data = cert.GetRawCertData ();
if (data != null)
return false;
}
}
- return (x509.RawData == null);
+ else
+ return false;
+ return x509 == null || (x509.RawData == null);
}
// LAMESPEC: This is the equivalent of the "thumbprint" that can be seen
}
// strangly there are no DateTime returning function
- // LAMESPEC: Microsoft returns the local time from Pacific Time (GMT-8)
- // BUG: This will not be corrected in Framework 1.1 and also affect WSE 1.0
public virtual string GetEffectiveDateString ()
{
if (hideDates)
return null;
- DateTime dt = x509.ValidFrom.ToUniversalTime().AddHours (-8);
- return dt.ToString (); //"yyyy-MM-dd HH:mm:ss");
+#if NET_2_0
+ return x509.ValidFrom.ToString ();
+#else
+ // LAMESPEC: Microsoft returns the local time from Pacific Time (GMT-8)
+ // BUG: This will not be corrected in Framework 1.1 and also affect WSE 1.0
+ return x509.ValidFrom.ToUniversalTime ().AddHours (-8).ToString ();
+#endif
}
// strangly there are no DateTime returning function
- // LAMESPEC: Microsoft returns the local time from Pacific Time (GMT-8)
- // BUG: This will not be corrected in Framework 1.1 and also affect WSE 1.0
public virtual string GetExpirationDateString ()
{
if (hideDates)
return null;
- DateTime dt = x509.ValidUntil.ToUniversalTime().AddHours (-8);
- return dt.ToString (); //"yyyy-MM-dd HH:mm:ss");
+#if NET_2_0
+ return x509.ValidUntil.ToString ();
+#else
+ // LAMESPEC: Microsoft returns the local time from Pacific Time (GMT-8)
+ // BUG: This will not be corrected in Framework 1.1 and also affect WSE 1.0
+ return x509.ValidUntil.ToUniversalTime ().AddHours (-8).ToString ();
+#endif
}
// well maybe someday there'll be support for PGP or SPKI ?
// TODO - PKCS12 without password
} else {
// try PKCS#12
- PKCS12 pfx = new PKCS12 (rawData, password);
- if (pfx.Certificates.Count > 0) {
- x509 = pfx.Certificates [0];
- } else {
- x509 = null;
+ try {
+ PKCS12 pfx = new PKCS12 (rawData, password);
+ if (pfx.Certificates.Count > 0) {
+ x509 = pfx.Certificates [0];
+ } else {
+ x509 = null;
+ }
+ }
+ catch {
+ // it's possible to supply a (unrequired/unusued) password
+ // fix bug #79028
+ x509 = new Mono.Security.X509.X509Certificate (rawData);
}
}
}