]> git.ipfire.org Git - thirdparty/openssl.git/blame - ssl/d1_srtp.c
Use allow_early_data_cb from SSL instead of SSL_CTX
[thirdparty/openssl.git] / ssl / d1_srtp.c
CommitLineData
846e33c7
RS
1/*
2 * Copyright 2011-2016 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>
18#include "ssl_locl.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 },
333f926d 39 {0}
0f113f3e 40};
333f926d
BL
41
42static int find_profile_by_name(char *profile_name,
8b0e934a 43 SRTP_PROTECTION_PROFILE **pptr, size_t len)
0f113f3e
MC
44{
45 SRTP_PROTECTION_PROFILE *p;
46
47 p = srtp_known_profiles;
48 while (p->name) {
86885c28
RS
49 if ((len == strlen(p->name))
50 && strncmp(p->name, profile_name, len) == 0) {
0f113f3e
MC
51 *pptr = p;
52 return 0;
53 }
54
55 p++;
56 }
57
58 return 1;
59}
60
61static int ssl_ctx_make_profiles(const char *profiles_string,
62 STACK_OF(SRTP_PROTECTION_PROFILE) **out)
63{
64 STACK_OF(SRTP_PROTECTION_PROFILE) *profiles;
65
66 char *col;
67 char *ptr = (char *)profiles_string;
0f113f3e
MC
68 SRTP_PROTECTION_PROFILE *p;
69
75ebbd9a 70 if ((profiles = sk_SRTP_PROTECTION_PROFILE_new_null()) == NULL) {
0f113f3e
MC
71 SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,
72 SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);
73 return 1;
74 }
75
76 do {
77 col = strchr(ptr, ':');
78
8b0e934a
MC
79 if (!find_profile_by_name(ptr, &p, col ? (size_t)(col - ptr)
80 : strlen(ptr))) {
0f113f3e
MC
81 if (sk_SRTP_PROTECTION_PROFILE_find(profiles, p) >= 0) {
82 SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,
83 SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
3c82e437 84 goto err;
0f113f3e
MC
85 }
86
3c82e437
F
87 if (!sk_SRTP_PROTECTION_PROFILE_push(profiles, p)) {
88 SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,
89 SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);
90 goto err;
91 }
0f113f3e
MC
92 } else {
93 SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,
94 SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);
3c82e437 95 goto err;
0f113f3e
MC
96 }
97
98 if (col)
99 ptr = col + 1;
100 } while (col);
101
fbdf0299
MC
102 sk_SRTP_PROTECTION_PROFILE_free(*out);
103
0f113f3e
MC
104 *out = profiles;
105
106 return 0;
a230b26e 107 err:
3c82e437
F
108 sk_SRTP_PROTECTION_PROFILE_free(profiles);
109 return 1;
0f113f3e
MC
110}
111
112int SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles)
113{
114 return ssl_ctx_make_profiles(profiles, &ctx->srtp_profiles);
115}
116
117int SSL_set_tlsext_use_srtp(SSL *s, const char *profiles)
118{
119 return ssl_ctx_make_profiles(profiles, &s->srtp_profiles);
120}
333f926d
BL
121
122STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *s)
0f113f3e
MC
123{
124 if (s != NULL) {
125 if (s->srtp_profiles != NULL) {
126 return s->srtp_profiles;
127 } else if ((s->ctx != NULL) && (s->ctx->srtp_profiles != NULL)) {
128 return s->ctx->srtp_profiles;
129 }
130 }
131
132 return NULL;
133}
333f926d
BL
134
135SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *s)
0f113f3e
MC
136{
137 return s->srtp_profile;
138}
333f926d 139#endif