ssh_key_parse.h
Go to the documentation of this file.
1 /**
2  * @file ssh_key_parse.h
3  * @brief SSH key parsing
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSH Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _SSH_KEY_PARSE_H
32 #define _SSH_KEY_PARSE_H
33 
34 //Dependencies
35 #include "ssh_types.h"
36 
37 //Magic identifier size
38 #define SSH_AUTH_MAGIC_SIZE 15
39 
40 
41 //C++ guard
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 
47 /**
48  * @brief RSA host key
49  **/
50 
51 typedef struct
52 {
57 
58 
59 /**
60  * @brief DSA host key
61  **/
62 
63 typedef struct
64 {
71 
72 
73 /**
74  * @brief ECDSA host key
75  **/
76 
77 typedef struct
78 {
83 
84 
85 /**
86  * @brief EdDSA host key
87  **/
88 
89 typedef struct
90 {
94 
95 
96 /**
97  * @brief Private key header (OpenSSH format)
98  **/
99 
100 typedef struct
101 {
105  uint32_t numKeys;
109 
110 
111 /**
112  * @brief RSA private key (OpenSSH format)
113  **/
114 
115 typedef struct
116 {
117  uint32_t checkInt1;
118  uint32_t checkInt2;
128 
129 
130 /**
131  * @brief DSA private key (OpenSSH format)
132  **/
133 
134 typedef struct
135 {
136  uint32_t checkInt1;
137  uint32_t checkInt2;
146 
147 
148 /**
149  * @brief ECDSA private key (OpenSSH format)
150  **/
151 
152 typedef struct
153 {
154  uint32_t checkInt1;
155  uint32_t checkInt2;
162 
163 
164 /**
165  * @brief EdDSA private key (OpenSSH format)
166  **/
167 
168 typedef struct
169 {
170  uint32_t checkInt1;
171  uint32_t checkInt2;
177 
178 
179 //SSH key parsing functions
180 error_t sshParseHostKey(const uint8_t *data, size_t length,
181  SshString *keyFormatId);
182 
183 error_t sshParseRsaHostKey(const uint8_t *data, size_t length,
184  SshRsaHostKey *hostKey);
185 
186 error_t sshParseDsaHostKey(const uint8_t *data, size_t length,
187  SshDsaHostKey *hostKey);
188 
189 error_t sshParseEcdsaHostKey(const uint8_t *data, size_t length,
190  SshEcdsaHostKey *hostKey);
191 
192 error_t sshParseEd25519HostKey(const uint8_t *data, size_t length,
193  SshEddsaHostKey *hostKey);
194 
195 error_t sshParseEd448HostKey(const uint8_t *data, size_t length,
196  SshEddsaHostKey *hostKey);
197 
198 error_t sshParseOpenSshPrivateKeyHeader(const uint8_t *data, size_t length,
199  SshPrivateKeyHeader *privateKeyHeader);
200 
201 error_t sshParseOpenSshRsaPrivateKey(const uint8_t *data, size_t length,
202  SshRsaPrivateKey *privateKey);
203 
204 error_t sshParseOpenSshDsaPrivateKey(const uint8_t *data, size_t length,
205  SshDsaPrivateKey *privateKey);
206 
207 error_t sshParseOpenSshEcdsaPrivateKey(const uint8_t *data, size_t length,
208  SshEcdsaPrivateKey *privateKey);
209 
210 error_t sshParseOpenSshEd25519PrivateKey(const uint8_t *data, size_t length,
211  SshEddsaPrivateKey *privateKey);
212 
213 error_t sshParseOpenSshEd448PrivateKey(const uint8_t *data, size_t length,
214  SshEddsaPrivateKey *privateKey);
215 
216 error_t sshCheckPrivateKeyPadding(const uint8_t *pad, size_t length);
217 
218 //C++ guard
219 #ifdef __cplusplus
220 }
221 #endif
222 
223 #endif
EdDSA private key (OpenSSH format)
SshBinaryString q
Definition: ssh_key_parse.h:67
SshBinaryString y
Definition: ssh_key_parse.h:69
SshBinaryString q
Binary string.
Definition: ssh_types.h:67
error_t sshParseEd448HostKey(const uint8_t *data, size_t length, SshEddsaHostKey *hostKey)
Parse an Ed448 host key structure.
DSA host key.
Definition: ssh_key_parse.h:64
SshString keyFormatId
Definition: ssh_key_parse.h:65
SshBinaryString d
ECDSA private key (OpenSSH format)
error_t sshCheckPrivateKeyPadding(const uint8_t *pad, size_t length)
Check padding string.
error_t sshParseOpenSshEd448PrivateKey(const uint8_t *data, size_t length, SshEddsaPrivateKey *privateKey)
Parse Ed448 private key blob (OpenSSH format)
uint8_t data[]
Definition: ethernet.h:222
DSA private key (OpenSSH format)
SshString keyFormatId
Definition: ssh_key_parse.h:79
error_t sshParseRsaHostKey(const uint8_t *data, size_t length, SshRsaHostKey *hostKey)
Parse an RSA host key structure.
SshString keyFormatId
SshBinaryString g
Definition: ssh_key_parse.h:68
SshBinaryString n
Definition: ssh_key_parse.h:55
SshBinaryString q
Private key header (OpenSSH format)
SshBinaryString encrypted
SshBinaryString q
Definition: ssh_key_parse.h:81
error_t
Error codes.
Definition: error.h:43
SshBinaryString n
RSA private key (OpenSSH format)
error_t sshParseHostKey(const uint8_t *data, size_t length, SshString *keyFormatId)
Parse host key structure.
Definition: ssh_key_parse.c:53
SshString keyFormatId
SshBinaryString e
SshBinaryString kdfOptions
SshString keyFormatId
Definition: ssh_key_parse.h:53
SshBinaryString p
Definition: ssh_key_parse.h:66
SshBinaryString d
SshBinaryString e
Definition: ssh_key_parse.h:54
EdDSA host key.
Definition: ssh_key_parse.h:90
uint8_t length
Definition: tcp.h:368
SshBinaryString y
SshBinaryString qinv
String.
Definition: ssh_types.h:56
SshString keyFormatId
Definition: ssh_key_parse.h:91
SshBinaryString d
error_t sshParseEcdsaHostKey(const uint8_t *data, size_t length, SshEcdsaHostKey *hostKey)
Parse an ECDSA host key structure.
error_t sshParseDsaHostKey(const uint8_t *data, size_t length, SshDsaHostKey *hostKey)
Parse a DSA host key structure.
SSH data type representations.
error_t sshParseOpenSshRsaPrivateKey(const uint8_t *data, size_t length, SshRsaPrivateKey *privateKey)
Parse RSA private key blob (OpenSSH format)
SshBinaryString g
error_t sshParseEd25519HostKey(const uint8_t *data, size_t length, SshEddsaHostKey *hostKey)
Parse an Ed25519 host key structure.
ECDSA host key.
Definition: ssh_key_parse.h:78
SshBinaryString q
error_t sshParseOpenSshDsaPrivateKey(const uint8_t *data, size_t length, SshDsaPrivateKey *privateKey)
Parse DSA private key blob (OpenSSH format)
error_t sshParseOpenSshEd25519PrivateKey(const uint8_t *data, size_t length, SshEddsaPrivateKey *privateKey)
Parse Ed25519 private key blob (OpenSSH format)
RSA host key.
Definition: ssh_key_parse.h:52
SshBinaryString p
SshBinaryString x
error_t sshParseOpenSshPrivateKeyHeader(const uint8_t *data, size_t length, SshPrivateKeyHeader *privateKeyHeader)
Parse private key header (OpenSSH format)
SshBinaryString p
SshBinaryString q
error_t sshParseOpenSshEcdsaPrivateKey(const uint8_t *data, size_t length, SshEcdsaPrivateKey *privateKey)
Parse ECDSA private key blob (OpenSSH format)
SshBinaryString q
Definition: ssh_key_parse.h:92
SshString curveName
Definition: ssh_key_parse.h:80
SshBinaryString publicKey