forked from scionproto/scion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcert.py
More file actions
executable file
·65 lines (57 loc) · 2.49 KB
/
cert.py
File metadata and controls
executable file
·65 lines (57 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2014 ETH Zurich
# Copyright 2018 ETH Zurich, Anapaya Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
:mod:`cert` --- SCION topology certificate generator
=============================================
"""
from collections import defaultdict
from plumbum import local
from topology.common import ArgsTopoConfig, srv_iter
class CertGenArgs(ArgsTopoConfig):
pass
class CertGenerator(object):
def __init__(self, args):
"""
:param CertGenArgs args: Contains the passed command line
arguments and the parsed topo config.
"""
self.args = args
self.pki = local['./bin/scion-pki']
self.core_count = defaultdict(int)
def generate(self, topo_dicts):
self.pki('tmpl', 'topo', self.args.topo_config, '-d', self.args.output_dir)
self.pki('keys', 'gen', '*', '-d', self.args.output_dir)
self.pki('trc', 'gen', '*', '-d', self.args.output_dir)
self.pki('certs', 'gen', '*', '-d', self.args.output_dir)
self.pki('certs', 'customers', '*', '-d', self.args.output_dir)
self._copy_files(topo_dicts)
def _copy_files(self, topo_dicts):
cp = local['cp']
# Copy the certs and key dir for all elements.
for topo_id, as_topo, base in srv_iter(
topo_dicts, self.args.output_dir, common=True):
elem_dir = local.path(base)
as_dir = elem_dir.dirname
cp('-r', as_dir / 'certs', elem_dir / 'certs')
cp('-r', as_dir / 'keys', elem_dir / 'keys')
cp(as_dir.dirname / 'trcs' // '*.trc', elem_dir / 'certs')
# Copy the customers dir for all certificate servers.
for topo_id, as_topo in topo_dicts.items():
as_dir = local.path(topo_id.base_dir(self.args.output_dir))
custom_dir = as_dir / 'customers'
if not custom_dir.exists():
continue
for elem in as_topo["CertificateService"]:
cp('-r', as_dir / 'customers', as_dir / elem / 'customers')