Line data Source code
1 : /*
2 : * Copyright (C) 2004-2024 Savoir-faire Linux Inc.
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 <https://www.gnu.org/licenses/>.
16 : */
17 : #pragma once
18 :
19 : #include "media/media_codec.h"
20 :
21 : #include <stdexcept>
22 : #include <string>
23 : #include <vector>
24 :
25 : using namespace std::literals;
26 :
27 : namespace jami {
28 :
29 : /**
30 : * General exception object that is thrown when
31 : * an error occurred with a regular expression
32 : * operation.
33 : */
34 : class ParseError : public std::invalid_argument
35 : {
36 : public:
37 0 : explicit ParseError(const std::string& error)
38 0 : : std::invalid_argument(error)
39 0 : {}
40 : };
41 :
42 : enum CipherMode { AESCounterMode, AESF8Mode };
43 :
44 : enum MACMode { HMACSHA1 };
45 :
46 : enum KeyMethod {
47 : Inline
48 : // url, maybe at some point
49 : };
50 :
51 : struct CryptoSuiteDefinition
52 : {
53 : std::string_view name;
54 : int masterKeyLength;
55 : int masterSaltLength;
56 : int srtpLifetime;
57 : int srtcpLifetime;
58 : CipherMode cipher;
59 : int encryptionKeyLength;
60 : MACMode mac;
61 : int srtpAuthTagLength;
62 : int srtcpAuthTagLength;
63 : int srtpAuthKeyLength;
64 : int srtcpAuthKeyLen;
65 : };
66 :
67 : /**
68 : * List of accepted Crypto-Suites
69 : * as defined in RFC4568 (6.2)
70 : */
71 :
72 : static std::vector<CryptoSuiteDefinition> CryptoSuites = {
73 : {"AES_CM_128_HMAC_SHA1_80"sv, 128, 112, 48, 31, AESCounterMode, 128, HMACSHA1, 80, 80, 160, 160},
74 :
75 : {"AES_CM_128_HMAC_SHA1_32"sv, 128, 112, 48, 31, AESCounterMode, 128, HMACSHA1, 32, 80, 160, 160},
76 :
77 : {"F8_128_HMAC_SHA1_80"sv, 128, 112, 48, 31, AESF8Mode, 128, HMACSHA1, 80, 80, 160, 160}};
78 :
79 : class SdesNegotiator
80 : {
81 : public:
82 : SdesNegotiator();
83 :
84 : static CryptoAttribute negotiate(const std::vector<std::string>& attributes);
85 :
86 : inline explicit operator bool() const { return not CryptoSuites.empty(); }
87 :
88 : private:
89 : static std::vector<CryptoAttribute> parse(const std::vector<std::string>& attributes);
90 : };
91 :
92 : } // namespace jami
|