Add support for OpenSSL 1.0
[folly.git] / folly / portability / OpenSSL.cpp
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <folly/portability/OpenSSL.h>
17
18 namespace folly {
19 namespace ssl {
20
21 #ifdef OPENSSL_IS_BORINGSSL
22 int SSL_CTX_set1_sigalgs_list(SSL_CTX*, const char*) {
23   return 1; // 0 implies error
24 }
25
26 int TLS1_get_client_version(SSL* s) {
27   return s->client_version;
28 }
29
30 int BIO_meth_set_read(BIO_METHOD* biom, int (*read)(BIO*, char*, int)) {
31   biom->bread = read;
32   return 1;
33 }
34
35 int BIO_meth_set_write(BIO_METHOD* biom, int (*write)(BIO*, const char*, int)) {
36   biom->bwrite = write;
37   return 1;
38 }
39
40 #elif FOLLY_OPENSSL_IS_102 || FOLLY_OPENSSL_IS_101 || FOLLY_OPENSSL_IS_100
41
42 #if FOLLY_OPENSSL_IS_100
43 uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *c) {
44   return c->id;
45 }
46
47 int TLS1_get_client_version(const SSL* s) {
48   return (s->client_version >> 8) == TLS1_VERSION_MAJOR ? s->client_version : 0;
49 }
50
51 #endif
52
53 int SSL_CTX_up_ref(SSL_CTX* ctx) {
54   return CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);
55 }
56
57 int SSL_SESSION_up_ref(SSL_SESSION* session) {
58   return CRYPTO_add(&session->references, 1, CRYPTO_LOCK_SSL_SESSION);
59 }
60
61 int X509_up_ref(X509* x) {
62   return CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
63 }
64
65 int BIO_meth_set_read(BIO_METHOD* biom, int (*read)(BIO*, char*, int)) {
66   biom->bread = read;
67   return 1;
68 }
69
70 int BIO_meth_set_write(BIO_METHOD* biom, int (*write)(BIO*, const char*, int)) {
71   biom->bwrite = write;
72   return 1;
73 }
74
75 #elif FOLLY_OPENSSL_IS_110
76
77 #endif
78 }
79 }