Skip to content

Commit

Permalink
tls: use TlsPolicy instead of pure integer
Browse files Browse the repository at this point in the history
- tls_need is now TlsPolicy variable tls_policy
  • Loading branch information
franku committed Nov 27, 2018
1 parent 167a31d commit 85b454b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
15 changes: 7 additions & 8 deletions core/src/dird/restore.cc
Expand Up @@ -235,8 +235,6 @@ static inline bool DoNativeRestoreBootstrap(JobControlRecord *jcr)
}

if (!jcr->passive_client) {
uint32_t tls_need = 0;

/*
* When the client is not in passive mode we can put the SD in
* listen mode for the FD connection. And ask the FD to connect
Expand Down Expand Up @@ -266,20 +264,19 @@ static inline bool DoNativeRestoreBootstrap(JobControlRecord *jcr)
/*
* TLS Requirement
*/
tls_need = store->IsTlsConfigured() ? TlsPolicy::kBnetTlsAuto : TlsPolicy::kBnetTlsNone;
TlsPolicy tls_policy = store->IsTlsConfigured() ? TlsPolicy::kBnetTlsAuto : TlsPolicy::kBnetTlsNone;

connection_target_address = StorageAddressToContact(client, store);

fd->fsend(storaddrcmd, connection_target_address,
store->SDDport, tls_need, jcr->sd_auth_key);
store->SDDport, tls_policy, jcr->sd_auth_key);
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));

Dmsg1(6, "dird>filed: %s", fd->msg);
if (!response(jcr, fd, OKstore, "Storage", DISPLAY_ERROR)) {
goto bail_out;
}
} else {
uint32_t tls_need = 0;
/*
* In passive mode we tell the FD what authorization key to use
* and the ask the SD to initiate the connection.
Expand All @@ -292,17 +289,19 @@ static inline bool DoNativeRestoreBootstrap(JobControlRecord *jcr)
goto bail_out;
}

TlsPolicy tls_policy;

if (jcr->res.client->connection_successful_handshake_ != ClientConnectionHandshakeMode::kTlsFirst) {
tls_need = client->GetPolicy();
tls_policy = client->GetPolicy();
} else {
tls_need = client->IsTlsConfigured() ? TlsPolicy::kBnetTlsAuto : TlsPolicy::kBnetTlsNone;
tls_policy = client->IsTlsConfigured() ? TlsPolicy::kBnetTlsAuto : TlsPolicy::kBnetTlsNone;
}

connection_target_address = ClientAddressToContact(client, store);
/*
* Tell the SD to connect to the FD.
*/
sd->fsend(passiveclientcmd, connection_target_address, client->FDport, tls_need);
sd->fsend(passiveclientcmd, connection_target_address, client->FDport, tls_policy);
Bmicrosleep(2,0);
if (!response(jcr, sd, OKpassiveclient, "Passive client", DISPLAY_ERROR)) {
goto bail_out;
Expand Down
2 changes: 1 addition & 1 deletion core/src/filed/dir_cmd.cc
Expand Up @@ -1586,7 +1586,7 @@ static bool StorageCmd(JobControlRecord *jcr)

jcr->store_bsock = storage_daemon_socket;

if (me->IsTlsConfigured() || tls_policy == TlsPolicy::kBnetTlsAuto) {
if (tls_policy == TlsPolicy::kBnetTlsAuto) {
std::string qualified_resource_name;
if (!my_config->GetQualifiedResourceNameTypeConverter()->ResourceToString(
jcr->Job, R_JOB, jcr->JobId, qualified_resource_name)) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/include/jcr.h
Expand Up @@ -681,7 +681,7 @@ extern JobControlRecord *get_jcr_by_session(uint32_t SessionId, uint32_t Session
extern JobControlRecord *get_jcr_by_partial_name(char *Job);
extern JobControlRecord *get_jcr_by_full_name(char *Job);
extern const char *JcrGetAuthenticateKey(uint32_t job_id, const char *unified_job_name);
TlsPolicy JcrGetTlsPolicy(const char *unified_job_name);
TlsPolicy JcrGetTlsPolicy(uint32_t job_id, const char *unified_job_name);
extern JobControlRecord *get_next_jcr(JobControlRecord *jcr);
extern void SetJcrJobStatus(JobControlRecord *jcr, int JobStatus);
extern int num_jobs_run;
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/jcr.cc
Expand Up @@ -843,7 +843,7 @@ const char *JcrGetAuthenticateKey(uint32_t job_id, const char *unified_job_name)
return auth_key;
}

TlsPolicy JcrGetTlsPolicy(const char *unified_job_name)
TlsPolicy JcrGetTlsPolicy(uint32_t job_id, const char *unified_job_name)
{
if (!unified_job_name) { return kBnetTlsUnknown; }

Expand Down
21 changes: 17 additions & 4 deletions core/src/lib/parse_conf.cc
Expand Up @@ -55,6 +55,8 @@
#include "lib/edit.h"
#include "lib/parse_conf.h"
#include "lib/qualified_resource_name_type_converter.h"
#include "lib/bstringlist.h"
#include "lib/ascii_control_characters.h"

#if defined(HAVE_WIN32)
#include "shlobj.h"
Expand Down Expand Up @@ -1026,11 +1028,22 @@ bool ConfigurationParser::GetConfiguredTlsPolicy(const std::string &r_code_str,
}
tls_policy = own_tls_resource->GetPolicy();
} else if(r_code_str == std::string("R_JOB")) {
TlsPolicy policy = JcrGetTlsPolicy(name.c_str());
if (policy == kBnetTlsUnknown) {
return false;
BStringList job_information(name, AsciiControlCharacters::RecordSeparator());
if (job_information.size() >= 3) {
uint32_t job_id;
try {
job_id = stoi(job_information[2]);
}
catch(const std::exception &e) {
return false;
}
TlsPolicy policy = JcrGetTlsPolicy(job_id, job_information[1].c_str());
if (policy != kBnetTlsUnknown) {
tls_policy = policy;
return true;
}
}
tls_policy = policy;
return false;
}
else {
uint32_t r_code = qualified_resource_name_type_converter_->StringToResourceType(r_code_str);
Expand Down

0 comments on commit 85b454b

Please sign in to comment.