| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #include "qx509_base_p.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | namespace QTlsPrivate { |
| 10 | |
| 11 | QByteArray X509CertificateBase::subjectInfoToString(QSslCertificate::SubjectInfo info) |
| 12 | { |
| 13 | QByteArray str; |
| 14 | switch (info) { |
| 15 | case QSslCertificate::Organization: str = QByteArray("O"); break; |
| 16 | case QSslCertificate::CommonName: str = QByteArray("CN"); break; |
| 17 | case QSslCertificate::LocalityName: str = QByteArray("L"); break; |
| 18 | case QSslCertificate::OrganizationalUnitName: str = QByteArray("OU"); break; |
| 19 | case QSslCertificate::CountryName: str = QByteArray("C"); break; |
| 20 | case QSslCertificate::StateOrProvinceName: str = QByteArray("ST"); break; |
| 21 | case QSslCertificate::DistinguishedNameQualifier: str = QByteArray("dnQualifier"); break; |
| 22 | case QSslCertificate::SerialNumber: str = QByteArray("serialNumber"); break; |
| 23 | case QSslCertificate::EmailAddress: str = QByteArray("emailAddress"); break; |
| 24 | } |
| 25 | |
| 26 | return str; |
| 27 | } |
| 28 | |
| 29 | bool X509CertificateBase::matchLineFeed(const QByteArray &pem, int *offset) |
| 30 | { |
| 31 | Q_ASSERT(offset); |
| 32 | |
| 33 | char ch = 0; |
| 34 | // ignore extra whitespace at the end of the line |
| 35 | while (*offset < pem.size() && (ch = pem.at(i: *offset)) == ' ') |
| 36 | ++*offset; |
| 37 | |
| 38 | if (ch == '\n') { |
| 39 | *offset += 1; |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | if (ch == '\r' && pem.size() > (*offset + 1) && pem.at(i: *offset + 1) == '\n') { |
| 44 | *offset += 2; |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | bool X509CertificateBase::isNull() const |
| 52 | { |
| 53 | return null; |
| 54 | } |
| 55 | |
| 56 | QByteArray X509CertificateBase::version() const |
| 57 | { |
| 58 | return versionString; |
| 59 | } |
| 60 | |
| 61 | QByteArray X509CertificateBase::serialNumber() const |
| 62 | { |
| 63 | return serialNumberString; |
| 64 | } |
| 65 | |
| 66 | QStringList X509CertificateBase::issuerInfo(QSslCertificate::SubjectInfo info) const |
| 67 | { |
| 68 | return issuerInfo(attribute: subjectInfoToString(info)); |
| 69 | } |
| 70 | |
| 71 | QStringList X509CertificateBase::issuerInfo(const QByteArray &attribute) const |
| 72 | { |
| 73 | return issuerInfoEntries.values(key: attribute); |
| 74 | } |
| 75 | |
| 76 | QStringList X509CertificateBase::subjectInfo(QSslCertificate::SubjectInfo info) const |
| 77 | { |
| 78 | return subjectInfo(attribute: subjectInfoToString(info)); |
| 79 | } |
| 80 | |
| 81 | QStringList X509CertificateBase::subjectInfo(const QByteArray &attribute) const |
| 82 | { |
| 83 | return subjectInfoEntries.values(key: attribute); |
| 84 | } |
| 85 | |
| 86 | QList<QByteArray> X509CertificateBase::subjectInfoAttributes() const |
| 87 | { |
| 88 | return subjectInfoEntries.uniqueKeys(); |
| 89 | } |
| 90 | |
| 91 | QList<QByteArray> X509CertificateBase::issuerInfoAttributes() const |
| 92 | { |
| 93 | return issuerInfoEntries.uniqueKeys(); |
| 94 | } |
| 95 | |
| 96 | QDateTime X509CertificateBase::effectiveDate() const |
| 97 | { |
| 98 | return notValidBefore; |
| 99 | } |
| 100 | |
| 101 | QDateTime X509CertificateBase::expiryDate() const |
| 102 | { |
| 103 | return notValidAfter; |
| 104 | } |
| 105 | |
| 106 | qsizetype X509CertificateBase::numberOfExtensions() const |
| 107 | { |
| 108 | return extensions.size(); |
| 109 | } |
| 110 | |
| 111 | QString X509CertificateBase::oidForExtension(qsizetype index) const |
| 112 | { |
| 113 | Q_ASSERT(validIndex(index)); |
| 114 | return extensions[index].oid; |
| 115 | } |
| 116 | |
| 117 | QString X509CertificateBase::nameForExtension(qsizetype index) const |
| 118 | { |
| 119 | Q_ASSERT(validIndex(index)); |
| 120 | return extensions[index].name; |
| 121 | } |
| 122 | |
| 123 | QVariant X509CertificateBase::valueForExtension(qsizetype index) const |
| 124 | { |
| 125 | Q_ASSERT(validIndex(index)); |
| 126 | return extensions[index].value; |
| 127 | } |
| 128 | |
| 129 | bool X509CertificateBase::isExtensionCritical(qsizetype index) const |
| 130 | { |
| 131 | Q_ASSERT(validIndex(index)); |
| 132 | return extensions[index].critical; |
| 133 | } |
| 134 | |
| 135 | bool X509CertificateBase::isExtensionSupported(qsizetype index) const |
| 136 | { |
| 137 | Q_ASSERT(validIndex(index)); |
| 138 | return extensions[index].supported; |
| 139 | } |
| 140 | |
| 141 | } // namespace QTlsPrivate |
| 142 | |
| 143 | QT_END_NAMESPACE |
| 144 |
