public void Get() { Debug.Enter(); SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor(); sp.ProcedureName = "net_operator_get"; sp.Parameters.Add("@operatorKey", SqlDbType.UniqueIdentifier); sp.Parameters.SetGuidFromString("@operatorKey", OperatorNodeID); SqlDataReaderAccessor reader = sp.ExecuteReader(); try { if (reader.Read()) { OperatorStatus = (OperatorStatus)reader.GetShort("operatorStatusID"); Name = reader.GetString("name"); SoapReplicationURL = reader.GetString("soapReplicationURL"); CertIssuerName = reader.GetString("certIssuer"); CertSubjectName = reader.GetString("certSubject"); Certificate = reader.GetBinary("certificate"); } } finally { reader.Close(); } Debug.Leave(); }
private void CheckCertificate(SoapMessage message) { HttpClientCertificate httpCert = HttpContext.Current.Request.ClientCertificate; X509Certificate requestCert = new X509Certificate(httpCert.Certificate); Debug.Verify(!Utility.StringEmpty(httpCert.Issuer), "UDDI_ERROR_FATALERROR_CLIENTCERTREQUIRED"); Debug.Verify(!Utility.StringEmpty(httpCert.Subject), "UDDI_ERROR_FATALERROR_CLIENTCERTREQUIRED"); SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor("net_operatorCert_get"); sp.Parameters.Add("@certSerialNo", SqlDbType.NVarChar, UDDI.Constants.Lengths.CertSerialNo); sp.Parameters.SetString("@certSerialNo", requestCert.GetSerialNumberString()); SqlDataReaderAccessor reader = sp.ExecuteReader(); try { if (reader.Read()) { Context.RemoteOperator = reader.GetGuidString("operatorKey"); byte[] operatorCertRaw = reader.GetBinary("certificate"); byte[] requestCertRaw = httpCert.Certificate; Debug.Verify( null != operatorCertRaw, "UDDI_ERROR_FATALERROR_CLIENTCERTNOTSTORED", ErrorType.E_fatalError, Context.RemoteOperator); if (operatorCertRaw.Length != requestCertRaw.Length) { throw new UDDIException( ErrorType.E_unknownUser, "UDDI_ERROR_UNKNOWNUSER_UNKOWNCERT"); } for (int i = 0; i < operatorCertRaw.Length; i++) { if (operatorCertRaw[i] != requestCertRaw[i]) { throw new UDDIException( ErrorType.E_unknownUser, "UDDI_ERROR_UNKNOWNUSER_UNKOWNCERT"); } } /* * TODO: Check to see if this works instead * * * X509Certificate operatorCert = new X509Certificate( operatorCertRaw ); * X509Certificate requestCert = new X509Certificate( requestCertRaw ); * * if( !requestCert.Equals( operatorCert ) ) * { * throw new UDDIException( * ErrorType.E_unknownUser, * "Unknown certificate" ); * } */ } else { throw new UDDIException( ErrorType.E_unknownUser, "UDDI_ERROR_UNKNOWNUSER_UNKOWNCERT"); } } finally { reader.Close(); } }
public static void ExportOperatorCertificate() { if (null == operatorKey) { operatorKey = Config.GetString("OperatorKey"); } if (File.Exists(filename) && !overwrite) { Console.Write("Overwrite '{0}' [y/n]? ", filename); int choice = Console.Read(); if ('y' != (char)choice && 'Y' != (char)choice) { Console.WriteLine(); Console.WriteLine("Operation aborted."); return; } } byte[] data = null; // // Retrieve the certificate. // SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor(); sp.ProcedureName = "net_operator_get"; sp.Parameters.Add("@operatorKey", SqlDbType.UniqueIdentifier); sp.Parameters.SetGuidFromString("@operatorKey", operatorKey); SqlDataReaderAccessor reader = sp.ExecuteReader(); try { if (reader.Read()) { data = reader.GetBinary("certificate"); } } finally { reader.Close(); } FileStream file = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.None); try { int filesize = (int)data.Length; file.Write(data, 0, filesize); Console.WriteLine("Wrote {0} byte(s) to certificate file '{1}'.\r\nSource: {{{2}}}", filesize, filename, operatorKey); } finally { file.Close(); } }