summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2015-09-11 17:03:03 +0000
committerjsing <>2015-09-11 17:03:03 +0000
commitd6a17a33bad1b73601de3cd3d861235bb94095e4 (patch)
tree566335f344d2d45b46306411899ca96eac0c558d /src/lib
parentc97e8bfe78ca48665c391112d5fd8c4954ec3db1 (diff)
downloadopenbsd-d6a17a33bad1b73601de3cd3d861235bb94095e4.tar.gz
openbsd-d6a17a33bad1b73601de3cd3d861235bb94095e4.tar.bz2
openbsd-d6a17a33bad1b73601de3cd3d861235bb94095e4.zip
Nuke ssl3_change_cipher_state().
ok "flensing knife"
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/src/ssl/s3_enc.c110
-rw-r--r--src/lib/libssl/src/ssl/ssl_locl.h3
-rw-r--r--src/lib/libssl/ssl_locl.h3
3 files changed, 3 insertions, 113 deletions
diff --git a/src/lib/libssl/src/ssl/s3_enc.c b/src/lib/libssl/src/ssl/s3_enc.c
index ced1083497..14c29e4edd 100644
--- a/src/lib/libssl/src/ssl/s3_enc.c
+++ b/src/lib/libssl/src/ssl/s3_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_enc.c,v 1.66 2015/09/11 17:01:19 jsing Exp $ */ 1/* $OpenBSD: s3_enc.c,v 1.67 2015/09/11 17:03:03 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -163,114 +163,6 @@ static unsigned char ssl3_pad_2[48] = {
163static int ssl3_handshake_mac(SSL *s, int md_nid, const char *sender, 163static int ssl3_handshake_mac(SSL *s, int md_nid, const char *sender,
164 int len, unsigned char *p); 164 int len, unsigned char *p);
165 165
166int
167ssl3_change_cipher_state(SSL *s, int which)
168{
169 const unsigned char *client_write_mac_secret, *server_write_mac_secret;
170 const unsigned char *client_write_key, *server_write_key;
171 const unsigned char *client_write_iv, *server_write_iv;
172 const unsigned char *mac_secret, *key, *iv;
173 unsigned char *key_block;
174 int mac_len, key_len, iv_len;
175 char is_read, use_client_keys;
176 EVP_CIPHER_CTX *cipher_ctx;
177 const EVP_CIPHER *cipher;
178 const EVP_MD *mac;
179
180
181 cipher = s->s3->tmp.new_sym_enc;
182 mac = s->s3->tmp.new_hash;
183
184 /* mac == NULL will lead to a crash later */
185 OPENSSL_assert(mac);
186
187 /*
188 * is_read is true if we have just read a ChangeCipherSpec message,
189 * that is we need to update the read cipherspec. Otherwise we have
190 * just written one.
191 */
192 is_read = (which & SSL3_CC_READ) != 0;
193
194 /*
195 * use_client_keys is true if we wish to use the keys for the "client
196 * write" direction. This is the case if we're a client sending a
197 * ChangeCipherSpec, or a server reading a client's ChangeCipherSpec.
198 */
199 use_client_keys = ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
200 (which == SSL3_CHANGE_CIPHER_SERVER_READ));
201
202
203 if (is_read) {
204 EVP_CIPHER_CTX_free(s->enc_read_ctx);
205 s->enc_read_ctx = NULL;
206 if ((cipher_ctx = EVP_CIPHER_CTX_new()) == NULL)
207 goto err;
208 s->enc_read_ctx = cipher_ctx;
209
210 if (ssl_replace_hash(&s->read_hash, mac) == NULL)
211 goto err;
212 } else {
213 EVP_CIPHER_CTX_free(s->enc_write_ctx);
214 s->enc_write_ctx = NULL;
215 if ((cipher_ctx = EVP_CIPHER_CTX_new()) == NULL)
216 goto err;
217 s->enc_write_ctx = cipher_ctx;
218
219 if (ssl_replace_hash(&s->write_hash, mac) == NULL)
220 goto err;
221 }
222
223 memset(is_read ? s->s3->read_sequence : s->s3->write_sequence,
224 0, SSL3_SEQUENCE_SIZE);
225
226 mac_len = EVP_MD_size(mac);
227 key_len = EVP_CIPHER_key_length(cipher);
228 iv_len = EVP_CIPHER_iv_length(cipher);
229
230 if (mac_len < 0)
231 goto err2;
232
233 key_block = s->s3->tmp.key_block;
234 client_write_mac_secret = key_block;
235 key_block += mac_len;
236 server_write_mac_secret = key_block;
237 key_block += mac_len;
238 client_write_key = key_block;
239 key_block += key_len;
240 server_write_key = key_block;
241 key_block += key_len;
242 client_write_iv = key_block;
243 key_block += iv_len;
244 server_write_iv = key_block;
245 key_block += iv_len;
246
247 if (use_client_keys) {
248 mac_secret = client_write_mac_secret;
249 key = client_write_key;
250 iv = client_write_iv;
251 } else {
252 mac_secret = server_write_mac_secret;
253 key = server_write_key;
254 iv = server_write_iv;
255 }
256
257 if (key_block - s->s3->tmp.key_block != s->s3->tmp.key_block_length) {
258 SSLerr(SSL_F_SSL3_CHANGE_CIPHER_STATE, ERR_R_INTERNAL_ERROR);
259 goto err2;
260 }
261
262 memcpy(is_read ? s->s3->read_mac_secret : s->s3->write_mac_secret,
263 mac_secret, mac_len);
264
265 EVP_CipherInit_ex(cipher_ctx, cipher, NULL, key, iv, !is_read);
266
267 return (1);
268err:
269 SSLerr(SSL_F_SSL3_CHANGE_CIPHER_STATE, ERR_R_MALLOC_FAILURE);
270err2:
271 return (0);
272}
273
274void 166void
275ssl3_cleanup_key_block(SSL *s) 167ssl3_cleanup_key_block(SSL *s)
276{ 168{
diff --git a/src/lib/libssl/src/ssl/ssl_locl.h b/src/lib/libssl/src/ssl/ssl_locl.h
index ec30c9cb6a..e4c6c45196 100644
--- a/src/lib/libssl/src/ssl/ssl_locl.h
+++ b/src/lib/libssl/src/ssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.109 2015/09/11 17:01:19 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.110 2015/09/11 17:03:03 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -603,7 +603,6 @@ int ssl3_send_newsession_ticket(SSL *s);
603int ssl3_send_cert_status(SSL *s); 603int ssl3_send_cert_status(SSL *s);
604int ssl3_get_finished(SSL *s, int state_a, int state_b); 604int ssl3_get_finished(SSL *s, int state_a, int state_b);
605int ssl3_send_change_cipher_spec(SSL *s, int state_a, int state_b); 605int ssl3_send_change_cipher_spec(SSL *s, int state_a, int state_b);
606int ssl3_change_cipher_state(SSL *s, int which);
607void ssl3_cleanup_key_block(SSL *s); 606void ssl3_cleanup_key_block(SSL *s);
608int ssl3_do_write(SSL *s, int type); 607int ssl3_do_write(SSL *s, int type);
609int ssl3_send_alert(SSL *s, int level, int desc); 608int ssl3_send_alert(SSL *s, int level, int desc);
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index ec30c9cb6a..e4c6c45196 100644
--- a/src/lib/libssl/ssl_locl.h
+++ b/src/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.109 2015/09/11 17:01:19 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.110 2015/09/11 17:03:03 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -603,7 +603,6 @@ int ssl3_send_newsession_ticket(SSL *s);
603int ssl3_send_cert_status(SSL *s); 603int ssl3_send_cert_status(SSL *s);
604int ssl3_get_finished(SSL *s, int state_a, int state_b); 604int ssl3_get_finished(SSL *s, int state_a, int state_b);
605int ssl3_send_change_cipher_spec(SSL *s, int state_a, int state_b); 605int ssl3_send_change_cipher_spec(SSL *s, int state_a, int state_b);
606int ssl3_change_cipher_state(SSL *s, int which);
607void ssl3_cleanup_key_block(SSL *s); 606void ssl3_cleanup_key_block(SSL *s);
608int ssl3_do_write(SSL *s, int type); 607int ssl3_do_write(SSL *s, int type);
609int ssl3_send_alert(SSL *s, int level, int desc); 608int ssl3_send_alert(SSL *s, int level, int desc);