wip
This commit is contained in:
		
							parent
							
								
									4a845d4956
								
							
						
					
					
						commit
						5340ec0c05
					
				
					 10 changed files with 16 additions and 77 deletions
				
			
		|  | @ -1,6 +1,3 @@ | ||||||
| from ipaddress import ip_interface |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| @metadata_reactor.provides( | @metadata_reactor.provides( | ||||||
|     'users/backup-receiver/authorized_keys' |     'users/backup-receiver/authorized_keys' | ||||||
| ) | ) | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								libs/ssh.py
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								libs/ssh.py
									
									
									
									
									
								
							|  | @ -1,28 +0,0 @@ | ||||||
| from base64 import b64decode, b64encode |  | ||||||
| from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey |  | ||||||
| from cryptography.hazmat.primitives import serialization |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def generate_ed25519_key_pair(secret): |  | ||||||
|     privkey_bytes = Ed25519PrivateKey.from_private_bytes(secret) |  | ||||||
|      |  | ||||||
|     nondeterministic_privatekey = privkey_bytes.private_bytes( |  | ||||||
|         encoding=serialization.Encoding.PEM, |  | ||||||
|         format=serialization.PrivateFormat.OpenSSH, |  | ||||||
|         encryption_algorithm=serialization.NoEncryption() |  | ||||||
|     ).decode() |  | ||||||
|     nondeterministic_bytes = b64decode(''.join(nondeterministic_privatekey.split('\n')[1:-2])) |  | ||||||
|     # handle random 32bit number, occuring twice in a row |  | ||||||
|     deterministic_bytes = nondeterministic_bytes[:98] + b'00000000' + nondeterministic_bytes[106:] |  | ||||||
|     deterministic_privatekey = '\n'.join([ |  | ||||||
|         '-----BEGIN OPENSSH PRIVATE KEY-----', |  | ||||||
|         b64encode(deterministic_bytes).decode(), |  | ||||||
|         '-----END OPENSSH PRIVATE KEY-----', |  | ||||||
|     ]) |  | ||||||
| 
 |  | ||||||
|     public_key = privkey_bytes.public_key().public_bytes( |  | ||||||
|         encoding=serialization.Encoding.OpenSSH, |  | ||||||
|         format=serialization.PublicFormat.OpenSSH, |  | ||||||
|     ).decode() |  | ||||||
|      |  | ||||||
|     return (deterministic_privatekey, public_key) |  | ||||||
							
								
								
									
										22
									
								
								nodes.py
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								nodes.py
									
									
									
									
									
								
							|  | @ -1,30 +1,10 @@ | ||||||
| from os import walk | from os import walk | ||||||
| from os.path import join, basename, splitext | from os.path import join, basename, splitext | ||||||
| 
 | 
 | ||||||
| converters = { |  | ||||||
|     '32_random_bytes_as_base64_for': lambda x: vault.random_bytes_as_base64_for(x, length=32), |  | ||||||
|     'decrypt': lambda x: vault.decrypt(x), |  | ||||||
|     'decrypt_file': lambda x: vault.decrypt_file(x), |  | ||||||
|     'password_for': lambda x: vault.password_for(x), |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| def demagify(data): |  | ||||||
|     if isinstance(data, str): |  | ||||||
|         for name, converter in converters.items(): |  | ||||||
|             if data.startswith(f'!{name}:'): |  | ||||||
|                 return converter(data[len(name) + 2:]) |  | ||||||
|         else: |  | ||||||
|             return data |  | ||||||
|     elif isinstance(data, dict): |  | ||||||
|         return type(data)({key: demagify(value) for key, value in data.items()}) |  | ||||||
|     elif isinstance(data, (list, set, tuple)): |  | ||||||
|         return type(data)([demagify(element) for element in data]) |  | ||||||
|     else: |  | ||||||
|         return data |  | ||||||
| 
 | 
 | ||||||
| for root, dirs, files in walk(join(repo_path, "nodes")): | for root, dirs, files in walk(join(repo_path, "nodes")): | ||||||
|     for filename in files: |     for filename in files: | ||||||
|         if filename.endswith(".py"): |         if filename.endswith(".py"): | ||||||
|             node = join(root, filename) |             node = join(root, filename) | ||||||
|             with open(node, 'r', encoding='utf-8') as f: |             with open(node, 'r', encoding='utf-8') as f: | ||||||
|                 nodes[splitext(basename(filename))[0]] = demagify(eval(f.read())) |                 nodes[splitext(basename(filename))[0]] = eval(f.read()) | ||||||
|  |  | ||||||
							
								
								
									
										5
									
								
								nodes/client1.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								nodes/client1.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | { | ||||||
|  |     'groups': [ | ||||||
|  |         'all', | ||||||
|  |     ], | ||||||
|  | } | ||||||
							
								
								
									
										5
									
								
								nodes/client2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								nodes/client2.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | { | ||||||
|  |     'groups': [ | ||||||
|  |         'all', | ||||||
|  |     ], | ||||||
|  | } | ||||||
							
								
								
									
										5
									
								
								nodes/client3.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								nodes/client3.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | { | ||||||
|  |     'groups': [ | ||||||
|  |         'all', | ||||||
|  |     ], | ||||||
|  | } | ||||||
|  | @ -1,5 +1,4 @@ | ||||||
| { | { | ||||||
|     'hostname': '10.0.0.5', |  | ||||||
|     'bundles': [ |     'bundles': [ | ||||||
|         'backup-server', |         'backup-server', | ||||||
|     ], |     ], | ||||||
|  |  | ||||||
|  | @ -1,8 +0,0 @@ | ||||||
| { |  | ||||||
|     'hostname': '10.0.0.2', |  | ||||||
|     'groups': [ |  | ||||||
|         'all', |  | ||||||
|     ], |  | ||||||
|     'metadata': { |  | ||||||
|     }, |  | ||||||
| } |  | ||||||
|  | @ -1,8 +0,0 @@ | ||||||
| { |  | ||||||
|     'dummy': True, |  | ||||||
|     'groups': [ |  | ||||||
|         'all', |  | ||||||
|     ], |  | ||||||
|     'metadata': { |  | ||||||
|     }, |  | ||||||
| } |  | ||||||
|  | @ -1,8 +0,0 @@ | ||||||
| { |  | ||||||
|     'hostname': '162.55.188.157', |  | ||||||
|     'groups': [ |  | ||||||
|         'all', |  | ||||||
|     ], |  | ||||||
|     'metadata': { |  | ||||||
|     }, |  | ||||||
| } |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 mwiegand
						mwiegand