-
-
Notifications
You must be signed in to change notification settings - Fork 213
Implement PKCS8 certificate support for all three backends. #147
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
Changes from 1 commit
eb269b8
c400390
1a6d7ba
ab437ba
beb8ebc
28eade4
7e9a612
da4cf1a
255dd54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
extern crate schannel; | ||
|
||
use self::schannel::cert_context::{CertContext, HashAlgorithm}; | ||
use self::schannel::cert_context::{CertContext, HashAlgorithm, KeySpec}; | ||
use self::schannel::cert_store::{CertAdd, CertStore, Memory, PfxImportOptions}; | ||
use self::schannel::schannel_cred::{Direction, Protocol, SchannelCred}; | ||
use self::schannel::crypt_prov::{AcquireOptions, ProviderType}; | ||
use self::schannel::tls_stream; | ||
use std::error; | ||
use std::fmt; | ||
|
@@ -96,6 +97,41 @@ impl Identity { | |
|
||
Ok(Identity { cert: identity }) | ||
} | ||
|
||
pub fn from_pkcs8(pem: &[u8], key: &[u8]) -> Result<Identity, Error> { | ||
let mut store = Memory::new()?.into_store(); | ||
let mut cert_iter = crate::pem::PemBlock::new(pem).into_iter(); | ||
let leaf = cert_iter.next().unwrap(); | ||
let cert = CertContext::from_pem(std::str::from_utf8(leaf).unwrap()).unwrap(); | ||
|
||
let mut options = AcquireOptions::new(); | ||
options.container("schannel"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I seem to remember there being problems on windows if the same container name is used multiple times. Probably worth a test that parses a couple of identities to confirm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the test case that caused issues on my previous attempt: b0b9164 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test still needs to be added. |
||
let type_ = ProviderType::rsa_full(); | ||
|
||
let mut container = match options.acquire(type_) { | ||
Ok(container) => container, | ||
Err(_) => options.new_keyset(true).acquire(type_).unwrap(), | ||
}; | ||
let key = crate::pem::pem_to_der(key, Some(crate::pem::PEM_PRIVATE_KEY)).unwrap(); | ||
container.import() | ||
.import_pkcs8(&key) | ||
.unwrap(); | ||
|
||
cert.set_key_prov_info() | ||
.container("schannel") | ||
.type_(type_) | ||
.keep_open(true) | ||
.key_spec(KeySpec::key_exchange()) | ||
.set() | ||
.unwrap(); | ||
let mut context = store.add_cert(&cert, CertAdd::Always)?; | ||
|
||
for int_cert in cert_iter { | ||
let certificate = Certificate::from_pem(int_cert)?; | ||
context = store.add_cert(&certificate.0, schannel::cert_store::CertAdd::Always)?; | ||
} | ||
Ok(Identity{cert: context}) | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
|
Uh oh!
There was an error while loading. Please reload this page.