1
0
mirror of https://github.com/golang/go synced 2024-11-08 06:46:16 -07:00
Commit Graph

777 Commits

Author SHA1 Message Date
Katie Hockman
6f3a9515b6 crypto/x509: generate SubjectKeyId for CAs
Fixes #26676

Change-Id: I5bc91d4a8161bc6ff25effcf93f551f735fef115
Reviewed-on: https://go-review.googlesource.com/c/go/+/227098
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-04-13 20:22:26 +00:00
Katie Hockman
614a713be5 crypto/tls: failed tls.Conn.Write returns a permanent error
Fixes #29971

Change-Id: I2f1653640c88fafe0ec17a75dcf41d5896c4cb8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/227840
Run-TryBot: Katie Hockman <katie@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-13 17:38:02 +00:00
Austin Clements
f4827240db crypto/x509: tidy darwin/arm64 build tags
The cgo build tag is not necessary for root_darwin_arm64.go. We can't
build for darwin/arm64 without cgo, and even if we did 1) this code
would work fine 2) the no-cgo code that shells out to
/usr/bin/security would not work.

(Suggested by Filippo.)

Change-Id: I98cac2ea96ec5ac1ae60b7e32d195d5e86e2bd66
Reviewed-on: https://go-review.googlesource.com/c/go/+/227583
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-04-08 19:25:32 +00:00
Austin Clements
f7e6ab44b4 all: remove scattered remnants of darwin/arm
This removes all conditions and conditional code (that I could find)
that depended on darwin/arm.

Fixes #35439 (since that only happened on darwin/arm)
Fixes #37611.

Change-Id: Ia4c32a5a4368ed75231075832b0b5bfb1ad11986
Reviewed-on: https://go-review.googlesource.com/c/go/+/227198
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-04-08 18:35:49 +00:00
Austin Clements
da8591b61c all: remove darwin/arm build-tags and files
This removes all files that are only used on darwin/arm and cleans up
build tags in files that are still used on other platforms.

Updates #37611.

Change-Id: Ic9490cf0edfc157c6276a7ca950c1768b34a998f
Reviewed-on: https://go-review.googlesource.com/c/go/+/227197
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-04-08 18:35:43 +00:00
Xiangdong Ji
339e9c6400 crypto/sha512: optimize sha512 by removing function literal
The function 'block' called indirectly via function literal 'blockGeneric' prevents
'gc' performing an accurate escape analysis to its arguments, that will result in
unnecessary heap object allocation and GC cost.

Consistent performance improvement to sha512 and its dependency packages are
observed on various arm64 servers if eliminating the function literal, especially for
small-sized benchmarks.

A72:
========================================================================================================
name                                               old time/op    new time/op     delta
pkg:crypto/sha512 goos:linux goarch:arm64
Hash8Bytes-64                                        1.61µs ± 0%     1.37µs ± 0%   -14.99%  (p=0.000 n=8+9)
Hash1K-64                                            11.2µs ± 0%     10.9µs ± 0%    -2.41%  (p=0.000 n=8+10)
Hash8K-64                                            77.8µs ± 0%     77.5µs ± 0%    -0.44%  (p=0.002 n=10+10)
pkg:crypto/ecdsa goos:linux goarch:arm64
pkg:crypto/hmac goos:linux goarch:arm64
pkg:crypto/tls goos:linux goarch:arm64
HandshakeServer/RSA-64                                920µs ± 0%      919µs ± 0%    -0.10%  (p=0.035 n=10+9)
HandshakeServer/ECDHE-P256-RSA/TLSv13-64             1.32ms ± 1%     1.31ms ± 0%    -0.24%  (p=0.002 n=9+8)
HandshakeServer/ECDHE-P256-RSA/TLSv12-64             1.25ms ± 0%     1.25ms ± 0%    -0.07%  (p=0.040 n=9+9)
HandshakeServer/ECDHE-P256-ECDSA-P256/TLSv12-64       486µs ± 0%      485µs ± 0%    -0.19%  (p=0.000 n=9+10)
HandshakeServer/ECDHE-X25519-ECDSA-P256/TLSv13-64    1.01ms ± 0%     1.01ms ± 0%    -0.36%  (p=0.000 n=9+10)
HandshakeServer/ECDHE-X25519-ECDSA-P256/TLSv12-64     948µs ± 0%      947µs ± 0%    -0.11%  (p=0.001 n=10+10)
HandshakeServer/ECDHE-P521-ECDSA-P521/TLSv12-64      42.1ms ± 3%     42.5ms ± 2%    +0.77%  (p=0.010 n=8+8)
Throughput/MaxPacket/8MB/TLSv13-64                   46.9ms ± 9%     42.8ms ± 2%    -8.71%  (p=0.000 n=10+9)
Throughput/MaxPacket/64MB/TLSv13-64                   385ms ±17%      332ms ±18%   -13.64%  (p=0.002 n=10+10)
Throughput/DynamicPacket/2MB/TLSv12-64              39.1ms ±110%     17.2ms ±24%   -55.97%  (p=0.002 n=10+9)
Throughput/DynamicPacket/4MB/TLSv12-64               32.2ms ±22%     27.2ms ±40%   -15.69%  (p=0.029 n=10+10)
Throughput/DynamicPacket/4MB/TLSv13-64               27.4ms ±18%     24.9ms ±31%    -9.12%  (p=0.031 n=9+9)
Throughput/DynamicPacket/8MB/TLSv12-64               61.8ms ±32%     43.9ms ±18%   -28.93%  (p=0.000 n=10+9)
Throughput/DynamicPacket/8MB/TLSv13-64               49.4ms ±14%     45.7ms ±19%    -7.44%  (p=0.035 n=10+10)
Throughput/DynamicPacket/32MB/TLSv13-64               181ms ±13%      163ms ± 7%   -10.17%  (p=0.001 n=9+10)
Latency/MaxPacket/5000kbps/TLSv13-64                 37.2ms ±52%     30.8ms ± 0%   -17.21%  (p=0.017 n=10+9)
Latency/DynamicPacket/2000kbps/TLSv13-64             16.7ms ± 1%     16.6ms ± 0%    -0.39%  (p=0.002 n=8+10)
pkg:crypto/ed25519 goos:linux goarch:arm64
KeyGeneration-64                                      139µs ± 0%      139µs ± 0%    -0.45%  (p=0.000 n=9+10)
NewKeyFromSeed-64                                     139µs ± 0%      139µs ± 0%    -0.34%  (p=0.000 n=10+10)
Signing-64                                            144µs ± 0%      143µs ± 0%    -0.73%  (p=0.000 n=10+10)
Verification-64                                       410µs ± 0%      410µs ± 0%    -0.09%  (p=0.000 n=9+9)

[Geo mean]                                           9.81ms          9.59ms         -2.30%

name                                               old speed      new speed       delta
pkg:crypto/sha512 goos:linux goarch:arm64
Hash8Bytes-64                                      4.96MB/s ± 0%   5.84MB/s ± 0%   +17.60%  (p=0.000 n=7+9)
Hash1K-64                                          91.5MB/s ± 0%   93.7MB/s ± 0%    +2.47%  (p=0.000 n=8+10)
Hash8K-64                                           105MB/s ± 0%    106MB/s ± 0%    +0.45%  (p=0.001 n=10+10)
pkg:crypto/hmac goos:linux goarch:arm64
pkg:crypto/tls goos:linux goarch:arm64
Throughput/MaxPacket/8MB/TLSv13-64                  179MB/s ± 9%    196MB/s ± 2%    +9.31%  (p=0.000 n=10+9)
Throughput/MaxPacket/64MB/TLSv13-64                 176MB/s ±20%    203MB/s ±16%   +15.35%  (p=0.002 n=10+10)
Throughput/DynamicPacket/2MB/TLSv12-64             70.2MB/s ±82%  118.9MB/s ±45%   +69.30%  (p=0.005 n=10+10)
Throughput/DynamicPacket/4MB/TLSv12-64              132MB/s ±19%    159MB/s ±31%   +20.31%  (p=0.029 n=10+10)
Throughput/DynamicPacket/4MB/TLSv13-64              155MB/s ±16%    171MB/s ±24%   +10.26%  (p=0.031 n=9+9)
Throughput/DynamicPacket/8MB/TLSv12-64              141MB/s ±37%    192MB/s ±15%   +36.28%  (p=0.000 n=10+9)
Throughput/DynamicPacket/8MB/TLSv13-64              170MB/s ±12%    185MB/s ±17%    +8.46%  (p=0.035 n=10+10)
Throughput/DynamicPacket/32MB/TLSv13-64             186MB/s ±12%    206MB/s ± 6%   +10.96%  (p=0.001 n=9+10)

[Geo mean]                                          133MB/s         141MB/s         +6.04%

name                                               old alloc/op   new alloc/op    delta
pkg:crypto/ecdsa goos:linux goarch:arm64
SignP256-64                                          3.03kB ± 0%     2.67kB ± 1%   -11.71%  (p=0.000 n=10+9)
pkg:crypto/ed25519 goos:linux goarch:arm64
NewKeyFromSeed-64                                      352B ± 0%         0B       -100.00%  (p=0.000 n=10+10)
Signing-64                                           1.50kB ± 0%     0.45kB ± 0%   -70.21%  (p=0.000 n=10+10)

[Geo mean]                                           3.39kB          4.08kB        +20.24%

