mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-02 21:53:38 +02:00
Use strings instead of bytes in SignatureAuthHandler
This commit is contained in:
@@ -584,7 +584,7 @@ class SignatureAuthHandler(AuthHandlerBase):
|
|||||||
if not self.ssh_add_path:
|
if not self.ssh_add_path:
|
||||||
return []
|
return []
|
||||||
cmd = [self.ssh_add_path, '-L']
|
cmd = [self.ssh_add_path, '-L']
|
||||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
|
||||||
stdout, _ = proc.communicate()
|
stdout, _ = proc.communicate()
|
||||||
if proc.returncode == 0 and stdout.strip():
|
if proc.returncode == 0 and stdout.strip():
|
||||||
return stdout.strip().splitlines()
|
return stdout.strip().splitlines()
|
||||||
@@ -596,7 +596,7 @@ class SignatureAuthHandler(AuthHandlerBase):
|
|||||||
# that's why we need to list ssh-agent's keys and store the first one into a temp file
|
# that's why we need to list ssh-agent's keys and store the first one into a temp file
|
||||||
keys_in_agent = self.list_ssh_agent_keys()
|
keys_in_agent = self.list_ssh_agent_keys()
|
||||||
if keys_in_agent:
|
if keys_in_agent:
|
||||||
self.temp_pubkey = tempfile.NamedTemporaryFile()
|
self.temp_pubkey = tempfile.NamedTemporaryFile(mode="w+")
|
||||||
self.temp_pubkey.write(keys_in_agent[0])
|
self.temp_pubkey.write(keys_in_agent[0])
|
||||||
self.temp_pubkey.flush()
|
self.temp_pubkey.flush()
|
||||||
return self.temp_pubkey.name
|
return self.temp_pubkey.name
|
||||||
@@ -610,10 +610,6 @@ class SignatureAuthHandler(AuthHandlerBase):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def ssh_sign(self, data, namespace, keyfile=None):
|
def ssh_sign(self, data, namespace, keyfile=None):
|
||||||
try:
|
|
||||||
data = bytes(data, 'utf-8')
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
if not keyfile:
|
if not keyfile:
|
||||||
keyfile = self.guess_keyfile()
|
keyfile = self.guess_keyfile()
|
||||||
else:
|
else:
|
||||||
@@ -622,8 +618,8 @@ class SignatureAuthHandler(AuthHandlerBase):
|
|||||||
keyfile = os.path.expanduser(keyfile)
|
keyfile = os.path.expanduser(keyfile)
|
||||||
|
|
||||||
cmd = [self.ssh_keygen_path, '-Y', 'sign', '-f', keyfile, '-n', namespace, '-q']
|
cmd = [self.ssh_keygen_path, '-Y', 'sign', '-f', keyfile, '-n', namespace, '-q']
|
||||||
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, encoding="utf-8")
|
||||||
stdout, _ = proc.communicate(data)
|
signature, _ = proc.communicate(data)
|
||||||
|
|
||||||
if self.temp_pubkey:
|
if self.temp_pubkey:
|
||||||
self.temp_pubkey.close()
|
self.temp_pubkey.close()
|
||||||
@@ -632,7 +628,6 @@ class SignatureAuthHandler(AuthHandlerBase):
|
|||||||
if proc.returncode:
|
if proc.returncode:
|
||||||
raise oscerr.OscIOError(None, 'ssh-keygen signature creation failed: %d' % proc.returncode)
|
raise oscerr.OscIOError(None, 'ssh-keygen signature creation failed: %d' % proc.returncode)
|
||||||
|
|
||||||
signature = decode_it(stdout)
|
|
||||||
match = re.match(r"\A-----BEGIN SSH SIGNATURE-----\n(.*)\n-----END SSH SIGNATURE-----", signature, re.S)
|
match = re.match(r"\A-----BEGIN SSH SIGNATURE-----\n(.*)\n-----END SSH SIGNATURE-----", signature, re.S)
|
||||||
if not match:
|
if not match:
|
||||||
raise oscerr.OscIOError(None, 'could not extract ssh signature')
|
raise oscerr.OscIOError(None, 'could not extract ssh signature')
|
||||||
|
Reference in New Issue
Block a user