qtransportauthdefs_qws.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QTRANSPORTAUTHDEFS_QWS_H
00043 #define QTRANSPORTAUTHDEFS_QWS_H
00044 
00045 #include <sys/types.h>
00046 #include <string.h>
00047 
00048 #include <QtCore/qglobal.h>
00049 
00050 QT_BEGIN_HEADER
00051 
00052 QT_BEGIN_NAMESPACE
00053 
00054 QT_MODULE(Gui)
00055 
00056 #define QSXE_KEY_LEN 16
00057 #define QSXE_MAGIC_BYTES 4
00058 
00059 // Number of bytes of each message to authenticate.  Just need to ensure
00060 // that the command at the beginning hasn't been tampered with.  This value
00061 // does not matter for trusted transports.
00062 #define AMOUNT_TO_AUTHENTICATE 200
00063 
00064 #define AUTH_ID(k) ((unsigned char)(k[QSXE_KEY_LEN]))
00065 #define AUTH_KEY(k) ((unsigned char *)(k))
00066 
00067 // must be a largish -ve number under any endianess when cast as an int
00068 const unsigned char magic[QSXE_MAGIC_BYTES] = { 0xBA, 0xD4, 0xD4, 0xBA };
00069 const int magicInt = 0xBAD4D4BA;
00070 
00071 #define QSXE_KEYFILE "keyfile"
00072 
00073 /*
00074   Header in above format, less the magic bytes.
00075   Useful for reading off the socket
00076 */
00077 struct AuthHeader
00078 {
00079     unsigned char len;
00080     unsigned char pad;
00081     unsigned char digest[QSXE_KEY_LEN];
00082     unsigned char id;
00083     unsigned char seq;
00084 };
00085 
00086 /*
00087   Header in a form suitable for authentication routines
00088 */
00089 struct AuthMessage
00090 {
00091     AuthMessage()
00092     {
00093         ::memset( authData, 0, sizeof(authData) );
00094         ::memcpy( pad_magic, magic, QSXE_MAGIC_BYTES );
00095     }
00096     unsigned char pad_magic[QSXE_MAGIC_BYTES];
00097     union {
00098         AuthHeader hdr;
00099         char authData[sizeof(AuthHeader)];
00100     };
00101     char payLoad[AMOUNT_TO_AUTHENTICATE];
00102 };
00103 
00107 struct AuthCookie
00108 {
00109     unsigned char key[QSXE_KEY_LEN];
00110     unsigned char pad;
00111     unsigned char progId;
00112 };
00113 
00114 /*
00115   Auth data as written to the key file - SUPERSEDED by usr_key_entry
00116 
00117   This is still used internally for some functions, ie the socket
00118   related calls.
00119 */
00120 struct AuthRecord
00121 {
00122     union {
00123         AuthCookie auth;
00124         char data[sizeof(struct AuthCookie)];
00125     };
00126     time_t change_time;
00127 };
00128 
00145 struct usr_key_entry
00146 {
00147     char key[QSXE_KEY_LEN];
00148     ino_t ino;
00149     dev_t dev;
00150 };
00151 
00152 
00158 struct IdBlock
00159 {
00160     quint64 inode;
00161     quint64 device;
00162     unsigned char pad;
00163     unsigned char progId;
00164     unsigned short installId;
00165     unsigned int keyOffset;
00166     qint64 install_time;
00167 };
00168 
00169 QT_END_NAMESPACE
00170 
00171 QT_END_HEADER
00172 
00173 #endif // QTRANSPORTAUTHDEFS_QWS_H
00174