Saturday, January 26, 2019

https with ngrok

While ngrok can be used to expose your local development application to the internet for testing,
the free version of ngrok does not support End-to-End TLS Tunnels aka https, but it does support forwarding of https to http

Note: Transport Layer Security (TLS) is the successor to SSL. TLS 1.0 was defined in RFC 2246 in January 1999.  Hypertext Transfer Protocol Secure (HTTPS), or “HTTP Secure,” is an application-specific implementation that is a combination of the Hypertext Transfer Protocol (HTTP) with the SSL/TLS.
reference: is-it-ssl-tls-or-https

For Single Sing On solutions, such as SAML, you application is required to be hosted over https

You might think you could just bind to the ssl port 443

> ngrok http myawesomeapp.local:443

Session Status                online
Session Expires               7 hours, 4 minutes
Version                       2.2.8
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://8316dcb8.ngrok.io -> myawesomeapp.local:443
Forwarding                    https://8316dcb8.ngrok.io -> myawesomeapp.local:443  

But, accessing https://8316dcb8.ngrok.io or http://8316dcb8.ngrok.io results in the browser showing

Bad Request
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.

So that is why you need the paid version of ngrok for End-to-End TLS Tunnels.

One solution is to pay for the Pro version of ngrok, which also gets you access to more features such as Whitelabel domains, Reserved TCP addresses, End-to-End TLS Tunnels, and more resources.

However, if your using PHP Symfony or the PHP OneLogin SAML library,
another solution is to modify your application to indicate that the request is actually https.

Start up ngrok

> ngrok http myawesomeapp.local:80

Session Status                online
Session Expires               7 hours, 4 minutes
Version                       2.2.8
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://8316dcb8.ngrok.io -> myawesomeapp.local:80
Forwarding                    https://8316dcb8.ngrok.io -> myawesomeapp.local:80  

If you view https://8316dcb8.ngrok.io, you will see your app, but you app will think its running on port 80 and http

Note: While this is PHP focused, the concept should apply to other applications.

To make your app think it's on https, in the bootstrap or initialization of your application, add:

// If the host url has ngrok.io, and the header X-Forwarded-Proto set by ngrok is https, then also set https on and the port to 443
if (strpos($_SERVER['HTTP_HOST'], 'ngrok.io') !== false && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
{
  $_SERVER['HTTPS'] = 'on';
  $_SERVER['SERVER_PORT'] = 443;
}

Note: For Symfony, you can place this code within the boostrap app_dev.php, above the creation of $request

> vi app_dev.php

// place here

$request = Request::createFromGlobals();
$response = $kernel->handle($request);


This will allow any following code which checks for https
such as OneLogins Utils::isHTTPS()
or Symfony Request->isSecure()
to return true when accessing the ngrok url over https

Note: This does not test or affect your applications ssl certs, as the browser thinks the request is from 8316dcb8.ngrok.io,  And if you are using ngrok daily for development or testing, it is fairly inexpensive to upgrade to the tls version which is a  simpler and better solution

Hopefully this helps you test Single Sing On solutions, such as SAML.

-End of Document-
Thanks for reading

Saturday, January 5, 2019

streamWriter - play and record internet radio stations

streamWriter is a free application for windows that plays and records music broadcasted by internet radio stations.  The internet radio stations listed in streamWriter may stream songs you know, definitely songs you don’t know, or interesting re-mixes of your favorites.  The internet radio stations are free in the sense that FM/AM is free.

Note some radio stations may contain commercials, or be in other languages than your own.

streamWriter features

  • Record as many streams as you want at the same time (MP3/AAC)
  • Automatically record a wishlist's song when it's playing on a stream
  • Player for streams and recorded files
  • Track splitting with silence detection
  • Function for manual cutting of saved titles
  • Tracks are named by a given pattern
  • Short songs (ads) can be skipped
  • Writing of tags to recorded files
  • Script-based postprocessing
  • Applying of effects to recorded songs (SoX)
  • Integration of different audio encoders
  • Scheduled recordings
  • Stream browser
  • Multilingual
  • Can be installed or used in portable mode
  • ...and much more!

streamWriter Website Help Donate


This post will cover the installation, recommended settings, and general usage of streamWriter.

Installation

1) Downloading and installing the executable or portable version
Run streamWriter
You will be greeted with some info and a settings wizard.  
You can change all settings later.

2) About, License, Thank you dialog

It’s unusual but kinda nice that you see the about dialog first.
Click Close

3) Choose your language

Click Next




4) Save settings location

Choose either option.  
The second option to Save data to application path is recommended to make the app portable.
Click Next

5) Choose to search for updates

Leave enabled is fine.
You will have to download and install new versions, which is safer than auto upgrades.
Click Next

6) Select recording folder

Choose the folder (directory) where you want streamed recordings to be saved.  
The default under Music is fine.
Click Next

7) Some miscellaneous settings

The defaults are fine.
Click Finish

8) Introduction

Some nice info, but you will probably forget all the words,
so continue on for more screenshots and info
Click Close

9) You now see the full app

Choose a radio stream

1) Filter your desired music by
  • Genre - Categorizes the type of music i.e. Country, Rock, etc.  
  • There are lots of Genres, and many overlap.
It’s more of a guideline than a rule.  
So some trial and error will be required to find what you like.

  • Kbps - Determines the quality of the songs being streamed. The higher the better quality, and bigger file size. Note, some music players may not play mp3s with high Kbps (also known as Bitrate).

Choose >= 192 should be a good mix of quality, size, and compatibility

    • Type - The file format of the radio stream.

    Choose MP3 for greater compatibility.

    2) Choose a radio stream

    Double click on a radio stream, listed on the bottom right side.  
    The radio stream will start.  
    By default, you will not hear anything as the radio stream will only record.

    3) Listen to the radio stream
    Click the Play button to listen while recording.

    Recommended Settings

    1) Go to settings...
    Click File -> Settings..

    2) General Settings
    Enable
    • Remember streams that were recording on exit
    • Remember stream that was playing on exit
    So when you restart the app, it continues playing the same radio stream.

    3) Recordings
    Enable
    • Only save whole songs
    • Remove saved titles from wishlist (you can add songs to wishlists, ignore lists)
    • Overwrite existing file if newer file is larger
    • Discard new file if existing one is larger
    The last two options should increase the odds of recording a better quality song

    4) Filenames
    You can change the location where songs are recorded too ie saved too
    For greater organization, change the Patterns for filenames of recorded tracks to include the artist as a folder

    • Original:
      • %streamname%\%artist% - %title%
    • Recommend folders by artist:
      • %streamname%\%artist%\%artist% - %title%
    The defaults on Filenames Advanced and Cut songs are fine.

    Note some radio streams do have commercials, of course.  
    The defaults on Filenames Advanced and Cut songs seem to be ok, but you can always try changing them if needed.

    5) Addons
    Click and download the addons for
    • Support encoding of MP3 using LAME (an encoder)
    • Support reading/writing of tags using AudioGenie (a tag writer)
    Writing tags to your MP3s allows audio players to display more information about the song, such as Artist, Title, Album, if known.

    6) Postprocessing

    Post processing is what happens to the song recording after being saved to a file.
    • Select MP3 as the format to convert recorded files to,
    Which ensures you are only dealing with MP3s, for greater compatibility with audio players.
    • Enabled Write tags to recorded songs.
    Writing tags to your MP3s allows audio players to display more information about the song, such as Artist, Title, Album, if known.

    Note that these settings will only apply to new radio streams.  So you will want to remove any of your current radio streams and re-add them.  Or choose and set the same settings by right clicking on the radio stream and selecting Settings..
    The defaults on the rest of the Settings: Bandwidth, Community, Hotkeys, Advanced, and General are fine.

    Manage radio stream

    1) While a radio stream is in the play list, and selected, you can use the toolbar button, or right click and apply some options.

    If there is a song currently playing which you really do not like,  
    • Choose Add title to global ignorelist and you will not hear it again.

    Each stream can have it’s own recording settings, under Settings..

    2) Saved songs
    Provides a basic music player.
    You may find the music player foobar or the video/audio player videolan useful, but the default windows player is fine too.

    3) Title search
    Searching for a know title can help you find a radio stream you may like.
    You can also right click and add the title or artist to your wish list.

    4) Play or Record or Both or Neither



    Well, that’s it.
    Hopefully you a good start on listening and recording internet radio streams.

    streamWriter  Website Help Donate


    -End of Document-
    Thanks for reading