]> Cypherpunks.ru repositories - gostls13.git/commit
crypto/x509: fix certificate policy marshaling
authorRoland Shoemaker <roland@golang.org>
Thu, 2 Nov 2023 17:04:21 +0000 (10:04 -0700)
committerRoland Shoemaker <roland@golang.org>
Fri, 3 Nov 2023 15:20:32 +0000 (15:20 +0000)
commite2d9574b14b3db044331da0c6fadeb62315c644a
tree7e0514a265918cd9c14b689b40ccc36065fbd263
parent1764da77c2562061533922f9f6354e53d37ebdbc
crypto/x509: fix certificate policy marshaling

CL 520535 added the new OID type, and the Certificate field Policies to
replace PolicyIdentifiers. During review I missed three problems: (1)
the marshaling of Certificate didn't take into account the case where
both fields were populated with the same OIDs (which would be the case
if you parsed a certificate and used it as a template), (2)
buildCertExtensions only generated the certificate policies extension if
PolicyIdentifiers was populated, and (3) how we would marshal an empty
OID (i.e. OID{}).

This change makes marshaling a certificate with an empty OID an error,
and only adds a single copy of any OID that appears in both Policies and
PolicyIdentifiers to the certificate policies extension. This should
make the round trip behavior for certificates reasonable.

Additionally this change documents that CreateCertificate uses the
Policies field from the template, and fixes buildCertExtensions to
populate the certificate policies extension if _either_
PolicyIdentifiers or Policies is populated, not just PolicyIdentifiers.

Fixes #63909

Change-Id: I0fcbd3ceaab7a376e7e991ff8b37e2145ffb4a61
Reviewed-on: https://go-review.googlesource.com/c/go/+/539297
Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/crypto/x509/x509.go
src/crypto/x509/x509_test.go