Quantcast
Viewing all 8156 articles
Browse latest View live

How to check a Certificate Revocation (CRL) using X509 Certificates in C#.NET?

Hi,

I need to use VeriSign CRL Location (URL) to check the Revocation (CRL) of Certificate in .NET framework. I find X509Chain class in .NET which has RevocationFlag, RevocationMode but not sure how to implement using CRL Location URL that is provided by VeriSign.

CRLs are publicly available from distribution points like HTTP or LDAP servers. A certificate usually contains a CRLDistributionPoints extension with a link to the location from where the corresponding CRL can be obtained. If we get Online Certificate Status Protocol (OCSP) or certificate revocation lists (CRLs), how do we check the status of Certificate revocation of X.509 certificates.


Please let me known is there any way to fetch CRL distribution point using .NET Framework 2.0 or 3.5.
I appreciate your guidance on this.

Thanks


Y. Haranadha Babu

How to Verify Certification Revocation (CRL) using x509chain??????

 

Hi,

I am developing a digital signature verification component  in C# .NET.

 

 In this verification I need to check the Certificate revocation status against a Offline CRL stored in a directory?

 

chk the below code by using  status online  i done that . but status offile i couldn't find any exapmle

X509Chain

chain = newX509Chain();

chain.ChainPolicy.RevocationFlag =

X509RevocationFlag.EntireChain;

chain.ChainPolicy.RevocationMode =

X509RevocationMode.Online; // | X509RevocationMode.Offline;

chain.ChainPolicy.UrlRetrievalTimeout =

newTimeSpan(0, 0, 30);

chain.ChainPolicy.VerificationFlags =

X509VerificationFlags.NoFlag;

chain.Build(certificate);

if (chain.ChainStatus.Length != 0)

Console.WriteLine(chain.ChainStatus[0].Status);

 

Could some one please let me know how to use X509Chain object for offline CRL verification? I didnt find any examples.  Or is there any other mechanism to do this checking?

 

Thnaks-

Supraja

Not getting a setting from the config file

Hi all;

We have a situation where on one person't computer, it is not reading a value set in the config file. Works fine elsewhere. This is an add-in to Word so the file is winword.exe.config and is as follows:

<configSections><section name="WindwardReports" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/></configSections><WindwardReports><add key="sql.timeout" value="240"/></WindwardReports>

And the code is:

var coll = System.Configuration.ConfigurationManager.GetSection("WindwardReports");

var str = coll["sql.timeout"];

How can we figure out why this is not working? Is there a way to list out what sequence of config files .NET is looking at and what it is seeing?

thanks - dave


What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

CheckX509RevocationMode check certificate revocation status against an offline CRL C# .NET 4.5

Hello everybody
 

I have a Project where I have to create a digital signature verification component  in C# .NET.

 

Because of the internet connection, I must to Offline CRL. So, I need to retrieve each certificate in a loop to check its certicate revocation status against an offline CRL that was previously stored in a server.

So, Im using this:

 

X509Chain ch = new X509Chain(); ch.Build (certificate); Console.WriteLine ("Chain Information"); ch.ChainPolicy.RevocationMode = X509RevocationMode.Online; Console.WriteLine ("Chain revocation flag: {0}", ch.ChainPolicy.RevocationFlag); Console.WriteLine ("Chain revocation mode: {0}", ch.ChainPolicy.RevocationMode); Console.WriteLine ("Chain verification flag: {0}", ch.ChainPolicy.VerificationFlags); Console.WriteLine ("Chain verification time: {0}", ch.ChainPolicy.VerificationTime); Console.WriteLine ("Chain status length: {0}", ch.ChainStatus.Length); Console.WriteLine ("Chain application policy count: {0}", ch.ChainPolicy.ApplicationPolicy.Count); Console.WriteLine ("Chain certificate policy count: {0} {1}", ch.ChainPolicy.CertificatePolicy.Count, Environment.NewLine);

if (chain.ChainStatus.Length != 0)

Console.WriteLine(chain.ChainStatus[0].Status);

