]> git.ipfire.org Git - thirdparty/openssl.git/blame - ssl/d1_srtp.c
Drop the last reference of SHLIB_EXT
[thirdparty/openssl.git] / ssl / d1_srtp.c
CommitLineData
846e33c7 1/*
454afd98 2 * Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
333f926d 3 *
2c18d164 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
846e33c7
RS
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
333f926d 8 */
846e33c7 9
333f926d 10/*
0f113f3e
MC
11 * DTLS code by Eric Rescorla <ekr@rtfm.com>
12 *
13 * Copyright (C) 2006, Network Resonance, Inc. Copyright (C) 2011, RTFM, Inc.
14 */
333f926d
BL
15
16#include <stdio.h>
17#include <openssl/objects.h>
706457b7 18#include "ssl_local.h"
333f926d 19
32b07f5a 20#ifndef OPENSSL_NO_SRTP
333f926d 21
0f113f3e 22static SRTP_PROTECTION_PROFILE srtp_known_profiles[] = {
333f926d 23 {
0f113f3e
MC
24 "SRTP_AES128_CM_SHA1_80",
25 SRTP_AES128_CM_SHA1_80,
26 },
333f926d 27 {
0f113f3e
MC
28 "SRTP_AES128_CM_SHA1_32",
29 SRTP_AES128_CM_SHA1_32,
30 },
43e5faa2
DS
31 {
32 "SRTP_AEAD_AES_128_GCM",
a230b26e 33 SRTP_AEAD_AES_128_GCM,
43e5faa2
DS
34 },
35 {
36 "SRTP_AEAD_AES_256_GCM",
a230b26e 37 SRTP_AEAD_AES_256_GCM,
43e5faa2 38 },
a425c0fe
KK
39 {
40 "SRTP_DOUBLE_AEAD_AES_128_GCM_AEAD_AES_128_GCM",
41 SRTP_DOUBLE_AEAD_AES_128_GCM_AEAD_AES_128_GCM,
42 },
43 {
44 "SRTP_DOUBLE_AEAD_AES_256_GCM_AEAD_AES_256_GCM",
45 SRTP_DOUBLE_AEAD_AES_256_GCM_AEAD_AES_256_GCM,
46 },
47 {
48 "SRTP_ARIA_128_CTR_HMAC_SHA1_80",
49 SRTP_ARIA_128_CTR_HMAC_SHA1_80,
50 },
51 {
52 "SRTP_ARIA_128_CTR_HMAC_SHA1_32",
53 SRTP_ARIA_128_CTR_HMAC_SHA1_32,
54 },
55 {
56 "SRTP_ARIA_256_CTR_HMAC_SHA1_80",
57 SRTP_ARIA_256_CTR_HMAC_SHA1_80,
58 },
59 {
60 "SRTP_ARIA_256_CTR_HMAC_SHA1_32",
61 SRTP_ARIA_256_CTR_HMAC_SHA1_32,
62 },
63 {
64 "SRTP_AEAD_ARIA_128_GCM",
65 SRTP_AEAD_ARIA_128_GCM,
66 },
67 {
68 "SRTP_AEAD_ARIA_256_GCM",
69 SRTP_AEAD_ARIA_256_GCM,
70 },
333f926d 71 {0}
0f113f3e 72};
333f926d
BL
73
74static int find_profile_by_name(char *profile_name,
8b0e934a 75 SRTP_PROTECTION_PROFILE **pptr, size_t len)
0f113f3e
MC
76{
77 SRTP_PROTECTION_PROFILE *p;
78
79 p = srtp_known_profiles;
80 while (p->name) {
86885c28
RS
81 if ((len == strlen(p->name))
82 && strncmp(p->name, profile_name, len) == 0) {
0f113f3e
MC
83 *pptr = p;
84 return 0;
85 }
86
87 p++;
88 }
89
90 return 1;
91}
92
93static int ssl_ctx_make_profiles(const char *profiles_string,
94 STACK_OF(SRTP_PROTECTION_PROFILE) **out)
95{
96 STACK_OF(SRTP_PROTECTION_PROFILE) *profiles;
97
98 char *col;
99 char *ptr = (char *)profiles_string;
0f113f3e
MC
100 SRTP_PROTECTION_PROFILE *p;
101
75ebbd9a 102 if ((profiles = sk_SRTP_PROTECTION_PROFILE_new_null()) == NULL) {
6849b73c 103 ERR_raise(ERR_LIB_SSL, SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);
0f113f3e
MC
104 return 1;
105 }
106
107 do {
108 col = strchr(ptr, ':');
109
8b0e934a
MC
110 if (!find_profile_by_name(ptr, &p, col ? (size_t)(col - ptr)
111 : strlen(ptr))) {
0f113f3e 112 if (sk_SRTP_PROTECTION_PROFILE_find(profiles, p) >= 0) {
6849b73c 113 ERR_raise(ERR_LIB_SSL, SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
3c82e437 114 goto err;
0f113f3e
MC
115 }
116
3c82e437 117 if (!sk_SRTP_PROTECTION_PROFILE_push(profiles, p)) {
6849b73c 118 ERR_raise(ERR_LIB_SSL, SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);
3c82e437
F
119 goto err;
120 }
0f113f3e 121 } else {
6849b73c 122 ERR_raise(ERR_LIB_SSL, SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);
3c82e437 123 goto err;
0f113f3e
MC
124 }
125
126 if (col)
127 ptr = col + 1;
128 } while (col);
129
fbdf0299
MC
130 sk_SRTP_PROTECTION_PROFILE_free(*out);
131
0f113f3e
MC
132 *out = profiles;
133
134 return 0;
a230b26e 135 err:
3c82e437
F
136 sk_SRTP_PROTECTION_PROFILE_free(profiles);
137 return 1;
0f113f3e
MC
138}
139
140int SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles)
141{
142 return ssl_ctx_make_profiles(profiles, &ctx->srtp_profiles);
143}
144
145int SSL_set_tlsext_use_srtp(SSL *s, const char *profiles)
146{
38b051a1
TM
147 SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL_ONLY(s);
148
149 if (sc == NULL)
150 return 0;
151
152 return ssl_ctx_make_profiles(profiles, &sc->srtp_profiles);
0f113f3e 153}
333f926d
BL
154
155STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *s)
0f113f3e 156{
38b051a1
TM
157 SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL_ONLY(s);
158
159 if (sc != NULL) {
160 if (sc->srtp_profiles != NULL) {
161 return sc->srtp_profiles;
0f113f3e
MC
162 } else if ((s->ctx != NULL) && (s->ctx->srtp_profiles != NULL)) {
163 return s->ctx->srtp_profiles;
164 }
165 }
166
167 return NULL;
168}
333f926d
BL
169
170SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *s)
0f113f3e 171{
38b051a1
TM
172 SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL_ONLY(s);
173
174 if (sc == NULL)
175 return 0;
176
177 return sc->srtp_profile;
0f113f3e 178}
333f926d 179#endif