Commit Graph
40 Commits
Author SHA1 Message Date
Brad Fitzpatrick f2135b814c all: clean up minor issues found by staticcheck
Use bytes.Equal instead of comparing bytes.Compare results to zero,
avoid Yoda conditions, drop a redundant zero slice capacity, use
strings.ReplaceAll, build acme error strings with a strings.Builder,
and lowercase an error string in ocsp. No behavior changes.

Change-Id: I5d2b3fa5c241adc75e61be0f2d2d7af1eb9e8d66
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/803200
Reviewed-by: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2026-07-21 14:30:59 -07:00
Daniel McCarney 243e02a382 ocsp: update ParseRequest docs & error conditions
ParseRequest was documented as erroring for inputs that contained
an optional request signature, and as only supporting requests for
a single certificate.

However, prior to this commit DER inputs that contained a signature
succeeded without verifying the signature, and inputs that contained
multiple certificate identifiers succeeded but only the first
certificate identifier was unmarshalled.

This commit updates the function behaviour to return an error for the
signature case as described in the docs, and to clarify the
documentation for inputs with multiple certificate identifiers.

Fixes golang/go#80300

Change-Id: I7446422d6c98bd406b8c43e55fea9a16ace9d4a6
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/798220
Reviewed-by: Roland Shoemaker <roland@golang.org>
Auto-Submit: Daniel McCarney <daniel@binaryparadox.net>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
2026-07-09 11:40:58 -07:00
Filippo Valsorda a6a393ffd6 all: bump go.mod version and drop compatibility shims
Also, remove the legacy import annotations.

Fixes golang/go#68147

Change-Id: Ibfcc9322f27224c0ba92ea42cd56912a7d8783fd
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/594256
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2024-06-26 15:12:35 +00:00
Brad Fitzpatrick 5bead598a0 ocsp: don't use iota for externally defined constants
Style fix: iota shouldn't be used for values that come from RFCs or
things that go over the wire or to disk.

Change-Id: Ib903ec1bce7e71ff81094db3de8d0b71e16f52f3
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/564695
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2024-02-18 02:21:00 +00:00
Dmitri Shuralyov 8779cbd1c9 all: update go directive to 1.18
Done with:

go get go@1.18
go mod tidy
go fix ./...

Using go1.21.3.

Also update avo to v0.5.0 in the curve25519/internal/field/_asm module.
It's newer and produces no diff in the generated code.

For golang/go#60268.

Change-Id: I9bd771ee8561595d7f68aaca76df6e3e33d35013
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/534141
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-10-11 22:02:22 +00:00
Roland Shoemaker ae2d96664a ocsp: add Response.Raw
Fixes golang/go#38340

Change-Id: I77afc901584ac3361eafa13c9ee9f8cf9ec2ee28
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/389256
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2022-03-31 22:09:35 +00:00
Dan Kortschak bba287dce9 ocsp: fix typo
Change-Id: Icd770cee9ce183f75c49c301f96a4aab73e80303
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/381674
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
2022-02-08 23:39:18 +00:00
Roland Shoemaker ceb1ce70b4 ocsp: rewrite tests that rely on SHA1-RSA
This test suite should really be completely re-written, but for now
we can just substitute the tests which relied on certificates that
were signed with SHA1-RSA.

Fixes #49443

Change-Id: Ibe4ae3b3062956a56e6e3579144312747df3ef9a
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/362334
Trust: Roland Shoemaker <roland@golang.org>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Katie Hockman <katie@golang.org>
2021-11-08 22:10:36 +00:00
Russ Cox 5ea612d1eb all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: I70526bf588bf4078887e567795867ece785d666b
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/294415
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-20 03:31:48 +00:00
Roland Shoemaker eb9a90e9f9 ocsp: Improve documentation for ParseResponse and ParseResponseForCert
This change clarifies the behaviors of ParseResponse and ParseResponseForCert,
particularly when parsing responses that contain multiple certificate statuses.

Fixes golang/go#30651

