Skip to content

Commit c9af3c3

Browse files
notoriagaJason Mobarak
andauthored
fix signature in MsgCertificateChain [GV2-193] (#1307)
Co-authored-by: Jason Mobarak <jason@swift-nav.com>
1 parent 5b11980 commit c9af3c3

File tree

77 files changed

+24039
-7408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+24039
-7408
lines changed

c/include/libsbp/cpp/message_traits.h

Lines changed: 93 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,43 @@ struct MessageTraits<sbp_msg_cell_modem_status_t> {
10231023
}
10241024
};
10251025

1026+
template <>
1027+
struct MessageTraits<sbp_msg_certificate_chain_dep_t> {
1028+
static constexpr sbp_msg_type_t id = SbpMsgCertificateChainDep;
1029+
static constexpr const char *name = "MSG_CERTIFICATE_CHAIN_DEP";
1030+
static const sbp_msg_certificate_chain_dep_t &get(const sbp_msg_t &msg) {
1031+
return msg.certificate_chain_dep;
1032+
}
1033+
static sbp_msg_certificate_chain_dep_t &get(sbp_msg_t &msg) {
1034+
return msg.certificate_chain_dep;
1035+
}
1036+
static void to_sbp_msg(const sbp_msg_certificate_chain_dep_t &msg,
1037+
sbp_msg_t *sbp_msg) {
1038+
sbp_msg->certificate_chain_dep = msg;
1039+
}
1040+
static sbp_msg_t to_sbp_msg(const sbp_msg_certificate_chain_dep_t &msg) {
1041+
sbp_msg_t sbp_msg;
1042+
sbp_msg.certificate_chain_dep = msg;
1043+
return sbp_msg;
1044+
}
1045+
static s8 send(sbp_state_t *state, u16 sender_id,
1046+
const sbp_msg_certificate_chain_dep_t &msg,
1047+
sbp_write_fn_t write) {
1048+
return sbp_msg_certificate_chain_dep_send(state, sender_id, &msg, write);
1049+
}
1050+
static s8 encode(uint8_t *buf, uint8_t len, uint8_t *n_written,
1051+
const sbp_msg_certificate_chain_dep_t &msg) {
1052+
return sbp_msg_certificate_chain_dep_encode(buf, len, n_written, &msg);
1053+
}
1054+
static s8 decode(const uint8_t *buf, uint8_t len, uint8_t *n_read,
1055+
sbp_msg_certificate_chain_dep_t *msg) {
1056+
return sbp_msg_certificate_chain_dep_decode(buf, len, n_read, msg);
1057+
}
1058+
static size_t encoded_len(const sbp_msg_certificate_chain_dep_t &msg) {
1059+
return sbp_msg_certificate_chain_dep_encoded_len(&msg);
1060+
}
1061+
};
1062+
10261063
template <>
10271064
struct MessageTraits<sbp_msg_certificate_chain_t> {
10281065
static constexpr sbp_msg_type_t id = SbpMsgCertificateChain;
@@ -1476,39 +1513,76 @@ struct MessageTraits<sbp_msg_ecdsa_certificate_t> {
14761513
};
14771514

14781515
template <>
1479-
struct MessageTraits<sbp_msg_ecdsa_signature_dep_t> {
1480-
static constexpr sbp_msg_type_t id = SbpMsgEcdsaSignatureDep;
1481-
static constexpr const char *name = "MSG_ECDSA_SIGNATURE_DEP";
1482-
static const sbp_msg_ecdsa_signature_dep_t &get(const sbp_msg_t &msg) {
1483-
return msg.ecdsa_signature_dep;
1516+
struct MessageTraits<sbp_msg_ecdsa_signature_dep_a_t> {
1517+
static constexpr sbp_msg_type_t id = SbpMsgEcdsaSignatureDepA;
1518+
static constexpr const char *name = "MSG_ECDSA_SIGNATURE_DEP_A";
1519+
static const sbp_msg_ecdsa_signature_dep_a_t &get(const sbp_msg_t &msg) {
1520+
return msg.ecdsa_signature_dep_a;
1521+
}
1522+
static sbp_msg_ecdsa_signature_dep_a_t &get(sbp_msg_t &msg) {
1523+
return msg.ecdsa_signature_dep_a;
1524+
}
1525+
static void to_sbp_msg(const sbp_msg_ecdsa_signature_dep_a_t &msg,
1526+
sbp_msg_t *sbp_msg) {
1527+
sbp_msg->ecdsa_signature_dep_a = msg;
1528+
}
1529+
static sbp_msg_t to_sbp_msg(const sbp_msg_ecdsa_signature_dep_a_t &msg) {
1530+
sbp_msg_t sbp_msg;
1531+
sbp_msg.ecdsa_signature_dep_a = msg;
1532+
return sbp_msg;
1533+
}
1534+
static s8 send(sbp_state_t *state, u16 sender_id,
1535+
const sbp_msg_ecdsa_signature_dep_a_t &msg,
1536+
sbp_write_fn_t write) {
1537+
return sbp_msg_ecdsa_signature_dep_a_send(state, sender_id, &msg, write);
1538+
}
1539+
static s8 encode(uint8_t *buf, uint8_t len, uint8_t *n_written,
1540+
const sbp_msg_ecdsa_signature_dep_a_t &msg) {
1541+
return sbp_msg_ecdsa_signature_dep_a_encode(buf, len, n_written, &msg);
1542+
}
1543+
static s8 decode(const uint8_t *buf, uint8_t len, uint8_t *n_read,
1544+
sbp_msg_ecdsa_signature_dep_a_t *msg) {
1545+
return sbp_msg_ecdsa_signature_dep_a_decode(buf, len, n_read, msg);
1546+
}
1547+
static size_t encoded_len(const sbp_msg_ecdsa_signature_dep_a_t &msg) {
1548+
return sbp_msg_ecdsa_signature_dep_a_encoded_len(&msg);
1549+
}
1550+
};
1551+
1552+
template <>
1553+
struct MessageTraits<sbp_msg_ecdsa_signature_dep_b_t> {
1554+
static constexpr sbp_msg_type_t id = SbpMsgEcdsaSignatureDepB;
1555+
static constexpr const char *name = "MSG_ECDSA_SIGNATURE_DEP_B";
1556+
static const sbp_msg_ecdsa_signature_dep_b_t &get(const sbp_msg_t &msg) {
1557+
return msg.ecdsa_signature_dep_b;
14841558
}
1485-
static sbp_msg_ecdsa_signature_dep_t &get(sbp_msg_t &msg) {
1486-
return msg.ecdsa_signature_dep;
1559+
static sbp_msg_ecdsa_signature_dep_b_t &get(sbp_msg_t &msg) {
1560+
return msg.ecdsa_signature_dep_b;
14871561
}
1488-
static void to_sbp_msg(const sbp_msg_ecdsa_signature_dep_t &msg,
1562+
static void to_sbp_msg(const sbp_msg_ecdsa_signature_dep_b_t &msg,
14891563
sbp_msg_t *sbp_msg) {
1490-
sbp_msg->ecdsa_signature_dep = msg;
1564+
sbp_msg->ecdsa_signature_dep_b = msg;
14911565
}
1492-
static sbp_msg_t to_sbp_msg(const sbp_msg_ecdsa_signature_dep_t &msg) {
1566+
static sbp_msg_t to_sbp_msg(const sbp_msg_ecdsa_signature_dep_b_t &msg) {
14931567
sbp_msg_t sbp_msg;
1494-
sbp_msg.ecdsa_signature_dep = msg;
1568+
sbp_msg.ecdsa_signature_dep_b = msg;
14951569
return sbp_msg;
14961570
}
14971571
static s8 send(sbp_state_t *state, u16 sender_id,
1498-
const sbp_msg_ecdsa_signature_dep_t &msg,
1572+
const sbp_msg_ecdsa_signature_dep_b_t &msg,
14991573
sbp_write_fn_t write) {
1500-
return sbp_msg_ecdsa_signature_dep_send(state, sender_id, &msg, write);
1574+
return sbp_msg_ecdsa_signature_dep_b_send(state, sender_id, &msg, write);
15011575
}
15021576
static s8 encode(uint8_t *buf, uint8_t len, uint8_t *n_written,
1503-
const sbp_msg_ecdsa_signature_dep_t &msg) {
1504-
return sbp_msg_ecdsa_signature_dep_encode(buf, len, n_written, &msg);
1577+
const sbp_msg_ecdsa_signature_dep_b_t &msg) {
1578+
return sbp_msg_ecdsa_signature_dep_b_encode(buf, len, n_written, &msg);
15051579
}
15061580
static s8 decode(const uint8_t *buf, uint8_t len, uint8_t *n_read,
1507-
sbp_msg_ecdsa_signature_dep_t *msg) {
1508-
return sbp_msg_ecdsa_signature_dep_decode(buf, len, n_read, msg);
1581+
sbp_msg_ecdsa_signature_dep_b_t *msg) {
1582+
return sbp_msg_ecdsa_signature_dep_b_decode(buf, len, n_read, msg);
15091583
}
1510-
static size_t encoded_len(const sbp_msg_ecdsa_signature_dep_t &msg) {
1511-
return sbp_msg_ecdsa_signature_dep_encoded_len(&msg);
1584+
static size_t encoded_len(const sbp_msg_ecdsa_signature_dep_b_t &msg) {
1585+
return sbp_msg_ecdsa_signature_dep_b_encoded_len(&msg);
15121586
}
15131587
};
15141588

c/include/libsbp/legacy/cpp/message_traits.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,23 +1186,35 @@ struct MessageTraits<msg_ecdsa_certificate_t> {
11861186

11871187

11881188
template<>
1189-
struct MessageTraits<msg_certificate_chain_t> {
1189+
struct MessageTraits<msg_certificate_chain_dep_t> {
11901190
static constexpr u16 id = 3077;
11911191
};
11921192

11931193

11941194
template<>
1195-
struct MessageTraits<msg_ecdsa_signature_dep_t> {
1195+
struct MessageTraits<msg_ecdsa_signature_dep_a_t> {
11961196
static constexpr u16 id = 3078;
11971197
};
11981198

11991199

12001200
template<>
1201-
struct MessageTraits<msg_ecdsa_signature_t> {
1201+
struct MessageTraits<msg_ecdsa_signature_dep_b_t> {
12021202
static constexpr u16 id = 3079;
12031203
};
12041204

12051205

1206+
template<>
1207+
struct MessageTraits<msg_ecdsa_signature_t> {
1208+
static constexpr u16 id = 3080;
1209+
};
1210+
1211+
1212+
template<>
1213+
struct MessageTraits<msg_certificate_chain_t> {
1214+
static constexpr u16 id = 3081;
1215+
};
1216+
1217+
12061218
template<>
12071219
struct MessageTraits<msg_fileio_config_req_t> {
12081220
static constexpr u16 id = 4097;

c/include/libsbp/legacy/signing.h

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ typedef struct SBP_ATTR_PACKED {
3939
u32 ns; /**< nanoseconds of second (range 0-999999999) [nanoseconds] */
4040
} utc_time_t;
4141

42+
typedef struct SBP_ATTR_PACKED {
43+
u8 len; /**< Number of bytes to use of the signature field. The DER
44+
encoded signature has a maximum size of 72 bytes but can
45+
vary between 70 and 72 bytes in length. */
46+
u8 data[72]; /**< DER encoded ECDSA signature for the messages using SHA-256
47+
as the digest algorithm. */
48+
} ecdsa_signature_t;
49+
4250
/** An ECDSA certificate split over multiple messages
4351
*
4452
* A DER encoded x.509 ECDSA-256 certificate (using curve secp256r1).
@@ -56,6 +64,41 @@ typedef struct SBP_ATTR_PACKED {
5664
u8 certificate_bytes[0]; /**< DER encoded x.509 ECDSA certificate bytes */
5765
} msg_ecdsa_certificate_t;
5866

67+
typedef struct SBP_ATTR_PACKED {
68+
u8 root_certificate[20]; /**< SHA-1 fingerprint of the root
69+
certificate */
70+
u8 intermediate_certificate[20]; /**< SHA-1 fingerprint of the intermediate
71+
certificate */
72+
u8 corrections_certificate[20]; /**< SHA-1 fingerprint of the corrections
73+
certificate */
74+
utc_time_t expiration; /**< The time after which the
75+
signature given is no longer
76+
valid. Implementors should
77+
consult a time source (such as
78+
GNSS) to check if the current
79+
time is later than the
80+
expiration time, if the
81+
condition is true, signatures
82+
in the stream should not be
83+
considered valid. */
84+
ecdsa_signature_t signature; /**< Signature (created by
85+
the root certificate)
86+
over the concatenation
87+
of the SBP payload bytes
88+
preceding this field.
89+
That is, the
90+
concatenation of
91+
`root_certificate`,
92+
`intermediate_certificate`,
93+
`corrections_certificate`
94+
and `expiration`. This
95+
certificate chain (allow
96+
list) can also be
97+
validated by fetching it
98+
from
99+
`http(s)://certs.swiftnav.com/chain`. */
100+
} msg_certificate_chain_t;
101+
59102
typedef struct SBP_ATTR_PACKED {
60103
u8 root_certificate[20]; /**< SHA-1 fingerprint of the root
61104
certificate */
@@ -79,7 +122,42 @@ typedef struct SBP_ATTR_PACKED {
79122
(allow list) can also be validated by
80123
fetching it from
81124
`http(s)://certs.swiftnav.com/chain`. */
82-
} msg_certificate_chain_t;
125+
} msg_certificate_chain_dep_t;
126+
127+
/** An ECDSA signature
128+
*
129+
* An ECDSA-256 signature using SHA-256 as the message digest algorithm.
130+
*/
131+
132+
typedef struct SBP_ATTR_PACKED {
133+
u8 flags; /**< Describes the format of the `signed\_messages`
134+
field below. */
135+
u8 stream_counter; /**< Signature message counter. Zero indexed and
136+
incremented with each signature message. The
137+
counter will not increment if this message was
138+
in response to an on demand request. The
139+
counter will roll over after 256 messages.
140+
Upon connection, the value of the counter may
141+
not initially be zero. */
142+
u8 on_demand_counter; /**< On demand message counter. Zero indexed and
143+
incremented with each signature message sent
144+
in response to an on demand message. The
145+
counter will roll over after 256 messages.
146+
Upon connection, the value of the counter may
147+
not initially be zero. */
148+
u8 certificate_id[4]; /**< The last 4 bytes of the certificate's SHA-1
149+
fingerprint */
150+
ecdsa_signature_t signature; /**< Signature over the frames of
151+
this message group. */
152+
u8 signed_messages[0]; /**< CRCs of the messages covered by this
153+
signature. For Skylark, which delivers SBP
154+
messages wrapped in Swift's proprietary RTCM
155+
message, these are the 24-bit CRCs from the
156+
RTCM message framing. For SBP only streams,
157+
this will be 16-bit CRCs from the SBP framing.
158+
See the `flags` field to determine the type of
159+
CRCs covered. */
160+
} msg_ecdsa_signature_t;
83161

84162
/** An ECDSA signature
85163
*
@@ -118,7 +196,7 @@ typedef struct SBP_ATTR_PACKED {
118196
this will be 16-bit CRCs from the SBP framing.
119197
See the `flags` field to determine the type of
120198
CRCs covered. */
121-
} msg_ecdsa_signature_t;
199+
} msg_ecdsa_signature_dep_b_t;
122200

123201
/** An ECDSA signature
124202
*
@@ -153,7 +231,7 @@ typedef struct SBP_ATTR_PACKED {
153231
this will be 16-bit CRCs from the SBP framing.
154232
See the `flags` field to determine the type of
155233
CRCs covered. */
156-
} msg_ecdsa_signature_dep_t;
234+
} msg_ecdsa_signature_dep_a_t;
157235

158236
typedef struct SBP_ATTR_PACKED {
159237
u8 n_msg; /**< Total number messages that make up the

c/include/libsbp/sbp_msg_type.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef enum {
8080
SbpMsgBootloaderHandshakeResp = SBP_MSG_BOOTLOADER_HANDSHAKE_RESP,
8181
SbpMsgBootloaderJumpToApp = SBP_MSG_BOOTLOADER_JUMP_TO_APP,
8282
SbpMsgCellModemStatus = SBP_MSG_CELL_MODEM_STATUS,
83+
SbpMsgCertificateChainDep = SBP_MSG_CERTIFICATE_CHAIN_DEP,
8384
SbpMsgCertificateChain = SBP_MSG_CERTIFICATE_CHAIN,
8485
SbpMsgCommandOutput = SBP_MSG_COMMAND_OUTPUT,
8586
SbpMsgCommandReq = SBP_MSG_COMMAND_REQ,
@@ -93,7 +94,8 @@ typedef enum {
9394
SbpMsgDopsDepA = SBP_MSG_DOPS_DEP_A,
9495
SbpMsgDops = SBP_MSG_DOPS,
9596
SbpMsgEcdsaCertificate = SBP_MSG_ECDSA_CERTIFICATE,
96-
SbpMsgEcdsaSignatureDep = SBP_MSG_ECDSA_SIGNATURE_DEP,
97+
SbpMsgEcdsaSignatureDepA = SBP_MSG_ECDSA_SIGNATURE_DEP_A,
98+
SbpMsgEcdsaSignatureDepB = SBP_MSG_ECDSA_SIGNATURE_DEP_B,
9799
SbpMsgEcdsaSignature = SBP_MSG_ECDSA_SIGNATURE,
98100
SbpMsgEd25519CertificateDep = SBP_MSG_ED25519_CERTIFICATE_DEP,
99101
SbpMsgEd25519SignatureDepA = SBP_MSG_ED25519_SIGNATURE_DEP_A,

0 commit comments

Comments
 (0)