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

Java wrapper for SDK #179

Merged
merged 24 commits into from
Nov 28, 2023
Merged

Java wrapper for SDK #179

merged 24 commits into from
Nov 28, 2023

Conversation

lukpotSym
Copy link
Contributor

@lukpotSym lukpotSym commented Aug 21, 2023

Type of change

- [ ] Bug fix
- [x] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Added a Maven-based Java project that wraps native C library for the SDK and exposed its commands through BitwardenClient class.

Code changes

  • Updated schemas.ts to generate Java classes for the API - difference with current generators is that it creates multiple files
  • Added BitWardenClient class as a wrapper for the native SDK library
  • BitwardenLibrary inteface uses JNA to link to the native lib
  • AutoCloseable inteface implemented to deal with freeing memory, client can be used with try-with-resources or close() can be called explicitly (finalize() method is deprecated in newer Java versions)

support/scripts/schemas.ts Outdated Show resolved Hide resolved
languages/java/pom.xml Outdated Show resolved Hide resolved
crates/sdk-schemas/src/main.rs Outdated Show resolved Hide resolved
languages/java/src/main/java/bit/sdk/BitwardenClient.java Outdated Show resolved Hide resolved
@lukpotSym lukpotSym requested a review from a team as a code owner September 12, 2023 20:48
.github/workflows/generate_schemas.yml Outdated Show resolved Hide resolved
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

Please follow the .NET sdk and unwrap all responses. A consumer of the library shouldn't be exposed to the internal response models.

.vscode/tasks.json Outdated Show resolved Hide resolved
languages/java/build.gradle Outdated Show resolved Hide resolved
languages/java/src/main/java/bit/sdk/BitwardenClient.java Outdated Show resolved Hide resolved
languages/java/src/main/java/bit/sdk/BitwardenClient.java Outdated Show resolved Hide resolved
languages/java/src/main/java/bit/sdk/BitwardenClient.java Outdated Show resolved Hide resolved
languages/java/src/main/java/bit/sdk/BitwardenClient.java Outdated Show resolved Hide resolved
@lukpotSym lukpotSym requested review from Hinton and vgrassia October 18, 2023 09:43
@vgrassia
Copy link
Member

vgrassia commented Nov 2, 2023

Workflows look good to me.

dani-garcia
dani-garcia previously approved these changes Nov 22, 2023
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Code looks good to me, two small naming changes, but I don't think they are very important

languages/java/build.gradle Outdated Show resolved Hide resolved
languages/java/settings.gradle Outdated Show resolved Hide resolved
@bitwarden-bot
Copy link

bitwarden-bot commented Nov 23, 2023

Logo
Checkmarx One – Scan Summary & Details9e449228-3143-43b1-8a67-570a00135650

New Issues

Severity Issue Source File / Package Checkmarx Insight
HIGH Reflected_XSS /languages/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt: 294 Attack Vector
MEDIUM Unchecked_Input_for_Loop_Condition /languages/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt: 294 Attack Vector

Fixed Issues

Severity Issue Source File / Package
HIGH Reflected_XSS /languages/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt: 115
MEDIUM Unchecked_Input_for_Loop_Condition /languages/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt: 115

dani-garcia
dani-garcia previously approved these changes Nov 23, 2023
.vscode/tasks.json Outdated Show resolved Hide resolved
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

Some minor nits, please also run intellij reformat code since many of the members can be made final.

.github/workflows/generate_schemas.yml Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
.vscode/tasks.json Outdated Show resolved Hide resolved
languages/java/.gitignore Outdated Show resolved Hide resolved
languages/java/README.md Outdated Show resolved Hide resolved
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

Minor nit remaining in the readme, looks good otherwise.

Hinton
Hinton previously approved these changes Nov 27, 2023
dani-garcia
dani-garcia previously approved these changes Nov 27, 2023
@lukpotSym lukpotSym dismissed stale reviews from dani-garcia and Hinton via b471480 November 27, 2023 13:12
@lukpotSym
Copy link
Contributor Author

