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