Could some one please let me know how to use X509Chain object for offline CRL verification?

Thanks in advance,

Ivo

ManagementObjectCollection

Below code is working fine in Window 2003 32 bit. but i am using code in window 2008 R2 and above OS. It takes lot of time 

Please any help me. Is there any setting related issue.....

ManagementObjectCollection moReturn;ManagementObjectCollection moReturnTotalPorts;


                //Get The Total Number of services for Depth
                moSearch = new ManagementObjectSearcher("Select * from  Win32_Service WHERE Name like  'DEPTH_REMOTE_WIN_SERVER_" + PortFrom + "%' ");
                moReturnTotalPorts = moSearch.Get();
                iTotalNoofPorts = moReturnTotalPorts.Count;

                //Get The Total Number of Running services for Depth
                moSearch = new ManagementObjectSearcher("Select * from  Win32_Service WHERE State='Running' and Name like 'DEPTH_REMOTE_WIN_SERVER_" + PortFrom + "%'  ");
                moReturn = moSearch.Get();
                iActivePorts = moReturn.Count;
                System.Diagnostics.EventLog.WriteEntry("GetPortDetails", "GetPortDetails start 1");
                if (NoOfMainPortUseres > 0)
                {
                 if (RemoteServers.Trim() != "")
                  {
                      System.Diagnostics.EventLog.WriteEntry("GetPortDetails", "GetPortDetails start 2 RemoteServers.Trim()!=''");
                    //NoOfMainPortUseres.                     
                      string[] sServerInfo;
                      string[] sPortInfo;

                      sServerInfo = RemoteServers.Trim().ToString().Split(("#").ToCharArray());
                      sPortInfo = sServerInfo[0].Trim().ToString().Split((",").ToCharArray());
                      System.Diagnostics.EventLog.WriteEntry("GetPortDetails", "sServerInfo --" + RemoteServers);
                      System.Diagnostics.EventLog.WriteEntry("GetPortDetails", "sPortInfo --" + sPortInfo);

                      CreatePort(sPortInfo[1].ToString() , sPortInfo[2].ToString(),sPortInfo[3].ToString());

                      try
                      {
                          objSession_Info = (IDepth.ISession_Info)Activator.GetObject(typeof(IDepth.ISession_Info), "tcp://" + sPortInfo[0].ToString() + ":" + sPortInfo[1].ToString()+ "/Session_Info");
                          objSession_Info.MaxUserinRootPort();

                          i = objSession_Info.MaxUserInMainPort;
                          if (NoOfMainPortUseres > i )
                          {
                              return objSession_Info.GetPortDetails() + "#" + sPortInfo[0].ToString() + "," + sPortInfo[2].ToString() + ","+ sPortInfo[3].ToString();
                              //return
                          }
                          System.Diagnostics.EventLog.WriteEntry("GetPortDetails", "GetPortDetails End 2 RemoteServers.Trim()!=''");

                      }

                      catch (Exception ex)
                      {
                          System.Diagnostics.EventLog.WriteEntry("Depth Distributor", ex.Message);
                     //     throw;
                      }

                  }
                }
                System.Diagnostics.EventLog.WriteEntry("GetPortDetails", "GetPortDetails start 2 RemoteServers.Trim()--"+ MaxUser.ToString());
               int iPortCounter = 0;
               Boolean bPortHang = false;
                //Get The Total Number of Running services for Depth
