ssh_key_import.c File Reference

SSH key file import functions. More...

#include "ssh/ssh.h"
#include "ssh/ssh_key_import.h"
#include "ssh/ssh_key_parse.h"
#include "ssh/ssh_key_decrypt.h"
#include "ssh/ssh_misc.h"
#include "encoding/base64.h"
#include "pkix/pem_import.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SSH_TRACE_LEVEL
 

Functions

error_t sshImportRsaPublicKey (const char_t *input, size_t length, RsaPublicKey *publicKey)
 Decode an SSH public key file containing an RSA public key. More...
 
error_t sshImportDsaPublicKey (const char_t *input, size_t length, DsaPublicKey *publicKey)
 Decode an SSH public key file containing a DSA public key. More...
 
error_t sshImportEcdsaPublicKey (const char_t *input, size_t length, EcDomainParameters *params, EcPublicKey *publicKey)
 Decode an SSH public key file containing an ECDSA public key. More...
 
error_t sshImportEd25519PublicKey (const char_t *input, size_t length, EddsaPublicKey *publicKey)
 Decode an SSH public key file containing an Ed25519 public key. More...
 
error_t sshImportEd448PublicKey (const char_t *input, size_t length, EddsaPublicKey *publicKey)
 Decode an SSH public key file containing an Ed448 public key. More...
 
error_t sshImportRsaPrivateKey (const char_t *input, size_t length, const char_t *password, RsaPrivateKey *privateKey)
 Decode an SSH private key file containing an RSA private key. More...
 
error_t sshImportDsaPrivateKey (const char_t *input, size_t length, const char_t *password, DsaPrivateKey *privateKey)
 Decode an SSH private key file containing a DSA private key. More...
 
error_t sshImportEcdsaPrivateKey (const char_t *input, size_t length, const char_t *password, EcPrivateKey *privateKey)
 Decode an SSH private key file containing an ECDSA private key. More...
 
error_t sshImportEd25519PrivateKey (const char_t *input, size_t length, const char_t *password, EddsaPrivateKey *privateKey)
 Decode an SSH private key file containing an Ed25519 private key. More...
 
error_t sshImportEd448PrivateKey (const char_t *input, size_t length, const char_t *password, EddsaPrivateKey *privateKey)
 Decode an SSH private key file containing an Ed448 private key. More...
 
error_t sshImportRsaHostKey (const SshRsaHostKey *hostKey, RsaPublicKey *publicKey)
 Import an RSA host key. More...
 
error_t sshImportDsaHostKey (const SshDsaHostKey *hostKey, DsaPublicKey *publicKey)
 Import a DSA host key. More...
 
error_t sshImportEcdsaHostKey (const SshEcdsaHostKey *hostKey, EcDomainParameters *params, EcPublicKey *publicKey)
 Import a ECDSA host key. More...
 
error_t sshImportEd25519HostKey (const SshEddsaHostKey *hostKey, EddsaPublicKey *publicKey)
 Import an Ed25519 host key. More...
 
error_t sshImportEd448HostKey (const SshEddsaHostKey *hostKey, EddsaPublicKey *publicKey)
 Import an Ed448 host key. More...
 
const char_tsshGetPublicKeyType (const char_t *input, size_t length)
 Get SSH public key type. More...
 
error_t sshDecodePublicKeyFile (const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen)
 Decode SSH public key file (SSH2 or OpenSSH format) More...
 
error_t sshDecodeSsh2PublicKeyFile (const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen)
 Decode SSH public key file (SSH2 format) More...
 
error_t sshDecodeOpenSshPublicKeyFile (const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen)
 Decode SSH public key file (OpenSSH format) More...
 
error_t sshDecodeOpenSshPrivateKeyFile (const char_t *input, size_t inputLen, uint8_t *output, size_t *outputLen)
 Decode SSH private key file (OpenSSH format) More...
 
int_t sshSearchMarker (const char_t *s, size_t sLen, const char_t *marker, size_t markerLen)
 Search a string for a given marker. More...
 

Detailed Description

SSH key file import functions.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneSSH Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file ssh_key_import.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SSH_TRACE_LEVEL

Definition at line 32 of file ssh_key_import.c.

Function Documentation

◆ sshDecodeOpenSshPrivateKeyFile()

error_t sshDecodeOpenSshPrivateKeyFile ( const char_t input,
size_t  inputLen,
uint8_t *  output,
size_t *  outputLen 
)

Decode SSH private key file (OpenSSH format)

Parameters
[in]inputSSH public key file to decode
[in]inputLenLength of the SSH private key file to decode
[out]outputPointer to the decoded data (optional parameter)
[out]outputLenLength of the decoded data

