19 Commits
Author SHA1 Message Date
mohammadmseet-hue d37c95e27d pkcs12: limit PBKDF iteration count to prevent CPU exhaustion
The PKCS#12 PBKDF iteration count is read directly from
the input file with no upper bound. A crafted 83-byte .p12
file can set iterations to 2^31-1 (2147483647), causing
Decode() to block a CPU core permanently.

This change adds a maximum iteration limit of 1000000 in
both verifyMac and pbDecrypterFor. Any file that specifies
more iterations than this cap is rejected with an error.

For reference, OpenSSL caps PBKDF2 at 10000000 iterations,
and scrypt is bounded by its memory-hardness parameters.
The 1000000 limit is generous for legitimate PKCS#12 files
while still preventing denial of service.

Fixes golang/go#78524

Change-Id: I1d12d6f5d90e347ca0dc113678abc51b0cff8d85
GitHub-Last-Rev: a0370d492dd4735cc7c1bb082b359ad79863fdae
GitHub-Pull-Request: golang/crypto#343
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/759900
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-06-04 06:58:05 -07:00
Filippo Valsorda 8c9ba31836 all: freeze and deprecate more packages
Fixes golang/go#65250

Change-Id: I6a6a6964a2c87e529be50dd67fec462483b07b75
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/701535
Reviewed-by: Mark Freeman <markfreeman@google.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-09-09 12:19:31 -07:00
cuishuang 4a75ba54c2 all: make function and struct comments match the names
Change-Id: Iba9c1fc2895adca0d3455f8068b040d0ca006408
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/639575
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2025-01-02 08:15:46 -08:00
Alexander Yastrebov a3485e1740 all: use math/bits.RotateLeft
Updates golang/go#31456

Change-Id: Idf043a25632526baa190bf42ed360cb79f85e493
GitHub-Last-Rev: 59461578926a85a87cc68dac96c0b7559766b7cf
GitHub-Pull-Request: golang/crypto#195
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/356518
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2022-10-24 17:35:37 +00:00
cui fliter 4161e89ecf all: replace bytes.Compare with bytes.Equal
Change-Id: I911366b91ff2a1d02d7de202a166d876fb873142
GitHub-Last-Rev: f50e00376856fb9da36bb98ed0cdfd96c2f3b304
GitHub-Pull-Request: golang/crypto#233
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/438536
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-05 02:52:14 +00:00
chronologos 948cd5f358 pkcs12: drop PKCS#12 attributes with unknown OIDs
Looking at our own use case as well as people running into the same issue
[1][2], it seems like users usually don't care about decoding unknown
PKCS12Attributes.

[1]: https://github.com/golang/go/issues/24325
[2]: https://github.com/SSLMate/go-pkcs12/pull/4

Fixes golang/go#24325

Change-Id: I4f3700d2551af6dac215c49dd179ce46c4b2a9db
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/241281
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-07-09 23:00:13 +00:00
Filippo Valsorda ab33eee955 pkcs12: document that we use the wrong PEM type
Fixes golang/go#28018

Change-Id: I2daf99789328ef476de834c3cc703e01b468b3ee
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/241337
Reviewed-by: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-07-07 23:50:45 +00:00
Lars Lehtonen bd318be043 pkcs12: fix dropped error
This fixes a dropped error in Decode().

Change-Id: Iae5cac72f63a80dd5230034a3cfe1d6e76cc3415
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/205421
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-08 23:40:33 +00:00
Filippo Valsorda 9c16a0384b pkcs12: add a note suggesting ToPEM for multiple certificates/keys
Updates golang/go#14015

Change-Id: Iffe73540c5d74e4b3d0664035a1bdce5b47663ee
Reviewed-on: https://go-review.googlesource.com/c/160258
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-01-31 18:23:23 +00:00
Filippo Valsorda ccddf3741a pkcs12: note that this package is frozen and point to an alternative
Change-Id: Ia4d87b816f176194cd9e37efb42e273d678a84b7
Reviewed-on: https://go-review.googlesource.com/c/160259
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-29 21:01:02 +00:00
Filippo Valsorda 54b0dbbbf4 Revert "pkcs12: add a DecodeAll method"
This reverts commit bf88e3f4ba.

