@blazetrails/ruby-compat 0.0.0-stage → 0.1.0-alpha0.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/LICENSE +21 -0
- package/NOTICE +6 -0
- package/README.md +440 -2
- package/dist/argument-error.d.ts +15 -0
- package/dist/argument-error.js +15 -0
- package/dist/argument-error.js.map +1 -0
- package/dist/array.d.ts +415 -0
- package/dist/array.js +1330 -0
- package/dist/array.js.map +1 -0
- package/dist/async-context-adapter.d.ts +19 -0
- package/dist/async-context-adapter.js +139 -0
- package/dist/async-context-adapter.js.map +1 -0
- package/dist/backtrace-location.d.ts +77 -0
- package/dist/backtrace-location.js +155 -0
- package/dist/backtrace-location.js.map +1 -0
- package/dist/base64.d.ts +73 -0
- package/dist/base64.js +164 -0
- package/dist/base64.js.map +1 -0
- package/dist/benchmark.d.ts +19 -0
- package/dist/benchmark.js +16 -0
- package/dist/benchmark.js.map +1 -0
- package/dist/big-decimal.d.ts +110 -0
- package/dist/big-decimal.js +582 -0
- package/dist/big-decimal.js.map +1 -0
- package/dist/bundler.d.ts +44 -0
- package/dist/bundler.js +101 -0
- package/dist/bundler.js.map +1 -0
- package/dist/cgi.d.ts +89 -0
- package/dist/cgi.js +168 -0
- package/dist/cgi.js.map +1 -0
- package/dist/child-process-adapter.d.ts +110 -0
- package/dist/child-process-adapter.js +272 -0
- package/dist/child-process-adapter.js.map +1 -0
- package/dist/class-module.d.ts +10 -0
- package/dist/class-module.js +10 -0
- package/dist/class-module.js.map +1 -0
- package/dist/classpath.d.ts +90 -0
- package/dist/classpath.js +207 -0
- package/dist/classpath.js.map +1 -0
- package/dist/closed-queue-error.d.ts +10 -0
- package/dist/closed-queue-error.js +10 -0
- package/dist/closed-queue-error.js.map +1 -0
- package/dist/comparable.d.ts +127 -0
- package/dist/comparable.js +376 -0
- package/dist/comparable.js.map +1 -0
- package/dist/complex.d.ts +48 -0
- package/dist/complex.js +162 -0
- package/dist/complex.js.map +1 -0
- package/dist/concurrent/atomic-boolean.d.ts +24 -0
- package/dist/concurrent/atomic-boolean.js +43 -0
- package/dist/concurrent/atomic-boolean.js.map +1 -0
- package/dist/concurrent/atomic-fixnum.d.ts +21 -0
- package/dist/concurrent/atomic-fixnum.js +35 -0
- package/dist/concurrent/atomic-fixnum.js.map +1 -0
- package/dist/concurrent/count-down-latch.d.ts +20 -0
- package/dist/concurrent/count-down-latch.js +50 -0
- package/dist/concurrent/count-down-latch.js.map +1 -0
- package/dist/concurrent/cyclic-barrier.d.ts +18 -0
- package/dist/concurrent/cyclic-barrier.js +50 -0
- package/dist/concurrent/cyclic-barrier.js.map +1 -0
- package/dist/concurrent/event.d.ts +19 -0
- package/dist/concurrent/event.js +31 -0
- package/dist/concurrent/event.js.map +1 -0
- package/dist/concurrent/map.d.ts +149 -0
- package/dist/concurrent/map.js +202 -0
- package/dist/concurrent/map.js.map +1 -0
- package/dist/concurrent/read-write-lock.d.ts +25 -0
- package/dist/concurrent/read-write-lock.js +70 -0
- package/dist/concurrent/read-write-lock.js.map +1 -0
- package/dist/concurrent/semaphore.d.ts +24 -0
- package/dist/concurrent/semaphore.js +74 -0
- package/dist/concurrent/semaphore.js.map +1 -0
- package/dist/concurrent/timer-task.d.ts +52 -0
- package/dist/concurrent/timer-task.js +112 -0
- package/dist/concurrent/timer-task.js.map +1 -0
- package/dist/constants.generated.d.ts +2 -0
- package/dist/constants.generated.js +64 -0
- package/dist/constants.generated.js.map +1 -0
- package/dist/converter-not-found-error.d.ts +14 -0
- package/dist/converter-not-found-error.js +14 -0
- package/dist/converter-not-found-error.js.map +1 -0
- package/dist/crypto-adapter.d.ts +64 -0
- package/dist/crypto-adapter.js +365 -0
- package/dist/crypto-adapter.js.map +1 -0
- package/dist/delegate.d.ts +156 -0
- package/dist/delegate.js +306 -0
- package/dist/delegate.js.map +1 -0
- package/dist/digest.d.ts +99 -0
- package/dist/digest.js +131 -0
- package/dist/digest.js.map +1 -0
- package/dist/dir.d.ts +218 -0
- package/dist/dir.js +599 -0
- package/dist/dir.js.map +1 -0
- package/dist/encoding-error.d.ts +14 -0
- package/dist/encoding-error.js +17 -0
- package/dist/encoding-error.js.map +1 -0
- package/dist/encoding.d.ts +121 -0
- package/dist/encoding.js +306 -0
- package/dist/encoding.js.map +1 -0
- package/dist/ensure.d.ts +15 -0
- package/dist/ensure.js +35 -0
- package/dist/ensure.js.map +1 -0
- package/dist/enumerable.d.ts +375 -0
- package/dist/enumerable.js +1100 -0
- package/dist/enumerable.js.map +1 -0
- package/dist/enumerator.d.ts +321 -0
- package/dist/enumerator.js +642 -0
- package/dist/enumerator.js.map +1 -0
- package/dist/eof-error.d.ts +14 -0
- package/dist/eof-error.js +14 -0
- package/dist/eof-error.js.map +1 -0
- package/dist/errno.d.ts +327 -0
- package/dist/errno.js +452 -0
- package/dist/errno.js.map +1 -0
- package/dist/exc-detailed-message.d.ts +15 -0
- package/dist/exc-detailed-message.js +106 -0
- package/dist/exc-detailed-message.js.map +1 -0
- package/dist/exc-to-s.d.ts +10 -0
- package/dist/exc-to-s.js +21 -0
- package/dist/exc-to-s.js.map +1 -0
- package/dist/exception.d.ts +34 -0
- package/dist/exception.js +99 -0
- package/dist/exception.js.map +1 -0
- package/dist/fiber-error.d.ts +12 -0
- package/dist/fiber-error.js +12 -0
- package/dist/fiber-error.js.map +1 -0
- package/dist/fiber.d.ts +51 -0
- package/dist/fiber.js +178 -0
- package/dist/fiber.js.map +1 -0
- package/dist/file-utils.d.ts +480 -0
- package/dist/file-utils.js +1823 -0
- package/dist/file-utils.js.map +1 -0
- package/dist/file.d.ts +635 -0
- package/dist/file.js +1312 -0
- package/dist/file.js.map +1 -0
- package/dist/float-domain-error.d.ts +17 -0
- package/dist/float-domain-error.js +17 -0
- package/dist/float-domain-error.js.map +1 -0
- package/dist/fork-children.d.ts +23 -0
- package/dist/fork-children.js +32 -0
- package/dist/fork-children.js.map +1 -0
- package/dist/frozen-error.d.ts +33 -0
- package/dist/frozen-error.js +42 -0
- package/dist/frozen-error.js.map +1 -0
- package/dist/fs-adapter.d.ts +158 -0
- package/dist/fs-adapter.js +253 -0
- package/dist/fs-adapter.js.map +1 -0
- package/dist/gem/deprecate.d.ts +10 -0
- package/dist/gem/deprecate.js +8 -0
- package/dist/gem/deprecate.js.map +1 -0
- package/dist/gem/requirement.d.ts +64 -0
- package/dist/gem/requirement.js +91 -0
- package/dist/gem/requirement.js.map +1 -0
- package/dist/gem/version.d.ts +50 -0
- package/dist/gem/version.js +148 -0
- package/dist/gem/version.js.map +1 -0
- package/dist/gem.d.ts +59 -0
- package/dist/gem.js +82 -0
- package/dist/gem.js.map +1 -0
- package/dist/hash.d.ts +967 -0
- package/dist/hash.js +1572 -0
- package/dist/hash.js.map +1 -0
- package/dist/http-adapter.d.ts +123 -0
- package/dist/http-adapter.js +220 -0
- package/dist/http-adapter.js.map +1 -0
- package/dist/immediate-executor.d.ts +20 -0
- package/dist/immediate-executor.js +39 -0
- package/dist/immediate-executor.js.map +1 -0
- package/dist/include.d.ts +778 -0
- package/dist/include.js +2195 -0
- package/dist/include.js.map +1 -0
- package/dist/index-error.d.ts +13 -0
- package/dist/index-error.js +13 -0
- package/dist/index-error.js.map +1 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/dist/invalid-byte-sequence-error.d.ts +62 -0
- package/dist/invalid-byte-sequence-error.js +75 -0
- package/dist/invalid-byte-sequence-error.js.map +1 -0
- package/dist/io-error.d.ts +14 -0
- package/dist/io-error.js +17 -0
- package/dist/io-error.js.map +1 -0
- package/dist/io.d.ts +867 -0
- package/dist/io.js +1960 -0
- package/dist/io.js.map +1 -0
- package/dist/ipaddr.d.ts +79 -0
- package/dist/ipaddr.js +405 -0
- package/dist/ipaddr.js.map +1 -0
- package/dist/json.d.ts +67 -0
- package/dist/json.js +185 -0
- package/dist/json.js.map +1 -0
- package/dist/kernel-catch.d.ts +59 -0
- package/dist/kernel-catch.js +184 -0
- package/dist/kernel-catch.js.map +1 -0
- package/dist/kernel-float.d.ts +19 -0
- package/dist/kernel-float.js +54 -0
- package/dist/kernel-float.js.map +1 -0
- package/dist/kernel-fork.d.ts +30 -0
- package/dist/kernel-fork.js +72 -0
- package/dist/kernel-fork.js.map +1 -0
- package/dist/kernel-format.d.ts +27 -0
- package/dist/kernel-format.js +901 -0
- package/dist/kernel-format.js.map +1 -0
- package/dist/kernel-hash.d.ts +7 -0
- package/dist/kernel-hash.js +33 -0
- package/dist/kernel-hash.js.map +1 -0
- package/dist/kernel-integer.d.ts +49 -0
- package/dist/kernel-integer.js +170 -0
- package/dist/kernel-integer.js.map +1 -0
- package/dist/kernel-rand.d.ts +16 -0
- package/dist/kernel-rand.js +237 -0
- package/dist/kernel-rand.js.map +1 -0
- package/dist/kernel-system.d.ts +40 -0
- package/dist/kernel-system.js +97 -0
- package/dist/kernel-system.js.map +1 -0
- package/dist/kernel-warn.d.ts +35 -0
- package/dist/kernel-warn.js +73 -0
- package/dist/kernel-warn.js.map +1 -0
- package/dist/key-error.d.ts +44 -0
- package/dist/key-error.js +59 -0
- package/dist/key-error.js.map +1 -0
- package/dist/keyword-splat.d.ts +41 -0
- package/dist/keyword-splat.js +65 -0
- package/dist/keyword-splat.js.map +1 -0
- package/dist/load-error.d.ts +19 -0
- package/dist/load-error.js +19 -0
- package/dist/load-error.js.map +1 -0
- package/dist/load.d.ts +121 -0
- package/dist/load.js +263 -0
- package/dist/load.js.map +1 -0
- package/dist/loaded-features.d.ts +13 -0
- package/dist/loaded-features.js +15 -0
- package/dist/loaded-features.js.map +1 -0
- package/dist/local-jump-error.d.ts +12 -0
- package/dist/local-jump-error.js +12 -0
- package/dist/local-jump-error.js.map +1 -0
- package/dist/logger/formatter.d.ts +21 -0
- package/dist/logger/formatter.js +43 -0
- package/dist/logger/formatter.js.map +1 -0
- package/dist/logger/log-device.d.ts +52 -0
- package/dist/logger/log-device.js +104 -0
- package/dist/logger/log-device.js.map +1 -0
- package/dist/logger/severity.d.ts +23 -0
- package/dist/logger/severity.js +42 -0
- package/dist/logger/severity.js.map +1 -0
- package/dist/logger.d.ts +127 -0
- package/dist/logger.js +215 -0
- package/dist/logger.js.map +1 -0
- package/dist/marshal.d.ts +83 -0
- package/dist/marshal.js +1487 -0
- package/dist/marshal.js.map +1 -0
- package/dist/match-data.d.ts +161 -0
- package/dist/match-data.js +284 -0
- package/dist/match-data.js.map +1 -0
- package/dist/method-cache.d.ts +17 -0
- package/dist/method-cache.js +19 -0
- package/dist/method-cache.js.map +1 -0
- package/dist/method-missing-proxy.d.ts +53 -0
- package/dist/method-missing-proxy.js +154 -0
- package/dist/method-missing-proxy.js.map +1 -0
- package/dist/method.d.ts +132 -0
- package/dist/method.js +320 -0
- package/dist/method.js.map +1 -0
- package/dist/monitor.d.ts +114 -0
- package/dist/monitor.js +270 -0
- package/dist/monitor.js.map +1 -0
- package/dist/mutex.d.ts +51 -0
- package/dist/mutex.js +150 -0
- package/dist/mutex.js.map +1 -0
- package/dist/name-error.d.ts +45 -0
- package/dist/name-error.js +54 -0
- package/dist/name-error.js.map +1 -0
- package/dist/net/http/exceptions.d.ts +31 -0
- package/dist/net/http/exceptions.js +46 -0
- package/dist/net/http/exceptions.js.map +1 -0
- package/dist/net/http/request.d.ts +137 -0
- package/dist/net/http/request.js +559 -0
- package/dist/net/http/request.js.map +1 -0
- package/dist/net/http/requests.d.ts +197 -0
- package/dist/net/http/requests.js +197 -0
- package/dist/net/http/requests.js.map +1 -0
- package/dist/net/http/response.d.ts +141 -0
- package/dist/net/http/response.js +416 -0
- package/dist/net/http/response.js.map +1 -0
- package/dist/net/http/responses.d.ts +345 -0
- package/dist/net/http/responses.js +486 -0
- package/dist/net/http/responses.js.map +1 -0
- package/dist/net/http.d.ts +278 -0
- package/dist/net/http.js +760 -0
- package/dist/net/http.js.map +1 -0
- package/dist/net/protocol.d.ts +227 -0
- package/dist/net/protocol.js +392 -0
- package/dist/net/protocol.js.map +1 -0
- package/dist/nil-class.d.ts +10 -0
- package/dist/nil-class.js +27 -0
- package/dist/nil-class.js.map +1 -0
- package/dist/no-method-error.d.ts +38 -0
- package/dist/no-method-error.js +45 -0
- package/dist/no-method-error.js.map +1 -0
- package/dist/not-implemented-error.d.ts +13 -0
- package/dist/not-implemented-error.js +14 -0
- package/dist/not-implemented-error.js.map +1 -0
- package/dist/numeric.d.ts +211 -0
- package/dist/numeric.js +802 -0
- package/dist/numeric.js.map +1 -0
- package/dist/object-space.d.ts +34 -0
- package/dist/object-space.js +152 -0
- package/dist/object-space.js.map +1 -0
- package/dist/object.d.ts +908 -0
- package/dist/object.js +2238 -0
- package/dist/object.js.map +1 -0
- package/dist/open-uri.d.ts +180 -0
- package/dist/open-uri.js +402 -0
- package/dist/open-uri.js.map +1 -0
- package/dist/open3.d.ts +69 -0
- package/dist/open3.js +134 -0
- package/dist/open3.js.map +1 -0
- package/dist/openssl.d.ts +479 -0
- package/dist/openssl.js +1052 -0
- package/dist/openssl.js.map +1 -0
- package/dist/optparse.d.ts +130 -0
- package/dist/optparse.js +457 -0
- package/dist/optparse.js.map +1 -0
- package/dist/os-adapter.d.ts +20 -0
- package/dist/os-adapter.js +95 -0
- package/dist/os-adapter.js.map +1 -0
- package/dist/pathname.d.ts +71 -0
- package/dist/pathname.js +394 -0
- package/dist/pathname.js.map +1 -0
- package/dist/pp.d.ts +60 -0
- package/dist/pp.js +195 -0
- package/dist/pp.js.map +1 -0
- package/dist/pretty-print.d.ts +89 -0
- package/dist/pretty-print.js +232 -0
- package/dist/pretty-print.js.map +1 -0
- package/dist/process-adapter.d.ts +224 -0
- package/dist/process-adapter.js +878 -0
- package/dist/process-adapter.js.map +1 -0
- package/dist/process.d.ts +192 -0
- package/dist/process.js +403 -0
- package/dist/process.js.map +1 -0
- package/dist/psych/class-loader.d.ts +92 -0
- package/dist/psych/class-loader.js +139 -0
- package/dist/psych/class-loader.js.map +1 -0
- package/dist/psych/coder.d.ts +144 -0
- package/dist/psych/coder.js +176 -0
- package/dist/psych/coder.js.map +1 -0
- package/dist/psych/core-ext.d.ts +8 -0
- package/dist/psych/core-ext.js +10 -0
- package/dist/psych/core-ext.js.map +1 -0
- package/dist/psych/emitter.d.ts +116 -0
- package/dist/psych/emitter.js +1130 -0
- package/dist/psych/emitter.js.map +1 -0
- package/dist/psych/exception.d.ts +43 -0
- package/dist/psych/exception.js +54 -0
- package/dist/psych/exception.js.map +1 -0
- package/dist/psych/handler.d.ts +59 -0
- package/dist/psych/handler.js +95 -0
- package/dist/psych/handler.js.map +1 -0
- package/dist/psych/handlers/document-stream.d.ts +17 -0
- package/dist/psych/handlers/document-stream.js +26 -0
- package/dist/psych/handlers/document-stream.js.map +1 -0
- package/dist/psych/nodes/alias.d.ts +15 -0
- package/dist/psych/nodes/alias.js +22 -0
- package/dist/psych/nodes/alias.js.map +1 -0
- package/dist/psych/nodes/document.d.ts +23 -0
- package/dist/psych/nodes/document.js +35 -0
- package/dist/psych/nodes/document.js.map +1 -0
- package/dist/psych/nodes/mapping.d.ts +25 -0
- package/dist/psych/nodes/mapping.js +35 -0
- package/dist/psych/nodes/mapping.js.map +1 -0
- package/dist/psych/nodes/node.d.ts +59 -0
- package/dist/psych/nodes/node.js +79 -0
- package/dist/psych/nodes/node.js.map +1 -0
- package/dist/psych/nodes/scalar.d.ts +35 -0
- package/dist/psych/nodes/scalar.js +47 -0
- package/dist/psych/nodes/scalar.js.map +1 -0
- package/dist/psych/nodes/sequence.d.ts +25 -0
- package/dist/psych/nodes/sequence.js +35 -0
- package/dist/psych/nodes/sequence.js.map +1 -0
- package/dist/psych/nodes/stream.d.ts +23 -0
- package/dist/psych/nodes/stream.js +31 -0
- package/dist/psych/nodes/stream.js.map +1 -0
- package/dist/psych/omap.d.ts +9 -0
- package/dist/psych/omap.js +9 -0
- package/dist/psych/omap.js.map +1 -0
- package/dist/psych/parser.d.ts +41 -0
- package/dist/psych/parser.js +139 -0
- package/dist/psych/parser.js.map +1 -0
- package/dist/psych/scalar-scanner.d.ts +35 -0
- package/dist/psych/scalar-scanner.js +173 -0
- package/dist/psych/scalar-scanner.js.map +1 -0
- package/dist/psych/syntax-error.d.ts +23 -0
- package/dist/psych/syntax-error.js +35 -0
- package/dist/psych/syntax-error.js.map +1 -0
- package/dist/psych/tree-builder.d.ts +51 -0
- package/dist/psych/tree-builder.js +118 -0
- package/dist/psych/tree-builder.js.map +1 -0
- package/dist/psych/visitors/depth-first.d.ts +27 -0
- package/dist/psych/visitors/depth-first.js +37 -0
- package/dist/psych/visitors/depth-first.js.map +1 -0
- package/dist/psych/visitors/emitter.d.ts +32 -0
- package/dist/psych/visitors/emitter.js +63 -0
- package/dist/psych/visitors/emitter.js.map +1 -0
- package/dist/psych/visitors/to-ruby.d.ts +110 -0
- package/dist/psych/visitors/to-ruby.js +396 -0
- package/dist/psych/visitors/to-ruby.js.map +1 -0
- package/dist/psych/visitors/visitor.d.ts +11 -0
- package/dist/psych/visitors/visitor.js +17 -0
- package/dist/psych/visitors/visitor.js.map +1 -0
- package/dist/psych/visitors/yaml-tree.d.ts +182 -0
- package/dist/psych/visitors/yaml-tree.js +593 -0
- package/dist/psych/visitors/yaml-tree.js.map +1 -0
- package/dist/psych-adapter.d.ts +65 -0
- package/dist/psych-adapter.js +121 -0
- package/dist/psych-adapter.js.map +1 -0
- package/dist/psych-yaml.d.ts +2 -0
- package/dist/psych-yaml.js +5 -0
- package/dist/psych-yaml.js.map +1 -0
- package/dist/psych.d.ts +257 -0
- package/dist/psych.js +332 -0
- package/dist/psych.js.map +1 -0
- package/dist/queue.d.ts +129 -0
- package/dist/queue.js +215 -0
- package/dist/queue.js.map +1 -0
- package/dist/racc/parser.d.ts +70 -0
- package/dist/racc/parser.js +206 -0
- package/dist/racc/parser.js.map +1 -0
- package/dist/range-error.d.ts +15 -0
- package/dist/range-error.js +15 -0
- package/dist/range-error.js.map +1 -0
- package/dist/range.d.ts +166 -0
- package/dist/range.js +421 -0
- package/dist/range.js.map +1 -0
- package/dist/rational.d.ts +167 -0
- package/dist/rational.js +379 -0
- package/dist/rational.js.map +1 -0
- package/dist/rb-config.d.ts +33 -0
- package/dist/rb-config.js +53 -0
- package/dist/rb-config.js.map +1 -0
- package/dist/rb-equal.d.ts +66 -0
- package/dist/rb-equal.js +261 -0
- package/dist/rb-equal.js.map +1 -0
- package/dist/rb-hash.d.ts +26 -0
- package/dist/rb-hash.js +108 -0
- package/dist/rb-hash.js.map +1 -0
- package/dist/regexp.d.ts +82 -0
- package/dist/regexp.js +191 -0
- package/dist/regexp.js.map +1 -0
- package/dist/repl-adapter.d.ts +188 -0
- package/dist/repl-adapter.js +388 -0
- package/dist/repl-adapter.js.map +1 -0
- package/dist/resolv.d.ts +30 -0
- package/dist/resolv.js +48 -0
- package/dist/resolv.js.map +1 -0
- package/dist/ruby-empty.d.ts +28 -0
- package/dist/ruby-empty.js +40 -0
- package/dist/ruby-empty.js.map +1 -0
- package/dist/ruby-platform.d.ts +39 -0
- package/dist/ruby-platform.js +49 -0
- package/dist/ruby-platform.js.map +1 -0
- package/dist/runtime-error.d.ts +15 -0
- package/dist/runtime-error.js +16 -0
- package/dist/runtime-error.js.map +1 -0
- package/dist/scheduled-task.d.ts +73 -0
- package/dist/scheduled-task.js +150 -0
- package/dist/scheduled-task.js.map +1 -0
- package/dist/secure-random.d.ts +33 -0
- package/dist/secure-random.js +78 -0
- package/dist/secure-random.js.map +1 -0
- package/dist/set.d.ts +158 -0
- package/dist/set.js +352 -0
- package/dist/set.js.map +1 -0
- package/dist/shellwords.d.ts +27 -0
- package/dist/shellwords.js +53 -0
- package/dist/shellwords.js.map +1 -0
- package/dist/signal-exception.d.ts +21 -0
- package/dist/signal-exception.js +21 -0
- package/dist/signal-exception.js.map +1 -0
- package/dist/socket.d.ts +230 -0
- package/dist/socket.js +484 -0
- package/dist/socket.js.map +1 -0
- package/dist/standard-error.d.ts +18 -0
- package/dist/standard-error.js +23 -0
- package/dist/standard-error.js.map +1 -0
- package/dist/stop-iteration.d.ts +10 -0
- package/dist/stop-iteration.js +10 -0
- package/dist/stop-iteration.js.map +1 -0
- package/dist/string/b.d.ts +19 -0
- package/dist/string/b.js +28 -0
- package/dist/string/b.js.map +1 -0
- package/dist/string/byte-methods.d.ts +57 -0
- package/dist/string/byte-methods.js +266 -0
- package/dist/string/byte-methods.js.map +1 -0
- package/dist/string/bytes.d.ts +35 -0
- package/dist/string/bytes.js +123 -0
- package/dist/string/bytes.js.map +1 -0
- package/dist/string/case-mapping.d.ts +57 -0
- package/dist/string/case-mapping.js +192 -0
- package/dist/string/case-mapping.js.map +1 -0
- package/dist/string/chomp.d.ts +15 -0
- package/dist/string/chomp.js +32 -0
- package/dist/string/chomp.js.map +1 -0
- package/dist/string/convert.d.ts +55 -0
- package/dist/string/convert.js +316 -0
- package/dist/string/convert.js.map +1 -0
- package/dist/string/delete.d.ts +14 -0
- package/dist/string/delete.js +17 -0
- package/dist/string/delete.js.map +1 -0
- package/dist/string/each.d.ts +108 -0
- package/dist/string/each.js +305 -0
- package/dist/string/each.js.map +1 -0
- package/dist/string/encode.d.ts +37 -0
- package/dist/string/encode.js +268 -0
- package/dist/string/encode.js.map +1 -0
- package/dist/string/force-encoding.d.ts +72 -0
- package/dist/string/force-encoding.js +147 -0
- package/dist/string/force-encoding.js.map +1 -0
- package/dist/string/inspect.d.ts +17 -0
- package/dist/string/inspect.js +81 -0
- package/dist/string/inspect.js.map +1 -0
- package/dist/string/method-table.d.ts +174 -0
- package/dist/string/method-table.js +805 -0
- package/dist/string/method-table.js.map +1 -0
- package/dist/string/scrub.d.ts +12 -0
- package/dist/string/scrub.js +33 -0
- package/dist/string/scrub.js.map +1 -0
- package/dist/string/slice.d.ts +26 -0
- package/dist/string/slice.js +73 -0
- package/dist/string/slice.js.map +1 -0
- package/dist/string/split.d.ts +11 -0
- package/dist/string/split.js +44 -0
- package/dist/string/split.js.map +1 -0
- package/dist/string/sub.d.ts +114 -0
- package/dist/string/sub.js +371 -0
- package/dist/string/sub.js.map +1 -0
- package/dist/string/succ.d.ts +14 -0
- package/dist/string/succ.js +118 -0
- package/dist/string/succ.js.map +1 -0
- package/dist/string/support.d.ts +135 -0
- package/dist/string/support.js +283 -0
- package/dist/string/support.js.map +1 -0
- package/dist/string/tr.d.ts +46 -0
- package/dist/string/tr.js +156 -0
- package/dist/string/tr.js.map +1 -0
- package/dist/string-io.d.ts +166 -0
- package/dist/string-io.js +248 -0
- package/dist/string-io.js.map +1 -0
- package/dist/string-scanner.d.ts +133 -0
- package/dist/string-scanner.js +248 -0
- package/dist/string-scanner.js.map +1 -0
- package/dist/struct.d.ts +54 -0
- package/dist/struct.js +222 -0
- package/dist/struct.js.map +1 -0
- package/dist/symbol.d.ts +48 -0
- package/dist/symbol.js +107 -0
- package/dist/symbol.js.map +1 -0
- package/dist/tempfile.d.ts +173 -0
- package/dist/tempfile.js +290 -0
- package/dist/tempfile.js.map +1 -0
- package/dist/temporal-tag.d.ts +23 -0
- package/dist/temporal-tag.js +29 -0
- package/dist/temporal-tag.js.map +1 -0
- package/dist/thread-error.d.ts +13 -0
- package/dist/thread-error.js +13 -0
- package/dist/thread-error.js.map +1 -0
- package/dist/thread-pool-executor.d.ts +119 -0
- package/dist/thread-pool-executor.js +250 -0
- package/dist/thread-pool-executor.js.map +1 -0
- package/dist/thread.d.ts +211 -0
- package/dist/thread.js +495 -0
- package/dist/thread.js.map +1 -0
- package/dist/timeout.d.ts +29 -0
- package/dist/timeout.js +41 -0
- package/dist/timeout.js.map +1 -0
- package/dist/tse.d.ts +40 -0
- package/dist/tse.js +62 -0
- package/dist/tse.js.map +1 -0
- package/dist/type-error.d.ts +14 -0
- package/dist/type-error.js +15 -0
- package/dist/type-error.js.map +1 -0
- package/dist/undefined-conversion-error.d.ts +10 -0
- package/dist/undefined-conversion-error.js +10 -0
- package/dist/undefined-conversion-error.js.map +1 -0
- package/dist/uri/common.d.ts +209 -0
- package/dist/uri/common.js +369 -0
- package/dist/uri/common.js.map +1 -0
- package/dist/uri/generic.d.ts +283 -0
- package/dist/uri/generic.js +810 -0
- package/dist/uri/generic.js.map +1 -0
- package/dist/uri/http.d.ts +23 -0
- package/dist/uri/http.js +30 -0
- package/dist/uri/http.js.map +1 -0
- package/dist/uri/https.d.ts +13 -0
- package/dist/uri/https.js +15 -0
- package/dist/uri/https.js.map +1 -0
- package/dist/uri/rfc2396-parser.d.ts +70 -0
- package/dist/uri/rfc2396-parser.js +264 -0
- package/dist/uri/rfc2396-parser.js.map +1 -0
- package/dist/uri/rfc3986-parser.d.ts +46 -0
- package/dist/uri/rfc3986-parser.js +171 -0
- package/dist/uri/rfc3986-parser.js.map +1 -0
- package/dist/uri.d.ts +13 -0
- package/dist/uri.js +13 -0
- package/dist/uri.js.map +1 -0
- package/dist/variable.d.ts +183 -0
- package/dist/variable.js +463 -0
- package/dist/variable.js.map +1 -0
- package/dist/verbose.d.ts +21 -0
- package/dist/verbose.js +26 -0
- package/dist/verbose.js.map +1 -0
- package/dist/yaml.d.ts +9 -0
- package/dist/yaml.js +9 -0
- package/dist/yaml.js.map +1 -0
- package/dist/zlib-adapter.d.ts +117 -0
- package/dist/zlib-adapter.js +250 -0
- package/dist/zlib-adapter.js.map +1 -0
- package/dist/zlib.d.ts +248 -0
- package/dist/zlib.js +362 -0
- package/dist/zlib.js.map +1 -0
- package/package.json +82 -3
package/dist/openssl.js
ADDED
|
@@ -0,0 +1,1052 @@
|
|
|
1
|
+
import { getCrypto } from "./crypto-adapter.js";
|
|
2
|
+
import { getFs } from "./fs-adapter.js";
|
|
3
|
+
import { DigestClass } from "./digest.js";
|
|
4
|
+
import { SecureRandom } from "./secure-random.js";
|
|
5
|
+
import { ArgumentError } from "./argument-error.js";
|
|
6
|
+
import { NotImplementedError } from "./not-implemented-error.js";
|
|
7
|
+
import { NoMethodError } from "./no-method-error.js";
|
|
8
|
+
import { StandardError } from "./standard-error.js";
|
|
9
|
+
import { IPAddr } from "./ipaddr.js";
|
|
10
|
+
import { stringSplit } from "./string/split.js";
|
|
11
|
+
const AEAD_MODES = ["gcm", "ccm", "ocb", "chacha20-poly1305", "siv"];
|
|
12
|
+
/**
|
|
13
|
+
* `OpenSSL::Cipher::CipherError` (`vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:1047`).
|
|
14
|
+
*
|
|
15
|
+
* @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:1047
|
|
16
|
+
*/
|
|
17
|
+
export class CipherError extends StandardError {
|
|
18
|
+
}
|
|
19
|
+
const SSL_VERIFY_CODES = [
|
|
20
|
+
"CERT_HAS_EXPIRED",
|
|
21
|
+
"CERT_NOT_YET_VALID",
|
|
22
|
+
"CERT_REVOKED",
|
|
23
|
+
"CERT_UNTRUSTED",
|
|
24
|
+
"CERT_REJECTED",
|
|
25
|
+
"CERT_SIGNATURE_FAILURE",
|
|
26
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
27
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
28
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
29
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
30
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
31
|
+
"HOSTNAME_MISMATCH",
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* `OpenSSL::SSL::SSLError` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2616`). A
|
|
35
|
+
* TLS failure reaches JS as the host's own error with an `ERR_SSL_` or
|
|
36
|
+
* `ERR_TLS_` code, or an OpenSSL certificate-verify code, which is this class to `rescue OpenSSL::SSL::SSLError`.
|
|
37
|
+
*
|
|
38
|
+
* @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2616
|
|
39
|
+
*/
|
|
40
|
+
class SSLError extends StandardError {
|
|
41
|
+
static [Symbol.hasInstance](error) {
|
|
42
|
+
const code = error?.code;
|
|
43
|
+
return (Function.prototype[Symbol.hasInstance].call(this, error) ||
|
|
44
|
+
(typeof code === "string" &&
|
|
45
|
+
(code.startsWith("ERR_SSL_") ||
|
|
46
|
+
code.startsWith("ERR_TLS_") ||
|
|
47
|
+
SSL_VERIFY_CODES.includes(code))));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** `OP_ALL` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:3004`). */
|
|
51
|
+
const OP_ALL = 0x80000850;
|
|
52
|
+
/** `OP_DONT_INSERT_EMPTY_FRAGMENTS` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:3026`). */
|
|
53
|
+
const OP_DONT_INSERT_EMPTY_FRAGMENTS = 0x800;
|
|
54
|
+
/** `OP_NO_COMPRESSION` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:3029`). */
|
|
55
|
+
const OP_NO_COMPRESSION = 0x20000;
|
|
56
|
+
/**
|
|
57
|
+
* `OpenSSL::X509` verify-result constants (`DefX509Const`,
|
|
58
|
+
* `vendor/ruby/v3.3.11/ext/openssl/ossl_x509.c:50-71`), keyed by the code a
|
|
59
|
+
* TLS failure carries.
|
|
60
|
+
*/
|
|
61
|
+
const X509_VERIFY_RESULTS = {
|
|
62
|
+
V_OK: 0,
|
|
63
|
+
V_ERR_UNABLE_TO_GET_ISSUER_CERT: 2,
|
|
64
|
+
V_ERR_CERT_SIGNATURE_FAILURE: 7,
|
|
65
|
+
V_ERR_CERT_NOT_YET_VALID: 9,
|
|
66
|
+
V_ERR_CERT_HAS_EXPIRED: 10,
|
|
67
|
+
V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: 18,
|
|
68
|
+
V_ERR_SELF_SIGNED_CERT_IN_CHAIN: 19,
|
|
69
|
+
V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: 20,
|
|
70
|
+
V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: 21,
|
|
71
|
+
V_ERR_CERT_REVOKED: 23,
|
|
72
|
+
V_ERR_CERT_UNTRUSTED: 27,
|
|
73
|
+
V_ERR_CERT_REJECTED: 28,
|
|
74
|
+
V_ERR_HOSTNAME_MISMATCH: 62,
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* `OpenSSL::X509::Store` (`vendor/ruby/v3.3.11/ext/openssl/ossl_x509store.c:920`).
|
|
78
|
+
* It holds PEM text, which a TLS handshake is handed as its trust anchors.
|
|
79
|
+
*
|
|
80
|
+
* @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_x509store.c:920
|
|
81
|
+
*/
|
|
82
|
+
export class Store {
|
|
83
|
+
/** @internal */
|
|
84
|
+
_certs = [];
|
|
85
|
+
/** @internal */
|
|
86
|
+
_defaultPaths = false;
|
|
87
|
+
/** @noRailsEquivalent PERMANENT */
|
|
88
|
+
async addFile(file) {
|
|
89
|
+
this._certs.push(new TextDecoder().decode(await getFs().readFile(file)));
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/** @noRailsEquivalent PERMANENT */
|
|
93
|
+
addCert(cert) {
|
|
94
|
+
this._certs.push(cert);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/** @noRailsEquivalent PERMANENT */
|
|
98
|
+
setDefaultPaths() {
|
|
99
|
+
this._defaultPaths = true;
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* `OpenSSL::SSL::SSLContext` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2633`,
|
|
105
|
+
* `lib/openssl/ssl.rb:22`).
|
|
106
|
+
*
|
|
107
|
+
* @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:22
|
|
108
|
+
*/
|
|
109
|
+
export class SSLContext {
|
|
110
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2910` */
|
|
111
|
+
static SESSION_CACHE_CLIENT = 0x0001;
|
|
112
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2915` */
|
|
113
|
+
static SESSION_CACHE_SERVER = 0x0002;
|
|
114
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2941` */
|
|
115
|
+
static SESSION_CACHE_NO_INTERNAL_STORE = 0x0300;
|
|
116
|
+
/** @noRailsEquivalent PERMANENT */
|
|
117
|
+
static DEFAULT_PARAMS = {
|
|
118
|
+
minVersion: 0x301,
|
|
119
|
+
verifyMode: 1,
|
|
120
|
+
verifyHostname: true,
|
|
121
|
+
options: ((OP_ALL & ~OP_DONT_INSERT_EMPTY_FRAGMENTS) | OP_NO_COMPRESSION) >>> 0,
|
|
122
|
+
};
|
|
123
|
+
/** @noRailsEquivalent PERMANENT */
|
|
124
|
+
static DEFAULT_CERT_STORE = (() => {
|
|
125
|
+
const store = new Store();
|
|
126
|
+
store.setDefaultPaths();
|
|
127
|
+
return store;
|
|
128
|
+
})();
|
|
129
|
+
/** @noRailsEquivalent PERMANENT */
|
|
130
|
+
options = 0;
|
|
131
|
+
/** @noRailsEquivalent PERMANENT */
|
|
132
|
+
verifyMode;
|
|
133
|
+
/** @noRailsEquivalent PERMANENT */
|
|
134
|
+
verifyHostname;
|
|
135
|
+
/** @noRailsEquivalent PERMANENT */
|
|
136
|
+
certStore = null;
|
|
137
|
+
/** @noRailsEquivalent PERMANENT */
|
|
138
|
+
caFile = null;
|
|
139
|
+
/** @noRailsEquivalent PERMANENT */
|
|
140
|
+
caPath = null;
|
|
141
|
+
/** @noRailsEquivalent PERMANENT */
|
|
142
|
+
timeout = null;
|
|
143
|
+
/** @noRailsEquivalent PERMANENT */
|
|
144
|
+
minVersion = null;
|
|
145
|
+
/** @noRailsEquivalent PERMANENT */
|
|
146
|
+
maxVersion = null;
|
|
147
|
+
/** @noRailsEquivalent PERMANENT */
|
|
148
|
+
cert = null;
|
|
149
|
+
/** @noRailsEquivalent PERMANENT */
|
|
150
|
+
key = null;
|
|
151
|
+
/** @noRailsEquivalent PERMANENT */
|
|
152
|
+
ciphers = null;
|
|
153
|
+
/** @noRailsEquivalent PERMANENT */
|
|
154
|
+
extraChainCert = null;
|
|
155
|
+
/** @noRailsEquivalent PERMANENT */
|
|
156
|
+
verifyCallback = null;
|
|
157
|
+
/** @noRailsEquivalent PERMANENT */
|
|
158
|
+
verifyDepth = null;
|
|
159
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2722` */
|
|
160
|
+
sessionNewCb = null;
|
|
161
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2898` */
|
|
162
|
+
sessionCacheMode = SSLContext.SESSION_CACHE_SERVER;
|
|
163
|
+
/**
|
|
164
|
+
* `ssl_timeout=`, the alias of `timeout=` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2880`).
|
|
165
|
+
*
|
|
166
|
+
* @noRailsEquivalent PERMANENT
|
|
167
|
+
*/
|
|
168
|
+
set sslTimeout(timeout) {
|
|
169
|
+
this.timeout = timeout;
|
|
170
|
+
}
|
|
171
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:208-221` */
|
|
172
|
+
set sslVersion(meth) {
|
|
173
|
+
meth = meth.replace(/(_client|_server)$/, "");
|
|
174
|
+
const version = METHODS_MAP[meth];
|
|
175
|
+
if (version === undefined)
|
|
176
|
+
throw new ArgumentError(`unknown SSL method \`${meth}'`);
|
|
177
|
+
this.minVersion = this.maxVersion = version;
|
|
178
|
+
}
|
|
179
|
+
constructor() {
|
|
180
|
+
this.options = (this.options | OpenSSL.SSL.OP_ALL) >>> 0;
|
|
181
|
+
this.verifyMode = OpenSSL.SSL.VERIFY_NONE;
|
|
182
|
+
this.verifyHostname = false;
|
|
183
|
+
}
|
|
184
|
+
/** @noRailsEquivalent PERMANENT */
|
|
185
|
+
setParams(params = {}) {
|
|
186
|
+
params = { ...SSLContext.DEFAULT_PARAMS, ...params };
|
|
187
|
+
this.options = params.options;
|
|
188
|
+
delete params.options;
|
|
189
|
+
for (const [name, value] of Object.entries(params)) {
|
|
190
|
+
if (!(name in this)) {
|
|
191
|
+
throw new NoMethodError(`undefined method '${name}=' for an instance of OpenSSL::SSL::SSLContext`);
|
|
192
|
+
}
|
|
193
|
+
this[name] = value;
|
|
194
|
+
}
|
|
195
|
+
if (this.verifyMode !== OpenSSL.SSL.VERIFY_NONE) {
|
|
196
|
+
if (!(this.caFile != null || this.caPath != null || this.certStore != null)) {
|
|
197
|
+
this.certStore = SSLContext.DEFAULT_CERT_STORE;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return params;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* `ossl_sslctx_setup` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:691-830`) and
|
|
204
|
+
* `set_minmax_proto_version` (`:162-185`): the trust anchors and protocol
|
|
205
|
+
* bounds this context hands the host's handshake.
|
|
206
|
+
*
|
|
207
|
+
* @internal @noRailsEquivalent PERMANENT
|
|
208
|
+
*/
|
|
209
|
+
async _setup() {
|
|
210
|
+
const certs = [];
|
|
211
|
+
if (this.caFile != null) {
|
|
212
|
+
certs.push(new TextDecoder().decode(await getFs().readFile(this.caFile)));
|
|
213
|
+
}
|
|
214
|
+
if (this.certStore != null)
|
|
215
|
+
certs.push(...this.certStore._certs);
|
|
216
|
+
const ca = certs.length > 0 ? certs : null;
|
|
217
|
+
const defaultPaths = this.certStore?._defaultPaths ?? false;
|
|
218
|
+
const min = _hostProtoVersion(this.minVersion);
|
|
219
|
+
const max = _hostProtoVersion(this.maxVersion);
|
|
220
|
+
return { ca, defaultPaths, ...(min && { minVersion: min }), ...(max && { maxVersion: max }) };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** `METHODS_MAP` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:223-230`). */
|
|
224
|
+
const METHODS_MAP = { SSLv23: 0, SSLv3: 0x300, TLSv1: 0x301, TLSv1_1: 0x302, TLSv1_2: 0x303 };
|
|
225
|
+
/** `parse_proto_version`'s map (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:123-153`). */
|
|
226
|
+
const PROTO_VERSIONS = {
|
|
227
|
+
SSL3: 0x300,
|
|
228
|
+
TLS1: 0x301,
|
|
229
|
+
TLS1_1: 0x302,
|
|
230
|
+
TLS1_2: 0x303,
|
|
231
|
+
TLS1_3: 0x304,
|
|
232
|
+
};
|
|
233
|
+
function _hostProtoVersion(version) {
|
|
234
|
+
if (version == null)
|
|
235
|
+
return undefined;
|
|
236
|
+
const v = typeof version === "number" ? version : PROTO_VERSIONS[version];
|
|
237
|
+
if (v === undefined)
|
|
238
|
+
throw new ArgumentError(`unrecognized version "${version}"`);
|
|
239
|
+
return v >= 0x301 ? `TLSv1${v === 0x301 ? "" : `.${v - 0x301}`}` : undefined;
|
|
240
|
+
}
|
|
241
|
+
const TLS1_DEFAULT_TIMEOUT = 7200;
|
|
242
|
+
/**
|
|
243
|
+
* `OpenSSL::SSL::Session` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl_session.c:301-330`):
|
|
244
|
+
* the host's serialized session, with the time it was established and its
|
|
245
|
+
* lifetime in seconds. The host reports neither, so `time` is the moment the
|
|
246
|
+
* host handed the session over and `timeout` is `TLS1_DEFAULT_TIMEOUT`, OpenSSL's
|
|
247
|
+
* `tls1_default_timeout` (`ssl/t1_lib.c`).
|
|
248
|
+
*
|
|
249
|
+
* @noRailsEquivalent PERMANENT
|
|
250
|
+
*/
|
|
251
|
+
export class Session {
|
|
252
|
+
_der;
|
|
253
|
+
time;
|
|
254
|
+
timeout;
|
|
255
|
+
constructor(
|
|
256
|
+
/** @internal */
|
|
257
|
+
_der,
|
|
258
|
+
/** @noRailsEquivalent PERMANENT */
|
|
259
|
+
time = new Date(),
|
|
260
|
+
/** @noRailsEquivalent PERMANENT */
|
|
261
|
+
timeout = TLS1_DEFAULT_TIMEOUT) {
|
|
262
|
+
this._der = _der;
|
|
263
|
+
this.time = time;
|
|
264
|
+
this.timeout = timeout;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* `OpenSSL::SSL.verify_certificate_identity` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:275-306`).
|
|
269
|
+
*
|
|
270
|
+
* @noRailsEquivalent PERMANENT
|
|
271
|
+
*/
|
|
272
|
+
export function verifyCertificateIdentity(cert, hostname) {
|
|
273
|
+
let shouldVerifyCommonName = true;
|
|
274
|
+
for (const ext of cert.extensions) {
|
|
275
|
+
if (ext.oid !== "subjectAltName")
|
|
276
|
+
continue;
|
|
277
|
+
const sequence = _derSeq(_derRead(ext._value, 0).value);
|
|
278
|
+
for (const san of sequence) {
|
|
279
|
+
switch (san.tag & 0x1f) {
|
|
280
|
+
case 2:
|
|
281
|
+
shouldVerifyCommonName = false;
|
|
282
|
+
if (verifyHostname(hostname, new TextDecoder().decode(san.value)))
|
|
283
|
+
return true;
|
|
284
|
+
break;
|
|
285
|
+
case 7:
|
|
286
|
+
shouldVerifyCommonName = false;
|
|
287
|
+
if (san.value.length === 4 || san.value.length === 16) {
|
|
288
|
+
try {
|
|
289
|
+
if (_bytesEqual(san.value, new IPAddr(hostname).hton()))
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
catch (e) {
|
|
293
|
+
if (!(e instanceof IPAddr.InvalidAddressError))
|
|
294
|
+
throw e;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (shouldVerifyCommonName) {
|
|
302
|
+
for (const [oid, value] of cert.subject._entries) {
|
|
303
|
+
if (oid === "CN") {
|
|
304
|
+
if (verifyHostname(hostname, value))
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* `OpenSSL::SSL.verify_hostname` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:308-338`).
|
|
313
|
+
*
|
|
314
|
+
* @noRailsEquivalent PERMANENT
|
|
315
|
+
*/
|
|
316
|
+
export function verifyHostname(hostname, san) {
|
|
317
|
+
if (!_isAsciiOnly(san))
|
|
318
|
+
return false;
|
|
319
|
+
if (!_isAsciiOnly(hostname))
|
|
320
|
+
return false;
|
|
321
|
+
const sanParts = stringSplit(san.toLowerCase(), ".");
|
|
322
|
+
if (sanParts.length < 2)
|
|
323
|
+
return san === hostname;
|
|
324
|
+
const hostParts = stringSplit(hostname.toLowerCase(), ".");
|
|
325
|
+
if (sanParts.length !== hostParts.length)
|
|
326
|
+
return false;
|
|
327
|
+
if (!verifyWildcard(hostParts.shift(), sanParts.shift()))
|
|
328
|
+
return false;
|
|
329
|
+
return sanParts.join(".") === hostParts.join(".");
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* `OpenSSL::SSL.verify_wildcard` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:341-357`).
|
|
333
|
+
*
|
|
334
|
+
* @noRailsEquivalent PERMANENT
|
|
335
|
+
*/
|
|
336
|
+
export function verifyWildcard(domainComponent, sanComponent) {
|
|
337
|
+
const parts = sanComponent.split("*");
|
|
338
|
+
if (parts.length > 2)
|
|
339
|
+
return false;
|
|
340
|
+
if (parts.length === 1)
|
|
341
|
+
return sanComponent === domainComponent;
|
|
342
|
+
if (domainComponent.startsWith("xn--") && sanComponent !== "*")
|
|
343
|
+
return false;
|
|
344
|
+
return (parts[0].length + parts[1].length < domainComponent.length &&
|
|
345
|
+
domainComponent.startsWith(parts[0]) &&
|
|
346
|
+
domainComponent.endsWith(parts[1]));
|
|
347
|
+
}
|
|
348
|
+
function _isAsciiOnly(str) {
|
|
349
|
+
return [...str].every((c) => c.charCodeAt(0) < 0x80);
|
|
350
|
+
}
|
|
351
|
+
function _bytesEqual(a, b) {
|
|
352
|
+
return a.length === b.length && a.every((byte, i) => byte === b[i]);
|
|
353
|
+
}
|
|
354
|
+
function _derRead(der, at) {
|
|
355
|
+
let length = der[at + 1];
|
|
356
|
+
let start = at + 2;
|
|
357
|
+
if (length & 0x80) {
|
|
358
|
+
const n = length & 0x7f;
|
|
359
|
+
length = 0;
|
|
360
|
+
for (let i = 0; i < n; i++)
|
|
361
|
+
length = length * 256 + der[start + i];
|
|
362
|
+
start += n;
|
|
363
|
+
}
|
|
364
|
+
return { tag: der[at], value: der.subarray(start, start + length), end: start + length };
|
|
365
|
+
}
|
|
366
|
+
function _derSeq(contents) {
|
|
367
|
+
const children = [];
|
|
368
|
+
for (let at = 0; at < contents.length;) {
|
|
369
|
+
const child = _derRead(contents, at);
|
|
370
|
+
children.push(child);
|
|
371
|
+
at = child.end;
|
|
372
|
+
}
|
|
373
|
+
return children;
|
|
374
|
+
}
|
|
375
|
+
function _derToOid(value) {
|
|
376
|
+
const arcs = [Math.floor(value[0] / 40), value[0] % 40];
|
|
377
|
+
let arc = 0;
|
|
378
|
+
for (const byte of value.subarray(1)) {
|
|
379
|
+
arc = arc * 128 + (byte & 0x7f);
|
|
380
|
+
if (!(byte & 0x80)) {
|
|
381
|
+
arcs.push(arc);
|
|
382
|
+
arc = 0;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const oid = arcs.join(".");
|
|
386
|
+
return Object.keys(OIDS).find((name) => OIDS[name] === oid) ?? oid;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* `OpenSSL::SSL::SSLSocket` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2963`,
|
|
390
|
+
* `lib/openssl/ssl.rb:359`). The handshake is the host's, run over `io`.
|
|
391
|
+
*
|
|
392
|
+
* @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:359
|
|
393
|
+
*/
|
|
394
|
+
export class SSLSocket {
|
|
395
|
+
io;
|
|
396
|
+
context;
|
|
397
|
+
/** @noRailsEquivalent PERMANENT */
|
|
398
|
+
hostname = null;
|
|
399
|
+
/** @noRailsEquivalent PERMANENT */
|
|
400
|
+
syncClose = false;
|
|
401
|
+
/** @internal */
|
|
402
|
+
_verifyResult = X509_VERIFY_RESULTS.V_OK;
|
|
403
|
+
/** @internal */
|
|
404
|
+
_closed = false;
|
|
405
|
+
/** @internal */
|
|
406
|
+
_session = null;
|
|
407
|
+
/** @internal */
|
|
408
|
+
_peerCert = null;
|
|
409
|
+
constructor(
|
|
410
|
+
/** @noRailsEquivalent PERMANENT */
|
|
411
|
+
io,
|
|
412
|
+
/** @noRailsEquivalent PERMANENT */
|
|
413
|
+
context) {
|
|
414
|
+
this.io = io;
|
|
415
|
+
this.context = context;
|
|
416
|
+
}
|
|
417
|
+
/** @noRailsEquivalent PERMANENT */
|
|
418
|
+
get verifyResult() {
|
|
419
|
+
return this._verifyResult;
|
|
420
|
+
}
|
|
421
|
+
/** @internal */
|
|
422
|
+
_setVerifyResult(code) {
|
|
423
|
+
if (code === "ERR_TLS_CERT_ALTNAME_INVALID")
|
|
424
|
+
code = "HOSTNAME_MISMATCH";
|
|
425
|
+
const result = typeof code === "string"
|
|
426
|
+
? X509_VERIFY_RESULTS[`V_ERR_${code}`]
|
|
427
|
+
: undefined;
|
|
428
|
+
if (result !== undefined)
|
|
429
|
+
this._verifyResult = result;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* `ossl_ssl_connect` (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:1847-1855`):
|
|
433
|
+
* `ossl_ssl_setup` and `ossl_start_ssl` over the host's handshake.
|
|
434
|
+
*
|
|
435
|
+
* @noRailsEquivalent PERMANENT
|
|
436
|
+
*/
|
|
437
|
+
async connect() {
|
|
438
|
+
const { ca, defaultPaths, minVersion, maxVersion } = await this.context._setup();
|
|
439
|
+
try {
|
|
440
|
+
await this.io.startSsl({
|
|
441
|
+
sslHostAddress: this.hostname,
|
|
442
|
+
verifyPeer: this.context.verifyMode !== OpenSSL.SSL.VERIFY_NONE,
|
|
443
|
+
verifyHostname: this.context.verifyHostname,
|
|
444
|
+
options: this.context.options,
|
|
445
|
+
session: this._session?._der ?? null,
|
|
446
|
+
sessionNewCb: (der) => {
|
|
447
|
+
if (this.context.sessionNewCb !== null)
|
|
448
|
+
this.context.sessionNewCb(this, new Session(der));
|
|
449
|
+
},
|
|
450
|
+
peerCertCb: (der) => {
|
|
451
|
+
this._peerCert = der === null ? null : new Certificate(der);
|
|
452
|
+
},
|
|
453
|
+
ca,
|
|
454
|
+
defaultPaths,
|
|
455
|
+
...(minVersion !== undefined && { minVersion }),
|
|
456
|
+
...(maxVersion !== undefined && { maxVersion }),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
catch (e) {
|
|
460
|
+
this._setVerifyResult(e?.code);
|
|
461
|
+
throw _osslStartSslError(e, this.io);
|
|
462
|
+
}
|
|
463
|
+
return this;
|
|
464
|
+
}
|
|
465
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2336-2348` */
|
|
466
|
+
set session(sess) {
|
|
467
|
+
this._session = sess;
|
|
468
|
+
}
|
|
469
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2977` */
|
|
470
|
+
get peerCert() {
|
|
471
|
+
return this._peerCert;
|
|
472
|
+
}
|
|
473
|
+
/** @noRailsEquivalent PERMANENT */
|
|
474
|
+
get cipher() {
|
|
475
|
+
return this.io.cipher ?? null;
|
|
476
|
+
}
|
|
477
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:396-410` */
|
|
478
|
+
postConnectionCheck(hostname) {
|
|
479
|
+
if (this.peerCert === null) {
|
|
480
|
+
let msg = "Peer verification enabled, but no certificate received.";
|
|
481
|
+
if (this.isUsingAnonCipher()) {
|
|
482
|
+
msg +=
|
|
483
|
+
` Anonymous cipher suite ${this.cipher[0]} was negotiated. ` +
|
|
484
|
+
"Anonymous suites must be disabled to use peer verification.";
|
|
485
|
+
}
|
|
486
|
+
throw new SSLError(msg);
|
|
487
|
+
}
|
|
488
|
+
if (!verifyCertificateIdentity(this.peerCert, hostname)) {
|
|
489
|
+
throw new SSLError(`hostname "${hostname}" does not match the server certificate`);
|
|
490
|
+
}
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* `using_anon_cipher?` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/ssl.rb:425-429`):
|
|
495
|
+
* the `aNULL` cipher list, OpenSSL's `ADH-` and `AECDH-` suites.
|
|
496
|
+
*
|
|
497
|
+
* @noRailsEquivalent PERMANENT
|
|
498
|
+
*/
|
|
499
|
+
isUsingAnonCipher() {
|
|
500
|
+
const name = this.cipher?.[0];
|
|
501
|
+
return name != null && /^A(EC)?DH-/.test(name);
|
|
502
|
+
}
|
|
503
|
+
/** @noRailsEquivalent PERMANENT */
|
|
504
|
+
close() {
|
|
505
|
+
if (this._closed)
|
|
506
|
+
return;
|
|
507
|
+
this._closed = true;
|
|
508
|
+
if (this.syncClose)
|
|
509
|
+
this.io.close();
|
|
510
|
+
}
|
|
511
|
+
/** @noRailsEquivalent PERMANENT */
|
|
512
|
+
isClosed() {
|
|
513
|
+
return this._closed;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* `ossl_start_ssl`'s raise (`vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:1797-1821`):
|
|
518
|
+
* the host's TLS failure as the `OpenSSL::SSL::SSLError` Ruby raises. A
|
|
519
|
+
* certificate-verify failure carries the host's verify code (the
|
|
520
|
+
* `SSL_VERIFY_CODES` `SSLError` matches) and `X509_verify_cert_error_string`'s
|
|
521
|
+
* text as its message, and is appended as `: certificate verify failed (...)`;
|
|
522
|
+
* any other failure appends OpenSSL's `ERR_reason_error_string`, the host
|
|
523
|
+
* error's `reason`, as `ossl_make_error` does (`ext/openssl/ossl.c:272-297`).
|
|
524
|
+
*/
|
|
525
|
+
function _osslStartSslError(e, io) {
|
|
526
|
+
if (!(e instanceof SSLError))
|
|
527
|
+
return e;
|
|
528
|
+
if (Function.prototype[Symbol.hasInstance].call(SSLError, e))
|
|
529
|
+
return e;
|
|
530
|
+
const host = e;
|
|
531
|
+
const errorAppend = SSL_VERIFY_CODES.includes(host.code)
|
|
532
|
+
? `: certificate verify failed (${host.message.replace(/; if the root CA .*$/s, "")})`
|
|
533
|
+
: `: ${host.reason ?? host.message}`;
|
|
534
|
+
let peeraddr = "(null)";
|
|
535
|
+
try {
|
|
536
|
+
const addrinfo = io.peeraddr?.();
|
|
537
|
+
if (addrinfo !== undefined)
|
|
538
|
+
peeraddr = `${addrinfo[2]}:${addrinfo[1]}`;
|
|
539
|
+
}
|
|
540
|
+
catch {
|
|
541
|
+
peeraddr = "(null)";
|
|
542
|
+
}
|
|
543
|
+
return new SSLError(`SSL_connect returned=1 errno=0 peeraddr=${peeraddr} state=error${errorAppend}`);
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* `OpenSSL::Cipher` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/cipher.rb:16`), the
|
|
547
|
+
* sliver Rails drives (`message_encryptor.rb:276-290`).
|
|
548
|
+
*
|
|
549
|
+
* @noRailsEquivalent PERMANENT — Ruby's openssl extension
|
|
550
|
+
* (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/cipher.rb:16`), which Rails calls
|
|
551
|
+
* without defining.
|
|
552
|
+
*/
|
|
553
|
+
export class Cipher {
|
|
554
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:1047 */
|
|
555
|
+
static CipherError = CipherError;
|
|
556
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:355 */
|
|
557
|
+
name;
|
|
558
|
+
mode = null;
|
|
559
|
+
currentKey = null;
|
|
560
|
+
currentIv = null;
|
|
561
|
+
impl = null;
|
|
562
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:139 */
|
|
563
|
+
constructor(name) {
|
|
564
|
+
this.name = name;
|
|
565
|
+
}
|
|
566
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:824 */
|
|
567
|
+
get keyLen() {
|
|
568
|
+
return this.cipherInfo().keyLength;
|
|
569
|
+
}
|
|
570
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:868 */
|
|
571
|
+
get ivLen() {
|
|
572
|
+
return this.cipherInfo().ivLength;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* `OpenSSL::Cipher#authenticated?` (`vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:547`),
|
|
576
|
+
* `EVP_CIPH_FLAG_AEAD_CIPHER` on the cipher — the AEAD modes the adapter
|
|
577
|
+
* names.
|
|
578
|
+
*
|
|
579
|
+
* @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:547
|
|
580
|
+
*/
|
|
581
|
+
authenticated() {
|
|
582
|
+
return AEAD_MODES.includes(this.cipherInfo().mode);
|
|
583
|
+
}
|
|
584
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:283 */
|
|
585
|
+
encrypt() {
|
|
586
|
+
this.mode = "encrypt";
|
|
587
|
+
return this;
|
|
588
|
+
}
|
|
589
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:302 */
|
|
590
|
+
decrypt() {
|
|
591
|
+
this.mode = "decrypt";
|
|
592
|
+
return this;
|
|
593
|
+
}
|
|
594
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:840 */
|
|
595
|
+
set key(key) {
|
|
596
|
+
const keyLen = this.keyLen;
|
|
597
|
+
if (key.length !== keyLen)
|
|
598
|
+
throw new ArgumentError(`key must be ${keyLen} bytes`);
|
|
599
|
+
this.currentKey = key;
|
|
600
|
+
}
|
|
601
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:884 */
|
|
602
|
+
set iv(iv) {
|
|
603
|
+
const ivLen = this.ivLen;
|
|
604
|
+
if (iv.length !== ivLen)
|
|
605
|
+
throw new ArgumentError(`iv must be ${ivLen} bytes`);
|
|
606
|
+
this.currentIv = iv;
|
|
607
|
+
}
|
|
608
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/lib/openssl/cipher.rb:56 */
|
|
609
|
+
randomIv() {
|
|
610
|
+
const str = SecureRandom.randomBytes(this.ivLen);
|
|
611
|
+
this.currentIv = str;
|
|
612
|
+
return str;
|
|
613
|
+
}
|
|
614
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:920 */
|
|
615
|
+
set authTag(tag) {
|
|
616
|
+
const impl = this.started();
|
|
617
|
+
if (!impl.setAuthTag) {
|
|
618
|
+
throw new Error("Crypto adapter does not support GCM auth tags (setAuthTag)");
|
|
619
|
+
}
|
|
620
|
+
try {
|
|
621
|
+
impl.setAuthTag(tag);
|
|
622
|
+
}
|
|
623
|
+
catch (e) {
|
|
624
|
+
if (e instanceof TypeError)
|
|
625
|
+
throw e;
|
|
626
|
+
throw new CipherError("unable to set AEAD tag");
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:898 */
|
|
630
|
+
get authTag() {
|
|
631
|
+
const impl = this.started();
|
|
632
|
+
if (!impl.getAuthTag) {
|
|
633
|
+
throw new Error("Crypto adapter does not support GCM auth tags (getAuthTag)");
|
|
634
|
+
}
|
|
635
|
+
return impl.getAuthTag();
|
|
636
|
+
}
|
|
637
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:958 */
|
|
638
|
+
set authData(data) {
|
|
639
|
+
const impl = this.started();
|
|
640
|
+
if (!impl.setAAD) {
|
|
641
|
+
throw new Error("Crypto adapter does not support AEAD auth data (setAAD)");
|
|
642
|
+
}
|
|
643
|
+
impl.setAAD(typeof data === "string" ? new TextEncoder().encode(data) : data);
|
|
644
|
+
}
|
|
645
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:504 */
|
|
646
|
+
update(data) {
|
|
647
|
+
try {
|
|
648
|
+
return this.started().update(data);
|
|
649
|
+
}
|
|
650
|
+
catch (e) {
|
|
651
|
+
if (e instanceof TypeError)
|
|
652
|
+
throw e;
|
|
653
|
+
throw new CipherError(e.message);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_cipher.c:568 */
|
|
657
|
+
final() {
|
|
658
|
+
try {
|
|
659
|
+
return this.started().final();
|
|
660
|
+
}
|
|
661
|
+
catch (e) {
|
|
662
|
+
if (e instanceof TypeError)
|
|
663
|
+
throw e;
|
|
664
|
+
throw new CipherError(e.message);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
cipherInfo() {
|
|
668
|
+
const crypto = getCrypto();
|
|
669
|
+
const info = crypto.getCipherInfo?.(this.name);
|
|
670
|
+
if (!info) {
|
|
671
|
+
throw new Error(`Crypto adapter does not know cipher "${this.name}" (getCipherInfo)`);
|
|
672
|
+
}
|
|
673
|
+
return info;
|
|
674
|
+
}
|
|
675
|
+
started() {
|
|
676
|
+
if (this.impl)
|
|
677
|
+
return this.impl;
|
|
678
|
+
if (!this.mode)
|
|
679
|
+
throw new Error("Cipher mode not set: call encrypt() or decrypt() first");
|
|
680
|
+
if (!this.currentKey)
|
|
681
|
+
throw new Error("Cipher key not set");
|
|
682
|
+
if (!this.currentIv)
|
|
683
|
+
throw new Error("Cipher iv not set");
|
|
684
|
+
const crypto = getCrypto();
|
|
685
|
+
this.impl =
|
|
686
|
+
this.mode === "encrypt"
|
|
687
|
+
? crypto.createCipheriv(this.name, this.currentKey, this.currentIv)
|
|
688
|
+
: crypto.createDecipheriv(this.name, this.currentKey, this.currentIv);
|
|
689
|
+
return this.impl;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function digestName(digest) {
|
|
693
|
+
return typeof digest === "string" ? digest : digest.algorithm;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* `OpenSSL::HMAC` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/hmac.rb:4`), the two
|
|
697
|
+
* class methods Rails calls (`request_forgery_protection.rb:466`,
|
|
698
|
+
* `message_verifier.rb:353`).
|
|
699
|
+
*
|
|
700
|
+
* @noRailsEquivalent PERMANENT — Ruby's openssl extension
|
|
701
|
+
* (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/hmac.rb:4`), which Rails calls without
|
|
702
|
+
* defining.
|
|
703
|
+
*/
|
|
704
|
+
export const HMAC = {
|
|
705
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/lib/openssl/hmac.rb:34 */
|
|
706
|
+
digest(digest, key, data) {
|
|
707
|
+
return getCrypto().createHmac(digestName(digest), key).update(data).digest();
|
|
708
|
+
},
|
|
709
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/lib/openssl/hmac.rb:56 */
|
|
710
|
+
hexdigest(digest, key, data) {
|
|
711
|
+
return getCrypto().createHmac(digestName(digest), key).update(data).digest("hex");
|
|
712
|
+
},
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* `OpenSSL::Random` (`vendor/ruby/v3.3.11/ext/openssl/ossl_rand.c:12`), the one
|
|
716
|
+
* module function bcrypt calls (`vendor/bcrypt-ruby/v3.1.20/lib/bcrypt/engine.rb:90`).
|
|
717
|
+
*
|
|
718
|
+
* @noRailsEquivalent PERMANENT — Ruby's openssl extension
|
|
719
|
+
* (`vendor/ruby/v3.3.11/ext/openssl/ossl_rand.c:12`), which no Rails file defines.
|
|
720
|
+
*/
|
|
721
|
+
export const Random = {
|
|
722
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_rand.c:105 */
|
|
723
|
+
randomBytes(len) {
|
|
724
|
+
return getCrypto().randomBytes(len);
|
|
725
|
+
},
|
|
726
|
+
};
|
|
727
|
+
function _derLength(length) {
|
|
728
|
+
if (length < 0x80)
|
|
729
|
+
return [length];
|
|
730
|
+
const bytes = [];
|
|
731
|
+
for (let n = length; n > 0; n = Math.floor(n / 256))
|
|
732
|
+
bytes.unshift(n & 0xff);
|
|
733
|
+
return [0x80 | bytes.length, ...bytes];
|
|
734
|
+
}
|
|
735
|
+
function _der(tag, ...contents) {
|
|
736
|
+
const body = contents.flatMap((c) => [...c]);
|
|
737
|
+
return Uint8Array.from([tag, ..._derLength(body.length), ...body]);
|
|
738
|
+
}
|
|
739
|
+
function _derInteger(value) {
|
|
740
|
+
const bytes = [];
|
|
741
|
+
for (let n = value; n > 0; n = Math.floor(n / 256))
|
|
742
|
+
bytes.unshift(n & 0xff);
|
|
743
|
+
if (bytes.length === 0 || bytes[0] & 0x80)
|
|
744
|
+
bytes.unshift(0);
|
|
745
|
+
return _der(0x02, Uint8Array.from(bytes));
|
|
746
|
+
}
|
|
747
|
+
function _derOid(oid) {
|
|
748
|
+
const [a, b, ...rest] = oid.split(".").map(Number);
|
|
749
|
+
const bytes = [a * 40 + b];
|
|
750
|
+
for (const arc of rest) {
|
|
751
|
+
const chunk = [arc & 0x7f];
|
|
752
|
+
for (let n = arc >>> 7; n > 0; n >>>= 7)
|
|
753
|
+
chunk.unshift((n & 0x7f) | 0x80);
|
|
754
|
+
bytes.push(...chunk);
|
|
755
|
+
}
|
|
756
|
+
return _der(0x06, Uint8Array.from(bytes));
|
|
757
|
+
}
|
|
758
|
+
const _utf8 = (s) => new TextEncoder().encode(s);
|
|
759
|
+
function _derTime(time) {
|
|
760
|
+
const iso = time.toISOString();
|
|
761
|
+
return _der(0x17, _utf8(iso.slice(2, 19).replace(/[-T:]/g, "") + "Z"));
|
|
762
|
+
}
|
|
763
|
+
const OIDS = {
|
|
764
|
+
CN: "2.5.4.3",
|
|
765
|
+
O: "2.5.4.10",
|
|
766
|
+
OU: "2.5.4.11",
|
|
767
|
+
C: "2.5.4.6",
|
|
768
|
+
basicConstraints: "2.5.29.19",
|
|
769
|
+
keyUsage: "2.5.29.15",
|
|
770
|
+
subjectAltName: "2.5.29.17",
|
|
771
|
+
sha256WithRSAEncryption: "1.2.840.113549.1.1.11",
|
|
772
|
+
};
|
|
773
|
+
/** `DEFAULT_OBJECT_TYPE` (`vendor/ruby/v3.3.11/ext/openssl/ossl_x509name.c:553`), `V_ASN1_UTF8STRING`. */
|
|
774
|
+
const DEFAULT_OBJECT_TYPE = 0x0c;
|
|
775
|
+
/** `OBJECT_TYPE_TEMPLATE` (`vendor/ruby/v3.3.11/ext/openssl/ossl_x509name.c:553-567`). */
|
|
776
|
+
const OBJECT_TYPE_TEMPLATE = {
|
|
777
|
+
C: 0x13,
|
|
778
|
+
countryName: 0x13,
|
|
779
|
+
serialNumber: 0x13,
|
|
780
|
+
dnQualifier: 0x13,
|
|
781
|
+
DC: 0x16,
|
|
782
|
+
domainComponent: 0x16,
|
|
783
|
+
emailAddress: 0x16,
|
|
784
|
+
};
|
|
785
|
+
const KEY_USAGE_BITS = [
|
|
786
|
+
"digitalSignature",
|
|
787
|
+
"nonRepudiation",
|
|
788
|
+
"keyEncipherment",
|
|
789
|
+
"dataEncipherment",
|
|
790
|
+
"keyAgreement",
|
|
791
|
+
"keyCertSign",
|
|
792
|
+
"cRLSign",
|
|
793
|
+
"encipherOnly",
|
|
794
|
+
];
|
|
795
|
+
/**
|
|
796
|
+
* `OpenSSL::PKey::RSA` (`vendor/ruby/v3.3.11/ext/openssl/ossl_pkey_rsa.c:86-131`),
|
|
797
|
+
* generated by the host's crypto adapter.
|
|
798
|
+
*
|
|
799
|
+
* @noRailsEquivalent PERMANENT
|
|
800
|
+
*/
|
|
801
|
+
export class RSA {
|
|
802
|
+
/** @internal */
|
|
803
|
+
_publicKeyDer;
|
|
804
|
+
/** @internal */
|
|
805
|
+
_privateKeyPem;
|
|
806
|
+
constructor(size) {
|
|
807
|
+
const crypto = getCrypto();
|
|
808
|
+
if (crypto.generateRsaKeyPair === undefined) {
|
|
809
|
+
throw new NotImplementedError("the crypto adapter has no RSA key generation");
|
|
810
|
+
}
|
|
811
|
+
const pair = crypto.generateRsaKeyPair(size);
|
|
812
|
+
this._publicKeyDer = pair.publicKeyDer;
|
|
813
|
+
this._privateKeyPem = pair.privateKeyPem;
|
|
814
|
+
}
|
|
815
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/lib/openssl/pkey.rb:343-345` */
|
|
816
|
+
get publicKey() {
|
|
817
|
+
const key = Object.create(RSA.prototype);
|
|
818
|
+
key._publicKeyDer = this._publicKeyDer;
|
|
819
|
+
key._privateKeyPem = null;
|
|
820
|
+
return key;
|
|
821
|
+
}
|
|
822
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_pkey_rsa.c:249` */
|
|
823
|
+
toPem() {
|
|
824
|
+
return this._privateKeyPem ?? _pem("PUBLIC KEY", this._publicKeyDer);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
function _pem(label, der) {
|
|
828
|
+
const base64 = btoa(String.fromCharCode(...der));
|
|
829
|
+
const lines = base64.match(/.{1,64}/g) ?? [];
|
|
830
|
+
return `-----BEGIN ${label}-----\n${lines.join("\n")}\n-----END ${label}-----\n`;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* `OpenSSL::X509::Name` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl/x509.rb:265-328`).
|
|
834
|
+
*
|
|
835
|
+
* @noRailsEquivalent PERMANENT
|
|
836
|
+
*/
|
|
837
|
+
export class Name {
|
|
838
|
+
_entries;
|
|
839
|
+
constructor(
|
|
840
|
+
/** @internal */
|
|
841
|
+
_entries = []) {
|
|
842
|
+
this._entries = _entries;
|
|
843
|
+
}
|
|
844
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/lib/openssl/x509.rb:305-316` */
|
|
845
|
+
static parse(str) {
|
|
846
|
+
let ary;
|
|
847
|
+
if (str.startsWith("/")) {
|
|
848
|
+
ary = str
|
|
849
|
+
.slice(1)
|
|
850
|
+
.split("/")
|
|
851
|
+
.map((i) => i.split("=", 2));
|
|
852
|
+
}
|
|
853
|
+
else {
|
|
854
|
+
ary = str.split(",").map((i) => i.trim().split("=", 2));
|
|
855
|
+
}
|
|
856
|
+
return new Name(ary);
|
|
857
|
+
}
|
|
858
|
+
/** @internal */
|
|
859
|
+
_toDer() {
|
|
860
|
+
return _der(0x30, ...this._entries.map(([key, value]) => {
|
|
861
|
+
if (OIDS[key] === undefined)
|
|
862
|
+
throw new ArgumentError(`invalid field name: ${key}`);
|
|
863
|
+
const type = OBJECT_TYPE_TEMPLATE[key] ?? DEFAULT_OBJECT_TYPE;
|
|
864
|
+
return _der(0x31, _der(0x30, _derOid(OIDS[key]), _der(type, _utf8(value))));
|
|
865
|
+
}));
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* `OpenSSL::X509::Extension` (`vendor/ruby/v3.3.11/ext/openssl/ossl_x509ext.c:358`).
|
|
870
|
+
*
|
|
871
|
+
* @noRailsEquivalent PERMANENT
|
|
872
|
+
*/
|
|
873
|
+
export class Extension {
|
|
874
|
+
oid;
|
|
875
|
+
_value;
|
|
876
|
+
critical;
|
|
877
|
+
constructor(
|
|
878
|
+
/** @noRailsEquivalent PERMANENT */
|
|
879
|
+
oid,
|
|
880
|
+
/** @internal */
|
|
881
|
+
_value,
|
|
882
|
+
/** @noRailsEquivalent PERMANENT */
|
|
883
|
+
critical = false) {
|
|
884
|
+
this.oid = oid;
|
|
885
|
+
this._value = _value;
|
|
886
|
+
this.critical = critical;
|
|
887
|
+
}
|
|
888
|
+
/** @internal */
|
|
889
|
+
_toDer() {
|
|
890
|
+
const critical = this.critical ? [_der(0x01, Uint8Array.of(0xff))] : [];
|
|
891
|
+
return _der(0x30, _derOid(OIDS[this.oid]), ...critical, _der(0x04, this._value));
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* `OpenSSL::X509::ExtensionFactory` (`vendor/ruby/v3.3.11/ext/openssl/ossl_x509ext.c:219-329`),
|
|
896
|
+
* for the `basicConstraints`, `keyUsage` and `subjectAltName` config strings.
|
|
897
|
+
*
|
|
898
|
+
* @noRailsEquivalent PERMANENT
|
|
899
|
+
*/
|
|
900
|
+
export class ExtensionFactory {
|
|
901
|
+
/** @noRailsEquivalent PERMANENT */
|
|
902
|
+
subjectCertificate = null;
|
|
903
|
+
/** @noRailsEquivalent PERMANENT */
|
|
904
|
+
issuerCertificate = null;
|
|
905
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/lib/openssl/x509.rb:17-25` */
|
|
906
|
+
createExtension(oid, value, critical = false) {
|
|
907
|
+
const items = value.split(",").map((item) => item.trim());
|
|
908
|
+
let der;
|
|
909
|
+
switch (oid) {
|
|
910
|
+
case "basicConstraints":
|
|
911
|
+
der = _der(0x30, ...(items.includes("CA:TRUE") ? [_der(0x01, Uint8Array.of(0xff))] : []));
|
|
912
|
+
break;
|
|
913
|
+
case "keyUsage": {
|
|
914
|
+
let bits = 0;
|
|
915
|
+
for (const item of items)
|
|
916
|
+
bits |= 0x80 >> KEY_USAGE_BITS.indexOf(item);
|
|
917
|
+
let unused = 0;
|
|
918
|
+
while (unused < 7 && !(bits & (1 << unused)))
|
|
919
|
+
unused++;
|
|
920
|
+
der = _der(0x03, Uint8Array.of(unused, bits));
|
|
921
|
+
break;
|
|
922
|
+
}
|
|
923
|
+
case "subjectAltName":
|
|
924
|
+
der = _der(0x30, ...items.map((item) => {
|
|
925
|
+
const [type, name] = item.split(":", 2);
|
|
926
|
+
if (type === "IP")
|
|
927
|
+
return _der(0x87, Uint8Array.from(name.split(".").map(Number)));
|
|
928
|
+
if (type === "DNS")
|
|
929
|
+
return _der(0x82, _utf8(name));
|
|
930
|
+
throw new ArgumentError(`unsupported subjectAltName type: ${type}`);
|
|
931
|
+
}));
|
|
932
|
+
break;
|
|
933
|
+
default:
|
|
934
|
+
throw new NotImplementedError(`unsupported extension: ${oid}`);
|
|
935
|
+
}
|
|
936
|
+
return new Extension(oid, der, critical);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* `OpenSSL::X509::Certificate` (`vendor/ruby/v3.3.11/ext/openssl/ossl_x509cert.c:815`).
|
|
941
|
+
*
|
|
942
|
+
* @noRailsEquivalent PERMANENT
|
|
943
|
+
*/
|
|
944
|
+
export class Certificate {
|
|
945
|
+
/** @noRailsEquivalent PERMANENT */
|
|
946
|
+
version = 0;
|
|
947
|
+
/** @noRailsEquivalent PERMANENT */
|
|
948
|
+
serial = 0;
|
|
949
|
+
/** @noRailsEquivalent PERMANENT */
|
|
950
|
+
subject = new Name();
|
|
951
|
+
/** @noRailsEquivalent PERMANENT */
|
|
952
|
+
issuer = new Name();
|
|
953
|
+
/** @noRailsEquivalent PERMANENT */
|
|
954
|
+
publicKey = null;
|
|
955
|
+
/** @noRailsEquivalent PERMANENT */
|
|
956
|
+
notBefore = null;
|
|
957
|
+
/** @noRailsEquivalent PERMANENT */
|
|
958
|
+
notAfter = null;
|
|
959
|
+
/** @noRailsEquivalent PERMANENT */
|
|
960
|
+
extensions = [];
|
|
961
|
+
/** @internal */
|
|
962
|
+
_der = null;
|
|
963
|
+
/**
|
|
964
|
+
* `ossl_x509_initialize` (`vendor/ruby/v3.3.11/ext/openssl/ossl_x509cert.c:110-137`)
|
|
965
|
+
* over a DER string, read for the subject and extensions of its `TBSCertificate`.
|
|
966
|
+
*/
|
|
967
|
+
constructor(der = null) {
|
|
968
|
+
if (der === null)
|
|
969
|
+
return;
|
|
970
|
+
this._der = der;
|
|
971
|
+
const tbs = _derSeq(_derSeq(_derRead(der, 0).value)[0].value);
|
|
972
|
+
const offset = tbs[0].tag === 0xa0 ? 1 : 0;
|
|
973
|
+
this.subject = new Name(_derSeq(tbs[offset + 4].value).map((rdn) => {
|
|
974
|
+
const [oid, value] = _derSeq(_derSeq(rdn.value)[0].value);
|
|
975
|
+
return [_derToOid(oid.value), new TextDecoder().decode(value.value)];
|
|
976
|
+
}));
|
|
977
|
+
const extensions = tbs.find((field) => field.tag === 0xa3);
|
|
978
|
+
if (extensions === undefined)
|
|
979
|
+
return;
|
|
980
|
+
for (const ext of _derSeq(_derRead(extensions.value, 0).value)) {
|
|
981
|
+
const parts = _derSeq(ext.value);
|
|
982
|
+
const critical = parts.length === 3 && parts[1].value[0] !== 0;
|
|
983
|
+
this.extensions.push(new Extension(_derToOid(parts[0].value), parts.at(-1).value, critical));
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_x509cert.c:681` */
|
|
987
|
+
addExtension(extension) {
|
|
988
|
+
this.extensions.push(extension);
|
|
989
|
+
return extension;
|
|
990
|
+
}
|
|
991
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_x509cert.c:523` */
|
|
992
|
+
sign(key, digest) {
|
|
993
|
+
if (digest.algorithm !== "sha256") {
|
|
994
|
+
throw new NotImplementedError(`unsupported digest: ${digest.algorithm}`);
|
|
995
|
+
}
|
|
996
|
+
const crypto = getCrypto();
|
|
997
|
+
if (crypto.sign === undefined || key._privateKeyPem === null) {
|
|
998
|
+
throw new NotImplementedError("the crypto adapter has no RSA signing");
|
|
999
|
+
}
|
|
1000
|
+
const algorithm = _der(0x30, _derOid(OIDS.sha256WithRSAEncryption), _der(0x05));
|
|
1001
|
+
const tbs = _der(0x30, _der(0xa0, _derInteger(this.version)), _derInteger(this.serial), algorithm, this.issuer._toDer(), _der(0x30, _derTime(this.notBefore), _derTime(this.notAfter)), this.subject._toDer(), this.publicKey._publicKeyDer, ...(this.extensions.length > 0
|
|
1002
|
+
? [_der(0xa3, _der(0x30, ...this.extensions.map((e) => e._toDer())))]
|
|
1003
|
+
: []));
|
|
1004
|
+
const signature = crypto.sign("sha256", tbs, key._privateKeyPem);
|
|
1005
|
+
this._der = _der(0x30, tbs, algorithm, _der(0x03, Uint8Array.of(0), signature));
|
|
1006
|
+
return this;
|
|
1007
|
+
}
|
|
1008
|
+
/** @noRailsEquivalent PERMANENT — `vendor/ruby/v3.3.11/ext/openssl/ossl_x509cert.c:209` */
|
|
1009
|
+
toPem() {
|
|
1010
|
+
return _pem("CERTIFICATE", this._der);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* `OpenSSL` (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl.rb:16`), so a ported body
|
|
1015
|
+
* spells `OpenSSL::HMAC.digest` the way the Ruby does.
|
|
1016
|
+
*
|
|
1017
|
+
* @noRailsEquivalent PERMANENT — Ruby's openssl extension
|
|
1018
|
+
* (`vendor/ruby/v3.3.11/ext/openssl/lib/openssl.rb:16`), which no Rails file defines.
|
|
1019
|
+
*/
|
|
1020
|
+
export const OpenSSL = {
|
|
1021
|
+
Cipher,
|
|
1022
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_ssl.c:2999-3000 */
|
|
1023
|
+
SSL: {
|
|
1024
|
+
VERIFY_NONE: 0,
|
|
1025
|
+
VERIFY_PEER: 1,
|
|
1026
|
+
OP_ALL,
|
|
1027
|
+
OP_DONT_INSERT_EMPTY_FRAGMENTS,
|
|
1028
|
+
OP_NO_COMPRESSION,
|
|
1029
|
+
SSLError,
|
|
1030
|
+
/** @internal */
|
|
1031
|
+
SSL_VERIFY_CODES,
|
|
1032
|
+
SSLContext,
|
|
1033
|
+
SSLSocket,
|
|
1034
|
+
Session,
|
|
1035
|
+
verifyCertificateIdentity,
|
|
1036
|
+
verifyHostname,
|
|
1037
|
+
verifyWildcard,
|
|
1038
|
+
},
|
|
1039
|
+
X509: { Store, Name, Certificate, Extension, ExtensionFactory, ...X509_VERIFY_RESULTS },
|
|
1040
|
+
PKey: { RSA },
|
|
1041
|
+
HMAC,
|
|
1042
|
+
Random,
|
|
1043
|
+
Digest: {
|
|
1044
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_digest.c:400 */
|
|
1045
|
+
MD5: new DigestClass("md5", "OpenSSL::Digest::MD5"),
|
|
1046
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_digest.c:400 */
|
|
1047
|
+
SHA1: new DigestClass("sha1", "OpenSSL::Digest::SHA1"),
|
|
1048
|
+
/** @noRailsEquivalent PERMANENT — vendor/ruby/v3.3.11/ext/openssl/ossl_digest.c:400 */
|
|
1049
|
+
SHA256: new DigestClass("sha256", "OpenSSL::Digest::SHA256"),
|
|
1050
|
+
},
|
|
1051
|
+
};
|
|
1052
|
+
//# sourceMappingURL=openssl.js.map
|