Skip to content

Commit be8e7b3

Browse files
authored
CP-307865 accept SHA512 for custom server certs (#6467)
A user can install server certificates to secure the connection between xapi and their API clients. So far we demanded SHA256 certificates. Accept SHA512 in addition. The patch renames the predicate to no longer imply that we only accept SHA256. Tested this: ``` openssl req -x509 -sha512 -nodes -days 365 -newkey rsa:2048 -keyout mycert.key -out mycert.crt -subj "/CN=localhost" xe host-server-certificate-install certificate=mycert.crt private-key=mycert.key ```
2 parents a841d38 + 44031b5 commit be8e7b3

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

ocaml/gencert/lib.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ let validate_pem_chain ~pem_leaf ~pem_chain now private_key =
9393
| _ ->
9494
Error (`Msg (server_certificate_key_mismatch, []))
9595
in
96-
let ensure_sha256_signature_algorithm certificate =
96+
let ensure_signature_algorithm certificate =
9797
match X509.Certificate.signature_algorithm certificate with
98-
| Some (_, `SHA256) ->
98+
| Some (_, (`SHA256 | `SHA512)) ->
9999
Ok certificate
100100
| _ ->
101101
Error (`Msg (server_certificate_signature_not_supported, []))
@@ -116,7 +116,7 @@ let validate_pem_chain ~pem_leaf ~pem_chain now private_key =
116116
~error_not_yet:server_certificate_not_valid_yet
117117
~error_expired:server_certificate_expired
118118
>>= ensure_keys_match private_key
119-
>>= ensure_sha256_signature_algorithm
119+
>>= ensure_signature_algorithm
120120
>>= fun cert ->
121121
match Option.map validate_chain pem_chain with
122122
| None ->

ocaml/gencert/test_lib.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ let valid_leaf_certificates =
5050
, "2020-02-01T00:00:00Z"
5151
, `SHA256
5252
)
53+
; ( "Valid, SHA512, matches key"
54+
, "pkey_rsa_2048"
55+
, "2020-02-01T00:00:00Z"
56+
, `SHA512
57+
)
5358
]
5459

5560
(* ( description, leaf_private_key, expected_private_key, time_of_validation,
@@ -80,6 +85,14 @@ let invalid_leaf_certificates =
8085
, server_certificate_key_mismatch
8186
, []
8287
)
88+
; ( "Valid, SHA512, keys do not match"
89+
, "pkey_rsa_2048"
90+
, "pkey_rsa_4096"
91+
, "2020-02-01T00:00:00Z"
92+
, `SHA512
93+
, server_certificate_key_mismatch
94+
, []
95+
)
8396
; ( "Valid, SHA1, matching keys"
8497
, "pkey_rsa_2048"
8598
, "pkey_rsa_2048"

ocaml/idl/datamodel_errors.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,8 +1708,8 @@ let _ =
17081708
~doc:"The provided certificate has expired." () ;
17091709
error Api_errors.server_certificate_signature_not_supported []
17101710
~doc:
1711-
"The provided certificate is not using the SHA256 (SHA2) signature \
1712-
algorithm."
1711+
"The provided certificate is not using one of the following SHA2 \
1712+
signature algorithms: SHA256, SHA512."
17131713
() ;
17141714

17151715
error Api_errors.server_certificate_chain_invalid []

0 commit comments

Comments
 (0)