name                                               old allocs/op  new allocs/op   delta
pkg:crypto/ecdsa goos:linux goarch:arm64
SignP256-64                                            34.0 ± 0%       32.0 ± 0%    -5.88%  (p=0.000 n=10+10)
SignP384-64                                           14.5k ± 0%      14.5k ± 0%    -0.12%  (p=0.045 n=10+10)
pkg:crypto/ed25519 goos:linux goarch:arm64
NewKeyFromSeed-64                                      2.00 ± 0%       0.00       -100.00%  (p=0.000 n=10+10)
Signing-64                                             11.0 ± 0%        5.0 ± 0%   -54.55%  (p=0.000 n=10+10)

[Geo mean]                                             35.7            53.6        +50.15%

A57:
=========================================================================================================
name                                              old time/op    new time/op    delta
pkg:crypto/sha512 goos:linux goarch:arm64
Hash8Bytes-8                                        1.93µs ± 0%    1.69µs ± 0%   -12.37%  (p=0.000 n=10+10)
Hash1K-8                                            13.8µs ± 0%    13.5µs ± 0%    -2.01%  (p=0.000 n=10+10)
Hash8K-8                                            96.1µs ± 0%    95.7µs ± 0%    -0.35%  (p=0.000 n=10+8)
pkg:crypto/ecdsa goos:linux goarch:arm64
SignP256-8                                          14.9µs ± 4%    14.4µs ± 1%    -2.84%  (p=0.000 n=10+9)
pkg:crypto/hmac goos:linux goarch:arm64
HMACSHA256_1K-8                                     1.87µs ± 0%    1.86µs ± 0%    -0.55%  (p=0.000 n=9+10)
HMACSHA256_32-8                                      760ns ± 0%     756ns ± 0%    -0.54%  (p=0.001 n=10+10)
pkg:crypto/tls goos:linux goarch:arm64
HandshakeServer/RSA-8                               1.11ms ± 0%    1.12ms ± 0%    +0.35%  (p=0.001 n=9+10)
HandshakeServer/ECDHE-P256-RSA/TLSv13-8             1.63ms ± 0%    1.63ms ± 0%    -0.23%  (p=0.004 n=10+9)
HandshakeServer/ECDHE-P256-ECDSA-P256/TLSv13-8       694µs ± 0%     687µs ± 0%    -0.96%  (p=0.000 n=10+8)
HandshakeServer/ECDHE-P256-ECDSA-P256/TLSv12-8       607µs ± 0%     601µs ± 0%    -0.99%  (p=0.000 n=9+9)
HandshakeServer/ECDHE-X25519-ECDSA-P256/TLSv13-8    1.25ms ± 0%    1.25ms ± 0%    -0.24%  (p=0.015 n=10+10)
HandshakeServer/ECDHE-X25519-ECDSA-P256/TLSv12-8    1.16ms ± 0%    1.16ms ± 0%    -0.30%  (p=0.000 n=8+10)
Latency/MaxPacket/200kbps/TLSv12-8                   697ms ± 0%     697ms ± 0%    +0.01%  (p=0.029 n=10+10)
Latency/DynamicPacket/200kbps/TLSv13-8               140ms ± 0%     140ms ± 0%    +0.04%  (p=0.006 n=9+10)
pkg:crypto/ed25519 goos:linux goarch:arm64
NewKeyFromSeed-8                                     168µs ± 0%     168µs ± 0%    +0.04%  (p=0.001 n=9+10)
Signing-8                                            174µs ± 0%     173µs ± 0%    -0.26%  (p=0.000 n=10+10)
Verification-8                                       495µs ± 0%     494µs ± 0%    -0.10%  (p=0.000 n=9+9)

[Geo mean]                                          9.85ms         9.82ms         -0.36%

name                                              old speed      new speed      delta
pkg:crypto/sha512 goos:linux goarch:arm64
Hash8Bytes-8                                      4.15MB/s ± 0%  4.74MB/s ± 0%   +14.11%  (p=0.000 n=10+10)
Hash1K-8                                          74.3MB/s ± 0%  75.8MB/s ± 0%    +2.05%  (p=0.000 n=10+10)
Hash8K-8                                          85.3MB/s ± 0%  85.6MB/s ± 0%    +0.35%  (p=0.000 n=10+8)
pkg:crypto/hmac goos:linux goarch:arm64
HMACSHA256_1K-8                                    549MB/s ± 0%   552MB/s ± 0%    +0.56%  (p=0.000 n=9+10)
HMACSHA256_32-8                                   42.1MB/s ± 0%  42.3MB/s ± 1%    +0.53%  (p=0.001 n=10+10)
pkg:crypto/tls goos:linux goarch:arm64

[Geo mean]                                         138MB/s        139MB/s         +0.54%

name                                              old alloc/op   new alloc/op   delta
pkg:crypto/ecdsa goos:linux goarch:arm64
SignP256-8                                          2.99kB ± 0%    2.64kB ± 0%   -11.77%  (p=0.000 n=10+10)
pkg:crypto/ed25519 goos:linux goarch:arm64
NewKeyFromSeed-8                                      352B ± 0%        0B       -100.00%  (p=0.000 n=10+10)
Signing-8                                           1.50kB ± 0%    0.45kB ± 0%   -70.21%  (p=0.000 n=10+10)

[Geo mean]                                          3.34kB         4.01kB        +20.04%

name                                              old allocs/op  new allocs/op  delta
pkg:crypto/ecdsa goos:linux goarch:arm64
SignP256-8                                            34.0 ± 0%      32.0 ± 0%    -5.88%  (p=0.000 n=10+10)
pkg:crypto/ed25519 goos:linux goarch:arm64
NewKeyFromSeed-8                                      2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Signing-8                                             11.0 ± 0%       5.0 ± 0%   -54.55%  (p=0.000 n=10+10)

[Geo mean]                                            35.7           53.6        +50.17%

Change-Id: Ibbda2d9bdff4eea4f611d4590abceb8764c44f2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/211617
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-03 18:17:13 +00:00
Filippo Valsorda
9baafabac9 crypto/rsa: refactor RSA-PSS signing and verification
Cleaned up for readability and consistency.

There is one tiny behavioral change: when PSSSaltLengthEqualsHash is
used and both hash and opts.Hash were set, hash.Size() was used for the
salt length instead of opts.Hash.Size(). That's clearly wrong because
opts.Hash is documented to override hash.

Change-Id: I3e25dad933961eac827c6d2e3bbfe45fc5a6fb0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/226937
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2020-04-02 17:46:57 +00:00
Katie Hockman
620208790e crypto/tls: add missing alert values
Fixes #35911

Change-Id: I093d25aa169963769b51c37d2481bce71bd0fd2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/226858
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-04-01 19:32:57 +00:00
Roland Shoemaker
5db079d2e5 crypto/rsa: reject invalid length PKCS#1v1.5 signatures
Per RFC 8017, reject signatures which are not the same length as the RSA
modulus. This matches the behavior of SignPKCS1v15 which properly left pads
the signatures it generates to the size of the modulus.

Fixes #21896

Change-Id: I2c42a0b24cf7fff158ece604b6f0c521a856d932
GitHub-Last-Rev: 6040f79906
GitHub-Pull-Request: golang/go#38140
Reviewed-on: https://go-review.googlesource.com/c/go/+/226203
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-31 17:41:35 +00:00
alex-semenyuk
82047a080f test, test/fixedbugs, crypto/x509, go/internal/gccgoimporter: fix typos
Change-Id: Ie2d605ca8cc3bde2e26c6865642ff4e6412cd075
GitHub-Last-Rev: ce5c3ba369
GitHub-Pull-Request: golang/go#38137
Reviewed-on: https://go-review.googlesource.com/c/go/+/226201
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-03-29 17:12:56 +00:00
Filippo Valsorda
b5f2c0f502 crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PublicKey.Equal
This makes all modern public keys in the standard library implement a
common interface (below) that can be used by applications for better
type safety and allows for checking that public (and private keys via
Public()) are equivalent.

interface {
    Equal(crypto.PublicKey) bool
}

Equality for ECDSA keys is complicated, we take a strict interpretation
that works for all secure applications (the ones not using the
unfortunate non-constant time CurveParams implementation) and fails
closed otherwise.

Tests in separate files to make them x_tests and avoid an import loop
with crypto/x509.

Re-landing of CL 223754. Dropped the test that was assuming named curves
are not implemented by CurveParams, because it's not true for all
curves, and anyway is not a property we need to test. There is still a
test to check that different curves make keys not Equal.

Fixes #21704
Fixes #38035

Reviewed-on: https://go-review.googlesource.com/c/go/+/223754
Reviewed-by: Katie Hockman <katie@golang.org>
Change-Id: I736759b145bfb4f7f8eecd78c324315d5a05385c
Reviewed-on: https://go-review.googlesource.com/c/go/+/225460
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-26 15:00:36 +00:00
Katie Hockman
9dcd6b32c8 crypto: implement Hash.String
Fixes #33430

Change-Id: I323323b3136dd7b408005c3bb5ea05e3b566bd38
Reviewed-on: https://go-review.googlesource.com/c/go/+/224937
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-03-24 17:24:24 +00:00
Bryan C. Mills
fb2a6343de Revert "crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PublicKey.Equal"
This reverts CL 223754.

Reason for revert: new tests are failing on all longtest builders.

Change-Id: I2257d106c132f3a02c0af6b20061d4f9a8093c4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/225077
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-23 21:15:27 +00:00
Filippo Valsorda
5c9bd499e1 crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PublicKey.Equal
This makes all modern public keys in the standard library implement a
common interface (below) that can be used by applications for better
type safety and allows for checking that public (and private keys via
Public()) are equivalent.

interface {
    Equal(crypto.PublicKey) bool
}