Definition at line 1709 of file ssh_key_import.c.

◆ sshDecodeOpenSshPublicKeyFile()

error_t sshDecodeOpenSshPublicKeyFile ( const char_t input,
size_t  inputLen,
uint8_t *  output,
size_t *  outputLen 
)

Decode SSH public key file (OpenSSH format)

Parameters
[in]inputSSH public key file to decode
[in]inputLenLength of the SSH public key file to decode
[out]outputPointer to the decoded data (optional parameter)
[out]outputLenLength of the decoded data

Definition at line 1634 of file ssh_key_import.c.

◆ sshDecodePublicKeyFile()

error_t sshDecodePublicKeyFile ( const char_t input,
size_t  inputLen,
uint8_t *  output,
size_t *  outputLen 
)

Decode SSH public key file (SSH2 or OpenSSH format)

Parameters
[in]inputSSH public key file to decode
[in]inputLenLength of the SSH public key file to decode
[out]outputPointer to the decoded data (optional parameter)
[out]outputLenLength of the decoded data

Definition at line 1491 of file ssh_key_import.c.

◆ sshDecodeSsh2PublicKeyFile()

error_t sshDecodeSsh2PublicKeyFile ( const char_t input,
size_t  inputLen,
uint8_t *  output,
size_t *  outputLen 
)

Decode SSH public key file (SSH2 format)

Parameters
[in]inputSSH public key file to decode
[in]inputLenLength of the SSH public key file to decode
[out]outputPointer to the decoded data (optional parameter)
[out]outputLenLength of the decoded data

Definition at line 1519 of file ssh_key_import.c.

◆ sshGetPublicKeyType()

const char_t* sshGetPublicKeyType ( const char_t input,
size_t  length 
)

Get SSH public key type.

Parameters
[in]inputSSH public key file
[in]lengthLength of the SSH public key file
Returns
SSH public key type

Definition at line 1348 of file ssh_key_import.c.

◆ sshImportDsaHostKey()

error_t sshImportDsaHostKey ( const SshDsaHostKey hostKey,
DsaPublicKey publicKey 
)

Import a DSA host key.

Parameters
[in]hostKeyPointer to the host key structure
[out]publicKeyPointer to the DSA public key
Returns
Error code

Definition at line 1190 of file ssh_key_import.c.

◆ sshImportDsaPrivateKey()

error_t sshImportDsaPrivateKey ( const char_t input,
size_t  length,
const char_t password,
DsaPrivateKey privateKey 
)

Decode an SSH private key file containing a DSA private key.

Parameters
[in]inputPointer to the SSH private key file
[in]lengthLength of the SSH private key file
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
[out]privateKeyDSA private key resulting from the parsing process
Returns
Error code

Definition at line 693 of file ssh_key_import.c.

◆ sshImportDsaPublicKey()

error_t sshImportDsaPublicKey ( const char_t input,
size_t  length,
DsaPublicKey publicKey 
)

Decode an SSH public key file containing a DSA public key.

Parameters
[in]inputPointer to the SSH public key file
[in]lengthLength of the SSH public key file
[out]publicKeyDSA public key resulting from the parsing process
Returns
Error code

Definition at line 169 of file ssh_key_import.c.

◆ sshImportEcdsaHostKey()

error_t sshImportEcdsaHostKey ( const SshEcdsaHostKey hostKey,
EcDomainParameters params,
EcPublicKey publicKey 
)

Import a ECDSA host key.

Parameters
[in]hostKeyPointer to the host key structure
[out]paramsEC domain parameters
[out]publicKeyPointer to the ECDSA public key
Returns
Error code

Definition at line 1249 of file ssh_key_import.c.

◆ sshImportEcdsaPrivateKey()

error_t sshImportEcdsaPrivateKey ( const char_t input,
size_t  length,
const char_t password,
EcPrivateKey privateKey 
)

Decode an SSH private key file containing an ECDSA private key.

Parameters
[in]inputPointer to the SSH private key file
[in]lengthLength of the SSH private key file
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
[out]privateKeyECDSA private key resulting from the parsing process
Returns
Error code

Definition at line 825 of file ssh_key_import.c.

◆ sshImportEcdsaPublicKey()

error_t sshImportEcdsaPublicKey ( const char_t input,
size_t  length,
EcDomainParameters params,
EcPublicKey publicKey 
)

Decode an SSH public key file containing an ECDSA public key.

Parameters
[in]inputPointer to the SSH public key file
[in]lengthLength of the SSH public key file
[out]paramsEC domain parameters resulting from the parsing process
[out]publicKeyECDSA public key resulting from the parsing process
Returns
Error code

