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

Linux support #40

Closed
wants to merge 4 commits into from
Closed

Linux support #40

wants to merge 4 commits into from

Conversation

dscreve
Copy link
Collaborator

@dscreve dscreve commented Mar 2, 2025

This PR add Linux support and maybe Windows (not tested).

@beatt83 beatt83 self-requested a review March 3, 2025 14:13
@beatt83
Copy link
Owner

beatt83 commented Mar 3, 2025

Hey @dscreve. This is awesome actually, good job. I would say we require a workflow that runs the tests in Linux. I agree with you this probably works on windows and (maybe) on android.

Copy link
Owner

@beatt83 beatt83 left a comment

Choose a reason for hiding this comment

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

So I checked your PR, :) as for now tests need to be updated they are failing building. This just happens because if you removed the SecKey: KeyRepresentable conformance, if you add the #if canImport(Security) and not remove the conformances the tests don't need to be fixed to run on Apple platforms.

Even so be aware that the a few tests are failing mainly the RSA example tests.

}

#else
return Data((0 ..< count).map { _ in UInt8.random(in: UInt8.min ... UInt8.max) })
Copy link
Owner

@beatt83 beatt83 Mar 3, 2025

Choose a reason for hiding this comment

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

We need to be careful here, UInt8.random may not be cryptographically secure, this basically depends on the platform, in Linux it may use dev/urandom or not.

I was checking if CryptoSwift had a secure random implementation for Linux they don't seem to have. Any opinion on this?

If not I would say at least for now we should add this in the documentation as a warning when running on Linux ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

/dev/urandom is available on most distribution : I think we can rely on it because if this not present, this a really customised distribution

Copy link
Owner

Choose a reason for hiding this comment

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

Cool agree with that.

Comment on lines 82 to 88
extension SecKey: KeyRepresentable {
public var jwk: JWK {
get throws {
try SecKeyExtended(secKey: self).jwk()
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

SecKey is still a big part of Apple systems, this conformance helps with the adoption of the library.

Instead of deleting the code you need to do this when SecKey is not available (there are a few other places on this PR that this is applicable):

#if canImport(Security)

extension SecKey: KeyRepresentable {
    public var jwk: JWK {
        get throws {
            try SecKeyExtended(secKey: self).jwk()
        }
    }
}

#else

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will fix this

@beatt83
Copy link
Owner

beatt83 commented Mar 6, 2025

Hey @dscreve . Ive been checking this and I fixed most of the problems and added a linux workflow so it can be tested, I've also tested on a docker and everything seems to run fine. Can you give me permissions so I can create a PR on your forked repo?

There is just as far as I see a remaining issue, the SWCompression fails on decompressing the tests from the RFC. So this library cannot be used.

@dscreve
Copy link
Collaborator Author

dscreve commented Mar 6, 2025

Hey @dscreve . Ive been checking this and I fixed most of the problems and added a linux workflow so it can be tested, I've also tested on a docker and everything seems to run fine. Can you give me permissions so I can create a PR on your forked repo?

There is just as far as I see a remaining issue, the SWCompression fails on decompressing the tests from the RFC. So this library cannot be used.

I was just working on this and discovered the SWCompression issue as you did....I commit my job and give you permissions. Is there something I have to do to allow you to fork ?

@beatt83
Copy link
Owner

beatt83 commented Mar 6, 2025

  • Is there something I have to do to allow you to fork ?

Since it is a forked repo if you don't mind just on the settings allow me to push. I created a different branch on top of your main I push and you decide.

The RSA tests were also failing the way you changed, I added a ci workflow to run the tests in Linux, I want to check what is the problem if there is other way to fix it without using Security framework.

@dscreve
Copy link
Collaborator Author

dscreve commented Mar 6, 2025 via email

@beatt83
Copy link
Owner

beatt83 commented Mar 6, 2025

@dscreve went to check this statement:

The RSA failed because you use 1024 RSA keys which is too short. Use 2048 keys and it will work.

It is true but you can use the other init that will accept 1024 _RSA.Encryption.PublicKey(unsafeDERRepresentation:) and it will work I changed this on the changes I will push ;)

So just the if the SWCompression issue is fixed and all tests run on linux we can merge ;)

@dscreve
Copy link
Collaborator Author

dscreve commented Mar 6, 2025 via email

@dscreve
Copy link
Collaborator Author

dscreve commented Mar 8, 2025

I have rewritten zlib compression to be compatible with NSData implementation.
This should be ok for now.

@beatt83
Copy link
Owner

beatt83 commented Mar 8, 2025

I have rewritten zlib compression to be compatible with NSData implementation. This should be ok for now.

Hey mate.
I was checking this in the weekend I left a PR for you on that repo :) .

Also can you give me the push permissions on your fork branch? I would really like to commit my changes on your PR, so we can have the GitHub actions as well.

@dscreve
Copy link
Collaborator Author

dscreve commented Mar 8, 2025 via email

@beatt83
Copy link
Owner

beatt83 commented Mar 8, 2025

@dscreve you can go to your forked repository -> settings -> collaborators -> add me as a collaborator beatt83.

This will enable me to push a branch and create a pr.

Since its a fork repo there is no problem I guess ;)

Screenshot 2025-03-08 at 20 52 37

@dscreve
Copy link
Collaborator Author

dscreve commented Mar 8, 2025 via email

@beatt83
Copy link
Owner

beatt83 commented Mar 8, 2025

Ok. I’ll do it tomorrow (it’s 22PM here)

Same :) U will be off site for a week, so I guess you got time, if I have access during the morning I will do it then ;) .

@dscreve
Copy link
Collaborator Author

dscreve commented Mar 8, 2025 via email

@beatt83
Copy link
Owner

beatt83 commented Mar 8, 2025

@dscreve I still cannot push but for the sake of time I went for a different approach. I pushed here and created a new PR #42 also I added you as a collaborator, hope you dont mind. ;)

@beatt83 beatt83 closed this Mar 8, 2025
@beatt83 beatt83 reopened this Mar 8, 2025
@beatt83
Copy link
Owner

beatt83 commented Mar 8, 2025

Closing this PR since we now have #42 .

@beatt83 beatt83 closed this Mar 8, 2025
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.

2 participants