summaryrefslogtreecommitdiff
path: root/azurelinuxagent/common/osutil/gaia.py
diff options
context:
space:
mode:
authorƁukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com>2017-07-03 13:44:00 +0200
committerusd-importer <ubuntu-server@lists.ubuntu.com>2017-07-03 12:23:41 +0000
commit70c0ea1ac879b2e1cba0a8edb1f3fbe82652413b (patch)
treef168bb289117feb1c0d5b2c73604b44e85b064e2 /azurelinuxagent/common/osutil/gaia.py
parent68754fe67f1b3da2e6ca45885641941b3229698a (diff)
parent63aafec1b1a480947da7d5579c3ffc66b8fe5bdb (diff)
downloadvyos-walinuxagent-70c0ea1ac879b2e1cba0a8edb1f3fbe82652413b.tar.gz
vyos-walinuxagent-70c0ea1ac879b2e1cba0a8edb1f3fbe82652413b.zip
Import patches-applied version 2.2.14-0ubuntu1 to applied/ubuntu/artful-proposed
Imported using git-ubuntu import. Changelog parent: 68754fe67f1b3da2e6ca45885641941b3229698a Unapplied parent: 63aafec1b1a480947da7d5579c3ffc66b8fe5bdb New changelog entries: * New upstream release (LP: #1701350). * debian/copyright: - Refreshed copyright content.
Diffstat (limited to 'azurelinuxagent/common/osutil/gaia.py')
-rw-r--r--azurelinuxagent/common/osutil/gaia.py69
1 files changed, 57 insertions, 12 deletions
diff --git a/azurelinuxagent/common/osutil/gaia.py b/azurelinuxagent/common/osutil/gaia.py
index a1069d3..6a87b6b 100644
--- a/azurelinuxagent/common/osutil/gaia.py
+++ b/azurelinuxagent/common/osutil/gaia.py
@@ -16,15 +16,20 @@
# Requires Python 2.4+ and Openssl 1.0+
#
+import base64
import socket
import struct
import time
-import azurelinuxagent.common.logger as logger
+import azurelinuxagent.common.conf as conf
from azurelinuxagent.common.exception import OSUtilError
+from azurelinuxagent.common.future import ustr, bytebuffer
+import azurelinuxagent.common.logger as logger
+from azurelinuxagent.common.osutil.default import DefaultOSUtil
+from azurelinuxagent.common.utils.cryptutil import CryptUtil
+import azurelinuxagent.common.utils.fileutil as fileutil
import azurelinuxagent.common.utils.shellutil as shellutil
import azurelinuxagent.common.utils.textutil as textutil
-from azurelinuxagent.common.osutil.default import DefaultOSUtil
class GaiaOSUtil(DefaultOSUtil):
@@ -64,12 +69,11 @@ class GaiaOSUtil(DefaultOSUtil):
if ret != 0:
raise OSUtilError("Failed to delete root password")
- def _replace_user(path, username):
+ def _replace_user(self, path, username):
+ if path.startswith('$HOME'):
+ path = '/home' + path[5:]
parts = path.split('/')
- for i in xrange(len(parts)):
- if parts[i] == '$HOME':
- parts[i + 1] = username
- break
+ parts[2] = username
return '/'.join(parts)
def deploy_ssh_keypair(self, username, keypair):
@@ -80,13 +84,57 @@ class GaiaOSUtil(DefaultOSUtil):
super(GaiaOSUtil, self).deploy_ssh_keypair(
username, (path, thumbprint))
+ def openssl_to_openssh(self, input_file, output_file):
+ cryptutil = CryptUtil(conf.get_openssl_cmd())
+ ret, out = shellutil.run_get_output(
+ conf.get_openssl_cmd() +
+ " rsa -pubin -noout -text -in '" + input_file + "'")
+ if ret != 0:
+ raise OSUtilError('openssl failed with {0}'.format(ret))
+
+ modulus = []
+ exponent = []
+ buf = None
+ for line in out.split('\n'):
+ if line.startswith('Modulus:'):
+ buf = modulus
+ buf.append(line)
+ continue
+ if line.startswith('Exponent:'):
+ buf = exponent
+ buf.append(line)
+ continue
+ if buf and line:
+ buf.append(line.strip().replace(':', ''))
+
+ def text_to_num(buf):
+ if len(buf) == 1:
+ return int(buf[0].split()[1])
+ return long(''.join(buf[1:]), 16)
+
+ n = text_to_num(modulus)
+ e = text_to_num(exponent)
+
+ keydata = bytearray()
+ keydata.extend(struct.pack('>I', len('ssh-rsa')))
+ keydata.extend(b'ssh-rsa')
+ keydata.extend(struct.pack('>I', len(cryptutil.num_to_bytes(e))))
+ keydata.extend(cryptutil.num_to_bytes(e))
+ keydata.extend(struct.pack('>I', len(cryptutil.num_to_bytes(n)) + 1))
+ keydata.extend(b'\0')
+ keydata.extend(cryptutil.num_to_bytes(n))
+ keydata_base64 = base64.b64encode(bytebuffer(keydata))
+ fileutil.write_file(output_file,
+ ustr(b'ssh-rsa ' + keydata_base64 + b'\n',
+ encoding='utf-8'))
+
def deploy_ssh_pubkey(self, username, pubkey):
logger.info('deploy_ssh_pubkey')
username = 'admin'
path, thumbprint, value = pubkey
path = self._replace_user(path, username)
super(GaiaOSUtil, self).deploy_ssh_pubkey(
- 'admin', (path, thumbprint, value))
+ username, (path, thumbprint, value))
def eject_dvd(self, chk_err=True):
logger.warn('eject is not supported on GAiA')
@@ -114,7 +162,7 @@ class GaiaOSUtil(DefaultOSUtil):
def restart_ssh_service(self):
return shellutil.run('/sbin/service sshd condrestart', chk_err=False)
- def _address_to_string(addr):
+ def _address_to_string(self, addr):
return socket.inet_ntoa(struct.pack("!I", addr))
def _get_prefix(self, mask):
@@ -146,6 +194,3 @@ class GaiaOSUtil(DefaultOSUtil):
def del_account(self, username):
logger.warn('del_account is ignored on GAiA')
-
- def set_admin_access_to_ip(self, dest_ip):
- logger.warn('set_admin_access_to_ip is ignored on GAiA')