source: trunk/src/gui/embedded/qtransportauth_qws_p.h@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QTRANSPORTAUTH_QWS_P_H
43#define QTRANSPORTAUTH_QWS_P_H
44
45//
46// W A R N I N G
47// -------------
48//
49// This file is not part of the Qt API. It exists purely as an
50// implementation detail. This header file may change from version to
51// version without notice, or even be removed.
52//
53// We mean it.
54//
55
56#include <QtCore/qglobal.h>
57
58#ifndef QT_NO_SXE
59
60#include "qtransportauth_qws.h"
61#include "qtransportauthdefs_qws.h"
62#include "qbuffer.h"
63
64#include <qmutex.h>
65#include <qdatetime.h>
66#include "private/qobject_p.h"
67
68#include <QtCore/qcache.h>
69
70QT_BEGIN_NAMESPACE
71
72// Uncomment to generate debug output
73// #define QTRANSPORTAUTH_DEBUG 1
74
75#ifdef QTRANSPORTAUTH_DEBUG
76void hexstring( char *buf, const unsigned char* key, size_t sz );
77#endif
78
79// proj id for ftok usage in sxe
80#define SXE_PROJ 10022
81
82/*!
83 \internal
84 memset for security purposes, guaranteed not to be optimized away
85 http://www.faqs.org/docs/Linux-HOWTO/Secure-Programs-HOWTO.html
86*/
87void *guaranteed_memset(void *v,int c,size_t n);
88
89class QUnixSocketMessage;
90
91/*!
92 \internal
93 \class AuthCookie
94 Struct to carry process authentication key and id
95*/
96#define QSXE_HEADER_LEN 24
97
98/*!
99 \macro AUTH_ID
100 Macro to manage authentication header. Format of header is:
101 \table
102 \header \i BYTES \i CONTENT
103 \row \i 0-3 \i magic numbers
104 \row \i 4 \i length of authenticated data (max 255 bytes)
105 \row i\ 5 \i reserved
106 \row \i 6-21 \i MAC digest, or shared secret in case of simple auth
107 \row \i 22 \i program id
108 \row \i 23 \i sequence number
109 \endtable
110 Total length of the header is 24 bytes
111
112 However this may change. Instead of coding these numbers use the AUTH_ID,
113 AUTH_KEY, AUTH_DATA and AUTH_SPACE macros.
114*/
115
116#define AUTH_ID(k) ((unsigned char)(k[QSXE_KEY_LEN]))
117#define AUTH_KEY(k) ((unsigned char *)(k))
118
119#define AUTH_DATA(x) (unsigned char *)((x) + QSXE_HEADER_LEN)
120#define AUTH_SPACE(x) ((x) + QSXE_HEADER_LEN)
121#define QSXE_LEN_IDX 4
122#define QSXE_KEY_IDX 6
123#define QSXE_PROG_IDX 22
124#define QSXE_SEQ_IDX 23
125
126class SxeRegistryLocker : public QObject
127{
128 Q_OBJECT
129public:
130 SxeRegistryLocker( QObject * );
131 ~SxeRegistryLocker();
132 bool success() const { return m_success; }
133private:
134 bool m_success;
135 QObject *m_reg;
136};
137
138class QTransportAuthPrivate : public QObjectPrivate
139{
140 Q_DECLARE_PUBLIC(QTransportAuth)
141public:
142 QTransportAuthPrivate();
143 ~QTransportAuthPrivate();
144
145 const unsigned char *getClientKey( unsigned char progId );
146 void invalidateClientKeyCache();
147
148 bool keyInitialised;
149 QString m_logFilePath;
150 QString m_keyFilePath;
151 QObject *m_packageRegistry;
152 AuthCookie authKey;
153 QCache<unsigned char, char> keyCache;
154 QHash< QObject*, QIODevice*> buffersByClient;
155 QMutex keyfileMutex;
156};
157
158/*!
159 \internal
160 Enforces the False Authentication Rate. If more than 4 authentications
161 are received per minute the sxemonitor is notified that the FAR has been exceeded
162*/
163class FAREnforcer
164{
165 public:
166 static FAREnforcer *getInstance();
167 void logAuthAttempt( QDateTime time = QDateTime::currentDateTime() );
168 void reset();
169
170#ifndef TEST_FAR_ENFORCER
171 private:
172#endif
173 FAREnforcer();
174 FAREnforcer( const FAREnforcer & );
175 FAREnforcer &operator=(FAREnforcer const & );
176
177 static const QString FARMessage;
178 static const int minutelyRate;
179 static const QString SxeTag;
180 static const int minute;
181
182 QList<QDateTime> authAttempts;
183};
184
185QT_END_NAMESPACE
186
187#endif // QT_NO_SXE
188#endif // QTRANSPORTAUTH_QWS_P_H
189
Note: See TracBrowser for help on using the repository browser.