static pn_event_type_t ssl_handler(test_handler_t *h, pn_event_t *e) { switch (pn_event_type(e)) { case PN_CONNECTION_BOUND: TEST_CHECK(h->t, 0 == pn_ssl_init(pn_ssl(pn_event_transport(e)), h->ssl_domain, NULL)); return PN_EVENT_NONE; case PN_CONNECTION_REMOTE_OPEN: { pn_ssl_t *ssl = pn_ssl(pn_event_transport(e)); TEST_CHECK(h->t, ssl); char protocol[256]; TEST_CHECK(h->t, pn_ssl_get_protocol_name(ssl, protocol, sizeof(protocol))); TEST_STR_IN(h->t, "TLS", protocol); return PN_CONNECTION_REMOTE_OPEN; } default: return PN_EVENT_NONE; } }
void apply(connection& c) { pn_connection_t *pnc = connection_options::pn_connection(c); pn_transport_t *pnt = pn_connection_transport(pnc); connector *outbound = dynamic_cast<connector*>( connection_context::get(c).handler.get()); bool uninit = (c.state() & endpoint::LOCAL_UNINIT); // pnt is NULL between reconnect attempts. // Only apply transport options if uninit or outbound with // transport not yet configured. if (pnt && (uninit || (outbound && !outbound->transport_configured()))) { // SSL if (outbound && outbound->address().scheme() == url::AMQPS) { pn_ssl_t *ssl = pn_ssl(pnt); if (pn_ssl_init(ssl, ssl_client_options.value.pn_domain(), NULL)) throw error(MSG("client SSL/TLS initialization error")); } else if (!outbound) { pn_acceptor_t *pnp = pn_connection_acceptor(pnc); if (pnp) { listener_context &lc(listener_context::get(pnp)); if (lc.ssl) { pn_ssl_t *ssl = pn_ssl(pnt); if (pn_ssl_init(ssl, ssl_server_options.value.pn_domain(), NULL)) throw error(MSG("server SSL/TLS initialization error")); } } } // SASL transport t = c.transport(); if (!sasl_enabled.set || sasl_enabled.value) { if (sasl_enabled.set) // Explicitly set, not just default behaviour. t.sasl(); // Force a sasl instance. Lazily create one otherwise. if (sasl_allow_insecure_mechs.set) t.sasl().allow_insecure_mechs(sasl_allow_insecure_mechs.value); if (sasl_allowed_mechs.set) t.sasl().allowed_mechs(sasl_allowed_mechs.value); if (sasl_config_name.set) t.sasl().config_name(sasl_config_name.value); if (sasl_config_path.set) t.sasl().config_path(sasl_config_path.value); } if (max_frame_size.set) pn_transport_set_max_frame(pnt, max_frame_size.value); if (max_channels.set) pn_transport_set_channel_max(pnt, max_channels.value); if (idle_timeout.set) pn_transport_set_idle_timeout(pnt, idle_timeout.value.ms()); } // Only apply connection options if uninit. if (uninit) { if (reconnect.set && outbound) outbound->reconnect_timer(reconnect.value); if (container_id.set) pn_connection_set_container(pnc, container_id.value.c_str()); if (link_prefix.set) connection_context::get(pnc).link_gen.prefix(link_prefix.value); } }