define PLC_MAIL_FROM_ADDRESS
[tests.git] / system / TestKey.py
1 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
2 # Copyright (C) 2010 INRIA 
3 #
4 import utils
5 import os, os.path
6 from TestSsh import TestSsh
7
8 class TestKey:
9
10     def __init__ (self, test_plc, key_spec):
11         self.test_plc = test_plc
12         self.key_spec = key_spec
13         self.test_ssh = TestSsh(self.test_plc.test_ssh)
14         
15     def name(self):
16         return self.key_spec['key_name']
17
18     def publicpath(self):
19         return "keys/{}.pub".format(self.name())
20     def privatepath(self):
21         return "keys/{}.rsa".format(self.name())
22
23     def store_key(self):
24         pub = self.publicpath()
25         priv = self.privatepath()
26         utils.header("Storing key {} in {}".format(self.name(), pub))
27         dir = os.path.dirname(pub)
28         if not os.path.isdir(dir):
29             os.mkdir(dir)
30         with open(pub,"w") as f:
31             f.write(self.key_spec['key_fields']['key'])
32         with open(priv,"w") as f:
33             f.write(self.key_spec['private'])
34         os.chmod(priv,0o400)
35         os.chmod(pub,0o444)
36