|
|
|
@ -35,29 +35,12 @@
|
|
|
|
|
|
|
|
|
|
#define CERT_EXPIRY_TIME (60*60*24*30) /* 30 days */
|
|
|
|
|
|
|
|
|
|
INLINE struct stream_fd *dtls_primary(struct packet_stream *ps) {
|
|
|
|
|
if (!ps->sfds.length)
|
|
|
|
|
return NULL;
|
|
|
|
|
return ps->sfds.head->data;
|
|
|
|
|
}
|
|
|
|
|
// determine the sfd to hold our DTLS context if we don't know the sfd.
|
|
|
|
|
// it's either the "selected_sfd" for regular multi-homed streams, or
|
|
|
|
|
// the first sfd in the list in case ICE is in use
|
|
|
|
|
struct stream_fd *dtls_sfd(struct packet_stream *ps) {
|
|
|
|
|
if (!ps)
|
|
|
|
|
return NULL;
|
|
|
|
|
if (PS_ISSET(ps, ICE))
|
|
|
|
|
return dtls_primary(ps);
|
|
|
|
|
return ps->selected_sfd;
|
|
|
|
|
}
|
|
|
|
|
// determine the DTLS context if we do have an sfd. can be sfd->dtls,
|
|
|
|
|
// or in case ICE is in use, the first sfd's context.
|
|
|
|
|
struct dtls_connection *dtls_ptr(struct stream_fd *sfd) {
|
|
|
|
|
if (!sfd)
|
|
|
|
|
return NULL;
|
|
|
|
|
struct packet_stream *ps = sfd->stream;
|
|
|
|
|
if (PS_ISSET(ps, ICE)) // ignore which sfd we were given
|
|
|
|
|
sfd = dtls_primary(ps);
|
|
|
|
|
return &ps->ice_dtls;
|
|
|
|
|
return &sfd->dtls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -403,15 +386,15 @@ struct dtls_cert *dtls_cert() {
|
|
|
|
|
|
|
|
|
|
static int verify_callback(int ok, X509_STORE_CTX *store) {
|
|
|
|
|
SSL *ssl;
|
|
|
|
|
struct stream_fd *sfd;
|
|
|
|
|
struct dtls_connection *d;
|
|
|
|
|
struct packet_stream *ps;
|
|
|
|
|
struct call_media *media;
|
|
|
|
|
|
|
|
|
|
ssl = X509_STORE_CTX_get_ex_data(store, SSL_get_ex_data_X509_STORE_CTX_idx());
|
|
|
|
|
sfd = SSL_get_app_data(ssl);
|
|
|
|
|
if (sfd->dtls.ssl != ssl)
|
|
|
|
|
d = SSL_get_app_data(ssl);
|
|
|
|
|
if (d->ssl != ssl)
|
|
|
|
|
return 0;
|
|
|
|
|
ps = sfd->stream;
|
|
|
|
|
ps = d->ptr;
|
|
|
|
|
if (!ps)
|
|
|
|
|
return 0;
|
|
|
|
|
if (PS_ISSET(ps, FINGERPRINT_VERIFIED))
|
|
|
|
@ -499,15 +482,11 @@ static int try_connect(struct dtls_connection *d) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dtls_connection_init(struct packet_stream *ps, int active, struct dtls_cert *cert) {
|
|
|
|
|
struct dtls_connection *d;
|
|
|
|
|
int dtls_connection_init(struct dtls_connection *d, struct packet_stream *ps, int active,
|
|
|
|
|
struct dtls_cert *cert)
|
|
|
|
|
{
|
|
|
|
|
unsigned long err;
|
|
|
|
|
|
|
|
|
|
struct stream_fd *sfd = dtls_sfd(ps);
|
|
|
|
|
if (!sfd)
|
|
|
|
|
return 0;
|
|
|
|
|
d = &sfd->dtls;
|
|
|
|
|
|
|
|
|
|
__DBG("dtls_connection_init(%i)", active);
|
|
|
|
|
|
|
|
|
|
if (d->init) {
|
|
|
|
@ -516,6 +495,8 @@ int dtls_connection_init(struct packet_stream *ps, int active, struct dtls_cert
|
|
|
|
|
dtls_connection_cleanup(d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->ptr = ps;
|
|
|
|
|
|
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
|
|
|
|
d->ssl_ctx = SSL_CTX_new(active ? DTLS_client_method() : DTLS_server_method());
|
|
|
|
|
#else
|
|
|
|
@ -548,7 +529,7 @@ int dtls_connection_init(struct packet_stream *ps, int active, struct dtls_cert
|
|
|
|
|
if (!d->r_bio || !d->w_bio)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
SSL_set_app_data(d->ssl, sfd); /* XXX obj reference here? */
|
|
|
|
|
SSL_set_app_data(d->ssl, d);
|
|
|
|
|
SSL_set_bio(d->ssl, d->r_bio, d->w_bio);
|
|
|
|
|
d->init = 1;
|
|
|
|
|
SSL_set_mode(d->ssl, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
|
|
|
|