Change-Id: Ia632c8c2a69d1b0c17d71f9f9dcb59ddb0be401b
GitHub-Last-Rev: 481f613438c91521fd90078cc0915cf01cf44b4e
GitHub-Pull-Request: golang/crypto#122
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/220353
Reviewed-by: Katie Hockman <katie@golang.org>
Trust: Roland Shoemaker <roland@golang.org>
2020-10-01 19:37:50 +00:00
Michael Cook b8fe1690c6 all: fix ineffectual assignments
audited using ineffassign tool from
github.com/gordonklaus/ineffassign
go generate does not generate any changes

Change-Id: Iabbec9ec1aae39081289d503d79fd7b4caadf17b
GitHub-Last-Rev: acd17cce410e9c68ce3c87b5546261be9153e3ea
GitHub-Pull-Request: golang/crypto#70
Reviewed-on: https://go-review.googlesource.com/c/155942
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-01-31 18:25:04 +00:00
Igor Zhilianin 45a5f77698 all: fix typos
Change-Id: I62cbcfcd0be5f6a74d93b85b24ff7607533bb239
GitHub-Last-Rev: 9967869e706e9fe7d13964bb32b30a44ba640869
GitHub-Pull-Request: golang/crypto#64
Reviewed-on: https://go-review.googlesource.com/c/145240
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-29 02:12:03 +00:00
Joe Shaw 80f0338f9e ocsp: remove error for > 1 certificate in response
Some OCSP responders contain more than one certificate, which can be
used to "help the OCSP client verify the responders signature" (RFC
6960 section 4.2.1).  This client doesn't do verification of the chain
to the root, but it's not an error for a responder to send more than
one.

Fixes golang/go#21527

Change-Id: Ie23cfcb347a4f7cdfb1a0cbad2aa03a1242553af
Reviewed-on: https://go-review.googlesource.com/57510
Reviewed-by: Adam Langley <agl@golang.org>
2018-05-01 15:29:04 +00:00
Kevin Burke 94eea52f7b all: run gofmt -s on source code
Per the description, the "-s" file issues slight simplifications to
the source code.

Change-Id: I77395d763f5eafb48653902dcedfa56b150b2d67
Reviewed-on: https://go-review.googlesource.com/80138
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-28 19:40:09 +00:00
Tobias Klauser ca1fcd4ab4 ocsp: fix vet format string issues
Fix the following format string issues reported by go vet:

  ocsp_test.go:46: Errorf format %d has arg resp.ThisUpdate of wrong type time.Time
  ocsp_test.go:50: Errorf format %d has arg resp.NextUpdate of wrong type time.Time
  ocsp_test.go:271: Errorf format %d has arg resp.ThisUpdate of wrong type time.Time
  ocsp_test.go:275: Errorf format %d has arg resp.NextUpdate of wrong type time.Time
  ocsp_test.go:279: Errorf format %d has arg resp.RevokedAt of wrong type time.Time

Change-Id: I3b516bb216424ad1777acfc27b11dc1b2d78836a
Reviewed-on: https://go-review.googlesource.com/76130
Reviewed-by: Filippo Valsorda <hi@filippo.io>
2017-11-05 17:27:39 +00:00
Anmol Sethi edd5e9b087 ocsp: remove incorrect iota and update docs on CreateRequest
Change-Id: Ib347b468035d699156b6bff6c30fb653a1c5804d
Reviewed-on: https://go-review.googlesource.com/71755
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2017-10-21 00:14:04 +00:00
Martin Kreichgauer dd85ac7e6a ocsp: remove a redundant conditional expression from an if statement
cert can never be nil here. The statement was incorrectly moved in
e1a4589.

Change-Id: I1fb2aa0bb26a2ad21e6f070952365233fb39a216
Reviewed-on: https://go-review.googlesource.com/48070
Reviewed-by: Adam Langley <agl@golang.org>
2017-07-11 14:53:18 +00:00
Martin Kreichgauer e1a4589e7d ocsp: enhance errors for responses without a matching SingleResponse
ParseResponseForCert would previously complain about an invalid hash OID
if the response contained no SingleResponse matching the certificate
provided by the caller.

