+ name[sizeof(name)-1] = 0; /* terminate name */
+ if (strcmp(name, "*UserAgent*") == 0) { /* default console */
+#ifdef HAVE_TLS
+ /* TLS Requirement */
+ if (director->tls_enable) {
+ if (director->tls_require) {
+ tls_local_need = BNET_TLS_REQUIRED;
+ } else {
+ tls_local_need = BNET_TLS_OK;
+ }
+ }
+
+ if (director->tls_verify_peer) {
+ verify_list = director->tls_allowed_cns;
+ }
+#endif /* HAVE_TLS */
+
+ auth_success = cram_md5_auth(ua, director->password, tls_local_need) &&
+ cram_md5_get_auth(ua, director->password, &tls_remote_need);
+ } else {
+ unbash_spaces(name);
+ cons = (CONRES *)GetResWithName(R_CONSOLE, name);
+ if (cons) {
+#ifdef HAVE_TLS
+ /* TLS Requirement */
+ if (cons->tls_enable) {
+ if (cons->tls_require) {
+ tls_local_need = BNET_TLS_REQUIRED;
+ } else {
+ tls_local_need = BNET_TLS_OK;
+ }
+ }
+
+ if (cons->tls_verify_peer) {
+ verify_list = cons->tls_allowed_cns;
+ }
+#endif /* HAVE_TLS */
+
+ auth_success = cram_md5_auth(ua, cons->password, tls_local_need) &&
+ cram_md5_get_auth(ua, cons->password, &tls_remote_need);
+
+ if (auth_success) {
+ uac->cons = cons; /* save console resource pointer */
+ }
+ } else {
+ auth_success = false;
+ goto auth_done;
+ }
+ }
+
+ /* Verify that the remote peer is willing to meet our TLS requirements */
+ if (tls_remote_need < tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
+ Emsg0(M_FATAL, 0, _("Authorization problem:"
+ " Remote client did not advertise required TLS support.\n"));
+ auth_success = false;
+ goto auth_done;
+ }
+
+ /* Verify that we are willing to meet the peer's requirements */
+ if (tls_remote_need > tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
+ Emsg0(M_FATAL, 0, _("Authorization problem:"
+ " Remote client requires TLS.\n"));
+ auth_success = false;
+ goto auth_done;
+ }
+
+#ifdef HAVE_TLS
+ if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) {
+ if (cons) {
+ tls_ctx = cons->tls_ctx;
+ } else {
+ tls_ctx = director->tls_ctx;
+ }
+
+ /* Engage TLS! Full Speed Ahead! */
+ if (!bnet_tls_server(tls_ctx, ua, verify_list)) {
+ Emsg0(M_ERROR, 0, _("TLS negotiation failed.\n"));
+ auth_success = false;
+ goto auth_done;
+ }
+ }
+#endif /* HAVE_TLS */
+