1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTRANSPORTAUTHDEFS_QWS_H
43 #define QTRANSPORTAUTHDEFS_QWS_H
44 
45 #include <sys/types.h>
46 #include <string.h>
47 
48 #include <QtCore/qglobal.h>
49 
50 QT_BEGIN_HEADER
51 
52 QT_BEGIN_NAMESPACE
53 
54 QT_MODULE(Gui)
55 
56 #define QSXE_KEY_LEN 16
57 #define QSXE_MAGIC_BYTES 4
58 
59 // Number of bytes of each message to authenticate.  Just need to ensure
60 // that the command at the beginning hasn't been tampered with.  This value
61 // does not matter for trusted transports.
62 #define AMOUNT_TO_AUTHENTICATE 200
63 
64 #define AUTH_ID(k) ((unsigned char)(k[QSXE_KEY_LEN]))
65 #define AUTH_KEY(k) ((unsigned char *)(k))
66 
67 // must be a largish -ve number under any endianess when cast as an int
68 const unsigned char magic[QSXE_MAGIC_BYTES] = { 0xBA, 0xD4, 0xD4, 0xBA };
69 const int magicInt = 0xBAD4D4BA;
70 
71 #define QSXE_KEYFILE "keyfile"
72 
73 /*
74   Header in above format, less the magic bytes.
75   Useful for reading off the socket
76 */
77 struct AuthHeader
78 {
79     unsigned char len;
80     unsigned char pad;
81     unsigned char digest[QSXE_KEY_LEN];
82     unsigned char id;
83     unsigned char seq;
84 };
85 
86 /*
87   Header in a form suitable for authentication routines
88 */
89 struct AuthMessage
90 {
AuthMessageAuthMessage91     AuthMessage()
92     {
93         ::memset( authData, 0, sizeof(authData) );
94         ::memcpy( pad_magic, magic, QSXE_MAGIC_BYTES );
95     }
96     unsigned char pad_magic[QSXE_MAGIC_BYTES];
97     union {
98         AuthHeader hdr;
99         char authData[sizeof(AuthHeader)];
100     };
101     char payLoad[AMOUNT_TO_AUTHENTICATE];
102 };
103 
104 /**
105   Auth data as stored in _key
106 */
107 struct AuthCookie
108 {
109     unsigned char key[QSXE_KEY_LEN];
110     unsigned char pad;
111     unsigned char progId;
112 };
113 
114 /*
115   Auth data as written to the key file - SUPERSEDED by usr_key_entry
116 
117   This is still used internally for some functions, ie the socket
118   related calls.
119 */
120 struct AuthRecord
121 {
122     union {
123         AuthCookie auth;
124         char data[sizeof(struct AuthCookie)];
125     };
126     time_t change_time;
127 };
128 
129 /*!
130   \class usr_key_entry
131   This comes from the SXE kernel patch file include/linux/lidsif.h
132 
133   This is the (new) data record for the key file (version 2).
134 
135   The key file is (now) either /proc/lids/keys (and the per-process
136   keys in /proc/<pid>/lids_key) OR for desktop/development ONLY (not
137   for production) it is $QPEDIR/etc/keyfile
138 
139   The key file maps keys to files.
140 
141   File are identified by inode and device numbers, not paths.
142 
143   (See the "installs" file for path to inode/device mapping)
144 */
145 struct usr_key_entry
146 {
147     char key[QSXE_KEY_LEN];
148     ino_t ino;
149     dev_t dev;
150 };
151 
152 
153 /*!
154   \class IdBlock
155   \brief Data record for the manifest file.
156   The manifest file maps program id's to files
157 */
158 struct IdBlock
159 {
160     quint64 inode;
161     quint64 device;
162     unsigned char pad;
163     unsigned char progId;
164     unsigned short installId;
165     unsigned int keyOffset;
166     qint64 install_time;
167 };
168 
169 QT_END_NAMESPACE
170 
171 QT_END_HEADER
172 
173 #endif // QTRANSPORTAUTHDEFS_QWS_H
174 
175