Exemplo n.º 1
0
        public IRaspRequest PrepareRequest(OiosiMessage message, UddiType uddiType)
        {
            // First we need to find out what type of object we are sending
            DocumentTypeConfigSearcher typeSearcher  = new DocumentTypeConfigSearcher();
            DocumentTypeConfig         docTypeConfig = typeSearcher.FindUniqueDocumentType(message.MessageXml);

            // 1. Lookup the endpoint address and certificate using UDDI
            UddiLookupResponse uddiResponse = this.Uddi(message, docTypeConfig);

            // 2. Download the server certificate using LDAP
            X509Certificate2 serverCert = this.Ldap(uddiResponse.CertificateSubjectSerialNumber);

            // 3. Check the validity status of the certificate using OCSP
            this.Revocation(serverCert);


            // 4. Let the user configure the client certificate
            Console.WriteLine("\nPlease configure the certificate used for sending\n----------------------------------------------------");
            X509Certificate2 clientCert  = this.GetCertificate(uddiType);
            Credentials      credentials = new Credentials(new OcesX509Certificate(clientCert), new OcesX509Certificate(serverCert));

            // Create request
            RaspRequest raspRequest = new RaspRequest(new Request(uddiResponse.EndpointAddress.GetAsUri(), credentials));


            return(raspRequest);
        }
Exemplo n.º 2
0
 public OiosiRaspClient(UddiType uddiType, String xmlDocumentUrl)
 {
     this.uddiType       = uddiType;
     this.xmlDocumentUrl = xmlDocumentUrl;
 }