Definition at line 253 of file ssh_key_import.c.

◆ sshImportEd25519HostKey()

error_t sshImportEd25519HostKey ( const SshEddsaHostKey hostKey,
EddsaPublicKey publicKey 
)

Import an Ed25519 host key.

Parameters
[in]hostKeyPointer to the host key structure
[out]publicKeyPointer to the Ed25519 public key
Returns
Error code

Definition at line 1296 of file ssh_key_import.c.

◆ sshImportEd25519PrivateKey()

error_t sshImportEd25519PrivateKey ( const char_t input,
size_t  length,
const char_t password,
EddsaPrivateKey privateKey 
)

Decode an SSH private key file containing an Ed25519 private key.

Parameters
[in]inputPointer to the SSH private key file
[in]lengthLength of the SSH private key file
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
[out]privateKeyEd25519 private key resulting from the parsing process
Returns
Error code

Definition at line 933 of file ssh_key_import.c.

◆ sshImportEd25519PublicKey()

error_t sshImportEd25519PublicKey ( const char_t input,
size_t  length,
EddsaPublicKey publicKey 
)

Decode an SSH public key file containing an Ed25519 public key.

Parameters
[in]inputPointer to the SSH public key file
[in]lengthLength of the SSH public key file
[out]publicKeyEd25519 public key resulting from the parsing process
Returns
Error code

Definition at line 344 of file ssh_key_import.c.

◆ sshImportEd448HostKey()

error_t sshImportEd448HostKey ( const SshEddsaHostKey hostKey,
EddsaPublicKey publicKey 
)

Import an Ed448 host key.

Parameters
[in]hostKeyPointer to the host key structure
[out]publicKeyPointer to the Ed448 public key
Returns
Error code

Definition at line 1322 of file ssh_key_import.c.

◆ sshImportEd448PrivateKey()

error_t sshImportEd448PrivateKey ( const char_t input,
size_t  length,
const char_t password,
EddsaPrivateKey privateKey 
)

Decode an SSH private key file containing an Ed448 private key.

Parameters
[in]inputPointer to the SSH private key file
[in]lengthLength of the SSH private key file
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
[out]privateKeyEd448 private key resulting from the parsing process
Returns
Error code

Definition at line 1041 of file ssh_key_import.c.

◆ sshImportEd448PublicKey()

error_t sshImportEd448PublicKey ( const char_t input,
size_t  length,
EddsaPublicKey publicKey 
)

Decode an SSH public key file containing an Ed448 public key.

Parameters
[in]inputPointer to the SSH public key file
[in]lengthLength of the SSH public key file
[out]publicKeyEd448 public key resulting from the parsing process
Returns
Error code

Definition at line 426 of file ssh_key_import.c.

◆ sshImportRsaHostKey()

error_t sshImportRsaHostKey ( const SshRsaHostKey hostKey,
RsaPublicKey publicKey 
)

Import an RSA host key.

Parameters
[in]hostKeyPointer to the host key structure
[out]publicKeyPointer to the RSA public key
Returns
Error code

Definition at line 1146 of file ssh_key_import.c.

◆ sshImportRsaPrivateKey()

error_t sshImportRsaPrivateKey ( const char_t input,
size_t  length,
const char_t password,
RsaPrivateKey privateKey 
)

Decode an SSH private key file containing an RSA private key.

Parameters
[in]inputPointer to the SSH private key file
[in]lengthLength of the SSH private key file
[in]passwordNULL-terminated string containing the password. This parameter is required if the private key is encrypted
[out]privateKeyRSA private key resulting from the parsing process
Returns
Error code

Definition at line 511 of file ssh_key_import.c.

◆ sshImportRsaPublicKey()

error_t sshImportRsaPublicKey ( const char_t input,
size_t  length,
RsaPublicKey publicKey 
)

Decode an SSH public key file containing an RSA public key.

Parameters
[in]inputPointer to the SSH public key file
[in]lengthLength of the SSH public key file
[out]publicKeyRSA public key resulting from the parsing process
Returns
Error code

Definition at line 86 of file ssh_key_import.c.

◆ sshSearchMarker()

int_t sshSearchMarker ( const char_t s,
size_t  sLen,
const char_t marker,
size_t  markerLen 
)

Search a string for a given marker.

Parameters
[in]sString to search
[in]sLenLength of the string to search
[in]markerString containing the marker to search for
[in]markerLenLength of the marker
Returns
The index of the first occurrence of the marker in the string, or -1 if the marker does not appear in the string

Definition at line 1758 of file ssh_key_import.c.