Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-build for Scala.js #515

Merged
merged 50 commits into from
Aug 10, 2021
Merged

Cross-build for Scala.js #515

merged 50 commits into from
Aug 10, 2021

Conversation

armanbilge
Copy link
Member

@armanbilge armanbilge commented Jul 29, 2021

Blocked by tpolecat/SourcePos#6 (cc @ChristopherDavenport) and also problems with scodec-bits. Update: I worked around the scodec issue. Just waiting on sourcepos and hopefully should be good to go? I'm have trouble running tests on local so going to be relying on CI for this one.

This is actually very nearly a pure cross. The most notable difference for JS was resurrecting the scram implementation courtesy of @mpilquist that was subsequently scrapped in #260 as well as adding an npm dependency to saslprep.

Comment on lines 95 to 100
private def Hi(str: String, salt: ByteVector, iterations: Int): ByteVector = {
// TODO It is unfortunate that we have to use a sync API here when an async is available
// To make the change here will require running an F[_]: Async up the hiearchy
val salted = crypto.pbkdf2Sync(str, salt.toByteBuffer.arrayBuffer(), iterations, 8 * 32, "sha256")
bufferToByteVector(salted)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate? PBKDF-2 should be completely CPU bound

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node.js offers an async version of this method with a callback. I assume they have a good reason for doing so.

My best guess would be that you are indeed right that it is CPU-bound, but it's CPU intensive enough that it would detrimentally block a single-threaded Node.js app.

@armanbilge armanbilge mentioned this pull request Jul 29, 2021
@tpolecat
Copy link
Member

tpolecat commented Jul 29, 2021

I appreciate your effort on this but I'm not convinced that anyone actually needs it. It's a significant complication and maintenance burden going forward. Can you justify this a little bit?

@armanbilge
Copy link
Member Author

No worries, completely understandable! I recently got http4s cross-building to JS (including ember-server) in http4s/http4s#4938. Many people seem interested in using this with Node.js on AWS lambda and/or similar services. Skunk would be an important part of that I assume.

@codecov-commenter
Copy link

codecov-commenter commented Aug 7, 2021

Codecov Report

Merging #515 (694f0d5) into main (ee39517) will increase coverage by 0.01%.
The diff coverage is 90.62%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #515      +/-   ##
==========================================
+ Coverage   85.21%   85.22%   +0.01%     
==========================================
  Files         121      124       +3     
  Lines        1589     1591       +2     
  Branches       47       38       -9     
==========================================
+ Hits         1354     1356       +2     
  Misses        235      235              
Impacted Files Coverage Δ
modules/core/jvm/src/main/scala/SSLPlatform.scala 11.11% <ø> (ø)
...in/scala/net/message/PasswordMessagePlatform.scala 91.66% <ø> (ø)
...shared/src/main/scala-2.13+/data/ArrPlatform.scala 100.00% <ø> (ø)
...odules/core/shared/src/main/scala-2/SqlState.scala 100.00% <ø> (ø)
...red/src/main/scala-2/codec/EnumCodecPlatform.scala 100.00% <ø> (ø)
...red/src/main/scala-2/syntax/StringContextOps.scala 100.00% <ø> (ø)
...s/core/shared/src/main/scala-2/util/Twiddler.scala 100.00% <ø> (ø)
...s/core/shared/src/main/scala/AppliedFragment.scala 100.00% <ø> (ø)
modules/core/shared/src/main/scala/Channel.scala 95.23% <ø> (ø)
modules/core/shared/src/main/scala/Codec.scala 100.00% <ø> (ø)
... and 115 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee39517...694f0d5. Read the comment docs.

@armanbilge armanbilge marked this pull request as ready for review August 7, 2021 03:39
@armanbilge
Copy link
Member Author

Thanks to fs2 3.1.0, all tests are passing now here. This is ready, all it needs is tpolecat/SourcePos#6.

// TODO It is unfortunate that we have to use a sync API here when an async is available
// To make the change here will require running an F[_]: Async up the hiearchy
val salted = crypto.pbkdf2Sync(str, byteVectorToUint8Array(salt), iterations, 8 * 32, "sha256")
bufferToByteVector(salted).take(32)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpilquist you wouldn't happen to have any guesses why this take(32) is necessary here, but not on JVM?

@tpolecat
Copy link
Member

tpolecat commented Aug 7, 2021

Amazing! I'm out for the day but will have a closer look later this weekend.

@armanbilge armanbilge marked this pull request as draft August 10, 2021 15:31
@tpolecat
Copy link
Member

Ok SourcePos 1.0.1 has been published. It may take a little while to appear on Central.

@armanbilge
Copy link
Member Author

Yep already on it :) central is fast these days!

@armanbilge armanbilge marked this pull request as ready for review August 10, 2021 17:22
Copy link
Member

@tpolecat tpolecat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some very minor things, but also can you explain why scala-js isn't running all the SSL tests?

modules/core/js/src/main/scala/SSLPlatform.scala Outdated Show resolved Hide resolved
modules/core/jvm/src/main/scala/SSLPlatform.scala Outdated Show resolved Hide resolved
modules/core/shared/src/main/scala/SSL.scala Outdated Show resolved Hide resolved
import skunk._
import natchez.Trace.Implicits.noop

trait SslTestPlatform { self: SslTest =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these tests not run for JS?

Copy link
Member Author

@armanbilge armanbilge Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On SJS I'm not running the tests that use the Trusted SSL (which trusts all certificates). AFAICT no such configuration exists in Node.js and therefore is not in fs2.io.js either. The way you would achieve a similar configuration I think is by setting the env variable NODE_TLS_REJECT_UNAUTHORIZED=0 before running Node.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you just have to tell node to ignore EVERY certificate? You can't do it per connection? That's kind of nuts.

Copy link
Member Author

@armanbilge armanbilge Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can do it on the global level with the environment variable and possibly on the socket level by fiddling with the TLS parameters: https://github.com/typelevel/fs2/blob/main/io/js/src/main/scala/fs2/io/net/tls/TLSParameters.scala#L51

But, no way to do it for an entire context.

@armanbilge
Copy link
Member Author

Should I be concerned and/or do something about the codecov/patch failure?

@tpolecat
Copy link
Member

No, don't worry about coverage.

@tpolecat
Copy link
Member

Any last words before I slam the button?

@armanbilge
Copy link
Member Author

Lol nope, thanks for merging!!

@tpolecat tpolecat merged commit e9cea1b into typelevel:main Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants