src/gui/embedded/qtransportauthdefs_qws.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    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 {
       
    91     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