Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/09 17:44:58 (16 years ago)
Author:
mbecirov
Message:

#528: WCF Service secured - you need to install the certificate in order to run the application properly!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Contracts/3.2/WcfSettings.cs

    r1530 r1579  
    1 using System;
     1#define USE_MSG_BINDING
     2using System;
    23using System.Collections.Generic;
    34using System.Linq;
     
    1112  public static class WcfSettings {
    1213
     14    public const string SERVERCERT = "HIVE-Server";
     15    public const int DEFAULTPORT = 9000;
     16   
     17    /// <summary>
     18    /// Gets a pre-defined binding using TCP for secure transport.
     19    /// </summary>
     20    /// <returns>A binding type of <see cref="NetTcpBinding"/></returns>
    1321    public static Binding GetBinding() {
     22#if USE_MSG_BINDING
    1423      NetTcpBinding binding = new NetTcpBinding(SecurityMode.Message);
     24#else
     25      NetTcpBinding binding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential);
     26      binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
     27#endif
    1528      return binding;
    1629    }
    1730
     31    /// <summary>
     32    /// Defines the used certificate for authentification located in a certification store.
     33    /// </summary>
     34    /// <param name="svchost">A service for which this certificate is applicable.</param>
     35    public static void SetServiceCertificate(ServiceHost svchost) {
     36      svchost.Credentials.ServiceCertificate.SetCertificate(
     37        StoreLocation.LocalMachine,
     38        StoreName.My,
     39        X509FindType.FindBySubjectName,
     40        SERVERCERT);
     41    }
     42
     43    /// <summary>
     44    /// Gets the currently active IP address.
     45    /// <remarks>If more than one IP connections is active, the first one will be used.</remarks>
     46    /// </summary>
     47    /// <returns></returns>
    1848    public static string GetActiveIP() {
    1949      return System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections()[0].LocalEndPoint.Address.ToString();
    2050    }
    2151
     52    /// <summary>
     53    /// Gets the default port used for HIVE services.
     54    /// </summary>
     55    /// <returns></returns>
    2256    public static int GetDefaultPort() {
    23       return 9000;
     57      return DEFAULTPORT;
    2458    }
    2559  }
    2660
    27   // WARNUNG: Dieser Code wird nur für Testzertifikate benötigt, wie sie beispielsweise von makecert erstellt werden.
    28   // Sie sollten diesen Code nicht in einer Produktionsumgebung verwenden.
     61  /// <summary>
     62  /// This class verifies the certificate defined by <see cref="SetServerCertificate"></see> method. Normally,
     63  /// the verification process is managed by the underlying operating system.
     64  /// </summary>
     65  /// <remarks>
     66  /// WARNUNG: Dieser Code wird nur für Testzertifikate benötigt, wie sie beispielsweise von makecert erstellt werden.
     67  /// Sie sollten diesen Code nicht in einer Produktionsumgebung verwenden.
     68  /// </remarks>
    2969  public class PermissiveCertificatePolicy {
    3070    string subjectName;
     
    4484        return true;
    4585      }
    46 
    4786      return false;
    4887    }
Note: See TracChangeset for help on using the changeset viewer.