mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-10 10:26:47 +09:00
pki_container_openssh: Add padding to be compatible with OpenSSH
OpenSSH has a block size of 8 so we need to always add padding.
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 128015bb17)
This commit is contained in:
committed by
Andreas Schneider
parent
f9beb3c690
commit
e69fb89e98
@@ -409,7 +409,7 @@ static int pki_openssh_export_privkey_blob(const ssh_key privkey,
|
|||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
if (privkey->ed25519_privkey == NULL ||
|
if (privkey->ed25519_privkey == NULL ||
|
||||||
privkey->ed25519_pubkey == NULL){
|
privkey->ed25519_pubkey == NULL) {
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
rc = ssh_buffer_pack(buffer,
|
rc = ssh_buffer_pack(buffer,
|
||||||
@@ -442,7 +442,6 @@ static int pki_private_key_encrypt(ssh_buffer privkey_buffer,
|
|||||||
char passphrase_buffer[128];
|
char passphrase_buffer[128];
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
uint8_t padding = 1;
|
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
||||||
cmp = strcmp(ciphername, "none");
|
cmp = strcmp(ciphername, "none");
|
||||||
@@ -469,14 +468,6 @@ static int pki_private_key_encrypt(ssh_buffer privkey_buffer,
|
|||||||
SSH_LOG(SSH_LOG_WARN, "Unsupported KDF %s", kdfname);
|
SSH_LOG(SSH_LOG_WARN, "Unsupported KDF %s", kdfname);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
while (ssh_buffer_get_len(privkey_buffer) % cipher.blocksize != 0) {
|
|
||||||
rc = ssh_buffer_add_u8(privkey_buffer, padding);
|
|
||||||
if (rc < 0) {
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
padding++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We need material for key (keysize bits / 8) and IV (blocksize) */
|
/* We need material for key (keysize bits / 8) and IV (blocksize) */
|
||||||
key_material_len = cipher.keysize/8 + cipher.blocksize;
|
key_material_len = cipher.keysize/8 + cipher.blocksize;
|
||||||
if (key_material_len > sizeof(key_material)){
|
if (key_material_len > sizeof(key_material)){
|
||||||
@@ -553,6 +544,7 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
|
|||||||
int to_encrypt=0;
|
int to_encrypt=0;
|
||||||
unsigned char *b64;
|
unsigned char *b64;
|
||||||
uint32_t str_len, len;
|
uint32_t str_len, len;
|
||||||
|
uint8_t padding = 1;
|
||||||
int ok;
|
int ok;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@@ -603,6 +595,18 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add padding regardless encryption because it is expected
|
||||||
|
* by OpenSSH tools.
|
||||||
|
* XXX Using 16 B as we use only AES cipher below anyway.
|
||||||
|
*/
|
||||||
|
while (ssh_buffer_get_len(privkey_buffer) % 16 != 0) {
|
||||||
|
rc = ssh_buffer_add_u8(privkey_buffer, padding);
|
||||||
|
if (rc < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
padding++;
|
||||||
|
}
|
||||||
|
|
||||||
if (to_encrypt){
|
if (to_encrypt){
|
||||||
ssh_buffer kdf_buf;
|
ssh_buffer kdf_buf;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user