Skip to content
Snippets Groups Projects
Commit 08bfac10 authored by Hans Trompert's avatar Hans Trompert
Browse files

base_url and non-TLS mode client authentication

- in a proxied setup base_url is not just the combination of host+port, in this
  case use base_url to specify your outside endpoint
- even in non-TLS mode enable client authentication when a key and certificate
  are specified
parent 0b7c2c68
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
# host=example.org # host=example.org
# port=9443 # port=9443
## in a proxied setup specify base_url
# base_url=https://opennsa.example.domain/
## security settings ## security settings
#tls=true # defaults to true #tls=true # defaults to true
......
...@@ -44,6 +44,7 @@ LOG_FILE = 'logfile' ...@@ -44,6 +44,7 @@ LOG_FILE = 'logfile'
HOST = 'host' HOST = 'host'
PORT = 'port' PORT = 'port'
TLS = 'tls' TLS = 'tls'
BASE_URL = 'base_url'
REST = 'rest' REST = 'rest'
NRM_MAP_FILE = 'nrmmap' NRM_MAP_FILE = 'nrmmap'
PEERS = 'peers' PEERS = 'peers'
...@@ -309,6 +310,11 @@ class Config(object): ...@@ -309,6 +310,11 @@ class Config(object):
vc[TLS] = cfg.getboolean(BLOCK_SERVICE, TLS, fallback=DEFAULT_TLS) vc[TLS] = cfg.getboolean(BLOCK_SERVICE, TLS, fallback=DEFAULT_TLS)
vc[PORT] = cfg.getint(BLOCK_SERVICE, PORT, fallback=DEFAULT_TLS_PORT if vc[TLS] else DEFAULT_TCP_PORT) vc[PORT] = cfg.getint(BLOCK_SERVICE, PORT, fallback=DEFAULT_TLS_PORT if vc[TLS] else DEFAULT_TCP_PORT)
try:
vc[BASE_URL] = cfg.get(BLOCK_SERVICE, BASE_URL)
except configparser.NoOptionError:
vc[BASE_URL] = None
try: try:
policies = cfg.get(BLOCK_SERVICE, POLICY).split(',') policies = cfg.get(BLOCK_SERVICE, POLICY).split(',')
for policy in policies: for policy in policies:
......
...@@ -108,9 +108,15 @@ def setupTLSContext(vc): ...@@ -108,9 +108,15 @@ def setupTLSContext(vc):
if not os.path.isdir(vc[config.CERTIFICATE_DIR]): if not os.path.isdir(vc[config.CERTIFICATE_DIR]):
raise config.ConfigurationError( raise config.ConfigurationError(
'certdir value {} is not a directory'.format(vc[config.CERTIFICATE_DIR])) 'certdir value {} is not a directory'.format(vc[config.CERTIFICATE_DIR]))
from opennsa.opennsaTlsContext import opennsaTlsContext if vc[config.KEY] and vc[config.CERTIFICATE]:
ctx_factory = opennsaTlsContext( # enable client authentication even when not in TLS mode
vc[config.CERTIFICATE_DIR], vc[config.VERIFY_CERT]) from opennsa.opennsaTlsContext import opennsa2WayTlsContext
ctx_factory = opennsa2WayTlsContext(
vc[config.KEY], vc[config.CERTIFICATE], vc[config.CERTIFICATE_DIR], vc[config.VERIFY_CERT])
else:
from opennsa.opennsaTlsContext import opennsaTlsContext
ctx_factory = opennsaTlsContext(
vc[config.CERTIFICATE_DIR], vc[config.VERIFY_CERT])
else: else:
ctx_factory = None ctx_factory = None
...@@ -168,8 +174,11 @@ class OpenNSAService(twistedservice.MultiService): ...@@ -168,8 +174,11 @@ class OpenNSAService(twistedservice.MultiService):
nsa_name = domain_name + ':nsa' nsa_name = domain_name + ':nsa'
# base url # base url
base_protocol = 'https://' if vc[config.TLS] else 'http://' if vc[config.BASE_URL]:
base_url = base_protocol + vc[config.HOST] + ':' + str(vc[config.PORT]) base_url = vc[config.BASE_URL]
else:
base_protocol = 'https://' if vc[config.TLS] else 'http://'
base_url = base_protocol + vc[config.HOST] + ':' + str(vc[config.PORT])
# nsi endpoint and agent # nsi endpoint and agent
provider_endpoint = base_url + '/NSI/services/CS2' # hardcode for now provider_endpoint = base_url + '/NSI/services/CS2' # hardcode for now
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment