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

Add AIProxy support for certificate pinning #54

Merged

Conversation

lzell
Copy link
Contributor

@lzell lzell commented Jun 26, 2024

  • Requests to AIProxy only succeed if we recognize the public certificate used in establishing the tls handshake. This makes performing a MITM attack more challenging. MITM is a common tactic against mobile apps because the attacker controls the hardware. They can use desktop proxy software to MITM an app and decrypt the https requests as they go by (this requires installing a trusted certificate on the attacker's phone, which is also trivial).

  • This is one additional layer of security in our defense against API abuse.

  • The majority of this patch only impacts AIProxy-specific code, however there are two spots where a change was required to the core codebase. I will highlight each with a comment. For details about why they were changed (which I consider an Apple bug) please see the docstring on AIProxyCertificatePinning.swift

/// for: request,
/// delegate: mySession.delegate as? URLSessionTaskDelegate
/// )
///
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamesrochabrun you will see I made the above changes to two places in the core of this lib. I tested both of them using the SwiftOpenAIExample app under the 'Default OpenAI Service' tab

let (data, response) = try await session.bytes(
for: request,
delegate: session.delegate as? URLSessionTaskDelegate
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change to the core lib here

let (data, response) = try await session.bytes(
for: request,
delegate: session.delegate as? URLSessionTaskDelegate
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change to the core lib here

@jamesrochabrun jamesrochabrun merged commit adf2112 into jamesrochabrun:main Jun 26, 2024
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.

None yet

2 participants