Equality for ECDSA keys is complicated, we take a strict interpretation
that works for all secure applications (the ones not using the
unfortunate non-constant time CurveParams implementation) and fails
closed otherwise.

Tests in separate files to make them x_tests and avoid an import loop
with crypto/x509.

Fixes #21704

Change-Id: Id5379c96384a11c5afde0614955360e7470bb1c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/223754
Reviewed-by: Katie Hockman <katie@golang.org>
2020-03-23 17:56:24 +00:00
Roland Shoemaker
5d47f870a6 crypto/x509: add RevocationList and CreateRevocationList
The existing Certificate.CreateCRL method generates non-conformant CRLs and
as such cannot be used for implementations that require standards
compliance. This change implements a new top level method, CreateCRL, which
generates compliant CRLs, and offers an extensible API if any
extensions/fields need to be supported in the future.

Here is an example Issuer/CRL generated using this change:
-----BEGIN CERTIFICATE-----
MIIBNjCB3aADAgECAgEWMAoGCCqGSM49BAMCMBIxEDAOBgNVBAMTB3Rlc3Rpbmcw
IhgPMDAwMTAxMDEwMDAwMDBaGA8wMDAxMDEwMTAwMDAwMFowEjEQMA4GA1UEAxMH
dGVzdGluZzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLHrudbSM36sn1VBrmm/
OfQTyEsI4tIUV1VmneOKHL9ENBGCiec4GhQm2SGnDT/sZy2bB3c3yozh/roS6cZJ
UZqjIDAeMA4GA1UdDwEB/wQEAwIBAjAMBgNVHQ4EBQQDAQIDMAoGCCqGSM49BAMC
A0gAMEUCIQCoAYN6CGZPgd5Sw5a1rd5VexciT5MCxTfXj+ZfJNfoiAIgQVCTB8AE
Nm2xset7+HOgtQYlKNw/rGd8cFcv5Y9aUzo=
-----END CERTIFICATE-----
-----BEGIN X509 CRL-----
MIHWMH0CAQEwCgYIKoZIzj0EAwIwEjEQMA4GA1UEAxMHdGVzdGluZxgPMDAwMTAx
MDIwMDAwMDBaGA8wMDAxMDEwMzAwMDAwMFowFjAUAgECGA8wMDAxMDEwMTAxMDAw
MFqgHjAcMA4GA1UdIwQHMAWAAwECAzAKBgNVHRQEAwIBBTAKBggqhkjOPQQDAgNJ
ADBGAiEAjqfj/IG4ys5WkjrbTNpDbr+saHGO/NujLJotlLL9KzgCIQDm8VZPzj0f
NYEQgAW4nsiUzlvEUCoHMw0141VCZXv67A==
-----END X509 CRL-----

Fixes #35428

Change-Id: Id96b6f47698d0bed39d586b46bd12374ee6ff88f
GitHub-Last-Rev: c83a601716
GitHub-Pull-Request: golang/go#36945
Reviewed-on: https://go-review.googlesource.com/c/go/+/217298
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-23 17:23:03 +00:00
Tobias Klauser
965f4566e9 crypto/x509: bump minimum macOS version to 10.11
The minimum macOS supported version is 10.11 as of Go 1.14, see #23011.
Thus, bump macosx-version-min to 10.11

While at it, drop __MAC_OS_X_VERSION_MAX_ALLOWED as suggested by
Filippo:

  In general, I can see why we'd want to tell the libraries which
  minimum version we target so they drop compatibility with older
  versions. No idea why we'd specify a max version, unless it's to make
  sure we don't use APIs added after that version, but then it would
  have to be 1011 not 1015.

  Let's try dropping that define and see if anything blows up? ¯\_(ツ)_/¯

Change-Id: I6b76623a9404724ccda40311ff95b3475ae8a60c
Reviewed-on: https://go-review.googlesource.com/c/go/+/214059
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-03-19 22:33:15 +00:00
Chris Le Roy
16822a2bc4 crypto/tls: update the MITM reference to "machine-in-the-middle"
Changing "man-in-the-middle" references to "machine-in-the-middle",
it's a more inclusive term and still aligns with the MITM acronym.

Change-Id: I81f954cff3d252433443f159ff9edaf59a28ab9d
GitHub-Last-Rev: 3e8f91424a
GitHub-Pull-Request: golang/go#37918
Reviewed-on: https://go-review.googlesource.com/c/go/+/223897
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-03-19 21:31:51 +00:00
Filippo Valsorda
efc832b8de crypto/tls: add {SignatureScheme,CurveID,ClientAuthType}.String()
Fixes #35499

Change-Id: Ieb487782f389f6d80e8f68ee980e584d906cb4da
Reviewed-on: https://go-review.googlesource.com/c/go/+/208226
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2020-03-11 20:02:18 +00:00
Ziheng Liu
42f8199290 all: fix incorrect channel and API usage in some unit tests
This CL changes some unit test functions, making sure that these tests (and goroutines spawned during test) won't block.
Since they are just test functions, I use one CL to fix them all. I hope this won't cause trouble to reviewers and can save time for us.
There are three main categories of incorrect logic fixed by this CL:
1. Use testing.Fatal()/Fatalf() in spawned goroutines, which is forbidden by Go's document.
2. Channels are used in such a way that, when errors or timeout happen, the test will be blocked and never return.
3. Channels are used in such a way that, when errors or timeout happen, the test can return but some spawned goroutines will be leaked, occupying resource until all other tests return and the process is killed.

Change-Id: I3df931ec380794a0cf1404e632c1dd57c65d63e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/219380
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-02-27 19:04:17 +00:00
Katie Hockman
d0e9a4ebfd crypto/tls: use new ecdsa.VerifyASN1 API
Change-Id: I2a233190bda78ca022ff4074b4553788847d7583
Reviewed-on: https://go-review.googlesource.com/c/go/+/220720
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-02-26 16:58:30 +00:00
Katie Hockman
975c01342a crypto/x509: use new ecdsa.VerifyASN1 API
Change-Id: Ia4f77d2965e34454e8dd3f2d8bf9c4f3065a9fbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/220721
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-02-26 15:50:14 +00:00
Emmanuel T Odeke
7a03d79498 crypto/x509: load roots from colon separated SSL_CERT_DIR in loadSystemRoots
"SSL_CERT_DIR" is meant to hold more than one directory, when a colon
is used as a delimiter. However, we assumed it'd be a single directory
for all root certificates.
OpenSSL and BoringSSL properly respected the colon separated
"SSL_CERT_DIR", as per:
* OpenSSL 12a765a523/crypto/x509/by_dir.c (L153-L209)
* BoringSSL 3ba9586bc0/crypto/x509/by_dir.c (L194-L247)

This change adds that parity to loadSystemRoots.

RELNOTE=yes

Fixes #35325

Change-Id: I0d554a00ccc34300a7f0529aa741ee7e2d5762f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/205237
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-02-26 05:45:54 +00:00
Katie Hockman
4e8badbbc2 crypto/cipher: require non-zero nonce size for AES-GCM
Also fix typo in crypto/cipher/gcm_test.go.

Fixes #37118

Change-Id: I8544d1eeeb1f0336cebb977b8c5bfa5e4c5ad8c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/218500
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-02-24 15:45:26 +00:00
Johan Jansson
d67d044310 crypto/tls: update ExampleDial with a valid root
When run as a separate program, the code in ExampleDial panicked due to
an expired certificate. Fixed this problem by replacing the expired
certificate with a valid one.

Also added a comment in the certificate to give a hint about why it
might fail in the future.

Fixes #35706

Change-Id: I3d300f7bccae050e4b73ded28b8029aa04b480bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/212601
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-02-21 23:20:22 +00:00
Filippo Valsorda
4045de378b crypto/tls: clarify TLS 1.0/1.1 CertificateRequestInfo.SignatureSchemes
This CL should not change the logic at all, but it took me a while to
figure out why we use these specific SignatureSchemes, so reformulate
the comment.

Change-Id: If519a58264209e6575417be07668e92ead0e772f
Reviewed-on: https://go-review.googlesource.com/c/go/+/208225
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2020-02-21 23:18:43 +00:00
Katie Hockman
8c09e8af36 crypto/ecdsa: add SignASN1, VerifyASN1
Update the Example in the crypto/ecdsa package for signing
and verifying signatures to use these new functions.

This also changes (*PrivateKey).Sign to use
x/crypto/cryptobyte/asn1 instead of encoding/asn1
to marshal the signature.

Fixes #20544

Change-Id: I3423cfc4d7f9e1748fbed5a631438c8a3b280df4
Reviewed-on: https://go-review.googlesource.com/c/go/+/217940
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-02-21 19:38:55 +00:00
Alexander Rakoczy
4f020a52c5 crypto/x509: correct error message for trailing issuer data
The error message for trailing data after the X.509 issuer should
correctly state "issuer" instead of "subject", which appears just above
this code.

Fixes #35841

Change-Id: Iea2605ce97f2b084eb78e88f2c27d7d43749d022
Reviewed-on: https://go-review.googlesource.com/c/go/+/208978
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2020-02-21 18:28:52 +00:00
Filippo Valsorda
25da21ddc9 crypto/elliptic: document the Name and names of each curve
See https://tools.ietf.org/html/rfc8422#appendix-A for a helpful table.

Also, commit to keeping them singletons, as that assumption is already
made all over the place in the ecosystem.

Fixes #34193

