-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins: Add {de}serializable type for ID-KEY ECDH exchange
To prevent replay attacks, the ID-KEY resource backend requires an ECDH public key exchange, as well a nonce for the generated AES-GCM key that is used to wrap the encrypted key. Add a type for easy {de}serialization of this data. Signed-off-by: Tyler Fanelli <[email protected]>
- Loading branch information
1 parent
611889d
commit 2c3a70a
Showing
5 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod resource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use super::super::super::{deserialize_base64, serialize_base64, String, Vec}; | ||
use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine}; | ||
use p384::PublicKey; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct IdKeyEcdh { | ||
#[serde( | ||
serialize_with = "serialize_ec_public_key_sec1_base64", | ||
deserialize_with = "deserialize_ec_public_key_sec1_base64" | ||
)] | ||
pub public_key: PublicKey, | ||
#[serde( | ||
serialize_with = "serialize_base64", | ||
deserialize_with = "deserialize_base64" | ||
)] | ||
pub iv: Vec<u8>, | ||
} | ||
|
||
fn serialize_ec_public_key_sec1_base64<S>( | ||
sub: &PublicKey, | ||
serializer: S, | ||
) -> core::result::Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
let encoded = BASE64_URL_SAFE_NO_PAD.encode(sub.to_sec1_bytes()); | ||
serializer.serialize_str(&encoded) | ||
} | ||
|
||
fn deserialize_ec_public_key_sec1_base64<'de, D>( | ||
deserializer: D, | ||
) -> core::result::Result<PublicKey, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let encoded = String::deserialize(deserializer)?; | ||
let sec1 = BASE64_URL_SAFE_NO_PAD | ||
.decode(encoded) | ||
.map_err(serde::de::Error::custom)?; | ||
let public_key = PublicKey::from_sec1_bytes(&sec1).map_err(serde::de::Error::custom)?; | ||
|
||
Ok(public_key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod id_key; |