Hi @dani-garcia @Hinton, I re-requested the review since some prechecks failed - a folder name for generate schemas wasn't updated after changing package name, and schemas.ts file needed prettier reformat. It seems I need approvals for prechecks to run again, hopefully they will pass this time.

dani-garcia
dani-garcia previously approved these changes Nov 27, 2023
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Seems the android workflow doesn't work correctly with external PRs and is failing, but that's not related to these changes.

vgrassia
vgrassia previously approved these changes Nov 27, 2023
@lukpotSym lukpotSym dismissed stale reviews from vgrassia and dani-garcia via 65e25d4 November 27, 2023 15:04
@lukpotSym
Copy link
Contributor Author

Seems the android workflow doesn't work correctly with external PRs and is failing, but that's not related to these changes.

Yes, android fails for all external PRs. I fixed a gradle issue that appeared on java workflow, it passes locally, but need to confirm if it now works on github environment

@dani-garcia
Copy link
Member

The java workflow seems to be failing still. I can reproduce the issue locally if I copy the libbitwarden_c.dylib file myself into src/main/resources/darwin-aarch64. If I run gradle jar after that, the build fails.

To solve it I just commented this whole block:

/*
jar {
//  Requires GitHub workflow to copy native library to resources
//  Uncomment the line below and copyNativeLib task above to use the local build (modify architecture if needed)
//    dependsOn tasks.named("copyNativeLib")
    into('darwin-aarch64') {
        from 'src/main/resources/darwin-aarch64'
    }
    into('darwin-x64') {
        from 'src/main/resources/darwin-x64'
    }
    into('ubuntu-x64') {
        from 'src/main/resources/ubuntu-x64'
    }
    into('windows-x64') {
        from 'src/main/resources/windows-x64'
    }
}
*/

The native libraries seem to be copied just fine as long as they are in the resources folder, and the error goes away, maybe that can work for CI too? For local development you can uncomment the copyNativeLib task and use that to copy the files to the correct place.

@lukpotSym
Copy link
Contributor Author

The java workflow seems to be failing still. I can reproduce the issue locally if I copy the libbitwarden_c.dylib file myself into src/main/resources/darwin-aarch64. If I run gradle jar after that, the build fails.

To solve it I just commented this whole block:

/*
jar {
//  Requires GitHub workflow to copy native library to resources
//  Uncomment the line below and copyNativeLib task above to use the local build (modify architecture if needed)
//    dependsOn tasks.named("copyNativeLib")
    into('darwin-aarch64') {
        from 'src/main/resources/darwin-aarch64'
    }
    into('darwin-x64') {
        from 'src/main/resources/darwin-x64'
    }
    into('ubuntu-x64') {
        from 'src/main/resources/ubuntu-x64'
    }
    into('windows-x64') {
        from 'src/main/resources/windows-x64'
    }
}
*/

The native libraries seem to be copied just fine as long as they are in the resources folder, and the error goes away, maybe that can work for CI too? For local development you can uncomment the copyNativeLib task and use that to copy the files to the correct place.

Thanks for the suggestion, it does indeed copy all resources without the jar task, and I've think I managed to set it up to correctly to copy local libs when uncommented.

@lukpotSym
Copy link
Contributor Author

Hi @dani-garcia @vgrassia @Hinton , please let me know if the current Build Java SDK workflow failure is expected on the forked repo - publishing the package gets 403 forbidden error. I am using the same approach as the android build, with secrets.GITHUB_TOKEN.

@Hinton
Copy link
Member

Hinton commented Nov 28, 2023

Pull requests from forks don't have access to the repository secrets and the GH token is read only. I would expect the publish step to fail but all steps leading up to it should succeed.

@vgrassia vgrassia self-requested a review November 28, 2023 14:52
@dani-garcia dani-garcia merged commit 31c005f into bitwarden:master Nov 28, 2023
50 of 52 checks passed
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.

5 participants