1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//! response of Service 29
use crate::{constants::LOG_TAG_SERVER, server::DoCanServer};
use iso14229_1::{
request::{self, Request},
response::{self, AuthReturnValue, Code, Response},
AuthenticationTask, Configuration, Iso14229Error,
};
use rs_can::{CanDevice, CanFrame};
use std::fmt::Display;
impl<D, C, F> DoCanServer<D, C, F>
where
D: CanDevice<Channel = C, Frame = F> + Clone + Send + 'static,
C: Clone + Eq + Display + Send + Sync + 'static,
F: CanFrame<Channel = C> + Clone + Display + 'static,
{
pub(crate) async fn authentication(
&self,
req: Request,
cfg: &Configuration,
) -> Result<(), Iso14229Error> {
let service = req.service();
let resp = match req.data::<request::Authentication>(cfg) {
Ok(ctx) => match req.sub_function() {
Some(sf) => {
if sf.is_suppress_positive() {
Response::new_negative(service, Code::SubFunctionNotSupported)
} else {
#[allow(unused)]
match sf.function::<AuthenticationTask>() {
Ok(task) => {
let data = match ctx {
request::Authentication::DeAuthenticate => {
response::Authentication::DeAuthenticate(
AuthReturnValue::RequestAccepted
)
}
request::Authentication::VerifyCertificateUnidirectional {
config,
certificate,
challenge
} => {
response::Authentication::VerifyCertificateUnidirectional {
value: AuthReturnValue::RequestAccepted,
challenge: certificate,
ephemeral_public_key: challenge,
}
}
request::Authentication::VerifyCertificateBidirectional {
config,
challenge,
certificate
} => {
response::Authentication::VerifyCertificateBidirectional {
value: AuthReturnValue::RequestAccepted,
challenge,
certificate,
proof_of_ownership: Default::default(),
ephemeral_public_key: Default::default(),
}
}
request::Authentication::ProofOfOwnership {
proof_of_ownership,
ephemeral_public_key,
} => {
response::Authentication::ProofOfOwnership {
value: AuthReturnValue::RequestAccepted,
session_keyinfo: ephemeral_public_key,
}
}
request::Authentication::TransmitCertificate {
cert_evaluation_id,
certificate,
} => {
response::Authentication::TransmitCertificate(
AuthReturnValue::RequestAccepted
)
}
request::Authentication::RequestChallengeForAuthentication {
config,
algo_indicator,
} => {
response::Authentication::RequestChallengeForAuthentication {
value: AuthReturnValue::RequestAccepted,
algo_indicator,
challenge: Default::default(),
additional: Default::default(),
}
}
request::Authentication::VerifyProofOfOwnershipUnidirectional {
algo_indicator,
proof_of_ownership,
challenge,
additional,
} => {
response::Authentication::VerifyProofOfOwnershipUnidirectional {
value: AuthReturnValue::RequestAccepted,
algo_indicator,
session_keyinfo: Default::default(),
}
}
request::Authentication::VerifyProofOfOwnershipBidirectional {
algo_indicator,
proof_of_ownership,
challenge,
additional,
} => {
response::Authentication::VerifyProofOfOwnershipBidirectional {
value: AuthReturnValue::RequestAccepted,
algo_indicator,
proof_of_ownership,
session_keyinfo: Default::default(),
}
}
request::Authentication::AuthenticationConfiguration => {
response::Authentication::AuthenticationConfiguration(
AuthReturnValue::RequestAccepted,
)
}
};
Response::new::<Vec<_>>(service, Some(sf.into()), data.into(), cfg)?
}
Err(e) => {
rsutil::warn!(
"{} can't parse sub-function on service: {}, because of: {}",
LOG_TAG_SERVER,
service,
e
);
Response::new_negative(
service,
Code::IncorrectMessageLengthOrInvalidFormat,
)
}
}
}
}
None => {
rsutil::warn!(
"{} can't get sub-function on service: {}",
LOG_TAG_SERVER,
service
);
Response::new_negative(service, Code::GeneralReject)
}
},
Err(e) => {
rsutil::warn!("{} Failed to parse request data: {:?}", LOG_TAG_SERVER, e);
Response::new_negative(service, Code::GeneralReject)
}
};
self.transmit_response(resp, true).await;
Ok(())
}
}