blob: e33a536c55c6ed1e24b909b422fd027c4e065347 [file] [log] [blame]
garciadeblas91806612017-02-23 11:15:28 +01001# Copyright 2016 RIFT.IO Inc
2# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Rajesh43076e52017-02-23 05:12:08 -050015
16import os
17
18class BootstrapSslMissingException(Exception):
19 pass
20
21# True if the environment variable is unset, otherwise False
22USE_SSL = os.environ.get("RIFT_BOOT_WITHOUT_HTTPS", None) is None
23
24def get_bootstrap_cert_and_key():
25 '''
26 Lookup the bootstrap certificate and key and return their paths
27 '''
28
29 user_cert = os.path.join("/", "etc", "ssl", "current.cert")
30 user_key = os.path.join("/", "etc", "ssl", "current.key")
31
32 if os.path.isfile(user_cert) and os.path.isfile(user_key):
33 return USE_SSL, user_cert, user_key
34
35 rift_install = os.environ["RIFT_INSTALL"]
36 rift_cert = os.path.join(rift_install, "etc", "ssl", "current.cert")
37 rift_key = os.path.join(rift_install, "etc", "ssl", "current.key")
38
39 if os.path.isfile(rift_cert) and os.path.isfile(rift_key):
40 return USE_SSL, rift_cert, rift_key
41
42 raise BootstrapSslMissingException()
43