Fix to handle bad or unreadable .pem keys
This commit is contained in:
parent
4bd0de2e8d
commit
29df4f4b64
|
@ -188,9 +188,9 @@ fn auth_handler(req: Request<Body>) -> Response<Body> {
|
|||
Response::new(Body::from(format!("BasicAuthentication {:?}", user)))
|
||||
}
|
||||
|
||||
fn jwk_from_pem(file_path: &Path) -> Result<JWK<Empty>, io::Error> {
|
||||
fn jwk_from_pem(file_path: &Path) -> Result<JWK<Empty>, Box<dyn std::error::Error + 'static>> {
|
||||
let key_bytes = fs::read(file_path)?;
|
||||
let rsa = Rsa::private_key_from_pem(key_bytes.as_slice()).unwrap();
|
||||
let rsa = Rsa::private_key_from_pem(key_bytes.as_slice())?;
|
||||
Ok(JWK {
|
||||
common: CommonParameters {
|
||||
algorithm: Some(Algorithm::Signature(SignatureAlgorithm::RS256)),
|
||||
|
@ -219,7 +219,10 @@ fn get_keys(_req: Request<Body>) -> Response<Body> {
|
|||
None => return None,
|
||||
};
|
||||
match ext.as_ref() {
|
||||
"pem" => Some(jwk_from_pem(path.as_path()).unwrap()),
|
||||
"pem" => match jwk_from_pem(path.as_path()) {
|
||||
Ok(jwk) => Some(jwk),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue