blob: 22739ff159fde65d4ca47edd22fc0a26d0b42df2 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05002 Copyright (C) 2006-2013 Werner Dittmann
Alexandre Lision51140e12013-12-02 10:54:09 -05003
4 This program is free software: you can redistribute it and/or modify
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05005 it under the terms of the GNU Lesser General Public License as published by
Alexandre Lision51140e12013-12-02 10:54:09 -05006 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef _ZRTPPACKETSASRELAY_H_
19#define _ZRTPPACKETSASRELAY_H_
20
21/**
22 * @file ZrtpPacketSASrelay.h
23 * @brief The ZRTP SAS Relay message
24 *
25 * @ingroup GNU_ZRTP
26 * @{
27 */
28
29#include <libzrtpcpp/ZrtpPacketBase.h>
30
31/**
32 * Implement the Confirm packet.
33 *
34 * The ZRTP message Confirm. The implementation sends this
35 * to confirm the switch to SRTP (encrypted) mode. The contents of
36 * the Confirm message are encrypted, thus the implementation
37 * can check if the secret keys work.
38 *
39 * @author Werner Dittmann <Werner.Dittmann@t-online.de>
40 */
41
42class __EXPORT ZrtpPacketSASrelay : public ZrtpPacketBase {
43
44 private:
45 SASrelay_t* sasRelayHeader; ///< Point to the Confirm message part
46
47 public:
48 /// Creates a Confirm packet with default data
49 ZrtpPacketSASrelay();
50
51 /// Creates a Confirm packet with default data and a given signature length
52 ZrtpPacketSASrelay(uint32_t sl);
53
54 /// Creates a Confirm packet from received data
55 ZrtpPacketSASrelay(uint8_t* d);
56
57 /// Normal destructor
58 virtual ~ZrtpPacketSASrelay();
59
60 /// Check is SAS verify flag is set
61 const bool isSASFlag() { return sasRelayHeader->flags & 0x4; }
62
63 /// Get pointer to filler bytes (contains one bit of signature length)
64 const uint8_t* getFiller() { return sasRelayHeader->filler; }
65
66 /// Get pointer to IV data, fixed byte array
67 const uint8_t* getIv() { return sasRelayHeader->iv; }
68
69 /// Get pointer to MAC data, fixed byte array
70 const uint8_t* getHmac() { return sasRelayHeader->hmac; }
71
72 /// Get pointer to new SAS rendering algorithm, fixed byte array
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050073 const uint8_t* getSasAlgo() {return sasRelayHeader->sas; }
Alexandre Lision51140e12013-12-02 10:54:09 -050074
75 /// Get pointer to new SAS hash data, fixed byte array
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050076 const uint8_t* getTrustedSas() { return sasRelayHeader->trustedSasHash; }
Alexandre Lision51140e12013-12-02 10:54:09 -050077
78 /// get the signature length in words
79 uint32_t getSignatureLength();
80
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050081 /// Check if packet length makes sense. SAS rely packets are 19 words at minumum, they are similar to Confirm
82 bool isLengthOk() {return (getLength() >= 19);}
83
Alexandre Lision51140e12013-12-02 10:54:09 -050084 /// set SAS verified flag
85 void setSASFlag() { sasRelayHeader->flags |= 0x4; }
86
87 /// Set MAC data, fixed length byte array
88 void setHmac(uint8_t* text) { memcpy(sasRelayHeader->hmac, text, sizeof(sasRelayHeader->hmac)); }
89
90 /// Set IV data, fixed length byte array
91 void setIv(uint8_t* text) { memcpy(sasRelayHeader->iv, text, sizeof(sasRelayHeader->iv)); }
92
93 /// Set SAS rendering algorithm, fixed length byte array
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050094 void setSasAlgo(uint8_t* text) { memcpy(sasRelayHeader->sas, text, sizeof(sasRelayHeader->sas)); }
Alexandre Lision51140e12013-12-02 10:54:09 -050095
96 /// Set SAS hash data, fixed length byte array
97 void setTrustedSas(uint8_t* text) { memcpy(sasRelayHeader->trustedSasHash, text, sizeof(sasRelayHeader->trustedSasHash)); }
98
99 /// Set signature length in words
100 void setSignatureLength(uint32_t sl);
101
102 private:
103 void initialize();
104 // Confirm packet is of variable length. It maximum size is 524 words:
105 // - 11 words fixed size
106 // - up to 513 words variable part, depending if signature is present and its length.
107 // This leads to a maximum of 4*524=2096 bytes.
108 uint8_t data[2100]; // large enough to hold a full blown Confirm packet
109
110};
111
112/**
113 * @}
114 */
115#endif // ZRTPPACKETSASRELAY
116