blob: e3ff85be21f2811ba05a78f24a9613caa616a6bf [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
Alexandre Lisionddd731e2014-01-31 11:50:08 -05002 Copyright (C) 2006-2010 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 _ZRTPPACKETCONFIRM_H_
19#define _ZRTPPACKETCONFIRM_H_
20
21/**
22 * @file ZrtpPacketConfirm.h
23 * @brief The ZRTP Confirm 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 ZrtpPacketConfirm : public ZrtpPacketBase {
43
44 private:
45 Confirm_t* confirmHeader; ///< Point to the Confirm message part
46
47 public:
48 /// Creates a Confirm packet with default data
49 ZrtpPacketConfirm();
50
51 /// Creates a Confirm packet with default data and a given signature length
52 ZrtpPacketConfirm(uint32_t sl);
53
54 /// Creates a Confirm packet from received data
55 ZrtpPacketConfirm(uint8_t* d);
56
57 /// Normal destructor
58 virtual ~ZrtpPacketConfirm();
59
60 /// Check if SAS verify flag is set
61 const bool isSASFlag() { return confirmHeader->flags & 0x4; }
62
63 /// Check if PBXEnrollment flag is set
64 const bool isPBXEnrollment() { return confirmHeader->flags & 0x8; }
65
66 /// Get pointer to filler bytes (contains one bit of signature length)
67 const uint8_t* getFiller() { return confirmHeader->filler; }
68
69 /// Get pointer to IV data, fixed byte array
70 const uint8_t* getIv() { return confirmHeader->iv; }
71
72 /// Get pointer to MAC data, fixed byte array
73 const uint8_t* getHmac() { return confirmHeader->hmac; }
74
75 /// Get Expiration time data
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050076 const uint32_t getExpTime() { return zrtpNtohl(confirmHeader->expTime); }
Alexandre Lision51140e12013-12-02 10:54:09 -050077
78 /// Get pointer to initial hash chain (H0) data, fixed byte array
79 uint8_t* getHashH0() { return confirmHeader->hashH0; }
80
81 /// Get pointer to signature data, variable length, refer to getSignatureLength()
82 const uint8_t* getSignatureData() { return ((uint8_t*)&confirmHeader->expTime) + 4; }
83
84 /// get the signature length in words
85 int32_t getSignatureLength();
86
87 /// set SAS verified flag
88 void setSASFlag() { confirmHeader->flags |= 0x4; }
89
90 /// set setPBXEnrollment flag
91 void setPBXEnrollment() { confirmHeader->flags |= 0x8; }
92
93 /// Set MAC data, fixed length byte array
94 void setHmac(uint8_t* text) { memcpy(confirmHeader->hmac, text, sizeof(confirmHeader->hmac)); }
95
96 /// Set IV data, fixed length byte array
97 void setIv(uint8_t* text) { memcpy(confirmHeader->iv, text, sizeof(confirmHeader->iv)); }
98
99 /// Set expiration time data
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500100 void setExpTime(uint32_t t) { confirmHeader->expTime = zrtpHtonl(t); }
Alexandre Lision51140e12013-12-02 10:54:09 -0500101
102 /// Set initial hash chain (H0) data, fixed length byte array
103 void setHashH0(uint8_t* t) { memcpy(confirmHeader->hashH0, t, sizeof(confirmHeader->hashH0)); }
104
105 /// Set signature data, length of the signature data in bytes and must be a multiple of 4.
106 bool setSignatureData(uint8_t* data, int32_t length);
107
108 /// Set signature length in words
109 bool setSignatureLength(uint32_t sl);
110
111 private:
112 void initialize();
113 // Confirm packet is of variable length. It maximum size is 524 words:
114 // - 11 words fixed size
115 // - up to 513 words variable part, depending if signature is present and its length.
116 // This leads to a maximum of 4*524=2096 bytes.
117 uint8_t data[2100]; // large enough to hold a full blown Confirm packet
118
119};
120
121/**
122 * @}
123 */
124#endif // ZRTPPACKETCONFIRM
125