From 57d9eb2b773705a21470de47464a60f6594fb49a Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Sat, 9 Aug 2014 23:49:43 +0300 Subject: [PATCH] SSL backend: Fix pem header/footer utility methods These methods assumed incoming data would have LF line endings, and therefore broke when parsing files with CRLF line endings. This simply removes the line feed from the header/footer strings, and switches to QByteArrayLiteral while doing so. Change-Id: I0c14634243c4bd7d19a6b5ef718b6ed1cc6bcdb2 Reviewed-by: Richard J. Moore --- src/network/ssl/qsslkey_p.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/network/ssl/qsslkey_p.cpp b/src/network/ssl/qsslkey_p.cpp index 991b29792e..37936fad10 100644 --- a/src/network/ssl/qsslkey_p.cpp +++ b/src/network/ssl/qsslkey_p.cpp @@ -106,12 +106,11 @@ QSslKey::QSslKey() */ QByteArray QSslKeyPrivate::pemHeader() const { - // ### use QByteArray::fromRawData() instead if (type == QSsl::PublicKey) - return QByteArray("-----BEGIN PUBLIC KEY-----\n"); + return QByteArrayLiteral("-----BEGIN PUBLIC KEY-----"); else if (algorithm == QSsl::Rsa) - return QByteArray("-----BEGIN RSA PRIVATE KEY-----\n"); - return QByteArray("-----BEGIN DSA PRIVATE KEY-----\n"); + return QByteArrayLiteral("-----BEGIN RSA PRIVATE KEY-----"); + return QByteArrayLiteral("-----BEGIN DSA PRIVATE KEY-----"); } /*! @@ -119,12 +118,11 @@ QByteArray QSslKeyPrivate::pemHeader() const */ QByteArray QSslKeyPrivate::pemFooter() const { - // ### use QByteArray::fromRawData() instead if (type == QSsl::PublicKey) - return QByteArray("-----END PUBLIC KEY-----\n"); + return QByteArrayLiteral("-----END PUBLIC KEY-----"); else if (algorithm == QSsl::Rsa) - return QByteArray("-----END RSA PRIVATE KEY-----\n"); - return QByteArray("-----END DSA PRIVATE KEY-----\n"); + return QByteArrayLiteral("-----END RSA PRIVATE KEY-----"); + return QByteArrayLiteral("-----END DSA PRIVATE KEY-----"); } /*! @@ -146,8 +144,8 @@ QByteArray QSslKeyPrivate::pemFromDer(const QByteArray &der) const if (rem) pem.append('\n'); // ### - pem.prepend(pemHeader()); - pem.append(pemFooter()); + pem.prepend(pemHeader() + '\n'); + pem.append(pemFooter() + '\n'); return pem; }