aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2016-02-03 00:27:44 +0100
committerRichard Levitte <levitte@openssl.org>2016-02-03 19:40:32 +0100
commitd858c87653257185ead1c5baf3d84cd7276dd912 (patch)
tree88c6ea3d7634e2cd36e4d4910d5d7f81a32562fc /apps
parent75d5bd4e7d61ba3ed845f9e8170eac6a48a26407 (diff)
downloadopenssl-d858c87653257185ead1c5baf3d84cd7276dd912.tar.gz
Refactoring BIO: Adapt BIO_s_datagram and all that depends on it
The control commands that previously took a struct sockaddr * have been changed to take a BIO_ADDR * instead. Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Diffstat (limited to 'apps')
-rw-r--r--apps/s_cb.c60
-rw-r--r--apps/s_server.c14
2 files changed, 27 insertions, 47 deletions
diff --git a/apps/s_cb.c b/apps/s_cb.c
index 5e36e7e2f8..dd4aa929c2 100644
--- a/apps/s_cb.c
+++ b/apps/s_cb.c
@@ -737,14 +737,9 @@ int generate_cookie_callback(SSL *ssl, unsigned char *cookie,
unsigned int *cookie_len)
{
unsigned char *buffer;
- unsigned int length;
- union {
- struct sockaddr sa;
- struct sockaddr_in s4;
-#if OPENSSL_USE_IPV6
- struct sockaddr_in6 s6;
-#endif
- } peer;
+ size_t length;
+ unsigned short port;
+ BIO_ADDR *peer = NULL;
/* Initialize a random secret */
if (!cookie_initialized) {
@@ -755,50 +750,31 @@ int generate_cookie_callback(SSL *ssl, unsigned char *cookie,
cookie_initialized = 1;
}
+ peer = BIO_ADDR_new();
+ if (peer == NULL) {
+ BIO_printf(bio_err, "memory full\n");
+ return 0;
+ }
+
/* Read peer information */
- (void)BIO_dgram_get_peer(SSL_get_rbio(ssl), &peer);
+ (void)BIO_dgram_get_peer(SSL_get_rbio(ssl), peer);
/* Create buffer with peer's address and port */
- length = 0;
- switch (peer.sa.sa_family) {
- case AF_INET:
- length += sizeof(struct in_addr);
- length += sizeof(peer.s4.sin_port);
- break;
-#if OPENSSL_USE_IPV6
- case AF_INET6:
- length += sizeof(struct in6_addr);
- length += sizeof(peer.s6.sin6_port);
- break;
-#endif
- default:
- OPENSSL_assert(0);
- break;
- }
+ BIO_ADDR_rawaddress(peer, NULL, &length);
+ OPENSSL_assert(length != 0);
+ port = BIO_ADDR_rawport(peer);
+ length += sizeof(port);
buffer = app_malloc(length, "cookie generate buffer");
- switch (peer.sa.sa_family) {
- case AF_INET:
- memcpy(buffer, &peer.s4.sin_port, sizeof(peer.s4.sin_port));
- memcpy(buffer + sizeof(peer.s4.sin_port),
- &peer.s4.sin_addr, sizeof(struct in_addr));
- break;
-#if OPENSSL_USE_IPV6
- case AF_INET6:
- memcpy(buffer, &peer.s6.sin6_port, sizeof(peer.s6.sin6_port));
- memcpy(buffer + sizeof(peer.s6.sin6_port),
- &peer.s6.sin6_addr, sizeof(struct in6_addr));
- break;
-#endif
- default:
- OPENSSL_assert(0);
- break;
- }
+ memcpy(buffer, &port, sizeof(port));
+ BIO_ADDR_rawaddress(peer, buffer + sizeof(port), NULL);
/* Calculate HMAC of buffer using the secret */
HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH,
buffer, length, cookie, cookie_len);
+
OPENSSL_free(buffer);
+ BIO_ADDR_free(peer);
return 1;
}
diff --git a/apps/s_server.c b/apps/s_server.c
index 6467060c0f..848ba1f0a2 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -2432,12 +2432,15 @@ static int init_ssl_connection(SSL *con)
unsigned next_proto_neg_len;
#endif
unsigned char *exportedkeymat;
-#ifndef OPENSSL_NO_DTLS
- struct sockaddr_storage client;
-#endif
#ifndef OPENSSL_NO_DTLS
if(dtlslisten) {
+ BIO_ADDR *client = NULL;
+
+ if ((client = BIO_ADDR_new()) == NULL) {
+ BIO_printf(bio_err, "ERROR - memory\n");
+ return 0;
+ }
i = DTLSv1_listen(con, &client);
if (i > 0) {
BIO *wbio;
@@ -2448,11 +2451,12 @@ static int init_ssl_connection(SSL *con)
BIO_get_fd(wbio, &fd);
}
- if(!wbio || connect(fd, (struct sockaddr *)&client,
- sizeof(struct sockaddr_storage))) {
+ if(!wbio || BIO_connect(fd, client, 0) == 0) {
BIO_printf(bio_err, "ERROR - unable to connect\n");
+ BIO_ADDR_free(client);
return 0;
}
+ BIO_ADDR_free(client);
dtlslisten = 0;
i = SSL_accept(con);
}