Change-Id: I2ec50fa18bb80e11d6101f2562df60b5e27d4f66
Reviewed-on: https://go-review.googlesource.com/c/go/+/218921
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-02-11 00:59:47 +00:00
Katie Hockman
7a36fa4002 crypto/x509: fix godoc for MarshalPKCS8PrivateKey
Fixes #36735

Change-Id: I93f005d78f4bfac773272995b165172461bae92f
Reviewed-on: https://go-review.googlesource.com/c/go/+/217917
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-02-05 21:53:13 +00:00
Filippo Valsorda
953bc8f391 crypto/x509: mitigate CVE-2020-0601 verification bypass on Windows
An attacker can trick the Windows system verifier to use a poisoned set
of elliptic curve parameters for a trusted root, allowing it to generate
spoofed signatures. When this happens, the returned chain will present
the unmodified original root, so the actual signatures won't verify (as
they are invalid for the correct parameters). Simply double check them
as a safety measure and mitigation.

Windows users should still install the system security patch ASAP.

This is the same mitigation adopted by Chromium:

https://chromium-review.googlesource.com/c/chromium/src/+/1994434

Change-Id: I2c734f6fb2cb51d906c7fd77034318ffeeb3e146
Reviewed-on: https://go-review.googlesource.com/c/go/+/215905
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ryan Sleevi <sleevi@google.com>
Reviewed-by: Katie Hockman <katie@golang.org>
2020-01-23 22:31:25 +00:00
Brad Fitzpatrick
5d9f1c847f crypto/tls: stop a timeout timer
I noticed this leak while writing CL 214977.

Change-Id: I7566952b8e4bc58939d23435aea86576fc58ddca
Reviewed-on: https://go-review.googlesource.com/c/go/+/214978
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-01-15 20:29:46 +00:00
bxq2011hust
79ccbe1b67 crypto/x509: this change modifies C.CopyPEMRoots to static function
Change-Id: Ic7997d1f747152afec78e8e439770166029f34ec
GitHub-Last-Rev: 6a07f25056
GitHub-Pull-Request: golang/go#36491
Reviewed-on: https://go-review.googlesource.com/c/go/+/214298
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-01-10 15:22:42 +00:00
Daniel Martí
41348081fa all: fix a number of misuses of the word "an"
After golang.org/cl/210124, I wondered if the same error had gone
unnoticed elsewhere. I quickly spotted another dozen mistakes after
reading through the output of:

	git grep '\<[Aa]n [bcdfgjklmnpqrtvwyz][a-z]'

Many results are false positives for acronyms like "an mtime", since
it's pronounced "an em-time". However, the total amount of output isn't
that large given how simple the grep pattern is.

Change-Id: Iaa2ca69e42f4587a9e3137d6c5ed758887906ca6
Reviewed-on: https://go-review.googlesource.com/c/go/+/210678
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Zach Jones <zachj1@gmail.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-10 16:23:10 +00:00
Alex Harford
33d20760a2 crypto/tls: fix a typo in TLS handshake comment
Fix a minor typo in the TLS handshake comment.

Change-Id: I0fd243e5440f6c77c97e844e6669a7974a2c8798
GitHub-Last-Rev: 21e91a1a48
GitHub-Pull-Request: golang/go#36030
Reviewed-on: https://go-review.googlesource.com/c/go/+/210289
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-12-06 23:53:46 +00:00
Filippo Valsorda
f4a8bf1283 crypto/tls: remove leftover extensionNextProtoNeg constant
NPN was removed in CL 174329.

Change-Id: Ic63ad53e7e24872e28673d590727e0300f435619
Reviewed-on: https://go-review.googlesource.com/c/go/+/208224
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-11-21 19:27:16 +00:00
Katie Hockman
ee04dbf430 crypto/x509: fix typo in godoc for ParseECPrivateKey
Change-Id: Ia65bac00fe8600f50620ce0583455eb33f06ff95
Reviewed-on: https://go-review.googlesource.com/c/go/+/207918
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-11-20 05:44:42 +00:00
Ville Skyttä
440f7d6404 all: fix a bunch of misspellings
Change-Id: I5b909df0fd048cd66c5a27fca1b06466d3bcaac7
GitHub-Last-Rev: 778c5d2131
GitHub-Pull-Request: golang/go#35624
Reviewed-on: https://go-review.googlesource.com/c/go/+/207421
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-11-15 21:04:43 +00:00
Filippo Valsorda
43ec1b12f5 src/vendor,crypto/tls: update to latest x/crypto and use new X25519 API
Change-Id: Icd5006e37861d892a5f3d4397c3826179c1b12ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/206657
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2019-11-13 01:15:54 +00:00
Bryan C. Mills
8c5dbba01c crypto/tls: retry ETIMEDOUT flakes in localPipe on dragonfly
Fixes #29583

Change-Id: Ia89433bddd4c9f67ec1f0150b730cde8a7e973ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/206759
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-12 17:55:14 +00:00
Filippo Valsorda
c2edcf4b12 crypto/tls: take key size into account in signature algorithm selection
Fixes #29793

Change-Id: I6e389d166c2d9a2ba8664a41f4b9569f2481b27f
Reviewed-on: https://go-review.googlesource.com/c/go/+/205177
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2019-11-12 01:09:40 +00:00
Filippo Valsorda
0ee22d97ad crypto/tls: add CipherSuites, InsecureCipherSuites and CipherSuiteName
Fixes #30325

Change-Id: I497110224bb73ecfcc4655698a794e7aa4a66925
Reviewed-on: https://go-review.googlesource.com/c/go/+/175517
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2019-11-12 01:09:31 +00:00
Filippo Valsorda
e2cac31508 crypto/tls: add correct names for CHACHA20_POLY1305 cipher suite constants
The cipher suites were apparently renamed late in the standardization
process, and we picked up the legacy name. We can't remove the old
constants, but add correctly named ones.

Fixes #32061

