Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslellipticcurve_openssl.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2014 Governikus GmbH & Co. KG. | - | ||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
9 | ** Commercial License Usage | - | ||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
16 | ** | - | ||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
25 | ** | - | ||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
29 | ** | - | ||||||
30 | ** $QT_END_LICENSE$ | - | ||||||
31 | ** | - | ||||||
32 | ****************************************************************************/ | - | ||||||
33 | - | |||||||
34 | #include "qsslellipticcurve.h" | - | ||||||
35 | #include "qsslsocket_p.h" | - | ||||||
36 | #include "qsslsocket_openssl_symbols_p.h" | - | ||||||
37 | - | |||||||
38 | #include <openssl/ssl.h> | - | ||||||
39 | #include <openssl/obj_mac.h> | - | ||||||
40 | - | |||||||
41 | #include <algorithm> | - | ||||||
42 | - | |||||||
43 | QT_BEGIN_NAMESPACE | - | ||||||
44 | - | |||||||
45 | QString QSslEllipticCurve::shortName() const | - | ||||||
46 | { | - | ||||||
47 | QString result; | - | ||||||
48 | #ifndef OPENSSL_NO_EC | - | ||||||
49 | if (id != 0)
| 10-268 | ||||||
50 | result = QString::fromLatin1(q_OBJ_nid2sn(id)); executed 268 times by 1 test: result = QString::fromLatin1(q_OBJ_nid2sn(id)); Executed by:
| 268 | ||||||
51 | #endif | - | ||||||
52 | return result; executed 278 times by 1 test: return result; Executed by:
| 278 | ||||||
53 | } | - | ||||||
54 | - | |||||||
55 | QString QSslEllipticCurve::longName() const | - | ||||||
56 | { | - | ||||||
57 | QString result; | - | ||||||
58 | #ifndef OPENSSL_NO_EC | - | ||||||
59 | if (id != 0)
| 10-268 | ||||||
60 | result = QString::fromLatin1(q_OBJ_nid2ln(id)); executed 268 times by 1 test: result = QString::fromLatin1(q_OBJ_nid2ln(id)); Executed by:
| 268 | ||||||
61 | #endif | - | ||||||
62 | return result; executed 278 times by 1 test: return result; Executed by:
| 278 | ||||||
63 | } | - | ||||||
64 | - | |||||||
65 | QSslEllipticCurve QSslEllipticCurve::fromShortName(const QString &name) | - | ||||||
66 | { | - | ||||||
67 | if (name.isEmpty())
| 2-68 | ||||||
68 | return QSslEllipticCurve(); executed 2 times by 1 test: return QSslEllipticCurve(); Executed by:
| 2 | ||||||
69 | - | |||||||
70 | QSslSocketPrivate::ensureInitialized(); | - | ||||||
71 | - | |||||||
72 | QSslEllipticCurve result; | - | ||||||
73 | - | |||||||
74 | #ifndef OPENSSL_NO_EC | - | ||||||
75 | const QByteArray curveNameLatin1 = name.toLatin1(); | - | ||||||
76 | - | |||||||
77 | int nid = q_OBJ_sn2nid(curveNameLatin1.data()); | - | ||||||
78 | - | |||||||
79 | #if OPENSSL_VERSION_NUMBER >= 0x10002000L | - | ||||||
80 | if (nid == 0 && q_SSLeay() >= 0x10002000L) | - | ||||||
81 | nid = q_EC_curve_nist2nid(curveNameLatin1.data()); | - | ||||||
82 | #endif // OPENSSL_VERSION_NUMBER >= 0x10002000L | - | ||||||
83 | - | |||||||
84 | result.id = nid; | - | ||||||
85 | #endif | - | ||||||
86 | - | |||||||
87 | return result; executed 68 times by 1 test: return result; Executed by:
| 68 | ||||||
88 | } | - | ||||||
89 | - | |||||||
90 | QSslEllipticCurve QSslEllipticCurve::fromLongName(const QString &name) | - | ||||||
91 | { | - | ||||||
92 | if (name.isEmpty())
| 2-68 | ||||||
93 | return QSslEllipticCurve(); executed 2 times by 1 test: return QSslEllipticCurve(); Executed by:
| 2 | ||||||
94 | - | |||||||
95 | QSslSocketPrivate::ensureInitialized(); | - | ||||||
96 | - | |||||||
97 | QSslEllipticCurve result; | - | ||||||
98 | - | |||||||
99 | #ifndef OPENSSL_NO_EC | - | ||||||
100 | const QByteArray curveNameLatin1 = name.toLatin1(); | - | ||||||
101 | - | |||||||
102 | int nid = q_OBJ_ln2nid(curveNameLatin1.data()); | - | ||||||
103 | result.id = nid; | - | ||||||
104 | #endif | - | ||||||
105 | - | |||||||
106 | return result; executed 68 times by 1 test: return result; Executed by:
| 68 | ||||||
107 | } | - | ||||||
108 | - | |||||||
109 | - | |||||||
110 | // The brainpool curve NIDs (RFC 7027) have been introduced in OpenSSL 1.0.2, | - | ||||||
111 | // redefine them here to make Qt compile with previous versions of OpenSSL | - | ||||||
112 | // (yet correctly recognize them as TLS named curves). | - | ||||||
113 | // See crypto/objects/obj_mac.h | - | ||||||
114 | #ifndef NID_brainpoolP256r1 | - | ||||||
115 | #define NID_brainpoolP256r1 927 | - | ||||||
116 | #endif | - | ||||||
117 | - | |||||||
118 | #ifndef NID_brainpoolP384r1 | - | ||||||
119 | #define NID_brainpoolP384r1 931 | - | ||||||
120 | #endif | - | ||||||
121 | - | |||||||
122 | #ifndef NID_brainpoolP512r1 | - | ||||||
123 | #define NID_brainpoolP512r1 933 | - | ||||||
124 | #endif | - | ||||||
125 | - | |||||||
126 | // NIDs of named curves allowed in TLS as per RFCs 4492 and 7027, | - | ||||||
127 | // see also https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8 | - | ||||||
128 | static const int tlsNamedCurveNIDs[] = { | - | ||||||
129 | // RFC 4492 | - | ||||||
130 | NID_sect163k1, | - | ||||||
131 | NID_sect163r1, | - | ||||||
132 | NID_sect163r2, | - | ||||||
133 | NID_sect193r1, | - | ||||||
134 | NID_sect193r2, | - | ||||||
135 | NID_sect233k1, | - | ||||||
136 | NID_sect233r1, | - | ||||||
137 | NID_sect239k1, | - | ||||||
138 | NID_sect283k1, | - | ||||||
139 | NID_sect283r1, | - | ||||||
140 | NID_sect409k1, | - | ||||||
141 | NID_sect409r1, | - | ||||||
142 | NID_sect571k1, | - | ||||||
143 | NID_sect571r1, | - | ||||||
144 | - | |||||||
145 | NID_secp160k1, | - | ||||||
146 | NID_secp160r1, | - | ||||||
147 | NID_secp160r2, | - | ||||||
148 | NID_secp192k1, | - | ||||||
149 | NID_X9_62_prime192v1, // secp192r1 | - | ||||||
150 | NID_secp224k1, | - | ||||||
151 | NID_secp224r1, | - | ||||||
152 | NID_secp256k1, | - | ||||||
153 | NID_X9_62_prime256v1, // secp256r1 | - | ||||||
154 | NID_secp384r1, | - | ||||||
155 | NID_secp521r1, | - | ||||||
156 | - | |||||||
157 | // RFC 7027 | - | ||||||
158 | NID_brainpoolP256r1, | - | ||||||
159 | NID_brainpoolP384r1, | - | ||||||
160 | NID_brainpoolP512r1 | - | ||||||
161 | }; | - | ||||||
162 | - | |||||||
163 | static const size_t tlsNamedCurveNIDCount = sizeof(tlsNamedCurveNIDs) / sizeof(tlsNamedCurveNIDs[0]); | - | ||||||
164 | - | |||||||
165 | bool QSslEllipticCurve::isTlsNamedCurve() const Q_DECL_NOTHROW | - | ||||||
166 | { | - | ||||||
167 | const int * const tlsNamedCurveNIDsEnd = tlsNamedCurveNIDs + tlsNamedCurveNIDCount; | - | ||||||
168 | return std::find(tlsNamedCurveNIDs, tlsNamedCurveNIDsEnd, id) != tlsNamedCurveNIDsEnd; executed 1 time by 1 test: return std::find(tlsNamedCurveNIDs, tlsNamedCurveNIDsEnd, id) != tlsNamedCurveNIDsEnd; Executed by:
| 1 | ||||||
169 | } | - | ||||||
170 | - | |||||||
171 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |