none
[UWP][C#]How to create a TLS secured UWP IP based networking server app

    Question

  • hello

    based on a project requirement i have to create a TLS secured c# UWP app which acts as a server

    to reach that goal i tried to use a only method i was able to find

    Windows.Networking.Sockets.StreamSocketListener.BindServiceNameAsync(string, Windows.Networking.Sockets.SocketProtectionLevel)

    but surprisingly this raise an exception (Only plain sockets are allowed for IP StreamSocketListeners) ?! serious?

    after some investigation i wonder why i cant find a solution for such an "easy" (at least for classic desktop apps...) task?

    every sample i found shows only the client side but not the server side

    for example the "How to secure socket connections with TLS/SSL (XAML)" guide

    so how is it possible to create a TLS secured IP based server app with UWP ?

    br
    Andre


    Wednesday, January 18, 2017 1:24 PM

Answers

All replies

  • Hello cyberh0me,

    I have test the code of the StreamSocket by setting the following code.

    In the sample, we set a listener,

    StreamSocketListener listener = new StreamSocketListener(); listener.ConnectionReceived += OnConnection;

    CoreApplication.Properties.Add("listener", listener);

    await listener.BindServiceNameAsync(ServiceNameForListener.Text,SocketProtectionLevel.Tls10);

    But there is no an exception, Could you give us more code in your test to reproduce the issue?

    More details, you can refer to the StreamSocket sample.

    Best regards,
    Breeze Liu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 19, 2017 10:05 AM
    Moderator
  • hello
    Add new Project Blank App (Universal Windows)
    Target Version 14393, Minimum Version 10586
    edit App.xaml.cs
    using Windows.Networking.Sockets;
    ..........
        sealed partial class App : Application
        {
            private StreamSocketListener Listener;
    ..........
            protected async override void OnLaunched(LaunchActivatedEventArgs e)
            {
    #if DEBUG
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    this.DebugSettings.EnableFrameRateCounter = true;
                }
    #endif
                Listener = new StreamSocketListener();
                Listener.ConnectionReceived += ConnectionReceived;
                await Listener.BindServiceNameAsync("21", SocketProtectionLevel.Tls10);
                Frame rootFrame = Window.Current.Content as Frame;
    ..........
            private void ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
            {
            }

    add "Private Networks (Client & Server)" in Package.appxmanifest
    start the Appp
    exception at line await Listener.BindServiceNameAsync
    Exception thrown: 'System.ArgumentException' in App1.exe
    WinRT information: 'protectionLevel': Only plain sockets are allowed for IP StreamSocketListeners.
    An exception of type 'System.ArgumentException' occurred in App1.exe but was not handled in user code
    WinRT information: 'protectionLevel': Only plain sockets are allowed for IP StreamSocketListeners.
    Additional information: The parameter is incorrect.

    • Edited by cyberh0me Thursday, January 19, 2017 1:13 PM
    Thursday, January 19, 2017 1:12 PM
  • hello

    you can download the changed files App.xaml.cs and Package.appxmanifest here

    https://1drv.ms/f/s!AmeIIBQl_WQUmsFjWnq7s7YDItxZsQ

    so simply

    Add new Project Blank App (Universal Windows)
    Target Version 14393, Minimum Version 10586

    and replace both files

    br
    Andre

    Thursday, January 19, 2017 1:18 PM
  • Hello cyberh0me,

    I am trying to do some research now. May be some time delay, Appreciate your patience.

    Best regards,
    Breeze Liu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 20, 2017 11:52 AM
    Moderator
  • ????
    Thursday, February 02, 2017 1:53 PM
  • common guys i need a solution !!!
    Wednesday, February 08, 2017 5:09 PM
  • Hello cyberh0me,

    >>so how is it possible to create a TLS secured IP based server app with UWP ?

    It is impossible. Base on the How to secure socket connections with TLS/SSL (XAML), you can find the following words,

    The StreamSocket object can be configured to use SSL/TLS for communications between the client and the server. This support for SSL/TLS is limited to using the StreamSocket object as the client in the SSL/TLS negotiation. SSL/TLS cannot currently be used by the StreamSocketListener with the StreamSocket created when a connection is received to enable SSL/TLS on the StreamSocket created, since the SSL/TLS negotiation as a server is not implemented for a StreamSocket. The client support for SSL/TLS does not include the ability to use client certificates.

    Best regards,
    Breeze Liu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 09, 2017 10:48 AM
    Moderator
  • i think this is one of the grey areas from UWP for every device

    another simple project not achievable with Windows IoT Core

    whats the way for feature request?
    • Edited by cyberh0me Thursday, February 09, 2017 11:30 AM
    Thursday, February 09, 2017 11:24 AM
  • Hi cyberh0me,

    You can submit this feature request to the UserVoice website:
    https://wpdev.uservoice.com/forums/110705-universal-windows-platform.

    Best regards,
    Breeze Liu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by cyberh0me Friday, February 10, 2017 10:45 AM
    • Unmarked as answer by cyberh0me Monday, March 20, 2017 10:42 PM
    Friday, February 10, 2017 4:19 AM
    Moderator
  • thank you

    added 2 years ago... SSL/TLS support for StreamSocketListener

    so i have to abandon Windows IoT Core

    you can mark whatever you like as answer

    Friday, February 10, 2017 10:21 AM
  • Hello cyberh0me,

    As the new policy, we can't mark the answer anymore by ourselves. If you think the answer is helpful or has resolved your issue, you can mark the answer. We encourage the poster to mark an answer, it will be beneficial to other community members searching and reading this thread for their similar issue.

    Best regards,
    Breeze Liu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 10, 2017 10:38 AM
    Moderator
  • it does not make sense to waste more time with uwp and windows iot core
    • Marked as answer by cyberh0me Monday, March 20, 2017 10:42 PM
    Monday, March 20, 2017 10:42 PM