Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds feature to upload and retrieve public keys from DSM #88

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ When building, make sure to disable default features (to disable
Nettle) and enable the CNG via `crypto-cng` Cargo feature:

```bash
$ cargo build --no-default-features --features crypto-cng,compression # Only change crypto backend
$ cargo build --no-default-features --features net,crypto-cng,compression
```

[`capnp`]: https://capnproto.org/install.html
Expand Down
10 changes: 9 additions & 1 deletion guide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ repository = "https://gitlab.com/sequoia-pgp/sequoia"
build = "build.rs"

[dependencies]
sequoia-openpgp = { path = "../openpgp", version = "1.0.0" }
sequoia-openpgp = { path = "../openpgp", version = "1.0.0", default-features = false }
anyhow = "1.0.18"

[lib]
bench = false

[features]
default = ["sequoia-openpgp/default"]
crypto-nettle = ["sequoia-openpgp/crypto-nettle"]
crypto-cng = ["sequoia-openpgp/crypto-cng"]
compression = ["sequoia-openpgp/compression"]
compression-deflate = ["sequoia-openpgp/compression-deflate"]
compression-bzip2 = ["sequoia-openpgp/compression-bzip2"]
2 changes: 1 addition & 1 deletion openpgp-dsm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openpgp-dsm"
version = "1.6.1"
version = "1.7.0"
authors = ["zugzwang <[email protected]>"]
edition = "2018"

Expand Down
33 changes: 28 additions & 5 deletions openpgp-dsm/src/der.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub mod serialize {
})
})
}

pub fn ec_private_25519(curve: &Curve, x: Vec<u8>) -> Result<Vec<u8>> {
let opaque_octet_string = yasna::construct_der(|w| {
w.write_bytes(&x);
Expand Down Expand Up @@ -235,19 +235,42 @@ pub mod serialize {
}))
}

pub fn spki_ecdh(curve: &Curve, e: &mpi::MPI) -> Vec<u8> {
pub fn spki_rsa(n: &mpi::MPI, e: &mpi::MPI) -> Vec<u8> {
// RSA public key
let rsa_public_key = yasna::construct_der(|der_writer| {
der_writer.write_sequence_of(|w| {
w.next()
.write_biguint(&BigUint::from_bytes_be(n.value()));
w.next()
.write_biguint(&BigUint::from_bytes_be(e.value()));
});
});

// Construct the SPKI structure
yasna::construct_der(|der_writer| {
der_writer.write_sequence_of(|w| {
w.next().write_sequence(|w| {
w.next().write_oid(&Oid::from_slice(&[1, 2, 840, 113549, 1, 1, 1]));
w.next().write_null();
});
w.next().write_bitvec(&BitVec::from_bytes(&rsa_public_key));
});
})
}

pub fn spki_ec(curve: &Curve, e: &mpi::MPI) -> Vec<u8> {
match curve {
Curve::Cv25519 => {
Curve::Cv25519 | Curve::Ed25519 => {
let x = e.value();
assert!(!x.is_empty());

let x = x[1..].to_vec();

let curve_25519_oid = Oid::from_slice(&[1, 3, 101, 110]);
let oid = curve_oid(curve).expect("bad curve OID");
yasna::construct_der(|w| {
w.write_sequence(|w| {
w.next().write_sequence(|w| {
w.next().write_oid(&curve_25519_oid);
w.next().write_oid(&oid);
});
w.next().write_bitvec(&BitVec::from_bytes(&x))
});
Expand Down
Loading