Skip to content

Go Proton Drive SDK with basic CRUD operations - #19

Closed
clayliddell wants to merge 28 commits into
ProtonDriveApps:mainfrom
clayliddell:go-sdk
Closed

clayliddell wants to merge 28 commits into
ProtonDriveApps:mainfrom
clayliddell:go-sdk

Conversation

@clayliddell

Copy link
Copy Markdown

Introduces a complete, pure-Go SDK for Proton Drive under go/. This PR provides a go package with basic operations for handling CRUD operations on Proton Drive.

What's included

  • Authentication: SRP login, session resume/export, mailbox password support, TOTP 2FA
  • Directory operations: listing, hash-based child search, folder creation
  • File operations: small-file (<4 MiB) and large-file (>4 MiB via v2 block API) uploads, streaming downloads with offset support, move, trash, empty trash
  • Crypto: PGP key generation, encryption, name hashing, block-level decryption
  • Testing: unit + integration test coverage for all operations

Testing

I've added unit tests and integration tests to validate functionality. Refer to TESTING.md for how to run the tests.

Usage

Refer to USAGE.md

Why?

There are existing apps using Proton Drive via the Proton API Library that no longer appear to be working (For example, the popular RClone project and it's Android Wrapper RoundSync).

Having an official go SDK would be huge for the Proton Drive community and users of these apps 😄

Large files (>4MB) now upload through the v2 draft/block/revision
flow: create file draft, encrypt blocks with session key and detached
signatures, upload block data to storage, then commit the revision.

Key fixes discovered during implementation:
- EncSignature must be string (PGP armored) not []byte; the API
  rejects base64-encoded armored data with 400/2002.
- Verification token uses server-provided verification code from
  GET /drive/v2/volumes/.../verification, not the content key packet.
  Token = verificationCode XOR encryptedData (zero-padded).
- Block data is encrypted with EncryptAndSign (not plain Encrypt)
  to include the inline signature matching the detached signature.

Live-verified with TestIntegrationUploadLargeFile (4MB+1KB file).
- Remove unused SessionHandler interface (SessionHooks serves this role)
- Remove unused ErrNotImplemented sentinel error
- Remove unused manager parameter from bootstrapDriveState chain
- Remove unused userAgent parameter from newManager (no upstream support)
- Remove dead variable assignments (passphraseSignature, signatureEmail)
- Remove unused firstNonEmpty helper from integration tests
- Remove _ = xAttrCommon discard (variable is used)
- Simplify TrashFolder (remove _ = recursive discard)
- types.go: all types, constants, Driver and Dialer interfaces
- client.go: Client type, all constructors and 16 methods
- session.go: Session, SessionHooks, Session.Valid
- errors.go: all sentinel errors
- fake.go: FakeDialer, FakeDriver and their methods
- dialer.go: NewDialer
- integration_config.go: IntegrationConfig, LoadIntegrationConfig, Validate, LoginOptions
- Mark SHA1 digest and block size retrieval as done
- Mark encrypted uploads and revision commit flow as done
- Update integrationCoverageChecklist() from 4/16 to 16/16 implemented
Add tests for all Client methods using FakeDriver:
- RootID (success + error), ListDirectory, SearchChild (found + not found)
- CreateFolder, GetRevisionAttrs, DownloadFile, UploadFile (success + error)
- MoveFile/Folder (success + error), TrashFile/Folder (success + error)
- EmptyTrash, ClearCache (call counting)
- FakeDialer.Resume (success + error), NewClientWithSession success path
- Nil-client guard for all 13 error-returning methods
…hChild

- TestIntegrationResume: login, capture session, create resumed client, verify About
- TestIntegrationDownloadWithOffset: upload 36-byte file, download from offset 10, verify content
- TestIntegrationSearchChildPositiveMatch: create folder, search for it, verify ID matches

Both new download and search tests create fresh clients to avoid depending on
singleton state after TestIntegrationLogout.
Split 1323-line standalone_driver.go into focused files:
- standalone_driver.go (~670 lines): core struct, Driver methods, traversal, move, trash
- upload.go (~310 lines): small-file and large-file upload flows
- download.go (~270 lines): streaming block download with offset
- crypto_helpers.go (~210 lines): PGP key gen, encryption, name hashing

Readability improvements:
- Add comments to all types, methods, and non-obvious logic in internal_drive_api.go
- Add comments to all internal functions in dialer.go (SRP flow, account bootstrap)
- Rename variables for clarity (manifestSignatureData -> manifestSigData, etc.)
- Extract helper functions: last32, sha256Sum, detectMIMEType
- Extract copyNodeSecretMaterial to eliminate duplicated deep-copy logic
- Factor uploadLargeFileFlow out of uploadFile for clearer routing
- README.md: slim to overview + project layout + links to USAGE/TESTING/COMPATIBILITY
- USAGE.md: complete examples for all operations (login, resume, list, search,
  create folder, upload small/large, download, offset download, revision attrs,
  move, trash, cache, logout, and fake driver injection for tests)
- TESTING.md: merged INTEGRATION.md with unit test instructions, updated
  coverage list, added command reference table
- Delete INTEGRATION.md (superseded by TESTING.md)
Add RFC 6238 TOTP generation (totp.go) so the SDK can auto-generate 2FA
codes from a base32 secret. LoginOptions gains a TOTPSecret field;
IntegrationConfig maps its two_factor_code to it. TwoFactorCode still
accepts pre-generated codes for backward compatibility.

Mailbox password path already worked (two-password mode uses mailbox
password as keyPass). Verified end-to-end with live integration tests
including 2FA + mailbox password.

Fix all 22 golangci-lint findings (0 issues now):
- 5 errcheck: nolint deferred resp.Body.Close() / blockReader.Close()
- 17 unused: remove dead API surface from internal_drive_api.go
  and mustEncryptSessionKeyPacket from upload.go

BaseURL already defaults to production when empty. Update USAGE.md
with simpler login examples, staging, TOTP, and mailbox password
examples.
- prevent race condition in unit tests
- minor formatting changes
- use provided user agent on http client
- reuse revision attrs when downloading files to reduce http calls
@cebas

cebas commented Mar 25, 2026

Copy link
Copy Markdown

Nice work! I'll give it a try someday.

@clayliddell clayliddell mentioned this pull request Mar 25, 2026
2 of 3 tasks
@horejsek

Copy link
Copy Markdown

Thank you for your contribution. However, it is not aligned with our goals. We want to have at most two implementations, currently C# and JavaScript. Any other supported languages must be implemented as binding for one of the two. Currently, we support only languages used by our own clients, that is JavaScript, C#, Swift and Kotlin, where the last two are using C# over C-interface. Lastly, we want the Drive SDK to focus only on the Drive logic, not implementing directly authentication and other dependencies.

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.

3 participants