-
Notifications
You must be signed in to change notification settings - Fork 180
RUST-226 Support tlsCertificateKeyFilePassword #1256
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
Merged
abr-egn
merged 11 commits into
mongodb:main
from
abr-egn:RUST-226/rustls-tlsCertificateKeyFilePassword
Dec 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cd1136f
RUST-226 Support tlsCertificateKeyFilePassword when using rustls
abr-egn 76496b2
fix features
abr-egn 6591c1a
oops, for real this time
abr-egn e794002
openssl support
abr-egn 71c8366
Update src/runtime/tls_openssl.rs
abr-egn 796628b
Update src/runtime/tls_openssl.rs
abr-egn 42089d8
Update src/client/options.rs
abr-egn ea8db25
clippy
abr-egn 8aa876d
msrv fix?
abr-egn 061c5a4
make it optional
abr-egn 0f85a68
unskip test
abr-egn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
openssl support
- Loading branch information
commit e79400286d414d1c34969c909688666b99ec6027
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
use crate::error::{ErrorKind, Result}; | ||
|
||
pub(crate) fn decrypt_private_key(pem_data: &[u8], password: &[u8]) -> Result<Vec<u8>> { | ||
let pems = pem::parse_many(&pem_data).map_err(|error| ErrorKind::InvalidTlsConfig { | ||
message: format!("Could not parse pemfile: {}", error), | ||
})?; | ||
let mut iter = pems | ||
.into_iter() | ||
.filter(|pem| pem.tag() == "ENCRYPTED PRIVATE KEY"); | ||
let encrypted_bytes = match iter.next() { | ||
Some(pem) => pem.into_contents(), | ||
None => { | ||
return Err(ErrorKind::InvalidTlsConfig { | ||
message: "No encrypted private keys found".into(), | ||
} | ||
.into()) | ||
} | ||
}; | ||
let encrypted_key = pkcs8::EncryptedPrivateKeyInfo::try_from(encrypted_bytes.as_slice()) | ||
.map_err(|error| ErrorKind::InvalidTlsConfig { | ||
message: format!("Invalid encrypted private key: {}", error), | ||
})?; | ||
let decrypted_key = | ||
encrypted_key | ||
.decrypt(password) | ||
.map_err(|error| ErrorKind::InvalidTlsConfig { | ||
message: format!("Failed to decrypt private key: {}", error), | ||
})?; | ||
Ok(decrypted_key.as_bytes().to_vec()) | ||
} |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.