Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ZrtpConfigure.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2010 Werner Dittmann
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  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 /*
19  * Authors: Werner Dittmann <Werner.Dittmann@t-online.de>
20  */
21 
22 #ifndef _ZRTPCONFIGURE_H_
23 #define _ZRTPCONFIGURE_H_
24 
32 #include <stdio.h>
33 #include <stdint.h>
34 #include <list>
35 #include <string>
36 #include <vector>
37 #include <string.h>
38 
40 
45 enum AlgoTypes {
47 };
48 
49 typedef void(*encrypt_t)(uint8_t*, int32_t, uint8_t*, uint8_t*, int32_t);
50 typedef void(*decrypt_t)(uint8_t*, int32_t, const uint8_t*, uint8_t*, int32_t);
51 
63 public:
86  AlgorithmEnum(const AlgoTypes type, const char* name, int32_t klen,
87  const char* ra, encrypt_t en, decrypt_t de, SrtpAlgorithms alId);
88 
93 
101  const char* getName();
102 
110  const char* getReadable();
111 
118  int getKeylen();
119 
134 
142 
152 
159  bool isValid();
160 
161 private:
163  std::string algoName;
164  int32_t keyLen;
165  std::string readable;
169 };
170 
185 class EnumBase {
186 public:
196  AlgorithmEnum& getByName(const char* name);
197 
204  std::list<std::string>* getAllNames();
205 
212  int getSize();
213 
222 
231  AlgorithmEnum& getByOrdinal(int ord);
232 
243  int getOrdinal(AlgorithmEnum& algo);
244 
245 protected:
246  EnumBase(AlgoTypes algo);
247  ~EnumBase();
248  void insert(const char* name);
249  void insert(const char* name, int32_t klen,
250  const char* ra, encrypt_t en, decrypt_t de, SrtpAlgorithms alId);
251 
252 private:
254  std::vector <AlgorithmEnum* > algos;
255 };
256 
260 class HashEnum : public EnumBase {
261 public:
262  HashEnum();
263  ~HashEnum();
264 };
265 
266 class SymCipherEnum : public EnumBase {
267 public:
268  SymCipherEnum();
269  ~SymCipherEnum();
270 };
271 
272 class PubKeyEnum : public EnumBase {
273 public:
274  PubKeyEnum();
275  ~PubKeyEnum();
276 };
277 
278 class SasTypeEnum : public EnumBase {
279 public:
280  SasTypeEnum();
281  ~SasTypeEnum();
282 };
283 
284 class AuthLengthEnum : public EnumBase {
285 public:
286  AuthLengthEnum();
287  ~AuthLengthEnum();
288 };
289 
290 extern HashEnum zrtpHashes;
292 extern PubKeyEnum zrtpPubKeys;
295 
313 public:
314  ZrtpConfigure(); /* Creates Configuration data */
315  ~ZrtpConfigure();
316 
321  static const int maxNoOfAlgos = 7;
334  void setStandardConfig();
335 
348  void setMandatoryOnly();
349 
355  void clear();
356 
372  int32_t addAlgo(AlgoTypes algoType, AlgorithmEnum& algo);
373 
390  int32_t addAlgoAt(AlgoTypes algoType, AlgorithmEnum& algo, int32_t index);
391 
411  int32_t removeAlgo(AlgoTypes algoType, AlgorithmEnum& algo);
412 
422  int32_t getNumConfiguredAlgos(AlgoTypes algoType);
423 
437  AlgorithmEnum& getAlgoAt(AlgoTypes algoType, int32_t index);
438 
451  bool containsAlgo(AlgoTypes algoType, AlgorithmEnum& algo);
452 
462  void setTrustedMitM(bool yesNo);
463 
470  bool isTrustedMitM();
471 
481  void setSasSignature(bool yesNo);
482 
489  bool isSasSignature();
490 
500  void setParanoidMode(bool yesNo);
501 
508  bool isParanoidMode();
509 
511  void printConfiguredAlgos(AlgoTypes algoTyp);
512 
513  private:
514  std::vector<AlgorithmEnum* > hashes;
515  std::vector<AlgorithmEnum* > symCiphers;
516  std::vector<AlgorithmEnum* > publicKeyAlgos;
517  std::vector<AlgorithmEnum* > sasTypes;
518  std::vector<AlgorithmEnum* > authLengths;
519 
523 
524 
525  AlgorithmEnum& getAlgoAt(std::vector<AlgorithmEnum* >& a, int32_t index);
526  int32_t addAlgo(std::vector<AlgorithmEnum* >& a, AlgorithmEnum& algo);
527  int32_t addAlgoAt(std::vector<AlgorithmEnum* >& a, AlgorithmEnum& algo, int32_t index);
528  int32_t removeAlgo(std::vector<AlgorithmEnum* >& a, AlgorithmEnum& algo);
529  int32_t getNumConfiguredAlgos(std::vector<AlgorithmEnum* >& a);
530  bool containsAlgo(std::vector<AlgorithmEnum* >& a, AlgorithmEnum& algo);
531  std::vector<AlgorithmEnum* >& getEnum(AlgoTypes algoType);
532 
533  void printConfiguredAlgos(std::vector<AlgorithmEnum* >& a);
534 
535  protected:
536 
537  public:
538 };
539 
543 #endif
544 
int getOrdinal(AlgorithmEnum &algo)
Get the ordinal number of an AlgorithmEnum.
ZRTP configuration data.
AlgoTypes algoType
std::vector< AlgorithmEnum * > algos
Common C++ generic string class.
decrypt_t getDecrypt()
Get the algorihm's key length.
AlgorithmEnum & getByOrdinal(int ord)
Return the AlgorithmEnum by its ordinal number.
SymCipherEnum zrtpSymCiphers
bool isValid()
Check if this AlgorithmEnum object is valid.
bool enableTrustedMitM
std::vector< AlgorithmEnum * > publicKeyAlgos
bool enableSasSignature
SrtpAlgorithms getAlgoId()
Get the algorihm's integer id.
HashEnum zrtpHashes
const char * getName()
Get the algorihm's name.
std::string algoName
The enumaration subclasses that contain the supported algorithm enumerations.
void(* encrypt_t)(uint8_t *, int32_t, uint8_t *, uint8_t *, int32_t)
Definition: ZrtpConfigure.h:49
SasTypeEnum zrtpSasTypes
AlgorithmEnum & getByName(const char *name)
Get an AlgorithmEnum by its name.
struct ZrtpConfigure ZrtpConfigure
Definition: ZrtpCWrapper.h:262
EnumBase provides methods to store and access algorithm enumerations of a specific algorithm type...
PubKeyEnum zrtpPubKeys
encrypt_t encrypt
std::vector< AlgorithmEnum * > hashes
std::vector< AlgorithmEnum * > symCiphers
void insert(const char *name)
AuthLengthEnum zrtpAuthLengths
std::vector< AlgorithmEnum * > authLengths
AlgoTypes getAlgoType()
Get the AlgoTypes to which this EnumBase belongs.
const char * getReadable()
Get the algorihm's readable name.
bool enableParanoidMode
SrtpAlgorithms
The algorihms that we support in SRTP and that ZRTP can negotiate.
Definition: ZrtpCallback.h:66
AlgoTypes
This enumerations list all configurable algorithm types.
Definition: ZrtpConfigure.h:45
decrypt_t decrypt
EnumBase(AlgoTypes algo)
void(* decrypt_t)(uint8_t *, int32_t, const uint8_t *, uint8_t *, int32_t)
Definition: ZrtpConfigure.h:50
#define __EXPORT
Definition: audio2.h:51
int getKeylen()
Get the algorihm's key length.
std::string readable
encrypt_t getEncrypt()
Get the algorihm's key length.
Callback interface between ZRTP and the RTP stack implementation.
AlgoTypes algoType
AlgoTypes getAlgoType()
Get the algorithm type of this AlgorithmEnum object.
SrtpAlgorithms algoId
std::vector< AlgorithmEnum * > sasTypes
int getSize()
Get the number of currently stored AlgorithmEnums.
~AlgorithmEnum()
AlgorithmEnum destructor.
AlgorithmEnum(const AlgoTypes type, const char *name, int32_t klen, const char *ra, encrypt_t en, decrypt_t de, SrtpAlgorithms alId)
Create an AlgorithmEnum object.
The algorithm enumration class.
Definition: ZrtpConfigure.h:62
std::list< std::string > * getAllNames()
Return all names of all currently stored AlgorithmEnums.