myNewLabel: //Added by JK for Port Issue
                if (MaxUser != 0)
                {
                    System.Diagnostics.EventLog.WriteEntry("GetPortDetails", "GetPortDetails start 2 if (MaxUser != 0)");
                    foreach (ManagementObject Mo in moReturn)
                    {
                        field = Mo["Name"].ToString().Split(("_").ToCharArray());
                        if (bPortHang == false)
                        {
                            StrPortName = field[field.Length - 1];
                        }
                        else
                        {
                            StrPortName = Convert.ToString(Convert.ToInt16(StrPortName) + 1);
                            bPortHang = false;
                        }

                        objSession_Info = (IDepth.ISession_Info)Activator.GetObject(typeof(IDepth.ISession_Info), "tcp://localhost:" + StrPortName.Trim() + "/Session_Info");
                        int iCurrentUserPerPort = objSession_Info.CurrentUser;

                        //Checking For the Maxmimum Per Port
                        //Else Create New Port
                        if (iCurrentUserPerPort >= MaxUser)
                        { 


                                ////System.ServiceProcess.ServiceController myController1 = null;
                                ////myController1 = new System.ServiceProcess.ServiceController("DEPTH_REMOTE_WIN_SERVER_" + StrPortName);
                                ////myController1.Refresh();
                                ////        if (myController1.Status == System.ServiceProcess.ServiceControllerStatus.Running)
                                ////        {
                                ////            //bPortStarted = true; commented by JK for port issue

                                ////            /*Port issue testing*/
                                ////            IDepth.ICommonTransactionFunc objCon;
                                ////            objCon = (IDepth.ICommonTransactionFunc)Activator.GetObject(typeof(IDepth.ICommonTransactionFunc),"tcp://localhost:" + StrPortName.Trim() + "/CommonTransactionFunc");
                                ////            DataSet dSet=null;
                                ////            String sTmp=objCon.RetrieveSearchData("GLVER", "", "", "","", ref dSet, null);


                                ////            if (dSet == null)
                                ////            {
                                ////                sReturnPortNO = "";
                                ////                continue; 
                                ////            }
                                            sReturnPortNO = "";
                                            continue; 
                                            /*Port issue testing*/

                                       // }          

                        }
                        else
                        { sReturnPortNO = StrPortName; return sReturnPortNO; }

                        iPortCounter = iPortCounter + 1;
                    }

                    //Checking For The Stoppe Ports 
                    if ((iTotalNoofPorts - iActivePorts) == 0)
                    {
                        if (bCreatePort == true)
                        {
                            if (moReturn.Count == 0) { CreateNewPort(PortFrom + "00"); return PortFrom + "00"; }
                            else
                            { if (sReturnPortNO == "")sReturnPortNO = CreateNewPort(StrPortName); }
                        }
                    }

                     //If Ports Present with Stopped Status Then Restart the Port
                    else
                    {
myLabel:
                        if (sUnResponcePort == "")
                        { moSearch = new ManagementObjectSearcher("Select * from  Win32_Service WHERE  State='Stopped' and Name like 'DEPTH_REMOTE_WIN_SERVER_" + PortFrom +"%'"); }
                        else
                        { moSearch = new ManagementObjectSearcher("Select * from  Win32_Service WHERE  State='Stopped' and Name like 'DEPTH_REMOTE_WIN_SERVER_" + PortFrom +"%'  " + sUnResponcePort.Trim() + " "); }

                        moReturn = moSearch.Get();

                        //Start Of 6 ----> if All Stopped Ports are Not Responding
                        if (moReturn.Count == 0)
                        {
                            int iTempNumOfPorts =1;
                            foreach (ManagementObject Mo in moReturnTotalPorts)
                            {
                                //Check For The Last Port
                                if (iTotalNoofPorts == iTempNumOfPorts)
                                {
                                    //if Last Port 
                                    string[] Tempfield;
                                    string sTempPortNumber = "";
                                    Tempfield = Mo["Name"].ToString().Split(("_").ToCharArray());
                                    sTempPortNumber = Tempfield[Tempfield.Length - 1];

                                    //Check for User Has Rights to Create Port
                                    if (bCreatePort == true)
                                    {
                                        //Creating a New Port
                                        return sReturnPortNO = CreateNewPort((int.Parse(sTempPortNumber) + 1).ToString());
                                    }
                                    else
                                    {return sReturnPortNO = "";}

                                }
                                iTempNumOfPorts++;
                            }

                        }
                        //End Of 6

                        foreach (ManagementObject Mo in moReturn)
                        {
                            System.Diagnostics.EventLog.WriteEntry("Get Port Detail", "Before Restarting Available Port;-"+DateTime.Now.ToString());
                            field = Mo["Name"].ToString().Split(("_").ToCharArray());
                            StrPortName = field[field.Length - 1];
                            sReturnPortNO = "";// StrPortName;
                            Assembly a = Assembly.LoadFrom(Application.StartupPath + "\\DEPTH_REMOTE_ADMIN.exe");
                            Type mytypes = a.GetType("DEPTH_REMOTE_ADMIN.DepthProfiler");
                            Object obj = Activator.CreateInstance(mytypes);
                            iBool = Boolean.Parse(mytypes.InvokeMember("RestartServer", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, new object[] { StrPortName }).ToString());

                            System.Diagnostics.EventLog.WriteEntry("Get Port Detail", "After Restarting Available Port;-" + DateTime.Now.ToString());
                            if (iBool == true)
                            {
                                DateTime dtStartime = DateTime.Now;
                                DateTime dtEndtime = DateTime.Now;
                                Boolean bPortStarted = false;


                                System.ServiceProcess.ServiceController myController = null;
                                myController = new System.ServiceProcess.ServiceController("DEPTH_REMOTE_WIN_SERVER_" + StrPortName);

                                do
                                {
                                        myController.Refresh();
                                        if (myController.Status == System.ServiceProcess.ServiceControllerStatus.Running)
                                        {
                                            bPortStarted = true; //commented by JK for port issue

                                            /*Port issue testing*/
                                            ////IDepth.ICommonTransactionFunc objCon;
                                            ////objCon = (IDepth.ICommonTransactionFunc)Activator.GetObject(typeof(IDepth.ICommonTransactionFunc),"tcp://localhost:" + StrPortName.Trim() + "/CommonTransactionFunc");
                                            ////DataSet dSet=null;
                                            ////String sTmp=objCon.RetrieveSearchData("GLVER", "", "", "","", ref dSet, null);


                                            ////if (dSet == null)
                                            ////{
                                            ////    bPortStarted = false;
                                            ////    bPortHang = true;
                                            ////    goto myNewLabel;
                                            ////}
                                            ////else
                                            ////{
                                            ////    bPortStarted = true;
                                            ////}
                                            /*Port issue testing*/

                                        }                                   

                                    dtEndtime = DateTime.Now;

                                    if (DateDiff(DateInterval.Second, dtStartime, dtEndtime) >= 15)
                                    {sUnResponcePort = sUnResponcePort + " AND Name <> 'DEPTH_REMOTE_WIN_SERVER_" + StrPortName + "'";
                                     goto myLabel;}
                                }
                                while (bPortStarted == false);

                               sReturnPortNO = StrPortName;
                                return sReturnPortNO;
                            }

                        }


                    }

                                                                                                                                                                                                                                    

How do I get into command mode in SQL Server 2014?

In the only reference I can find for Command Mode, I am instructed to use the icon on query toolbar, but I can not identify it. Is there a menu alternative? can I invoke it through code?

Sandy Shin

Licence key in .NET

I am thinking of implementing a good licensing mechanism that has a good resistance against piracy. The required mechanism should use a licence key and the licence key must update regularly. Do you guys have any better suggestions? What are the parameters/algorithms/characteristics that I need to concern to make a hack proof license mechanism?

using sData in C# to post sales

Hi,

I would like to anyone tried to knows where to get details on how to post sales into Sage 50 Accounting using C# andsData.


Thanks,
Jassim

Win32Exception from ReleaseCapture call in Window.ShowDialog

Hi,

We are getting "The operation completed successfully" Win32 exception in a very specific use case. In our application there are some old windows made in Progress OpenEdge that can be opened as children of a main window. The problem occurs when a user opens a context menu in one of them and then tries to open a modal window with a shortcut, they get the following exception:

System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully
at MS.Win32.SafeNativeMethods.ReleaseCapture()
at System.Windows.Window.ShowDialog()

[the next line is already our ShowModalWindow method]

The relevant fragment of System.Windows.Window class on Reference Source has some interesting comments:

if (hWndCapture != IntPtr.Zero)
{
    //
    // NOTE: hamidm -- 7/14/04
    // EnableWindow(false) (called from EnableThreadWindows(false)
    // sends WM_CANCELMODE to the window, so we don't need
    // to send it again.  However, if we change our impl
    // of dialog such that we don't disable all windows on the
    // thread, then we would need this call. Keeping this code here
    // until we finish the Dialog task # 18498

    // UnsafeNativeMethods.SendMessage(hWndCapture,
    //                                WindowMessage.WM_CANCELMODE,
    //                                IntPtr.Zero,
    //                                IntPtr.Zero);

    // hWndCapture = UnsafeNativeMethods.GetCapture();
    // if (hWndCapture != IntPtr.Zero)
    // {
        // PS # 862892
        // WCP: Investigate whether ReleaseCapture is needed in ShowDialog
        SafeNativeMethods.ReleaseCapture();
    // }
}

Simply catching an exception causes the main window to freeze, but leaves the old form operational.

Any ideas what might be causing this behavior and how can we fix it?

Thanks,
Marek

AttachConsole() - Console.WriteLine() doesn't work sometimes

I know, that this question has been stated before - but I didn't find any answer.

Let's take this simple example:


    static class Program
    {
        [DllImport("kernel32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool AttachConsole([MarshalAs(UnmanagedType.U4)] int dwProcessId);

        [STAThread]
        static void Main()
        {
            if (AttachConsole(-1))
                Console.WriteLine(@"AttachConsole() succeeded!");
            else
                MessageBox.Show(@"AttachConsole() failed!");
        }
    }

When I start cmd.exe (For example by Run) - it works - I get "AttachConsole() succeeded".

When I start it in any named window (e.g. Developer Command Prompt) - I get nothing. No console output, no message box. Moreover - when I run Marshal.GetLastWin32Error() - I get 2 (File not found).

Is there any way to lose this problem?

IE 10 prompt username password and other browser working fine

IE 10 prompt username password and other browser working fine.

The  below workaround is not working for me.

I tried two options, but both are not working my machine
1. Added site as a trusted site
2. Internet Options, Internet, Custom Level and set the User Authentication --> Logon to "Automatically logon with current user name and password

Thanks

Chandirasekaran


VS 2010 and sql server support

Hi,

I'm currently using VS 2010 10.0.40219.1,Framework 4.5.50938 SP1 

Is the above is supported with sql servers versions of 2012, 2014.

What if i switch to  VS2012, will it support sql server 2008, 2008 R2.

Pleas share your inputs

Thanks

I am facing a Problem with reading images from database

Hi everybody..

any help will be most appreciated, I am facing problem with reading images from database. I am pasting my code... 


                string connect = "datasource = localhost; port = 3306; username = root; password = ;"; 
                MySqlConnection conn = new MySqlConnection(connect); // creating connecting string
                MySqlCommand sda = new MySqlCommand(@"select * from management.add_products ", conn); //creating query
                MySqlDataReader reader; 
                try
                {
                    conn.Open(); // Opening Connection
                    reader = sda.ExecuteReader(); // Executing my Query..
                    while (reader.Read())
                    {
                        byte[] imgg = (byte[])(reader["Picture"]);
                        if (imgg == null)
                            pc1.Image = null;
                        else
                        {
                            MemoryStream mstream = new MemoryStream(imgg);
                            pc1.Image = System.Drawing.Image.FromStream(mstream);
                        }
                }

It says Parameter not Valid... i am reading all the images from database


files with the same name in the blob storage

Hi!

I´m new with azure and blobs

My question is: If I upload 3 files with the same name, what it´s going to happend? the 3 files are going to storage in the conteiner? only one of the files it´s going to storage?

Thanks

I Have Problem In filtering in gridview by using binding source

bs.Filter = String.Format("SalesDate >= '{0:yyyy-MM-dd}' AND SalesDate <= '{1:yyyy-MM-dd}' ", FromDate, ToDate);

By Using This above filtering line, I got this error

Cannot perform '>=' operation on System.DateTime and System.String.


Discover Bluetooth LE Device and its custom service with uuid and its characteristics

Hello Team,

I have a requirement for developing a library in C# which can be used in any windows app (Metro or Non Metro) apps to discover Bluetooth LE devices which are advertising a custom service with uuid and pair and find all the characteristics of the service and send parameters and receive response.

I have tried 32feet.NET library which everyone talks about but realized it doesn't support Bluetooth LE devices. Is there any way I can do that? Or do I have write C# wrapper to use winsock2.2 library to call native code to access Bluetooth stack?

Please suggest. We have been able to achieve this requirement in Mac OSX by using their core Bluetooth framework.

how to deserialize xml with structure of abitrary nested layers of base class?

let say i want to represent arithmetic expression using xml:

<?xml version="1.0" encoding="utf-8" ?><expr><add><num>10</num><num>20</num></add></expr>

and here is my classes to represent this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    public abstract class Evaluable
    {
        public abstract int Eval();
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Test
{
    [Serializable]
    [XmlRoot("expr")]
    public class Expr
    {
        [XmlElement]
        public Evaluable Evaluable { get; set; }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Test
{
    [Serializable]
    [XmlRoot("add")]
    [XmlType("add")]
    public class Add : Evaluable
    {
        [XmlElement]
        public List<Evaluable> Elems { get; set; }

        public override int Eval()
        {
            return Elems.Select(e => e.Eval()).Sum();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Test
{
    [Serializable]
    [XmlRoot("num")]
    [XmlType("num")]
    public class Num : Evaluable
    {
        [XmlText]
        public int Val { get; set; }

        public override int Eval()
        {
            return Val;
        }
    }
}

but it doesn't work, and it's reasonable, since Serializer doesn't know any thing about the subclass. but how to make it work?

here is my deserialization code:

var serializer = new XmlSerializer(typeof(Expr), new[] { typeof(Add), typeof(Num) });
            Expr expr = null;
            using (var file = new StreamReader("expr.xml"))
            {
                expr = serializer.Deserialize(file) as Expr;
            }

RegistryKey showing Object reference not set to an instance of an object

Hi,

Why I am getting Object reference not set to an instance of an object when trying to read from registry? although I have a valid value there! The error is shown on this line:

connection_string = "Server=" + myapplication.GetValue("ServerHost").ToString() + ";";

and the value of ServerHost is 127.0.0.1


public string get_connectionstring(string system_key)
{
    string connection_string;

    RegistryKey myapplication_registry = Registry.LocalMachine.OpenSubKey("SOFTWARE\\myapplication", true);
    RegistryKey system_registry = Registry.LocalMachine.OpenSubKey("SOFTWARE\\myapplication\\" + system_key, true);

    connection_string = "Server=" + myapplication.GetValue("ServerHost").ToString() + ";";
    connection_string += "Port=" + myapplication.GetValue("ServerPort").ToString() + ";";
    connection_string += "Database=" + system_registry.GetValue("DatabaseName").ToString() + ";";
    connection_string += "Uid=" + myapplication.GetValue("ServerUserID").ToString() + ";";
    connection_string += "Pwd=" + cipher_utility.Decrypt<RijndaelManaged>(myapplication.GetValue("ServerPassword").ToString(), "{xxxx-xxxx-xxxx-xxxx-xxxxxxx}", "{xxxx-xxxx-xxx-xxx-xxxxxxx}") + ";";
    connection_string += "Connect Timeout=" + myapplication.GetValue("ConnectTimeout").ToString()+ ";";
    connection_string += "default command timeout=" + myapplication.GetValue("ConnectTimeout").ToString() + ";";

    return connection_string;
}

multilingual website in asp .net using unicode.

Dear sir,

I just want to create a website which support multiple languages. I want to develop this website without using the Google translator and asp .net resource file.

I am trying it using Unicode concept. 

Language should be changed according to the selected language and the input by the user should be according to selected language.

Please help sir..

Thank you in advance..

Which one is the best source code in Microsoft Developer Network Samples?

Viewing all 8156 articles
Browse latest View live