2012-11-19 12 views
7

एसएसएल मोनो पर सर्विस स्टैक पर समर्थित है?सर्विस स्टैक पर एसएसएल

मैं केवल करने के लिए एक मैक और निर्देशों का मैं यहां पाया एक PVK फ़ाइल बनाने के लिए एक खिड़कियों उपकरण का उपयोग करने के लिए कह उपयोग कर सकते है: http://joshua.perina.com/geo/post/using-ssl-https-with-mono-httplistener

साइट एक लिनक्स डेमॉन की प्रक्रिया के लिए एक नवोदय स्क्रिप्ट का उपयोग कर के रूप में की मेजबानी की है सर्वर को ऊपर रखो।

उत्तर

9

मैंने सर्विस ऐप के लिए एसएसएल समर्थन को सक्षम करने के लिए अपने ऐप होस्ट में कुछ कोड लिखना समाप्त कर दिया, जो कवर के तहत एचटीपी लिस्टनर का उपयोग करता है। यहां कुछ कोड है जो एक कंसोल अनुप्रयोग के लिए सर्विस स्टैक के लिए एसएसएल सक्षम करेगा:

public class AppHost : AppHostHttpListenerBase 
{ 
    public AppHost() : base("Service", typeof(AppHost).Assembly) 
    { 
    } 

    public override void Configure(Funq.Container container) 
    { 
     Plugins.Add(new RazorFormat()); 
    } 

    static void AddP12 (string filename, string password, ushort port) 
    { 
     string dirname = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); 
     string path = Path.Combine(dirname, ".mono"); 
     path = Path.Combine(path, "httplistener"); 
     if (!Directory.Exists(path)) 
     { 
      Console.WriteLine("Creating directory: " + path); 
      Directory.CreateDirectory(path); 
     } 
     X509Certificate2 x509 = null; 
     try { 
      x509 = new X509Certificate2 (filename, password); 
     } catch (Exception e) { 
      Console.Error.WriteLine ("error loading certificate [{0}]", e.Message); 
      return; 
     } 

     string target_cert = Path.Combine (path, String.Format ("{0}.cer", port)); 
     if (File.Exists(target_cert)) 
     { 
      Console.Error.WriteLine ("error: there is already a certificate for that port."); 
      return; 
     } 
     string target_pvk = Path.Combine (path, String.Format ("{0}.pvk", port)); 
     if (File.Exists(target_pvk)) { 
      Console.Error.WriteLine ("error: there is already a certificate for that port."); 
      return; 
     } 

     using (Stream cer = File.OpenWrite (target_cert)) 
     { 
      byte[] raw = x509.RawData; 
      cer.Write (raw, 0, raw.Length); 
     } 

     PrivateKey pvk = new PrivateKey(); 
     pvk.RSA = x509.PrivateKey as RSA; 
     pvk.Save(target_pvk);   
    } 

    public static void Main(string[] args) 
    { 
     string listeningOn = string.Empty; 
     if (args.Length == 1) 
      listeningOn = "http://*:" + args[0] + "/"; 
     else if (args.Length == 3) 
     { 
      listeningOn = "https://*:" + args[0] + "/"; 
      AddP12(args[1], args[2], Convert.ToUInt16(args[0])); 
     } 
     else 
     { 
      Console.WriteLine("Usage: [port] [p12 certificate] [p12 password]"); 
      return; 
     } 
     AppHost appHost = new AppHost(); 
     appHost.Init(); 
     appHost.Start(listeningOn); 
     Console.WriteLine("Service Stack Server started at {0}, listening on {1}", DateTime.Now, listeningOn); 
     while (true) System.Threading.Thread.Sleep(100); 
    } 
} 
+1

ऐसा लगता है कि यह सिर्फ एक स्थान से दूसरे स्थान पर एक प्रमाणपत्र कॉपी करता है। यह कैसे मदद करता है? ऑपरेटिंग सिस्टम में संभवतः प्रमाण पत्र विन्यास भी आवश्यक है? –