Change-Id: I65ee25c12c10934391af88b76b18565da67453fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/205068
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2019-11-12 01:09:23 +00:00
Filippo Valsorda
52a5bf4d33 crypto/tls: re-enable RSA-PSS in TLS 1.2 again
TLS 1.3, which requires RSA-PSS, is now enabled without a GODEBUG
opt-out, and with the introduction of
Certificate.SupportedSignatureAlgorithms (#28660) there is a
programmatic way to avoid RSA-PSS (disable TLS 1.3 with MaxVersion and
use that field to specify only PKCS#1 v1.5 SignatureSchemes).

This effectively reverts 0b3a57b537,
although following CL 205061 all of the signing-side logic is
conveniently centralized in signatureSchemesForCertificate.

Fixes #32425

Change-Id: I7c9a8893bb5d518d86eae7db82612b9b2cd257d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/205063
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2019-11-12 01:09:15 +00:00
Filippo Valsorda
5b17b65750 crypto/tls: implement Certificate.SupportedSignatureAlgorithms
This will let applications stop crypto/tls from using a certificate key
with an algorithm that is not supported by its crypto.Signer, like
hardware backed keys that can't do RSA-PSS.

Fixes #28660

Change-Id: I294cc06bddf813fff35c5107540c4a1788e1dace
Reviewed-on: https://go-review.googlesource.com/c/go/+/205062
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2019-11-12 01:09:06 +00:00
Filippo Valsorda
eb93c684d4 crypto/tls: select only compatible chains from Certificates
Now that we have a full implementation of the logic to check certificate
compatibility, we can let applications just list multiple chains in
Certificates (for example, an RSA and an ECDSA one) and choose the most
appropriate automatically.

NameToCertificate only maps each name to one chain, so simply deprecate
it, and while at it simplify its implementation by not stripping
trailing dots from the SNI (which is specified not to have any, see RFC
6066, Section 3) and by not supporting multi-level wildcards, which are
not a thing in the WebPKI (and in crypto/x509).

The performance of SupportsCertificate without Leaf is poor, but doesn't
affect current users. For now document that, and address it properly in
the next cycle. See #35504.

While cleaning up the Certificates/GetCertificate/GetConfigForClient
behavior, also support leaving Certificates/GetCertificate nil if
GetConfigForClient is set, and send unrecognized_name when there are no
available certificates.

Fixes #29139
Fixes #18377

Change-Id: I26604db48806fe4d608388e55da52f34b7ca4566
Reviewed-on: https://go-review.googlesource.com/c/go/+/205059
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2019-11-12 01:08:57 +00:00
Filippo Valsorda
4b21642161 crypto/tls: implement (*CertificateRequestInfo).SupportsCertificate
Also, add Version to CertificateRequestInfo, as the semantics of
SignatureSchemes change based on version: the ECDSA SignatureSchemes are
only constrained to a specific curve in TLS 1.3.

Fixes #32426

Change-Id: I7a551bea864799e98118349ac2476162893d1ffd
Reviewed-on: https://go-review.googlesource.com/c/go/+/205058
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2019-11-12 01:08:46 +00:00
Filippo Valsorda
dd0173845f crypto/tls: implement (*ClientHelloInfo).SupportsCertificate
We'll also use this function for a better selection logic from
Config.Certificates in a later CL.

Updates #32426

Change-Id: Ie239574d02eb7fd2cf025ec36721c8c7e082d0bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/205057
Reviewed-by: Katie Hockman <katie@golang.org>
2019-11-12 01:08:34 +00:00
Filippo Valsorda
ec732632c2 crypto/tls: refactor certificate and signature algorithm logic
This refactors a lot of the certificate support logic to make it cleaner
and reusable where possible. These changes will make the following CLs
much simpler.

In particular, the heavily overloaded pickSignatureAlgorithm is gone.
That function used to cover both signing and verifying side, would work
both for pre-signature_algorithms TLS 1.0/1.1 and TLS 1.2, and returned
sigalg, type and hash.

Now, TLS 1.0/1.1 and 1.2 are differentiated at the caller, as they have
effectively completely different logic. TLS 1.0/1.1 simply use
legacyTypeAndHashFromPublicKey as they employ a fixed hash function and
signature algorithm for each public key type. TLS 1.2 is instead routed
through selectSignatureScheme (on the signing side) or
isSupportedSignatureAlgorithm (on the verifying side) and
typeAndHashFromSignatureScheme, like TLS 1.3.

On the signing side, signatureSchemesForCertificate was already version
aware (for PKCS#1 v1.5 vs PSS support), so selectSignatureScheme just
had to learn the Section 7.4.1.4.1 defaults for a missing
signature_algorithms to replace pickSignatureAlgorithm.

On the verifying side, pickSignatureAlgorithm was also checking the
public key type, while isSupportedSignatureAlgorithm +
typeAndHashFromSignatureScheme are not, but that check was redundant
with the one in verifyHandshakeSignature.

There should be no major change in behavior so far. A few minor changes
came from the refactor: we now correctly require signature_algorithms in
TLS 1.3 when using a certificate; we won't use Ed25519 in TLS 1.2 if the
client didn't send signature_algorithms; and we don't send
ec_points_format in the ServerHello (a compatibility measure) if we are
not doing ECDHE anyway because there are no mutually supported curves.

The tests also got simpler because they test simpler functions. The
caller logic switching between TLS 1.0/1.1 and 1.2 is tested by the
transcript tests.

Updates #32426

Change-Id: Ice9dcaea78d204718f661f8d60efdb408ba41577
Reviewed-on: https://go-review.googlesource.com/c/go/+/205061
Reviewed-by: Katie Hockman <katie@golang.org>
2019-11-12 01:07:15 +00:00
Lorenz Brun
ad7ce3911f crypto/x509: fix CreateCRL for Ed25519 CAs
This makes Ed25519 certificates work for CreateCRL(). This previously
failed (panic: crypto: requested hash function #0 is unavailable) because
the hash could not be skipped, but Ed25519 uses no hash.

A similar fix has been applied in a few other places when Ed25519 was added
when Ed25519 certificates were originally introduced, but was missed
here.

Change-Id: I16fcfcd53ba3bb8f773e5de972b8fedde1f6350e

Change-Id: I16fcfcd53ba3bb8f773e5de972b8fedde1f6350e
GitHub-Last-Rev: bf7f1458f8
GitHub-Pull-Request: golang/go#35241
Reviewed-on: https://go-review.googlesource.com/c/go/+/204046
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-11-11 18:00:18 +00:00
Filippo Valsorda
29cfb4d3c3 crypto/tls: add ExampleConfig_VerifyPeerCertificate
Setting InsecureSkipVerify and VerifyPeerCertificate is the recommended
way to customize and override certificate validation.

However, there is boilerplate involved and it usually requires first
reimplementing the default validation strategy to then customize it.
Provide an example that does the same thing as the default as a starting
point.

Examples of where we directed users to do something similar are in
issues #35467, #31791, #28754, #21971, and #24151.

Fixes #31792

Change-Id: Id033e9fa3cac9dff1f7be05c72dfb34b4f973fd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/193620
Reviewed-by: Adam Langley <agl@golang.org>
2019-11-09 20:08:06 +00:00
Katie Hockman
552987fdbf crypto/dsa: prevent bad public keys from causing panic
dsa.Verify might currently use a nil s inverse in a
multiplication if the public key contains a non-prime Q,
causing a panic. Change this to check that the mod
inverse exists before using it.

Fixes CVE-2019-17596

Fixes #34960

Change-Id: I94d5f3cc38f1b5d52d38dcb1d253c71b7fd1cae7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/572809
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/205441
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-11-05 20:21:34 +00:00
Filippo Valsorda
03aca99f47 crypto/tls: make -update only regenerate transcripts for failing tests
Change-Id: Ie68fd4fe2879e6b5417a1a4240971e3d837bf115
Reviewed-on: https://go-review.googlesource.com/c/go/+/204377
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-04 20:39:53 +00:00
Alex Brainman
d2c039fb21 crypto/x509: make '-gcflags=all=-d=checkptr' flag work
Replace

buf := [HUGE_CONST]*T)(unsafe.Pointer(p))[:]

with

buf := [HUGE_CONST]*T)(unsafe.Pointer(p))[:n:n]

Pointer p points to n of T elements. New unsafe pointer conversion
logic verifies that both first and last elements point into the
same Go variable. And this change adjusts all code to comply with
this rule.

Verified by running

go test -a -short -gcflags=all=-d=checkptr crypto/x509

The test does not fail even with original version of this code. I
suspect it is because all variables I changed live outside of Go
memory. But I am just guessing, I don't really know how pointer
checker works.

Updates golang/go#34972

Change-Id: Ibc33fdc9e2023d9b14905c9badf2f0b683999ab8
Reviewed-on: https://go-review.googlesource.com/c/go/+/204621
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-11-03 01:44:46 +00:00
Katie Hockman
dc0c23ec9d crypto/dsa: change bitwise checks to mod operations
Even though bitwise operations may be slightly more
performant, the readability improvement of a mod
operation is worth the tradeoff.

Change-Id: I352c92ad355c6eb6ef99e3da00e1eff2d2ea5812
Reviewed-on: https://go-review.googlesource.com/c/go/+/204739
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-02 15:46:47 +00:00
Olivier Poitrey
02a5502ab8 crypto/tls: send ec_points_format extension in ServerHello
Follow the recommandation from RFC 8422, section 5.1.2 of sending back the
ec_points_format extension when requested by the client. This is to fix
some clients declining the handshake if omitted.

Fixes #31943

Change-Id: I7b04dbac6f9af75cda094073defe081e1e9a295d
Reviewed-on: https://go-review.googlesource.com/c/go/+/176418
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Olivier Poitrey <rs@rhapsodyk.net>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-31 15:14:45 +00:00
Filippo Valsorda
cd18da451f crypto/tls: improve error messages for invalid certificates and signatures
Also, fix the alert value sent when a signature by a client certificate
is invalid in TLS 1.0-1.2.

Fixes #35190

Change-Id: I2ae1d5593dfd5ee2b4d979664aec74aab4a8a704
Reviewed-on: https://go-review.googlesource.com/c/go/+/204157
Reviewed-by: Katie Hockman <katie@golang.org>
2019-10-30 20:18:59 +00:00
Lynn Boger
ac346a5fd9 crypto/elliptic: clean up ppc64le implementation slightly
As suggested by comments from the review of CL 168478, this adds
Go code to do reverse bytes and removes the asm code, as well
as making a few cosmetic changes.

Change-Id: I08276a11222e03c3b42f4c9dc0d10a371a418be7
Reviewed-on: https://go-review.googlesource.com/c/go/+/203937
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
2019-10-29 12:23:21 +00:00
Lynn Boger
adef06c7a5 crypto/elliptic: add asm implementation for p256 on ppc64le
This adds an asm implementation of the p256 functions used
in crypto/elliptic, utilizing VMX, VSX to improve performance.
On a power9 the improvement is:

elliptic benchmarks:
name            old time/op    new time/op    delta
BaseMult          1.40ms ± 0%    1.44ms ± 0%   +2.66%  (p=0.029 n=4+4)
BaseMultP256       317µs ± 0%      50µs ± 0%  -84.14%  (p=0.029 n=4+4)
ScalarMultP256     854µs ± 2%     214µs ± 0%  -74.91%  (p=0.029 n=4+4)

ecdsa benchmarks:
name           old time/op    new time/op    delta
SignP256          377µs ± 0%     111µs ± 0%  -70.57%  (p=0.029 n=4+4)
SignP384         6.55ms ± 0%    6.48ms ± 0%   -1.03%  (p=0.029 n=4+4)
VerifyP256       1.19ms ± 0%    0.26ms ± 0%  -78.54%  (p=0.029 n=4+4)
KeyGeneration     319µs ± 0%      52µs ± 0%  -83.56%  (p=0.029 n=4+4)

This implemenation is based on the s390x implementation, using
comparable instructions for most with some minor changes where the
instructions are not quite the same.

Some changes were also needed since s390x is big endian and ppc64le
is little endian.

This also enables the fuzz_test for ppc64le.

Change-Id: I59a69515703b82ad2929f68ba2f11208fa833181
Reviewed-on: https://go-review.googlesource.com/c/go/+/168478
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
2019-10-28 12:35:06 +00:00
Josh Bleecher Snyder
0f559941fb crypto/tls: move a defer out of a loop
Rhys Hiltner noted in #14939 that this defer was
syntactically inside a loop, but was only ever

executed once. Now that defer in a loop
is significantly slower, pull this one out.

name                                    old time/op   new time/op   delta
Throughput/MaxPacket/1MB/TLSv12-8        3.94ms ± 8%   3.93ms ±13%    ~     (p=0.967 n=15+15)
Throughput/MaxPacket/1MB/TLSv13-8        4.33ms ± 3%   4.51ms ± 7%  +4.00%  (p=0.000 n=14+14)
Throughput/MaxPacket/2MB/TLSv12-8        6.80ms ± 6%   7.01ms ± 4%  +3.15%  (p=0.000 n=14+14)
Throughput/MaxPacket/2MB/TLSv13-8        6.96ms ± 5%   6.80ms ± 5%  -2.43%  (p=0.006 n=15+14)
Throughput/MaxPacket/4MB/TLSv12-8        12.0ms ± 3%   11.7ms ± 2%  -2.88%  (p=0.000 n=15+13)
Throughput/MaxPacket/4MB/TLSv13-8        12.1ms ± 3%   11.7ms ± 2%  -3.54%  (p=0.000 n=13+13)
Throughput/MaxPacket/8MB/TLSv12-8        22.2ms ± 3%   21.6ms ± 3%  -2.97%  (p=0.000 n=15+15)
Throughput/MaxPacket/8MB/TLSv13-8        22.5ms ± 5%   22.0ms ± 3%  -2.34%  (p=0.004 n=15+15)
Throughput/MaxPacket/16MB/TLSv12-8       42.4ms ± 3%   41.3ms ± 3%  -2.49%  (p=0.001 n=15+15)
Throughput/MaxPacket/16MB/TLSv13-8       43.4ms ± 5%   42.3ms ± 3%  -2.33%  (p=0.006 n=15+14)
Throughput/MaxPacket/32MB/TLSv12-8       83.1ms ± 4%   80.6ms ± 3%  -2.98%  (p=0.000 n=15+15)
Throughput/MaxPacket/32MB/TLSv13-8       85.2ms ± 8%   82.6ms ± 4%  -3.02%  (p=0.005 n=15+15)
Throughput/MaxPacket/64MB/TLSv12-8        167ms ± 7%    158ms ± 2%  -5.21%  (p=0.000 n=15+15)
Throughput/MaxPacket/64MB/TLSv13-8        170ms ± 4%    162ms ± 3%  -4.83%  (p=0.000 n=15+15)
Throughput/DynamicPacket/1MB/TLSv12-8    4.13ms ± 7%   4.00ms ± 8%    ~     (p=0.061 n=15+15)
Throughput/DynamicPacket/1MB/TLSv13-8    4.72ms ± 6%   4.64ms ± 7%    ~     (p=0.377 n=14+15)
Throughput/DynamicPacket/2MB/TLSv12-8    7.29ms ± 7%   7.09ms ± 7%    ~     (p=0.070 n=15+14)
Throughput/DynamicPacket/2MB/TLSv13-8    7.18ms ± 5%   6.59ms ± 4%  -8.34%  (p=0.000 n=15+15)
Throughput/DynamicPacket/4MB/TLSv12-8    12.3ms ± 3%   11.9ms ± 4%  -3.31%  (p=0.000 n=15+14)
Throughput/DynamicPacket/4MB/TLSv13-8    12.2ms ± 4%   12.0ms ± 4%  -1.91%  (p=0.019 n=15+15)
Throughput/DynamicPacket/8MB/TLSv12-8    22.4ms ± 3%   21.9ms ± 3%  -2.18%  (p=0.000 n=15+15)
Throughput/DynamicPacket/8MB/TLSv13-8    22.7ms ± 3%   22.2ms ± 3%  -2.35%  (p=0.000 n=15+15)
Throughput/DynamicPacket/16MB/TLSv12-8   42.3ms ± 3%   42.1ms ± 3%    ~     (p=0.505 n=14+15)
Throughput/DynamicPacket/16MB/TLSv13-8   42.7ms ± 3%   43.3ms ± 7%    ~     (p=0.123 n=15+14)
Throughput/DynamicPacket/32MB/TLSv12-8   82.8ms ± 3%   81.9ms ± 3%    ~     (p=0.112 n=14+15)
Throughput/DynamicPacket/32MB/TLSv13-8   84.6ms ± 6%   83.9ms ± 4%    ~     (p=0.624 n=15+15)
Throughput/DynamicPacket/64MB/TLSv12-8    166ms ± 4%    163ms ± 6%    ~     (p=0.081 n=15+15)
Throughput/DynamicPacket/64MB/TLSv13-8    165ms ± 3%    168ms ± 3%  +1.56%  (p=0.029 n=15+15)

Change-Id: I22409b05afe761b8ed1912b15c67fc03f88d3d1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/203481
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-26 15:17:28 +00:00
Ghazni Nattarshah
67fb5530f0 crypto/x509: gofmt verify.go
Fixes #35052

Change-Id: Ie7c52f39203cf16d8b53a333b591cffccdf7446a
Reviewed-on: https://go-review.googlesource.com/c/go/+/202877
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-23 18:07:56 +00:00
Bryan C. Mills
71d127aafd crypto/tls: retry net.Dial flakes on Dragonfly
localPipe currently flakes in various crypto/tls tests. Since that
function doesn't seem to flake anywhere else, I suspect a kernel bug.

To make the test less flaky, retry the Dial if we suspect that it is
affected. (Worst case, we delay the test by a few seconds before
erroring out as usual.)

Fixes #29583

Change-Id: I357990ffa316edb471bd7d46d6404fa0884da646
Reviewed-on: https://go-review.googlesource.com/c/go/+/202557
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-21 19:06:29 +00:00
Michael Munday
943df4f629 crypto/ecdsa: remove s390x assembly
This a revert of CL 174437 and follow up fix CL 201317.

The s390x assembly in this package makes use of an instruction
(specifically KDSA) which is not supported by the current build
machine. Remove this assembly for now, we can revisit this
functionality once we have a newer build machine and can ensure
that this assembly is well tested.

Updates #34927.

Change-Id: I779286fa7d9530a254b53a515ee76b1218821f2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/201360
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-16 21:57:24 +00:00
bill_ofarrell
86f40a2e03 crypto/ecdsa: fix buffer size on s390x for ecdsa
I used too small a size for buffers, which can cause a panic in some testing.
The new buffer size is generous and sufficient for all purposes.

Fixes #34927
Fixes #34928

Change-Id: Icdbbfed5da87fe3757be40dfd23182b37ec62d58
Reviewed-on: https://go-review.googlesource.com/c/go/+/201317
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-16 03:09:29 +00:00
fenos
2ac8f799d8 crypto/tls: consistently use %v for error formatting
We should keep a consistent way of formatting errors
in this file.

Fixes #34848

Change-Id: Ibb75908504f381fccab0281a42e788ef8c716b6f
Reviewed-on: https://go-review.googlesource.com/c/go/+/200679
Run-TryBot: Johan Brandhorst <johan.brandhorst@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-11 14:23:52 +00:00
Brad Fitzpatrick
03ef105dae all: remove nacl (part 3, more amd64p32)
Part 1: CL 199499 (GOOS nacl)
Part 2: CL 200077 (amd64p32 files, toolchain)
Part 3: stuff that arguably should've been part of Part 2, but I forgot
        one of my grep patterns when splitting the original CL up into
        two parts.

This one might also have interesting stuff to resurrect for any future
x32 ABI support.

Updates #30439

Change-Id: I2b4143374a253a003666f3c69e776b7e456bdb9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/200318
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-10 22:38:38 +00:00
Brad Fitzpatrick
07b4abd62e all: remove the nacl port (part 2, amd64p32 + toolchain)
This is part two if the nacl removal. Part 1 was CL 199499.

This CL removes amd64p32 support, which might be useful in the future
if we implement the x32 ABI. It also removes the nacl bits in the
toolchain, and some remaining nacl bits.

Updates #30439

Change-Id: I2475d5bb066d1b474e00e40d95b520e7c2e286e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/200077
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-09 22:34:34 +00:00
Brad Fitzpatrick
a38a917aee all: remove the nacl port (part 1)
You were a useful port and you've served your purpose.
Thanks for all the play.

A subsequent CL will remove amd64p32 (including assembly files and
toolchain bits) and remaining bits. The amd64p32 removal will be
separated into its own CL in case we want to support the Linux x32 ABI
in the future and want our old amd64p32 support as a starting point.

Updates #30439

Change-Id: Ia3a0c7d49804adc87bf52a4dea7e3d3007f2b1cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/199499
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-09 06:14:44 +00:00
Brad Fitzpatrick
0fb95e788e crypto/tls: remove NPN support
RELNOTE=yes

Fixes #28362

Change-Id: I43813c0c17bbe6c4cbb4d1f121518c434b3f5aa8
Reviewed-on: https://go-review.googlesource.com/c/go/+/174329
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-10-04 18:07:46 +00:00
Vojtech Bocek
72dc3a0919 crypto/x509: truncate signed hash before DSA signature verification
According to spec, the hash must be truncated, but crypto/dsa
does not do it. We can't fix it in crypto/dsa, because it would break
verification of previously generated signatures.
In crypto/x509 however, go can't generate DSA certs, only verify them,
so the fix here should be safe.

Fixes #22017

Change-Id: Iee7e20a5d76f45da8901a7ca686063639092949f
GitHub-Last-Rev: 8041cde8d2
GitHub-Pull-Request: golang/go#34630
Reviewed-on: https://go-review.googlesource.com/c/go/+/198138
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-10-04 16:27:55 +00:00
W. Trevor King
30d7b64008 crypto/x509: add Detail to Expired errors
Because errors like:

    certificate has expired or is not yet valid

make it difficult to distinguish between "certificate has expired" and
"my local clock is skewed".  Including our idea of the local time
makes it easier to identify the clock-skew case, and including the
violated certificate constraint saves folks the trouble of looking it
up in the target certificate.

Change-Id: I52e0e71705ee36f6afde1bb5a47b9b42ed5ead5b
GitHub-Last-Rev: db2ca4029c
GitHub-Pull-Request: golang/go#34646
Reviewed-on: https://go-review.googlesource.com/c/go/+/198046
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-02 19:23:07 +00:00
chauncyc
cde282dbdd crypto/x509: add IPAddresses to list of template fields used by CreateCertificate
Change-Id: Ifbdf33ee4e413c3edba59b7dbed00ab90698cd35
GitHub-Last-Rev: c3bd33c4cf
GitHub-Pull-Request: golang/go#34277
Reviewed-on: https://go-review.googlesource.com/c/go/+/195157
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-09-30 21:25:36 +00:00
Lynn Boger
d979ac33a2 crypto/cipher: improve xorBytesVSX asm for ppc64x
This improves the performance of xorBytesVSX in crypto/cipher by
unrolling the loop that does the stores. Improvement on power9:

name                 old time/op    new time/op    delta
XORBytes/8Bytes        17.9ns ± 0%    18.2ns ± 0%   +1.53%  (p=0.029 n=4+4)
XORBytes/128Bytes      24.4ns ± 0%    22.5ns ± 0%   -7.79%  (p=0.029 n=4+4)
XORBytes/2048Bytes      131ns ± 0%     109ns ± 0%  -16.79%  (p=0.029 n=4+4)
XORBytes/32768Bytes    1.74µs ± 0%    1.43µs ± 8%  -18.04%  (p=0.029 n=4+4)

Change-Id: I75bd625d3ae9daa7bda54c523028671ab036b13d
Reviewed-on: https://go-review.googlesource.com/c/go/+/197058
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Carlos Eduardo Seo <cseo@linux.vnet.ibm.com>
2019-09-24 21:30:45 +00:00
Lynn Boger
904fdb3757 crypto/aes,crypto/cipher: add asm implementation for aes-gcm on ppc64le
This adds an asm implementation for aes-gcm on ppc64le to improve
performance.

Results on power8:

name                     old time/op    new time/op     delta
AESGCMSeal1K-192           13.4µs ± 0%      3.7µs ± 0%    -72.48%  (p=1.000 n=1+1)
AESGCMOpen1K-192           10.6µs ± 0%      2.9µs ± 0%    -72.97%  (p=1.000 n=1+1)
AESGCMSign8K-192           60.2µs ± 0%      1.3µs ± 0%    -97.88%  (p=1.000 n=1+1)
AESGCMSeal8K-192           80.5µs ± 0%     22.9µs ± 0%    -71.51%  (p=1.000 n=1+1)
AESGCMOpen8K-192           80.5µs ± 0%     21.5µs ± 0%    -73.27%  (p=1.000 n=1+1)

Change-Id: I026bd4f417095a987eda0f521004af90bc964661
Reviewed-on: https://go-review.googlesource.com/c/go/+/191969
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
2019-09-24 16:15:36 +00:00
lukechampine
2dfff3633b crypto/ed25519: outline NewKeyFromSeed and Sign
This allows the returned key/signature to be stack-allocated where possible.

name              old time/op    new time/op    delta
NewKeyFromSeed-4    61.8µs ± 8%    57.2µs ±11%      ~     (p=0.056 n=5+5)
Signing-4           56.6µs ± 3%    67.8µs ±38%      ~     (p=1.000 n=5+5)

name              old alloc/op   new alloc/op   delta
NewKeyFromSeed-4     64.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)
Signing-4             512B ± 0%      448B ± 0%   -12.50%  (p=0.008 n=5+5)

name              old allocs/op  new allocs/op  delta
NewKeyFromSeed-4      1.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
Signing-4             6.00 ± 0%      5.00 ± 0%   -16.67%  (p=0.008 n=5+5)

Change-Id: I7dc6a1b8a483c4b213f380ac7c30cefc5caca0f9
GitHub-Last-Rev: 0dd2e0f93e
GitHub-Pull-Request: golang/go#34357
Reviewed-on: https://go-review.googlesource.com/c/go/+/195980
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-24 10:23:40 +00:00
Andrew Medvedev
37c033b0a5 crypto/x509: give type hint in error message in marshalPublicKey
Currently if type of public key is unsupported, error message is "only
RSA and ECDSA public keys supported". After adding Ed25519 this message
is no longer correct.

Moreover, it is superfluous because documentation for
MarshalPKIXPublicKey, CreateCertificateRequest and CreateCertificate
already lists supported public key types.

This CL removes unnecessary details from error message.
It also adds reporting the type of unsupported key, which helps
debugging cases when struct (instead of a pointer) to otherwise correct
public key is given.

Fixes #32640

Change-Id: I45e6e3d756b543688d850009b4da8a4023c05027
Reviewed-on: https://go-review.googlesource.com/c/go/+/196777
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-09-23 14:57:39 +00:00
Ainar Garipov
51c8d969bd src: gofmt -s
Change-Id: I56d7eeaf777ac30886ee77428ca1ac72b77fbf7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/193849
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-09 18:57:05 +00:00
Ainar Garipov
0efbd10157 all: fix typos
Use the following (suboptimal) script to obtain a list of possible
typos:

  #!/usr/bin/env sh

  set -x

  git ls-files |\
    grep -e '\.\(c\|cc\|go\)$' |\
    xargs -n 1\
    awk\
    '/\/\// { gsub(/.*\/\//, ""); print; } /\/\*/, /\*\// { gsub(/.*\/\*/, ""); gsub(/\*\/.*/, ""); }' |\
    hunspell -d en_US -l |\
    grep '^[[:upper:]]\{0,1\}[[:lower:]]\{1,\}$' |\
    grep -v -e '^.\{1,4\}$' -e '^.\{16,\}$' |\
    sort -f |\
    uniq -c |\
    awk '$1 == 1 { print $2; }'

Then, go through the results manually and fix the most obvious typos in
the non-vendored code.

Change-Id: I3cb5830a176850e1a0584b8a40b47bde7b260eae
Reviewed-on: https://go-review.googlesource.com/c/go/+/193848
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-09-08 17:28:20 +00:00
Filippo Valsorda
1452119867 crypto/x509: remove IsCA exception for broken Entrust root
The exception allowed a specific intermediate [1] to chain up to a
broken root that lacked the CA:TRUE X509v3 Basic Constraint.

The broken root [2] is expiring at the end of 2019, so we can remove the
exception in Go 1.14.

Moreover, there is a reissued version of that root [3] (same Subject and
SPKI, valid CA) which expires in 2029, so root stores should have
migrated to it already, making the exception unnecessary.

[1]: https://crt.sh/?caid=57
[2]: https://crt.sh/?id=1616049
[3]: https://crt.sh/?id=55

Change-Id: I43f51100982791b0e8bac90d143b60851cd46dfc
Reviewed-on: https://go-review.googlesource.com/c/go/+/193038
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-03 21:10:31 +00:00
empijei
89865f8ba6 crypto/x509: allow nil Certificates to be compared in Equal
The current implementation panics on nil certificates,
so introduce a nil check and early return true if both
are nil, false if only one is.

Fixes #28743

Change-Id: I71b0dee3e505d3ad562a4470ccc22c3a2579bc52
Reviewed-on: https://go-review.googlesource.com/c/go/+/167118
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-28 17:13:49 +00:00
Mostyn Bramley-Moore
84198445d4 crypto/ecdsa: improve documentation readability
Include references in the package-level comment block, expand
the obscure IRO acronym, and add a reference for "the standard
(cryptographic) assumptions".

Fixes #33589

Change-Id: I76c3b0a2f7258b3ab4bf1c8e7681c5d159720a20
GitHub-Last-Rev: 30d5a1e2fb
GitHub-Pull-Request: golang/go#33723
Reviewed-on: https://go-review.googlesource.com/c/go/+/190840
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-08-28 16:28:19 +00:00
Filippo Valsorda
a8c2e5c6ad crypto/tls: remove TLS 1.3 opt-out
Fixes #30055

Change-Id: If757c43b52fc7bf62b0afb1c720615329fb5569d
Reviewed-on: https://go-review.googlesource.com/c/go/+/191999
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-08-27 22:25:08 +00:00
Filippo Valsorda
ffcb678f47 crypto/tls: remove SSLv3 support
SSLv3 has been irreparably broken since the POODLE attack 5 years ago
and RFC 7568 (f.k.a. draft-ietf-tls-sslv3-diediedie) prohibits its use
in no uncertain terms.

As announced in the Go 1.13 release notes, remove support for it
entirely in Go 1.14.

Updates #32716

Change-Id: Id653557961d8f75f484a01e6afd2e104a4ccceaf
Reviewed-on: https://go-review.googlesource.com/c/go/+/191976
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-08-27 22:24:05 +00:00
Filippo Valsorda
2ebc3d8157 crypto/tls: make SSLv3 again disabled by default
It was mistakenly re-enabled in CL 146217.

Fixes #33837

Change-Id: I8c0e1787114c6232df5888e51e355906622295bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/191877
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-08-27 20:43:47 +00:00
Filippo Valsorda
5235501c05 crypto/x509: add Ed25519 to ExampleParsePKIXPublicKey
ParsePKIXPublicKey gained Ed25519 support in CL 175478.

Change-Id: I11ffe0a62743292367b3adb103956e61bad57cc4
Reviewed-on: https://go-review.googlesource.com/c/go/+/183243
Reviewed-by: Katie Hockman <katie@golang.org>
2019-07-29 16:52:01 +00:00
Dominik Honnef
c4ca60313e all: change some function documentation to be more idiomatic
Change-Id: I932de9bb061a8ba3332ef03207983e8b98d6f1e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/187918
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-07-28 18:09:57 +00:00
Filippo Valsorda
a6a7b148f8 crypto/tls: deprecate SSLv3 support
Updates #32716

Change-Id: Ia0c03918e8f2da4d9824c49c6d4cfca1b0787b0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/184102
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2019-07-15 23:00:52 +00:00
Filippo Valsorda
20e4540e90 crypto/tls: remove TestVerifyHostnameResumed
Session resumption is not a reliable TLS behavior: the server can decide
to reject a session ticket for a number of reasons, or no reason at all.
This makes this non-hermetic test extremely brittle.

It's currently broken on the builders for both TLS 1.2 and TLS 1.3, and
I could reproduce the issue for TLS 1.3 only. As I was debugging it, it
started passing entirely on my machine.

In practice, it doesn't get us any coverage as resumption is already
tested with the recorded exchange tests, and TestVerifyHostname still
provides a smoke test checking that we can in fact talk TLS.

Fixes #32978

Change-Id: I63505e22ff7704f25ad700d46e4ff14850ba5d3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/186239
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-07-15 20:55:12 +00:00
Russ Cox
623d653db7 crypto/tls: deflake localPipe in tests
The localPipe implementation assumes that every successful net.Dial
results in exactly one successful listener.Accept. I don't believe this
is guaranteed by essentially any operating system. For this test, we're
seeing flakes on dragonfly (#29583).

But see also #19519, flakes due to the same assumption on FreeBSD
and macOS in package net's own tests.

This CL rewrites localPipe to try a few times to get a matching pair
of connections on the dial and accept side.

Fixes #29583.

Change-Id: Idb045b18c404eae457f091df20456c5ae879a291
Reviewed-on: https://go-review.googlesource.com/c/go/+/184157
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-06-29 13:17:15 +00:00
Filippo Valsorda
94aa155432 crypto/x509: normalize and expand docs of Parse and Marshal functions
Change-Id: I8f0e109053bbbd8bde4fa64059fd070d8f4acef2
Reviewed-on: https://go-review.googlesource.com/c/go/+/183117
Reviewed-by: Adam Langley <agl@golang.org>
2019-06-20 19:38:48 +00:00
Filippo Valsorda
ee63782fd6 crypto/tls: reject low-order Curve25519 points
The RFC recommends checking the X25519 output to ensure it's not the
zero value, to guard against peers trying to remove contributory
behavior.

In TLS there should be enough transcript involvement to mitigate any
attack, and the RSA key exchange would suffer from the same issues by
design, so not proposing a backport.

See #31846

Change-Id: I8e657f8ee8aa72c3f8ca3b124555202638c53f5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/183039
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2019-06-20 19:30:01 +00:00
Filippo Valsorda
0884bca05a crypto/tls: move shared code and resources to handshake_test.go
Removed cross-dependencies between handshake_server_test.go and
handshake_client_test.go; moved all initialization to TestMain; replaced
SSLKEYLOGFILE environment variable with -keylog flag.

Change-Id: Ida6712daa44e01a2c00658e8a1896087ee88bcb0
Reviewed-on: https://go-review.googlesource.com/c/go/+/183057
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2019-06-20 19:27:15 +00:00
Filippo Valsorda
0b3a57b537 crypto/tls: disable RSA-PSS in TLS 1.2 again
Signing with RSA-PSS can uncover faulty crypto.Signer implementations,
and it can fail for (broken) small keys. We'll have to take that
breakage eventually, but it would be nice for it to be opt-out at first.

TLS 1.3 requires RSA-PSS and is opt-out in Go 1.13. Instead of making a
TLS 1.3 opt-out influence a TLS 1.2 behavior, let's wait to add RSA-PSS
to TLS 1.2 until TLS 1.3 is on without opt-out.

Note that since the Client Hello is sent before a protocol version is
selected, we have to advertise RSA-PSS there to support TLS 1.3.
That means that we still support RSA-PSS on the client in TLS 1.2 for
verifying server certificates, which is fine, as all issues arise on the
signing side. We have to be careful not to pick (or consider available)
RSA-PSS on the client for client certificates, though.

We'd expect tests to change only in TLS 1.2:

    * the server won't pick PSS to sign the key exchange
      (Server-TLSv12-* w/ RSA, TestHandshakeServerRSAPSS);
    * the server won't advertise PSS in CertificateRequest
      (Server-TLSv12-ClientAuthRequested*, TestClientAuth);
    * and the client won't pick PSS for its CertificateVerify
      (Client-TLSv12-ClientCert-RSA-*, TestHandshakeClientCertRSAPSS,
      Client-TLSv12-Renegotiate* because "R" requests a client cert).

Client-TLSv13-ClientCert-RSA-RSAPSS was updated because of a fix in the test.

This effectively reverts 8834353072.

Testing was made more complex by the undocumented semantics of OpenSSL's
-[client_]sigalgs (see openssl/openssl#9172).

Updates #32425

Change-Id: Iaddeb2df1f5c75cd090cc8321df2ac8e8e7db349
Reviewed-on: https://go-review.googlesource.com/c/go/+/182339
Reviewed-by: Adam Langley <agl@golang.org>
2019-06-19 19:59:14 +00:00
Richard Musiol
c468ad0417 syscall/js: replace TypedArrayOf with CopyBytesToGo/CopyBytesToJS
The typed arrays returned by TypedArrayOf were backed by WebAssembly
memory. They became invalid each time we grow the WebAssembly memory.
This made them very error prone and hard to use correctly.

This change removes TypedArrayOf completely and instead introduces
CopyBytesToGo and CopyBytesToJS for copying bytes between a byte
slice and an Uint8Array. This breaking change is still allowed for
the syscall/js package.

Fixes #31980.
Fixes #31812.

Change-Id: I14c76fdd60b48dd517c1593972a56d04965cb272
Reviewed-on: https://go-review.googlesource.com/c/go/+/177537
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-24 09:38:37 +00:00
bill_ofarrell
7e5bc4775f crypto/ecdsa: implement ecdsa on s390x for P256/P384/P521 using KDSA instruction
Utilize KDSA when available. This guarantees constant time operation on all three curves mentioned,
and is faster than conventional assembly. The IBM Z model(s) that support KDSA as used in this CL
are not yet publicly available, and so we are unable to release performance data at this time.

Change-Id: I85360dcf90fe42d2bf32afe3f638e282de10a518
Reviewed-on: https://go-review.googlesource.com/c/go/+/174437
Run-TryBot: Michael Munday <mike.munday@ibm.com>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
2019-05-24 08:16:32 +00:00
Michael McLoughlin
3ce865d7a0 crypto/sha*: replace putUint{32,64} helpers
Replaces putUint{32,64} functions in crypto/sha* packages with the
equivalent functions encoding/binary.BigEndian.PutUint{32,64}.

Change-Id: I9208d2125202ea9c97777560e6917d21893aced0
Reviewed-on: https://go-review.googlesource.com/c/go/+/156117
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-23 16:16:26 +00:00
Filippo Valsorda
42bb476893 crypto/x509: include roots with empty or multiple policies on macOS
To a fifth reading of the relevant docs, it looks like

1) a constraint dictionary with no policy applies to all of them;
2) multiple applying constraint dictionaries should have their results OR'd;
3) untrusted certificates in the keychain should be used for chain building.

