blob: 04721fa20595a228651c9ead36cea1b060ea8c02 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
Alexandre Lisionddd731e2014-01-31 11:50:08 -05002 Copyright (C) 2006-2011 Werner Dittmann
Alexandre Lision51140e12013-12-02 10:54:09 -05003
4 This program is free software: you can redistribute it and/or modify
Alexandre Lisionddd731e2014-01-31 11:50:08 -05005 it under the terms of the GNU 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 Lisionddd731e2014-01-31 11:50:08 -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
81 /// set SAS verified flag
82 void setSASFlag() { sasRelayHeader->flags |= 0x4; }
83
84 /// Set MAC data, fixed length byte array
85 void setHmac(uint8_t* text) { memcpy(sasRelayHeader->hmac, text, sizeof(sasRelayHeader->hmac)); }
86
87 /// Set IV data, fixed length byte array
88 void setIv(uint8_t* text) { memcpy(sasRelayHeader->iv, text, sizeof(sasRelayHeader->iv)); }
89
90 /// Set SAS rendering algorithm, fixed length byte array
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050091 void setSasAlgo(uint8_t* text) { memcpy(sasRelayHeader->sas, text, sizeof(sasRelayHeader->sas)); }
Alexandre Lision51140e12013-12-02 10:54:09 -050092
93 /// Set SAS hash data, fixed length byte array
94 void setTrustedSas(uint8_t* text) { memcpy(sasRelayHeader->trustedSasHash, text, sizeof(sasRelayHeader->trustedSasHash)); }
95
96 /// Set signature length in words
97 void setSignatureLength(uint32_t sl);
98
99 private:
100 void initialize();
101 // Confirm packet is of variable length. It maximum size is 524 words:
102 // - 11 words fixed size
103 // - up to 513 words variable part, depending if signature is present and its length.
104 // This leads to a maximum of 4*524=2096 bytes.
105 uint8_t data[2100]; // large enough to hold a full blown Confirm packet
106
107};
108
109/**
110 * @}
111 */
112#endif // ZRTPPACKETSASRELAY
113