/src/rtpproxy/modules/dtls_gw/rtpp_dtls_util.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022 Sippy Software, Inc., http://www.sippysoft.com |
3 | | * |
4 | | * Redistribution and use in source and binary forms, with or without |
5 | | * modification, are permitted provided that the following conditions |
6 | | * are met: |
7 | | * 1. Redistributions of source code must retain the above copyright |
8 | | * notice, this list of conditions and the following disclaimer. |
9 | | * 2. Redistributions in binary form must reproduce the above copyright |
10 | | * notice, this list of conditions and the following disclaimer in the |
11 | | * documentation and/or other materials provided with the distribution. |
12 | | * |
13 | | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
14 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
16 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
17 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
19 | | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
20 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
21 | | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22 | | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
23 | | * SUCH DAMAGE. |
24 | | * |
25 | | */ |
26 | | |
27 | | #include <string.h> |
28 | | |
29 | | #include <openssl/ssl.h> |
30 | | #include <openssl/err.h> |
31 | | |
32 | | #include "rtpp_dtls_util.h" |
33 | | |
34 | | int |
35 | | rtpp_dtls_fp_gen(const X509 *cert, char *buf, int len) |
36 | 4 | { |
37 | 4 | uint8_t fp[FP_DIGEST_LEN] = {0}; |
38 | 4 | unsigned int fp_len, i; |
39 | | |
40 | 4 | if (len < FP_DIGEST_STRBUF_LEN) |
41 | 0 | return (-1); |
42 | 4 | fp_len = sizeof(fp); |
43 | 4 | if (X509_digest(cert, EVP_sha256(), fp, &fp_len) != 1) { |
44 | 0 | ERR_clear_error(); |
45 | 0 | return (-1); |
46 | 0 | } |
47 | 4 | memcpy(buf, FP_DIGEST_ALG, sizeof(FP_DIGEST_ALG) - 1); |
48 | 4 | buf += sizeof(FP_DIGEST_ALG) - 1; |
49 | 4 | buf[0] = ' '; |
50 | 4 | buf++; |
51 | 132 | for (i = 0; i < FP_DIGEST_LEN; i++) { |
52 | 128 | sprintf(buf, "%.2X", fp[i]); |
53 | 128 | buf += 2; |
54 | 128 | if (i != (FP_DIGEST_LEN - 1)) { |
55 | 124 | buf[0] = ':'; |
56 | 124 | buf++; |
57 | 124 | } |
58 | 128 | } |
59 | 4 | return (0); |
60 | 4 | } |