This fixes 1), approximates 2) and punts on 3).

Fixes #30672
Fixes #30471

Change-Id: Ibbaabf0b77d267377c0b5de07abca3445c2c2302
Reviewed-on: https://go-review.googlesource.com/c/go/+/178539
Reviewed-by: Adam Langley <agl@golang.org>
2019-05-22 16:23:17 +00:00
Filippo Valsorda
2326a66878 crypto/x509: fix and cleanup loadSystemRoots on macOS
Note how untrustedData is never NULL, so loadSystemRoots was checking
the wrong thing.

Also, renamed the C function to CopyPEMRoots to follow the
CoreFoundation naming convention on ownership.

Finally, redirect all debug output to standard error.

Change-Id: Ie80abefadf8974a75c0646aa02fcfcebcbe3bde8
Reviewed-on: https://go-review.googlesource.com/c/go/+/178538
Reviewed-by: Adam Langley <agl@golang.org>
2019-05-22 16:20:11 +00:00
Filippo Valsorda
a3d4655c24 crypto/x509: fix value ownership in isSSLPolicy on macOS
CFDictionaryGetValueIfPresent does not take ownership of the value, so
releasing the properties dictionary before passing the value to CFEqual
can crash. Not really clear why this works most of the time.

See https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html

Fixes #28092
Hopefully fixes #30763

