-
Notifications
You must be signed in to change notification settings - Fork 292
CA-398341: Populate fingerprints of CA certificates on startup #6006
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 all commits
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 |
---|---|---|
|
@@ -904,6 +904,67 @@ let upgrade_update_guidance = | |
) | ||
} | ||
|
||
let upgrade_ca_fingerprints = | ||
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 dead code until you add the new function to the |
||
{ | ||
description= "Upgrade the fingerprint fields for ca certificates" | ||
; version= (fun x -> x < (5, 783)) | ||
; (* the version where we started updating missing fingerprint_sha256 | ||
and fingerprint_sha1 fields for ca certs *) | ||
fn= | ||
(fun ~__context -> | ||
let expr = | ||
let open Xapi_database.Db_filter_types in | ||
And | ||
( Or | ||
( Eq (Field "fingerprint_sha256", Literal "") | ||
, Eq (Field "fingerprint_sha1", Literal "") | ||
) | ||
, Eq (Field "type", Literal "ca") | ||
) | ||
in | ||
let empty = Db.Certificate.get_records_where ~__context ~expr in | ||
List.iter | ||
(fun (self, record) -> | ||
let read_fingerprints filename = | ||
let ( let* ) = Result.bind in | ||
try | ||
let* certificate = | ||
Xapi_stdext_unix.Unixext.string_of_file filename | ||
|> Cstruct.of_string | ||
|> X509.Certificate.decode_pem | ||
in | ||
let sha1 = | ||
Certificates.pp_fingerprint ~hash_type:`SHA1 certificate | ||
in | ||
let sha256 = | ||
Certificates.pp_fingerprint ~hash_type:`SHA256 certificate | ||
in | ||
Ok (sha1, sha256) | ||
with | ||
| Unix.Unix_error (Unix.ENOENT, _, _) -> | ||
Error | ||
(`Msg (Printf.sprintf "filename %s does not exist" filename)) | ||
| exn -> | ||
Error (`Msg (Printexc.to_string exn)) | ||
in | ||
let filename = | ||
Filename.concat | ||
!Xapi_globs.trusted_certs_dir | ||
record.API.certificate_name | ||
in | ||
match read_fingerprints filename with | ||
| Ok (sha1, sha256) -> | ||
Db.Certificate.set_fingerprint_sha1 ~__context ~self ~value:sha1 ; | ||
Db.Certificate.set_fingerprint_sha256 ~__context ~self | ||
~value:sha256 | ||
| Error (`Msg msg) -> | ||
D.info "%s: ignoring error when reading CA certificate %s: %s" | ||
__FUNCTION__ record.API.certificate_name msg | ||
) | ||
empty | ||
) | ||
} | ||
|
||
let rules = | ||
[ | ||
upgrade_domain_type | ||
|
@@ -933,6 +994,7 @@ let rules = | |
; remove_legacy_ssl_support | ||
; empty_pool_uefi_certificates | ||
; upgrade_update_guidance | ||
; upgrade_ca_fingerprints | ||
] | ||
|
||
(* Maybe upgrade most recent db *) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1432,12 +1432,12 @@ let certificate_install ~__context ~name ~cert = | |
|
||
let install_ca_certificate = certificate_install | ||
|
||
let certificate_uninstall ~__context ~name = | ||
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. Trying to understand how the legacy names work. Why is the legacy name "certificate_uninstall" still needed (here and in message_forwarding.ml and datamodel_pool.ml if the deprecated xe command doesn't even use it? It calls pool_install_ca_certificate which calls uninstall_ca_certificate, not certificate_uninstall. What is it providing compatibility with, is this for upgrades from much older xapis? 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. API clients might still use this function, this is why it needs to be kept. |
||
let uninstall_ca_certificate ~__context ~name ~force = | ||
let open Certificates in | ||
pool_uninstall CA_Certificate ~__context ~name ; | ||
pool_uninstall CA_Certificate ~__context ~name ~force ; | ||
Db_util.remove_ca_cert_by_name ~__context name | ||
|
||
let uninstall_ca_certificate = certificate_uninstall | ||
let certificate_uninstall = uninstall_ca_certificate ~force:false | ||
psafont marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let certificate_list ~__context = | ||
let open Certificates in | ||
|
@@ -1446,7 +1446,7 @@ let certificate_list ~__context = | |
|
||
let crl_install = Certificates.(pool_install CRL) | ||
|
||
let crl_uninstall = Certificates.(pool_uninstall CRL) | ||
let crl_uninstall = Certificates.(pool_uninstall CRL ~force:false) | ||
|
||
let crl_list ~__context = Certificates.(local_list CRL) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.