/src/openssl/ssl/d1_srtp.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the OpenSSL license (the "License"). You may not use |
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 |
8 | | */ |
9 | | |
10 | | /* |
11 | | * DTLS code by Eric Rescorla <ekr@rtfm.com> |
12 | | * |
13 | | * Copyright (C) 2006, Network Resonance, Inc. Copyright (C) 2011, RTFM, Inc. |
14 | | */ |
15 | | |
16 | | #include <stdio.h> |
17 | | #include <openssl/objects.h> |
18 | | #include "ssl_locl.h" |
19 | | |
20 | | #ifndef OPENSSL_NO_SRTP |
21 | | |
22 | | static SRTP_PROTECTION_PROFILE srtp_known_profiles[] = { |
23 | | { |
24 | | "SRTP_AES128_CM_SHA1_80", |
25 | | SRTP_AES128_CM_SHA1_80, |
26 | | }, |
27 | | { |
28 | | "SRTP_AES128_CM_SHA1_32", |
29 | | SRTP_AES128_CM_SHA1_32, |
30 | | }, |
31 | | { |
32 | | "SRTP_AEAD_AES_128_GCM", |
33 | | SRTP_AEAD_AES_128_GCM, |
34 | | }, |
35 | | { |
36 | | "SRTP_AEAD_AES_256_GCM", |
37 | | SRTP_AEAD_AES_256_GCM, |
38 | | }, |
39 | | {0} |
40 | | }; |
41 | | |
42 | | static int find_profile_by_name(char *profile_name, |
43 | | SRTP_PROTECTION_PROFILE **pptr, size_t len) |
44 | 0 | { |
45 | 0 | SRTP_PROTECTION_PROFILE *p; |
46 | 0 |
|
47 | 0 | p = srtp_known_profiles; |
48 | 0 | while (p->name) { |
49 | 0 | if ((len == strlen(p->name)) |
50 | 0 | && strncmp(p->name, profile_name, len) == 0) { |
51 | 0 | *pptr = p; |
52 | 0 | return 0; |
53 | 0 | } |
54 | 0 | |
55 | 0 | p++; |
56 | 0 | } |
57 | 0 |
|
58 | 0 | return 1; |
59 | 0 | } |
60 | | |
61 | | static int ssl_ctx_make_profiles(const char *profiles_string, |
62 | | STACK_OF(SRTP_PROTECTION_PROFILE) **out) |
63 | 0 | { |
64 | 0 | STACK_OF(SRTP_PROTECTION_PROFILE) *profiles; |
65 | 0 |
|
66 | 0 | char *col; |
67 | 0 | char *ptr = (char *)profiles_string; |
68 | 0 | SRTP_PROTECTION_PROFILE *p; |
69 | 0 |
|
70 | 0 | if ((profiles = sk_SRTP_PROTECTION_PROFILE_new_null()) == NULL) { |
71 | 0 | SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES, |
72 | 0 | SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES); |
73 | 0 | return 1; |
74 | 0 | } |
75 | 0 |
|
76 | 0 | do { |
77 | 0 | col = strchr(ptr, ':'); |
78 | 0 |
|
79 | 0 | if (!find_profile_by_name(ptr, &p, col ? (size_t)(col - ptr) |
80 | 0 | : strlen(ptr))) { |
81 | 0 | if (sk_SRTP_PROTECTION_PROFILE_find(profiles, p) >= 0) { |
82 | 0 | SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES, |
83 | 0 | SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST); |
84 | 0 | goto err; |
85 | 0 | } |
86 | 0 |
|
87 | 0 | if (!sk_SRTP_PROTECTION_PROFILE_push(profiles, p)) { |
88 | 0 | SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES, |
89 | 0 | SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES); |
90 | 0 | goto err; |
91 | 0 | } |
92 | 0 | } else { |
93 | 0 | SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES, |
94 | 0 | SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE); |
95 | 0 | goto err; |
96 | 0 | } |
97 | 0 |
|
98 | 0 | if (col) |
99 | 0 | ptr = col + 1; |
100 | 0 | } while (col); |
101 | 0 |
|
102 | 0 | sk_SRTP_PROTECTION_PROFILE_free(*out); |
103 | 0 |
|
104 | 0 | *out = profiles; |
105 | 0 |
|
106 | 0 | return 0; |
107 | 0 | err: |
108 | 0 | sk_SRTP_PROTECTION_PROFILE_free(profiles); |
109 | 0 | return 1; |
110 | 0 | } |
111 | | |
112 | | int SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles) |
113 | 0 | { |
114 | 0 | return ssl_ctx_make_profiles(profiles, &ctx->srtp_profiles); |
115 | 0 | } |
116 | | |
117 | | int SSL_set_tlsext_use_srtp(SSL *s, const char *profiles) |
118 | 0 | { |
119 | 0 | return ssl_ctx_make_profiles(profiles, &s->srtp_profiles); |
120 | 0 | } |
121 | | |
122 | | STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *s) |
123 | 0 | { |
124 | 0 | if (s != NULL) { |
125 | 0 | if (s->srtp_profiles != NULL) { |
126 | 0 | return s->srtp_profiles; |
127 | 0 | } else if ((s->ctx != NULL) && (s->ctx->srtp_profiles != NULL)) { |
128 | 0 | return s->ctx->srtp_profiles; |
129 | 0 | } |
130 | 0 | } |
131 | 0 | |
132 | 0 | return NULL; |
133 | 0 | } |
134 | | |
135 | | SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *s) |
136 | 0 | { |
137 | 0 | return s->srtp_profile; |
138 | 0 | } |
139 | | #endif |