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

Implementing TLS/SSL streaming and configuration. #1083

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public abstract class BroadcastConfiguration
protected LongProperty mMaximumRecordingAge = new SimpleLongProperty(10 * 60 * 1000); //10 minutes default
protected BooleanProperty mEnabled = new SimpleBooleanProperty(false);
protected BooleanProperty mValid = new SimpleBooleanProperty();
protected BooleanProperty mTlsEnabled = new SimpleBooleanProperty();
private int mId = ++UNIQUE_ID;

public BroadcastConfiguration()
Expand Down Expand Up @@ -162,6 +163,14 @@ public BooleanProperty validProperty()
return mValid;
}

/**
* Configuration TLS property
*/
public BooleanProperty tlsProperty()
{
return mTlsEnabled;
}

/**
* Broadcast server type
*/
Expand Down Expand Up @@ -354,6 +363,20 @@ public void setEnabled(boolean enabled)
mEnabled.set(enabled);
}

/**
* Indicates if this broadcaster is using TLS in its protocol.
*/
@JacksonXmlProperty(isAttribute = true, localName = "tlsEnabled")
public boolean isTlsEnabled()
{
return mTlsEnabled.get();
}

public void setTLSEnabled(boolean tlsEnabled)
{
mTlsEnabled.set(tlsEnabled);
}

@Override
public boolean equals(Object o)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public BooleanProperty enabledProperty()
return mBroadcastConfiguration.enabledProperty();
}

/**
* Enabled state of the tls configuration
*/
public BooleanProperty tlsProperty()
{
return mBroadcastConfiguration.tlsProperty();
}