Fixes golang/go#19540

Change-Id: I0354c4048707a788ed3d184cc88b4f13f65544ba
Reviewed-on: https://go-review.googlesource.com/44005
Reviewed-by: Adam Langley <agl@golang.org>
2017-06-01 17:31:14 +00:00
Adam Langley dd96d35c1b ocsp: fix test flakiness
The test was assuming that the OCSP creation wouldn't cross a minute
boundary, which is flakey nonsense. Instead assert that the timestamp in
the OCSP response is within an hour of when we check it.

Change-Id: I3c822b738e9b04385319eb29a1cd275dc2ed112e
Reviewed-on: https://go-review.googlesource.com/36648
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-09 19:00:49 +00:00
Martin Kreichgauer f5719d2458 ocsp: Expose ResponderID in parsed Response.
ResponderID is unmarshalled into either ResponderName or
ResponderKeyHash depending on which one is present.

Fixes golang/go#14971.

Change-Id: I5ba602753d81835da531321e94898408395068dd
Reviewed-on: https://go-review.googlesource.com/34380
Reviewed-by: Adam Langley <agl@golang.org>
2016-12-21 17:16:36 +00:00
Roland Shoemaker b07d8c9677 x/crypto/ocsp: Don't hard-code OCSP response hash function
Allows user to set the hash function to use in the OCSP response
when using ocsp.CreateResponse instead of hard-coding the use of
SHA-1. The field IssuerHash is added to the ocsp.Response struct
to set which hash to use. If none is provided CreateResponse falls
back to SHA1. ParseResponse also attempts to populate this field
and will fail if a unsupported hash algorithm is provided.

Change-Id: I3905b1706f347387724e57c33cb82a3b46ffcdf9
Reviewed-on: https://go-review.googlesource.com/32214
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-12-08 20:19:12 +00:00
Paul van Brouwershaven d172538b2c x/crypto/ocsp: Accept status for multiple certificates in response
This change add a function select to correct response from a responder
that includes multiple certificates in the case the server uses response
pre-generation.

RFC6960 section 4.2.2 states:

"The response MUST include a SingleResponse for each certificate in
   the request.  The response SHOULD NOT include any additional
   SingleResponse elements, but, for example, OCSP responders that
   pre-generate status responses might include additional SingleResponse
   elements if necessary to improve response pre-generation performance
   or cache efficiency (according to [RFC5019], Section 2.2.1)."

Change-Id: I39eeaa3daf16a7d7eb030e34229f16cf4295f9d7
Reviewed-on: https://go-review.googlesource.com/10611
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-06 17:47:01 +00:00
Roland Shoemaker 0e69e08b8a ocsp: add Request.Marshal method
Tests that Marshaling a parsed response
returns the same bytes as were parsed.

Use Marshal in CreateRequest;
still passes CreateRequest's golden test.

Change-Id: I427ef8372d7b62c43b7718d7d90631d022377d32
Reviewed-on: https://go-review.googlesource.com/19488
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-06 17:46:04 +00:00
Fedor Indutny 2c99acdd1e ocsp: fix default value of Version in ResponseData
ASN.1 specification of `ResponseData` is:

    ResponseData ::= SEQUENCE {
          version              [0] EXPLICIT Version DEFAULT v1,
          responderID              ResponderID,
          producedAt               GeneralizedTime,
          responses                SEQUENCE OF SingleResponse,
          responseExtensions   [1] EXPLICIT Extensions OPTIONAL }

Where `Version` is:

    Version ::= INTEGER { v1(0) }

Invalid default value results in a presence of a field that otherwise
should not be present.

See: https://github.com/openssl/openssl/issues/1297
Fixes: golang/#16321

