1238384Sjkim/* ssl/t1_lib.c */
2238384Sjkim/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3238384Sjkim * All rights reserved.
4238384Sjkim *
5238384Sjkim * This package is an SSL implementation written
6238384Sjkim * by Eric Young (eay@cryptsoft.com).
7238384Sjkim * The implementation was written so as to conform with Netscapes SSL.
8280297Sjkim *
9238384Sjkim * This library is free for commercial and non-commercial use as long as
10238384Sjkim * the following conditions are aheared to.  The following conditions
11238384Sjkim * apply to all code found in this distribution, be it the RC4, RSA,
12238384Sjkim * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13238384Sjkim * included with this distribution is covered by the same copyright terms
14238384Sjkim * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15280297Sjkim *
16238384Sjkim * Copyright remains Eric Young's, and as such any Copyright notices in
17238384Sjkim * the code are not to be removed.
18238384Sjkim * If this package is used in a product, Eric Young should be given attribution
19238384Sjkim * as the author of the parts of the library used.
20238384Sjkim * This can be in the form of a textual message at program startup or
21238384Sjkim * in documentation (online or textual) provided with the package.
22280297Sjkim *
23238384Sjkim * Redistribution and use in source and binary forms, with or without
24238384Sjkim * modification, are permitted provided that the following conditions
25238384Sjkim * are met:
26238384Sjkim * 1. Redistributions of source code must retain the copyright
27238384Sjkim *    notice, this list of conditions and the following disclaimer.
28238384Sjkim * 2. Redistributions in binary form must reproduce the above copyright
29238384Sjkim *    notice, this list of conditions and the following disclaimer in the
30238384Sjkim *    documentation and/or other materials provided with the distribution.
31238384Sjkim * 3. All advertising materials mentioning features or use of this software
32238384Sjkim *    must display the following acknowledgement:
33238384Sjkim *    "This product includes cryptographic software written by
34238384Sjkim *     Eric Young (eay@cryptsoft.com)"
35238384Sjkim *    The word 'cryptographic' can be left out if the rouines from the library
36238384Sjkim *    being used are not cryptographic related :-).
37280297Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from
38238384Sjkim *    the apps directory (application code) you must include an acknowledgement:
39238384Sjkim *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40280297Sjkim *
41238384Sjkim * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42238384Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43238384Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44238384Sjkim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45238384Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46238384Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47238384Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48238384Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49238384Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50238384Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51238384Sjkim * SUCH DAMAGE.
52280297Sjkim *
53238384Sjkim * The licence and distribution terms for any publically available version or
54238384Sjkim * derivative of this code cannot be changed.  i.e. this code cannot simply be
55238384Sjkim * copied and put under another distribution licence
56238384Sjkim * [including the GNU Public Licence.]
57238384Sjkim */
58238384Sjkim/* ====================================================================
59238384Sjkim * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
60238384Sjkim *
61238384Sjkim * Redistribution and use in source and binary forms, with or without
62238384Sjkim * modification, are permitted provided that the following conditions
63238384Sjkim * are met:
64238384Sjkim *
65238384Sjkim * 1. Redistributions of source code must retain the above copyright
66280297Sjkim *    notice, this list of conditions and the following disclaimer.
67238384Sjkim *
68238384Sjkim * 2. Redistributions in binary form must reproduce the above copyright
69238384Sjkim *    notice, this list of conditions and the following disclaimer in
70238384Sjkim *    the documentation and/or other materials provided with the
71238384Sjkim *    distribution.
72238384Sjkim *
73238384Sjkim * 3. All advertising materials mentioning features or use of this
74238384Sjkim *    software must display the following acknowledgment:
75238384Sjkim *    "This product includes software developed by the OpenSSL Project
76238384Sjkim *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77238384Sjkim *
78238384Sjkim * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79238384Sjkim *    endorse or promote products derived from this software without
80238384Sjkim *    prior written permission. For written permission, please contact
81238384Sjkim *    openssl-core@openssl.org.
82238384Sjkim *
83238384Sjkim * 5. Products derived from this software may not be called "OpenSSL"
84238384Sjkim *    nor may "OpenSSL" appear in their names without prior written
85238384Sjkim *    permission of the OpenSSL Project.
86238384Sjkim *
87238384Sjkim * 6. Redistributions of any form whatsoever must retain the following
88238384Sjkim *    acknowledgment:
89238384Sjkim *    "This product includes software developed by the OpenSSL Project
90238384Sjkim *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91238384Sjkim *
92238384Sjkim * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93238384Sjkim * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94238384Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95238384Sjkim * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
96238384Sjkim * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97238384Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98238384Sjkim * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99238384Sjkim * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100238384Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101238384Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102238384Sjkim * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103238384Sjkim * OF THE POSSIBILITY OF SUCH DAMAGE.
104238384Sjkim * ====================================================================
105238384Sjkim *
106238384Sjkim * This product includes cryptographic software written by Eric Young
107238384Sjkim * (eay@cryptsoft.com).  This product includes software written by Tim
108238384Sjkim * Hudson (tjh@cryptsoft.com).
109238384Sjkim *
110238384Sjkim */
111238384Sjkim/*
112280297Sjkim * DTLS code by Eric Rescorla <ekr@rtfm.com>
113280297Sjkim *
114280297Sjkim * Copyright (C) 2006, Network Resonance, Inc. Copyright (C) 2011, RTFM, Inc.
115280297Sjkim */
116238384Sjkim
117238384Sjkim#include <stdio.h>
118238384Sjkim#include <openssl/objects.h>
119238384Sjkim#include "ssl_locl.h"
120290207Sjkim#include "srtp.h"
121246772Sjkim
122246772Sjkim#ifndef OPENSSL_NO_SRTP
123246772Sjkim
124280297Sjkimstatic SRTP_PROTECTION_PROFILE srtp_known_profiles[] = {
125238384Sjkim    {
126280297Sjkim     "SRTP_AES128_CM_SHA1_80",
127280297Sjkim     SRTP_AES128_CM_SHA1_80,
128280297Sjkim     },
129238384Sjkim    {
130280297Sjkim     "SRTP_AES128_CM_SHA1_32",
131280297Sjkim     SRTP_AES128_CM_SHA1_32,
132280297Sjkim     },
133280297Sjkim# if 0
134238384Sjkim    {
135280297Sjkim     "SRTP_NULL_SHA1_80",
136280297Sjkim     SRTP_NULL_SHA1_80,
137280297Sjkim     },
138238384Sjkim    {
139280297Sjkim     "SRTP_NULL_SHA1_32",
140280297Sjkim     SRTP_NULL_SHA1_32,
141280297Sjkim     },
142280297Sjkim# endif
143238384Sjkim    {0}
144280297Sjkim};
145238384Sjkim
146238384Sjkimstatic int find_profile_by_name(char *profile_name,
147280297Sjkim                                SRTP_PROTECTION_PROFILE **pptr, unsigned len)
148280297Sjkim{
149280297Sjkim    SRTP_PROTECTION_PROFILE *p;
150238384Sjkim
151280297Sjkim    p = srtp_known_profiles;
152280297Sjkim    while (p->name) {
153280297Sjkim        if ((len == strlen(p->name)) && !strncmp(p->name, profile_name, len)) {
154280297Sjkim            *pptr = p;
155280297Sjkim            return 0;
156280297Sjkim        }
157238384Sjkim
158280297Sjkim        p++;
159280297Sjkim    }
160238384Sjkim
161280297Sjkim    return 1;
162280297Sjkim}
163238384Sjkim
164280297Sjkimstatic int ssl_ctx_make_profiles(const char *profiles_string,
165280297Sjkim                                 STACK_OF(SRTP_PROTECTION_PROFILE) **out)
166280297Sjkim{
167280297Sjkim    STACK_OF(SRTP_PROTECTION_PROFILE) *profiles;
168238384Sjkim
169280297Sjkim    char *col;
170280297Sjkim    char *ptr = (char *)profiles_string;
171238384Sjkim
172280297Sjkim    SRTP_PROTECTION_PROFILE *p;
173238384Sjkim
174280297Sjkim    if (!(profiles = sk_SRTP_PROTECTION_PROFILE_new_null())) {
175280297Sjkim        SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,
176280297Sjkim               SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);
177280297Sjkim        return 1;
178280297Sjkim    }
179273144Sjkim
180280297Sjkim    do {
181280297Sjkim        col = strchr(ptr, ':');
182238384Sjkim
183280297Sjkim        if (!find_profile_by_name(ptr, &p,
184280297Sjkim                                  col ? col - ptr : (int)strlen(ptr))) {
185280297Sjkim            if (sk_SRTP_PROTECTION_PROFILE_find(profiles, p) >= 0) {
186280297Sjkim                SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,
187280297Sjkim                       SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
188280297Sjkim                sk_SRTP_PROTECTION_PROFILE_free(profiles);
189280297Sjkim                return 1;
190280297Sjkim            }
191238384Sjkim
192280297Sjkim            sk_SRTP_PROTECTION_PROFILE_push(profiles, p);
193280297Sjkim        } else {
194280297Sjkim            SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,
195280297Sjkim                   SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);
196280297Sjkim            sk_SRTP_PROTECTION_PROFILE_free(profiles);
197280297Sjkim            return 1;
198280297Sjkim        }
199238384Sjkim
200280297Sjkim        if (col)
201280297Sjkim            ptr = col + 1;
202280297Sjkim    } while (col);
203238384Sjkim
204280297Sjkim    *out = profiles;
205238384Sjkim
206280297Sjkim    return 0;
207280297Sjkim}
208280297Sjkim
209280297Sjkimint SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles)
210280297Sjkim{
211280297Sjkim    return ssl_ctx_make_profiles(profiles, &ctx->srtp_profiles);
212280297Sjkim}
213280297Sjkim
214280297Sjkimint SSL_set_tlsext_use_srtp(SSL *s, const char *profiles)
215280297Sjkim{
216280297Sjkim    return ssl_ctx_make_profiles(profiles, &s->srtp_profiles);
217280297Sjkim}
218280297Sjkim
219238384SjkimSTACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *s)
220280297Sjkim{
221280297Sjkim    if (s != NULL) {
222280297Sjkim        if (s->srtp_profiles != NULL) {
223280297Sjkim            return s->srtp_profiles;
224280297Sjkim        } else if ((s->ctx != NULL) && (s->ctx->srtp_profiles != NULL)) {
225280297Sjkim            return s->ctx->srtp_profiles;
226280297Sjkim        }
227280297Sjkim    }
228238384Sjkim
229280297Sjkim    return NULL;
230280297Sjkim}
231238384Sjkim
232238384SjkimSRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *s)
233280297Sjkim{
234280297Sjkim    return s->srtp_profile;
235280297Sjkim}
236238384Sjkim
237280297Sjkim/*
238280297Sjkim * Note: this function returns 0 length if there are no profiles specified
239280297Sjkim */
240280297Sjkimint ssl_add_clienthello_use_srtp_ext(SSL *s, unsigned char *p, int *len,
241280297Sjkim                                     int maxlen)
242280297Sjkim{
243280297Sjkim    int ct = 0;
244280297Sjkim    int i;
245280297Sjkim    STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = 0;
246280297Sjkim    SRTP_PROTECTION_PROFILE *prof;
247238384Sjkim
248280297Sjkim    clnt = SSL_get_srtp_profiles(s);
249280297Sjkim    ct = sk_SRTP_PROTECTION_PROFILE_num(clnt); /* -1 if clnt == 0 */
250238384Sjkim
251280297Sjkim    if (p) {
252280297Sjkim        if (ct == 0) {
253280297Sjkim            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT,
254280297Sjkim                   SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST);
255280297Sjkim            return 1;
256280297Sjkim        }
257238384Sjkim
258280297Sjkim        if ((2 + ct * 2 + 1) > maxlen) {
259280297Sjkim            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT,
260280297Sjkim                   SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG);
261280297Sjkim            return 1;
262280297Sjkim        }
263238384Sjkim
264280297Sjkim        /* Add the length */
265280297Sjkim        s2n(ct * 2, p);
266280297Sjkim        for (i = 0; i < ct; i++) {
267280297Sjkim            prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i);
268280297Sjkim            s2n(prof->id, p);
269280297Sjkim        }
270238384Sjkim
271280297Sjkim        /* Add an empty use_mki value */
272280297Sjkim        *p++ = 0;
273280297Sjkim    }
274238384Sjkim
275280297Sjkim    *len = 2 + ct * 2 + 1;
276238384Sjkim
277280297Sjkim    return 0;
278280297Sjkim}
279238384Sjkim
280280297Sjkimint ssl_parse_clienthello_use_srtp_ext(SSL *s, unsigned char *d, int len,
281280297Sjkim                                       int *al)
282280297Sjkim{
283280297Sjkim    SRTP_PROTECTION_PROFILE *sprof;
284280297Sjkim    STACK_OF(SRTP_PROTECTION_PROFILE) *srvr;
285280297Sjkim    int ct;
286280297Sjkim    int mki_len;
287280297Sjkim    int i, srtp_pref;
288280297Sjkim    unsigned int id;
289238384Sjkim
290280297Sjkim    /* Length value + the MKI length */
291280297Sjkim    if (len < 3) {
292280297Sjkim        SSLerr(SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT,
293280297Sjkim               SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
294280297Sjkim        *al = SSL_AD_DECODE_ERROR;
295280297Sjkim        return 1;
296280297Sjkim    }
297280297Sjkim
298280297Sjkim    /* Pull off the length of the cipher suite list */
299280297Sjkim    n2s(d, ct);
300280297Sjkim    len -= 2;
301280297Sjkim
302280297Sjkim    /* Check that it is even */
303280297Sjkim    if (ct % 2) {
304280297Sjkim        SSLerr(SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT,
305280297Sjkim               SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
306280297Sjkim        *al = SSL_AD_DECODE_ERROR;
307280297Sjkim        return 1;
308280297Sjkim    }
309280297Sjkim
310280297Sjkim    /* Check that lengths are consistent */
311280297Sjkim    if (len < (ct + 1)) {
312280297Sjkim        SSLerr(SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT,
313280297Sjkim               SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
314280297Sjkim        *al = SSL_AD_DECODE_ERROR;
315280297Sjkim        return 1;
316280297Sjkim    }
317280297Sjkim
318280297Sjkim    srvr = SSL_get_srtp_profiles(s);
319280297Sjkim    s->srtp_profile = NULL;
320280297Sjkim    /* Search all profiles for a match initially */
321280297Sjkim    srtp_pref = sk_SRTP_PROTECTION_PROFILE_num(srvr);
322280297Sjkim
323280297Sjkim    while (ct) {
324280297Sjkim        n2s(d, id);
325280297Sjkim        ct -= 2;
326238384Sjkim        len -= 2;
327238384Sjkim
328280297Sjkim        /*
329280297Sjkim         * Only look for match in profiles of higher preference than
330280297Sjkim         * current match.
331280297Sjkim         * If no profiles have been have been configured then this
332280297Sjkim         * does nothing.
333280297Sjkim         */
334280297Sjkim        for (i = 0; i < srtp_pref; i++) {
335280297Sjkim            sprof = sk_SRTP_PROTECTION_PROFILE_value(srvr, i);
336280297Sjkim            if (sprof->id == id) {
337280297Sjkim                s->srtp_profile = sprof;
338280297Sjkim                srtp_pref = i;
339280297Sjkim                break;
340280297Sjkim            }
341280297Sjkim        }
342280297Sjkim    }
343238384Sjkim
344280297Sjkim    /*
345280297Sjkim     * Now extract the MKI value as a sanity check, but discard it for now
346280297Sjkim     */
347280297Sjkim    mki_len = *d;
348280297Sjkim    d++;
349280297Sjkim    len--;
350238384Sjkim
351280297Sjkim    if (mki_len != len) {
352280297Sjkim        SSLerr(SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT,
353280297Sjkim               SSL_R_BAD_SRTP_MKI_VALUE);
354280297Sjkim        *al = SSL_AD_DECODE_ERROR;
355280297Sjkim        return 1;
356280297Sjkim    }
357238384Sjkim
358280297Sjkim    return 0;
359280297Sjkim}
360238384Sjkim
361280297Sjkimint ssl_add_serverhello_use_srtp_ext(SSL *s, unsigned char *p, int *len,
362280297Sjkim                                     int maxlen)
363280297Sjkim{
364280297Sjkim    if (p) {
365280297Sjkim        if (maxlen < 5) {
366280297Sjkim            SSLerr(SSL_F_SSL_ADD_SERVERHELLO_USE_SRTP_EXT,
367280297Sjkim                   SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG);
368280297Sjkim            return 1;
369280297Sjkim        }
370238384Sjkim
371280297Sjkim        if (s->srtp_profile == 0) {
372280297Sjkim            SSLerr(SSL_F_SSL_ADD_SERVERHELLO_USE_SRTP_EXT,
373280297Sjkim                   SSL_R_USE_SRTP_NOT_NEGOTIATED);
374280297Sjkim            return 1;
375280297Sjkim        }
376280297Sjkim        s2n(2, p);
377280297Sjkim        s2n(s->srtp_profile->id, p);
378280297Sjkim        *p++ = 0;
379280297Sjkim    }
380280297Sjkim    *len = 5;
381238384Sjkim
382280297Sjkim    return 0;
383280297Sjkim}
384238384Sjkim
385280297Sjkimint ssl_parse_serverhello_use_srtp_ext(SSL *s, unsigned char *d, int len,
386280297Sjkim                                       int *al)
387280297Sjkim{
388280297Sjkim    unsigned id;
389280297Sjkim    int i;
390280297Sjkim    int ct;
391238384Sjkim
392280297Sjkim    STACK_OF(SRTP_PROTECTION_PROFILE) *clnt;
393280297Sjkim    SRTP_PROTECTION_PROFILE *prof;
394238384Sjkim
395280297Sjkim    if (len != 5) {
396280297Sjkim        SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT,
397280297Sjkim               SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
398280297Sjkim        *al = SSL_AD_DECODE_ERROR;
399280297Sjkim        return 1;
400280297Sjkim    }
401238384Sjkim
402280297Sjkim    n2s(d, ct);
403280297Sjkim    if (ct != 2) {
404280297Sjkim        SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT,
405280297Sjkim               SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
406280297Sjkim        *al = SSL_AD_DECODE_ERROR;
407280297Sjkim        return 1;
408280297Sjkim    }
409238384Sjkim
410280297Sjkim    n2s(d, id);
411280297Sjkim    if (*d) {                   /* Must be no MKI, since we never offer one */
412280297Sjkim        SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT,
413280297Sjkim               SSL_R_BAD_SRTP_MKI_VALUE);
414280297Sjkim        *al = SSL_AD_ILLEGAL_PARAMETER;
415280297Sjkim        return 1;
416280297Sjkim    }
417238384Sjkim
418280297Sjkim    clnt = SSL_get_srtp_profiles(s);
419238384Sjkim
420280297Sjkim    /* Throw an error if the server gave us an unsolicited extension */
421280297Sjkim    if (clnt == NULL) {
422280297Sjkim        SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT,
423280297Sjkim               SSL_R_NO_SRTP_PROFILES);
424280297Sjkim        *al = SSL_AD_DECODE_ERROR;
425280297Sjkim        return 1;
426280297Sjkim    }
427238384Sjkim
428280297Sjkim    /*
429280297Sjkim     * Check to see if the server gave us something we support (and
430280297Sjkim     * presumably offered)
431280297Sjkim     */
432280297Sjkim    for (i = 0; i < sk_SRTP_PROTECTION_PROFILE_num(clnt); i++) {
433280297Sjkim        prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i);
434238384Sjkim
435280297Sjkim        if (prof->id == id) {
436280297Sjkim            s->srtp_profile = prof;
437280297Sjkim            *al = 0;
438280297Sjkim            return 0;
439280297Sjkim        }
440280297Sjkim    }
441238384Sjkim
442280297Sjkim    SSLerr(SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT,
443280297Sjkim           SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
444280297Sjkim    *al = SSL_AD_DECODE_ERROR;
445280297Sjkim    return 1;
446280297Sjkim}
447280297Sjkim
448238384Sjkim#endif
449