typenative 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/node/assert.js +2 -2
- package/bin/node/child_process.js +66 -8
- package/bin/node/fs.js +1012 -4
- package/bin/node/histogram.js +1991 -0
- package/bin/node/process.js +14 -2
- package/bin/node/sqlite.js +1488 -5
- package/bin/node/stream.js +2 -1
- package/bin/node/system_extra.js +3 -270
- package/bin/node/test.js +39 -1
- package/bin/node/test_report.js +47 -1
- package/bin/node/test_run.js +57 -2
- package/bin/node/util.js +8 -5
- package/bin/node/webassembly.js +20 -5
- package/bin/node/webview.js +3257 -244
- package/bin/node/zlib.js +118 -14
- package/bin/node/zlib_iter.js +585 -0
- package/bin/transpiler.js +1370 -258
- package/bin/version.js +1 -1
- package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
- package/package.json +10 -1
- package/types/tsconfig.json +17 -0
- package/types/typenative-npm.d.ts +492 -12
- package/types/typenative.d.ts +88 -2
- package/.gitattributes +0 -1
- package/.github/workflows/ci.yml +0 -68
- package/.github/workflows/npm-publish-github-packages.yml +0 -88
- package/CHANGELOG.md +0 -1746
- package/CONTRIBUTION.md +0 -133
- package/conformance.md +0 -1497
- package/examples/README.md +0 -114
- package/examples/angular-templates/README.md +0 -141
- package/examples/angular-templates/bench.mjs +0 -173
- package/examples/angular-templates/dom-type-globals.d.ts +0 -21
- package/examples/angular-templates/dom-type-stubs.ts +0 -21
- package/examples/angular-templates/main.ts +0 -135
- package/examples/angular-templates/parity.mjs +0 -157
- package/examples/angular-templates/run-node.mjs +0 -69
- package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
- package/examples/desktop-notes/README.md +0 -106
- package/examples/desktop-notes/bench.mjs +0 -125
- package/examples/desktop-notes/main.ts +0 -131
- package/examples/desktop-notes/package-lock.json +0 -726
- package/examples/desktop-notes/package.json +0 -9
- package/examples/desktop-notes/ui.ts +0 -176
- package/examples/dupe-finder/README.md +0 -78
- package/examples/dupe-finder/bench.mjs +0 -120
- package/examples/dupe-finder/main.ts +0 -87
- package/examples/fibonacci/README.md +0 -89
- package/examples/fibonacci/bench.mjs +0 -87
- package/examples/fibonacci/main.ts +0 -21
- package/examples/hello-world/README.md +0 -62
- package/examples/hello-world/bench.mjs +0 -66
- package/examples/hello-world/main.ts +0 -7
- package/examples/json-server/README.md +0 -132
- package/examples/json-server/bench.mjs +0 -263
- package/examples/json-server/main.ts +0 -67
- package/examples/mandelbrot-png/README.md +0 -63
- package/examples/mandelbrot-png/bench.mjs +0 -95
- package/examples/mandelbrot-png/main.ts +0 -98
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +0 -174
- package/examples/marked-cli/bench.mjs +0 -178
- package/examples/marked-cli/main.ts +0 -410
- package/examples/marked-cli/parity.mjs +0 -185
- package/examples/marked-cli/vendor/marked/LICENSE +0 -44
- package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
- package/examples/openai-chat/README.md +0 -148
- package/examples/openai-chat/bench.mjs +0 -175
- package/examples/openai-chat/main.ts +0 -488
- package/examples/react-compiler/README.md +0 -185
- package/examples/react-compiler/bench.mjs +0 -181
- package/examples/react-compiler/main.ts +0 -324
- package/examples/react-compiler/parity.mjs +0 -362
- package/examples/react-compiler/run-node.mjs +0 -90
- package/examples/react-compiler/vendor/babel/LICENSE +0 -22
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
- package/examples/react-compiler/vendor/charcodes/package.json +0 -25
- package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
- package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
- package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
- package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
- package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
- package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
- package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
- package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
- package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
- package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
- package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
- package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
- package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
- package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
- package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
- package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
- package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
- package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
- package/examples/react-compiler/vendor/zod/LICENSE +0 -21
- package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
- package/examples/react-compiler/vendor.mjs +0 -688
- package/examples/todo-cli/README.md +0 -69
- package/examples/todo-cli/bench.mjs +0 -89
- package/examples/todo-cli/main.ts +0 -92
- package/examples/yaml-cli/README.md +0 -152
- package/examples/yaml-cli/bench.mjs +0 -265
- package/examples/yaml-cli/main.ts +0 -251
- package/examples/yaml-cli/parity.mjs +0 -156
- package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
- package/performance/README.md +0 -248
- package/performance/any-dynamic.ts +0 -21
- package/performance/any-record-view.ts +0 -20
- package/performance/arr-for-of.ts +0 -29
- package/performance/arr-hof.ts +0 -21
- package/performance/arr-push-index.ts +0 -15
- package/performance/arr-push-local.ts +0 -39
- package/performance/arr-slice-concat.ts +0 -24
- package/performance/arr-sort.ts +0 -21
- package/performance/async-await.ts +0 -24
- package/performance/async-promise-all.ts +0 -38
- package/performance/bigint-arith.ts +0 -36
- package/performance/buf-encode.ts +0 -29
- package/performance/class-accessors.ts +0 -48
- package/performance/class-dispatch.ts +0 -52
- package/performance/date-format.ts +0 -18
- package/performance/events-emit.ts +0 -27
- package/performance/exc-throw-rare.ts +0 -25
- package/performance/exc-try-catch.ts +0 -26
- package/performance/fn-closures.ts +0 -29
- package/performance/fn-recursion-tree.ts +0 -31
- package/performance/fn-rest-spread.ts +0 -43
- package/performance/gen-for-of.ts +0 -46
- package/performance/gen-next.ts +0 -32
- package/performance/iter-helpers.ts +0 -38
- package/performance/json-any.ts +0 -30
- package/performance/json-roundtrip.ts +0 -27
- package/performance/map-delete.ts +0 -24
- package/performance/map-iterate.ts +0 -26
- package/performance/map-number-keys.ts +0 -37
- package/performance/map-string-keys.ts +0 -22
- package/performance/num-arith-loop.ts +0 -14
- package/performance/num-bitwise.ts +0 -21
- package/performance/num-hash-imul.ts +0 -36
- package/performance/num-mod-int.ts +0 -16
- package/performance/num-to-string.ts +0 -16
- package/performance/obj-alloc.ts +0 -32
- package/performance/obj-keys-entries.ts +0 -44
- package/performance/obj-optional-chain.ts +0 -42
- package/performance/obj-record-dict.ts +0 -24
- package/performance/obj-spread-destructure.ts +0 -40
- package/performance/regex-exec.ts +0 -29
- package/performance/regex-replace-fn.ts +0 -24
- package/performance/regex-site.ts +0 -28
- package/performance/set-ops.ts +0 -20
- package/performance/str-char-scan.ts +0 -35
- package/performance/str-concat-plus.ts +0 -18
- package/performance/str-concat.ts +0 -24
- package/performance/str-methods.ts +0 -24
- package/performance/str-short-scan.ts +0 -26
- package/performance/str-split-join.ts +0 -23
- package/performance/str-switch-compare.ts +0 -50
- package/performance/str-template.ts +0 -16
- package/performance/str-unicode.ts +0 -25
- package/performance/typed-array.ts +0 -30
- package/performance/union-switch.ts +0 -57
- package/performance/union-typeof.ts +0 -40
- package/performance/wasm-call.ts +0 -63
- package/tsparser/check.go +0 -158
- package/tsparser/go.mod +0 -14
- package/tsparser/go.sum +0 -22
- package/tsparser/main.go +0 -363
- package/tsparser/tsparser.exe +0 -4
package/bin/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by scripts/gen-version.mjs — do not edit.
|
|
2
|
-
export const VERSION = '0.7.
|
|
2
|
+
export const VERSION = '0.7.1';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Treat all files in this repo as binary, with no git magic updating
|
|
2
|
+
# line endings. Windows users contributing to Go will need to use a
|
|
3
|
+
# modern version of git and editors capable of LF line endings.
|
|
4
|
+
#
|
|
5
|
+
# We'll prevent accidental CRLF line endings from entering the repo
|
|
6
|
+
# via the git-review gofmt checks.
|
|
7
|
+
#
|
|
8
|
+
# See golang.org/issue/9281
|
|
9
|
+
|
|
10
|
+
* -text
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Copyright (c) 2015, 2018, 2019 Opsmate, Inc. All rights reserved.
|
|
2
|
+
Copyright (c) 2009 The Go Authors. All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are
|
|
6
|
+
met:
|
|
7
|
+
|
|
8
|
+
* Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
* Redistributions in binary form must reproduce the above
|
|
11
|
+
copyright notice, this list of conditions and the following disclaimer
|
|
12
|
+
in the documentation and/or other materials provided with the
|
|
13
|
+
distribution.
|
|
14
|
+
* Neither the name of Google Inc. nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
19
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
20
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
21
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
22
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
23
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
24
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
25
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
26
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# package pkcs12
|
|
2
|
+
|
|
3
|
+
[](https://pkg.go.dev/software.sslmate.com/src/go-pkcs12)
|
|
4
|
+
|
|
5
|
+
import "software.sslmate.com/src/go-pkcs12"
|
|
6
|
+
|
|
7
|
+
Package pkcs12 implements some of PKCS#12 (also known as P12 or PFX).
|
|
8
|
+
It is intended for decoding DER-encoded P12/PFX files for use with the `crypto/tls`
|
|
9
|
+
package, and for encoding P12/PFX files for use by legacy applications which
|
|
10
|
+
do not support newer formats. Since PKCS#12 uses weak encryption
|
|
11
|
+
primitives, it SHOULD NOT be used for new applications.
|
|
12
|
+
|
|
13
|
+
Note that only DER-encoded PKCS#12 files are supported, even though PKCS#12
|
|
14
|
+
allows BER encoding. This is because encoding/asn1 only supports DER.
|
|
15
|
+
|
|
16
|
+
This package is forked from `golang.org/x/crypto/pkcs12`, which is frozen.
|
|
17
|
+
The implementation is distilled from https://tools.ietf.org/html/rfc7292
|
|
18
|
+
and referenced documents.
|
|
19
|
+
|
|
20
|
+
## Import Path
|
|
21
|
+
|
|
22
|
+
Note that although the source code and issue tracker for this package are hosted
|
|
23
|
+
on GitHub, the import path is:
|
|
24
|
+
|
|
25
|
+
software.sslmate.com/src/go-pkcs12
|
|
26
|
+
|
|
27
|
+
Please be sure to use this path when you `go get` and `import` this package.
|
|
28
|
+
|
|
29
|
+
## Report Issues / Send Patches
|
|
30
|
+
|
|
31
|
+
Open an issue or PR at https://github.com/SSLMate/go-pkcs12
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright 2015 The Go Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
package pkcs12
|
|
6
|
+
|
|
7
|
+
import (
|
|
8
|
+
"errors"
|
|
9
|
+
"unicode/utf16"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// bmpStringZeroTerminated returns s encoded in UCS-2 with a zero terminator.
|
|
13
|
+
func bmpStringZeroTerminated(s string) ([]byte, error) {
|
|
14
|
+
// References:
|
|
15
|
+
// https://tools.ietf.org/html/rfc7292#appendix-B.1
|
|
16
|
+
// The above RFC provides the info that BMPStrings are NULL terminated.
|
|
17
|
+
|
|
18
|
+
ret, err := bmpString(s)
|
|
19
|
+
if err != nil {
|
|
20
|
+
return nil, err
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return append(ret, 0, 0), nil
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// bmpString returns s encoded in UCS-2
|
|
27
|
+
func bmpString(s string) ([]byte, error) {
|
|
28
|
+
// References:
|
|
29
|
+
// https://tools.ietf.org/html/rfc7292#appendix-B.1
|
|
30
|
+
// https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane
|
|
31
|
+
// - non-BMP characters are encoded in UTF 16 by using a surrogate pair of 16-bit codes
|
|
32
|
+
// EncodeRune returns 0xfffd if the rune does not need special encoding
|
|
33
|
+
|
|
34
|
+
ret := make([]byte, 0, 2*len(s)+2)
|
|
35
|
+
|
|
36
|
+
for _, r := range s {
|
|
37
|
+
if t, _ := utf16.EncodeRune(r); t != 0xfffd {
|
|
38
|
+
return nil, errors.New("pkcs12: string contains characters that cannot be encoded in UCS-2")
|
|
39
|
+
}
|
|
40
|
+
ret = append(ret, byte(r/256), byte(r%256))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return ret, nil
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
func decodeBMPString(bmpString []byte) (string, error) {
|
|
47
|
+
if len(bmpString)%2 != 0 {
|
|
48
|
+
return "", errors.New("pkcs12: odd-length BMP string")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// strip terminator if present
|
|
52
|
+
if l := len(bmpString); l >= 2 && bmpString[l-1] == 0 && bmpString[l-2] == 0 {
|
|
53
|
+
bmpString = bmpString[:l-2]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
s := make([]uint16, 0, len(bmpString)/2)
|
|
57
|
+
for len(bmpString) > 0 {
|
|
58
|
+
s = append(s, uint16(bmpString[0])<<8+uint16(bmpString[1]))
|
|
59
|
+
bmpString = bmpString[2:]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return string(utf16.Decode(s)), nil
|
|
63
|
+
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// Copyright 2015, 2018, 2019 Opsmate, Inc. All rights reserved.
|
|
2
|
+
// Copyright 2015 The Go Authors. All rights reserved.
|
|
3
|
+
// Use of this source code is governed by a BSD-style
|
|
4
|
+
// license that can be found in the LICENSE file.
|
|
5
|
+
|
|
6
|
+
package pkcs12
|
|
7
|
+
|
|
8
|
+
import (
|
|
9
|
+
"bytes"
|
|
10
|
+
"crypto/aes"
|
|
11
|
+
"crypto/cipher"
|
|
12
|
+
"crypto/des"
|
|
13
|
+
"crypto/sha1"
|
|
14
|
+
"crypto/sha256"
|
|
15
|
+
"crypto/sha512"
|
|
16
|
+
"crypto/x509/pkix"
|
|
17
|
+
"encoding/asn1"
|
|
18
|
+
"errors"
|
|
19
|
+
"fmt"
|
|
20
|
+
"hash"
|
|
21
|
+
"io"
|
|
22
|
+
|
|
23
|
+
"golang.org/x/crypto/pbkdf2"
|
|
24
|
+
"software.sslmate.com/src/go-pkcs12/internal/rc2"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
var (
|
|
28
|
+
oidPBEWithSHAAnd3KeyTripleDESCBC = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 1, 3})
|
|
29
|
+
oidPBEWithSHAAnd128BitRC2CBC = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 1, 5})
|
|
30
|
+
oidPBEWithSHAAnd40BitRC2CBC = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 1, 6})
|
|
31
|
+
oidPBES2 = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 5, 13})
|
|
32
|
+
oidPBKDF2 = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 5, 12})
|
|
33
|
+
oidHmacWithSHA1 = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 2, 7})
|
|
34
|
+
oidHmacWithSHA256 = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 2, 9})
|
|
35
|
+
oidHmacWithSHA512 = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 2, 11})
|
|
36
|
+
oidAES128CBC = asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 1, 2})
|
|
37
|
+
oidAES192CBC = asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 1, 22})
|
|
38
|
+
oidAES256CBC = asn1.ObjectIdentifier([]int{2, 16, 840, 1, 101, 3, 4, 1, 42})
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
// pbeCipher is an abstraction of a PKCS#12 cipher.
|
|
42
|
+
type pbeCipher interface {
|
|
43
|
+
// create returns a cipher.Block given a key.
|
|
44
|
+
create(key []byte) (cipher.Block, error)
|
|
45
|
+
// deriveKey returns a key derived from the given password and salt.
|
|
46
|
+
deriveKey(salt, password []byte, iterations int) []byte
|
|
47
|
+
// deriveKey returns an IV derived from the given password and salt.
|
|
48
|
+
deriveIV(salt, password []byte, iterations int) []byte
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type shaWithTripleDESCBC struct{}
|
|
52
|
+
|
|
53
|
+
func (shaWithTripleDESCBC) create(key []byte) (cipher.Block, error) {
|
|
54
|
+
return des.NewTripleDESCipher(key)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func (shaWithTripleDESCBC) deriveKey(salt, password []byte, iterations int) []byte {
|
|
58
|
+
return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 1, 24)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func (shaWithTripleDESCBC) deriveIV(salt, password []byte, iterations int) []byte {
|
|
62
|
+
return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 2, 8)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type shaWith128BitRC2CBC struct{}
|
|
66
|
+
|
|
67
|
+
func (shaWith128BitRC2CBC) create(key []byte) (cipher.Block, error) {
|
|
68
|
+
return rc2.New(key, len(key)*8)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
func (shaWith128BitRC2CBC) deriveKey(salt, password []byte, iterations int) []byte {
|
|
72
|
+
return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 1, 16)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
func (shaWith128BitRC2CBC) deriveIV(salt, password []byte, iterations int) []byte {
|
|
76
|
+
return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 2, 8)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type shaWith40BitRC2CBC struct{}
|
|
80
|
+
|
|
81
|
+
func (shaWith40BitRC2CBC) create(key []byte) (cipher.Block, error) {
|
|
82
|
+
return rc2.New(key, len(key)*8)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func (shaWith40BitRC2CBC) deriveKey(salt, password []byte, iterations int) []byte {
|
|
86
|
+
return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 1, 5)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
func (shaWith40BitRC2CBC) deriveIV(salt, password []byte, iterations int) []byte {
|
|
90
|
+
return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 2, 8)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type pbeParams struct {
|
|
94
|
+
Salt []byte
|
|
95
|
+
Iterations int
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
func pbeCipherFor(algorithm pkix.AlgorithmIdentifier, password []byte) (cipher.Block, []byte, error) {
|
|
99
|
+
var cipherType pbeCipher
|
|
100
|
+
|
|
101
|
+
switch {
|
|
102
|
+
case algorithm.Algorithm.Equal(oidPBEWithSHAAnd3KeyTripleDESCBC):
|
|
103
|
+
cipherType = shaWithTripleDESCBC{}
|
|
104
|
+
case algorithm.Algorithm.Equal(oidPBEWithSHAAnd128BitRC2CBC):
|
|
105
|
+
cipherType = shaWith128BitRC2CBC{}
|
|
106
|
+
case algorithm.Algorithm.Equal(oidPBEWithSHAAnd40BitRC2CBC):
|
|
107
|
+
cipherType = shaWith40BitRC2CBC{}
|
|
108
|
+
case algorithm.Algorithm.Equal(oidPBES2):
|
|
109
|
+
// rfc7292#appendix-B.1 (the original PKCS#12 PBE) requires passwords formatted as BMPStrings.
|
|
110
|
+
// However, rfc8018#section-3 recommends that the password for PBES2 follow ASCII or UTF-8.
|
|
111
|
+
// This is also what Windows expects.
|
|
112
|
+
// Therefore, we convert the password to UTF-8.
|
|
113
|
+
originalPassword, err := decodeBMPString(password)
|
|
114
|
+
if err != nil {
|
|
115
|
+
return nil, nil, err
|
|
116
|
+
}
|
|
117
|
+
utf8Password := []byte(originalPassword)
|
|
118
|
+
return pbes2CipherFor(algorithm, utf8Password)
|
|
119
|
+
default:
|
|
120
|
+
return nil, nil, NotImplementedError("pbe algorithm " + algorithm.Algorithm.String() + " is not supported")
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var params pbeParams
|
|
124
|
+
if err := unmarshal(algorithm.Parameters.FullBytes, ¶ms); err != nil {
|
|
125
|
+
return nil, nil, err
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
key := cipherType.deriveKey(params.Salt, password, params.Iterations)
|
|
129
|
+
iv := cipherType.deriveIV(params.Salt, password, params.Iterations)
|
|
130
|
+
|
|
131
|
+
block, err := cipherType.create(key)
|
|
132
|
+
if err != nil {
|
|
133
|
+
return nil, nil, err
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return block, iv, nil
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
func pbDecrypterFor(algorithm pkix.AlgorithmIdentifier, password []byte) (cipher.BlockMode, int, error) {
|
|
140
|
+
block, iv, err := pbeCipherFor(algorithm, password)
|
|
141
|
+
if err != nil {
|
|
142
|
+
return nil, 0, err
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return cipher.NewCBCDecrypter(block, iv), block.BlockSize(), nil
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
func pbDecrypt(info decryptable, password []byte) (decrypted []byte, err error) {
|
|
149
|
+
cbc, blockSize, err := pbDecrypterFor(info.Algorithm(), password)
|
|
150
|
+
if err != nil {
|
|
151
|
+
return nil, err
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
encrypted := info.Data()
|
|
155
|
+
if len(encrypted) == 0 {
|
|
156
|
+
return nil, errors.New("pkcs12: empty encrypted data")
|
|
157
|
+
}
|
|
158
|
+
if len(encrypted)%blockSize != 0 {
|
|
159
|
+
return nil, errors.New("pkcs12: input is not a multiple of the block size")
|
|
160
|
+
}
|
|
161
|
+
decrypted = make([]byte, len(encrypted))
|
|
162
|
+
cbc.CryptBlocks(decrypted, encrypted)
|
|
163
|
+
|
|
164
|
+
psLen := int(decrypted[len(decrypted)-1])
|
|
165
|
+
if psLen == 0 || psLen > blockSize {
|
|
166
|
+
return nil, ErrDecryption
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if len(decrypted) < psLen {
|
|
170
|
+
return nil, ErrDecryption
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
ps := decrypted[len(decrypted)-psLen:]
|
|
174
|
+
decrypted = decrypted[:len(decrypted)-psLen]
|
|
175
|
+
if bytes.Compare(ps, bytes.Repeat([]byte{byte(psLen)}, psLen)) != 0 {
|
|
176
|
+
return nil, ErrDecryption
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// PBES2-params ::= SEQUENCE {
|
|
183
|
+
// keyDerivationFunc AlgorithmIdentifier {{PBES2-KDFs}},
|
|
184
|
+
// encryptionScheme AlgorithmIdentifier {{PBES2-Encs}}
|
|
185
|
+
// }
|
|
186
|
+
type pbes2Params struct {
|
|
187
|
+
Kdf pkix.AlgorithmIdentifier
|
|
188
|
+
EncryptionScheme pkix.AlgorithmIdentifier
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// PBKDF2-params ::= SEQUENCE {
|
|
192
|
+
// salt CHOICE {
|
|
193
|
+
// specified OCTET STRING,
|
|
194
|
+
// otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
|
|
195
|
+
// },
|
|
196
|
+
// iterationCount INTEGER (1..MAX),
|
|
197
|
+
// keyLength INTEGER (1..MAX) OPTIONAL,
|
|
198
|
+
// prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT
|
|
199
|
+
// algid-hmacWithSHA1
|
|
200
|
+
// }
|
|
201
|
+
type pbkdf2Params struct {
|
|
202
|
+
Salt asn1.RawValue
|
|
203
|
+
Iterations int
|
|
204
|
+
KeyLength int `asn1:"optional"`
|
|
205
|
+
Prf pkix.AlgorithmIdentifier `asn1:"optional"`
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
func pbes2CipherFor(algorithm pkix.AlgorithmIdentifier, password []byte) (cipher.Block, []byte, error) {
|
|
209
|
+
var params pbes2Params
|
|
210
|
+
if err := unmarshal(algorithm.Parameters.FullBytes, ¶ms); err != nil {
|
|
211
|
+
return nil, nil, err
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if !params.Kdf.Algorithm.Equal(oidPBKDF2) {
|
|
215
|
+
return nil, nil, NotImplementedError("pbes2 kdf algorithm " + params.Kdf.Algorithm.String() + " is not supported")
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
var kdfParams pbkdf2Params
|
|
219
|
+
if err := unmarshal(params.Kdf.Parameters.FullBytes, &kdfParams); err != nil {
|
|
220
|
+
return nil, nil, err
|
|
221
|
+
}
|
|
222
|
+
if kdfParams.Salt.Tag != asn1.TagOctetString {
|
|
223
|
+
return nil, nil, NotImplementedError("only octet string salts are supported for pbes2/pbkdf2")
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
var prf func() hash.Hash
|
|
227
|
+
switch {
|
|
228
|
+
case kdfParams.Prf.Algorithm.Equal(oidHmacWithSHA256):
|
|
229
|
+
prf = sha256.New
|
|
230
|
+
case kdfParams.Prf.Algorithm.Equal(oidHmacWithSHA512):
|
|
231
|
+
prf = sha512.New
|
|
232
|
+
case kdfParams.Prf.Algorithm.Equal(oidHmacWithSHA1):
|
|
233
|
+
prf = sha1.New
|
|
234
|
+
case kdfParams.Prf.Algorithm == nil:
|
|
235
|
+
// Algorithm not specified; defaults to SHA1 according to ASN1 definition
|
|
236
|
+
prf = sha1.New
|
|
237
|
+
default:
|
|
238
|
+
return nil, nil, NotImplementedError("pbes2 prf " + kdfParams.Prf.Algorithm.String() + " is not supported")
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
var keyLen int
|
|
242
|
+
switch {
|
|
243
|
+
case params.EncryptionScheme.Algorithm.Equal(oidAES256CBC):
|
|
244
|
+
keyLen = 32
|
|
245
|
+
case params.EncryptionScheme.Algorithm.Equal(oidAES192CBC):
|
|
246
|
+
keyLen = 24
|
|
247
|
+
case params.EncryptionScheme.Algorithm.Equal(oidAES128CBC):
|
|
248
|
+
keyLen = 16
|
|
249
|
+
default:
|
|
250
|
+
return nil, nil, NotImplementedError("pbes2 algorithm " + params.EncryptionScheme.Algorithm.String() + " is not supported")
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
key := pbkdf2.Key(password, kdfParams.Salt.Bytes, kdfParams.Iterations, keyLen, prf)
|
|
254
|
+
iv := params.EncryptionScheme.Parameters.Bytes
|
|
255
|
+
|
|
256
|
+
block, err := aes.NewCipher(key)
|
|
257
|
+
if err != nil {
|
|
258
|
+
return nil, nil, err
|
|
259
|
+
}
|
|
260
|
+
if len(iv) != block.BlockSize() {
|
|
261
|
+
return nil, nil, fmt.Errorf("pkcs12: invalid IV length in PBES2 encryption scheme (IV length %d does not match block size %d)", len(iv), block.BlockSize())
|
|
262
|
+
}
|
|
263
|
+
return block, iv, nil
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// decryptable abstracts an object that contains ciphertext.
|
|
267
|
+
type decryptable interface {
|
|
268
|
+
Algorithm() pkix.AlgorithmIdentifier
|
|
269
|
+
Data() []byte
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
func pbEncrypterFor(algorithm pkix.AlgorithmIdentifier, password []byte) (cipher.BlockMode, int, error) {
|
|
273
|
+
block, iv, err := pbeCipherFor(algorithm, password)
|
|
274
|
+
if err != nil {
|
|
275
|
+
return nil, 0, err
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return cipher.NewCBCEncrypter(block, iv), block.BlockSize(), nil
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
func pbEncrypt(info encryptable, decrypted []byte, password []byte) error {
|
|
282
|
+
cbc, blockSize, err := pbEncrypterFor(info.Algorithm(), password)
|
|
283
|
+
if err != nil {
|
|
284
|
+
return err
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
psLen := blockSize - len(decrypted)%blockSize
|
|
288
|
+
encrypted := make([]byte, len(decrypted)+psLen)
|
|
289
|
+
copy(encrypted[:len(decrypted)], decrypted)
|
|
290
|
+
copy(encrypted[len(decrypted):], bytes.Repeat([]byte{byte(psLen)}, psLen))
|
|
291
|
+
cbc.CryptBlocks(encrypted, encrypted)
|
|
292
|
+
|
|
293
|
+
info.SetData(encrypted)
|
|
294
|
+
|
|
295
|
+
return nil
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// encryptable abstracts a object that contains ciphertext.
|
|
299
|
+
type encryptable interface {
|
|
300
|
+
Algorithm() pkix.AlgorithmIdentifier
|
|
301
|
+
SetData([]byte)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
func makePBES2Parameters(rand io.Reader, salt []byte, iterations int) ([]byte, error) {
|
|
305
|
+
var err error
|
|
306
|
+
|
|
307
|
+
randomIV := make([]byte, 16)
|
|
308
|
+
if _, err := rand.Read(randomIV); err != nil {
|
|
309
|
+
return nil, err
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
var kdfparams pbkdf2Params
|
|
313
|
+
if kdfparams.Salt.FullBytes, err = asn1.Marshal(salt); err != nil {
|
|
314
|
+
return nil, err
|
|
315
|
+
}
|
|
316
|
+
kdfparams.Iterations = iterations
|
|
317
|
+
kdfparams.Prf.Algorithm = oidHmacWithSHA256
|
|
318
|
+
kdfparams.Prf.Parameters = asn1.NullRawValue
|
|
319
|
+
|
|
320
|
+
var params pbes2Params
|
|
321
|
+
params.Kdf.Algorithm = oidPBKDF2
|
|
322
|
+
if params.Kdf.Parameters.FullBytes, err = asn1.Marshal(kdfparams); err != nil {
|
|
323
|
+
return nil, err
|
|
324
|
+
}
|
|
325
|
+
params.EncryptionScheme.Algorithm = oidAES256CBC
|
|
326
|
+
if params.EncryptionScheme.Parameters.FullBytes, err = asn1.Marshal(randomIV); err != nil {
|
|
327
|
+
return nil, err
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return asn1.Marshal(params)
|
|
331
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2015 The Go Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
package pkcs12
|
|
6
|
+
|
|
7
|
+
import "errors"
|
|
8
|
+
|
|
9
|
+
var (
|
|
10
|
+
// ErrDecryption represents a failure to decrypt the input.
|
|
11
|
+
ErrDecryption = errors.New("pkcs12: decryption error, incorrect padding")
|
|
12
|
+
|
|
13
|
+
// ErrIncorrectPassword is returned when an incorrect password is detected.
|
|
14
|
+
// Usually, P12/PFX data is signed to be able to verify the password.
|
|
15
|
+
ErrIncorrectPassword = errors.New("pkcs12: decryption password incorrect")
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
// NotImplementedError indicates that the input is not currently supported.
|
|
19
|
+
type NotImplementedError string
|
|
20
|
+
|
|
21
|
+
func (e NotImplementedError) Error() string {
|
|
22
|
+
return "pkcs12: " + string(e)
|
|
23
|
+
}
|