Change-Id: Ibb065a67624e1877cfbe62e0483d781d783f74f0
Reviewed-on: https://go-review.googlesource.com/24841
Reviewed-by: Adam Langley <agl@golang.org>
2016-07-11 18:24:12 +00:00
Martin Hamrle 077efaa604 x/crypto: fix typos
The typos were found by misspell tool.

Change-Id: I120740f12f7ba48330749ebf84050a7b98e01016
Reviewed-on: https://go-review.googlesource.com/24725
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2016-07-06 16:40:51 +00:00
Adam Langley de93d05161 x/crypto/ocsp: correct OID for DSA-with-SHA-256.
This was incorrect in crypto/x509 and go copied here.
See https://go-review.googlesource.com/#/c/20549 for the fix to
crypto/x509.

Fixes golang/go#14663.

Change-Id: I1fdca4b3f3edfeef1ee4ae01b1cf252ad8471163
Reviewed-on: https://go-review.googlesource.com/20550
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-10 23:43:30 +00:00
Adam Langley 1f22c01038 x/crypto/ocsp: return errors to reflect OCSP errors.
Previously, OCSP errors (like “malformed request”, not “that certificate
is revoked”) were intended to result in a Response being returned with
Status set to ServerFailed. However, since an “optional” tag was missing
in the ASN.1, a parse error was actually returned.

This CL changes that behaviour so that ParseResponse will now return an
error for these responses. That error will be a ResponseError, allowing
callers to find the exact error code.

Change-Id: I4f8ae5ba39203c2c204fb1d65471d1427bf68b25
Reviewed-on: https://go-review.googlesource.com/18944
Reviewed-by: Adam Langley <agl@golang.org>
2016-01-26 18:40:38 +00:00
Richard Barnes 552e9d568f ocsp: add support for OCSP response extensions
Some current uses of OCSP require extensions. In particular, Certificate
Transparency (RFC 6962) can use an OCSP extension to carry a Signed
Certificate Timestamp. This patch adds support for OCSP extensions (in
particular, singleExtensions), by adding Extensions and ExtraExtensions
fields with the same semantics as in x509.Certificate.

As a side-effect, trying to parse a response with a critical extension
will now return an error, just like parsing a certificate.

This change does not enable extensions in OCSP requests, just responses.

Change-Id: I5918f26ea1bb9d1ece96e85a6bb7691c7c017467
Reviewed-on: https://go-review.googlesource.com/18202
Reviewed-by: Adam Langley <agl@golang.org>
2016-01-04 21:17:08 +00:00
Richard Barnes 287a1d87db ocsp: use asn1.Enumerated for revocation reason
In the initial patch enabling generation of OCSP responses, the Reason
field in the revokedInfo struct used for serializing responses was set
to type int. That type maps to the ASN.1 type INTEGER, not ENUMERATED,
as required by RFC 6960. As a result, if you serialize an OCSP
resonse with the Reason field populated, then it will be rejected as
malformed by compliant OCSP parsers.

This patch changes the type of the Reason field in revokedInfo to
asn1.Enumerated. It leaves the RevocationReason field in the public
Response struct as int, and converts between the two.  The patch
also adds constant for the defined revocation reasons.

Change-Id: I97205319503f447cde12d9a0bb0bd1a8db7a66ee
Reviewed-on: https://go-review.googlesource.com/13964
Reviewed-by: Adam Langley <agl@golang.org>
2015-08-29 18:47:43 +00:00
Richard Barnes 173ce04bfa ocsp: Remove "explicit" tag from "revokedInfo"
The current implementation is not compliant with the ASN.1 structure
for an OCSP response in RFC 6960. In the RFC, the "revoked" field is
marked "implicit". The "explicit" tag in the current struct causes
the encoder to emit an additional SEQUENCE, which cases some parsers
(notably OpenSSL) to reject OCSP responses as malformed.  This patch
simply removes the "explicit" tag, so that the emitted DER is
compliant with the RFC.