Exemplo n.º 3
0
        public X509Certificate2 GetCertificate(UddiType UddiType)
        {
            //Console.Write("Serial number: 45 a2 f4 a1");
            //string serial = "45 a2 f4 a1";
            // Test certificate - Must be importet into windows key store

            /*
             * Certificat - Virksomhedscertificat
             * Issued To      Christian Pedersen
             * Issued by      TDC OCES Systemtest CA II
             * Valid From     26-05-2010
             * Valid To       26-05-2012
             * Serial number  40 37 86 cc
             * StoreName      My
             * StoreLocation  CurrentUser
             *
             * can not be used - is not a funktionscertificat
             */

            /*
             * Certificat
             * Issued To      Testendpoint (funktionscertifikat)
             * Issued by      TDC OCES Systemtest CA II
             * Valid From     17-04-2008
             * Valid To       17-04-2010
             * Serial number  40 36 d8 5e
             * StoreName      My
             * StoreLocation  CurrentUser
             *
             *  Can not be used - Is a funktionscertificat, but it has expired
             */

            /*
             * Certificat
             * Issued To      FOCES1 (funktionscertifikat)
             * Issued by      TDC OCES Systemtest CA II
             * Valid From     16-10-2011
             * Valid To       16-10-2009
             * Serial number  40 37 60 8e
             * StoreName      My
             * StoreLocation  CurrentUser
             *
             *  Installed from https://www.certifikat.dk/export/sites/dk.certifikat.oc/da/developer/eksempler/
             */

            /*
             * Certificat
             * Issued To      TU GENEREL FOCES gyldig (funktionscertifikat)
             * Issued by      TRUST2408 Systemtest VIII CA
             * Valid From     26-10-2011
             * Valid To       26-10-2015
             * Serial number  4c 05 5a 37
             * StoreName      My
             * StoreLocation  CurrentUser
             *
             *  Installed from http://view.svn.softwareborsen.dk/cgi-bin/index.cgi/openebusiness/dk.gov.oiosi/common/resources/Certificates/
             */

            X509Certificate2 clientCert = null;
            string           serial     = null;

            // You can define the default certificate to use here:
            switch (UddiType)
            {
            case UddiType.Production:
            {
                serial = "56 df e9 a7";

                break;
            }

            case UddiType.Test:
            {
                //serial = "40 37 fb 49";
                serial = "4c 05 5a 37";
                break;
            }

            default:
            {
                throw new NotImplementedException("The uddi type '" + UddiType.ToString() + "' is unknown.");
            }
            }

            StoreName     storeName       = StoreName.My;
            StoreLocation storeLocation   = StoreLocation.CurrentUser;
            string        storeNameString = string.Empty;
            int           storeNameInt;
            string        storeLocationString = string.Empty;
            int           storeLocationInt;
            string        certificateString = string.Empty;
            int           certificateInt;
            X509Store     certStore;
            //bool selectAgain = false;
            bool selectNewStore = false;

            while (clientCert == null)
            {
                Console.Write("Store ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write("[" + StoreName.My + "/" + StoreName.Root + "/" + StoreName.AddressBook + "/" + StoreName.CertificateAuthority + "]: ");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(storeName.ToString());

                Console.Write("Store Location ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write("[" + StoreLocation.CurrentUser + "/" + StoreLocation.LocalMachine + "]: ");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(storeLocation.ToString());

                if (selectNewStore == false)
                {
                    // try to retrive the certificate

                    Console.WriteLine("Serial number: " + serial);

                    certStore = new X509Store(storeName, storeLocation);
                    certStore.Open(OpenFlags.ReadOnly);

                    X509Certificate2Collection collection = certStore.Certificates.Find(X509FindType.FindBySerialNumber, serial, true);
                    certStore.Close();
                    clientCert = null;

                    if (collection.Count > 0)
                    {
                        clientCert = collection[0];
                    }
                }

                if (clientCert == null)
                {
                    // the certificate not found
                    //Console.WriteLine("Certificate not found, type in new serial number: ");
                    //serial = Console.ReadLine();

                    // store name
                    do
                    {
                        Console.WriteLine();
                        Console.WriteLine("Select StoreName (type the index/int):");
                        Console.WriteLine("1 - StoreName.My");
                        Console.WriteLine("2 - StoreName.Root");
                        Console.WriteLine("3 - StoreName.AddressBook");
                        Console.WriteLine("4 - StoreName.CertificateAuthority");
                        storeNameString = Console.ReadLine();
                        if (int.TryParse(storeNameString, out storeNameInt))
                        {
                            switch (storeNameInt)
                            {
                            case 1:
                            {
                                storeName = StoreName.My;
                                break;
                            }

                            case 2:
                            {
                                storeName = StoreName.Root;
                                break;
                            }

                            case 3:
                            {
                                storeName = StoreName.AddressBook;
                                break;
                            }

                            case 4:
                            {
                                storeName = StoreName.CertificateAuthority;
                                break;
                            }

                            default:
                            {
                                Console.WriteLine("Not in range.");
                                storeNameString = string.Empty;
                                break;
                            }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Not a int!!!");
                            storeNameString = string.Empty;
                        }
                    }while (string.IsNullOrEmpty(storeNameString));

                    // StoreLocation
                    do
                    {
                        Console.WriteLine();
                        Console.WriteLine("Select StoreLocation (type the index/int):");
                        Console.WriteLine("1 - StoreName.CurrentUser");
                        Console.WriteLine("2 - StoreName.LocalMachine");
                        storeLocationString = Console.ReadLine();
                        if (int.TryParse(storeLocationString, out storeLocationInt))
                        {
                            switch (storeLocationInt)
                            {
                            case 1:
                            {
                                storeLocation = StoreLocation.CurrentUser;
                                break;
                            }

                            case 2:
                            {
                                storeLocation = StoreLocation.LocalMachine;
                                break;
                            }

                            default:
                            {
                                Console.WriteLine("Not in range.");
                                storeLocationString = string.Empty;
                                break;
                            }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Not a int!!!");
                            storeLocationString = string.Empty;
                        }
                    }while (string.IsNullOrEmpty(storeLocationString));

                    // StoreLocation

                    do
                    {
                        serial = string.Empty;
                        Console.WriteLine();
                        Console.WriteLine("Select certificate (type the index/int) (0 for new certificate location):");
                        Console.WriteLine("Index - Serial number - ExpireDate");
                        certStore = new X509Store(storeName, storeLocation);
                        certStore.Open(OpenFlags.ReadOnly);
                        X509Certificate2Enumerator x509Certificate2Enumerator = certStore.Certificates.GetEnumerator();

                        int             index = 1;
                        X509Certificate x509Certificate;
                        IDictionary <int, X509Certificate> map = new Dictionary <int, X509Certificate>();
                        //int subjectMax = 45;
                        while (x509Certificate2Enumerator.MoveNext())
                        {
                            x509Certificate = x509Certificate2Enumerator.Current;
                            map.Add(index, x509Certificate);
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.Write(" " + index + " - ");
                            //Console.ForegroundColor = ConsoleColor.Gray;
                            Console.Write(x509Certificate.GetSerialNumberString() + " - ");
                            Console.WriteLine(x509Certificate.GetExpirationDateString());
                            Console.ForegroundColor = ConsoleColor.White;
                            //if (x509Certificate.Subject.Length <= subjectMax)
                            //{
                            Console.WriteLine(x509Certificate.Subject);

                            /*}
                             * else
                             * {
                             *  Console.WriteLine(x509Certificate.Subject.Substring(0, subjectMax));
                             * }*/

                            index++;
                        }
                        certStore.Close();
                        if (index == 1)
                        {
                            Console.WriteLine("No certificate a selected location");
                            //serial = "No certificate a selected location";
                            selectNewStore = true;
                        }
                        else
                        {
                            certificateString = Console.ReadLine();

                            if (int.TryParse(certificateString, out certificateInt))
                            {
                                if (certificateInt == 0)
                                {
                                    //serial = "try Again - certificate not found";
                                    selectNewStore = true;
                                }
                                else if (map.ContainsKey(certificateInt))
                                {
                                    serial         = map[certificateInt].GetSerialNumberString();
                                    selectNewStore = false;
                                }
                                else
                                {
                                    Console.WriteLine("Index out of range.");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Not a int!!!");
                            }
                        }
                    }while (!selectNewStore && string.IsNullOrEmpty(serial));
                }
            }

            Console.WriteLine("Expire: " + clientCert.GetExpirationDateString());

            return(clientCert);
        }
Exemplo n.º 4
0
 public OiosiRaspClient()
 {
     this.uddiType       = UddiType.Test;
     this.xmlDocumentUrl = this.PATH_INVOICE_XML;
 }