cya_u
Fork of CyaSSL-forEncrypt by
ssl.c@2:d0516dc143b1, 2017-05-10 (annotated)
- Committer:
- vbahl2
- Date:
- Wed May 10 18:20:47 2017 +0000
- Revision:
- 2:d0516dc143b1
- Parent:
- 0:5045d2638c29
updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
toddouska | 0:5045d2638c29 | 1 | /* ssl.c |
toddouska | 0:5045d2638c29 | 2 | * |
toddouska | 0:5045d2638c29 | 3 | * Copyright (C) 2006-2009 Sawtooth Consulting Ltd. |
toddouska | 0:5045d2638c29 | 4 | * |
toddouska | 0:5045d2638c29 | 5 | * This file is part of CyaSSL. |
toddouska | 0:5045d2638c29 | 6 | * |
toddouska | 0:5045d2638c29 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
toddouska | 0:5045d2638c29 | 8 | * it under the terms of the GNU General Public License as published by |
toddouska | 0:5045d2638c29 | 9 | * the Free Software Foundation; either version 2 of the License, or |
toddouska | 0:5045d2638c29 | 10 | * (at your option) any later version. |
toddouska | 0:5045d2638c29 | 11 | * |
toddouska | 0:5045d2638c29 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
toddouska | 0:5045d2638c29 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
toddouska | 0:5045d2638c29 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
toddouska | 0:5045d2638c29 | 15 | * GNU General Public License for more details. |
toddouska | 0:5045d2638c29 | 16 | * |
toddouska | 0:5045d2638c29 | 17 | * You should have received a copy of the GNU General Public License |
toddouska | 0:5045d2638c29 | 18 | * along with this program; if not, write to the Free Software |
toddouska | 0:5045d2638c29 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
toddouska | 0:5045d2638c29 | 20 | */ |
toddouska | 0:5045d2638c29 | 21 | |
toddouska | 0:5045d2638c29 | 22 | |
toddouska | 0:5045d2638c29 | 23 | #include "ssl.h" |
toddouska | 0:5045d2638c29 | 24 | #include "cyassl_int.h" |
toddouska | 0:5045d2638c29 | 25 | #include "cyassl_error.h" |
toddouska | 0:5045d2638c29 | 26 | #include "coding.h" |
toddouska | 0:5045d2638c29 | 27 | |
toddouska | 0:5045d2638c29 | 28 | #ifdef OPENSSL_EXTRA |
toddouska | 0:5045d2638c29 | 29 | /* openssl headers begin */ |
toddouska | 0:5045d2638c29 | 30 | #include "evp.h" |
toddouska | 0:5045d2638c29 | 31 | #include "hmac.h" |
toddouska | 0:5045d2638c29 | 32 | #include "crypto.h" |
toddouska | 0:5045d2638c29 | 33 | #include "des.h" |
toddouska | 0:5045d2638c29 | 34 | /* openssl headers end, cyassl internal headers next */ |
toddouska | 0:5045d2638c29 | 35 | #include "ctc_hmac.h" |
toddouska | 0:5045d2638c29 | 36 | #include "random.h" |
toddouska | 0:5045d2638c29 | 37 | #include "des3.h" |
toddouska | 0:5045d2638c29 | 38 | #include "ctc_md4.h" |
toddouska | 0:5045d2638c29 | 39 | #include "coding.h" |
toddouska | 0:5045d2638c29 | 40 | #endif |
toddouska | 0:5045d2638c29 | 41 | |
toddouska | 0:5045d2638c29 | 42 | #ifdef HAVE_ERRNO_H |
toddouska | 0:5045d2638c29 | 43 | #include <errno.h> |
toddouska | 0:5045d2638c29 | 44 | #endif |
toddouska | 0:5045d2638c29 | 45 | |
toddouska | 0:5045d2638c29 | 46 | #define TRUE 1 |
toddouska | 0:5045d2638c29 | 47 | #define FALSE 0 |
toddouska | 0:5045d2638c29 | 48 | |
toddouska | 0:5045d2638c29 | 49 | |
toddouska | 0:5045d2638c29 | 50 | #ifndef min |
toddouska | 0:5045d2638c29 | 51 | |
toddouska | 0:5045d2638c29 | 52 | static INLINE word32 min(word32 a, word32 b) |
toddouska | 0:5045d2638c29 | 53 | { |
toddouska | 0:5045d2638c29 | 54 | return a > b ? b : a; |
toddouska | 0:5045d2638c29 | 55 | } |
toddouska | 0:5045d2638c29 | 56 | |
toddouska | 0:5045d2638c29 | 57 | #endif /* min */ |
toddouska | 0:5045d2638c29 | 58 | |
toddouska | 0:5045d2638c29 | 59 | |
toddouska | 0:5045d2638c29 | 60 | |
toddouska | 0:5045d2638c29 | 61 | SSL_CTX* SSL_CTX_new(SSL_METHOD* method) |
toddouska | 0:5045d2638c29 | 62 | { |
toddouska | 0:5045d2638c29 | 63 | SSL_CTX* ctx = (SSL_CTX*) XMALLOC(sizeof(SSL_CTX), 0, DYNAMIC_TYPE_CTX); |
toddouska | 0:5045d2638c29 | 64 | if (ctx) |
toddouska | 0:5045d2638c29 | 65 | InitSSL_Ctx(ctx, method); |
toddouska | 0:5045d2638c29 | 66 | |
toddouska | 0:5045d2638c29 | 67 | return ctx; |
toddouska | 0:5045d2638c29 | 68 | } |
toddouska | 0:5045d2638c29 | 69 | |
toddouska | 0:5045d2638c29 | 70 | |
toddouska | 0:5045d2638c29 | 71 | void SSL_CTX_free(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 72 | { |
toddouska | 0:5045d2638c29 | 73 | if (ctx) |
toddouska | 0:5045d2638c29 | 74 | FreeSSL_Ctx(ctx); |
toddouska | 0:5045d2638c29 | 75 | } |
toddouska | 0:5045d2638c29 | 76 | |
toddouska | 0:5045d2638c29 | 77 | |
toddouska | 0:5045d2638c29 | 78 | SSL* SSL_new(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 79 | { |
toddouska | 0:5045d2638c29 | 80 | |
toddouska | 0:5045d2638c29 | 81 | SSL* ssl = (SSL*) XMALLOC(sizeof(SSL), ctx->heap, DYNAMIC_TYPE_SSL); |
toddouska | 0:5045d2638c29 | 82 | if (ssl) |
toddouska | 0:5045d2638c29 | 83 | if (InitSSL(ssl, ctx) < 0) { |
toddouska | 0:5045d2638c29 | 84 | FreeSSL(ssl); |
toddouska | 0:5045d2638c29 | 85 | ssl = 0; |
toddouska | 0:5045d2638c29 | 86 | } |
toddouska | 0:5045d2638c29 | 87 | |
toddouska | 0:5045d2638c29 | 88 | return ssl; |
toddouska | 0:5045d2638c29 | 89 | } |
toddouska | 0:5045d2638c29 | 90 | |
toddouska | 0:5045d2638c29 | 91 | |
toddouska | 0:5045d2638c29 | 92 | void SSL_free(SSL* ssl) |
toddouska | 0:5045d2638c29 | 93 | { |
toddouska | 0:5045d2638c29 | 94 | CYASSL_ENTER("SSL_free"); |
toddouska | 0:5045d2638c29 | 95 | if (ssl) |
toddouska | 0:5045d2638c29 | 96 | FreeSSL(ssl); |
toddouska | 0:5045d2638c29 | 97 | CYASSL_LEAVE("SSL_free", 0); |
toddouska | 0:5045d2638c29 | 98 | } |
toddouska | 0:5045d2638c29 | 99 | |
toddouska | 0:5045d2638c29 | 100 | |
toddouska | 0:5045d2638c29 | 101 | int SSL_set_fd(SSL* ssl, int fd) |
toddouska | 0:5045d2638c29 | 102 | { |
toddouska | 0:5045d2638c29 | 103 | ssl->rfd = fd; /* not used directly to allow IO callbacks */ |
toddouska | 0:5045d2638c29 | 104 | ssl->wfd = fd; |
toddouska | 0:5045d2638c29 | 105 | |
toddouska | 0:5045d2638c29 | 106 | ssl->IOCB_ReadCtx = &ssl->rfd; |
toddouska | 0:5045d2638c29 | 107 | ssl->IOCB_WriteCtx = &ssl->wfd; |
toddouska | 0:5045d2638c29 | 108 | |
toddouska | 0:5045d2638c29 | 109 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 110 | } |
toddouska | 0:5045d2638c29 | 111 | |
toddouska | 0:5045d2638c29 | 112 | |
toddouska | 0:5045d2638c29 | 113 | int SSL_get_fd(const SSL* ssl) |
toddouska | 0:5045d2638c29 | 114 | { |
toddouska | 0:5045d2638c29 | 115 | return ssl->rfd; |
toddouska | 0:5045d2638c29 | 116 | } |
toddouska | 0:5045d2638c29 | 117 | |
toddouska | 0:5045d2638c29 | 118 | |
toddouska | 0:5045d2638c29 | 119 | int CyaSSL_negotiate(SSL* ssl) |
toddouska | 0:5045d2638c29 | 120 | { |
toddouska | 0:5045d2638c29 | 121 | int err = -1; |
toddouska | 0:5045d2638c29 | 122 | |
toddouska | 0:5045d2638c29 | 123 | #ifndef NO_CYASSL_SERVER |
toddouska | 0:5045d2638c29 | 124 | if (ssl->options.side == SERVER_END) |
toddouska | 0:5045d2638c29 | 125 | err = SSL_accept(ssl); |
toddouska | 0:5045d2638c29 | 126 | #endif |
toddouska | 0:5045d2638c29 | 127 | |
toddouska | 0:5045d2638c29 | 128 | #ifndef NO_CYASSL_CLIENT |
toddouska | 0:5045d2638c29 | 129 | if (ssl->options.side == CLIENT_END) |
toddouska | 0:5045d2638c29 | 130 | err = SSL_connect(ssl); |
toddouska | 0:5045d2638c29 | 131 | #endif |
toddouska | 0:5045d2638c29 | 132 | |
toddouska | 0:5045d2638c29 | 133 | if (err == SSL_SUCCESS) |
toddouska | 0:5045d2638c29 | 134 | return 0; |
toddouska | 0:5045d2638c29 | 135 | else |
toddouska | 0:5045d2638c29 | 136 | return err; |
toddouska | 0:5045d2638c29 | 137 | } |
toddouska | 0:5045d2638c29 | 138 | |
toddouska | 0:5045d2638c29 | 139 | |
toddouska | 0:5045d2638c29 | 140 | int SSL_write(SSL* ssl, const void* buffer, int sz) |
toddouska | 0:5045d2638c29 | 141 | { |
toddouska | 0:5045d2638c29 | 142 | int ret; |
toddouska | 0:5045d2638c29 | 143 | |
toddouska | 0:5045d2638c29 | 144 | CYASSL_ENTER("SSL_write()"); |
toddouska | 0:5045d2638c29 | 145 | |
toddouska | 0:5045d2638c29 | 146 | #ifdef HAVE_ERRNO_H |
toddouska | 0:5045d2638c29 | 147 | errno = 0; |
toddouska | 0:5045d2638c29 | 148 | #endif |
toddouska | 0:5045d2638c29 | 149 | |
toddouska | 0:5045d2638c29 | 150 | ret = SendData(ssl, buffer, sz); |
toddouska | 0:5045d2638c29 | 151 | |
toddouska | 0:5045d2638c29 | 152 | CYASSL_LEAVE("SSL_write()", ret); |
toddouska | 0:5045d2638c29 | 153 | |
toddouska | 0:5045d2638c29 | 154 | if (ret < 0) |
toddouska | 0:5045d2638c29 | 155 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 156 | else |
toddouska | 0:5045d2638c29 | 157 | return ret; |
toddouska | 0:5045d2638c29 | 158 | } |
toddouska | 0:5045d2638c29 | 159 | |
toddouska | 0:5045d2638c29 | 160 | |
toddouska | 0:5045d2638c29 | 161 | int SSL_read(SSL* ssl, void* buffer, int sz) |
toddouska | 0:5045d2638c29 | 162 | { |
toddouska | 0:5045d2638c29 | 163 | int ret; |
toddouska | 0:5045d2638c29 | 164 | |
toddouska | 0:5045d2638c29 | 165 | CYASSL_ENTER("SSL_read()"); |
toddouska | 0:5045d2638c29 | 166 | |
toddouska | 0:5045d2638c29 | 167 | #ifdef HAVE_ERRNO_H |
toddouska | 0:5045d2638c29 | 168 | errno = 0; |
toddouska | 0:5045d2638c29 | 169 | #endif |
toddouska | 0:5045d2638c29 | 170 | |
toddouska | 0:5045d2638c29 | 171 | ret = ReceiveData(ssl, (byte*)buffer, min(sz, OUTPUT_RECORD_SIZE)); |
toddouska | 0:5045d2638c29 | 172 | |
toddouska | 0:5045d2638c29 | 173 | CYASSL_LEAVE("SSL_read()", ret); |
toddouska | 0:5045d2638c29 | 174 | |
toddouska | 0:5045d2638c29 | 175 | if (ret < 0) |
toddouska | 0:5045d2638c29 | 176 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 177 | else |
toddouska | 0:5045d2638c29 | 178 | return ret; |
toddouska | 0:5045d2638c29 | 179 | } |
toddouska | 0:5045d2638c29 | 180 | |
toddouska | 0:5045d2638c29 | 181 | |
toddouska | 0:5045d2638c29 | 182 | int SSL_shutdown(SSL* ssl) |
toddouska | 0:5045d2638c29 | 183 | { |
toddouska | 0:5045d2638c29 | 184 | CYASSL_ENTER("SSL_shutdown()"); |
toddouska | 0:5045d2638c29 | 185 | |
toddouska | 0:5045d2638c29 | 186 | if (ssl->options.quietShutdown) { |
toddouska | 0:5045d2638c29 | 187 | CYASSL_MSG("quiet shutdown, no close notify sent"); |
toddouska | 0:5045d2638c29 | 188 | return 0; |
toddouska | 0:5045d2638c29 | 189 | } |
toddouska | 0:5045d2638c29 | 190 | |
toddouska | 0:5045d2638c29 | 191 | /* try to send close notify, not an error if can't */ |
toddouska | 0:5045d2638c29 | 192 | if (!ssl->options.isClosed && !ssl->options.connReset && |
toddouska | 0:5045d2638c29 | 193 | !ssl->options.sentNotify) { |
toddouska | 0:5045d2638c29 | 194 | ssl->error = SendAlert(ssl, alert_warning, close_notify); |
toddouska | 0:5045d2638c29 | 195 | if (ssl->error < 0) { |
toddouska | 0:5045d2638c29 | 196 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 197 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 198 | } |
toddouska | 0:5045d2638c29 | 199 | ssl->options.sentNotify = 1; /* don't send close_notify twice */ |
toddouska | 0:5045d2638c29 | 200 | } |
toddouska | 0:5045d2638c29 | 201 | |
toddouska | 0:5045d2638c29 | 202 | CYASSL_LEAVE("SSL_shutdown()", ssl->error); |
toddouska | 0:5045d2638c29 | 203 | |
toddouska | 0:5045d2638c29 | 204 | ssl->error = SSL_ERROR_SYSCALL; /* simulate OpenSSL behavior */ |
toddouska | 0:5045d2638c29 | 205 | |
toddouska | 0:5045d2638c29 | 206 | return 0; |
toddouska | 0:5045d2638c29 | 207 | } |
toddouska | 0:5045d2638c29 | 208 | |
toddouska | 0:5045d2638c29 | 209 | |
toddouska | 0:5045d2638c29 | 210 | int SSL_get_error(SSL* ssl, int dummy) |
toddouska | 0:5045d2638c29 | 211 | { |
toddouska | 0:5045d2638c29 | 212 | if (ssl->error == WANT_READ) |
toddouska | 0:5045d2638c29 | 213 | return SSL_ERROR_WANT_READ; /* convert to OpenSSL type */ |
toddouska | 0:5045d2638c29 | 214 | else if (ssl->error == WANT_WRITE) |
toddouska | 0:5045d2638c29 | 215 | return SSL_ERROR_WANT_WRITE; /* convert to OpenSSL type */ |
toddouska | 0:5045d2638c29 | 216 | else if (ssl->error == ZERO_RETURN) |
toddouska | 0:5045d2638c29 | 217 | return SSL_ERROR_ZERO_RETURN; /* convert to OpenSSL type */ |
toddouska | 0:5045d2638c29 | 218 | return ssl->error; |
toddouska | 0:5045d2638c29 | 219 | } |
toddouska | 0:5045d2638c29 | 220 | |
toddouska | 0:5045d2638c29 | 221 | |
toddouska | 0:5045d2638c29 | 222 | int SSL_want_read(SSL* ssl) |
toddouska | 0:5045d2638c29 | 223 | { |
toddouska | 0:5045d2638c29 | 224 | if (ssl->error == WANT_READ) |
toddouska | 0:5045d2638c29 | 225 | return 1; |
toddouska | 0:5045d2638c29 | 226 | |
toddouska | 0:5045d2638c29 | 227 | return 0; |
toddouska | 0:5045d2638c29 | 228 | } |
toddouska | 0:5045d2638c29 | 229 | |
toddouska | 0:5045d2638c29 | 230 | |
toddouska | 0:5045d2638c29 | 231 | int SSL_want_write(SSL* ssl) |
toddouska | 0:5045d2638c29 | 232 | { |
toddouska | 0:5045d2638c29 | 233 | if (ssl->error == WANT_WRITE) |
toddouska | 0:5045d2638c29 | 234 | return 1; |
toddouska | 0:5045d2638c29 | 235 | |
toddouska | 0:5045d2638c29 | 236 | return 0; |
toddouska | 0:5045d2638c29 | 237 | } |
toddouska | 0:5045d2638c29 | 238 | |
toddouska | 0:5045d2638c29 | 239 | |
toddouska | 0:5045d2638c29 | 240 | char* ERR_error_string(unsigned long errNumber, char* buffer) |
toddouska | 0:5045d2638c29 | 241 | { |
toddouska | 0:5045d2638c29 | 242 | static char* msg = "Please supply a buffer for error string"; |
toddouska | 0:5045d2638c29 | 243 | |
toddouska | 0:5045d2638c29 | 244 | if (buffer) { |
toddouska | 0:5045d2638c29 | 245 | SetErrorString(errNumber, buffer); |
toddouska | 0:5045d2638c29 | 246 | return buffer; |
toddouska | 0:5045d2638c29 | 247 | } |
toddouska | 0:5045d2638c29 | 248 | |
toddouska | 0:5045d2638c29 | 249 | return msg; |
toddouska | 0:5045d2638c29 | 250 | } |
toddouska | 0:5045d2638c29 | 251 | |
toddouska | 0:5045d2638c29 | 252 | |
toddouska | 0:5045d2638c29 | 253 | void ERR_error_string_n(unsigned long e, char* buf, size_t len) |
toddouska | 0:5045d2638c29 | 254 | { |
toddouska | 0:5045d2638c29 | 255 | if (len) ERR_error_string(e, buf); |
toddouska | 0:5045d2638c29 | 256 | } |
toddouska | 0:5045d2638c29 | 257 | |
toddouska | 0:5045d2638c29 | 258 | |
toddouska | 0:5045d2638c29 | 259 | #ifndef NO_FILESYSTEM |
toddouska | 0:5045d2638c29 | 260 | |
toddouska | 0:5045d2638c29 | 261 | void ERR_print_errors_fp(FILE* fp, int err) |
toddouska | 0:5045d2638c29 | 262 | { |
toddouska | 0:5045d2638c29 | 263 | char buffer[MAX_ERROR_SZ + 1]; |
toddouska | 0:5045d2638c29 | 264 | |
toddouska | 0:5045d2638c29 | 265 | SetErrorString(err, buffer); |
toddouska | 0:5045d2638c29 | 266 | fprintf(fp, "%s", buffer); |
toddouska | 0:5045d2638c29 | 267 | } |
toddouska | 0:5045d2638c29 | 268 | |
toddouska | 0:5045d2638c29 | 269 | #endif |
toddouska | 0:5045d2638c29 | 270 | |
toddouska | 0:5045d2638c29 | 271 | |
toddouska | 0:5045d2638c29 | 272 | int SSL_pending(SSL* ssl) |
toddouska | 0:5045d2638c29 | 273 | { |
toddouska | 0:5045d2638c29 | 274 | return ssl->buffers.clearOutputBuffer.length; |
toddouska | 0:5045d2638c29 | 275 | } |
toddouska | 0:5045d2638c29 | 276 | |
toddouska | 0:5045d2638c29 | 277 | |
toddouska | 0:5045d2638c29 | 278 | /* owns der */ |
toddouska | 0:5045d2638c29 | 279 | static int AddCA(SSL_CTX* ctx, buffer der) |
toddouska | 0:5045d2638c29 | 280 | { |
toddouska | 0:5045d2638c29 | 281 | word32 ret; |
toddouska | 0:5045d2638c29 | 282 | DecodedCert cert; |
toddouska | 0:5045d2638c29 | 283 | Signer* signer = 0; |
toddouska | 0:5045d2638c29 | 284 | |
toddouska | 0:5045d2638c29 | 285 | InitDecodedCert(&cert, der.buffer, ctx->heap); |
toddouska | 0:5045d2638c29 | 286 | ret = ParseCert(&cert, der.length, CA_TYPE, ctx->verifyPeer, 0); |
toddouska | 0:5045d2638c29 | 287 | |
toddouska | 0:5045d2638c29 | 288 | if (ret == 0) { |
toddouska | 0:5045d2638c29 | 289 | /* take over signer parts */ |
toddouska | 0:5045d2638c29 | 290 | signer = MakeSigner(ctx->heap); |
toddouska | 0:5045d2638c29 | 291 | if (!signer) |
toddouska | 0:5045d2638c29 | 292 | ret = MEMORY_ERROR; |
toddouska | 0:5045d2638c29 | 293 | else { |
toddouska | 0:5045d2638c29 | 294 | signer->keyOID = cert.keyOID; |
toddouska | 0:5045d2638c29 | 295 | signer->publicKey = cert.publicKey; |
toddouska | 0:5045d2638c29 | 296 | signer->pubKeySize = cert.pubKeySize; |
toddouska | 0:5045d2638c29 | 297 | signer->name = cert.subjectCN; |
toddouska | 0:5045d2638c29 | 298 | XMEMCPY(signer->hash, cert.subjectHash, SHA_DIGEST_SIZE); |
toddouska | 0:5045d2638c29 | 299 | |
toddouska | 0:5045d2638c29 | 300 | cert.publicKey = 0; /* don't free here */ |
toddouska | 0:5045d2638c29 | 301 | cert.subjectCN = 0; |
toddouska | 0:5045d2638c29 | 302 | |
toddouska | 0:5045d2638c29 | 303 | signer->next = ctx->caList; |
toddouska | 0:5045d2638c29 | 304 | ctx->caList = signer; /* takes ownership */ |
toddouska | 0:5045d2638c29 | 305 | } |
toddouska | 0:5045d2638c29 | 306 | } |
toddouska | 0:5045d2638c29 | 307 | |
toddouska | 0:5045d2638c29 | 308 | FreeDecodedCert(&cert); |
toddouska | 0:5045d2638c29 | 309 | XFREE(der.buffer, ctx->heap, DYNAMIC_TYPE_CA); |
toddouska | 0:5045d2638c29 | 310 | |
toddouska | 0:5045d2638c29 | 311 | if (ret == 0) return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 312 | return ret; |
toddouska | 0:5045d2638c29 | 313 | } |
toddouska | 0:5045d2638c29 | 314 | |
toddouska | 0:5045d2638c29 | 315 | |
toddouska | 0:5045d2638c29 | 316 | #ifndef NO_SESSION_CACHE |
toddouska | 0:5045d2638c29 | 317 | |
toddouska | 0:5045d2638c29 | 318 | /* basic config gives a cache with 33 sessions, adequate for clients and |
toddouska | 0:5045d2638c29 | 319 | embedded servers |
toddouska | 0:5045d2638c29 | 320 | |
toddouska | 0:5045d2638c29 | 321 | BIG_SESSION_CACHE allows 1055 sessions, adequate for servers that aren't |
toddouska | 0:5045d2638c29 | 322 | under heavy load, basically allows 200 new sessions per minute |
toddouska | 0:5045d2638c29 | 323 | |
toddouska | 0:5045d2638c29 | 324 | HUGE_SESSION_CACHE yields 65,791 sessions, for servers under heavy load, |
toddouska | 0:5045d2638c29 | 325 | allows over 13,000 new sessions per minute or over 200 new sessions per |
toddouska | 0:5045d2638c29 | 326 | second |
toddouska | 0:5045d2638c29 | 327 | */ |
toddouska | 0:5045d2638c29 | 328 | #ifdef HUGE_SESSION_CACHE |
toddouska | 0:5045d2638c29 | 329 | #define SESSIONS_PER_ROW 11 |
toddouska | 0:5045d2638c29 | 330 | #define SESSION_ROWS 5981 |
toddouska | 0:5045d2638c29 | 331 | #elif defined(BIG_SESSION_CACHE) |
toddouska | 0:5045d2638c29 | 332 | #define SESSIONS_PER_ROW 5 |
toddouska | 0:5045d2638c29 | 333 | #define SESSION_ROWS 211 |
toddouska | 0:5045d2638c29 | 334 | #else |
toddouska | 0:5045d2638c29 | 335 | #define SESSIONS_PER_ROW 3 |
toddouska | 0:5045d2638c29 | 336 | #define SESSION_ROWS 11 |
toddouska | 0:5045d2638c29 | 337 | #endif |
toddouska | 0:5045d2638c29 | 338 | |
toddouska | 0:5045d2638c29 | 339 | typedef struct SessionRow { |
toddouska | 0:5045d2638c29 | 340 | int nextIdx; /* where to place next one */ |
toddouska | 0:5045d2638c29 | 341 | int totalCount; /* sessions ever on this row */ |
toddouska | 0:5045d2638c29 | 342 | SSL_SESSION Sessions[SESSIONS_PER_ROW]; |
toddouska | 0:5045d2638c29 | 343 | } SessionRow; |
toddouska | 0:5045d2638c29 | 344 | |
toddouska | 0:5045d2638c29 | 345 | static SessionRow SessionCache[SESSION_ROWS]; |
toddouska | 0:5045d2638c29 | 346 | |
toddouska | 0:5045d2638c29 | 347 | static CyaSSL_Mutex mutex; /* SessionCache mutex */ |
toddouska | 0:5045d2638c29 | 348 | |
toddouska | 0:5045d2638c29 | 349 | #endif /* NO_SESSION_CACHE */ |
toddouska | 0:5045d2638c29 | 350 | |
toddouska | 0:5045d2638c29 | 351 | |
toddouska | 0:5045d2638c29 | 352 | static int PemToDer(const unsigned char* buff, long sz, int type, |
toddouska | 0:5045d2638c29 | 353 | buffer* der, void* heap, EncryptedInfo* info) |
toddouska | 0:5045d2638c29 | 354 | { |
toddouska | 0:5045d2638c29 | 355 | char header[PEM_LINE_LEN]; |
toddouska | 0:5045d2638c29 | 356 | char footer[PEM_LINE_LEN]; |
toddouska | 0:5045d2638c29 | 357 | char* headerEnd; |
toddouska | 0:5045d2638c29 | 358 | char* footerEnd; |
toddouska | 0:5045d2638c29 | 359 | long neededSz; |
toddouska | 0:5045d2638c29 | 360 | int pkcs8 = 0; |
toddouska | 0:5045d2638c29 | 361 | int dynamicType; |
toddouska | 0:5045d2638c29 | 362 | |
toddouska | 0:5045d2638c29 | 363 | if (type == CERT_TYPE || type == CA_TYPE) { |
toddouska | 0:5045d2638c29 | 364 | XSTRNCPY(header, "-----BEGIN CERTIFICATE-----", sizeof(header)); |
toddouska | 0:5045d2638c29 | 365 | XSTRNCPY(footer, "-----END CERTIFICATE-----", sizeof(footer)); |
toddouska | 0:5045d2638c29 | 366 | dynamicType = (type == CA_TYPE) ? DYNAMIC_TYPE_CA : |
toddouska | 0:5045d2638c29 | 367 | DYNAMIC_TYPE_CERT; |
toddouska | 0:5045d2638c29 | 368 | } else { |
toddouska | 0:5045d2638c29 | 369 | XSTRNCPY(header, "-----BEGIN RSA PRIVATE KEY-----", sizeof(header)); |
toddouska | 0:5045d2638c29 | 370 | XSTRNCPY(footer, "-----END RSA PRIVATE KEY-----", sizeof(footer)); |
toddouska | 0:5045d2638c29 | 371 | dynamicType = DYNAMIC_TYPE_KEY; |
toddouska | 0:5045d2638c29 | 372 | } |
toddouska | 0:5045d2638c29 | 373 | |
toddouska | 0:5045d2638c29 | 374 | /* find header */ |
toddouska | 0:5045d2638c29 | 375 | headerEnd = XSTRSTR((char*)buff, header); |
toddouska | 0:5045d2638c29 | 376 | if (!headerEnd && type == PRIVATEKEY_TYPE) { /* may be pkcs8 */ |
toddouska | 0:5045d2638c29 | 377 | XSTRNCPY(header, "-----BEGIN PRIVATE KEY-----", sizeof(header)); |
toddouska | 0:5045d2638c29 | 378 | XSTRNCPY(footer, "-----END PRIVATE KEY-----", sizeof(footer)); |
toddouska | 0:5045d2638c29 | 379 | |
toddouska | 0:5045d2638c29 | 380 | headerEnd = XSTRSTR((char*)buff, header); |
toddouska | 0:5045d2638c29 | 381 | if (headerEnd) |
toddouska | 0:5045d2638c29 | 382 | pkcs8 = 1; |
toddouska | 0:5045d2638c29 | 383 | /* |
toddouska | 0:5045d2638c29 | 384 | else |
toddouska | 0:5045d2638c29 | 385 | maybe encrypted "-----BEGIN ENCRYPTED PRIVATE KEY-----" |
toddouska | 0:5045d2638c29 | 386 | */ |
toddouska | 0:5045d2638c29 | 387 | } |
toddouska | 0:5045d2638c29 | 388 | if (!headerEnd) |
toddouska | 0:5045d2638c29 | 389 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 390 | headerEnd += XSTRLEN(header); |
toddouska | 0:5045d2638c29 | 391 | |
toddouska | 0:5045d2638c29 | 392 | /* get next line */ |
toddouska | 0:5045d2638c29 | 393 | if (headerEnd[0] == '\n') |
toddouska | 0:5045d2638c29 | 394 | headerEnd++; |
toddouska | 0:5045d2638c29 | 395 | else if (headerEnd[1] == '\n') |
toddouska | 0:5045d2638c29 | 396 | headerEnd += 2; |
toddouska | 0:5045d2638c29 | 397 | else |
toddouska | 0:5045d2638c29 | 398 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 399 | |
toddouska | 0:5045d2638c29 | 400 | #ifdef OPENSSL_EXTRA |
toddouska | 0:5045d2638c29 | 401 | { |
toddouska | 0:5045d2638c29 | 402 | /* remove encrypted header if there */ |
toddouska | 0:5045d2638c29 | 403 | char encHeader[] = "Proc-Type"; |
toddouska | 0:5045d2638c29 | 404 | char* line = XSTRSTR((char*)buff, encHeader); |
toddouska | 0:5045d2638c29 | 405 | if (line) { |
toddouska | 0:5045d2638c29 | 406 | char* newline; |
toddouska | 0:5045d2638c29 | 407 | char* finish; |
toddouska | 0:5045d2638c29 | 408 | char* start = XSTRSTR(line, "DES"); |
toddouska | 0:5045d2638c29 | 409 | |
toddouska | 0:5045d2638c29 | 410 | if (!start) |
toddouska | 0:5045d2638c29 | 411 | start = XSTRSTR(line, "AES"); |
toddouska | 0:5045d2638c29 | 412 | |
toddouska | 0:5045d2638c29 | 413 | if (!start) return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 414 | if (!info) return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 415 | |
toddouska | 0:5045d2638c29 | 416 | finish = XSTRSTR(start, ","); |
toddouska | 0:5045d2638c29 | 417 | |
toddouska | 0:5045d2638c29 | 418 | if (start && finish && (start < finish)) { |
toddouska | 0:5045d2638c29 | 419 | newline = XSTRSTR(finish, "\r"); |
toddouska | 0:5045d2638c29 | 420 | |
toddouska | 0:5045d2638c29 | 421 | XMEMCPY(info->name, start, finish - start); |
toddouska | 0:5045d2638c29 | 422 | info->name[finish - start] = 0; |
toddouska | 0:5045d2638c29 | 423 | XMEMCPY(info->iv, finish + 1, sizeof(info->iv)); |
toddouska | 0:5045d2638c29 | 424 | |
toddouska | 0:5045d2638c29 | 425 | if (!newline) newline = XSTRSTR(finish, "\n"); |
toddouska | 0:5045d2638c29 | 426 | if (newline && (newline > finish)) { |
toddouska | 0:5045d2638c29 | 427 | info->ivSz = (word32)(newline - (finish + 1)); |
toddouska | 0:5045d2638c29 | 428 | info->set = 1; |
toddouska | 0:5045d2638c29 | 429 | } |
toddouska | 0:5045d2638c29 | 430 | else |
toddouska | 0:5045d2638c29 | 431 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 432 | } |
toddouska | 0:5045d2638c29 | 433 | else |
toddouska | 0:5045d2638c29 | 434 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 435 | |
toddouska | 0:5045d2638c29 | 436 | /* eat blank line */ |
toddouska | 0:5045d2638c29 | 437 | while (*newline == '\r' || *newline == '\n') |
toddouska | 0:5045d2638c29 | 438 | newline++; |
toddouska | 0:5045d2638c29 | 439 | headerEnd = newline; |
toddouska | 0:5045d2638c29 | 440 | } |
toddouska | 0:5045d2638c29 | 441 | } |
toddouska | 0:5045d2638c29 | 442 | #endif /* OPENSSL_EXTRA */ |
toddouska | 0:5045d2638c29 | 443 | |
toddouska | 0:5045d2638c29 | 444 | /* find footer */ |
toddouska | 0:5045d2638c29 | 445 | footerEnd = XSTRSTR((char*)buff, footer); |
toddouska | 0:5045d2638c29 | 446 | if (!footerEnd) return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 447 | |
toddouska | 0:5045d2638c29 | 448 | /* set up der buffer */ |
toddouska | 0:5045d2638c29 | 449 | neededSz = (long)(footerEnd - headerEnd); |
toddouska | 0:5045d2638c29 | 450 | if (neededSz > sz || neededSz < 0) return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 451 | der->buffer = (byte*) XMALLOC(neededSz, heap, dynamicType); |
toddouska | 0:5045d2638c29 | 452 | if (!der->buffer) return MEMORY_ERROR; |
toddouska | 0:5045d2638c29 | 453 | der->length = neededSz; |
toddouska | 0:5045d2638c29 | 454 | |
toddouska | 0:5045d2638c29 | 455 | if (Base64Decode((byte*)headerEnd, neededSz, der->buffer, |
toddouska | 0:5045d2638c29 | 456 | &der->length) < 0) |
toddouska | 0:5045d2638c29 | 457 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 458 | |
toddouska | 0:5045d2638c29 | 459 | if (pkcs8) |
toddouska | 0:5045d2638c29 | 460 | return ToTraditional(der->buffer, der->length); |
toddouska | 0:5045d2638c29 | 461 | |
toddouska | 0:5045d2638c29 | 462 | /* not full support yet |
toddouska | 0:5045d2638c29 | 463 | if (pkcs8Enc) |
toddouska | 0:5045d2638c29 | 464 | return ToTraditionalEnc(der->buffer, der->length); |
toddouska | 0:5045d2638c29 | 465 | */ |
toddouska | 0:5045d2638c29 | 466 | |
toddouska | 0:5045d2638c29 | 467 | return 0; |
toddouska | 0:5045d2638c29 | 468 | } |
toddouska | 0:5045d2638c29 | 469 | |
toddouska | 0:5045d2638c29 | 470 | |
toddouska | 0:5045d2638c29 | 471 | static int ProcessBuffer(SSL_CTX* ctx, const unsigned char* buff, |
toddouska | 0:5045d2638c29 | 472 | long sz, int format, int type) |
toddouska | 0:5045d2638c29 | 473 | { |
toddouska | 0:5045d2638c29 | 474 | EncryptedInfo info; |
toddouska | 0:5045d2638c29 | 475 | buffer der; /* holds DER or RAW (for NTRU */ |
toddouska | 0:5045d2638c29 | 476 | int dynamicType; |
toddouska | 0:5045d2638c29 | 477 | |
toddouska | 0:5045d2638c29 | 478 | info.set = 0; |
toddouska | 0:5045d2638c29 | 479 | der.buffer = 0; |
toddouska | 0:5045d2638c29 | 480 | |
toddouska | 0:5045d2638c29 | 481 | if (format != SSL_FILETYPE_ASN1 && format != SSL_FILETYPE_PEM |
toddouska | 0:5045d2638c29 | 482 | && format != SSL_FILETYPE_RAW) |
toddouska | 0:5045d2638c29 | 483 | return SSL_BAD_FILETYPE; |
toddouska | 0:5045d2638c29 | 484 | |
toddouska | 0:5045d2638c29 | 485 | if (type == CA_TYPE) |
toddouska | 0:5045d2638c29 | 486 | dynamicType = DYNAMIC_TYPE_CA; |
toddouska | 0:5045d2638c29 | 487 | else if (type == CERT_TYPE) |
toddouska | 0:5045d2638c29 | 488 | dynamicType = DYNAMIC_TYPE_CERT; |
toddouska | 0:5045d2638c29 | 489 | else |
toddouska | 0:5045d2638c29 | 490 | dynamicType = DYNAMIC_TYPE_KEY; |
toddouska | 0:5045d2638c29 | 491 | |
toddouska | 0:5045d2638c29 | 492 | if (format == SSL_FILETYPE_PEM) { |
toddouska | 0:5045d2638c29 | 493 | if (PemToDer(buff, sz, type, &der, ctx->heap, &info) < 0) { |
toddouska | 0:5045d2638c29 | 494 | XFREE(der.buffer, ctx->heap, dynamicType); |
toddouska | 0:5045d2638c29 | 495 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 496 | } |
toddouska | 0:5045d2638c29 | 497 | } |
toddouska | 0:5045d2638c29 | 498 | else { /* ASN1 (DER) or RAW (NTRU) */ |
toddouska | 0:5045d2638c29 | 499 | der.buffer = (byte*) XMALLOC(sz, ctx->heap, dynamicType); |
toddouska | 0:5045d2638c29 | 500 | if (!der.buffer) return MEMORY_ERROR; |
toddouska | 0:5045d2638c29 | 501 | XMEMCPY(der.buffer, buff, sz); |
toddouska | 0:5045d2638c29 | 502 | der.length = sz; |
toddouska | 0:5045d2638c29 | 503 | } |
toddouska | 0:5045d2638c29 | 504 | |
toddouska | 0:5045d2638c29 | 505 | #ifdef OPENSSL_EXTRA |
toddouska | 0:5045d2638c29 | 506 | if (info.set) { |
toddouska | 0:5045d2638c29 | 507 | /* decrypt */ |
toddouska | 0:5045d2638c29 | 508 | char password[80]; |
toddouska | 0:5045d2638c29 | 509 | int passwordSz; |
toddouska | 0:5045d2638c29 | 510 | |
toddouska | 0:5045d2638c29 | 511 | byte key[AES_256_KEY_SIZE]; |
toddouska | 0:5045d2638c29 | 512 | byte iv[AES_IV_SIZE]; |
toddouska | 0:5045d2638c29 | 513 | |
toddouska | 0:5045d2638c29 | 514 | if (!ctx->passwd_cb) return -1; |
toddouska | 0:5045d2638c29 | 515 | |
toddouska | 0:5045d2638c29 | 516 | /* use file's salt for key derivation, hex decode first */ |
toddouska | 0:5045d2638c29 | 517 | if (Base16Decode(info.iv, info.ivSz, info.iv, &info.ivSz) != 0) |
toddouska | 0:5045d2638c29 | 518 | return -1; |
toddouska | 0:5045d2638c29 | 519 | |
toddouska | 0:5045d2638c29 | 520 | passwordSz = ctx->passwd_cb(password, sizeof(password), 0, |
toddouska | 0:5045d2638c29 | 521 | ctx->userdata); |
toddouska | 0:5045d2638c29 | 522 | if (EVP_BytesToKey(info.name, "MD5", info.iv, (byte*)password, |
toddouska | 0:5045d2638c29 | 523 | passwordSz, 1, key, iv) <= 0) |
toddouska | 0:5045d2638c29 | 524 | return -1; |
toddouska | 0:5045d2638c29 | 525 | |
toddouska | 0:5045d2638c29 | 526 | if (XSTRNCMP(info.name, "DES-CBC", 7) == 0) { |
toddouska | 0:5045d2638c29 | 527 | Des des; |
toddouska | 0:5045d2638c29 | 528 | Des_SetKey(&des, key, info.iv, DES_DECRYPTION); |
toddouska | 0:5045d2638c29 | 529 | Des_CbcDecrypt(&des, der.buffer, der.buffer, der.length); |
toddouska | 0:5045d2638c29 | 530 | } |
toddouska | 0:5045d2638c29 | 531 | else if (XSTRNCMP(info.name, "DES-EDE3-CBC", 13) == 0) { |
toddouska | 0:5045d2638c29 | 532 | Des3 des; |
toddouska | 0:5045d2638c29 | 533 | Des3_SetKey(&des, key, info.iv, DES_DECRYPTION); |
toddouska | 0:5045d2638c29 | 534 | Des3_CbcDecrypt(&des, der.buffer, der.buffer, der.length); |
toddouska | 0:5045d2638c29 | 535 | } |
toddouska | 0:5045d2638c29 | 536 | else if (XSTRNCMP(info.name, "AES-128-CBC", 13) == 0) { |
toddouska | 0:5045d2638c29 | 537 | Aes aes; |
toddouska | 0:5045d2638c29 | 538 | AesSetKey(&aes, key, AES_128_KEY_SIZE, info.iv, AES_DECRYPTION); |
toddouska | 0:5045d2638c29 | 539 | AesCbcDecrypt(&aes, der.buffer, der.buffer, der.length); |
toddouska | 0:5045d2638c29 | 540 | } |
toddouska | 0:5045d2638c29 | 541 | else if (XSTRNCMP(info.name, "AES-192-CBC", 13) == 0) { |
toddouska | 0:5045d2638c29 | 542 | Aes aes; |
toddouska | 0:5045d2638c29 | 543 | AesSetKey(&aes, key, AES_192_KEY_SIZE, info.iv, AES_DECRYPTION); |
toddouska | 0:5045d2638c29 | 544 | AesCbcDecrypt(&aes, der.buffer, der.buffer, der.length); |
toddouska | 0:5045d2638c29 | 545 | } |
toddouska | 0:5045d2638c29 | 546 | else if (XSTRNCMP(info.name, "AES-256-CBC", 13) == 0) { |
toddouska | 0:5045d2638c29 | 547 | Aes aes; |
toddouska | 0:5045d2638c29 | 548 | AesSetKey(&aes, key, AES_256_KEY_SIZE, info.iv, AES_DECRYPTION); |
toddouska | 0:5045d2638c29 | 549 | AesCbcDecrypt(&aes, der.buffer, der.buffer, der.length); |
toddouska | 0:5045d2638c29 | 550 | } |
toddouska | 0:5045d2638c29 | 551 | else |
toddouska | 0:5045d2638c29 | 552 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 553 | } |
toddouska | 0:5045d2638c29 | 554 | #endif /* OPENSSL_EXTRA */ |
toddouska | 0:5045d2638c29 | 555 | |
toddouska | 0:5045d2638c29 | 556 | if (type == CA_TYPE) |
toddouska | 0:5045d2638c29 | 557 | return AddCA(ctx, der); /* takes der over */ |
toddouska | 0:5045d2638c29 | 558 | else if (type == CERT_TYPE) { |
toddouska | 0:5045d2638c29 | 559 | if (ctx->certificate.buffer) |
toddouska | 0:5045d2638c29 | 560 | XFREE(ctx->certificate.buffer, ctx->heap, dynamicType); |
toddouska | 0:5045d2638c29 | 561 | ctx->certificate = der; /* takes der over */ |
toddouska | 0:5045d2638c29 | 562 | } |
toddouska | 0:5045d2638c29 | 563 | else if (type == PRIVATEKEY_TYPE) { |
toddouska | 0:5045d2638c29 | 564 | if (ctx->privateKey.buffer) |
toddouska | 0:5045d2638c29 | 565 | XFREE(ctx->privateKey.buffer, ctx->heap, dynamicType); |
toddouska | 0:5045d2638c29 | 566 | ctx->privateKey = der; /* takes der over */ |
toddouska | 0:5045d2638c29 | 567 | } |
toddouska | 0:5045d2638c29 | 568 | else { |
toddouska | 0:5045d2638c29 | 569 | XFREE(der.buffer, ctx->heap, dynamicType); |
toddouska | 0:5045d2638c29 | 570 | return SSL_BAD_CERTTYPE; |
toddouska | 0:5045d2638c29 | 571 | } |
toddouska | 0:5045d2638c29 | 572 | |
toddouska | 0:5045d2638c29 | 573 | if (type == PRIVATEKEY_TYPE && format != SSL_FILETYPE_RAW) { |
toddouska | 0:5045d2638c29 | 574 | /* make sure RSA key can be used */ |
toddouska | 0:5045d2638c29 | 575 | RsaKey key; |
toddouska | 0:5045d2638c29 | 576 | word32 idx = 0; |
toddouska | 0:5045d2638c29 | 577 | |
toddouska | 0:5045d2638c29 | 578 | InitRsaKey(&key, 0); |
toddouska | 0:5045d2638c29 | 579 | if (RsaPrivateKeyDecode(der.buffer, &idx, &key, der.length) != 0) { |
toddouska | 0:5045d2638c29 | 580 | FreeRsaKey(&key); |
toddouska | 0:5045d2638c29 | 581 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 582 | } |
toddouska | 0:5045d2638c29 | 583 | |
toddouska | 0:5045d2638c29 | 584 | FreeRsaKey(&key); |
toddouska | 0:5045d2638c29 | 585 | } |
toddouska | 0:5045d2638c29 | 586 | |
toddouska | 0:5045d2638c29 | 587 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 588 | } |
toddouska | 0:5045d2638c29 | 589 | |
toddouska | 0:5045d2638c29 | 590 | |
toddouska | 0:5045d2638c29 | 591 | #ifndef NO_FILESYSTEM |
toddouska | 0:5045d2638c29 | 592 | |
toddouska | 0:5045d2638c29 | 593 | #ifndef MICRIUM |
toddouska | 0:5045d2638c29 | 594 | #define XFILE FILE |
toddouska | 0:5045d2638c29 | 595 | #define XFOPEN fopen |
toddouska | 0:5045d2638c29 | 596 | #define XFSEEK fseek |
toddouska | 0:5045d2638c29 | 597 | #define XFTELL ftell |
toddouska | 0:5045d2638c29 | 598 | #define XREWIND rewind |
toddouska | 0:5045d2638c29 | 599 | #define XFREAD fread |
toddouska | 0:5045d2638c29 | 600 | #define XFCLOSE fclose |
toddouska | 0:5045d2638c29 | 601 | #define XSEEK_END SEEK_END |
toddouska | 0:5045d2638c29 | 602 | #else |
toddouska | 0:5045d2638c29 | 603 | #include <fs.h> |
toddouska | 0:5045d2638c29 | 604 | #define XFILE FS_FILE |
toddouska | 0:5045d2638c29 | 605 | #define XFOPEN fs_fopen |
toddouska | 0:5045d2638c29 | 606 | #define XFSEEK fs_fseek |
toddouska | 0:5045d2638c29 | 607 | #define XFTELL fs_ftell |
toddouska | 0:5045d2638c29 | 608 | #define XREWIND fs_rewind |
toddouska | 0:5045d2638c29 | 609 | #define XFREAD fs_fread |
toddouska | 0:5045d2638c29 | 610 | #define XFCLOSE fs_fclose |
toddouska | 0:5045d2638c29 | 611 | #define XSEEK_END FS_SEEK_END |
toddouska | 0:5045d2638c29 | 612 | #endif |
toddouska | 0:5045d2638c29 | 613 | |
toddouska | 0:5045d2638c29 | 614 | static int ProcessFile(SSL_CTX* ctx, const char* fname, int format, int type) |
toddouska | 0:5045d2638c29 | 615 | { |
toddouska | 0:5045d2638c29 | 616 | byte staticBuffer[FILE_BUFFER_SIZE]; |
toddouska | 0:5045d2638c29 | 617 | byte* buffer = staticBuffer; |
toddouska | 0:5045d2638c29 | 618 | int dynamic = 0; |
toddouska | 0:5045d2638c29 | 619 | int ret; |
toddouska | 0:5045d2638c29 | 620 | long sz = 0; |
toddouska | 0:5045d2638c29 | 621 | XFILE* file = XFOPEN(fname, "rb"); |
toddouska | 0:5045d2638c29 | 622 | |
toddouska | 0:5045d2638c29 | 623 | if (!file) return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 624 | XFSEEK(file, 0, XSEEK_END); |
toddouska | 0:5045d2638c29 | 625 | sz = XFTELL(file); |
toddouska | 0:5045d2638c29 | 626 | XREWIND(file); |
toddouska | 0:5045d2638c29 | 627 | |
toddouska | 0:5045d2638c29 | 628 | if (sz > sizeof(staticBuffer)) { |
toddouska | 0:5045d2638c29 | 629 | buffer = (byte*) XMALLOC(sz, ctx->heap, DYNAMIC_TYPE_FILE); |
toddouska | 0:5045d2638c29 | 630 | if (buffer == NULL) { |
toddouska | 0:5045d2638c29 | 631 | XFCLOSE(file); |
toddouska | 0:5045d2638c29 | 632 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 633 | } |
toddouska | 0:5045d2638c29 | 634 | dynamic = 1; |
toddouska | 0:5045d2638c29 | 635 | } |
toddouska | 0:5045d2638c29 | 636 | |
toddouska | 0:5045d2638c29 | 637 | if ( (ret = XFREAD(buffer, sz, 1, file)) < 0) |
toddouska | 0:5045d2638c29 | 638 | ret = SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 639 | else |
toddouska | 0:5045d2638c29 | 640 | ret = ProcessBuffer(ctx, buffer, sz, format, type); |
toddouska | 0:5045d2638c29 | 641 | |
toddouska | 0:5045d2638c29 | 642 | XFCLOSE(file); |
toddouska | 0:5045d2638c29 | 643 | if (dynamic) XFREE(buffer, ctx->heap, DYNAMIC_TYPE_FILE); |
toddouska | 0:5045d2638c29 | 644 | |
toddouska | 0:5045d2638c29 | 645 | return ret; |
toddouska | 0:5045d2638c29 | 646 | } |
toddouska | 0:5045d2638c29 | 647 | |
toddouska | 0:5045d2638c29 | 648 | |
toddouska | 0:5045d2638c29 | 649 | /* just one for now TODO: add dir support from path */ |
toddouska | 0:5045d2638c29 | 650 | int SSL_CTX_load_verify_locations(SSL_CTX* ctx, const char* file, |
toddouska | 0:5045d2638c29 | 651 | const char* path) |
toddouska | 0:5045d2638c29 | 652 | { |
toddouska | 0:5045d2638c29 | 653 | if (ProcessFile(ctx, file, SSL_FILETYPE_PEM, CA_TYPE) == SSL_SUCCESS) |
toddouska | 0:5045d2638c29 | 654 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 655 | |
toddouska | 0:5045d2638c29 | 656 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 657 | } |
toddouska | 0:5045d2638c29 | 658 | |
toddouska | 0:5045d2638c29 | 659 | |
toddouska | 0:5045d2638c29 | 660 | #ifdef CYASSL_DER_LOAD |
toddouska | 0:5045d2638c29 | 661 | |
toddouska | 0:5045d2638c29 | 662 | /* Add format parameter to allow DER load of CA files */ |
toddouska | 0:5045d2638c29 | 663 | int CyaSSL_CTX_load_verify_locations(SSL_CTX* ctx, const char* file, int format) |
toddouska | 0:5045d2638c29 | 664 | { |
toddouska | 0:5045d2638c29 | 665 | if (ProcessFile(ctx, file, format, CA_TYPE) == SSL_SUCCESS) |
toddouska | 0:5045d2638c29 | 666 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 667 | |
toddouska | 0:5045d2638c29 | 668 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 669 | } |
toddouska | 0:5045d2638c29 | 670 | |
toddouska | 0:5045d2638c29 | 671 | #endif /* CYASSL_DER_LOAD */ |
toddouska | 0:5045d2638c29 | 672 | |
toddouska | 0:5045d2638c29 | 673 | |
toddouska | 0:5045d2638c29 | 674 | #ifdef CYASSL_CERT_GEN |
toddouska | 0:5045d2638c29 | 675 | |
toddouska | 0:5045d2638c29 | 676 | /* load pem cert from file into der buffer, return der size or error */ |
toddouska | 0:5045d2638c29 | 677 | int CyaSSL_PemCertToDer(const char* fileName, unsigned char* derBuf, int derSz) |
toddouska | 0:5045d2638c29 | 678 | { |
toddouska | 0:5045d2638c29 | 679 | byte staticBuffer[FILE_BUFFER_SIZE]; |
toddouska | 0:5045d2638c29 | 680 | byte* fileBuf = staticBuffer; |
toddouska | 0:5045d2638c29 | 681 | int dynamic = 0; |
toddouska | 0:5045d2638c29 | 682 | int ret; |
toddouska | 0:5045d2638c29 | 683 | long sz = 0; |
toddouska | 0:5045d2638c29 | 684 | XFILE* file = XFOPEN(fileName, "rb"); |
toddouska | 0:5045d2638c29 | 685 | EncryptedInfo info; |
toddouska | 0:5045d2638c29 | 686 | buffer converted; |
toddouska | 0:5045d2638c29 | 687 | |
toddouska | 0:5045d2638c29 | 688 | converted.buffer = 0; |
toddouska | 0:5045d2638c29 | 689 | |
toddouska | 0:5045d2638c29 | 690 | if (!file) return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 691 | XFSEEK(file, 0, XSEEK_END); |
toddouska | 0:5045d2638c29 | 692 | sz = XFTELL(file); |
toddouska | 0:5045d2638c29 | 693 | XREWIND(file); |
toddouska | 0:5045d2638c29 | 694 | |
toddouska | 0:5045d2638c29 | 695 | if (sz > sizeof(staticBuffer)) { |
toddouska | 0:5045d2638c29 | 696 | fileBuf = (byte*) XMALLOC(sz, 0, DYNAMIC_TYPE_FILE); |
toddouska | 0:5045d2638c29 | 697 | if (fileBuf == NULL) { |
toddouska | 0:5045d2638c29 | 698 | XFCLOSE(file); |
toddouska | 0:5045d2638c29 | 699 | return SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 700 | } |
toddouska | 0:5045d2638c29 | 701 | dynamic = 1; |
toddouska | 0:5045d2638c29 | 702 | } |
toddouska | 0:5045d2638c29 | 703 | |
toddouska | 0:5045d2638c29 | 704 | if ( (ret = XFREAD(fileBuf, sz, 1, file)) < 0) |
toddouska | 0:5045d2638c29 | 705 | ret = SSL_BAD_FILE; |
toddouska | 0:5045d2638c29 | 706 | else |
toddouska | 0:5045d2638c29 | 707 | ret = PemToDer(fileBuf, sz, CA_TYPE, &converted, 0, &info); |
toddouska | 0:5045d2638c29 | 708 | |
toddouska | 0:5045d2638c29 | 709 | if (ret == 0) { |
toddouska | 0:5045d2638c29 | 710 | if (converted.length < derSz) { |
toddouska | 0:5045d2638c29 | 711 | memcpy(derBuf, converted.buffer, converted.length); |
toddouska | 0:5045d2638c29 | 712 | ret = converted.length; |
toddouska | 0:5045d2638c29 | 713 | } |
toddouska | 0:5045d2638c29 | 714 | else |
toddouska | 0:5045d2638c29 | 715 | ret = BUFFER_E; |
toddouska | 0:5045d2638c29 | 716 | } |
toddouska | 0:5045d2638c29 | 717 | |
toddouska | 0:5045d2638c29 | 718 | XFREE(converted.buffer, 0, DYNAMIC_TYPE_CA); |
toddouska | 0:5045d2638c29 | 719 | if (dynamic) |
toddouska | 0:5045d2638c29 | 720 | XFREE(fileBuf, 0, DYNAMIC_TYPE_FILE); |
toddouska | 0:5045d2638c29 | 721 | XFCLOSE(file); |
toddouska | 0:5045d2638c29 | 722 | |
toddouska | 0:5045d2638c29 | 723 | return ret; |
toddouska | 0:5045d2638c29 | 724 | } |
toddouska | 0:5045d2638c29 | 725 | |
toddouska | 0:5045d2638c29 | 726 | #endif /* CYASSL_CERT_GEN */ |
toddouska | 0:5045d2638c29 | 727 | |
toddouska | 0:5045d2638c29 | 728 | |
toddouska | 0:5045d2638c29 | 729 | int SSL_CTX_use_certificate_file(SSL_CTX* ctx, const char* file, int format) |
toddouska | 0:5045d2638c29 | 730 | { |
toddouska | 0:5045d2638c29 | 731 | if (ProcessFile(ctx, file, format, CERT_TYPE) == SSL_SUCCESS) |
toddouska | 0:5045d2638c29 | 732 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 733 | |
toddouska | 0:5045d2638c29 | 734 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 735 | } |
toddouska | 0:5045d2638c29 | 736 | |
toddouska | 0:5045d2638c29 | 737 | |
toddouska | 0:5045d2638c29 | 738 | int SSL_CTX_use_PrivateKey_file(SSL_CTX* ctx, const char* file, int format) |
toddouska | 0:5045d2638c29 | 739 | { |
toddouska | 0:5045d2638c29 | 740 | if (ProcessFile(ctx, file, format, PRIVATEKEY_TYPE) == SSL_SUCCESS) |
toddouska | 0:5045d2638c29 | 741 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 742 | |
toddouska | 0:5045d2638c29 | 743 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 744 | } |
toddouska | 0:5045d2638c29 | 745 | |
toddouska | 0:5045d2638c29 | 746 | |
toddouska | 0:5045d2638c29 | 747 | int SSL_CTX_use_certificate_chain_file(SSL_CTX* ctx, const char* file) |
toddouska | 0:5045d2638c29 | 748 | { |
toddouska | 0:5045d2638c29 | 749 | /* add first to ctx, all tested implementations support this */ |
toddouska | 0:5045d2638c29 | 750 | if (ProcessFile(ctx, file, SSL_FILETYPE_PEM, CERT_TYPE) == SSL_SUCCESS) |
toddouska | 0:5045d2638c29 | 751 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 752 | |
toddouska | 0:5045d2638c29 | 753 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 754 | } |
toddouska | 0:5045d2638c29 | 755 | |
toddouska | 0:5045d2638c29 | 756 | |
toddouska | 0:5045d2638c29 | 757 | #ifdef HAVE_NTRU |
toddouska | 0:5045d2638c29 | 758 | |
toddouska | 0:5045d2638c29 | 759 | int CyaSSL_CTX_use_NTRUPrivateKey_file(SSL_CTX* ctx, const char* file) |
toddouska | 0:5045d2638c29 | 760 | { |
toddouska | 0:5045d2638c29 | 761 | if (ProcessFile(ctx, file, SSL_FILETYPE_RAW, PRIVATEKEY_TYPE) |
toddouska | 0:5045d2638c29 | 762 | == SSL_SUCCESS) { |
toddouska | 0:5045d2638c29 | 763 | ctx->haveNTRU = 1; |
toddouska | 0:5045d2638c29 | 764 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 765 | } |
toddouska | 0:5045d2638c29 | 766 | |
toddouska | 0:5045d2638c29 | 767 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 768 | } |
toddouska | 0:5045d2638c29 | 769 | |
toddouska | 0:5045d2638c29 | 770 | #endif /* HAVE_NTRU */ |
toddouska | 0:5045d2638c29 | 771 | |
toddouska | 0:5045d2638c29 | 772 | |
toddouska | 0:5045d2638c29 | 773 | |
toddouska | 0:5045d2638c29 | 774 | #ifdef OPENSSL_EXTRA |
toddouska | 0:5045d2638c29 | 775 | |
toddouska | 0:5045d2638c29 | 776 | int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX* ctx,const char* file,int format) |
toddouska | 0:5045d2638c29 | 777 | { |
toddouska | 0:5045d2638c29 | 778 | if (ProcessFile(ctx, file, format, PRIVATEKEY_TYPE) == SSL_SUCCESS) |
toddouska | 0:5045d2638c29 | 779 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 780 | |
toddouska | 0:5045d2638c29 | 781 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 782 | } |
toddouska | 0:5045d2638c29 | 783 | |
toddouska | 0:5045d2638c29 | 784 | #endif /* OPENSSL_EXTRA */ |
toddouska | 0:5045d2638c29 | 785 | |
toddouska | 0:5045d2638c29 | 786 | #endif /* NO_FILESYSTEM */ |
toddouska | 0:5045d2638c29 | 787 | |
toddouska | 0:5045d2638c29 | 788 | |
toddouska | 0:5045d2638c29 | 789 | void SSL_CTX_set_verify(SSL_CTX* ctx, int mode, VerifyCallback vc) |
toddouska | 0:5045d2638c29 | 790 | { |
toddouska | 0:5045d2638c29 | 791 | if (mode & SSL_VERIFY_PEER) { |
toddouska | 0:5045d2638c29 | 792 | ctx->verifyPeer = 1; |
toddouska | 0:5045d2638c29 | 793 | ctx->verifyNone = 0; /* in case perviously set */ |
toddouska | 0:5045d2638c29 | 794 | } |
toddouska | 0:5045d2638c29 | 795 | |
toddouska | 0:5045d2638c29 | 796 | if (mode == SSL_VERIFY_NONE) { |
toddouska | 0:5045d2638c29 | 797 | ctx->verifyNone = 1; |
toddouska | 0:5045d2638c29 | 798 | ctx->verifyPeer = 0; /* in case previously set */ |
toddouska | 0:5045d2638c29 | 799 | } |
toddouska | 0:5045d2638c29 | 800 | |
toddouska | 0:5045d2638c29 | 801 | if (mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) |
toddouska | 0:5045d2638c29 | 802 | ctx->failNoCert = 1; |
toddouska | 0:5045d2638c29 | 803 | |
toddouska | 0:5045d2638c29 | 804 | ctx->verifyCallback = vc; |
toddouska | 0:5045d2638c29 | 805 | } |
toddouska | 0:5045d2638c29 | 806 | |
toddouska | 0:5045d2638c29 | 807 | |
toddouska | 0:5045d2638c29 | 808 | #ifndef NO_SESSION_CACHE |
toddouska | 0:5045d2638c29 | 809 | |
toddouska | 0:5045d2638c29 | 810 | SSL_SESSION* SSL_get_session(SSL* ssl) |
toddouska | 0:5045d2638c29 | 811 | { |
toddouska | 0:5045d2638c29 | 812 | return GetSession(ssl, 0); |
toddouska | 0:5045d2638c29 | 813 | } |
toddouska | 0:5045d2638c29 | 814 | |
toddouska | 0:5045d2638c29 | 815 | |
toddouska | 0:5045d2638c29 | 816 | int SSL_set_session(SSL* ssl, SSL_SESSION* session) |
toddouska | 0:5045d2638c29 | 817 | { |
toddouska | 0:5045d2638c29 | 818 | if (session) |
toddouska | 0:5045d2638c29 | 819 | return SetSession(ssl, session); |
toddouska | 0:5045d2638c29 | 820 | |
toddouska | 0:5045d2638c29 | 821 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 822 | } |
toddouska | 0:5045d2638c29 | 823 | |
toddouska | 0:5045d2638c29 | 824 | #endif /* NO_SESSION_CACHE */ |
toddouska | 0:5045d2638c29 | 825 | |
toddouska | 0:5045d2638c29 | 826 | |
toddouska | 0:5045d2638c29 | 827 | void SSL_load_error_strings(void) /* compatibility only */ |
toddouska | 0:5045d2638c29 | 828 | {} |
toddouska | 0:5045d2638c29 | 829 | |
toddouska | 0:5045d2638c29 | 830 | |
toddouska | 0:5045d2638c29 | 831 | int SSL_library_init(void) |
toddouska | 0:5045d2638c29 | 832 | { |
toddouska | 0:5045d2638c29 | 833 | if (InitCyaSSL() == 0) |
toddouska | 0:5045d2638c29 | 834 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 835 | else |
toddouska | 0:5045d2638c29 | 836 | return -1; |
toddouska | 0:5045d2638c29 | 837 | } |
toddouska | 0:5045d2638c29 | 838 | |
toddouska | 0:5045d2638c29 | 839 | |
toddouska | 0:5045d2638c29 | 840 | #ifndef NO_SESSION_CACHE |
toddouska | 0:5045d2638c29 | 841 | |
toddouska | 0:5045d2638c29 | 842 | /* on by default if built in but allow user to turn off */ |
toddouska | 0:5045d2638c29 | 843 | long SSL_CTX_set_session_cache_mode(SSL_CTX* ctx, long mode) |
toddouska | 0:5045d2638c29 | 844 | { |
toddouska | 0:5045d2638c29 | 845 | if (mode == SSL_SESS_CACHE_OFF) |
toddouska | 0:5045d2638c29 | 846 | ctx->sessionCacheOff = 1; |
toddouska | 0:5045d2638c29 | 847 | |
toddouska | 0:5045d2638c29 | 848 | if (mode == SSL_SESS_CACHE_NO_AUTO_CLEAR) |
toddouska | 0:5045d2638c29 | 849 | ctx->sessionCacheFlushOff = 1; |
toddouska | 0:5045d2638c29 | 850 | |
toddouska | 0:5045d2638c29 | 851 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 852 | } |
toddouska | 0:5045d2638c29 | 853 | |
toddouska | 0:5045d2638c29 | 854 | #endif /* NO_SESSION_CACHE */ |
toddouska | 0:5045d2638c29 | 855 | |
toddouska | 0:5045d2638c29 | 856 | |
toddouska | 0:5045d2638c29 | 857 | int SSL_CTX_set_cipher_list(SSL_CTX* ctx, const char* list) |
toddouska | 0:5045d2638c29 | 858 | { |
toddouska | 0:5045d2638c29 | 859 | if (SetCipherList(ctx, list)) |
toddouska | 0:5045d2638c29 | 860 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 861 | else |
toddouska | 0:5045d2638c29 | 862 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 863 | } |
toddouska | 0:5045d2638c29 | 864 | |
toddouska | 0:5045d2638c29 | 865 | |
toddouska | 0:5045d2638c29 | 866 | /* client only parts */ |
toddouska | 0:5045d2638c29 | 867 | #ifndef NO_CYASSL_CLIENT |
toddouska | 0:5045d2638c29 | 868 | |
toddouska | 0:5045d2638c29 | 869 | SSL_METHOD* SSLv3_client_method(void) |
toddouska | 0:5045d2638c29 | 870 | { |
toddouska | 0:5045d2638c29 | 871 | SSL_METHOD* method = (SSL_METHOD*) XMALLOC(sizeof(SSL_METHOD), 0, |
toddouska | 0:5045d2638c29 | 872 | DYNAMIC_TYPE_METHOD); |
toddouska | 0:5045d2638c29 | 873 | if (method) |
toddouska | 0:5045d2638c29 | 874 | InitSSL_Method(method, MakeSSLv3()); |
toddouska | 0:5045d2638c29 | 875 | return method; |
toddouska | 0:5045d2638c29 | 876 | } |
toddouska | 0:5045d2638c29 | 877 | |
toddouska | 0:5045d2638c29 | 878 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 879 | SSL_METHOD* DTLSv1_client_method(void) |
toddouska | 0:5045d2638c29 | 880 | { |
toddouska | 0:5045d2638c29 | 881 | SSL_METHOD* method = (SSL_METHOD*) XMALLOC(sizeof(SSL_METHOD), 0, |
toddouska | 0:5045d2638c29 | 882 | DYNAMIC_TYPE_METHOD); |
toddouska | 0:5045d2638c29 | 883 | if (method) |
toddouska | 0:5045d2638c29 | 884 | InitSSL_Method(method, MakeDTLSv1()); |
toddouska | 0:5045d2638c29 | 885 | return method; |
toddouska | 0:5045d2638c29 | 886 | } |
toddouska | 0:5045d2638c29 | 887 | #endif |
toddouska | 0:5045d2638c29 | 888 | |
toddouska | 0:5045d2638c29 | 889 | |
toddouska | 0:5045d2638c29 | 890 | /* please see note at top of README if you get an error from connect */ |
toddouska | 0:5045d2638c29 | 891 | int SSL_connect(SSL* ssl) |
toddouska | 0:5045d2638c29 | 892 | { |
toddouska | 0:5045d2638c29 | 893 | int neededState; |
toddouska | 0:5045d2638c29 | 894 | |
toddouska | 0:5045d2638c29 | 895 | CYASSL_ENTER("SSL_connect()"); |
toddouska | 0:5045d2638c29 | 896 | |
toddouska | 0:5045d2638c29 | 897 | #ifdef HAVE_ERRNO_H |
toddouska | 0:5045d2638c29 | 898 | errno = 0; |
toddouska | 0:5045d2638c29 | 899 | #endif |
toddouska | 0:5045d2638c29 | 900 | |
toddouska | 0:5045d2638c29 | 901 | if (ssl->options.side != CLIENT_END) { |
toddouska | 0:5045d2638c29 | 902 | CYASSL_ERROR(ssl->error = SIDE_ERROR); |
toddouska | 0:5045d2638c29 | 903 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 904 | } |
toddouska | 0:5045d2638c29 | 905 | |
toddouska | 0:5045d2638c29 | 906 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 907 | if (ssl->version.major == DTLS_MAJOR && |
toddouska | 0:5045d2638c29 | 908 | ssl->version.minor == DTLS_MINOR) { |
toddouska | 0:5045d2638c29 | 909 | ssl->options.dtls = 1; |
toddouska | 0:5045d2638c29 | 910 | ssl->options.tls = 1; |
toddouska | 0:5045d2638c29 | 911 | ssl->options.tls1_1 = 1; |
toddouska | 0:5045d2638c29 | 912 | } |
toddouska | 0:5045d2638c29 | 913 | #endif |
toddouska | 0:5045d2638c29 | 914 | |
toddouska | 0:5045d2638c29 | 915 | if (ssl->buffers.outputBuffer.length > 0) { |
toddouska | 0:5045d2638c29 | 916 | if ( (ssl->error = SendBuffered(ssl)) == 0) { |
toddouska | 0:5045d2638c29 | 917 | ssl->options.connectState++; |
toddouska | 0:5045d2638c29 | 918 | CYASSL_MSG("connect state: Advanced from buffered send"); |
toddouska | 0:5045d2638c29 | 919 | } |
toddouska | 0:5045d2638c29 | 920 | else { |
toddouska | 0:5045d2638c29 | 921 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 922 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 923 | } |
toddouska | 0:5045d2638c29 | 924 | } |
toddouska | 0:5045d2638c29 | 925 | |
toddouska | 0:5045d2638c29 | 926 | switch (ssl->options.connectState) { |
toddouska | 0:5045d2638c29 | 927 | |
toddouska | 0:5045d2638c29 | 928 | case CONNECT_BEGIN : |
toddouska | 0:5045d2638c29 | 929 | /* always send client hello first */ |
toddouska | 0:5045d2638c29 | 930 | if ( (ssl->error = SendClientHello(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 931 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 932 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 933 | } |
toddouska | 0:5045d2638c29 | 934 | ssl->options.connectState = CLIENT_HELLO_SENT; |
toddouska | 0:5045d2638c29 | 935 | CYASSL_MSG("connect state: CLIENT_HELLO_SENT"); |
toddouska | 0:5045d2638c29 | 936 | |
toddouska | 0:5045d2638c29 | 937 | case CLIENT_HELLO_SENT : |
toddouska | 0:5045d2638c29 | 938 | neededState = ssl->options.resuming ? SERVER_FINISHED_COMPLETE : |
toddouska | 0:5045d2638c29 | 939 | SERVER_HELLODONE_COMPLETE; |
toddouska | 0:5045d2638c29 | 940 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 941 | if (ssl->options.dtls && !ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 942 | neededState = SERVER_HELLOVERIFYREQUEST_COMPLETE; |
toddouska | 0:5045d2638c29 | 943 | #endif |
toddouska | 0:5045d2638c29 | 944 | /* get response */ |
toddouska | 0:5045d2638c29 | 945 | while (ssl->options.serverState < neededState) { |
toddouska | 0:5045d2638c29 | 946 | if ( (ssl->error = ProcessReply(ssl)) < 0) { |
toddouska | 0:5045d2638c29 | 947 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 948 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 949 | } |
toddouska | 0:5045d2638c29 | 950 | /* if resumption failed, reset needed state */ |
toddouska | 0:5045d2638c29 | 951 | else if (neededState == SERVER_FINISHED_COMPLETE) |
toddouska | 0:5045d2638c29 | 952 | if (!ssl->options.resuming) { |
toddouska | 0:5045d2638c29 | 953 | if (!ssl->options.dtls) |
toddouska | 0:5045d2638c29 | 954 | neededState = SERVER_HELLODONE_COMPLETE; |
toddouska | 0:5045d2638c29 | 955 | else |
toddouska | 0:5045d2638c29 | 956 | neededState = SERVER_HELLOVERIFYREQUEST_COMPLETE; |
toddouska | 0:5045d2638c29 | 957 | } |
toddouska | 0:5045d2638c29 | 958 | } |
toddouska | 0:5045d2638c29 | 959 | |
toddouska | 0:5045d2638c29 | 960 | ssl->options.connectState = HELLO_AGAIN; |
toddouska | 0:5045d2638c29 | 961 | CYASSL_MSG("connect state: HELLO_AGAIN"); |
toddouska | 0:5045d2638c29 | 962 | |
toddouska | 0:5045d2638c29 | 963 | case HELLO_AGAIN : |
toddouska | 0:5045d2638c29 | 964 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 965 | if (ssl->options.dtls && !ssl->options.resuming) { |
toddouska | 0:5045d2638c29 | 966 | /* re-init hashes, exclude first hello and verify request */ |
toddouska | 0:5045d2638c29 | 967 | InitMd5(&ssl->hashMd5); |
toddouska | 0:5045d2638c29 | 968 | InitSha(&ssl->hashSha); |
toddouska | 0:5045d2638c29 | 969 | if ( (ssl->error = SendClientHello(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 970 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 971 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 972 | } |
toddouska | 0:5045d2638c29 | 973 | } |
toddouska | 0:5045d2638c29 | 974 | #endif |
toddouska | 0:5045d2638c29 | 975 | |
toddouska | 0:5045d2638c29 | 976 | ssl->options.connectState = HELLO_AGAIN_REPLY; |
toddouska | 0:5045d2638c29 | 977 | CYASSL_MSG("connect state: HELLO_AGAIN_REPLY"); |
toddouska | 0:5045d2638c29 | 978 | |
toddouska | 0:5045d2638c29 | 979 | case HELLO_AGAIN_REPLY : |
toddouska | 0:5045d2638c29 | 980 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 981 | if (ssl->options.dtls) { |
toddouska | 0:5045d2638c29 | 982 | neededState = ssl->options.resuming ? |
toddouska | 0:5045d2638c29 | 983 | SERVER_FINISHED_COMPLETE : SERVER_HELLODONE_COMPLETE; |
toddouska | 0:5045d2638c29 | 984 | |
toddouska | 0:5045d2638c29 | 985 | /* get response */ |
toddouska | 0:5045d2638c29 | 986 | while (ssl->options.serverState < neededState) { |
toddouska | 0:5045d2638c29 | 987 | if ( (ssl->error = ProcessReply(ssl)) < 0) { |
toddouska | 0:5045d2638c29 | 988 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 989 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 990 | } |
toddouska | 0:5045d2638c29 | 991 | /* if resumption failed, reset needed state */ |
toddouska | 0:5045d2638c29 | 992 | else if (neededState == SERVER_FINISHED_COMPLETE) |
toddouska | 0:5045d2638c29 | 993 | if (!ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 994 | neededState = SERVER_HELLODONE_COMPLETE; |
toddouska | 0:5045d2638c29 | 995 | } |
toddouska | 0:5045d2638c29 | 996 | } |
toddouska | 0:5045d2638c29 | 997 | #endif |
toddouska | 0:5045d2638c29 | 998 | |
toddouska | 0:5045d2638c29 | 999 | ssl->options.connectState = FIRST_REPLY_DONE; |
toddouska | 0:5045d2638c29 | 1000 | CYASSL_MSG("connect state: FIRST_REPLY_DONE"); |
toddouska | 0:5045d2638c29 | 1001 | |
toddouska | 0:5045d2638c29 | 1002 | case FIRST_REPLY_DONE : |
toddouska | 0:5045d2638c29 | 1003 | if (ssl->options.sendVerify) |
toddouska | 0:5045d2638c29 | 1004 | if ( (ssl->error = SendCertificate(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1005 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1006 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1007 | } |
toddouska | 0:5045d2638c29 | 1008 | |
toddouska | 0:5045d2638c29 | 1009 | ssl->options.connectState = FIRST_REPLY_FIRST; |
toddouska | 0:5045d2638c29 | 1010 | CYASSL_MSG("connect state: FIRST_REPLY_FIRST"); |
toddouska | 0:5045d2638c29 | 1011 | |
toddouska | 0:5045d2638c29 | 1012 | case FIRST_REPLY_FIRST : |
toddouska | 0:5045d2638c29 | 1013 | if (!ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 1014 | if ( (ssl->error = SendClientKeyExchange(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1015 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1016 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1017 | } |
toddouska | 0:5045d2638c29 | 1018 | |
toddouska | 0:5045d2638c29 | 1019 | ssl->options.connectState = FIRST_REPLY_SECOND; |
toddouska | 0:5045d2638c29 | 1020 | CYASSL_MSG("connect state: FIRST_REPLY_SECOND"); |
toddouska | 0:5045d2638c29 | 1021 | |
toddouska | 0:5045d2638c29 | 1022 | case FIRST_REPLY_SECOND : |
toddouska | 0:5045d2638c29 | 1023 | if (ssl->options.sendVerify) |
toddouska | 0:5045d2638c29 | 1024 | if ( (ssl->error = SendCertificateVerify(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1025 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1026 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1027 | } |
toddouska | 0:5045d2638c29 | 1028 | ssl->options.connectState = FIRST_REPLY_THIRD; |
toddouska | 0:5045d2638c29 | 1029 | CYASSL_MSG("connect state: FIRST_REPLY_THIRD"); |
toddouska | 0:5045d2638c29 | 1030 | |
toddouska | 0:5045d2638c29 | 1031 | case FIRST_REPLY_THIRD : |
toddouska | 0:5045d2638c29 | 1032 | if ( (ssl->error = SendChangeCipher(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1033 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1034 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1035 | } |
toddouska | 0:5045d2638c29 | 1036 | ssl->options.connectState = FIRST_REPLY_FOURTH; |
toddouska | 0:5045d2638c29 | 1037 | CYASSL_MSG("connect state: FIRST_REPLY_FOURTH"); |
toddouska | 0:5045d2638c29 | 1038 | |
toddouska | 0:5045d2638c29 | 1039 | case FIRST_REPLY_FOURTH : |
toddouska | 0:5045d2638c29 | 1040 | if ( (ssl->error = SendFinished(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1041 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1042 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1043 | } |
toddouska | 0:5045d2638c29 | 1044 | |
toddouska | 0:5045d2638c29 | 1045 | ssl->options.connectState = FINISHED_DONE; |
toddouska | 0:5045d2638c29 | 1046 | CYASSL_MSG("connect state: FINISHED_DONE"); |
toddouska | 0:5045d2638c29 | 1047 | |
toddouska | 0:5045d2638c29 | 1048 | case FINISHED_DONE : |
toddouska | 0:5045d2638c29 | 1049 | /* get response */ |
toddouska | 0:5045d2638c29 | 1050 | while (ssl->options.serverState < SERVER_FINISHED_COMPLETE) |
toddouska | 0:5045d2638c29 | 1051 | if ( (ssl->error = ProcessReply(ssl)) < 0) { |
toddouska | 0:5045d2638c29 | 1052 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1053 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1054 | } |
toddouska | 0:5045d2638c29 | 1055 | |
toddouska | 0:5045d2638c29 | 1056 | ssl->options.connectState = SECOND_REPLY_DONE; |
toddouska | 0:5045d2638c29 | 1057 | CYASSL_MSG("connect state: SECOND_REPLY_DONE"); |
toddouska | 0:5045d2638c29 | 1058 | |
toddouska | 0:5045d2638c29 | 1059 | case SECOND_REPLY_DONE: |
toddouska | 0:5045d2638c29 | 1060 | if (ssl->buffers.inputBuffer.dynamicFlag) |
toddouska | 0:5045d2638c29 | 1061 | ShrinkInputBuffer(ssl, NO_FORCED_FREE); |
toddouska | 0:5045d2638c29 | 1062 | CYASSL_LEAVE("SSL_connect()", SSL_SUCCESS); |
toddouska | 0:5045d2638c29 | 1063 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1064 | |
toddouska | 0:5045d2638c29 | 1065 | default: |
toddouska | 0:5045d2638c29 | 1066 | CYASSL_MSG("Unknown connect state ERROR"); |
toddouska | 0:5045d2638c29 | 1067 | return SSL_FATAL_ERROR; /* unknown connect state */ |
toddouska | 0:5045d2638c29 | 1068 | } |
toddouska | 0:5045d2638c29 | 1069 | } |
toddouska | 0:5045d2638c29 | 1070 | |
toddouska | 0:5045d2638c29 | 1071 | #endif /* NO_CYASSL_CLIENT */ |
toddouska | 0:5045d2638c29 | 1072 | |
toddouska | 0:5045d2638c29 | 1073 | |
toddouska | 0:5045d2638c29 | 1074 | /* server only parts */ |
toddouska | 0:5045d2638c29 | 1075 | #ifndef NO_CYASSL_SERVER |
toddouska | 0:5045d2638c29 | 1076 | |
toddouska | 0:5045d2638c29 | 1077 | SSL_METHOD* SSLv3_server_method(void) |
toddouska | 0:5045d2638c29 | 1078 | { |
toddouska | 0:5045d2638c29 | 1079 | SSL_METHOD* method = (SSL_METHOD*) XMALLOC(sizeof(SSL_METHOD), 0, |
toddouska | 0:5045d2638c29 | 1080 | DYNAMIC_TYPE_METHOD); |
toddouska | 0:5045d2638c29 | 1081 | if (method) { |
toddouska | 0:5045d2638c29 | 1082 | InitSSL_Method(method, MakeSSLv3()); |
toddouska | 0:5045d2638c29 | 1083 | method->side = SERVER_END; |
toddouska | 0:5045d2638c29 | 1084 | } |
toddouska | 0:5045d2638c29 | 1085 | return method; |
toddouska | 0:5045d2638c29 | 1086 | } |
toddouska | 0:5045d2638c29 | 1087 | |
toddouska | 0:5045d2638c29 | 1088 | |
toddouska | 0:5045d2638c29 | 1089 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 1090 | SSL_METHOD* DTLSv1_server_method(void) |
toddouska | 0:5045d2638c29 | 1091 | { |
toddouska | 0:5045d2638c29 | 1092 | SSL_METHOD* method = (SSL_METHOD*) XMALLOC(sizeof(SSL_METHOD), 0, |
toddouska | 0:5045d2638c29 | 1093 | DYNAMIC_TYPE_METHOD); |
toddouska | 0:5045d2638c29 | 1094 | if (method) { |
toddouska | 0:5045d2638c29 | 1095 | InitSSL_Method(method, MakeDTLSv1()); |
toddouska | 0:5045d2638c29 | 1096 | method->side = SERVER_END; |
toddouska | 0:5045d2638c29 | 1097 | } |
toddouska | 0:5045d2638c29 | 1098 | return method; |
toddouska | 0:5045d2638c29 | 1099 | } |
toddouska | 0:5045d2638c29 | 1100 | #endif |
toddouska | 0:5045d2638c29 | 1101 | |
toddouska | 0:5045d2638c29 | 1102 | |
toddouska | 0:5045d2638c29 | 1103 | int SSL_accept(SSL* ssl) |
toddouska | 0:5045d2638c29 | 1104 | { |
toddouska | 0:5045d2638c29 | 1105 | CYASSL_ENTER("SSL_accept()"); |
toddouska | 0:5045d2638c29 | 1106 | |
toddouska | 0:5045d2638c29 | 1107 | #ifdef HAVE_ERRNO_H |
toddouska | 0:5045d2638c29 | 1108 | errno = 0; |
toddouska | 0:5045d2638c29 | 1109 | #endif |
toddouska | 0:5045d2638c29 | 1110 | |
toddouska | 0:5045d2638c29 | 1111 | if (ssl->options.side != SERVER_END) { |
toddouska | 0:5045d2638c29 | 1112 | CYASSL_ERROR(ssl->error = SIDE_ERROR); |
toddouska | 0:5045d2638c29 | 1113 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1114 | } |
toddouska | 0:5045d2638c29 | 1115 | |
toddouska | 0:5045d2638c29 | 1116 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 1117 | if (ssl->version.major == DTLS_MAJOR && |
toddouska | 0:5045d2638c29 | 1118 | ssl->version.minor == DTLS_MINOR) { |
toddouska | 0:5045d2638c29 | 1119 | ssl->options.dtls = 1; |
toddouska | 0:5045d2638c29 | 1120 | ssl->options.tls = 1; |
toddouska | 0:5045d2638c29 | 1121 | ssl->options.tls1_1 = 1; |
toddouska | 0:5045d2638c29 | 1122 | } |
toddouska | 0:5045d2638c29 | 1123 | #endif |
toddouska | 0:5045d2638c29 | 1124 | |
toddouska | 0:5045d2638c29 | 1125 | if (ssl->buffers.outputBuffer.length > 0) { |
toddouska | 0:5045d2638c29 | 1126 | if ( (ssl->error = SendBuffered(ssl)) == 0) { |
toddouska | 0:5045d2638c29 | 1127 | ssl->options.acceptState++; |
toddouska | 0:5045d2638c29 | 1128 | CYASSL_MSG("accept state: Advanced from buffered send"); |
toddouska | 0:5045d2638c29 | 1129 | } |
toddouska | 0:5045d2638c29 | 1130 | else { |
toddouska | 0:5045d2638c29 | 1131 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1132 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1133 | } |
toddouska | 0:5045d2638c29 | 1134 | } |
toddouska | 0:5045d2638c29 | 1135 | |
toddouska | 0:5045d2638c29 | 1136 | switch (ssl->options.acceptState) { |
toddouska | 0:5045d2638c29 | 1137 | |
toddouska | 0:5045d2638c29 | 1138 | case ACCEPT_BEGIN : |
toddouska | 0:5045d2638c29 | 1139 | /* get response */ |
toddouska | 0:5045d2638c29 | 1140 | while (ssl->options.clientState < CLIENT_HELLO_COMPLETE) |
toddouska | 0:5045d2638c29 | 1141 | if ( (ssl->error = ProcessReply(ssl)) < 0) { |
toddouska | 0:5045d2638c29 | 1142 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1143 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1144 | } |
toddouska | 0:5045d2638c29 | 1145 | ssl->options.acceptState = ACCEPT_CLIENT_HELLO_DONE; |
toddouska | 0:5045d2638c29 | 1146 | CYASSL_MSG("accept state ACCEPT_CLIENT_HELLO_DONE"); |
toddouska | 0:5045d2638c29 | 1147 | |
toddouska | 0:5045d2638c29 | 1148 | case ACCEPT_CLIENT_HELLO_DONE : |
toddouska | 0:5045d2638c29 | 1149 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 1150 | if (ssl->options.dtls && !ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 1151 | if ( (ssl->error = SendHelloVerifyRequest(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1152 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1153 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1154 | } |
toddouska | 0:5045d2638c29 | 1155 | #endif |
toddouska | 0:5045d2638c29 | 1156 | ssl->options.acceptState = HELLO_VERIFY_SENT; |
toddouska | 0:5045d2638c29 | 1157 | CYASSL_MSG("accept state HELLO_VERIFY_SENT"); |
toddouska | 0:5045d2638c29 | 1158 | |
toddouska | 0:5045d2638c29 | 1159 | case HELLO_VERIFY_SENT: |
toddouska | 0:5045d2638c29 | 1160 | #ifdef CYASSL_DTLS |
toddouska | 0:5045d2638c29 | 1161 | if (ssl->options.dtls && !ssl->options.resuming) { |
toddouska | 0:5045d2638c29 | 1162 | ssl->options.clientState = NULL_STATE; /* get again */ |
toddouska | 0:5045d2638c29 | 1163 | /* re-init hashes, exclude first hello and verify request */ |
toddouska | 0:5045d2638c29 | 1164 | InitMd5(&ssl->hashMd5); |
toddouska | 0:5045d2638c29 | 1165 | InitSha(&ssl->hashSha); |
toddouska | 0:5045d2638c29 | 1166 | |
toddouska | 0:5045d2638c29 | 1167 | while (ssl->options.clientState < CLIENT_HELLO_COMPLETE) |
toddouska | 0:5045d2638c29 | 1168 | if ( (ssl->error = ProcessReply(ssl)) < 0) { |
toddouska | 0:5045d2638c29 | 1169 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1170 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1171 | } |
toddouska | 0:5045d2638c29 | 1172 | } |
toddouska | 0:5045d2638c29 | 1173 | #endif |
toddouska | 0:5045d2638c29 | 1174 | ssl->options.acceptState = ACCEPT_FIRST_REPLY_DONE; |
toddouska | 0:5045d2638c29 | 1175 | CYASSL_MSG("accept state ACCEPT_FIRST_REPLY_DONE"); |
toddouska | 0:5045d2638c29 | 1176 | |
toddouska | 0:5045d2638c29 | 1177 | case ACCEPT_FIRST_REPLY_DONE : |
toddouska | 0:5045d2638c29 | 1178 | if ( (ssl->error = SendServerHello(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1179 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1180 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1181 | } |
toddouska | 0:5045d2638c29 | 1182 | ssl->options.acceptState = SERVER_HELLO_SENT; |
toddouska | 0:5045d2638c29 | 1183 | CYASSL_MSG("accept state SERVER_HELLO_SENT"); |
toddouska | 0:5045d2638c29 | 1184 | |
toddouska | 0:5045d2638c29 | 1185 | case SERVER_HELLO_SENT : |
toddouska | 0:5045d2638c29 | 1186 | if (!ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 1187 | if ( (ssl->error = SendCertificate(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1188 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1189 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1190 | } |
toddouska | 0:5045d2638c29 | 1191 | ssl->options.acceptState = CERT_SENT; |
toddouska | 0:5045d2638c29 | 1192 | CYASSL_MSG("accept state CERT_SENT"); |
toddouska | 0:5045d2638c29 | 1193 | |
toddouska | 0:5045d2638c29 | 1194 | case CERT_SENT : |
toddouska | 0:5045d2638c29 | 1195 | if (!ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 1196 | if ( (ssl->error = SendServerKeyExchange(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1197 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1198 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1199 | } |
toddouska | 0:5045d2638c29 | 1200 | ssl->options.acceptState = KEY_EXCHANGE_SENT; |
toddouska | 0:5045d2638c29 | 1201 | CYASSL_MSG("accept state KEY_EXCHANGE_SENT"); |
toddouska | 0:5045d2638c29 | 1202 | |
toddouska | 0:5045d2638c29 | 1203 | case KEY_EXCHANGE_SENT : |
toddouska | 0:5045d2638c29 | 1204 | if (!ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 1205 | if (ssl->options.verifyPeer) |
toddouska | 0:5045d2638c29 | 1206 | if ( (ssl->error = SendCertificateRequest(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1207 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1208 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1209 | } |
toddouska | 0:5045d2638c29 | 1210 | ssl->options.acceptState = CERT_REQ_SENT; |
toddouska | 0:5045d2638c29 | 1211 | CYASSL_MSG("accept state CERT_REQ_SENT"); |
toddouska | 0:5045d2638c29 | 1212 | |
toddouska | 0:5045d2638c29 | 1213 | case CERT_REQ_SENT : |
toddouska | 0:5045d2638c29 | 1214 | if (!ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 1215 | if ( (ssl->error = SendServerHelloDone(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1216 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1217 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1218 | } |
toddouska | 0:5045d2638c29 | 1219 | ssl->options.acceptState = SERVER_HELLO_DONE; |
toddouska | 0:5045d2638c29 | 1220 | CYASSL_MSG("accept state SERVER_HELLO_DONE"); |
toddouska | 0:5045d2638c29 | 1221 | |
toddouska | 0:5045d2638c29 | 1222 | case SERVER_HELLO_DONE : |
toddouska | 0:5045d2638c29 | 1223 | if (!ssl->options.resuming) { |
toddouska | 0:5045d2638c29 | 1224 | while (ssl->options.clientState < CLIENT_FINISHED_COMPLETE) |
toddouska | 0:5045d2638c29 | 1225 | if ( (ssl->error = ProcessReply(ssl)) < 0) { |
toddouska | 0:5045d2638c29 | 1226 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1227 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1228 | } |
toddouska | 0:5045d2638c29 | 1229 | } |
toddouska | 0:5045d2638c29 | 1230 | ssl->options.acceptState = ACCEPT_SECOND_REPLY_DONE; |
toddouska | 0:5045d2638c29 | 1231 | CYASSL_MSG("accept state ACCEPT_SECOND_REPLY_DONE"); |
toddouska | 0:5045d2638c29 | 1232 | |
toddouska | 0:5045d2638c29 | 1233 | case ACCEPT_SECOND_REPLY_DONE : |
toddouska | 0:5045d2638c29 | 1234 | if ( (ssl->error = SendChangeCipher(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1235 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1236 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1237 | } |
toddouska | 0:5045d2638c29 | 1238 | ssl->options.acceptState = CHANGE_CIPHER_SENT; |
toddouska | 0:5045d2638c29 | 1239 | CYASSL_MSG("accept state CHANGE_CIPHER_SENT"); |
toddouska | 0:5045d2638c29 | 1240 | |
toddouska | 0:5045d2638c29 | 1241 | case CHANGE_CIPHER_SENT : |
toddouska | 0:5045d2638c29 | 1242 | if ( (ssl->error = SendFinished(ssl)) != 0) { |
toddouska | 0:5045d2638c29 | 1243 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1244 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1245 | } |
toddouska | 0:5045d2638c29 | 1246 | |
toddouska | 0:5045d2638c29 | 1247 | ssl->options.acceptState = ACCEPT_FINISHED_DONE; |
toddouska | 0:5045d2638c29 | 1248 | CYASSL_MSG("accept state ACCEPT_FINISHED_DONE"); |
toddouska | 0:5045d2638c29 | 1249 | |
toddouska | 0:5045d2638c29 | 1250 | case ACCEPT_FINISHED_DONE : |
toddouska | 0:5045d2638c29 | 1251 | if (ssl->options.resuming) |
toddouska | 0:5045d2638c29 | 1252 | while (ssl->options.clientState < CLIENT_FINISHED_COMPLETE) |
toddouska | 0:5045d2638c29 | 1253 | if ( (ssl->error = ProcessReply(ssl)) < 0) { |
toddouska | 0:5045d2638c29 | 1254 | CYASSL_ERROR(ssl->error); |
toddouska | 0:5045d2638c29 | 1255 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1256 | } |
toddouska | 0:5045d2638c29 | 1257 | |
toddouska | 0:5045d2638c29 | 1258 | ssl->options.acceptState = ACCEPT_THIRD_REPLY_DONE; |
toddouska | 0:5045d2638c29 | 1259 | CYASSL_MSG("accept state ACCEPT_THIRD_REPLY_DONE"); |
toddouska | 0:5045d2638c29 | 1260 | |
toddouska | 0:5045d2638c29 | 1261 | case ACCEPT_THIRD_REPLY_DONE : |
toddouska | 0:5045d2638c29 | 1262 | if (ssl->buffers.inputBuffer.dynamicFlag) |
toddouska | 0:5045d2638c29 | 1263 | ShrinkInputBuffer(ssl, NO_FORCED_FREE); |
toddouska | 0:5045d2638c29 | 1264 | CYASSL_LEAVE("SSL_accept()", SSL_SUCCESS); |
toddouska | 0:5045d2638c29 | 1265 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1266 | |
toddouska | 0:5045d2638c29 | 1267 | default : |
toddouska | 0:5045d2638c29 | 1268 | CYASSL_MSG("Unknown accept state ERROR"); |
toddouska | 0:5045d2638c29 | 1269 | return SSL_FATAL_ERROR; |
toddouska | 0:5045d2638c29 | 1270 | } |
toddouska | 0:5045d2638c29 | 1271 | } |
toddouska | 0:5045d2638c29 | 1272 | |
toddouska | 0:5045d2638c29 | 1273 | #endif /* NO_CYASSL_SERVER */ |
toddouska | 0:5045d2638c29 | 1274 | |
toddouska | 0:5045d2638c29 | 1275 | |
toddouska | 0:5045d2638c29 | 1276 | int InitCyaSSL(void) |
toddouska | 0:5045d2638c29 | 1277 | { |
toddouska | 0:5045d2638c29 | 1278 | if (InitMutex(&mutex) == 0) |
toddouska | 0:5045d2638c29 | 1279 | return 0; |
toddouska | 0:5045d2638c29 | 1280 | else |
toddouska | 0:5045d2638c29 | 1281 | return -1; |
toddouska | 0:5045d2638c29 | 1282 | } |
toddouska | 0:5045d2638c29 | 1283 | |
toddouska | 0:5045d2638c29 | 1284 | |
toddouska | 0:5045d2638c29 | 1285 | int FreeCyaSSL(void) |
toddouska | 0:5045d2638c29 | 1286 | { |
toddouska | 0:5045d2638c29 | 1287 | if (FreeMutex(&mutex) == 0) |
toddouska | 0:5045d2638c29 | 1288 | return 0; |
toddouska | 0:5045d2638c29 | 1289 | else |
toddouska | 0:5045d2638c29 | 1290 | return -1; |
toddouska | 0:5045d2638c29 | 1291 | } |
toddouska | 0:5045d2638c29 | 1292 | |
toddouska | 0:5045d2638c29 | 1293 | |
toddouska | 0:5045d2638c29 | 1294 | #ifndef NO_SESSION_CACHE |
toddouska | 0:5045d2638c29 | 1295 | |
toddouska | 0:5045d2638c29 | 1296 | |
toddouska | 0:5045d2638c29 | 1297 | static INLINE word32 HashSession(const byte* sessionID) |
toddouska | 0:5045d2638c29 | 1298 | { |
toddouska | 0:5045d2638c29 | 1299 | /* id is random, just make 32 bit number from first 4 bytes for now */ |
toddouska | 0:5045d2638c29 | 1300 | return (sessionID[0] << 24) | (sessionID[1] << 16) | (sessionID[2] << 8) | |
toddouska | 0:5045d2638c29 | 1301 | sessionID[3]; |
toddouska | 0:5045d2638c29 | 1302 | } |
toddouska | 0:5045d2638c29 | 1303 | |
toddouska | 0:5045d2638c29 | 1304 | |
toddouska | 0:5045d2638c29 | 1305 | void SSL_flush_sessions(SSL_CTX* ctx, long tm) |
toddouska | 0:5045d2638c29 | 1306 | { |
toddouska | 0:5045d2638c29 | 1307 | /* static table now, no flusing needed */ |
toddouska | 0:5045d2638c29 | 1308 | } |
toddouska | 0:5045d2638c29 | 1309 | |
toddouska | 0:5045d2638c29 | 1310 | |
toddouska | 0:5045d2638c29 | 1311 | SSL_SESSION* GetSession(SSL* ssl, byte* masterSecret) |
toddouska | 0:5045d2638c29 | 1312 | { |
toddouska | 0:5045d2638c29 | 1313 | SSL_SESSION* ret = 0; |
toddouska | 0:5045d2638c29 | 1314 | const byte* id = ssl->arrays.sessionID; |
toddouska | 0:5045d2638c29 | 1315 | word32 row; |
toddouska | 0:5045d2638c29 | 1316 | int idx; |
toddouska | 0:5045d2638c29 | 1317 | |
toddouska | 0:5045d2638c29 | 1318 | if (ssl->options.sessionCacheOff) |
toddouska | 0:5045d2638c29 | 1319 | return 0; |
toddouska | 0:5045d2638c29 | 1320 | |
toddouska | 0:5045d2638c29 | 1321 | row = HashSession(id) % SESSION_ROWS; |
toddouska | 0:5045d2638c29 | 1322 | |
toddouska | 0:5045d2638c29 | 1323 | if (LockMutex(&mutex) != 0) |
toddouska | 0:5045d2638c29 | 1324 | return 0; |
toddouska | 0:5045d2638c29 | 1325 | |
toddouska | 0:5045d2638c29 | 1326 | if (SessionCache[row].totalCount >= SESSIONS_PER_ROW) |
toddouska | 0:5045d2638c29 | 1327 | idx = SESSIONS_PER_ROW - 1; |
toddouska | 0:5045d2638c29 | 1328 | else |
toddouska | 0:5045d2638c29 | 1329 | idx = SessionCache[row].nextIdx - 1; |
toddouska | 0:5045d2638c29 | 1330 | |
toddouska | 0:5045d2638c29 | 1331 | for (; idx >= 0; idx--) { |
toddouska | 0:5045d2638c29 | 1332 | SSL_SESSION* current; |
toddouska | 0:5045d2638c29 | 1333 | |
toddouska | 0:5045d2638c29 | 1334 | if (idx >= SESSIONS_PER_ROW) /* server could have restarted, idx */ |
toddouska | 0:5045d2638c29 | 1335 | break; /* would be word32(-1) and seg fault */ |
toddouska | 0:5045d2638c29 | 1336 | |
toddouska | 0:5045d2638c29 | 1337 | current = &SessionCache[row].Sessions[idx]; |
toddouska | 0:5045d2638c29 | 1338 | if (XMEMCMP(current->sessionID, id, ID_LEN) == 0) { |
toddouska | 0:5045d2638c29 | 1339 | if (LowResTimer() < (current->bornOn + current->timeout)) { |
toddouska | 0:5045d2638c29 | 1340 | ret = current; |
toddouska | 0:5045d2638c29 | 1341 | if (masterSecret) |
toddouska | 0:5045d2638c29 | 1342 | XMEMCPY(masterSecret, current->masterSecret, SECRET_LEN); |
toddouska | 0:5045d2638c29 | 1343 | } |
toddouska | 0:5045d2638c29 | 1344 | break; |
toddouska | 0:5045d2638c29 | 1345 | } |
toddouska | 0:5045d2638c29 | 1346 | } |
toddouska | 0:5045d2638c29 | 1347 | |
toddouska | 0:5045d2638c29 | 1348 | UnLockMutex(&mutex); |
toddouska | 0:5045d2638c29 | 1349 | |
toddouska | 0:5045d2638c29 | 1350 | return ret; |
toddouska | 0:5045d2638c29 | 1351 | } |
toddouska | 0:5045d2638c29 | 1352 | |
toddouska | 0:5045d2638c29 | 1353 | |
toddouska | 0:5045d2638c29 | 1354 | int SetSession(SSL* ssl, SSL_SESSION* session) |
toddouska | 0:5045d2638c29 | 1355 | { |
toddouska | 0:5045d2638c29 | 1356 | if (ssl->options.sessionCacheOff) |
toddouska | 0:5045d2638c29 | 1357 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 1358 | |
toddouska | 0:5045d2638c29 | 1359 | if (LowResTimer() < (session->bornOn + session->timeout)) { |
toddouska | 0:5045d2638c29 | 1360 | ssl->session = *session; |
toddouska | 0:5045d2638c29 | 1361 | ssl->options.resuming = 1; |
toddouska | 0:5045d2638c29 | 1362 | |
toddouska | 0:5045d2638c29 | 1363 | #ifdef SESSION_CERTS |
toddouska | 0:5045d2638c29 | 1364 | ssl->version = session->version; |
toddouska | 0:5045d2638c29 | 1365 | ssl->options.cipherSuite = session->cipherSuite; |
toddouska | 0:5045d2638c29 | 1366 | #endif |
toddouska | 0:5045d2638c29 | 1367 | |
toddouska | 0:5045d2638c29 | 1368 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1369 | } |
toddouska | 0:5045d2638c29 | 1370 | return SSL_FAILURE; /* session timed out */ |
toddouska | 0:5045d2638c29 | 1371 | } |
toddouska | 0:5045d2638c29 | 1372 | |
toddouska | 0:5045d2638c29 | 1373 | |
toddouska | 0:5045d2638c29 | 1374 | int AddSession(SSL* ssl) |
toddouska | 0:5045d2638c29 | 1375 | { |
toddouska | 0:5045d2638c29 | 1376 | word32 row, idx; |
toddouska | 0:5045d2638c29 | 1377 | |
toddouska | 0:5045d2638c29 | 1378 | if (ssl->options.sessionCacheOff) |
toddouska | 0:5045d2638c29 | 1379 | return 0; |
toddouska | 0:5045d2638c29 | 1380 | |
toddouska | 0:5045d2638c29 | 1381 | row = HashSession(ssl->arrays.sessionID) % SESSION_ROWS; |
toddouska | 0:5045d2638c29 | 1382 | |
toddouska | 0:5045d2638c29 | 1383 | if (LockMutex(&mutex) != 0) |
toddouska | 0:5045d2638c29 | 1384 | return -1; |
toddouska | 0:5045d2638c29 | 1385 | |
toddouska | 0:5045d2638c29 | 1386 | idx = SessionCache[row].nextIdx++; |
toddouska | 0:5045d2638c29 | 1387 | |
toddouska | 0:5045d2638c29 | 1388 | XMEMCPY(SessionCache[row].Sessions[idx].masterSecret, |
toddouska | 0:5045d2638c29 | 1389 | ssl->arrays.masterSecret, SECRET_LEN); |
toddouska | 0:5045d2638c29 | 1390 | XMEMCPY(SessionCache[row].Sessions[idx].sessionID, ssl->arrays.sessionID, |
toddouska | 0:5045d2638c29 | 1391 | ID_LEN); |
toddouska | 0:5045d2638c29 | 1392 | |
toddouska | 0:5045d2638c29 | 1393 | SessionCache[row].Sessions[idx].timeout = DEFAULT_TIMEOUT; |
toddouska | 0:5045d2638c29 | 1394 | SessionCache[row].Sessions[idx].bornOn = LowResTimer(); |
toddouska | 0:5045d2638c29 | 1395 | |
toddouska | 0:5045d2638c29 | 1396 | #ifdef SESSION_CERTS |
toddouska | 0:5045d2638c29 | 1397 | SessionCache[row].Sessions[idx].chain.count = ssl->session.chain.count; |
toddouska | 0:5045d2638c29 | 1398 | XMEMCPY(SessionCache[row].Sessions[idx].chain.certs, |
toddouska | 0:5045d2638c29 | 1399 | ssl->session.chain.certs, sizeof(x509_buffer) * MAX_CHAIN_DEPTH); |
toddouska | 0:5045d2638c29 | 1400 | |
toddouska | 0:5045d2638c29 | 1401 | SessionCache[row].Sessions[idx].version = ssl->version; |
toddouska | 0:5045d2638c29 | 1402 | SessionCache[row].Sessions[idx].cipherSuite = ssl->options.cipherSuite; |
toddouska | 0:5045d2638c29 | 1403 | #endif |
toddouska | 0:5045d2638c29 | 1404 | |
toddouska | 0:5045d2638c29 | 1405 | SessionCache[row].totalCount++; |
toddouska | 0:5045d2638c29 | 1406 | if (SessionCache[row].nextIdx == SESSIONS_PER_ROW) |
toddouska | 0:5045d2638c29 | 1407 | SessionCache[row].nextIdx = 0; |
toddouska | 0:5045d2638c29 | 1408 | |
toddouska | 0:5045d2638c29 | 1409 | if (UnLockMutex(&mutex) != 0) |
toddouska | 0:5045d2638c29 | 1410 | return -1; |
toddouska | 0:5045d2638c29 | 1411 | |
toddouska | 0:5045d2638c29 | 1412 | return 0; |
toddouska | 0:5045d2638c29 | 1413 | } |
toddouska | 0:5045d2638c29 | 1414 | |
toddouska | 0:5045d2638c29 | 1415 | |
toddouska | 0:5045d2638c29 | 1416 | #ifdef SESSION_STATS |
toddouska | 0:5045d2638c29 | 1417 | |
toddouska | 0:5045d2638c29 | 1418 | void PrintSessionStats(void) |
toddouska | 0:5045d2638c29 | 1419 | { |
toddouska | 0:5045d2638c29 | 1420 | word32 totalSessionsSeen = 0; |
toddouska | 0:5045d2638c29 | 1421 | word32 totalSessionsNow = 0; |
toddouska | 0:5045d2638c29 | 1422 | word32 rowNow; |
toddouska | 0:5045d2638c29 | 1423 | int i; |
toddouska | 0:5045d2638c29 | 1424 | double E; /* expected freq */ |
toddouska | 0:5045d2638c29 | 1425 | double chiSquare = 0; |
toddouska | 0:5045d2638c29 | 1426 | |
toddouska | 0:5045d2638c29 | 1427 | for (i = 0; i < SESSION_ROWS; i++) { |
toddouska | 0:5045d2638c29 | 1428 | totalSessionsSeen += SessionCache[i].totalCount; |
toddouska | 0:5045d2638c29 | 1429 | |
toddouska | 0:5045d2638c29 | 1430 | if (SessionCache[i].totalCount >= SESSIONS_PER_ROW) |
toddouska | 0:5045d2638c29 | 1431 | rowNow = SESSIONS_PER_ROW; |
toddouska | 0:5045d2638c29 | 1432 | else if (SessionCache[i].nextIdx == 0) |
toddouska | 0:5045d2638c29 | 1433 | rowNow = 0; |
toddouska | 0:5045d2638c29 | 1434 | else |
toddouska | 0:5045d2638c29 | 1435 | rowNow = SessionCache[i].nextIdx; |
toddouska | 0:5045d2638c29 | 1436 | |
toddouska | 0:5045d2638c29 | 1437 | totalSessionsNow += rowNow; |
toddouska | 0:5045d2638c29 | 1438 | } |
toddouska | 0:5045d2638c29 | 1439 | |
toddouska | 0:5045d2638c29 | 1440 | printf("Total Sessions Seen = %d\n", totalSessionsSeen); |
toddouska | 0:5045d2638c29 | 1441 | printf("Total Sessions Now = %d\n", totalSessionsNow); |
toddouska | 0:5045d2638c29 | 1442 | |
toddouska | 0:5045d2638c29 | 1443 | E = (double)totalSessionsSeen / SESSION_ROWS; |
toddouska | 0:5045d2638c29 | 1444 | |
toddouska | 0:5045d2638c29 | 1445 | for (i = 0; i < SESSION_ROWS; i++) { |
toddouska | 0:5045d2638c29 | 1446 | double diff = SessionCache[i].totalCount - E; |
toddouska | 0:5045d2638c29 | 1447 | diff *= diff; /* sqaure */ |
toddouska | 0:5045d2638c29 | 1448 | diff /= E; /* normalize */ |
toddouska | 0:5045d2638c29 | 1449 | |
toddouska | 0:5045d2638c29 | 1450 | chiSquare += diff; |
toddouska | 0:5045d2638c29 | 1451 | } |
toddouska | 0:5045d2638c29 | 1452 | printf(" chi-square = %5.1f, d.f. = %d\n", chiSquare, |
toddouska | 0:5045d2638c29 | 1453 | SESSION_ROWS - 1); |
toddouska | 0:5045d2638c29 | 1454 | if (SESSION_ROWS == 11) |
toddouska | 0:5045d2638c29 | 1455 | printf(" .05 p value = 18.3, chi-square should be less\n"); |
toddouska | 0:5045d2638c29 | 1456 | else if (SESSION_ROWS == 211) |
toddouska | 0:5045d2638c29 | 1457 | printf(".05 p value = 244.8, chi-square should be less\n"); |
toddouska | 0:5045d2638c29 | 1458 | else if (SESSION_ROWS == 5981) |
toddouska | 0:5045d2638c29 | 1459 | printf(".05 p value = 6161.0, chi-square should be less\n"); |
toddouska | 0:5045d2638c29 | 1460 | printf("\n"); |
toddouska | 0:5045d2638c29 | 1461 | } |
toddouska | 0:5045d2638c29 | 1462 | |
toddouska | 0:5045d2638c29 | 1463 | #endif /* SESSION_STATS */ |
toddouska | 0:5045d2638c29 | 1464 | |
toddouska | 0:5045d2638c29 | 1465 | #endif /* NO_SESSION_CACHE */ |
toddouska | 0:5045d2638c29 | 1466 | |
toddouska | 0:5045d2638c29 | 1467 | |
toddouska | 0:5045d2638c29 | 1468 | /* call before SSL_connect, if verifying will add name check to |
toddouska | 0:5045d2638c29 | 1469 | date check and signature check */ |
toddouska | 0:5045d2638c29 | 1470 | int CyaSSL_check_domain_name(SSL* ssl, const char* dn) |
toddouska | 0:5045d2638c29 | 1471 | { |
toddouska | 0:5045d2638c29 | 1472 | if (ssl->buffers.domainName.buffer) |
toddouska | 0:5045d2638c29 | 1473 | XFREE(ssl->buffers.domainName.buffer, ssl->heap, DYNAMIC_TYPE_DOMAIN); |
toddouska | 0:5045d2638c29 | 1474 | |
toddouska | 0:5045d2638c29 | 1475 | ssl->buffers.domainName.length = (word32)XSTRLEN(dn) + 1; |
toddouska | 0:5045d2638c29 | 1476 | ssl->buffers.domainName.buffer = (byte*) XMALLOC( |
toddouska | 0:5045d2638c29 | 1477 | ssl->buffers.domainName.length, ssl->heap, DYNAMIC_TYPE_DOMAIN); |
toddouska | 0:5045d2638c29 | 1478 | |
toddouska | 0:5045d2638c29 | 1479 | if (ssl->buffers.domainName.buffer) { |
toddouska | 0:5045d2638c29 | 1480 | XSTRNCPY((char*)ssl->buffers.domainName.buffer, dn, |
toddouska | 0:5045d2638c29 | 1481 | ssl->buffers.domainName.length); |
toddouska | 0:5045d2638c29 | 1482 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1483 | } |
toddouska | 0:5045d2638c29 | 1484 | else { |
toddouska | 0:5045d2638c29 | 1485 | ssl->error = MEMORY_ERROR; |
toddouska | 0:5045d2638c29 | 1486 | return SSL_FAILURE; |
toddouska | 0:5045d2638c29 | 1487 | } |
toddouska | 0:5045d2638c29 | 1488 | } |
toddouska | 0:5045d2638c29 | 1489 | |
toddouska | 0:5045d2638c29 | 1490 | |
toddouska | 0:5045d2638c29 | 1491 | /* turn on CyaSSL zlib compression |
toddouska | 0:5045d2638c29 | 1492 | returns 0 for success, else error (not built in) |
toddouska | 0:5045d2638c29 | 1493 | */ |
toddouska | 0:5045d2638c29 | 1494 | int CyaSSL_set_compression(SSL* ssl) |
toddouska | 0:5045d2638c29 | 1495 | { |
toddouska | 0:5045d2638c29 | 1496 | #ifdef HAVE_LIBZ |
toddouska | 0:5045d2638c29 | 1497 | ssl->options.usingCompression = 1; |
toddouska | 0:5045d2638c29 | 1498 | return 0; |
toddouska | 0:5045d2638c29 | 1499 | #else |
toddouska | 0:5045d2638c29 | 1500 | return -1; |
toddouska | 0:5045d2638c29 | 1501 | #endif |
toddouska | 0:5045d2638c29 | 1502 | } |
toddouska | 0:5045d2638c29 | 1503 | |
toddouska | 0:5045d2638c29 | 1504 | |
toddouska | 0:5045d2638c29 | 1505 | #ifndef USE_WINDOWS_API |
toddouska | 0:5045d2638c29 | 1506 | #ifndef NO_WRITEV |
toddouska | 0:5045d2638c29 | 1507 | |
toddouska | 0:5045d2638c29 | 1508 | /* simulate writev semantics, doesn't actually do block at a time though |
toddouska | 0:5045d2638c29 | 1509 | because of SSL_write behavior and because front adds may be small */ |
toddouska | 0:5045d2638c29 | 1510 | int CyaSSL_writev(SSL* ssl, const struct iovec* iov, int iovcnt) |
toddouska | 0:5045d2638c29 | 1511 | { |
toddouska | 0:5045d2638c29 | 1512 | byte tmp[OUTPUT_RECORD_SIZE]; |
toddouska | 0:5045d2638c29 | 1513 | byte* buffer = tmp; |
toddouska | 0:5045d2638c29 | 1514 | int send = 0; |
toddouska | 0:5045d2638c29 | 1515 | int newBuffer = 0; |
toddouska | 0:5045d2638c29 | 1516 | int idx = 0; |
toddouska | 0:5045d2638c29 | 1517 | int i; |
toddouska | 0:5045d2638c29 | 1518 | int ret; |
toddouska | 0:5045d2638c29 | 1519 | |
toddouska | 0:5045d2638c29 | 1520 | for (i = 0; i < iovcnt; i++) |
toddouska | 0:5045d2638c29 | 1521 | send += iov[i].iov_len; |
toddouska | 0:5045d2638c29 | 1522 | |
toddouska | 0:5045d2638c29 | 1523 | if (send > sizeof(tmp)) { |
toddouska | 0:5045d2638c29 | 1524 | byte* tmp2 = (byte*) XMALLOC(send, ssl->heap, |
toddouska | 0:5045d2638c29 | 1525 | DYNAMIC_TYPE_WRITEV); |
toddouska | 0:5045d2638c29 | 1526 | if (!tmp2) |
toddouska | 0:5045d2638c29 | 1527 | return MEMORY_ERROR; |
toddouska | 0:5045d2638c29 | 1528 | buffer = tmp2; |
toddouska | 0:5045d2638c29 | 1529 | newBuffer = 1; |
toddouska | 0:5045d2638c29 | 1530 | } |
toddouska | 0:5045d2638c29 | 1531 | |
toddouska | 0:5045d2638c29 | 1532 | for (i = 0; i < iovcnt; i++) { |
toddouska | 0:5045d2638c29 | 1533 | XMEMCPY(&buffer[idx], iov[i].iov_base, iov[i].iov_len); |
toddouska | 0:5045d2638c29 | 1534 | idx += iov[i].iov_len; |
toddouska | 0:5045d2638c29 | 1535 | } |
toddouska | 0:5045d2638c29 | 1536 | |
toddouska | 0:5045d2638c29 | 1537 | ret = SSL_write(ssl, buffer, send); |
toddouska | 0:5045d2638c29 | 1538 | |
toddouska | 0:5045d2638c29 | 1539 | if (newBuffer) XFREE(buffer, ssl->heap, DYNAMIC_TYPE_WRITEV); |
toddouska | 0:5045d2638c29 | 1540 | |
toddouska | 0:5045d2638c29 | 1541 | return ret; |
toddouska | 0:5045d2638c29 | 1542 | } |
toddouska | 0:5045d2638c29 | 1543 | #endif |
toddouska | 0:5045d2638c29 | 1544 | #endif |
toddouska | 0:5045d2638c29 | 1545 | |
toddouska | 0:5045d2638c29 | 1546 | |
toddouska | 0:5045d2638c29 | 1547 | #ifdef CYASSL_CALLBACKS |
toddouska | 0:5045d2638c29 | 1548 | |
toddouska | 0:5045d2638c29 | 1549 | typedef struct itimerval Itimerval; |
toddouska | 0:5045d2638c29 | 1550 | |
toddouska | 0:5045d2638c29 | 1551 | /* don't keep calling simple functions while setting up timer and singals |
toddouska | 0:5045d2638c29 | 1552 | if no inlining these are the next best */ |
toddouska | 0:5045d2638c29 | 1553 | |
toddouska | 0:5045d2638c29 | 1554 | #define AddTimes(a, b, c) \ |
toddouska | 0:5045d2638c29 | 1555 | do { \ |
toddouska | 0:5045d2638c29 | 1556 | c.tv_sec = a.tv_sec + b.tv_sec; \ |
toddouska | 0:5045d2638c29 | 1557 | c.tv_usec = a.tv_usec + b.tv_usec; \ |
toddouska | 0:5045d2638c29 | 1558 | if (c.tv_sec >= 1000000) { \ |
toddouska | 0:5045d2638c29 | 1559 | c.tv_sec++; \ |
toddouska | 0:5045d2638c29 | 1560 | c.tv_usec -= 1000000; \ |
toddouska | 0:5045d2638c29 | 1561 | } \ |
toddouska | 0:5045d2638c29 | 1562 | } while (0) |
toddouska | 0:5045d2638c29 | 1563 | |
toddouska | 0:5045d2638c29 | 1564 | |
toddouska | 0:5045d2638c29 | 1565 | #define SubtractTimes(a, b, c) \ |
toddouska | 0:5045d2638c29 | 1566 | do { \ |
toddouska | 0:5045d2638c29 | 1567 | c.tv_sec = a.tv_sec - b.tv_sec; \ |
toddouska | 0:5045d2638c29 | 1568 | c.tv_usec = a.tv_usec - b.tv_usec; \ |
toddouska | 0:5045d2638c29 | 1569 | if (c.tv_sec < 0) { \ |
toddouska | 0:5045d2638c29 | 1570 | c.tv_sec--; \ |
toddouska | 0:5045d2638c29 | 1571 | c.tv_usec += 1000000; \ |
toddouska | 0:5045d2638c29 | 1572 | } \ |
toddouska | 0:5045d2638c29 | 1573 | } while (0) |
toddouska | 0:5045d2638c29 | 1574 | |
toddouska | 0:5045d2638c29 | 1575 | #define CmpTimes(a, b, cmp) \ |
toddouska | 0:5045d2638c29 | 1576 | ((a.tv_sec == b.tv_sec) ? \ |
toddouska | 0:5045d2638c29 | 1577 | (a.tv_usec cmp b.tv_usec) : \ |
toddouska | 0:5045d2638c29 | 1578 | (a.tv_sec cmp b.tv_sec)) \ |
toddouska | 0:5045d2638c29 | 1579 | |
toddouska | 0:5045d2638c29 | 1580 | |
toddouska | 0:5045d2638c29 | 1581 | /* do nothing handler */ |
toddouska | 0:5045d2638c29 | 1582 | static void myHandler(int signo) |
toddouska | 0:5045d2638c29 | 1583 | { |
toddouska | 0:5045d2638c29 | 1584 | return; |
toddouska | 0:5045d2638c29 | 1585 | } |
toddouska | 0:5045d2638c29 | 1586 | |
toddouska | 0:5045d2638c29 | 1587 | |
toddouska | 0:5045d2638c29 | 1588 | static int CyaSSL_ex_wrapper(SSL* ssl, HandShakeCallBack hsCb, |
toddouska | 0:5045d2638c29 | 1589 | TimeoutCallBack toCb, Timeval timeout) |
toddouska | 0:5045d2638c29 | 1590 | { |
toddouska | 0:5045d2638c29 | 1591 | int ret = -1; |
toddouska | 0:5045d2638c29 | 1592 | int oldTimerOn = 0; /* was timer already on */ |
toddouska | 0:5045d2638c29 | 1593 | Timeval startTime; |
toddouska | 0:5045d2638c29 | 1594 | Timeval endTime; |
toddouska | 0:5045d2638c29 | 1595 | Timeval totalTime; |
toddouska | 0:5045d2638c29 | 1596 | Itimerval myTimeout; |
toddouska | 0:5045d2638c29 | 1597 | Itimerval oldTimeout; /* if old timer adjust from total time to reset */ |
toddouska | 0:5045d2638c29 | 1598 | struct sigaction act, oact; |
toddouska | 0:5045d2638c29 | 1599 | |
toddouska | 0:5045d2638c29 | 1600 | #define ERR_OUT(x) { ssl->hsInfoOn = 0; ssl->toInfoOn = 0; return x; } |
toddouska | 0:5045d2638c29 | 1601 | |
toddouska | 0:5045d2638c29 | 1602 | if (hsCb) { |
toddouska | 0:5045d2638c29 | 1603 | ssl->hsInfoOn = 1; |
toddouska | 0:5045d2638c29 | 1604 | InitHandShakeInfo(&ssl->handShakeInfo); |
toddouska | 0:5045d2638c29 | 1605 | } |
toddouska | 0:5045d2638c29 | 1606 | if (toCb) { |
toddouska | 0:5045d2638c29 | 1607 | ssl->toInfoOn = 1; |
toddouska | 0:5045d2638c29 | 1608 | InitTimeoutInfo(&ssl->timeoutInfo); |
toddouska | 0:5045d2638c29 | 1609 | |
toddouska | 0:5045d2638c29 | 1610 | if (gettimeofday(&startTime, 0) < 0) |
toddouska | 0:5045d2638c29 | 1611 | ERR_OUT(GETTIME_ERROR); |
toddouska | 0:5045d2638c29 | 1612 | |
toddouska | 0:5045d2638c29 | 1613 | /* use setitimer to simulate getitimer, init 0 myTimeout */ |
toddouska | 0:5045d2638c29 | 1614 | myTimeout.it_interval.tv_sec = 0; |
toddouska | 0:5045d2638c29 | 1615 | myTimeout.it_interval.tv_usec = 0; |
toddouska | 0:5045d2638c29 | 1616 | myTimeout.it_value.tv_sec = 0; |
toddouska | 0:5045d2638c29 | 1617 | myTimeout.it_value.tv_usec = 0; |
toddouska | 0:5045d2638c29 | 1618 | if (setitimer(ITIMER_REAL, &myTimeout, &oldTimeout) < 0) |
toddouska | 0:5045d2638c29 | 1619 | ERR_OUT(SETITIMER_ERROR); |
toddouska | 0:5045d2638c29 | 1620 | |
toddouska | 0:5045d2638c29 | 1621 | if (oldTimeout.it_value.tv_sec || oldTimeout.it_value.tv_usec) { |
toddouska | 0:5045d2638c29 | 1622 | oldTimerOn = 1; |
toddouska | 0:5045d2638c29 | 1623 | |
toddouska | 0:5045d2638c29 | 1624 | /* is old timer going to expire before ours */ |
toddouska | 0:5045d2638c29 | 1625 | if (CmpTimes(oldTimeout.it_value, timeout, <)) { |
toddouska | 0:5045d2638c29 | 1626 | timeout.tv_sec = oldTimeout.it_value.tv_sec; |
toddouska | 0:5045d2638c29 | 1627 | timeout.tv_usec = oldTimeout.it_value.tv_usec; |
toddouska | 0:5045d2638c29 | 1628 | } |
toddouska | 0:5045d2638c29 | 1629 | } |
toddouska | 0:5045d2638c29 | 1630 | myTimeout.it_value.tv_sec = timeout.tv_sec; |
toddouska | 0:5045d2638c29 | 1631 | myTimeout.it_value.tv_usec = timeout.tv_usec; |
toddouska | 0:5045d2638c29 | 1632 | |
toddouska | 0:5045d2638c29 | 1633 | /* set up signal handler, don't restart socket send/recv */ |
toddouska | 0:5045d2638c29 | 1634 | act.sa_handler = myHandler; |
toddouska | 0:5045d2638c29 | 1635 | sigemptyset(&act.sa_mask); |
toddouska | 0:5045d2638c29 | 1636 | act.sa_flags = 0; |
toddouska | 0:5045d2638c29 | 1637 | #ifdef SA_INTERRUPT |
toddouska | 0:5045d2638c29 | 1638 | act.sa_flags |= SA_INTERRUPT; |
toddouska | 0:5045d2638c29 | 1639 | #endif |
toddouska | 0:5045d2638c29 | 1640 | if (sigaction(SIGALRM, &act, &oact) < 0) |
toddouska | 0:5045d2638c29 | 1641 | ERR_OUT(SIGACT_ERROR); |
toddouska | 0:5045d2638c29 | 1642 | |
toddouska | 0:5045d2638c29 | 1643 | if (setitimer(ITIMER_REAL, &myTimeout, 0) < 0) |
toddouska | 0:5045d2638c29 | 1644 | ERR_OUT(SETITIMER_ERROR); |
toddouska | 0:5045d2638c29 | 1645 | } |
toddouska | 0:5045d2638c29 | 1646 | |
toddouska | 0:5045d2638c29 | 1647 | /* do main work */ |
toddouska | 0:5045d2638c29 | 1648 | #ifndef NO_CYASSL_CLIENT |
toddouska | 0:5045d2638c29 | 1649 | if (ssl->options.side == CLIENT_END) |
toddouska | 0:5045d2638c29 | 1650 | ret = SSL_connect(ssl); |
toddouska | 0:5045d2638c29 | 1651 | #endif |
toddouska | 0:5045d2638c29 | 1652 | #ifndef NO_CYASSL_SERVER |
toddouska | 0:5045d2638c29 | 1653 | if (ssl->options.side == SERVER_END) |
toddouska | 0:5045d2638c29 | 1654 | ret = SSL_accept(ssl); |
toddouska | 0:5045d2638c29 | 1655 | #endif |
toddouska | 0:5045d2638c29 | 1656 | |
toddouska | 0:5045d2638c29 | 1657 | /* do callbacks */ |
toddouska | 0:5045d2638c29 | 1658 | if (toCb) { |
toddouska | 0:5045d2638c29 | 1659 | if (oldTimerOn) { |
toddouska | 0:5045d2638c29 | 1660 | gettimeofday(&endTime, 0); |
toddouska | 0:5045d2638c29 | 1661 | SubtractTimes(endTime, startTime, totalTime); |
toddouska | 0:5045d2638c29 | 1662 | /* adjust old timer for elapsed time */ |
toddouska | 0:5045d2638c29 | 1663 | if (CmpTimes(totalTime, oldTimeout.it_value, <)) |
toddouska | 0:5045d2638c29 | 1664 | SubtractTimes(oldTimeout.it_value, totalTime, |
toddouska | 0:5045d2638c29 | 1665 | oldTimeout.it_value); |
toddouska | 0:5045d2638c29 | 1666 | else { |
toddouska | 0:5045d2638c29 | 1667 | /* reset value to interval, may be off */ |
toddouska | 0:5045d2638c29 | 1668 | oldTimeout.it_value.tv_sec = oldTimeout.it_interval.tv_sec; |
toddouska | 0:5045d2638c29 | 1669 | oldTimeout.it_value.tv_usec =oldTimeout.it_interval.tv_usec; |
toddouska | 0:5045d2638c29 | 1670 | } |
toddouska | 0:5045d2638c29 | 1671 | /* keep iter the same whether there or not */ |
toddouska | 0:5045d2638c29 | 1672 | } |
toddouska | 0:5045d2638c29 | 1673 | /* restore old handler */ |
toddouska | 0:5045d2638c29 | 1674 | if (sigaction(SIGALRM, &oact, 0) < 0) |
toddouska | 0:5045d2638c29 | 1675 | ret = SIGACT_ERROR; /* more pressing error, stomp */ |
toddouska | 0:5045d2638c29 | 1676 | else |
toddouska | 0:5045d2638c29 | 1677 | /* use old settings which may turn off (expired or not there) */ |
toddouska | 0:5045d2638c29 | 1678 | if (setitimer(ITIMER_REAL, &oldTimeout, 0) < 0) |
toddouska | 0:5045d2638c29 | 1679 | ret = SETITIMER_ERROR; |
toddouska | 0:5045d2638c29 | 1680 | |
toddouska | 0:5045d2638c29 | 1681 | /* if we had a timeout call callback */ |
toddouska | 0:5045d2638c29 | 1682 | if (ssl->timeoutInfo.timeoutName[0]) { |
toddouska | 0:5045d2638c29 | 1683 | ssl->timeoutInfo.timeoutValue.tv_sec = timeout.tv_sec; |
toddouska | 0:5045d2638c29 | 1684 | ssl->timeoutInfo.timeoutValue.tv_usec = timeout.tv_usec; |
toddouska | 0:5045d2638c29 | 1685 | (toCb)(&ssl->timeoutInfo); |
toddouska | 0:5045d2638c29 | 1686 | } |
toddouska | 0:5045d2638c29 | 1687 | /* clean up */ |
toddouska | 0:5045d2638c29 | 1688 | FreeTimeoutInfo(&ssl->timeoutInfo, ssl->heap); |
toddouska | 0:5045d2638c29 | 1689 | ssl->toInfoOn = 0; |
toddouska | 0:5045d2638c29 | 1690 | } |
toddouska | 0:5045d2638c29 | 1691 | if (hsCb) { |
toddouska | 0:5045d2638c29 | 1692 | FinishHandShakeInfo(&ssl->handShakeInfo, ssl); |
toddouska | 0:5045d2638c29 | 1693 | (hsCb)(&ssl->handShakeInfo); |
toddouska | 0:5045d2638c29 | 1694 | ssl->hsInfoOn = 0; |
toddouska | 0:5045d2638c29 | 1695 | } |
toddouska | 0:5045d2638c29 | 1696 | return ret; |
toddouska | 0:5045d2638c29 | 1697 | } |
toddouska | 0:5045d2638c29 | 1698 | |
toddouska | 0:5045d2638c29 | 1699 | |
toddouska | 0:5045d2638c29 | 1700 | #ifndef NO_CYASSL_CLIENT |
toddouska | 0:5045d2638c29 | 1701 | |
toddouska | 0:5045d2638c29 | 1702 | int CyaSSL_connect_ex(SSL* ssl, HandShakeCallBack hsCb, |
toddouska | 0:5045d2638c29 | 1703 | TimeoutCallBack toCb, Timeval timeout) |
toddouska | 0:5045d2638c29 | 1704 | { |
toddouska | 0:5045d2638c29 | 1705 | return CyaSSL_ex_wrapper(ssl, hsCb, toCb, timeout); |
toddouska | 0:5045d2638c29 | 1706 | } |
toddouska | 0:5045d2638c29 | 1707 | |
toddouska | 0:5045d2638c29 | 1708 | #endif |
toddouska | 0:5045d2638c29 | 1709 | |
toddouska | 0:5045d2638c29 | 1710 | |
toddouska | 0:5045d2638c29 | 1711 | #ifndef NO_CYASSL_SERVER |
toddouska | 0:5045d2638c29 | 1712 | |
toddouska | 0:5045d2638c29 | 1713 | int CyaSSL_accept_ex(SSL* ssl, HandShakeCallBack hsCb, |
toddouska | 0:5045d2638c29 | 1714 | TimeoutCallBack toCb,Timeval timeout) |
toddouska | 0:5045d2638c29 | 1715 | { |
toddouska | 0:5045d2638c29 | 1716 | return CyaSSL_ex_wrapper(ssl, hsCb, toCb, timeout); |
toddouska | 0:5045d2638c29 | 1717 | } |
toddouska | 0:5045d2638c29 | 1718 | |
toddouska | 0:5045d2638c29 | 1719 | #endif |
toddouska | 0:5045d2638c29 | 1720 | |
toddouska | 0:5045d2638c29 | 1721 | #endif /* CYASSL_CALLBACKS */ |
toddouska | 0:5045d2638c29 | 1722 | |
toddouska | 0:5045d2638c29 | 1723 | |
toddouska | 0:5045d2638c29 | 1724 | #ifndef NO_PSK |
toddouska | 0:5045d2638c29 | 1725 | |
toddouska | 0:5045d2638c29 | 1726 | void SSL_CTX_set_psk_client_callback(SSL_CTX* ctx, psk_client_callback cb) |
toddouska | 0:5045d2638c29 | 1727 | { |
toddouska | 0:5045d2638c29 | 1728 | ctx->havePSK = 1; |
toddouska | 0:5045d2638c29 | 1729 | ctx->client_psk_cb = cb; |
toddouska | 0:5045d2638c29 | 1730 | } |
toddouska | 0:5045d2638c29 | 1731 | |
toddouska | 0:5045d2638c29 | 1732 | |
toddouska | 0:5045d2638c29 | 1733 | void SSL_set_psk_client_callback(SSL* ssl, psk_client_callback cb) |
toddouska | 0:5045d2638c29 | 1734 | { |
toddouska | 0:5045d2638c29 | 1735 | ssl->options.havePSK = 1; |
toddouska | 0:5045d2638c29 | 1736 | ssl->options.client_psk_cb = cb; |
toddouska | 0:5045d2638c29 | 1737 | |
toddouska | 0:5045d2638c29 | 1738 | InitSuites(&ssl->suites, ssl->version,TRUE,TRUE, ssl->options.haveNTRU); |
toddouska | 0:5045d2638c29 | 1739 | } |
toddouska | 0:5045d2638c29 | 1740 | |
toddouska | 0:5045d2638c29 | 1741 | |
toddouska | 0:5045d2638c29 | 1742 | void SSL_CTX_set_psk_server_callback(SSL_CTX* ctx, psk_server_callback cb) |
toddouska | 0:5045d2638c29 | 1743 | { |
toddouska | 0:5045d2638c29 | 1744 | ctx->havePSK = 1; |
toddouska | 0:5045d2638c29 | 1745 | ctx->server_psk_cb = cb; |
toddouska | 0:5045d2638c29 | 1746 | } |
toddouska | 0:5045d2638c29 | 1747 | |
toddouska | 0:5045d2638c29 | 1748 | |
toddouska | 0:5045d2638c29 | 1749 | void SSL_set_psk_server_callback(SSL* ssl, psk_server_callback cb) |
toddouska | 0:5045d2638c29 | 1750 | { |
toddouska | 0:5045d2638c29 | 1751 | ssl->options.havePSK = 1; |
toddouska | 0:5045d2638c29 | 1752 | ssl->options.server_psk_cb = cb; |
toddouska | 0:5045d2638c29 | 1753 | |
toddouska | 0:5045d2638c29 | 1754 | InitSuites(&ssl->suites, ssl->version, ssl->options.haveDH, TRUE, |
toddouska | 0:5045d2638c29 | 1755 | ssl->options.haveNTRU); |
toddouska | 0:5045d2638c29 | 1756 | } |
toddouska | 0:5045d2638c29 | 1757 | |
toddouska | 0:5045d2638c29 | 1758 | |
toddouska | 0:5045d2638c29 | 1759 | const char* SSL_get_psk_identity_hint(const SSL* ssl) |
toddouska | 0:5045d2638c29 | 1760 | { |
toddouska | 0:5045d2638c29 | 1761 | return ssl->arrays.server_hint; |
toddouska | 0:5045d2638c29 | 1762 | } |
toddouska | 0:5045d2638c29 | 1763 | |
toddouska | 0:5045d2638c29 | 1764 | |
toddouska | 0:5045d2638c29 | 1765 | const char* SSL_get_psk_identity(const SSL* ssl) |
toddouska | 0:5045d2638c29 | 1766 | { |
toddouska | 0:5045d2638c29 | 1767 | return ssl->arrays.client_identity; |
toddouska | 0:5045d2638c29 | 1768 | } |
toddouska | 0:5045d2638c29 | 1769 | |
toddouska | 0:5045d2638c29 | 1770 | |
toddouska | 0:5045d2638c29 | 1771 | int SSL_CTX_use_psk_identity_hint(SSL_CTX* ctx, const char* hint) |
toddouska | 0:5045d2638c29 | 1772 | { |
toddouska | 0:5045d2638c29 | 1773 | if (hint == 0) |
toddouska | 0:5045d2638c29 | 1774 | ctx->server_hint[0] = 0; |
toddouska | 0:5045d2638c29 | 1775 | else |
toddouska | 0:5045d2638c29 | 1776 | XSTRNCPY(ctx->server_hint, hint, MAX_PSK_ID_LEN); |
toddouska | 0:5045d2638c29 | 1777 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1778 | } |
toddouska | 0:5045d2638c29 | 1779 | |
toddouska | 0:5045d2638c29 | 1780 | |
toddouska | 0:5045d2638c29 | 1781 | int SSL_use_psk_identity_hint(SSL* ssl, const char* hint) |
toddouska | 0:5045d2638c29 | 1782 | { |
toddouska | 0:5045d2638c29 | 1783 | if (hint == 0) |
toddouska | 0:5045d2638c29 | 1784 | ssl->arrays.server_hint[0] = 0; |
toddouska | 0:5045d2638c29 | 1785 | else |
toddouska | 0:5045d2638c29 | 1786 | XSTRNCPY(ssl->arrays.server_hint, hint, MAX_PSK_ID_LEN); |
toddouska | 0:5045d2638c29 | 1787 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1788 | } |
toddouska | 0:5045d2638c29 | 1789 | |
toddouska | 0:5045d2638c29 | 1790 | #endif /* NO_PSK */ |
toddouska | 0:5045d2638c29 | 1791 | |
toddouska | 0:5045d2638c29 | 1792 | |
toddouska | 0:5045d2638c29 | 1793 | #if defined(NO_FILESYSTEM) || defined(MICRIUM) |
toddouska | 0:5045d2638c29 | 1794 | |
toddouska | 0:5045d2638c29 | 1795 | /* CyaSSL extension allows DER files to be loaded from buffers as well */ |
toddouska | 0:5045d2638c29 | 1796 | int CyaSSL_CTX_load_verify_buffer(SSL_CTX* ctx, const unsigned char* buffer, |
toddouska | 0:5045d2638c29 | 1797 | long sz, int format) |
toddouska | 0:5045d2638c29 | 1798 | { |
toddouska | 0:5045d2638c29 | 1799 | return ProcessBuffer(ctx, buffer, sz, format, CA_TYPE); |
toddouska | 0:5045d2638c29 | 1800 | } |
toddouska | 0:5045d2638c29 | 1801 | |
toddouska | 0:5045d2638c29 | 1802 | |
toddouska | 0:5045d2638c29 | 1803 | int CyaSSL_CTX_use_certificate_buffer(SSL_CTX* ctx, |
toddouska | 0:5045d2638c29 | 1804 | const unsigned char* buffer,long sz,int format) |
toddouska | 0:5045d2638c29 | 1805 | { |
toddouska | 0:5045d2638c29 | 1806 | return ProcessBuffer(ctx, buffer, sz, format, CERT_TYPE); |
toddouska | 0:5045d2638c29 | 1807 | } |
toddouska | 0:5045d2638c29 | 1808 | |
toddouska | 0:5045d2638c29 | 1809 | |
toddouska | 0:5045d2638c29 | 1810 | int CyaSSL_CTX_use_PrivateKey_buffer(SSL_CTX* ctx, |
toddouska | 0:5045d2638c29 | 1811 | const unsigned char* buffer,long sz,int format) |
toddouska | 0:5045d2638c29 | 1812 | { |
toddouska | 0:5045d2638c29 | 1813 | return ProcessBuffer(ctx, buffer, sz, format, PRIVATEKEY_TYPE); |
toddouska | 0:5045d2638c29 | 1814 | } |
toddouska | 0:5045d2638c29 | 1815 | |
toddouska | 0:5045d2638c29 | 1816 | |
toddouska | 0:5045d2638c29 | 1817 | int CyaSSL_CTX_use_certificate_chain_buffer(SSL_CTX* ctx, |
toddouska | 0:5045d2638c29 | 1818 | const unsigned char* buffer, long sz) |
toddouska | 0:5045d2638c29 | 1819 | { |
toddouska | 0:5045d2638c29 | 1820 | /* add first to ctx, all tested implementations support this */ |
toddouska | 0:5045d2638c29 | 1821 | return ProcessBuffer(ctx, buffer, sz, SSL_FILETYPE_PEM, CA_TYPE); |
toddouska | 0:5045d2638c29 | 1822 | } |
toddouska | 0:5045d2638c29 | 1823 | |
toddouska | 0:5045d2638c29 | 1824 | #endif /* NO_FILESYSTEM || MICRIUM */ |
toddouska | 0:5045d2638c29 | 1825 | |
toddouska | 0:5045d2638c29 | 1826 | |
toddouska | 0:5045d2638c29 | 1827 | #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS) |
toddouska | 0:5045d2638c29 | 1828 | |
toddouska | 0:5045d2638c29 | 1829 | |
toddouska | 0:5045d2638c29 | 1830 | int SSLeay_add_ssl_algorithms(void) |
toddouska | 0:5045d2638c29 | 1831 | { |
toddouska | 0:5045d2638c29 | 1832 | OpenSSL_add_all_algorithms(); |
toddouska | 0:5045d2638c29 | 1833 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1834 | } |
toddouska | 0:5045d2638c29 | 1835 | |
toddouska | 0:5045d2638c29 | 1836 | |
toddouska | 0:5045d2638c29 | 1837 | long SSL_CTX_sess_set_cache_size(SSL_CTX* ctx, long sz) |
toddouska | 0:5045d2638c29 | 1838 | { |
toddouska | 0:5045d2638c29 | 1839 | /* cache size fixed at compile time in CyaSSL */ |
toddouska | 0:5045d2638c29 | 1840 | return 0; |
toddouska | 0:5045d2638c29 | 1841 | } |
toddouska | 0:5045d2638c29 | 1842 | |
toddouska | 0:5045d2638c29 | 1843 | |
toddouska | 0:5045d2638c29 | 1844 | void SSL_CTX_set_quiet_shutdown(SSL_CTX* ctx, int mode) |
toddouska | 0:5045d2638c29 | 1845 | { |
toddouska | 0:5045d2638c29 | 1846 | if (mode) |
toddouska | 0:5045d2638c29 | 1847 | ctx->quietShutdown = 1; |
toddouska | 0:5045d2638c29 | 1848 | } |
toddouska | 0:5045d2638c29 | 1849 | |
toddouska | 0:5045d2638c29 | 1850 | |
toddouska | 0:5045d2638c29 | 1851 | int SSL_CTX_check_private_key(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 1852 | { |
toddouska | 0:5045d2638c29 | 1853 | /* TODO: check private against public for RSA match */ |
toddouska | 0:5045d2638c29 | 1854 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1855 | } |
toddouska | 0:5045d2638c29 | 1856 | |
toddouska | 0:5045d2638c29 | 1857 | |
toddouska | 0:5045d2638c29 | 1858 | void SSL_set_bio(SSL* ssl, BIO* rd, BIO* wr) |
toddouska | 0:5045d2638c29 | 1859 | { |
toddouska | 0:5045d2638c29 | 1860 | SSL_set_rfd(ssl, rd->fd); |
toddouska | 0:5045d2638c29 | 1861 | SSL_set_wfd(ssl, wr->fd); |
toddouska | 0:5045d2638c29 | 1862 | |
toddouska | 0:5045d2638c29 | 1863 | ssl->biord = rd; |
toddouska | 0:5045d2638c29 | 1864 | ssl->biowr = wr; |
toddouska | 0:5045d2638c29 | 1865 | } |
toddouska | 0:5045d2638c29 | 1866 | |
toddouska | 0:5045d2638c29 | 1867 | |
toddouska | 0:5045d2638c29 | 1868 | void SSL_CTX_set_client_CA_list(SSL_CTX* ctx, STACK_OF(X509_NAME)* names) |
toddouska | 0:5045d2638c29 | 1869 | { |
toddouska | 0:5045d2638c29 | 1870 | |
toddouska | 0:5045d2638c29 | 1871 | } |
toddouska | 0:5045d2638c29 | 1872 | |
toddouska | 0:5045d2638c29 | 1873 | |
toddouska | 0:5045d2638c29 | 1874 | STACK_OF(X509_NAME)* SSL_load_client_CA_file(const char* fname) |
toddouska | 0:5045d2638c29 | 1875 | { |
toddouska | 0:5045d2638c29 | 1876 | return 0; |
toddouska | 0:5045d2638c29 | 1877 | } |
toddouska | 0:5045d2638c29 | 1878 | |
toddouska | 0:5045d2638c29 | 1879 | |
toddouska | 0:5045d2638c29 | 1880 | int SSL_CTX_set_default_verify_paths(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 1881 | { |
toddouska | 0:5045d2638c29 | 1882 | /* TODO:, not needed in goahead */ |
toddouska | 0:5045d2638c29 | 1883 | return SSL_NOT_IMPLEMENTED; |
toddouska | 0:5045d2638c29 | 1884 | } |
toddouska | 0:5045d2638c29 | 1885 | |
toddouska | 0:5045d2638c29 | 1886 | |
toddouska | 0:5045d2638c29 | 1887 | void SSL_set_accept_state(SSL* ssl) |
toddouska | 0:5045d2638c29 | 1888 | { |
toddouska | 0:5045d2638c29 | 1889 | byte havePSK = 0; |
toddouska | 0:5045d2638c29 | 1890 | |
toddouska | 0:5045d2638c29 | 1891 | ssl->options.side = SERVER_END; |
toddouska | 0:5045d2638c29 | 1892 | /* reset suites in case user switched */ |
toddouska | 0:5045d2638c29 | 1893 | #ifndef NO_PSK |
toddouska | 0:5045d2638c29 | 1894 | havePSK = ssl->options.havePSK; |
toddouska | 0:5045d2638c29 | 1895 | #endif |
toddouska | 0:5045d2638c29 | 1896 | InitSuites(&ssl->suites, ssl->version, ssl->options.haveDH, havePSK, |
toddouska | 0:5045d2638c29 | 1897 | ssl->options.haveNTRU); |
toddouska | 0:5045d2638c29 | 1898 | } |
toddouska | 0:5045d2638c29 | 1899 | |
toddouska | 0:5045d2638c29 | 1900 | |
toddouska | 0:5045d2638c29 | 1901 | void OpenSSL_add_all_algorithms(void) |
toddouska | 0:5045d2638c29 | 1902 | { |
toddouska | 0:5045d2638c29 | 1903 | InitCyaSSL(); |
toddouska | 0:5045d2638c29 | 1904 | } |
toddouska | 0:5045d2638c29 | 1905 | |
toddouska | 0:5045d2638c29 | 1906 | |
toddouska | 0:5045d2638c29 | 1907 | int SSLeay_add_all_algorithms(void) |
toddouska | 0:5045d2638c29 | 1908 | { |
toddouska | 0:5045d2638c29 | 1909 | OpenSSL_add_all_algorithms(); |
toddouska | 0:5045d2638c29 | 1910 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1911 | } |
toddouska | 0:5045d2638c29 | 1912 | |
toddouska | 0:5045d2638c29 | 1913 | |
toddouska | 0:5045d2638c29 | 1914 | void SSL_CTX_set_tmp_rsa_callback(SSL_CTX* ctx, RSA*(*f)(SSL*, int, int)) |
toddouska | 0:5045d2638c29 | 1915 | { |
toddouska | 0:5045d2638c29 | 1916 | /* CyaSSL verifies all these internally */ |
toddouska | 0:5045d2638c29 | 1917 | } |
toddouska | 0:5045d2638c29 | 1918 | |
toddouska | 0:5045d2638c29 | 1919 | |
toddouska | 0:5045d2638c29 | 1920 | void SSL_set_shutdown(SSL* ssl, int opt) |
toddouska | 0:5045d2638c29 | 1921 | { |
toddouska | 0:5045d2638c29 | 1922 | |
toddouska | 0:5045d2638c29 | 1923 | } |
toddouska | 0:5045d2638c29 | 1924 | |
toddouska | 0:5045d2638c29 | 1925 | |
toddouska | 0:5045d2638c29 | 1926 | long SSL_CTX_set_options(SSL_CTX* ctx, long opt) |
toddouska | 0:5045d2638c29 | 1927 | { |
toddouska | 0:5045d2638c29 | 1928 | /* goahead calls with 0, do nothing */ |
toddouska | 0:5045d2638c29 | 1929 | return opt; |
toddouska | 0:5045d2638c29 | 1930 | } |
toddouska | 0:5045d2638c29 | 1931 | |
toddouska | 0:5045d2638c29 | 1932 | |
toddouska | 0:5045d2638c29 | 1933 | int SSL_set_rfd(SSL* ssl, int rfd) |
toddouska | 0:5045d2638c29 | 1934 | { |
toddouska | 0:5045d2638c29 | 1935 | ssl->rfd = rfd; /* not used directly to allow IO callbacks */ |
toddouska | 0:5045d2638c29 | 1936 | |
toddouska | 0:5045d2638c29 | 1937 | ssl->IOCB_ReadCtx = &ssl->rfd; |
toddouska | 0:5045d2638c29 | 1938 | |
toddouska | 0:5045d2638c29 | 1939 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1940 | } |
toddouska | 0:5045d2638c29 | 1941 | |
toddouska | 0:5045d2638c29 | 1942 | |
toddouska | 0:5045d2638c29 | 1943 | int SSL_set_wfd(SSL* ssl, int wfd) |
toddouska | 0:5045d2638c29 | 1944 | { |
toddouska | 0:5045d2638c29 | 1945 | ssl->wfd = wfd; /* not used directly to allow IO callbacks */ |
toddouska | 0:5045d2638c29 | 1946 | |
toddouska | 0:5045d2638c29 | 1947 | ssl->IOCB_WriteCtx = &ssl->wfd; |
toddouska | 0:5045d2638c29 | 1948 | |
toddouska | 0:5045d2638c29 | 1949 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 1950 | } |
toddouska | 0:5045d2638c29 | 1951 | |
toddouska | 0:5045d2638c29 | 1952 | |
toddouska | 0:5045d2638c29 | 1953 | RSA* RSA_generate_key(int len, unsigned long bits, void(*f)(int, |
toddouska | 0:5045d2638c29 | 1954 | int, void*), void* data) |
toddouska | 0:5045d2638c29 | 1955 | { |
toddouska | 0:5045d2638c29 | 1956 | /* no tmp key needed, actual generation not supported */ |
toddouska | 0:5045d2638c29 | 1957 | return 0; |
toddouska | 0:5045d2638c29 | 1958 | } |
toddouska | 0:5045d2638c29 | 1959 | |
toddouska | 0:5045d2638c29 | 1960 | |
toddouska | 0:5045d2638c29 | 1961 | X509_NAME* X509_get_issuer_name(X509* cert) |
toddouska | 0:5045d2638c29 | 1962 | { |
toddouska | 0:5045d2638c29 | 1963 | return &cert->issuer; |
toddouska | 0:5045d2638c29 | 1964 | } |
toddouska | 0:5045d2638c29 | 1965 | |
toddouska | 0:5045d2638c29 | 1966 | |
toddouska | 0:5045d2638c29 | 1967 | X509_NAME* X509_get_subject_name(X509* cert) |
toddouska | 0:5045d2638c29 | 1968 | { |
toddouska | 0:5045d2638c29 | 1969 | return &cert->subject; |
toddouska | 0:5045d2638c29 | 1970 | } |
toddouska | 0:5045d2638c29 | 1971 | |
toddouska | 0:5045d2638c29 | 1972 | |
toddouska | 0:5045d2638c29 | 1973 | /* copy name into buffer, at most sz bytes, if buffer is null will |
toddouska | 0:5045d2638c29 | 1974 | malloc buffer, call responsible for freeing */ |
toddouska | 0:5045d2638c29 | 1975 | char* X509_NAME_oneline(X509_NAME* name, char* buffer, int sz) |
toddouska | 0:5045d2638c29 | 1976 | { |
toddouska | 0:5045d2638c29 | 1977 | int copySz = min(sz, name->sz); |
toddouska | 0:5045d2638c29 | 1978 | if (!name->sz) return buffer; |
toddouska | 0:5045d2638c29 | 1979 | |
toddouska | 0:5045d2638c29 | 1980 | if (!buffer) { |
toddouska | 0:5045d2638c29 | 1981 | buffer = (char*)XMALLOC(name->sz, 0, DYNAMIC_TYPE_OPENSSL); |
toddouska | 0:5045d2638c29 | 1982 | if (!buffer) return buffer; |
toddouska | 0:5045d2638c29 | 1983 | copySz = name->sz; |
toddouska | 0:5045d2638c29 | 1984 | } |
toddouska | 0:5045d2638c29 | 1985 | |
toddouska | 0:5045d2638c29 | 1986 | if (copySz == 0) |
toddouska | 0:5045d2638c29 | 1987 | return buffer; |
toddouska | 0:5045d2638c29 | 1988 | |
toddouska | 0:5045d2638c29 | 1989 | XMEMCPY(buffer, name->name, copySz - 1); |
toddouska | 0:5045d2638c29 | 1990 | buffer[copySz - 1] = 0; |
toddouska | 0:5045d2638c29 | 1991 | |
toddouska | 0:5045d2638c29 | 1992 | return buffer; |
toddouska | 0:5045d2638c29 | 1993 | } |
toddouska | 0:5045d2638c29 | 1994 | |
toddouska | 0:5045d2638c29 | 1995 | |
toddouska | 0:5045d2638c29 | 1996 | X509* X509_STORE_CTX_get_current_cert(X509_STORE_CTX* ctx) |
toddouska | 0:5045d2638c29 | 1997 | { |
toddouska | 0:5045d2638c29 | 1998 | return 0; |
toddouska | 0:5045d2638c29 | 1999 | } |
toddouska | 0:5045d2638c29 | 2000 | |
toddouska | 0:5045d2638c29 | 2001 | |
toddouska | 0:5045d2638c29 | 2002 | int X509_STORE_CTX_get_error(X509_STORE_CTX* ctx) |
toddouska | 0:5045d2638c29 | 2003 | { |
toddouska | 0:5045d2638c29 | 2004 | return 0; |
toddouska | 0:5045d2638c29 | 2005 | } |
toddouska | 0:5045d2638c29 | 2006 | |
toddouska | 0:5045d2638c29 | 2007 | |
toddouska | 0:5045d2638c29 | 2008 | int X509_STORE_CTX_get_error_depth(X509_STORE_CTX* ctx) |
toddouska | 0:5045d2638c29 | 2009 | { |
toddouska | 0:5045d2638c29 | 2010 | return 0; |
toddouska | 0:5045d2638c29 | 2011 | } |
toddouska | 0:5045d2638c29 | 2012 | |
toddouska | 0:5045d2638c29 | 2013 | |
toddouska | 0:5045d2638c29 | 2014 | BIO_METHOD* BIO_f_buffer(void) |
toddouska | 0:5045d2638c29 | 2015 | { |
toddouska | 0:5045d2638c29 | 2016 | static BIO_METHOD meth; |
toddouska | 0:5045d2638c29 | 2017 | meth.type = BIO_BUFFER; |
toddouska | 0:5045d2638c29 | 2018 | |
toddouska | 0:5045d2638c29 | 2019 | return &meth; |
toddouska | 0:5045d2638c29 | 2020 | } |
toddouska | 0:5045d2638c29 | 2021 | |
toddouska | 0:5045d2638c29 | 2022 | |
toddouska | 0:5045d2638c29 | 2023 | long BIO_set_write_buffer_size(BIO* bio, long size) |
toddouska | 0:5045d2638c29 | 2024 | { |
toddouska | 0:5045d2638c29 | 2025 | /* CyaSSL has internal buffer, compatibility only */ |
toddouska | 0:5045d2638c29 | 2026 | return size; |
toddouska | 0:5045d2638c29 | 2027 | } |
toddouska | 0:5045d2638c29 | 2028 | |
toddouska | 0:5045d2638c29 | 2029 | |
toddouska | 0:5045d2638c29 | 2030 | BIO_METHOD* BIO_f_ssl(void) |
toddouska | 0:5045d2638c29 | 2031 | { |
toddouska | 0:5045d2638c29 | 2032 | static BIO_METHOD meth; |
toddouska | 0:5045d2638c29 | 2033 | meth.type = BIO_SSL; |
toddouska | 0:5045d2638c29 | 2034 | |
toddouska | 0:5045d2638c29 | 2035 | return &meth; |
toddouska | 0:5045d2638c29 | 2036 | } |
toddouska | 0:5045d2638c29 | 2037 | |
toddouska | 0:5045d2638c29 | 2038 | |
toddouska | 0:5045d2638c29 | 2039 | BIO* BIO_new_socket(int sfd, int close) |
toddouska | 0:5045d2638c29 | 2040 | { |
toddouska | 0:5045d2638c29 | 2041 | BIO* bio = (BIO*) XMALLOC(sizeof(BIO), 0, DYNAMIC_TYPE_OPENSSL); |
toddouska | 0:5045d2638c29 | 2042 | if (bio) { |
toddouska | 0:5045d2638c29 | 2043 | bio->type = BIO_SOCKET; |
toddouska | 0:5045d2638c29 | 2044 | bio->close = close; |
toddouska | 0:5045d2638c29 | 2045 | bio->eof = 0; |
toddouska | 0:5045d2638c29 | 2046 | bio->ssl = 0; |
toddouska | 0:5045d2638c29 | 2047 | bio->fd = sfd; |
toddouska | 0:5045d2638c29 | 2048 | bio->prev = 0; |
toddouska | 0:5045d2638c29 | 2049 | bio->next = 0; |
toddouska | 0:5045d2638c29 | 2050 | } |
toddouska | 0:5045d2638c29 | 2051 | return bio; |
toddouska | 0:5045d2638c29 | 2052 | } |
toddouska | 0:5045d2638c29 | 2053 | |
toddouska | 0:5045d2638c29 | 2054 | |
toddouska | 0:5045d2638c29 | 2055 | int BIO_eof(BIO* b) |
toddouska | 0:5045d2638c29 | 2056 | { |
toddouska | 0:5045d2638c29 | 2057 | if (b->eof) |
toddouska | 0:5045d2638c29 | 2058 | return 1; |
toddouska | 0:5045d2638c29 | 2059 | |
toddouska | 0:5045d2638c29 | 2060 | return 0; |
toddouska | 0:5045d2638c29 | 2061 | } |
toddouska | 0:5045d2638c29 | 2062 | |
toddouska | 0:5045d2638c29 | 2063 | |
toddouska | 0:5045d2638c29 | 2064 | long BIO_set_ssl(BIO* b, SSL* ssl, int close) |
toddouska | 0:5045d2638c29 | 2065 | { |
toddouska | 0:5045d2638c29 | 2066 | b->ssl = ssl; |
toddouska | 0:5045d2638c29 | 2067 | b->close = close; |
toddouska | 0:5045d2638c29 | 2068 | /* add to ssl for bio free if SSL_free called before/instead of free_all? */ |
toddouska | 0:5045d2638c29 | 2069 | |
toddouska | 0:5045d2638c29 | 2070 | return 0; |
toddouska | 0:5045d2638c29 | 2071 | } |
toddouska | 0:5045d2638c29 | 2072 | |
toddouska | 0:5045d2638c29 | 2073 | |
toddouska | 0:5045d2638c29 | 2074 | BIO* BIO_new(BIO_METHOD* method) |
toddouska | 0:5045d2638c29 | 2075 | { |
toddouska | 0:5045d2638c29 | 2076 | BIO* bio = (BIO*) XMALLOC(sizeof(BIO), 0, DYNAMIC_TYPE_OPENSSL); |
toddouska | 0:5045d2638c29 | 2077 | if (bio) { |
toddouska | 0:5045d2638c29 | 2078 | bio->type = method->type; |
toddouska | 0:5045d2638c29 | 2079 | bio->close = 0; |
toddouska | 0:5045d2638c29 | 2080 | bio->eof = 0; |
toddouska | 0:5045d2638c29 | 2081 | bio->ssl = 0; |
toddouska | 0:5045d2638c29 | 2082 | bio->fd = 0; |
toddouska | 0:5045d2638c29 | 2083 | bio->prev = 0; |
toddouska | 0:5045d2638c29 | 2084 | bio->next = 0; |
toddouska | 0:5045d2638c29 | 2085 | } |
toddouska | 0:5045d2638c29 | 2086 | return bio; |
toddouska | 0:5045d2638c29 | 2087 | } |
toddouska | 0:5045d2638c29 | 2088 | |
toddouska | 0:5045d2638c29 | 2089 | |
toddouska | 0:5045d2638c29 | 2090 | #ifdef USE_WINDOWS_API |
toddouska | 0:5045d2638c29 | 2091 | #define CloseSocket(s) closesocket(s) |
toddouska | 0:5045d2638c29 | 2092 | #else |
toddouska | 0:5045d2638c29 | 2093 | #define CloseSocket(s) close(s) |
toddouska | 0:5045d2638c29 | 2094 | #endif |
toddouska | 0:5045d2638c29 | 2095 | |
toddouska | 0:5045d2638c29 | 2096 | int BIO_free(BIO* bio) |
toddouska | 0:5045d2638c29 | 2097 | { |
toddouska | 0:5045d2638c29 | 2098 | /* unchain?, doesn't matter in goahead since from free all */ |
toddouska | 0:5045d2638c29 | 2099 | if (bio) { |
toddouska | 0:5045d2638c29 | 2100 | if (bio->close) { |
toddouska | 0:5045d2638c29 | 2101 | if (bio->ssl) |
toddouska | 0:5045d2638c29 | 2102 | SSL_free(bio->ssl); |
toddouska | 0:5045d2638c29 | 2103 | if (bio->fd) |
toddouska | 0:5045d2638c29 | 2104 | CloseSocket(bio->fd); |
toddouska | 0:5045d2638c29 | 2105 | } |
toddouska | 0:5045d2638c29 | 2106 | XFREE(bio, 0, DYNAMIC_TYPE_OPENSSL); |
toddouska | 0:5045d2638c29 | 2107 | } |
toddouska | 0:5045d2638c29 | 2108 | return 0; |
toddouska | 0:5045d2638c29 | 2109 | } |
toddouska | 0:5045d2638c29 | 2110 | |
toddouska | 0:5045d2638c29 | 2111 | |
toddouska | 0:5045d2638c29 | 2112 | int BIO_free_all(BIO* bio) |
toddouska | 0:5045d2638c29 | 2113 | { |
toddouska | 0:5045d2638c29 | 2114 | BIO* next = bio; |
toddouska | 0:5045d2638c29 | 2115 | |
toddouska | 0:5045d2638c29 | 2116 | while ( (bio = next) ) { |
toddouska | 0:5045d2638c29 | 2117 | next = bio->next; |
toddouska | 0:5045d2638c29 | 2118 | BIO_free(bio); |
toddouska | 0:5045d2638c29 | 2119 | } |
toddouska | 0:5045d2638c29 | 2120 | return 0; |
toddouska | 0:5045d2638c29 | 2121 | } |
toddouska | 0:5045d2638c29 | 2122 | |
toddouska | 0:5045d2638c29 | 2123 | |
toddouska | 0:5045d2638c29 | 2124 | int BIO_read(BIO* bio, void* buf, int len) |
toddouska | 0:5045d2638c29 | 2125 | { |
toddouska | 0:5045d2638c29 | 2126 | int ret; |
toddouska | 0:5045d2638c29 | 2127 | SSL* ssl = 0; |
toddouska | 0:5045d2638c29 | 2128 | BIO* front = bio; |
toddouska | 0:5045d2638c29 | 2129 | |
toddouska | 0:5045d2638c29 | 2130 | /* already got eof, again is error */ |
toddouska | 0:5045d2638c29 | 2131 | if (front->eof) |
toddouska | 0:5045d2638c29 | 2132 | return -1; |
toddouska | 0:5045d2638c29 | 2133 | |
toddouska | 0:5045d2638c29 | 2134 | while(bio && ((ssl = bio->ssl) == 0) ) |
toddouska | 0:5045d2638c29 | 2135 | bio = bio->next; |
toddouska | 0:5045d2638c29 | 2136 | |
toddouska | 0:5045d2638c29 | 2137 | if (ssl == 0) return -1; |
toddouska | 0:5045d2638c29 | 2138 | |
toddouska | 0:5045d2638c29 | 2139 | ret = SSL_read(ssl, buf, len); |
toddouska | 0:5045d2638c29 | 2140 | if (ret == 0) |
toddouska | 0:5045d2638c29 | 2141 | front->eof = 1; |
toddouska | 0:5045d2638c29 | 2142 | else if (ret < 0) { |
toddouska | 0:5045d2638c29 | 2143 | int err = SSL_get_error(ssl, 0); |
toddouska | 0:5045d2638c29 | 2144 | if ( !(err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) ) |
toddouska | 0:5045d2638c29 | 2145 | front->eof = 1; |
toddouska | 0:5045d2638c29 | 2146 | } |
toddouska | 0:5045d2638c29 | 2147 | return ret; |
toddouska | 0:5045d2638c29 | 2148 | } |
toddouska | 0:5045d2638c29 | 2149 | |
toddouska | 0:5045d2638c29 | 2150 | |
toddouska | 0:5045d2638c29 | 2151 | int BIO_write(BIO* bio, const void* data, int len) |
toddouska | 0:5045d2638c29 | 2152 | { |
toddouska | 0:5045d2638c29 | 2153 | int ret; |
toddouska | 0:5045d2638c29 | 2154 | SSL* ssl = 0; |
toddouska | 0:5045d2638c29 | 2155 | BIO* front = bio; |
toddouska | 0:5045d2638c29 | 2156 | |
toddouska | 0:5045d2638c29 | 2157 | /* already got eof, again is error */ |
toddouska | 0:5045d2638c29 | 2158 | if (front->eof) |
toddouska | 0:5045d2638c29 | 2159 | return -1; |
toddouska | 0:5045d2638c29 | 2160 | |
toddouska | 0:5045d2638c29 | 2161 | while(bio && ((ssl = bio->ssl) == 0) ) |
toddouska | 0:5045d2638c29 | 2162 | bio = bio->next; |
toddouska | 0:5045d2638c29 | 2163 | |
toddouska | 0:5045d2638c29 | 2164 | if (ssl == 0) return -1; |
toddouska | 0:5045d2638c29 | 2165 | |
toddouska | 0:5045d2638c29 | 2166 | ret = SSL_write(ssl, data, len); |
toddouska | 0:5045d2638c29 | 2167 | if (ret == 0) |
toddouska | 0:5045d2638c29 | 2168 | front->eof = 1; |
toddouska | 0:5045d2638c29 | 2169 | else if (ret < 0) { |
toddouska | 0:5045d2638c29 | 2170 | int err = SSL_get_error(ssl, 0); |
toddouska | 0:5045d2638c29 | 2171 | if ( !(err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) ) |
toddouska | 0:5045d2638c29 | 2172 | front->eof = 1; |
toddouska | 0:5045d2638c29 | 2173 | } |
toddouska | 0:5045d2638c29 | 2174 | |
toddouska | 0:5045d2638c29 | 2175 | return ret; |
toddouska | 0:5045d2638c29 | 2176 | } |
toddouska | 0:5045d2638c29 | 2177 | |
toddouska | 0:5045d2638c29 | 2178 | |
toddouska | 0:5045d2638c29 | 2179 | BIO* BIO_push(BIO* top, BIO* append) |
toddouska | 0:5045d2638c29 | 2180 | { |
toddouska | 0:5045d2638c29 | 2181 | top->next = append; |
toddouska | 0:5045d2638c29 | 2182 | append->prev = top; |
toddouska | 0:5045d2638c29 | 2183 | |
toddouska | 0:5045d2638c29 | 2184 | return top; |
toddouska | 0:5045d2638c29 | 2185 | } |
toddouska | 0:5045d2638c29 | 2186 | |
toddouska | 0:5045d2638c29 | 2187 | |
toddouska | 0:5045d2638c29 | 2188 | int BIO_flush(BIO* bio) |
toddouska | 0:5045d2638c29 | 2189 | { |
toddouska | 0:5045d2638c29 | 2190 | /* for CyaSSL no flushing needed */ |
toddouska | 0:5045d2638c29 | 2191 | return 1; |
toddouska | 0:5045d2638c29 | 2192 | } |
toddouska | 0:5045d2638c29 | 2193 | |
toddouska | 0:5045d2638c29 | 2194 | |
toddouska | 0:5045d2638c29 | 2195 | #endif /* OPENSSL_EXTRA || GOAHEAD_WS */ |
toddouska | 0:5045d2638c29 | 2196 | |
toddouska | 0:5045d2638c29 | 2197 | |
toddouska | 0:5045d2638c29 | 2198 | #ifdef OPENSSL_EXTRA |
toddouska | 0:5045d2638c29 | 2199 | |
toddouska | 0:5045d2638c29 | 2200 | unsigned long SSLeay(void) |
toddouska | 0:5045d2638c29 | 2201 | { |
toddouska | 0:5045d2638c29 | 2202 | return SSLEAY_VERSION_NUMBER; |
toddouska | 0:5045d2638c29 | 2203 | } |
toddouska | 0:5045d2638c29 | 2204 | |
toddouska | 0:5045d2638c29 | 2205 | |
toddouska | 0:5045d2638c29 | 2206 | const char* SSLeay_version(int type) |
toddouska | 0:5045d2638c29 | 2207 | { |
toddouska | 0:5045d2638c29 | 2208 | static const char* version = "SSLeay CyaSSL compatibility"; |
toddouska | 0:5045d2638c29 | 2209 | return version; |
toddouska | 0:5045d2638c29 | 2210 | } |
toddouska | 0:5045d2638c29 | 2211 | |
toddouska | 0:5045d2638c29 | 2212 | |
toddouska | 0:5045d2638c29 | 2213 | void MD5_Init(MD5_CTX* md5) |
toddouska | 0:5045d2638c29 | 2214 | { |
toddouska | 0:5045d2638c29 | 2215 | typedef char md5_test[sizeof(MD5_CTX) >= sizeof(Md5) ? 1 : -1]; |
toddouska | 0:5045d2638c29 | 2216 | (void)sizeof(md5_test); |
toddouska | 0:5045d2638c29 | 2217 | |
toddouska | 0:5045d2638c29 | 2218 | InitMd5((Md5*)md5); |
toddouska | 0:5045d2638c29 | 2219 | } |
toddouska | 0:5045d2638c29 | 2220 | |
toddouska | 0:5045d2638c29 | 2221 | |
toddouska | 0:5045d2638c29 | 2222 | void MD5_Update(MD5_CTX* md5, const void* input, unsigned long sz) |
toddouska | 0:5045d2638c29 | 2223 | { |
toddouska | 0:5045d2638c29 | 2224 | Md5Update((Md5*)md5, (const byte*)input, sz); |
toddouska | 0:5045d2638c29 | 2225 | } |
toddouska | 0:5045d2638c29 | 2226 | |
toddouska | 0:5045d2638c29 | 2227 | |
toddouska | 0:5045d2638c29 | 2228 | void MD5_Final(byte* input, MD5_CTX* md5) |
toddouska | 0:5045d2638c29 | 2229 | { |
toddouska | 0:5045d2638c29 | 2230 | Md5Final((Md5*)md5, input); |
toddouska | 0:5045d2638c29 | 2231 | } |
toddouska | 0:5045d2638c29 | 2232 | |
toddouska | 0:5045d2638c29 | 2233 | |
toddouska | 0:5045d2638c29 | 2234 | void SHA_Init(SHA_CTX* sha) |
toddouska | 0:5045d2638c29 | 2235 | { |
toddouska | 0:5045d2638c29 | 2236 | typedef char sha_test[sizeof(SHA_CTX) >= sizeof(Sha) ? 1 : -1]; |
toddouska | 0:5045d2638c29 | 2237 | (void)sizeof(sha_test); |
toddouska | 0:5045d2638c29 | 2238 | |
toddouska | 0:5045d2638c29 | 2239 | InitSha((Sha*)sha); |
toddouska | 0:5045d2638c29 | 2240 | } |
toddouska | 0:5045d2638c29 | 2241 | |
toddouska | 0:5045d2638c29 | 2242 | |
toddouska | 0:5045d2638c29 | 2243 | void SHA_Update(SHA_CTX* sha, const void* input, unsigned long sz) |
toddouska | 0:5045d2638c29 | 2244 | { |
toddouska | 0:5045d2638c29 | 2245 | ShaUpdate((Sha*)sha, (const byte*)input, sz); |
toddouska | 0:5045d2638c29 | 2246 | } |
toddouska | 0:5045d2638c29 | 2247 | |
toddouska | 0:5045d2638c29 | 2248 | |
toddouska | 0:5045d2638c29 | 2249 | void SHA_Final(byte* input, SHA_CTX* sha) |
toddouska | 0:5045d2638c29 | 2250 | { |
toddouska | 0:5045d2638c29 | 2251 | ShaFinal((Sha*)sha, input); |
toddouska | 0:5045d2638c29 | 2252 | } |
toddouska | 0:5045d2638c29 | 2253 | |
toddouska | 0:5045d2638c29 | 2254 | |
toddouska | 0:5045d2638c29 | 2255 | const EVP_MD* EVP_md5(void) |
toddouska | 0:5045d2638c29 | 2256 | { |
toddouska | 0:5045d2638c29 | 2257 | static const char* type = "MD5"; |
toddouska | 0:5045d2638c29 | 2258 | return type; |
toddouska | 0:5045d2638c29 | 2259 | } |
toddouska | 0:5045d2638c29 | 2260 | |
toddouska | 0:5045d2638c29 | 2261 | |
toddouska | 0:5045d2638c29 | 2262 | const EVP_MD* EVP_sha1(void) |
toddouska | 0:5045d2638c29 | 2263 | { |
toddouska | 0:5045d2638c29 | 2264 | static const char* type = "SHA"; |
toddouska | 0:5045d2638c29 | 2265 | return type; |
toddouska | 0:5045d2638c29 | 2266 | } |
toddouska | 0:5045d2638c29 | 2267 | |
toddouska | 0:5045d2638c29 | 2268 | |
toddouska | 0:5045d2638c29 | 2269 | void EVP_MD_CTX_init(EVP_MD_CTX* ctx) |
toddouska | 0:5045d2638c29 | 2270 | { |
toddouska | 0:5045d2638c29 | 2271 | /* do nothing */ |
toddouska | 0:5045d2638c29 | 2272 | } |
toddouska | 0:5045d2638c29 | 2273 | |
toddouska | 0:5045d2638c29 | 2274 | |
toddouska | 0:5045d2638c29 | 2275 | int EVP_MD_CTX_cleanup(EVP_MD_CTX* ctx) |
toddouska | 0:5045d2638c29 | 2276 | { |
toddouska | 0:5045d2638c29 | 2277 | return 0; |
toddouska | 0:5045d2638c29 | 2278 | } |
toddouska | 0:5045d2638c29 | 2279 | |
toddouska | 0:5045d2638c29 | 2280 | |
toddouska | 0:5045d2638c29 | 2281 | int EVP_DigestInit(EVP_MD_CTX* ctx, const EVP_MD* type) |
toddouska | 0:5045d2638c29 | 2282 | { |
toddouska | 0:5045d2638c29 | 2283 | if (XSTRNCMP(type, "MD5", 3) == 0) { |
toddouska | 0:5045d2638c29 | 2284 | ctx->macType = MD5; |
toddouska | 0:5045d2638c29 | 2285 | MD5_Init((MD5_CTX*)&ctx->hash); |
toddouska | 0:5045d2638c29 | 2286 | } |
toddouska | 0:5045d2638c29 | 2287 | else if (XSTRNCMP(type, "SHA", 3) == 0) { |
toddouska | 0:5045d2638c29 | 2288 | ctx->macType = SHA; |
toddouska | 0:5045d2638c29 | 2289 | SHA_Init((SHA_CTX*)&ctx->hash); |
toddouska | 0:5045d2638c29 | 2290 | } |
toddouska | 0:5045d2638c29 | 2291 | else |
toddouska | 0:5045d2638c29 | 2292 | return -1; |
toddouska | 0:5045d2638c29 | 2293 | |
toddouska | 0:5045d2638c29 | 2294 | return 0; |
toddouska | 0:5045d2638c29 | 2295 | } |
toddouska | 0:5045d2638c29 | 2296 | |
toddouska | 0:5045d2638c29 | 2297 | |
toddouska | 0:5045d2638c29 | 2298 | int EVP_DigestUpdate(EVP_MD_CTX* ctx, const void* data, size_t sz) |
toddouska | 0:5045d2638c29 | 2299 | { |
toddouska | 0:5045d2638c29 | 2300 | if (ctx->macType == MD5) |
toddouska | 0:5045d2638c29 | 2301 | MD5_Update((MD5_CTX*)&ctx->hash, data, (unsigned long)sz); |
toddouska | 0:5045d2638c29 | 2302 | else if (ctx->macType == SHA) |
toddouska | 0:5045d2638c29 | 2303 | SHA_Update((SHA_CTX*)&ctx->hash, data, (unsigned long)sz); |
toddouska | 0:5045d2638c29 | 2304 | else |
toddouska | 0:5045d2638c29 | 2305 | return -1; |
toddouska | 0:5045d2638c29 | 2306 | |
toddouska | 0:5045d2638c29 | 2307 | return 0; |
toddouska | 0:5045d2638c29 | 2308 | } |
toddouska | 0:5045d2638c29 | 2309 | |
toddouska | 0:5045d2638c29 | 2310 | |
toddouska | 0:5045d2638c29 | 2311 | int EVP_DigestFinal(EVP_MD_CTX* ctx, unsigned char* md, unsigned int* s) |
toddouska | 0:5045d2638c29 | 2312 | { |
toddouska | 0:5045d2638c29 | 2313 | if (ctx->macType == MD5) { |
toddouska | 0:5045d2638c29 | 2314 | MD5_Final(md, (MD5_CTX*)&ctx->hash); |
toddouska | 0:5045d2638c29 | 2315 | if (s) *s = MD5_DIGEST_SIZE; |
toddouska | 0:5045d2638c29 | 2316 | } |
toddouska | 0:5045d2638c29 | 2317 | else if (ctx->macType == SHA) { |
toddouska | 0:5045d2638c29 | 2318 | SHA_Final(md, (SHA_CTX*)&ctx->hash); |
toddouska | 0:5045d2638c29 | 2319 | if (s) *s = SHA_DIGEST_SIZE; |
toddouska | 0:5045d2638c29 | 2320 | } |
toddouska | 0:5045d2638c29 | 2321 | else |
toddouska | 0:5045d2638c29 | 2322 | return -1; |
toddouska | 0:5045d2638c29 | 2323 | |
toddouska | 0:5045d2638c29 | 2324 | return 0; |
toddouska | 0:5045d2638c29 | 2325 | } |
toddouska | 0:5045d2638c29 | 2326 | |
toddouska | 0:5045d2638c29 | 2327 | |
toddouska | 0:5045d2638c29 | 2328 | int EVP_DigestFinal_ex(EVP_MD_CTX* ctx, unsigned char* md, unsigned int* s) |
toddouska | 0:5045d2638c29 | 2329 | { |
toddouska | 0:5045d2638c29 | 2330 | return EVP_DigestFinal(ctx, md, s); |
toddouska | 0:5045d2638c29 | 2331 | } |
toddouska | 0:5045d2638c29 | 2332 | |
toddouska | 0:5045d2638c29 | 2333 | |
toddouska | 0:5045d2638c29 | 2334 | unsigned char* HMAC(const EVP_MD* evp_md, const void* key, int key_len, |
toddouska | 0:5045d2638c29 | 2335 | const unsigned char* d, int n, unsigned char* md, unsigned int* md_len) |
toddouska | 0:5045d2638c29 | 2336 | { |
toddouska | 0:5045d2638c29 | 2337 | Hmac hmac; |
toddouska | 0:5045d2638c29 | 2338 | |
toddouska | 0:5045d2638c29 | 2339 | if (!md) return 0; /* no static buffer support */ |
toddouska | 0:5045d2638c29 | 2340 | |
toddouska | 0:5045d2638c29 | 2341 | if (XSTRNCMP(evp_md, "MD5", 3) == 0) { |
toddouska | 0:5045d2638c29 | 2342 | HmacSetKey(&hmac, MD5, key, key_len); |
toddouska | 0:5045d2638c29 | 2343 | if (md_len) *md_len = MD5_DIGEST_SIZE; |
toddouska | 0:5045d2638c29 | 2344 | } |
toddouska | 0:5045d2638c29 | 2345 | else if (XSTRNCMP(evp_md, "SHA", 3) == 0) { |
toddouska | 0:5045d2638c29 | 2346 | HmacSetKey(&hmac, SHA, key, key_len); |
toddouska | 0:5045d2638c29 | 2347 | if (md_len) *md_len = SHA_DIGEST_SIZE; |
toddouska | 0:5045d2638c29 | 2348 | } |
toddouska | 0:5045d2638c29 | 2349 | else |
toddouska | 0:5045d2638c29 | 2350 | return 0; |
toddouska | 0:5045d2638c29 | 2351 | |
toddouska | 0:5045d2638c29 | 2352 | HmacUpdate(&hmac, d, n); |
toddouska | 0:5045d2638c29 | 2353 | HmacFinal(&hmac, md); |
toddouska | 0:5045d2638c29 | 2354 | |
toddouska | 0:5045d2638c29 | 2355 | return md; |
toddouska | 0:5045d2638c29 | 2356 | } |
toddouska | 0:5045d2638c29 | 2357 | |
toddouska | 0:5045d2638c29 | 2358 | unsigned long ERR_get_error(void) |
toddouska | 0:5045d2638c29 | 2359 | { |
toddouska | 0:5045d2638c29 | 2360 | /* TODO: */ |
toddouska | 0:5045d2638c29 | 2361 | return 0; |
toddouska | 0:5045d2638c29 | 2362 | } |
toddouska | 0:5045d2638c29 | 2363 | |
toddouska | 0:5045d2638c29 | 2364 | void ERR_clear_error(void) |
toddouska | 0:5045d2638c29 | 2365 | { |
toddouska | 0:5045d2638c29 | 2366 | /* TODO: */ |
toddouska | 0:5045d2638c29 | 2367 | } |
toddouska | 0:5045d2638c29 | 2368 | |
toddouska | 0:5045d2638c29 | 2369 | |
toddouska | 0:5045d2638c29 | 2370 | int RAND_status(void) |
toddouska | 0:5045d2638c29 | 2371 | { |
toddouska | 0:5045d2638c29 | 2372 | return 1; /* CTaoCrypt provides enough seed internally */ |
toddouska | 0:5045d2638c29 | 2373 | } |
toddouska | 0:5045d2638c29 | 2374 | |
toddouska | 0:5045d2638c29 | 2375 | |
toddouska | 0:5045d2638c29 | 2376 | int RAND_bytes(unsigned char* buf, int num) |
toddouska | 0:5045d2638c29 | 2377 | { |
toddouska | 0:5045d2638c29 | 2378 | RNG rng; |
toddouska | 0:5045d2638c29 | 2379 | |
toddouska | 0:5045d2638c29 | 2380 | if (InitRng(&rng)) |
toddouska | 0:5045d2638c29 | 2381 | return 0; |
toddouska | 0:5045d2638c29 | 2382 | |
toddouska | 0:5045d2638c29 | 2383 | RNG_GenerateBlock(&rng, buf, num); |
toddouska | 0:5045d2638c29 | 2384 | |
toddouska | 0:5045d2638c29 | 2385 | return 1; |
toddouska | 0:5045d2638c29 | 2386 | } |
toddouska | 0:5045d2638c29 | 2387 | |
toddouska | 0:5045d2638c29 | 2388 | |
toddouska | 0:5045d2638c29 | 2389 | int DES_key_sched(const_DES_cblock* key, DES_key_schedule* schedule) |
toddouska | 0:5045d2638c29 | 2390 | { |
toddouska | 0:5045d2638c29 | 2391 | XMEMCPY(schedule, key, sizeof(const_DES_cblock)); |
toddouska | 0:5045d2638c29 | 2392 | return 0; |
toddouska | 0:5045d2638c29 | 2393 | } |
toddouska | 0:5045d2638c29 | 2394 | |
toddouska | 0:5045d2638c29 | 2395 | |
toddouska | 0:5045d2638c29 | 2396 | void DES_cbc_encrypt(const unsigned char* input, unsigned char* output, |
toddouska | 0:5045d2638c29 | 2397 | long length, DES_key_schedule* schedule, DES_cblock* ivec, |
toddouska | 0:5045d2638c29 | 2398 | int enc) |
toddouska | 0:5045d2638c29 | 2399 | { |
toddouska | 0:5045d2638c29 | 2400 | Des des; |
toddouska | 0:5045d2638c29 | 2401 | Des_SetKey(&des, (const byte*)schedule, (const byte*)ivec, !enc); |
toddouska | 0:5045d2638c29 | 2402 | |
toddouska | 0:5045d2638c29 | 2403 | if (enc) |
toddouska | 0:5045d2638c29 | 2404 | Des_CbcEncrypt(&des, output, input, length); |
toddouska | 0:5045d2638c29 | 2405 | else |
toddouska | 0:5045d2638c29 | 2406 | Des_CbcDecrypt(&des, output, input, length); |
toddouska | 0:5045d2638c29 | 2407 | } |
toddouska | 0:5045d2638c29 | 2408 | |
toddouska | 0:5045d2638c29 | 2409 | |
toddouska | 0:5045d2638c29 | 2410 | /* correctly sets ivec for next call */ |
toddouska | 0:5045d2638c29 | 2411 | void DES_ncbc_encrypt(const unsigned char* input, unsigned char* output, |
toddouska | 0:5045d2638c29 | 2412 | long length, DES_key_schedule* schedule, DES_cblock* ivec, |
toddouska | 0:5045d2638c29 | 2413 | int enc) |
toddouska | 0:5045d2638c29 | 2414 | { |
toddouska | 0:5045d2638c29 | 2415 | Des des; |
toddouska | 0:5045d2638c29 | 2416 | Des_SetKey(&des, (const byte*)schedule, (const byte*)ivec, !enc); |
toddouska | 0:5045d2638c29 | 2417 | |
toddouska | 0:5045d2638c29 | 2418 | if (enc) |
toddouska | 0:5045d2638c29 | 2419 | Des_CbcEncrypt(&des, output, input, length); |
toddouska | 0:5045d2638c29 | 2420 | else |
toddouska | 0:5045d2638c29 | 2421 | Des_CbcDecrypt(&des, output, input, length); |
toddouska | 0:5045d2638c29 | 2422 | |
toddouska | 0:5045d2638c29 | 2423 | XMEMCPY(ivec, output + length - sizeof(DES_cblock), sizeof(DES_cblock)); |
toddouska | 0:5045d2638c29 | 2424 | } |
toddouska | 0:5045d2638c29 | 2425 | |
toddouska | 0:5045d2638c29 | 2426 | |
toddouska | 0:5045d2638c29 | 2427 | void ERR_free_strings(void) |
toddouska | 0:5045d2638c29 | 2428 | { |
toddouska | 0:5045d2638c29 | 2429 | /* handled internally */ |
toddouska | 0:5045d2638c29 | 2430 | } |
toddouska | 0:5045d2638c29 | 2431 | |
toddouska | 0:5045d2638c29 | 2432 | |
toddouska | 0:5045d2638c29 | 2433 | void ERR_remove_state(unsigned long state) |
toddouska | 0:5045d2638c29 | 2434 | { |
toddouska | 0:5045d2638c29 | 2435 | /* TODO: GetErrors().Remove(); */ |
toddouska | 0:5045d2638c29 | 2436 | } |
toddouska | 0:5045d2638c29 | 2437 | |
toddouska | 0:5045d2638c29 | 2438 | |
toddouska | 0:5045d2638c29 | 2439 | void EVP_cleanup(void) |
toddouska | 0:5045d2638c29 | 2440 | { |
toddouska | 0:5045d2638c29 | 2441 | /* nothing to do here */ |
toddouska | 0:5045d2638c29 | 2442 | } |
toddouska | 0:5045d2638c29 | 2443 | |
toddouska | 0:5045d2638c29 | 2444 | |
toddouska | 0:5045d2638c29 | 2445 | void CRYPTO_cleanup_all_ex_data(void) |
toddouska | 0:5045d2638c29 | 2446 | { |
toddouska | 0:5045d2638c29 | 2447 | /* nothing to do here */ |
toddouska | 0:5045d2638c29 | 2448 | } |
toddouska | 0:5045d2638c29 | 2449 | |
toddouska | 0:5045d2638c29 | 2450 | |
toddouska | 0:5045d2638c29 | 2451 | long SSL_CTX_set_mode(SSL_CTX* ctx, long mode) |
toddouska | 0:5045d2638c29 | 2452 | { |
toddouska | 0:5045d2638c29 | 2453 | /* SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER is CyaSSL default mode */ |
toddouska | 0:5045d2638c29 | 2454 | |
toddouska | 0:5045d2638c29 | 2455 | if (mode == SSL_MODE_ENABLE_PARTIAL_WRITE) |
toddouska | 0:5045d2638c29 | 2456 | ctx->partialWrite = 1; |
toddouska | 0:5045d2638c29 | 2457 | |
toddouska | 0:5045d2638c29 | 2458 | return mode; |
toddouska | 0:5045d2638c29 | 2459 | } |
toddouska | 0:5045d2638c29 | 2460 | |
toddouska | 0:5045d2638c29 | 2461 | |
toddouska | 0:5045d2638c29 | 2462 | long SSL_CTX_get_mode(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 2463 | { |
toddouska | 0:5045d2638c29 | 2464 | /* TODO: */ |
toddouska | 0:5045d2638c29 | 2465 | return 0; |
toddouska | 0:5045d2638c29 | 2466 | } |
toddouska | 0:5045d2638c29 | 2467 | |
toddouska | 0:5045d2638c29 | 2468 | |
toddouska | 0:5045d2638c29 | 2469 | void SSL_CTX_set_default_read_ahead(SSL_CTX* ctx, int m) |
toddouska | 0:5045d2638c29 | 2470 | { |
toddouska | 0:5045d2638c29 | 2471 | /* TODO: maybe? */ |
toddouska | 0:5045d2638c29 | 2472 | } |
toddouska | 0:5045d2638c29 | 2473 | |
toddouska | 0:5045d2638c29 | 2474 | |
toddouska | 0:5045d2638c29 | 2475 | int SSL_CTX_set_session_id_context(SSL_CTX* ctx, |
toddouska | 0:5045d2638c29 | 2476 | const unsigned char* sid_ctx, |
toddouska | 0:5045d2638c29 | 2477 | unsigned int sid_ctx_len) |
toddouska | 0:5045d2638c29 | 2478 | { |
toddouska | 0:5045d2638c29 | 2479 | /* No application specific context needed for cyaSSL */ |
toddouska | 0:5045d2638c29 | 2480 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 2481 | } |
toddouska | 0:5045d2638c29 | 2482 | |
toddouska | 0:5045d2638c29 | 2483 | |
toddouska | 0:5045d2638c29 | 2484 | long SSL_CTX_sess_get_cache_size(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 2485 | { |
toddouska | 0:5045d2638c29 | 2486 | /* TODO: maybe? */ |
toddouska | 0:5045d2638c29 | 2487 | return (~0); |
toddouska | 0:5045d2638c29 | 2488 | } |
toddouska | 0:5045d2638c29 | 2489 | |
toddouska | 0:5045d2638c29 | 2490 | unsigned long ERR_get_error_line_data(const char** file, int* line, |
toddouska | 0:5045d2638c29 | 2491 | const char** data, int *flags) |
toddouska | 0:5045d2638c29 | 2492 | { |
toddouska | 0:5045d2638c29 | 2493 | /* Not implemented */ |
toddouska | 0:5045d2638c29 | 2494 | return 0; |
toddouska | 0:5045d2638c29 | 2495 | } |
toddouska | 0:5045d2638c29 | 2496 | |
toddouska | 0:5045d2638c29 | 2497 | |
toddouska | 0:5045d2638c29 | 2498 | X509* SSL_get_peer_certificate(SSL* ssl) |
toddouska | 0:5045d2638c29 | 2499 | { |
toddouska | 0:5045d2638c29 | 2500 | if (ssl->peerCert.issuer.sz) |
toddouska | 0:5045d2638c29 | 2501 | return &ssl->peerCert; |
toddouska | 0:5045d2638c29 | 2502 | else |
toddouska | 0:5045d2638c29 | 2503 | return 0; |
toddouska | 0:5045d2638c29 | 2504 | } |
toddouska | 0:5045d2638c29 | 2505 | |
toddouska | 0:5045d2638c29 | 2506 | |
toddouska | 0:5045d2638c29 | 2507 | |
toddouska | 0:5045d2638c29 | 2508 | int SSL_set_ex_data(SSL* ssl, int idx, void* data) |
toddouska | 0:5045d2638c29 | 2509 | { |
toddouska | 0:5045d2638c29 | 2510 | return 0; |
toddouska | 0:5045d2638c29 | 2511 | } |
toddouska | 0:5045d2638c29 | 2512 | |
toddouska | 0:5045d2638c29 | 2513 | |
toddouska | 0:5045d2638c29 | 2514 | int SSL_get_shutdown(const SSL* ssl) |
toddouska | 0:5045d2638c29 | 2515 | { |
toddouska | 0:5045d2638c29 | 2516 | return 0; |
toddouska | 0:5045d2638c29 | 2517 | } |
toddouska | 0:5045d2638c29 | 2518 | |
toddouska | 0:5045d2638c29 | 2519 | |
toddouska | 0:5045d2638c29 | 2520 | int SSL_set_session_id_context(SSL* ssl, const unsigned char* id, |
toddouska | 0:5045d2638c29 | 2521 | unsigned int len) |
toddouska | 0:5045d2638c29 | 2522 | { |
toddouska | 0:5045d2638c29 | 2523 | return 0; |
toddouska | 0:5045d2638c29 | 2524 | } |
toddouska | 0:5045d2638c29 | 2525 | |
toddouska | 0:5045d2638c29 | 2526 | |
toddouska | 0:5045d2638c29 | 2527 | void SSL_set_connect_state(SSL* ssl) |
toddouska | 0:5045d2638c29 | 2528 | { |
toddouska | 0:5045d2638c29 | 2529 | /* client by default */ |
toddouska | 0:5045d2638c29 | 2530 | } |
toddouska | 0:5045d2638c29 | 2531 | |
toddouska | 0:5045d2638c29 | 2532 | |
toddouska | 0:5045d2638c29 | 2533 | int SSL_session_reused(SSL* ssl) |
toddouska | 0:5045d2638c29 | 2534 | { |
toddouska | 0:5045d2638c29 | 2535 | return ssl->options.resuming; |
toddouska | 0:5045d2638c29 | 2536 | } |
toddouska | 0:5045d2638c29 | 2537 | |
toddouska | 0:5045d2638c29 | 2538 | |
toddouska | 0:5045d2638c29 | 2539 | void SSL_SESSION_free(SSL_SESSION* session) |
toddouska | 0:5045d2638c29 | 2540 | { |
toddouska | 0:5045d2638c29 | 2541 | |
toddouska | 0:5045d2638c29 | 2542 | } |
toddouska | 0:5045d2638c29 | 2543 | |
toddouska | 0:5045d2638c29 | 2544 | |
toddouska | 0:5045d2638c29 | 2545 | const char* SSL_get_version(SSL* ssl) |
toddouska | 0:5045d2638c29 | 2546 | { |
toddouska | 0:5045d2638c29 | 2547 | if (ssl->version.major == 3) { |
toddouska | 0:5045d2638c29 | 2548 | switch (ssl->version.minor) { |
toddouska | 0:5045d2638c29 | 2549 | case 0 : |
toddouska | 0:5045d2638c29 | 2550 | return "SSLv3"; |
toddouska | 0:5045d2638c29 | 2551 | case 1 : |
toddouska | 0:5045d2638c29 | 2552 | return "TLSv1"; |
toddouska | 0:5045d2638c29 | 2553 | case 2 : |
toddouska | 0:5045d2638c29 | 2554 | return "TLSv1.1"; |
toddouska | 0:5045d2638c29 | 2555 | case 3 : |
toddouska | 0:5045d2638c29 | 2556 | return "TLSv1.2"; |
toddouska | 0:5045d2638c29 | 2557 | } |
toddouska | 0:5045d2638c29 | 2558 | } |
toddouska | 0:5045d2638c29 | 2559 | return "unknown"; |
toddouska | 0:5045d2638c29 | 2560 | } |
toddouska | 0:5045d2638c29 | 2561 | |
toddouska | 0:5045d2638c29 | 2562 | |
toddouska | 0:5045d2638c29 | 2563 | SSL_CIPHER* SSL_get_current_cipher(SSL* ssl) |
toddouska | 0:5045d2638c29 | 2564 | { |
toddouska | 0:5045d2638c29 | 2565 | return &ssl->cipher; |
toddouska | 0:5045d2638c29 | 2566 | } |
toddouska | 0:5045d2638c29 | 2567 | |
toddouska | 0:5045d2638c29 | 2568 | |
toddouska | 0:5045d2638c29 | 2569 | const char* SSL_CIPHER_get_name(const SSL_CIPHER* cipher) |
toddouska | 0:5045d2638c29 | 2570 | { |
toddouska | 0:5045d2638c29 | 2571 | if (cipher) { |
toddouska | 0:5045d2638c29 | 2572 | switch (cipher->ssl->options.cipherSuite) { |
toddouska | 0:5045d2638c29 | 2573 | case SSL_RSA_WITH_RC4_128_SHA : |
toddouska | 0:5045d2638c29 | 2574 | return "SSL_RSA_WITH_RC4_128_SHA"; |
toddouska | 0:5045d2638c29 | 2575 | case SSL_RSA_WITH_RC4_128_MD5 : |
toddouska | 0:5045d2638c29 | 2576 | return "SSL_RSA_WITH_RC4_128_MD5"; |
toddouska | 0:5045d2638c29 | 2577 | case SSL_RSA_WITH_3DES_EDE_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2578 | return "SSL_RSA_WITH_3DES_EDE_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2579 | case TLS_RSA_WITH_AES_128_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2580 | return "TLS_RSA_WITH_AES_128_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2581 | case TLS_RSA_WITH_AES_256_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2582 | return "TLS_RSA_WITH_AES_256_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2583 | case TLS_PSK_WITH_AES_128_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2584 | return "TLS_PSK_WITH_AES_128_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2585 | case TLS_PSK_WITH_AES_256_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2586 | return "TLS_PSK_WITH_AES_256_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2587 | case TLS_DHE_RSA_WITH_AES_128_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2588 | return "TLS_DHE_RSA_WITH_AES_128_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2589 | case TLS_DHE_RSA_WITH_AES_256_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2590 | return "TLS_DHE_RSA_WITH_AES_256_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2591 | case TLS_RSA_WITH_HC_128_CBC_MD5 : |
toddouska | 0:5045d2638c29 | 2592 | return "TLS_RSA_WITH_HC_128_CBC_MD5"; |
toddouska | 0:5045d2638c29 | 2593 | case TLS_RSA_WITH_HC_128_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2594 | return "TLS_RSA_WITH_HC_128_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2595 | case TLS_RSA_WITH_RABBIT_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2596 | return "TLS_RSA_WITH_RABBIT_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2597 | case TLS_NTRU_RSA_WITH_RC4_128_SHA : |
toddouska | 0:5045d2638c29 | 2598 | return "TLS_NTRU_RSA_WITH_RC4_128_SHA"; |
toddouska | 0:5045d2638c29 | 2599 | case TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2600 | return "TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2601 | case TLS_NTRU_RSA_WITH_AES_128_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2602 | return "TLS_NTRU_RSA_WITH_AES_128_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2603 | case TLS_NTRU_RSA_WITH_AES_256_CBC_SHA : |
toddouska | 0:5045d2638c29 | 2604 | return "TLS_NTRU_RSA_WITH_AES_256_CBC_SHA"; |
toddouska | 0:5045d2638c29 | 2605 | } |
toddouska | 0:5045d2638c29 | 2606 | } |
toddouska | 0:5045d2638c29 | 2607 | |
toddouska | 0:5045d2638c29 | 2608 | return "NONE"; |
toddouska | 0:5045d2638c29 | 2609 | } |
toddouska | 0:5045d2638c29 | 2610 | |
toddouska | 0:5045d2638c29 | 2611 | |
toddouska | 0:5045d2638c29 | 2612 | char* SSL_CIPHER_description(SSL_CIPHER* cipher, char* buffer, int len) |
toddouska | 0:5045d2638c29 | 2613 | { |
toddouska | 0:5045d2638c29 | 2614 | return 0; |
toddouska | 0:5045d2638c29 | 2615 | } |
toddouska | 0:5045d2638c29 | 2616 | |
toddouska | 0:5045d2638c29 | 2617 | |
toddouska | 0:5045d2638c29 | 2618 | SSL_SESSION* SSL_get1_session(SSL* ssl) /* what's ref count */ |
toddouska | 0:5045d2638c29 | 2619 | { |
toddouska | 0:5045d2638c29 | 2620 | return 0; |
toddouska | 0:5045d2638c29 | 2621 | } |
toddouska | 0:5045d2638c29 | 2622 | |
toddouska | 0:5045d2638c29 | 2623 | |
toddouska | 0:5045d2638c29 | 2624 | void X509_free(X509* buf) |
toddouska | 0:5045d2638c29 | 2625 | { |
toddouska | 0:5045d2638c29 | 2626 | |
toddouska | 0:5045d2638c29 | 2627 | } |
toddouska | 0:5045d2638c29 | 2628 | |
toddouska | 0:5045d2638c29 | 2629 | |
toddouska | 0:5045d2638c29 | 2630 | void OPENSSL_free(void* buf) |
toddouska | 0:5045d2638c29 | 2631 | { |
toddouska | 0:5045d2638c29 | 2632 | |
toddouska | 0:5045d2638c29 | 2633 | } |
toddouska | 0:5045d2638c29 | 2634 | |
toddouska | 0:5045d2638c29 | 2635 | |
toddouska | 0:5045d2638c29 | 2636 | int OCSP_parse_url(char* url, char** host, char** port, char** path, |
toddouska | 0:5045d2638c29 | 2637 | int* ssl) |
toddouska | 0:5045d2638c29 | 2638 | { |
toddouska | 0:5045d2638c29 | 2639 | return 0; |
toddouska | 0:5045d2638c29 | 2640 | } |
toddouska | 0:5045d2638c29 | 2641 | |
toddouska | 0:5045d2638c29 | 2642 | |
toddouska | 0:5045d2638c29 | 2643 | SSL_METHOD* SSLv2_client_method(void) |
toddouska | 0:5045d2638c29 | 2644 | { |
toddouska | 0:5045d2638c29 | 2645 | return 0; |
toddouska | 0:5045d2638c29 | 2646 | } |
toddouska | 0:5045d2638c29 | 2647 | |
toddouska | 0:5045d2638c29 | 2648 | |
toddouska | 0:5045d2638c29 | 2649 | SSL_METHOD* SSLv2_server_method(void) |
toddouska | 0:5045d2638c29 | 2650 | { |
toddouska | 0:5045d2638c29 | 2651 | return 0; |
toddouska | 0:5045d2638c29 | 2652 | } |
toddouska | 0:5045d2638c29 | 2653 | |
toddouska | 0:5045d2638c29 | 2654 | |
toddouska | 0:5045d2638c29 | 2655 | #ifndef NO_MD4 |
toddouska | 0:5045d2638c29 | 2656 | |
toddouska | 0:5045d2638c29 | 2657 | void MD4_Init(MD4_CTX* md4) |
toddouska | 0:5045d2638c29 | 2658 | { |
toddouska | 0:5045d2638c29 | 2659 | /* make sure we have a big enough buffer */ |
toddouska | 0:5045d2638c29 | 2660 | typedef char ok[sizeof(md4->buffer) >= sizeof(Md4) ? 1 : -1]; |
toddouska | 0:5045d2638c29 | 2661 | (void) sizeof(ok); |
toddouska | 0:5045d2638c29 | 2662 | |
toddouska | 0:5045d2638c29 | 2663 | InitMd4((Md4*)md4); |
toddouska | 0:5045d2638c29 | 2664 | } |
toddouska | 0:5045d2638c29 | 2665 | |
toddouska | 0:5045d2638c29 | 2666 | |
toddouska | 0:5045d2638c29 | 2667 | void MD4_Update(MD4_CTX* md4, const void* data, size_t len) |
toddouska | 0:5045d2638c29 | 2668 | { |
toddouska | 0:5045d2638c29 | 2669 | Md4Update((Md4*)md4, (const byte*)data, (word32)len); |
toddouska | 0:5045d2638c29 | 2670 | } |
toddouska | 0:5045d2638c29 | 2671 | |
toddouska | 0:5045d2638c29 | 2672 | |
toddouska | 0:5045d2638c29 | 2673 | void MD4_Final(unsigned char* digest, MD4_CTX* md4) |
toddouska | 0:5045d2638c29 | 2674 | { |
toddouska | 0:5045d2638c29 | 2675 | Md4Final((Md4*)md4, digest); |
toddouska | 0:5045d2638c29 | 2676 | } |
toddouska | 0:5045d2638c29 | 2677 | |
toddouska | 0:5045d2638c29 | 2678 | #endif /* NO_MD4 */ |
toddouska | 0:5045d2638c29 | 2679 | |
toddouska | 0:5045d2638c29 | 2680 | |
toddouska | 0:5045d2638c29 | 2681 | BIO* BIO_pop(BIO* top) |
toddouska | 0:5045d2638c29 | 2682 | { |
toddouska | 0:5045d2638c29 | 2683 | return 0; |
toddouska | 0:5045d2638c29 | 2684 | } |
toddouska | 0:5045d2638c29 | 2685 | |
toddouska | 0:5045d2638c29 | 2686 | |
toddouska | 0:5045d2638c29 | 2687 | int BIO_pending(BIO* bio) |
toddouska | 0:5045d2638c29 | 2688 | { |
toddouska | 0:5045d2638c29 | 2689 | return 0; |
toddouska | 0:5045d2638c29 | 2690 | } |
toddouska | 0:5045d2638c29 | 2691 | |
toddouska | 0:5045d2638c29 | 2692 | |
toddouska | 0:5045d2638c29 | 2693 | |
toddouska | 0:5045d2638c29 | 2694 | BIO_METHOD* BIO_s_mem(void) |
toddouska | 0:5045d2638c29 | 2695 | { |
toddouska | 0:5045d2638c29 | 2696 | return 0; |
toddouska | 0:5045d2638c29 | 2697 | } |
toddouska | 0:5045d2638c29 | 2698 | |
toddouska | 0:5045d2638c29 | 2699 | |
toddouska | 0:5045d2638c29 | 2700 | BIO_METHOD* BIO_f_base64(void) |
toddouska | 0:5045d2638c29 | 2701 | { |
toddouska | 0:5045d2638c29 | 2702 | return 0; |
toddouska | 0:5045d2638c29 | 2703 | } |
toddouska | 0:5045d2638c29 | 2704 | |
toddouska | 0:5045d2638c29 | 2705 | |
toddouska | 0:5045d2638c29 | 2706 | void BIO_set_flags(BIO* bio, int flags) |
toddouska | 0:5045d2638c29 | 2707 | { |
toddouska | 0:5045d2638c29 | 2708 | |
toddouska | 0:5045d2638c29 | 2709 | } |
toddouska | 0:5045d2638c29 | 2710 | |
toddouska | 0:5045d2638c29 | 2711 | |
toddouska | 0:5045d2638c29 | 2712 | |
toddouska | 0:5045d2638c29 | 2713 | void RAND_screen(void) |
toddouska | 0:5045d2638c29 | 2714 | { |
toddouska | 0:5045d2638c29 | 2715 | |
toddouska | 0:5045d2638c29 | 2716 | } |
toddouska | 0:5045d2638c29 | 2717 | |
toddouska | 0:5045d2638c29 | 2718 | |
toddouska | 0:5045d2638c29 | 2719 | const char* RAND_file_name(char* fname, size_t len) |
toddouska | 0:5045d2638c29 | 2720 | { |
toddouska | 0:5045d2638c29 | 2721 | return 0; |
toddouska | 0:5045d2638c29 | 2722 | } |
toddouska | 0:5045d2638c29 | 2723 | |
toddouska | 0:5045d2638c29 | 2724 | |
toddouska | 0:5045d2638c29 | 2725 | int RAND_write_file(const char* fname) |
toddouska | 0:5045d2638c29 | 2726 | { |
toddouska | 0:5045d2638c29 | 2727 | return 0; |
toddouska | 0:5045d2638c29 | 2728 | } |
toddouska | 0:5045d2638c29 | 2729 | |
toddouska | 0:5045d2638c29 | 2730 | |
toddouska | 0:5045d2638c29 | 2731 | int RAND_load_file(const char* fname, long len) |
toddouska | 0:5045d2638c29 | 2732 | { |
toddouska | 0:5045d2638c29 | 2733 | /* CTaoCrypt provides enough entropy internally or will report error */ |
toddouska | 0:5045d2638c29 | 2734 | if (len == -1) |
toddouska | 0:5045d2638c29 | 2735 | return 1024; |
toddouska | 0:5045d2638c29 | 2736 | else |
toddouska | 0:5045d2638c29 | 2737 | return (int)len; |
toddouska | 0:5045d2638c29 | 2738 | } |
toddouska | 0:5045d2638c29 | 2739 | |
toddouska | 0:5045d2638c29 | 2740 | |
toddouska | 0:5045d2638c29 | 2741 | int RAND_egd(const char* path) |
toddouska | 0:5045d2638c29 | 2742 | { |
toddouska | 0:5045d2638c29 | 2743 | return 0; |
toddouska | 0:5045d2638c29 | 2744 | } |
toddouska | 0:5045d2638c29 | 2745 | |
toddouska | 0:5045d2638c29 | 2746 | |
toddouska | 0:5045d2638c29 | 2747 | |
toddouska | 0:5045d2638c29 | 2748 | COMP_METHOD* COMP_zlib(void) |
toddouska | 0:5045d2638c29 | 2749 | { |
toddouska | 0:5045d2638c29 | 2750 | return 0; |
toddouska | 0:5045d2638c29 | 2751 | } |
toddouska | 0:5045d2638c29 | 2752 | |
toddouska | 0:5045d2638c29 | 2753 | |
toddouska | 0:5045d2638c29 | 2754 | COMP_METHOD* COMP_rle(void) |
toddouska | 0:5045d2638c29 | 2755 | { |
toddouska | 0:5045d2638c29 | 2756 | return 0; |
toddouska | 0:5045d2638c29 | 2757 | } |
toddouska | 0:5045d2638c29 | 2758 | |
toddouska | 0:5045d2638c29 | 2759 | |
toddouska | 0:5045d2638c29 | 2760 | int SSL_COMP_add_compression_method(int method, void* data) |
toddouska | 0:5045d2638c29 | 2761 | { |
toddouska | 0:5045d2638c29 | 2762 | return 0; |
toddouska | 0:5045d2638c29 | 2763 | } |
toddouska | 0:5045d2638c29 | 2764 | |
toddouska | 0:5045d2638c29 | 2765 | |
toddouska | 0:5045d2638c29 | 2766 | |
toddouska | 0:5045d2638c29 | 2767 | int SSL_get_ex_new_index(long idx, void* data, void* cb1, void* cb2, |
toddouska | 0:5045d2638c29 | 2768 | void* cb3) |
toddouska | 0:5045d2638c29 | 2769 | { |
toddouska | 0:5045d2638c29 | 2770 | return 0; |
toddouska | 0:5045d2638c29 | 2771 | } |
toddouska | 0:5045d2638c29 | 2772 | |
toddouska | 0:5045d2638c29 | 2773 | |
toddouska | 0:5045d2638c29 | 2774 | int CRYPTO_num_locks(void) |
toddouska | 0:5045d2638c29 | 2775 | { |
toddouska | 0:5045d2638c29 | 2776 | return 0; |
toddouska | 0:5045d2638c29 | 2777 | } |
toddouska | 0:5045d2638c29 | 2778 | |
toddouska | 0:5045d2638c29 | 2779 | |
toddouska | 0:5045d2638c29 | 2780 | void CRYPTO_set_id_callback(unsigned long (*f)(void)) |
toddouska | 0:5045d2638c29 | 2781 | { |
toddouska | 0:5045d2638c29 | 2782 | |
toddouska | 0:5045d2638c29 | 2783 | } |
toddouska | 0:5045d2638c29 | 2784 | |
toddouska | 0:5045d2638c29 | 2785 | |
toddouska | 0:5045d2638c29 | 2786 | void CRYPTO_set_locking_callback(void (*f)(int, int, const char*, int)) |
toddouska | 0:5045d2638c29 | 2787 | { |
toddouska | 0:5045d2638c29 | 2788 | |
toddouska | 0:5045d2638c29 | 2789 | } |
toddouska | 0:5045d2638c29 | 2790 | |
toddouska | 0:5045d2638c29 | 2791 | |
toddouska | 0:5045d2638c29 | 2792 | void CRYPTO_set_dynlock_create_callback(CRYPTO_dynlock_value* (*f)( |
toddouska | 0:5045d2638c29 | 2793 | const char*, int)) |
toddouska | 0:5045d2638c29 | 2794 | { |
toddouska | 0:5045d2638c29 | 2795 | |
toddouska | 0:5045d2638c29 | 2796 | } |
toddouska | 0:5045d2638c29 | 2797 | |
toddouska | 0:5045d2638c29 | 2798 | |
toddouska | 0:5045d2638c29 | 2799 | void CRYPTO_set_dynlock_lock_callback(void (*f)(int, CRYPTO_dynlock_value*, |
toddouska | 0:5045d2638c29 | 2800 | const char*, int)) |
toddouska | 0:5045d2638c29 | 2801 | { |
toddouska | 0:5045d2638c29 | 2802 | |
toddouska | 0:5045d2638c29 | 2803 | } |
toddouska | 0:5045d2638c29 | 2804 | |
toddouska | 0:5045d2638c29 | 2805 | |
toddouska | 0:5045d2638c29 | 2806 | void CRYPTO_set_dynlock_destroy_callback(void (*f)(CRYPTO_dynlock_value*, |
toddouska | 0:5045d2638c29 | 2807 | const char*, int)) |
toddouska | 0:5045d2638c29 | 2808 | { |
toddouska | 0:5045d2638c29 | 2809 | |
toddouska | 0:5045d2638c29 | 2810 | } |
toddouska | 0:5045d2638c29 | 2811 | |
toddouska | 0:5045d2638c29 | 2812 | |
toddouska | 0:5045d2638c29 | 2813 | |
toddouska | 0:5045d2638c29 | 2814 | const char* X509_verify_cert_error_string(long err) |
toddouska | 0:5045d2638c29 | 2815 | { |
toddouska | 0:5045d2638c29 | 2816 | return 0; |
toddouska | 0:5045d2638c29 | 2817 | } |
toddouska | 0:5045d2638c29 | 2818 | |
toddouska | 0:5045d2638c29 | 2819 | |
toddouska | 0:5045d2638c29 | 2820 | |
toddouska | 0:5045d2638c29 | 2821 | int X509_LOOKUP_add_dir(X509_LOOKUP* lookup, const char* dir, long len) |
toddouska | 0:5045d2638c29 | 2822 | { |
toddouska | 0:5045d2638c29 | 2823 | return 0; |
toddouska | 0:5045d2638c29 | 2824 | } |
toddouska | 0:5045d2638c29 | 2825 | |
toddouska | 0:5045d2638c29 | 2826 | |
toddouska | 0:5045d2638c29 | 2827 | int X509_LOOKUP_load_file(X509_LOOKUP* lookup, const char* file, long len) |
toddouska | 0:5045d2638c29 | 2828 | { |
toddouska | 0:5045d2638c29 | 2829 | return 0; |
toddouska | 0:5045d2638c29 | 2830 | } |
toddouska | 0:5045d2638c29 | 2831 | |
toddouska | 0:5045d2638c29 | 2832 | |
toddouska | 0:5045d2638c29 | 2833 | X509_LOOKUP_METHOD* X509_LOOKUP_hash_dir(void) |
toddouska | 0:5045d2638c29 | 2834 | { |
toddouska | 0:5045d2638c29 | 2835 | return 0; |
toddouska | 0:5045d2638c29 | 2836 | } |
toddouska | 0:5045d2638c29 | 2837 | |
toddouska | 0:5045d2638c29 | 2838 | |
toddouska | 0:5045d2638c29 | 2839 | X509_LOOKUP_METHOD* X509_LOOKUP_file(void) |
toddouska | 0:5045d2638c29 | 2840 | { |
toddouska | 0:5045d2638c29 | 2841 | return 0; |
toddouska | 0:5045d2638c29 | 2842 | } |
toddouska | 0:5045d2638c29 | 2843 | |
toddouska | 0:5045d2638c29 | 2844 | |
toddouska | 0:5045d2638c29 | 2845 | |
toddouska | 0:5045d2638c29 | 2846 | X509_LOOKUP* X509_STORE_add_lookup(X509_STORE* store, X509_LOOKUP_METHOD* m) |
toddouska | 0:5045d2638c29 | 2847 | { |
toddouska | 0:5045d2638c29 | 2848 | return 0; |
toddouska | 0:5045d2638c29 | 2849 | } |
toddouska | 0:5045d2638c29 | 2850 | |
toddouska | 0:5045d2638c29 | 2851 | |
toddouska | 0:5045d2638c29 | 2852 | X509_STORE* X509_STORE_new(void) |
toddouska | 0:5045d2638c29 | 2853 | { |
toddouska | 0:5045d2638c29 | 2854 | return 0; |
toddouska | 0:5045d2638c29 | 2855 | } |
toddouska | 0:5045d2638c29 | 2856 | |
toddouska | 0:5045d2638c29 | 2857 | |
toddouska | 0:5045d2638c29 | 2858 | int X509_STORE_get_by_subject(X509_STORE_CTX* ctx, int idx, X509_NAME* name, |
toddouska | 0:5045d2638c29 | 2859 | X509_OBJECT* obj) |
toddouska | 0:5045d2638c29 | 2860 | { |
toddouska | 0:5045d2638c29 | 2861 | return 0; |
toddouska | 0:5045d2638c29 | 2862 | } |
toddouska | 0:5045d2638c29 | 2863 | |
toddouska | 0:5045d2638c29 | 2864 | |
toddouska | 0:5045d2638c29 | 2865 | int X509_STORE_CTX_init(X509_STORE_CTX* ctx, X509_STORE* store, X509* x509, |
toddouska | 0:5045d2638c29 | 2866 | STACK_OF(X509)* sk) |
toddouska | 0:5045d2638c29 | 2867 | { |
toddouska | 0:5045d2638c29 | 2868 | return 0; |
toddouska | 0:5045d2638c29 | 2869 | } |
toddouska | 0:5045d2638c29 | 2870 | |
toddouska | 0:5045d2638c29 | 2871 | |
toddouska | 0:5045d2638c29 | 2872 | void X509_STORE_CTX_cleanup(X509_STORE_CTX* ctx) |
toddouska | 0:5045d2638c29 | 2873 | { |
toddouska | 0:5045d2638c29 | 2874 | |
toddouska | 0:5045d2638c29 | 2875 | } |
toddouska | 0:5045d2638c29 | 2876 | |
toddouska | 0:5045d2638c29 | 2877 | |
toddouska | 0:5045d2638c29 | 2878 | |
toddouska | 0:5045d2638c29 | 2879 | ASN1_TIME* X509_CRL_get_lastUpdate(X509_CRL* crl) |
toddouska | 0:5045d2638c29 | 2880 | { |
toddouska | 0:5045d2638c29 | 2881 | return 0; |
toddouska | 0:5045d2638c29 | 2882 | } |
toddouska | 0:5045d2638c29 | 2883 | |
toddouska | 0:5045d2638c29 | 2884 | |
toddouska | 0:5045d2638c29 | 2885 | ASN1_TIME* X509_CRL_get_nextUpdate(X509_CRL* crl) |
toddouska | 0:5045d2638c29 | 2886 | { |
toddouska | 0:5045d2638c29 | 2887 | return 0; |
toddouska | 0:5045d2638c29 | 2888 | } |
toddouska | 0:5045d2638c29 | 2889 | |
toddouska | 0:5045d2638c29 | 2890 | |
toddouska | 0:5045d2638c29 | 2891 | |
toddouska | 0:5045d2638c29 | 2892 | EVP_PKEY* X509_get_pubkey(X509* x509) |
toddouska | 0:5045d2638c29 | 2893 | { |
toddouska | 0:5045d2638c29 | 2894 | return 0; |
toddouska | 0:5045d2638c29 | 2895 | } |
toddouska | 0:5045d2638c29 | 2896 | |
toddouska | 0:5045d2638c29 | 2897 | |
toddouska | 0:5045d2638c29 | 2898 | int X509_CRL_verify(X509_CRL* crl, EVP_PKEY* key) |
toddouska | 0:5045d2638c29 | 2899 | { |
toddouska | 0:5045d2638c29 | 2900 | return 0; |
toddouska | 0:5045d2638c29 | 2901 | } |
toddouska | 0:5045d2638c29 | 2902 | |
toddouska | 0:5045d2638c29 | 2903 | |
toddouska | 0:5045d2638c29 | 2904 | void X509_STORE_CTX_set_error(X509_STORE_CTX* ctx, int err) |
toddouska | 0:5045d2638c29 | 2905 | { |
toddouska | 0:5045d2638c29 | 2906 | |
toddouska | 0:5045d2638c29 | 2907 | } |
toddouska | 0:5045d2638c29 | 2908 | |
toddouska | 0:5045d2638c29 | 2909 | |
toddouska | 0:5045d2638c29 | 2910 | void X509_OBJECT_free_contents(X509_OBJECT* obj) |
toddouska | 0:5045d2638c29 | 2911 | { |
toddouska | 0:5045d2638c29 | 2912 | |
toddouska | 0:5045d2638c29 | 2913 | } |
toddouska | 0:5045d2638c29 | 2914 | |
toddouska | 0:5045d2638c29 | 2915 | |
toddouska | 0:5045d2638c29 | 2916 | void EVP_PKEY_free(EVP_PKEY* key) |
toddouska | 0:5045d2638c29 | 2917 | { |
toddouska | 0:5045d2638c29 | 2918 | |
toddouska | 0:5045d2638c29 | 2919 | } |
toddouska | 0:5045d2638c29 | 2920 | |
toddouska | 0:5045d2638c29 | 2921 | |
toddouska | 0:5045d2638c29 | 2922 | int X509_cmp_current_time(const ASN1_TIME* time) |
toddouska | 0:5045d2638c29 | 2923 | { |
toddouska | 0:5045d2638c29 | 2924 | return 0; |
toddouska | 0:5045d2638c29 | 2925 | } |
toddouska | 0:5045d2638c29 | 2926 | |
toddouska | 0:5045d2638c29 | 2927 | |
toddouska | 0:5045d2638c29 | 2928 | int sk_X509_REVOKED_num(X509_REVOKED* revoked) |
toddouska | 0:5045d2638c29 | 2929 | { |
toddouska | 0:5045d2638c29 | 2930 | return 0; |
toddouska | 0:5045d2638c29 | 2931 | } |
toddouska | 0:5045d2638c29 | 2932 | |
toddouska | 0:5045d2638c29 | 2933 | |
toddouska | 0:5045d2638c29 | 2934 | |
toddouska | 0:5045d2638c29 | 2935 | X509_REVOKED* X509_CRL_get_REVOKED(X509_CRL* crl) |
toddouska | 0:5045d2638c29 | 2936 | { |
toddouska | 0:5045d2638c29 | 2937 | return 0; |
toddouska | 0:5045d2638c29 | 2938 | } |
toddouska | 0:5045d2638c29 | 2939 | |
toddouska | 0:5045d2638c29 | 2940 | |
toddouska | 0:5045d2638c29 | 2941 | X509_REVOKED* sk_X509_REVOKED_value(X509_REVOKED* revoked, int value) |
toddouska | 0:5045d2638c29 | 2942 | { |
toddouska | 0:5045d2638c29 | 2943 | return 0; |
toddouska | 0:5045d2638c29 | 2944 | } |
toddouska | 0:5045d2638c29 | 2945 | |
toddouska | 0:5045d2638c29 | 2946 | |
toddouska | 0:5045d2638c29 | 2947 | |
toddouska | 0:5045d2638c29 | 2948 | ASN1_INTEGER* X509_get_serialNumber(X509* x509) |
toddouska | 0:5045d2638c29 | 2949 | { |
toddouska | 0:5045d2638c29 | 2950 | return 0; |
toddouska | 0:5045d2638c29 | 2951 | } |
toddouska | 0:5045d2638c29 | 2952 | |
toddouska | 0:5045d2638c29 | 2953 | |
toddouska | 0:5045d2638c29 | 2954 | |
toddouska | 0:5045d2638c29 | 2955 | int ASN1_TIME_print(BIO* bio, const ASN1_TIME* time) |
toddouska | 0:5045d2638c29 | 2956 | { |
toddouska | 0:5045d2638c29 | 2957 | return 0; |
toddouska | 0:5045d2638c29 | 2958 | } |
toddouska | 0:5045d2638c29 | 2959 | |
toddouska | 0:5045d2638c29 | 2960 | |
toddouska | 0:5045d2638c29 | 2961 | |
toddouska | 0:5045d2638c29 | 2962 | int ASN1_INTEGER_cmp(const ASN1_INTEGER* a, const ASN1_INTEGER* b) |
toddouska | 0:5045d2638c29 | 2963 | { |
toddouska | 0:5045d2638c29 | 2964 | return 0; |
toddouska | 0:5045d2638c29 | 2965 | } |
toddouska | 0:5045d2638c29 | 2966 | |
toddouska | 0:5045d2638c29 | 2967 | |
toddouska | 0:5045d2638c29 | 2968 | long ASN1_INTEGER_get(const ASN1_INTEGER* i) |
toddouska | 0:5045d2638c29 | 2969 | { |
toddouska | 0:5045d2638c29 | 2970 | return 0; |
toddouska | 0:5045d2638c29 | 2971 | } |
toddouska | 0:5045d2638c29 | 2972 | |
toddouska | 0:5045d2638c29 | 2973 | |
toddouska | 0:5045d2638c29 | 2974 | |
toddouska | 0:5045d2638c29 | 2975 | void* X509_STORE_CTX_get_ex_data(X509_STORE_CTX* ctx, int idx) |
toddouska | 0:5045d2638c29 | 2976 | { |
toddouska | 0:5045d2638c29 | 2977 | return 0; |
toddouska | 0:5045d2638c29 | 2978 | } |
toddouska | 0:5045d2638c29 | 2979 | |
toddouska | 0:5045d2638c29 | 2980 | |
toddouska | 0:5045d2638c29 | 2981 | int SSL_get_ex_data_X509_STORE_CTX_idx(void) |
toddouska | 0:5045d2638c29 | 2982 | { |
toddouska | 0:5045d2638c29 | 2983 | return 0; |
toddouska | 0:5045d2638c29 | 2984 | } |
toddouska | 0:5045d2638c29 | 2985 | |
toddouska | 0:5045d2638c29 | 2986 | |
toddouska | 0:5045d2638c29 | 2987 | void* SSL_get_ex_data(const SSL* ssl, int idx) |
toddouska | 0:5045d2638c29 | 2988 | { |
toddouska | 0:5045d2638c29 | 2989 | return 0; |
toddouska | 0:5045d2638c29 | 2990 | } |
toddouska | 0:5045d2638c29 | 2991 | |
toddouska | 0:5045d2638c29 | 2992 | |
toddouska | 0:5045d2638c29 | 2993 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX* ctx, void* userdata) |
toddouska | 0:5045d2638c29 | 2994 | { |
toddouska | 0:5045d2638c29 | 2995 | ctx->userdata = userdata; |
toddouska | 0:5045d2638c29 | 2996 | } |
toddouska | 0:5045d2638c29 | 2997 | |
toddouska | 0:5045d2638c29 | 2998 | |
toddouska | 0:5045d2638c29 | 2999 | void SSL_CTX_set_default_passwd_cb(SSL_CTX* ctx, pem_password_cb cb) |
toddouska | 0:5045d2638c29 | 3000 | { |
toddouska | 0:5045d2638c29 | 3001 | ctx->passwd_cb = cb; |
toddouska | 0:5045d2638c29 | 3002 | } |
toddouska | 0:5045d2638c29 | 3003 | |
toddouska | 0:5045d2638c29 | 3004 | |
toddouska | 0:5045d2638c29 | 3005 | long SSL_CTX_set_timeout(SSL_CTX* ctx, long to) |
toddouska | 0:5045d2638c29 | 3006 | { |
toddouska | 0:5045d2638c29 | 3007 | return 0; |
toddouska | 0:5045d2638c29 | 3008 | } |
toddouska | 0:5045d2638c29 | 3009 | |
toddouska | 0:5045d2638c29 | 3010 | |
toddouska | 0:5045d2638c29 | 3011 | void SSL_CTX_set_info_callback(SSL_CTX* ctx, void (*f)()) |
toddouska | 0:5045d2638c29 | 3012 | { |
toddouska | 0:5045d2638c29 | 3013 | |
toddouska | 0:5045d2638c29 | 3014 | } |
toddouska | 0:5045d2638c29 | 3015 | |
toddouska | 0:5045d2638c29 | 3016 | |
toddouska | 0:5045d2638c29 | 3017 | unsigned long ERR_peek_error(void) |
toddouska | 0:5045d2638c29 | 3018 | { |
toddouska | 0:5045d2638c29 | 3019 | return 0; |
toddouska | 0:5045d2638c29 | 3020 | } |
toddouska | 0:5045d2638c29 | 3021 | |
toddouska | 0:5045d2638c29 | 3022 | |
toddouska | 0:5045d2638c29 | 3023 | int ERR_GET_REASON(int err) |
toddouska | 0:5045d2638c29 | 3024 | { |
toddouska | 0:5045d2638c29 | 3025 | return 0; |
toddouska | 0:5045d2638c29 | 3026 | } |
toddouska | 0:5045d2638c29 | 3027 | |
toddouska | 0:5045d2638c29 | 3028 | |
toddouska | 0:5045d2638c29 | 3029 | char* SSL_alert_type_string_long(int alert) |
toddouska | 0:5045d2638c29 | 3030 | { |
toddouska | 0:5045d2638c29 | 3031 | return 0; |
toddouska | 0:5045d2638c29 | 3032 | } |
toddouska | 0:5045d2638c29 | 3033 | |
toddouska | 0:5045d2638c29 | 3034 | |
toddouska | 0:5045d2638c29 | 3035 | char* SSL_alert_desc_string_long(int alert) |
toddouska | 0:5045d2638c29 | 3036 | { |
toddouska | 0:5045d2638c29 | 3037 | return 0; |
toddouska | 0:5045d2638c29 | 3038 | } |
toddouska | 0:5045d2638c29 | 3039 | |
toddouska | 0:5045d2638c29 | 3040 | |
toddouska | 0:5045d2638c29 | 3041 | char* SSL_state_string_long(SSL* ssl) |
toddouska | 0:5045d2638c29 | 3042 | { |
toddouska | 0:5045d2638c29 | 3043 | return 0; |
toddouska | 0:5045d2638c29 | 3044 | } |
toddouska | 0:5045d2638c29 | 3045 | |
toddouska | 0:5045d2638c29 | 3046 | |
toddouska | 0:5045d2638c29 | 3047 | |
toddouska | 0:5045d2638c29 | 3048 | void RSA_free(RSA* rsa) |
toddouska | 0:5045d2638c29 | 3049 | { |
toddouska | 0:5045d2638c29 | 3050 | |
toddouska | 0:5045d2638c29 | 3051 | } |
toddouska | 0:5045d2638c29 | 3052 | |
toddouska | 0:5045d2638c29 | 3053 | |
toddouska | 0:5045d2638c29 | 3054 | int PEM_def_callback(char* name, int num, int w, void* key) |
toddouska | 0:5045d2638c29 | 3055 | { |
toddouska | 0:5045d2638c29 | 3056 | return 0; |
toddouska | 0:5045d2638c29 | 3057 | } |
toddouska | 0:5045d2638c29 | 3058 | |
toddouska | 0:5045d2638c29 | 3059 | |
toddouska | 0:5045d2638c29 | 3060 | long SSL_CTX_sess_accept(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3061 | { |
toddouska | 0:5045d2638c29 | 3062 | return 0; |
toddouska | 0:5045d2638c29 | 3063 | } |
toddouska | 0:5045d2638c29 | 3064 | |
toddouska | 0:5045d2638c29 | 3065 | |
toddouska | 0:5045d2638c29 | 3066 | long SSL_CTX_sess_connect(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3067 | { |
toddouska | 0:5045d2638c29 | 3068 | return 0; |
toddouska | 0:5045d2638c29 | 3069 | } |
toddouska | 0:5045d2638c29 | 3070 | |
toddouska | 0:5045d2638c29 | 3071 | |
toddouska | 0:5045d2638c29 | 3072 | long SSL_CTX_sess_accept_good(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3073 | { |
toddouska | 0:5045d2638c29 | 3074 | return 0; |
toddouska | 0:5045d2638c29 | 3075 | } |
toddouska | 0:5045d2638c29 | 3076 | |
toddouska | 0:5045d2638c29 | 3077 | |
toddouska | 0:5045d2638c29 | 3078 | long SSL_CTX_sess_connect_good(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3079 | { |
toddouska | 0:5045d2638c29 | 3080 | return 0; |
toddouska | 0:5045d2638c29 | 3081 | } |
toddouska | 0:5045d2638c29 | 3082 | |
toddouska | 0:5045d2638c29 | 3083 | |
toddouska | 0:5045d2638c29 | 3084 | long SSL_CTX_sess_accept_renegotiate(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3085 | { |
toddouska | 0:5045d2638c29 | 3086 | return 0; |
toddouska | 0:5045d2638c29 | 3087 | } |
toddouska | 0:5045d2638c29 | 3088 | |
toddouska | 0:5045d2638c29 | 3089 | |
toddouska | 0:5045d2638c29 | 3090 | long SSL_CTX_sess_connect_renegotiate(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3091 | { |
toddouska | 0:5045d2638c29 | 3092 | return 0; |
toddouska | 0:5045d2638c29 | 3093 | } |
toddouska | 0:5045d2638c29 | 3094 | |
toddouska | 0:5045d2638c29 | 3095 | |
toddouska | 0:5045d2638c29 | 3096 | long SSL_CTX_sess_hits(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3097 | { |
toddouska | 0:5045d2638c29 | 3098 | return 0; |
toddouska | 0:5045d2638c29 | 3099 | } |
toddouska | 0:5045d2638c29 | 3100 | |
toddouska | 0:5045d2638c29 | 3101 | |
toddouska | 0:5045d2638c29 | 3102 | long SSL_CTX_sess_cb_hits(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3103 | { |
toddouska | 0:5045d2638c29 | 3104 | return 0; |
toddouska | 0:5045d2638c29 | 3105 | } |
toddouska | 0:5045d2638c29 | 3106 | |
toddouska | 0:5045d2638c29 | 3107 | |
toddouska | 0:5045d2638c29 | 3108 | long SSL_CTX_sess_cache_full(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3109 | { |
toddouska | 0:5045d2638c29 | 3110 | return 0; |
toddouska | 0:5045d2638c29 | 3111 | } |
toddouska | 0:5045d2638c29 | 3112 | |
toddouska | 0:5045d2638c29 | 3113 | |
toddouska | 0:5045d2638c29 | 3114 | long SSL_CTX_sess_misses(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3115 | { |
toddouska | 0:5045d2638c29 | 3116 | return 0; |
toddouska | 0:5045d2638c29 | 3117 | } |
toddouska | 0:5045d2638c29 | 3118 | |
toddouska | 0:5045d2638c29 | 3119 | |
toddouska | 0:5045d2638c29 | 3120 | long SSL_CTX_sess_timeouts(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3121 | { |
toddouska | 0:5045d2638c29 | 3122 | return 0; |
toddouska | 0:5045d2638c29 | 3123 | } |
toddouska | 0:5045d2638c29 | 3124 | |
toddouska | 0:5045d2638c29 | 3125 | |
toddouska | 0:5045d2638c29 | 3126 | long SSL_CTX_sess_number(SSL_CTX* ctx) |
toddouska | 0:5045d2638c29 | 3127 | { |
toddouska | 0:5045d2638c29 | 3128 | return 0; |
toddouska | 0:5045d2638c29 | 3129 | } |
toddouska | 0:5045d2638c29 | 3130 | |
toddouska | 0:5045d2638c29 | 3131 | |
toddouska | 0:5045d2638c29 | 3132 | void DES_set_key_unchecked(const_DES_cblock* des, DES_key_schedule* key) |
toddouska | 0:5045d2638c29 | 3133 | { |
toddouska | 0:5045d2638c29 | 3134 | } |
toddouska | 0:5045d2638c29 | 3135 | |
toddouska | 0:5045d2638c29 | 3136 | |
toddouska | 0:5045d2638c29 | 3137 | void DES_set_odd_parity(DES_cblock* des) |
toddouska | 0:5045d2638c29 | 3138 | { |
toddouska | 0:5045d2638c29 | 3139 | } |
toddouska | 0:5045d2638c29 | 3140 | |
toddouska | 0:5045d2638c29 | 3141 | |
toddouska | 0:5045d2638c29 | 3142 | void DES_ecb_encrypt(DES_cblock* desa, DES_cblock* desb, |
toddouska | 0:5045d2638c29 | 3143 | DES_key_schedule* key, int len) |
toddouska | 0:5045d2638c29 | 3144 | { |
toddouska | 0:5045d2638c29 | 3145 | } |
toddouska | 0:5045d2638c29 | 3146 | |
toddouska | 0:5045d2638c29 | 3147 | int BIO_printf(BIO* bio, const char* format, ...) |
toddouska | 0:5045d2638c29 | 3148 | { |
toddouska | 0:5045d2638c29 | 3149 | return 0; |
toddouska | 0:5045d2638c29 | 3150 | } |
toddouska | 0:5045d2638c29 | 3151 | |
toddouska | 0:5045d2638c29 | 3152 | |
toddouska | 0:5045d2638c29 | 3153 | int ASN1_UTCTIME_print(BIO* bio, const ASN1_UTCTIME* a) |
toddouska | 0:5045d2638c29 | 3154 | { |
toddouska | 0:5045d2638c29 | 3155 | return 0; |
toddouska | 0:5045d2638c29 | 3156 | } |
toddouska | 0:5045d2638c29 | 3157 | |
toddouska | 0:5045d2638c29 | 3158 | |
toddouska | 0:5045d2638c29 | 3159 | int sk_num(X509_REVOKED* rev) |
toddouska | 0:5045d2638c29 | 3160 | { |
toddouska | 0:5045d2638c29 | 3161 | return 0; |
toddouska | 0:5045d2638c29 | 3162 | } |
toddouska | 0:5045d2638c29 | 3163 | |
toddouska | 0:5045d2638c29 | 3164 | |
toddouska | 0:5045d2638c29 | 3165 | void* sk_value(X509_REVOKED* rev, int i) |
toddouska | 0:5045d2638c29 | 3166 | { |
toddouska | 0:5045d2638c29 | 3167 | return 0; |
toddouska | 0:5045d2638c29 | 3168 | } |
toddouska | 0:5045d2638c29 | 3169 | |
toddouska | 0:5045d2638c29 | 3170 | |
toddouska | 0:5045d2638c29 | 3171 | int EVP_BytesToKey(const EVP_CIPHER* type, const EVP_MD* md, |
toddouska | 0:5045d2638c29 | 3172 | const byte* salt, const byte* data, int sz, int count, |
toddouska | 0:5045d2638c29 | 3173 | byte* key, byte* iv) |
toddouska | 0:5045d2638c29 | 3174 | { |
toddouska | 0:5045d2638c29 | 3175 | int keyLen = 0; |
toddouska | 0:5045d2638c29 | 3176 | int ivLen = 0; |
toddouska | 0:5045d2638c29 | 3177 | |
toddouska | 0:5045d2638c29 | 3178 | Md5 myMD; |
toddouska | 0:5045d2638c29 | 3179 | byte digest[MD5_DIGEST_SIZE]; |
toddouska | 0:5045d2638c29 | 3180 | |
toddouska | 0:5045d2638c29 | 3181 | int j; |
toddouska | 0:5045d2638c29 | 3182 | int keyLeft; |
toddouska | 0:5045d2638c29 | 3183 | int ivLeft; |
toddouska | 0:5045d2638c29 | 3184 | int keyOutput = 0; |
toddouska | 0:5045d2638c29 | 3185 | |
toddouska | 0:5045d2638c29 | 3186 | InitMd5(&myMD); |
toddouska | 0:5045d2638c29 | 3187 | |
toddouska | 0:5045d2638c29 | 3188 | /* only support MD5 for now */ |
toddouska | 0:5045d2638c29 | 3189 | if (XSTRNCMP(md, "MD5", 3)) return 0; |
toddouska | 0:5045d2638c29 | 3190 | |
toddouska | 0:5045d2638c29 | 3191 | /* only support CBC DES and AES for now */ |
toddouska | 0:5045d2638c29 | 3192 | if (XSTRNCMP(type, "DES-CBC", 7) == 0) { |
toddouska | 0:5045d2638c29 | 3193 | keyLen = DES_KEY_SIZE; |
toddouska | 0:5045d2638c29 | 3194 | ivLen = DES_IV_SIZE; |
toddouska | 0:5045d2638c29 | 3195 | } |
toddouska | 0:5045d2638c29 | 3196 | else if (XSTRNCMP(type, "DES-EDE3-CBC", 12) == 0) { |
toddouska | 0:5045d2638c29 | 3197 | keyLen = DES3_KEY_SIZE; |
toddouska | 0:5045d2638c29 | 3198 | ivLen = DES_IV_SIZE; |
toddouska | 0:5045d2638c29 | 3199 | } |
toddouska | 0:5045d2638c29 | 3200 | else if (XSTRNCMP(type, "AES-128-CBC", 11) == 0) { |
toddouska | 0:5045d2638c29 | 3201 | keyLen = AES_128_KEY_SIZE; |
toddouska | 0:5045d2638c29 | 3202 | ivLen = AES_IV_SIZE; |
toddouska | 0:5045d2638c29 | 3203 | } |
toddouska | 0:5045d2638c29 | 3204 | else if (XSTRNCMP(type, "AES-192-CBC", 11) == 0) { |
toddouska | 0:5045d2638c29 | 3205 | keyLen = AES_192_KEY_SIZE; |
toddouska | 0:5045d2638c29 | 3206 | ivLen = AES_IV_SIZE; |
toddouska | 0:5045d2638c29 | 3207 | } |
toddouska | 0:5045d2638c29 | 3208 | else if (XSTRNCMP(type, "AES-256-CBC", 11) == 0) { |
toddouska | 0:5045d2638c29 | 3209 | keyLen = AES_256_KEY_SIZE; |
toddouska | 0:5045d2638c29 | 3210 | ivLen = AES_IV_SIZE; |
toddouska | 0:5045d2638c29 | 3211 | } |
toddouska | 0:5045d2638c29 | 3212 | else |
toddouska | 0:5045d2638c29 | 3213 | return 0; |
toddouska | 0:5045d2638c29 | 3214 | |
toddouska | 0:5045d2638c29 | 3215 | keyLeft = keyLen; |
toddouska | 0:5045d2638c29 | 3216 | ivLeft = ivLen; |
toddouska | 0:5045d2638c29 | 3217 | |
toddouska | 0:5045d2638c29 | 3218 | while (keyOutput < (keyLen + ivLen)) { |
toddouska | 0:5045d2638c29 | 3219 | int digestLeft = MD5_DIGEST_SIZE; |
toddouska | 0:5045d2638c29 | 3220 | /* D_(i - 1) */ |
toddouska | 0:5045d2638c29 | 3221 | if (keyOutput) /* first time D_0 is empty */ |
toddouska | 0:5045d2638c29 | 3222 | Md5Update(&myMD, digest, MD5_DIGEST_SIZE); |
toddouska | 0:5045d2638c29 | 3223 | /* data */ |
toddouska | 0:5045d2638c29 | 3224 | Md5Update(&myMD, data, sz); |
toddouska | 0:5045d2638c29 | 3225 | /* salt */ |
toddouska | 0:5045d2638c29 | 3226 | if (salt) |
toddouska | 0:5045d2638c29 | 3227 | Md5Update(&myMD, salt, EVP_SALT_SIZE); |
toddouska | 0:5045d2638c29 | 3228 | Md5Final(&myMD, digest); |
toddouska | 0:5045d2638c29 | 3229 | /* count */ |
toddouska | 0:5045d2638c29 | 3230 | for (j = 1; j < count; j++) { |
toddouska | 0:5045d2638c29 | 3231 | Md5Update(&myMD, digest, MD5_DIGEST_SIZE); |
toddouska | 0:5045d2638c29 | 3232 | Md5Final(&myMD, digest); |
toddouska | 0:5045d2638c29 | 3233 | } |
toddouska | 0:5045d2638c29 | 3234 | |
toddouska | 0:5045d2638c29 | 3235 | if (keyLeft) { |
toddouska | 0:5045d2638c29 | 3236 | int store = min(keyLeft, MD5_DIGEST_SIZE); |
toddouska | 0:5045d2638c29 | 3237 | XMEMCPY(&key[keyLen - keyLeft], digest, store); |
toddouska | 0:5045d2638c29 | 3238 | |
toddouska | 0:5045d2638c29 | 3239 | keyOutput += store; |
toddouska | 0:5045d2638c29 | 3240 | keyLeft -= store; |
toddouska | 0:5045d2638c29 | 3241 | digestLeft -= store; |
toddouska | 0:5045d2638c29 | 3242 | } |
toddouska | 0:5045d2638c29 | 3243 | |
toddouska | 0:5045d2638c29 | 3244 | if (ivLeft && digestLeft) { |
toddouska | 0:5045d2638c29 | 3245 | int store = min(ivLeft, digestLeft); |
toddouska | 0:5045d2638c29 | 3246 | XMEMCPY(&iv[ivLen - ivLeft], &digest[MD5_DIGEST_SIZE - |
toddouska | 0:5045d2638c29 | 3247 | digestLeft], store); |
toddouska | 0:5045d2638c29 | 3248 | keyOutput += store; |
toddouska | 0:5045d2638c29 | 3249 | ivLeft -= store; |
toddouska | 0:5045d2638c29 | 3250 | } |
toddouska | 0:5045d2638c29 | 3251 | } |
toddouska | 0:5045d2638c29 | 3252 | if (keyOutput != (keyLen + ivLen)) |
toddouska | 0:5045d2638c29 | 3253 | return 0; |
toddouska | 0:5045d2638c29 | 3254 | return keyOutput; |
toddouska | 0:5045d2638c29 | 3255 | } |
toddouska | 0:5045d2638c29 | 3256 | |
toddouska | 0:5045d2638c29 | 3257 | /* stunnel 4.28 needs */ |
toddouska | 0:5045d2638c29 | 3258 | void* SSL_CTX_get_ex_data(const SSL_CTX* ctx, int d) |
toddouska | 0:5045d2638c29 | 3259 | { |
toddouska | 0:5045d2638c29 | 3260 | return 0; |
toddouska | 0:5045d2638c29 | 3261 | } |
toddouska | 0:5045d2638c29 | 3262 | |
toddouska | 0:5045d2638c29 | 3263 | |
toddouska | 0:5045d2638c29 | 3264 | int SSL_CTX_set_ex_data(SSL_CTX* ctx, int d, void* p) |
toddouska | 0:5045d2638c29 | 3265 | { |
toddouska | 0:5045d2638c29 | 3266 | return SSL_SUCCESS; |
toddouska | 0:5045d2638c29 | 3267 | } |
toddouska | 0:5045d2638c29 | 3268 | |
toddouska | 0:5045d2638c29 | 3269 | |
toddouska | 0:5045d2638c29 | 3270 | void SSL_CTX_sess_set_get_cb(SSL_CTX* ctx, SSL_SESSION*(*f)(SSL*, |
toddouska | 0:5045d2638c29 | 3271 | unsigned char*, int, int*)) |
toddouska | 0:5045d2638c29 | 3272 | { |
toddouska | 0:5045d2638c29 | 3273 | |
toddouska | 0:5045d2638c29 | 3274 | } |
toddouska | 0:5045d2638c29 | 3275 | |
toddouska | 0:5045d2638c29 | 3276 | |
toddouska | 0:5045d2638c29 | 3277 | void SSL_CTX_sess_set_new_cb(SSL_CTX* ctx, int (*f)(SSL*, SSL_SESSION*)) |
toddouska | 0:5045d2638c29 | 3278 | { |
toddouska | 0:5045d2638c29 | 3279 | |
toddouska | 0:5045d2638c29 | 3280 | } |
toddouska | 0:5045d2638c29 | 3281 | |
toddouska | 0:5045d2638c29 | 3282 | |
toddouska | 0:5045d2638c29 | 3283 | void SSL_CTX_sess_set_remove_cb(SSL_CTX* ctx, void (*f)(SSL_CTX*, |
toddouska | 0:5045d2638c29 | 3284 | SSL_SESSION*)) |
toddouska | 0:5045d2638c29 | 3285 | { |
toddouska | 0:5045d2638c29 | 3286 | |
toddouska | 0:5045d2638c29 | 3287 | } |
toddouska | 0:5045d2638c29 | 3288 | |
toddouska | 0:5045d2638c29 | 3289 | |
toddouska | 0:5045d2638c29 | 3290 | int i2d_SSL_SESSION(SSL_SESSION* sess, unsigned char** p) |
toddouska | 0:5045d2638c29 | 3291 | { |
toddouska | 0:5045d2638c29 | 3292 | return sizeof(SSL_SESSION); |
toddouska | 0:5045d2638c29 | 3293 | } |
toddouska | 0:5045d2638c29 | 3294 | |
toddouska | 0:5045d2638c29 | 3295 | |
toddouska | 0:5045d2638c29 | 3296 | SSL_SESSION* d2i_SSL_SESSION(SSL_SESSION** sess, const unsigned char** p, |
toddouska | 0:5045d2638c29 | 3297 | long i) |
toddouska | 0:5045d2638c29 | 3298 | { |
toddouska | 0:5045d2638c29 | 3299 | return *sess; |
toddouska | 0:5045d2638c29 | 3300 | } |
toddouska | 0:5045d2638c29 | 3301 | |
toddouska | 0:5045d2638c29 | 3302 | |
toddouska | 0:5045d2638c29 | 3303 | long SSL_SESSION_get_timeout(const SSL_SESSION* sess) |
toddouska | 0:5045d2638c29 | 3304 | { |
toddouska | 0:5045d2638c29 | 3305 | return sess->timeout; |
toddouska | 0:5045d2638c29 | 3306 | } |
toddouska | 0:5045d2638c29 | 3307 | |
toddouska | 0:5045d2638c29 | 3308 | |
toddouska | 0:5045d2638c29 | 3309 | long SSL_SESSION_get_time(const SSL_SESSION* sess) |
toddouska | 0:5045d2638c29 | 3310 | { |
toddouska | 0:5045d2638c29 | 3311 | return sess->bornOn; |
toddouska | 0:5045d2638c29 | 3312 | } |
toddouska | 0:5045d2638c29 | 3313 | |
toddouska | 0:5045d2638c29 | 3314 | |
toddouska | 0:5045d2638c29 | 3315 | int SSL_CTX_get_ex_new_index(long idx, void* arg, void* a, void* b, void* c) |
toddouska | 0:5045d2638c29 | 3316 | { |
toddouska | 0:5045d2638c29 | 3317 | return 0; |
toddouska | 0:5045d2638c29 | 3318 | } |
toddouska | 0:5045d2638c29 | 3319 | |
toddouska | 0:5045d2638c29 | 3320 | |
toddouska | 0:5045d2638c29 | 3321 | #endif /* OPENSSL_EXTRA */ |
toddouska | 0:5045d2638c29 | 3322 | |
toddouska | 0:5045d2638c29 | 3323 | |
toddouska | 0:5045d2638c29 | 3324 | #ifdef SESSION_CERTS |
toddouska | 0:5045d2638c29 | 3325 | |
toddouska | 0:5045d2638c29 | 3326 | |
toddouska | 0:5045d2638c29 | 3327 | /* Get peer's certificate chain */ |
toddouska | 0:5045d2638c29 | 3328 | X509_CHAIN* CyaSSL_get_peer_chain(SSL* ssl) |
toddouska | 0:5045d2638c29 | 3329 | { |
toddouska | 0:5045d2638c29 | 3330 | if (ssl) |
toddouska | 0:5045d2638c29 | 3331 | return &ssl->session.chain; |
toddouska | 0:5045d2638c29 | 3332 | |
toddouska | 0:5045d2638c29 | 3333 | return 0; |
toddouska | 0:5045d2638c29 | 3334 | } |
toddouska | 0:5045d2638c29 | 3335 | |
toddouska | 0:5045d2638c29 | 3336 | |
toddouska | 0:5045d2638c29 | 3337 | /* Get peer's certificate chain total count */ |
toddouska | 0:5045d2638c29 | 3338 | int CyaSSL_get_chain_count(X509_CHAIN* chain) |
toddouska | 0:5045d2638c29 | 3339 | { |
toddouska | 0:5045d2638c29 | 3340 | if (chain) |
toddouska | 0:5045d2638c29 | 3341 | return chain->count; |
toddouska | 0:5045d2638c29 | 3342 | |
toddouska | 0:5045d2638c29 | 3343 | return 0; |
toddouska | 0:5045d2638c29 | 3344 | } |
toddouska | 0:5045d2638c29 | 3345 | |
toddouska | 0:5045d2638c29 | 3346 | |
toddouska | 0:5045d2638c29 | 3347 | /* Get peer's ASN.1 DER ceritifcate at index (idx) length in bytes */ |
toddouska | 0:5045d2638c29 | 3348 | int CyaSSL_get_chain_length(X509_CHAIN* chain, int idx) |
toddouska | 0:5045d2638c29 | 3349 | { |
toddouska | 0:5045d2638c29 | 3350 | if (chain) |
toddouska | 0:5045d2638c29 | 3351 | return chain->certs[idx].length; |
toddouska | 0:5045d2638c29 | 3352 | |
toddouska | 0:5045d2638c29 | 3353 | return 0; |
toddouska | 0:5045d2638c29 | 3354 | } |
toddouska | 0:5045d2638c29 | 3355 | |
toddouska | 0:5045d2638c29 | 3356 | |
toddouska | 0:5045d2638c29 | 3357 | /* Get peer's ASN.1 DER ceritifcate at index (idx) */ |
toddouska | 0:5045d2638c29 | 3358 | byte* CyaSSL_get_chain_cert(X509_CHAIN* chain, int idx) |
toddouska | 0:5045d2638c29 | 3359 | { |
toddouska | 0:5045d2638c29 | 3360 | if (chain) |
toddouska | 0:5045d2638c29 | 3361 | return chain->certs[idx].buffer; |
toddouska | 0:5045d2638c29 | 3362 | |
toddouska | 0:5045d2638c29 | 3363 | return 0; |
toddouska | 0:5045d2638c29 | 3364 | } |
toddouska | 0:5045d2638c29 | 3365 | |
toddouska | 0:5045d2638c29 | 3366 | |
toddouska | 0:5045d2638c29 | 3367 | /* Get peer's PEM ceritifcate at index (idx), output to buffer if inLen big |
toddouska | 0:5045d2638c29 | 3368 | enough else return error (-1), output length is in *outLen */ |
toddouska | 0:5045d2638c29 | 3369 | int CyaSSL_get_chain_cert_pem(X509_CHAIN* chain, int idx, |
toddouska | 0:5045d2638c29 | 3370 | unsigned char* buffer, int inLen, int* outLen) |
toddouska | 0:5045d2638c29 | 3371 | { |
toddouska | 0:5045d2638c29 | 3372 | const char header[] = "-----BEGIN CERTIFICATE-----\n"; |
toddouska | 0:5045d2638c29 | 3373 | const char footer[] = "-----END CERTIFICATE-----\n"; |
toddouska | 0:5045d2638c29 | 3374 | |
toddouska | 0:5045d2638c29 | 3375 | int headerLen = sizeof(header) - 1; |
toddouska | 0:5045d2638c29 | 3376 | int footerLen = sizeof(footer) - 1; |
toddouska | 0:5045d2638c29 | 3377 | int i; |
toddouska | 0:5045d2638c29 | 3378 | |
toddouska | 0:5045d2638c29 | 3379 | if (!chain || !outLen || !buffer) |
toddouska | 0:5045d2638c29 | 3380 | return -1; |
toddouska | 0:5045d2638c29 | 3381 | |
toddouska | 0:5045d2638c29 | 3382 | /* don't even try if inLen too short */ |
toddouska | 0:5045d2638c29 | 3383 | if (inLen < headerLen + footerLen + chain->certs[idx].length) |
toddouska | 0:5045d2638c29 | 3384 | return -1; |
toddouska | 0:5045d2638c29 | 3385 | |
toddouska | 0:5045d2638c29 | 3386 | /* header */ |
toddouska | 0:5045d2638c29 | 3387 | XMEMCPY(buffer, header, headerLen); |
toddouska | 0:5045d2638c29 | 3388 | i = headerLen; |
toddouska | 0:5045d2638c29 | 3389 | |
toddouska | 0:5045d2638c29 | 3390 | /* body */ |
toddouska | 0:5045d2638c29 | 3391 | *outLen = inLen; /* input to Base64Encode */ |
toddouska | 0:5045d2638c29 | 3392 | if (Base64Encode(chain->certs[idx].buffer, chain->certs[idx].length, |
toddouska | 0:5045d2638c29 | 3393 | buffer + i, (word32*)outLen) < 0) |
toddouska | 0:5045d2638c29 | 3394 | return -1; |
toddouska | 0:5045d2638c29 | 3395 | i += *outLen; |
toddouska | 0:5045d2638c29 | 3396 | |
toddouska | 0:5045d2638c29 | 3397 | /* footer */ |
toddouska | 0:5045d2638c29 | 3398 | if ( (i + footerLen) > inLen) |
toddouska | 0:5045d2638c29 | 3399 | return -1; |
toddouska | 0:5045d2638c29 | 3400 | XMEMCPY(buffer + i, footer, footerLen); |
toddouska | 0:5045d2638c29 | 3401 | *outLen += headerLen + footerLen; |
toddouska | 0:5045d2638c29 | 3402 | |
toddouska | 0:5045d2638c29 | 3403 | return 0; |
toddouska | 0:5045d2638c29 | 3404 | } |
toddouska | 0:5045d2638c29 | 3405 | |
toddouska | 0:5045d2638c29 | 3406 | |
toddouska | 0:5045d2638c29 | 3407 | /* get session ID */ |
toddouska | 0:5045d2638c29 | 3408 | const byte* CyaSSL_get_sessionID(const SSL_SESSION* session) |
toddouska | 0:5045d2638c29 | 3409 | { |
toddouska | 0:5045d2638c29 | 3410 | return session->sessionID; |
toddouska | 0:5045d2638c29 | 3411 | } |
toddouska | 0:5045d2638c29 | 3412 | |
toddouska | 0:5045d2638c29 | 3413 | |
toddouska | 0:5045d2638c29 | 3414 | #endif /* SESSION_CERTS */ |
toddouska | 0:5045d2638c29 | 3415 |