Change-Id: I5ee7ca276b753a48abc3aedfb78b8af68b448dd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/178537
Reviewed-by: Adam Langley <agl@golang.org>
2019-05-22 16:12:45 +00:00
Russ Cox
06b0babf31 all: shorten some tests
Shorten some of the longest tests that run during all.bash.
Removes 7r 50u 21s from all.bash.

After this change, all.bash is under 5 minutes again on my laptop.

For #26473.

Change-Id: Ie0460aa935808d65460408feaed210fbaa1d5d79
Reviewed-on: https://go-review.googlesource.com/c/go/+/177559
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-05-22 12:54:00 +00:00
Russ Cox
02fe6ba958 all: remove PEM-encoded private keys from tests
Gerrit is complaining about pushes that affect these files
and forcing people to use -o nokeycheck, which defeats
the point of the check. Hide the keys from this kind of scan
by marking them explicitly as testing keys.

This is a little annoying but better than training everyone
who ever edits one of these test files to reflexively override
the Gerrit check.

The only remaining keys explicitly marked as private instead
of testing are in examples, and there's not much to do
about those. Hopefully they are not edited as much.

Change-Id: I4431592b5266cb39fe6a80b40e742d97da803a0b
Reviewed-on: https://go-review.googlesource.com/c/go/+/178178
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-21 20:03:55 +00:00