Line data Source code
1 : /*
2 : * Copyright (C) 2004-2024 Savoir-faire Linux Inc.
3 : *
4 : * Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
5 : * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
6 : * Author: Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com>
7 : *
8 : * This program is free software; you can redistribute it and/or modify
9 : * it under the terms of the GNU General Public License as published by
10 : * the Free Software Foundation; either version 3 of the License, or
11 : * (at your option) any later version.
12 : *
13 : * This program is distributed in the hope that it will be useful,
14 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : * GNU General Public License for more details.
17 : *
18 : * You should have received a copy of the GNU General Public License
19 : * along with this program; if not, write to the Free Software
20 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 : */
22 : #pragma once
23 :
24 : #include "media/media_codec.h"
25 :
26 : #include <stdexcept>
27 : #include <string>
28 : #include <vector>
29 :
30 : using namespace std::literals;
31 :
32 : namespace jami {
33 :
34 : /**
35 : * General exception object that is thrown when
36 : * an error occurred with a regular expression
37 : * operation.
38 : */
39 : class ParseError : public std::invalid_argument
40 : {
41 : public:
42 0 : explicit ParseError(const std::string& error)
43 0 : : std::invalid_argument(error)
44 0 : {}
45 : };
46 :
47 : enum CipherMode { AESCounterMode, AESF8Mode };
48 :
49 : enum MACMode { HMACSHA1 };
50 :
51 : enum KeyMethod {
52 : Inline
53 : // url, maybe at some point
54 : };
55 :
56 : struct CryptoSuiteDefinition
57 : {
58 : std::string_view name;
59 : int masterKeyLength;
60 : int masterSaltLength;
61 : int srtpLifetime;
62 : int srtcpLifetime;
63 : CipherMode cipher;
64 : int encryptionKeyLength;
65 : MACMode mac;
66 : int srtpAuthTagLength;
67 : int srtcpAuthTagLength;
68 : int srtpAuthKeyLength;
69 : int srtcpAuthKeyLen;
70 : };
71 :
72 : /**
73 : * List of accepted Crypto-Suites
74 : * as defined in RFC4568 (6.2)
75 : */
76 :
77 : static std::vector<CryptoSuiteDefinition> CryptoSuites = {
78 : {"AES_CM_128_HMAC_SHA1_80"sv, 128, 112, 48, 31, AESCounterMode, 128, HMACSHA1, 80, 80, 160, 160},
79 :
80 : {"AES_CM_128_HMAC_SHA1_32"sv, 128, 112, 48, 31, AESCounterMode, 128, HMACSHA1, 32, 80, 160, 160},
81 :
82 : {"F8_128_HMAC_SHA1_80"sv, 128, 112, 48, 31, AESF8Mode, 128, HMACSHA1, 80, 80, 160, 160}};
83 :
84 : class SdesNegotiator
85 : {
86 : public:
87 : SdesNegotiator();
88 :
89 : static CryptoAttribute negotiate(const std::vector<std::string>& attributes);
90 :
91 : inline explicit operator bool() const { return not CryptoSuites.empty(); }
92 :
93 : private:
94 : static std::vector<CryptoAttribute> parse(const std::vector<std::string>& attributes);
95 : };
96 :
97 : } // namespace jami
|