Results 1 to 8 of 8

Thread: Generating key and certificate for QSslSocket

  1. #1
    Join Date
    Mar 2011
    Location
    PL
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Generating key and certificate for QSslSocket

    I am writing simple network communicator which uses SSL, and I want to be sure how to create certificate and private key correctly. I use following command to create keys:
    Qt Code:
    1. openssl req -x509 -newkey rsa:2048 -keyout server.key -days 365 -out server.crt -nodes
    To copy to clipboard, switch view to plain text mode 
    And on the server I use
    server.crt as argument for addCaCertificate() and setLocalCertificate()
    server.key as argument for setPrivateKey()
    On the client I use
    server.crt as argument for addCaCertificate()
    server.crt is public and I share this for users
    I want to know if this, what I described is correct and secure
    Last edited by dawwin; 26th March 2011 at 21:40.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Generating key and certificate for QSslSocket

    In my opinion CA and the server should have different certificates. The server certificate should be signed with the CA certificate.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2011
    Location
    PL
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Generating key and certificate for QSslSocket

    Now I use following commands to generate keys
    Qt Code:
    1. ./CA.pl -newca
    2. ./CA.pl -newreq-nodes
    3. ./CA.pl -signreq
    To copy to clipboard, switch view to plain text mode 

    CA certificate is generated in demoCA/cacert.pem
    Private key is newkey.pem
    Signed certificate is newcert.pem

    On the server I use
    demoCA/cacert.pem as argument for addCaCertificate()
    newcert.pem as argument for setLocalCertificate()
    newkey.pem as argument for setPrivateKey()
    On the client I use
    demoCA/cacert.pem as argument for addCaCertificate()
    demoCA/cacert.pem is public

    How about now?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Generating key and certificate for QSslSocket

    I don't know what this perl script does so it is hard to say, but it looks better now.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2011
    Location
    PL
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Generating key and certificate for QSslSocket

    This script is available in /usr/lib/ssl/misc directory. It's part of the OpenSSL
    Qt Code:
    1. ./CA.pl -newca #creates new CA certificate
    2. ./CA.pl -newreq-nodes #creates a new certificate request
    3. ./CA.pl -signreq #calls the ca program to sign a certificate request
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Generating key and certificate for QSslSocket

    Quote Originally Posted by dawwin View Post
    This script is available in /usr/lib/ssl/misc directory. It's part of the OpenSSL
    Which doesn't mean I have to immediately run to /usr/lib/ssl/misc and analyze it, right? This is nothing related to Qt, you know.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2011
    Location
    PL
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Generating key and certificate for QSslSocket

    I explained commands, which I use to generate keys so You don't have to analyze this script. I don't even want you to do this. I just want to know if I use private key and certificates correctly
    Last edited by dawwin; 27th March 2011 at 13:39.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Generating key and certificate for QSslSocket

    Quote Originally Posted by dawwin View Post
    I explained commands, which I use to generate keys
    No. You listed calls to a perl script that calls *some* openssl commands that do something. Since without looking at CA.pl it is not possible to determine what commands they are it is not possible to say whether what you are doing is what you should do.

    I just want to know if I use private key and certificates correctly
    No idea, ask on an OpenSSL forum. The SSL handshake is done by OpenSSL and not Qt, this is really nothing related to Qt. Qt just passes the data you provide to the underlying SSL layer. I would say that if it works, it is fine. You don't have any security here anyway as you're using a self-signed certificate so this doesn't really matter, you just want the handshake to succeed. Only that you have a chance to deliver your CA certificate using some safe channel to your clients and if they install it as a trusted certificate and verify it when starting the connection it will be ok. But that's of course also nothing related to Qt...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QWebView + HTTPS with certificate example
    By kylls in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2011, 06:07
  2. Qt 4.7 SSL error : "The certificate has expired”
    By Joshy Abraham in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2011, 06:06
  3. Qt getting client certificates from OS certificate store.
    By sargsyan.taron in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 16:39
  4. Symbian - self-signed certificate
    By metRo_ in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 10th March 2010, 06:10
  5. Replies: 0
    Last Post: 9th March 2009, 03:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.