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

SSL certificate problem: self-signed certificate #57

Open
p-w-rs opened this issue Aug 20, 2023 · 2 comments
Open

SSL certificate problem: self-signed certificate #57

p-w-rs opened this issue Aug 20, 2023 · 2 comments

Comments

@p-w-rs
Copy link

p-w-rs commented Aug 20, 2023

I am trying to send an email with my ProtonMail account, I have bridge installed which runs an smtp server on my local machine at 127.0.0.1:1025 and uses SSL for security, the bridge then relays my email to ProtonMail servers which don't support smtp directly for security reasons, thus they created the bridge.

When I do this I get his error when running send:

* processing: smtps://127.0.0.1:1025
*   Trying 127.0.0.1:1025...
* Connected to 127.0.0.1 (127.0.0.1) port 1025
*  CAfile: /opt/homebrew/Cellar/julia/1.9.2/share/julia/cert.pem
*  CApath: none
* SSL certificate problem: self-signed certificate
* Closing connection
┌ Error: ERROR:
│   exception =
│    curl_easy_perform() failed: SSL peer certificate or SSH remote key was not OK
│    Stacktrace:
...

So I need to figure out how to solve this certificate issue?

Here is my code:

url = "smtps://127.0.0.1:1025"
opt = SendOptions(
  isSSL=true,
  username=ENV["BRIDGE_UNAME"],
  passwd=ENV["BRIDGE_PASS"],
  verbose=true
)

function send_email2(name, sender, receiver, subject, message, attachments)
    global url, opt

    to = ["<$receiver>"]
    from = "$name <$sender>"
    replyto = sender
    body = get_body(to, from, subject, message; replyto, attachments)
    
    resp = send(url, to, from, body, opt)
end
@p-w-rs
Copy link
Author

p-w-rs commented Aug 20, 2023

I have a solution just add cacert to the SendOptions struct

mutable struct SendOptions
  isSSL::Bool
  username::String
  passwd::String
  cacert::String
  verbose::Bool
end

and then use a default value of LibCURL.cacert

function SendOptions(; isSSL::Bool = false, username::AbstractString = "",
                     passwd::AbstractString = "", cacert = LibCURL.cacert, verbose::Bool = false, kwargs...)
...

And then we can do this:

if options.isSSL
    @ce_curl curl_easy_setopt curl CURLOPT_USE_SSL CURLUSESSL_ALL
    @ce_curl curl_easy_setopt curl CURLOPT_CAINFO options.cacert
  end

@aviks
Copy link
Owner

aviks commented Aug 21, 2023

Yeah, that sounds like a decent design. Would you make a PR? I'd probably add cacert as the last parameter in the list, after verbose.

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

No branches or pull requests

2 participants