Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 5 of 5
  1. #1
    Senior Member
    Join Date
    Mar 2011
    Posts
    174

    LWP::UserAgent fails on Windows to connect to https

    The SoundCloud plugin has a problem for Windows users. It tries to make a connection to an https server using LWP::UserAgent. This fails with the strange error message "500 Can't connect to api.soundcloud.com:443 ()"

    Here is a simplified version of the code:
    Code:
    use LWP::Simple;
    use LWP::UserAgent;
    use Data::Dumper;
    my $ua = LWP::UserAgent->new(
      requests_redirectable => [],
    );
    my $res = $ua->get('https://api.soundcloud.com');
    $log->debug(Dumper($res));
    This actually fails for all https servers, so it's not specific on the SoundCloud server.

    I tracked it down (I think, at least), by turning on SSL debug logging. This gives the follow log:
    Code:
    [21-09-12 14:36:51.4017] IO::Socket::SSL::DEBUG (342) Warning: DEBUG: ...>IO/Socket/SSL.pm:736: call Net::SSLeay::connect
    [21-09-12 14:36:51.4028] IO::Socket::SSL::DEBUG (342) Warning: DEBUG: ...>IO/Socket/SSL.pm:739: done Net::SSLeay::connect -> 1
    [21-09-12 14:36:51.4035] IO::Socket::SSL::DEBUG (342) Warning: DEBUG: ...>IO/Socket/SSL.pm:794: ssl handshake done
    [21-09-12 14:36:56.0613] Plugins::SqueezeCloud::ProtocolHandler::gotNextTrack (124) https://api.soundcloud.com/tracks/1123051864/stream
    [21-09-12 14:36:56.0846] IO::Socket::SSL::DEBUG (342) Warning: DEBUG: ...>IO/Socket/SSL.pm:2350: Invalid default certificate authority locations
    SSL error:  10344: 1 - error:2006D002:BIO routines:BIO_new_file:system lib
    SSL error:  10344: 2 - error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib
     
    [21-09-12 14:36:56.0855] IO::Socket::SSL::DEBUG (342) Warning: DEBUG: ...>IO/Socket/SSL.pm:2350: global error: Invalid default certificate authority locations error:0200107B:system library:fopen:Unknown error
    [21-09-12 14:36:56.0869] Plugins::SqueezeCloud::ProtocolHandler::gotNextTrack (142) $VAR1 = {
              'SSL_ca_file' => '\\Mozilla\\CA\\cacert.pem'
            };
    [21-09-12 14:36:56.0877] Plugins::SqueezeCloud::ProtocolHandler::gotNextTrack (143) Error: Failed to get redirect location from https://api.soundcloud.com/tracks/1123051864/stream
    [21-09-12 14:36:56.0883] Plugins::SqueezeCloud::ProtocolHandler::gotNextTrack (144) 500 Can't connect to api.soundcloud.com:443 ()
    [21-09-12 14:36:56.0909] IO::Socket::SSL::DEBUG (342) Warning: DEBUG: ...>IO/Socket/SSL.pm:2733: free ctx 198423064 open=198425016 198423064 198424040 198424528 198425504 104326296 104327272 104326784 104327760
    [21-09-12 14:36:56.0918] IO::Socket::SSL::DEBUG (342) Warning: DEBUG: ...>IO/Socket/SSL.pm:2745: OK free ctx 198423064
    The error "Invalid default certificate authority locations" is what I think is wrong. It occurs on Windows 10, but not on my Linux (Debian) or MacOS machines. Setting some options for SSL_VERIFY_NONE etc doesn't seem to make a difference.

    BTW, the reason I'm using LWP::UserAgent and not Slim::Networking::SimpleAsyncHTTP is that I need to get the 'Location' header of a 302 redirect. SimpleAsyncHTTP always follows redirects and doesn't seem to have an option to display redirects and get the data for the 302 redirect itself.
    Last edited by 505; 2021-09-12 at 06:19.

  2. #2
    Senior Member
    Join Date
    Mar 2011
    Posts
    174
    Nevermind, found the solution myself. SSL verify options don't need to be set on the useragent object, but by using
    Code:
    use IO::Socket::SSL;
    IO::Socket::SSL::set_defaults(
    		SSL_verify_mode => Net::SSLeay::VERIFY_NONE() 
    			) if preferences('server')->get('insecureHTTPS');

  3. #3
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,666

    LWP::UserAgent fails on Windows to connect to https

    > BTW, the reason I'm using LWP::UserAgent and not
    > Slim::Networking::SimpleAsyncHTTP is that I need to get the 'Location'
    > header of a 302 redirect. SimpleAsyncHTTP always follows redirects and
    > doesn't seem to have an option to display redirects and get the data for
    > the 302 redirect itself.


    Ugh... the code indeed does a "$maxRedirect || 7". Which means that as
    Perl considers 0 a falsy value, it would be set to 7 instead. Would
    using -1 work?

  4. #4
    Senior Member
    Join Date
    Aug 2014
    Location
    UK
    Posts
    603
    Quote Originally Posted by 505 View Post

    BTW, the reason I'm using LWP::UserAgent and not Slim::Networking::SimpleAsyncHTTP is that I need to get the 'Location' header of a 302 redirect. SimpleAsyncHTTP always follows redirects and doesn't seem to have an option to display redirects and get the data for the 302 redirect itself.
    When I need the redirect data I use Slim::Networking::Async::HTTP . if you use sendRequest on that session you can pass in an "onRedirect" callback. Here is an example of where I use it in BBC Sounds : https://github.com/expectingtofly/LM...agement.pm#L95
    Stuart McLean

    ExpectingToFly Plugins :
    BBC Sounds, Global Player (UK), Times Radio, UK Radio Player, Virgin Radio (UK) and the Radio Favourites Plugin

    For BBC Sounds help see the BBC Sounds Wiki.

  5. #5
    Senior Member
    Join Date
    Mar 2011
    Posts
    174
    Quote Originally Posted by mherger View Post
    >
    Ugh... the code indeed does a "$maxRedirect || 7". Which means that as
    Perl considers 0 a falsy value, it would be set to 7 instead. Would
    using -1 work?
    No, I tried it with 0 and -1, and both don't work. Also, when the redirect limit is hit, it thrown an error (goes to the error callback) instead of the success callback, which isn't that nice for the flow.

    Quote Originally Posted by expectingtofly View Post
    When I need the redirect data I use Slim::Networking::Async::HTTP . if you use sendRequest on that session you can pass in an "onRedirect" callback. Here is an example of where I use it in BBC Sounds : https://github.com/expectingtofly/LM...agement.pm#L95
    Thanks, I'll take a look it this!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •