Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/proto/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ pub struct Ed25519PrivateKey {
pub k_enc_a: Vec<u8>
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct SkEd25519PrivateKey {
pub enc_a: Vec<u8>,
pub application: String,
pub flags: u8,
pub key_handle: Vec<u8>,
pub reserved: Vec<u8>
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct RsaPrivateKey {
pub n: MpInt,
Expand All @@ -38,12 +47,24 @@ pub struct EcDsaPrivateKey {
pub d: MpInt
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct SkEcDsaPrivateKey {
pub identifier: String,
pub q: MpInt,
pub application: String,
pub flags: u8,
pub key_handle: Vec<u8>,
pub reserved: Vec<u8>
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum PrivateKey {
Dss(DssPrivateKey),
Ed25519(Ed25519PrivateKey),
SkEd25519(SkEd25519PrivateKey),
Rsa(RsaPrivateKey),
EcDsa(EcDsaPrivateKey)
EcDsa(EcDsaPrivateKey),
SkEcDsa(SkEcDsaPrivateKey)
}

impl KeyType for RsaPrivateKey {
Expand All @@ -58,6 +79,10 @@ impl KeyType for Ed25519PrivateKey {
const KEY_TYPE: &'static str = "ssh-ed25519";
}

impl KeyType for SkEd25519PrivateKey {
const KEY_TYPE: &'static str = "sk-ssh-ed25519@openssh.com";
}

impl KeyType for EcDsaPrivateKey {
const KEY_TYPE: &'static str = "ecdsa-sha2";

Expand All @@ -66,10 +91,20 @@ impl KeyType for EcDsaPrivateKey {
}
}

impl KeyType for SkEcDsaPrivateKey {
const KEY_TYPE: &'static str = "sk-ecdsa-sha2";

fn key_type(&self) -> String {
format!("{}-{}@openssh.com", Self::KEY_TYPE, self.identifier)
}
}

impl_key_type_enum_ser_de!(
PrivateKey,
(PrivateKey::Dss, DssPrivateKey),
(PrivateKey::Rsa, RsaPrivateKey),
(PrivateKey::EcDsa, EcDsaPrivateKey),
(PrivateKey::Ed25519, Ed25519PrivateKey)
(PrivateKey::SkEcDsa, SkEcDsaPrivateKey),
(PrivateKey::Ed25519, Ed25519PrivateKey),
(PrivateKey::SkEd25519, SkEd25519PrivateKey)
);
54 changes: 52 additions & 2 deletions src/proto/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,32 @@ pub struct EcDsaPublicKey {
pub q: MpInt
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct SkEcDsaPublicKey {
pub identifier: String,
pub q: MpInt,
pub application: String,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Ed25519PublicKey {
pub enc_a: Vec<u8>
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct SkEd25519PublicKey {
pub enc_a: Vec<u8>,
pub application: String,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum PublicKey {
Dss(DssPublicKey),
Ed25519(Ed25519PublicKey),
SkEd25519(SkEd25519PublicKey),
Rsa(RsaPublicKey),
EcDsa(EcDsaPublicKey)
EcDsa(EcDsaPublicKey),
SkEcDsa(SkEcDsaPublicKey),
}

impl KeyType for RsaPublicKey {
Expand All @@ -60,13 +75,27 @@ impl KeyType for EcDsaPublicKey {
}
}

impl KeyType for SkEd25519PublicKey {
const KEY_TYPE: &'static str = "sk-ssh-ed25519@openssh.com";
}

impl KeyType for SkEcDsaPublicKey {
const KEY_TYPE: &'static str = "sk-ecdsa-sha2";

fn key_type(&self) -> String {
format!("{}-{}@openssh.com", Self::KEY_TYPE, self.identifier)
}
}

impl From<PrivateKey> for PublicKey {
fn from(key: PrivateKey) -> Self {
match key {
PrivateKey::Dss(key) => PublicKey::Dss(DssPublicKey::from(key)),
PrivateKey::Ed25519(key) => PublicKey::Ed25519(Ed25519PublicKey::from(key)),
PrivateKey::SkEd25519(key) => PublicKey::SkEd25519(SkEd25519PublicKey::from(key)),
PrivateKey::Rsa(key) => PublicKey::Rsa(RsaPublicKey::from(key)),
PrivateKey::EcDsa(key) => PublicKey::EcDsa(EcDsaPublicKey::from(key)),
PrivateKey::SkEcDsa(key) => PublicKey::SkEcDsa(SkEcDsaPublicKey::from(key)),
}
}
}
Expand Down Expand Up @@ -100,6 +129,16 @@ impl From<EcDsaPrivateKey> for EcDsaPublicKey {
}
}

impl From<SkEcDsaPrivateKey> for SkEcDsaPublicKey {
fn from(key: SkEcDsaPrivateKey) -> Self {
Self {
identifier: key.identifier,
q: key.q,
application: key.application
}
}
}

impl From<Ed25519PrivateKey> for Ed25519PublicKey {
fn from(key: Ed25519PrivateKey) -> Self {
Self {
Expand All @@ -108,6 +147,15 @@ impl From<Ed25519PrivateKey> for Ed25519PublicKey {
}
}

impl From<SkEd25519PrivateKey> for SkEd25519PublicKey {
fn from(key: SkEd25519PrivateKey) -> Self {
Self {
enc_a: key.enc_a,
application: key.application
}
}
}

impl From<&PrivateKey> for PublicKey {
fn from(key: &PrivateKey) -> Self {
Self::from(key.clone())
Expand Down Expand Up @@ -143,7 +191,9 @@ impl_key_type_enum_ser_de!(
(PublicKey::Dss, DssPublicKey),
(PublicKey::Rsa, RsaPublicKey),
(PublicKey::EcDsa, EcDsaPublicKey),
(PublicKey::Ed25519, Ed25519PublicKey)
(PublicKey::SkEcDsa, SkEcDsaPublicKey),
(PublicKey::Ed25519, Ed25519PublicKey),
(PublicKey::SkEd25519, SkEd25519PublicKey)
);


8 changes: 8 additions & 0 deletions src/proto/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ pub struct Signature {
pub blob: Vec<u8>
}

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct SkSignature {
pub algorithm: String,
pub blob: Vec<u8>,
pub flags: u8,
pub counter: u32
}

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct EcDsaSignature {
pub identifier: String,
Expand Down