Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Replacing subjectDisplayName() by issuerInfo, keeping the same behavior



  • Hello,

    I am currently porting code that was done in Qt 5.12 to Qt 5.9. In code 5.12 I have a method in the QSslCertificate, which does not exist in 5.9. This is a method used to retrieve the name of an SSL certificate, subjectDisplayName().

    For the moment I have replaced the calls to subjectDisplayName() by subjectInfo(QSslCertificate :: CommonName).

    My problem is that subjectDisplayName return a string, which is logic, cause it's the name of the subject. But subjectinfo(QSslCertificate::CommonName) return a QStringList, what does this mean?
    Does this mean that the subject can have several common name? If so then why does subjectDisplayName () only return one name?

    Thank you for your help, have a good day :)



  • @Pantoufle said in Replacing subjectDisplayName() by issuerInfo, keeping the same behavior:

    I am currently porting code that was done in Qt 5.12 to Qt 5.9

    Why would one move backwards?

    My problem is that subjectDisplayName return a string, which is logic, cause it's the name of the subject. But subjectinfo(QSslCertificate::CommonName) return a QStringList, what does this mean?

    It means that you still can get the name by parsing the stringList (if available) :)



  • Why would one move backwards?

    Because the original project is in 5.9 and I'm not the main maintainer of this project, so, I'm just dealing with it ^^.

    It means that you still can get the name by parsing the stringList (if available) :)

    Parsing? I was guessing that if I user the argument "QSslCertificate::CommonName" it would return me only the name.

    For example :

    QString name = cert.subjectinfo(QSslCertificate::CommonName)[0]
    

    This line don't return me the name?

    Thanks for your help.



  • @Pantoufle said in Replacing subjectDisplayName() by issuerInfo, keeping the same behavior:

    This line don't return me the name?

    What do you get?

    There is a stringList because there can be more than one entry. Each entry is a new string in your stringList.

    Returns the information for the subject, or an empty list if there is no information for subject in the certificate. There can be more than one entry of each type.
    (https://doc.qt.io/qt-5/qsslcertificate.html#subjectInfo)



  • What do you get?

    I'm on an embedded device and i cant have acces to it easily, so i can't really test it for now. It would be too simple :p.

    There is a stringList because there can be more than one entry. Each entry is a new string in your stringList.

    If I pass QSslCertificate :: CommonName in argument of the method, does this return me a list of name, or all the info? By all info I mean, name, locality, country ...



  • @Pantoufle said in Replacing subjectDisplayName() by issuerInfo, keeping the same behavior:

    If I pass QSslCertificate :: CommonName in argument of the method, does this return me a list of name, or all the info? By all info I mean, name, locality, country ...

    Everything that is stored in "CN":

    QSslCertificate::CommonName ---- "CN" The common name; most often this is used to store the host name.

    Could be empty, could be more than 1 string. Depends on your certificate.

    Just try it when you can test it and see what you get.



  • Ok great, I'll keep you posted. Thanks for the help and have a nice day.


Log in to reply