Change-Id: Ifa65a73a8d24f08fe3c2794309df772edc8bb114
Reviewed-on: https://go-review.googlesource.com/13572
Reviewed-by: Adam Langley <agl@golang.org>
2015-08-12 10:57:53 +00:00
Richard Barnes 5b330e8ba0 ocsp: pre-serialized responses and improved ASN.1
OCSP responders sometimes rely on pre-generated responses to increase
performance. In such cases, RFC 5019 allows responders to respond with
responseStatus unauthorized if they do not have a pre-generated response for
a certificate. This patch provides a pre-serialized unauthorized response.

This change also updates the serialization of OCSP responses so that the
resulting DER encoding is compatible with other parsers.

Note: This change depends on updates to encoding/asn1 to improve handling
of flags and time values.

https://go-review.googlesource.com/#/c/5970/

Change-Id: I77e042de6535a70b0996e058cb38a00076a16dd4
Reviewed-on: https://go-review.googlesource.com/4121
Reviewed-by: Adam Langley <agl@golang.org>
2015-05-30 20:13:26 +00:00
Shenghou Ma ce6bda6918 ocsp: fix test on TZ=UTC systems
If the system is using UTC, then time.Now().loc != time.UTC().loc,
so it should not use reflect.DeepEqual to compare two times.

While we're here, also fix some copy-paste errors.

Change-Id: I1fef5f22f5b5eb978746d2695a1b43f153e4a408
Reviewed-on: https://go-review.googlesource.com/10335
Reviewed-by: Adam Langley <agl@golang.org>
2015-05-26 16:42:54 +00:00
Richard Barnes f7445b17d6 ocsp: Add server-side OCSP processing
The current content of the ocsp module is focused on the processing needed to implement an OCSP client: it only implements request generation and response parsing.

This change adds response generation and request parsing.

Change-Id: Idf6f4e69af504520f2b58340734e45cd92bb3d60
Reviewed-on: https://go-review.googlesource.com/3666
Reviewed-by: Adam Langley <agl@golang.org>
2015-02-06 19:37:46 +00:00
David Symonds 1fbbd62cfe crypto: add import comments.
Change-Id: I33240faf1b8620d0cd600de661928d8e422ebdbc
Reviewed-on: https://go-review.googlesource.com/1235
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-09 23:26:36 +00:00
Adam Langley 16d76afb29 go.crypto/ocsp: pass in the issuing certificate.
Paul van Brouwershaven pointed out that it would be better to pass in
the issuing certificate and have the verification be done in the OCSP
package than to expect the caller to deal with the difference between
responses with and without a responder certificate.

R=golang-dev, dayveday, paul
CC=golang-dev
https://golang.org/cl/11220043
2013-07-29 15:32:19 -04:00
Adam Langley 3f4ad28b7c go.crypto/ocsp: make the zero value of RequestOptions valid and documented.
R=bradfitz
CC=golang-dev
https://golang.org/cl/10431044
2013-06-21 15:16:14 -04:00
Adam Langley b88b016522 go.crypto/ocsp: allow cert-less responses and support making requests.
Some OCSP responses (notably COMODO's) don't use an intermediate
certificate to sign OCSP responses so this change allowed that.

Additionally, a CreateRequest function is added for creating OCSP
requests.

This change makes one API change: SerialNumber becomes a *big.Int to
match crypto/x509. The original code dates to before encoding/asn1
could cope with big.Ints and using a []byte was a workaround for that.

R=golang-dev
CC=golang-dev
https://golang.org/cl/10402043
2013-06-20 11:11:09 -04:00
Adam Langley ae4d10368a crypto/oscp: update in light of cl/5625045
R=rsc
CC=golang-dev
https://golang.org/cl/5608055
2012-02-20 10:56:33 -05:00
David Symonds 3d6f310da6 go.crypto: Update for new crypto/x509 error.
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5674046
2012-02-15 13:00:29 +11:00
Russ Cox 470549d502 go.crypto: initial code
Manual edits to README.
Moved from main Go repository, deleted Makefiles, ran gofix -r go1rename.

Tested with: go test code.google.com/p/go.crypto/...

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5564059
2012-01-25 15:31:12 -05:00