/**
* Name of the broadcast configuration
*/
Expand Down Expand Up @@ -147,7 +156,7 @@ public boolean hasAudioBroadcaster()
*/
public static Callback<ConfiguredBroadcast, Observable[]> extractor()
{
return (ConfiguredBroadcast b) -> new Observable[] {b.nameProperty(), b.enabledProperty(),
return (ConfiguredBroadcast b) -> new Observable[] {b.nameProperty(), b.enabledProperty(), b.tlsProperty(),
b.broadcastStateProperty(), b.getBroadcastConfiguration().validProperty()};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package io.github.dsheirer.audio.broadcast.icecast;

import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.alias.AliasList;
Expand All @@ -37,7 +38,6 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
Expand All @@ -48,7 +48,6 @@
public class IcecastBroadcastMetadataUpdater implements IBroadcastMetadataUpdater
{
private final static Logger mLog = LoggerFactory.getLogger(IcecastBroadcastMetadataUpdater.class);
private final static String UTF8 = "UTF-8";
private HttpClient mHttpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
private IcecastConfiguration mIcecastConfiguration;
private AliasModel mAliasModel;
Expand Down Expand Up @@ -77,87 +76,69 @@ public IcecastBroadcastMetadataUpdater(IcecastConfiguration icecastConfiguration
public void update(IdentifierCollection identifierCollection)
{
StringBuilder sb = new StringBuilder();
sb.append("http://");
sb.append(mIcecastConfiguration.getHost());
sb.append(":");
sb.append(mIcecastConfiguration.getPort());
sb.append("/admin/metadata?mode=updinfo&mount=");
sb.append(URLEncoder.encode(mIcecastConfiguration.getMountPoint(), Charsets.UTF_8));
sb.append("&charset=UTF%2d8");
sb.append("&song=").append(URLEncoder.encode(getSong(identifierCollection), Charsets.UTF_8));

final String metadataUpdateURL = sb.toString();
URI uri = URI.create(metadataUpdateURL);

ThreadPool.SCHEDULED.submit(() -> {
try
{
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.header(IcecastHeader.AUTHORIZATION.getValue(), mIcecastConfiguration.getBase64EncodedCredentials())
.header(IcecastHeader.USER_AGENT.getValue(), SystemProperties.getInstance().getApplicationName())
.GET()
.build();

try
{
sb.append("http://");
sb.append(mIcecastConfiguration.getHost());
sb.append(":");
sb.append(mIcecastConfiguration.getPort());
sb.append("/admin/metadata?mode=updinfo&mount=");
sb.append(URLEncoder.encode(mIcecastConfiguration.getMountPoint(), UTF8));
sb.append("&charset=UTF%2d8");
sb.append("&song=").append(URLEncoder.encode(getSong(identifierCollection), UTF8));
}
catch(UnsupportedEncodingException uee)
{
mLog.error("Error encoding metadata information to UTF-8", uee);
sb = null;
}

if(sb != null)
{
final String metadataUpdateURL = sb.toString();
URI uri = URI.create(metadataUpdateURL);
HttpResponse<String> response = null;

ThreadPool.SCHEDULED.submit(new Runnable()
{
@Override
public void run()
try
{
try
response = mHttpClient.send(request, HttpResponse.BodyHandlers.ofString());
}
catch(IOException ioe)
{
if(!mConnectionLoggingSuppressed)
{
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.header(IcecastHeader.AUTHORIZATION.getValue(), mIcecastConfiguration.getBase64EncodedCredentials())
.header(IcecastHeader.USER_AGENT.getValue(), SystemProperties.getInstance().getApplicationName())
.GET()
.build();

HttpResponse<String> response = null;

try
{
response = mHttpClient.send(request, HttpResponse.BodyHandlers.ofString());
}
catch(IOException ioe)
{
if(!mConnectionLoggingSuppressed)
{
mLog.error("IO Error submitting Icecast metadata update [" +
(metadataUpdateURL != null ? metadataUpdateURL : "no url"), ioe);
mConnectionLoggingSuppressed = true;
}
}
catch(InterruptedException ie)
{
mLog.error("Interrupted Exception Error", ie);
}
mLog.error("IO Error submitting Icecast metadata update [{}] ", metadataUpdateURL, ioe);
mConnectionLoggingSuppressed = true;
}
}
catch(InterruptedException ie)
{
mLog.error("Interrupted Exception Error", ie);
}

if(response != null)
{
if(response.statusCode() == 200)
{
mConnectionLoggingSuppressed = false;
}
else
{
if(!mConnectionLoggingSuppressed)
{
mLog.info("Error submitting Icecast 2 Metadata update to URL [" + metadataUpdateURL +
"] HTTP Response Code [" + response.statusCode() + "] Body [" + response.body() + "]");
mConnectionLoggingSuppressed = true;
}
}
}
if(response != null)
{
if(response.statusCode() == 200)
{
mConnectionLoggingSuppressed = false;
}
catch(Throwable t)
else
{
mLog.error("There was an error submitting an Icecast metadata update", t);
if(!mConnectionLoggingSuppressed)
{
mLog.info("Error submitting Icecast 2 Metadata update to URL [" + metadataUpdateURL +
"] HTTP Response Code [" + response.statusCode() + "] Body [" + response.body() + "]");
mConnectionLoggingSuppressed = true;
}
}
}
});
}
}
catch(Throwable t)
{
mLog.error("There was an error submitting an Icecast metadata update", t);
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public abstract class IcecastConfiguration extends BroadcastConfiguration
private int mChannels = 1;
private int mSampleRate = 8000;
private String mURL;
private boolean mIsTlsStatus;

public IcecastConfiguration(BroadcastFormat format)
{
Expand Down Expand Up @@ -260,6 +261,16 @@ public String getURL()
return mURL;
}

@JacksonXmlProperty(isAttribute = true, localName = "tls_enabled")
public boolean isTlsEnabled()
{
return mIsTlsStatus;
}

public void setTlsStatus(boolean tlsStatus){
this.mIsTlsStatus = tlsStatus;
}

/**
* URL associated with the broadcastAudio where users can find additional details.
*
Expand Down
Loading