ssh_cert_parse.h
Go to the documentation of this file.
1 /**
2  * @file ssh_cert_parse.h
3  * @brief SSH certificate 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_CERT_PARSE_H
32 #define _SSH_CERT_PARSE_H
33 
34 //Dependencies
35 #include "ssh_types.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /**
44  * @brief SSH certificate types
45  **/
46 
47 typedef enum
48 {
52 
53 
54 /**
55  * @brief RSA public key
56  **/
57 
58 typedef struct
59 {
63 
64 
65 /**
66  * @brief DSA public key
67  **/
68 
69 typedef struct
70 {
76 
77 
78 /**
79  * @brief ECDSA public key
80  **/
81 
82 typedef struct
83 {
87 
88 
89 /**
90  * @brief Ed25519 public key
91  **/
92 
93 typedef struct
94 {
97 
98 
99 /**
100  * @brief Public key
101  **/
102 
103 typedef union
104 {
110 
111 
112 /**
113  * @brief SSH certificate (OpenSSH format)
114  **/
115 
116 typedef struct
117 {
121  uint64_t serial;
122  uint32_t type;
125  uint64_t validAfter;
126  uint64_t validBefore;
133 
134 
135 //SSH certificate parsing functions
136 error_t sshParseCertificate(const uint8_t *data, size_t length,
137  SshCertificate *cert);
138 
139 error_t sshParseRsaCertPublicKey(const uint8_t *data, size_t length,
140  size_t *consumed, SshRsaCertPublicKey *publicKey);
141 
142 error_t sshParseDsaCertPublicKey(const uint8_t *data, size_t length,
143  size_t *consumed, SshDsaCertPublicKey *publicKey);
144 
145 error_t sshParseEcdsaCertPublicKey(const uint8_t *data, size_t length,
146  size_t *consumed, SshEcdsaCertPublicKey *publicKey);
147 
148 error_t sshParseEd25519CertPublicKey(const uint8_t *data, size_t length,
149  size_t *consumed, SshEd25519CertPublicKey *publicKey);
150 
151 error_t sshParseValidPrincipals(const uint8_t *data, size_t length,
152  SshBinaryString *validPrincipals);
153 
154 error_t sshParseCriticalOptions(const uint8_t *data, size_t length,
155  SshBinaryString *criticalOptions);
156 
157 error_t sshParseExtensions(const uint8_t *data, size_t length,
159 
161  SshString *name);
162 
165 
166 bool_t sshGetExtension(const SshCertificate *cert, uint_t index,
168 
169 //C++ guard
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif
uint8_t extensions[]
Definition: ntp_common.h:207
int bool_t
Definition: compiler_port.h:53
Binary string.
Definition: ssh_types.h:67
error_t sshParseCertificate(const uint8_t *data, size_t length, SshCertificate *cert)
Parse SSH certificate.
uint8_t data[]
Definition: ethernet.h:222
SshRsaCertPublicKey rsaPublicKey
error_t sshParseCriticalOptions(const uint8_t *data, size_t length, SshBinaryString *criticalOptions)
Parse 'critical options' field.
SshBinaryString g
SshBinaryString n
char_t name[]
error_t sshParseDsaCertPublicKey(const uint8_t *data, size_t length, size_t *consumed, SshDsaCertPublicKey *publicKey)
Parse a DSA public key.
bool_t sshGetCriticalOption(const SshCertificate *cert, uint_t index, SshString *name, SshBinaryString *data)
Extract the critical option at specified index.
ECDSA public key.
error_t sshParseEd25519CertPublicKey(const uint8_t *data, size_t length, size_t *consumed, SshEd25519CertPublicKey *publicKey)
Parse an Ed25519 public key.
SshBinaryString p
error_t sshParseEcdsaCertPublicKey(const uint8_t *data, size_t length, size_t *consumed, SshEcdsaCertPublicKey *publicKey)
Parse an ECDSA public key.
SshBinaryString validPrincipals
error_t
Error codes.
Definition: error.h:43
SshDsaCertPublicKey dsaPublicKey
@ SSH_CERT_TYPE_USER
error_t sshParseExtensions(const uint8_t *data, size_t length, SshBinaryString *extensions)
Parse 'extensions' field.
SshBinaryString extensions
DSA public key.
SshBinaryString reserved
uint64_t validAfter
SshEcdsaCertPublicKey ecdsaPublicKey
uint8_t length
Definition: tcp.h:368
SshBinaryString y
String.
Definition: ssh_types.h:56
SshBinaryString q
SshBinaryString criticalOptions
RSA public key.
SshBinaryString e
error_t sshParseRsaCertPublicKey(const uint8_t *data, size_t length, size_t *consumed, SshRsaCertPublicKey *publicKey)
Parse an RSA public key.
SshString keyFormatId
SshBinaryString signatureKey
SSH data type representations.
SshCertPublicKey publicKey
uint64_t validBefore
bool_t sshGetValidPrincipal(const SshCertificate *cert, uint_t index, SshString *name)
Extract the principal name at specified index.
bool_t sshGetExtension(const SshCertificate *cert, uint_t index, SshString *name, SshBinaryString *data)
Extract the extension at specified index.
error_t sshParseValidPrincipals(const uint8_t *data, size_t length, SshBinaryString *validPrincipals)
Parse 'valid principals' field.
SshBinaryString nonce
SshBinaryString signature
@ SSH_CERT_TYPE_HOST
SshCertType
SSH certificate types.
unsigned int uint_t
Definition: compiler_port.h:50
Ed25519 public key.
SSH certificate (OpenSSH format)
SshBinaryString q
SshEd25519CertPublicKey ed25519PublicKey