Reason for revert: https://go-review.googlesource.com/c/crypto/+/105876/12#message-0dad31af2b487e895ee6926ded82f85ac81c74f8

Updates golang/go#14015

Change-Id: I8eb3ed73f78ac11841ad73435bba00a330d59b58
Reviewed-on: https://go-review.googlesource.com/c/160257
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-29 20:08:51 +00:00
Julien Kauffmann bf88e3f4ba pkcs12: add a DecodeAll method
Addition of a DecodeAll function as it was mentioned in #14015.

This solves a need many people seem to have, where there is no effective
way loading PKCS12 files that contain more than one certificate and one
private key.

The utility functions used by Decode are all internal, which makes
implementing this on the user-side tedious, hence the suggestion of
providing a more liberal version of the function: DecodeAll.

Fixes golang/go#14015

Change-Id: I03c541553b6cb488c2c59d39575342a43136e592
GitHub-Last-Rev: 05f6847ff80ca34c92a01a688c7b81e874af3009
GitHub-Pull-Request: golang/crypto#38
Reviewed-on: https://go-review.googlesource.com/c/105876
Reviewed-by: Adam Shannon <adamkshannon@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-29 17:05:51 +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
namusyaka b0c9c05bfe all: fix article typos
a -> an

Change-Id: I95a940df64cb825887b75a80eadc822095b49781
Reviewed-on: https://go-review.googlesource.com/63991
Run-TryBot: Alex Vaghin <ddos@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Vaghin <ddos@google.com>
2017-09-15 13:46:28 +00:00
Kevin Burke 5ef0053f77 all: use HTTPS for links that support it
Many websites now support HTTPS that may not at the time the code was
committed; let's use the HTTPS links where we can.

Change-Id: I7099dfa0dbb213294e65b4387f343d6e8f955b97
Reviewed-on: https://go-review.googlesource.com/47131
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-29 04:21:55 +00:00
Fredrik Forsmo 459e265272 pkcs12: fix ToPEM to not ignore non-nil error from getSafeContents
Fixes golang/go#19542

Change-Id: I60d2370d1d1e0763c72c9cc203ea2ff21123af73
Reviewed-on: https://go-review.googlesource.com/38261
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-03-17 16:37:34 +00:00
Brad Fitzpatrick f23ba3a5ee x/crypto/pkcs12: fix typo in struct tag
No test, though, because I don't know this code. Sad that it passes
with the typo, though.

Fixes golang/go#13855

Change-Id: I1170baa0f94ae4b671f5ca654cb7dcc393d1cc4d
Reviewed-on: https://go-review.googlesource.com/18363
Reviewed-by: Adam Langley <agl@golang.org>
2016-01-07 16:18:51 +00:00
Cedric Staub 575fdbe86e x/crypto/pkcs12: deal with short byte array in PBKDF
A bug in the PBKDF implementation in the pkcs12 package caused certain
inputs to produce the wrong output. In step 6C, we treat Ij as a big.Int
of v bytes and compute Ij + B + 1. The resulting big.Int can have
leading zero bytes, such that Ij.Bytes() produces a byte array that is
smaller than v bytes. In this case we must zero-pad the output to make
Ijb properly sized.

Change-Id: I6e672e6f6bbbd5bea419355d318db289731bb174
Reviewed-on: https://go-review.googlesource.com/16520
Reviewed-by: Adam Langley <agl@golang.org>
2015-11-02 18:45:47 +00:00
Paul Meyer c8b9e6388e x/crypto: Add pkcs12 package for reading pkcs12 data
Package pkcs12 provides some Go implementations of PKCS#12.
This implementation is distilled from https://tools.ietf.org/html/rfc7292 and
referenced documents. It is intented for decoding P12/PFX-stored certificate+key
for use with the crypto/tls package.

Package includes @dgryski's RC2 implementation as a sub package as requested in
https://github.com/golang/go/issues/10621.

Change-Id: I78401241e39cd0099e9082a3a227cf0a3a36e6d1
Reviewed-on: https://go-review.googlesource.com/11986
Reviewed-by: Adam Langley <agl@golang.org>
Run-TryBot: Adam Langley <agl@golang.org>
2015-10-04 18:58:11 +00:00