Add HMAC as request param, if authentication is enabled
This commit is contained in:
parent
d7ba8b2978
commit
25d5fa9646
|
@ -14,6 +14,8 @@ import java.nio.file.FileSystems;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
|
@ -34,6 +36,7 @@ import com.iheartradio.m3u8.ParseException;
|
|||
import com.iheartradio.m3u8.PlaylistException;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Hmac;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.Recording;
|
||||
import ctbrec.io.HttpClient;
|
||||
|
@ -71,6 +74,13 @@ public class MergedHlsDownload extends AbstractHlsDownload {
|
|||
mergeThread = createMergeThread(targetFile, progressListener, false);
|
||||
LOG.debug("Merge thread started");
|
||||
mergeThread.start();
|
||||
if(Config.getInstance().getSettings().requireAuthentication) {
|
||||
URL u = new URL(segmentPlaylistUri);
|
||||
String path = u.getPath();
|
||||
byte[] key = Config.getInstance().getSettings().key;
|
||||
String hmac = Hmac.calculate(path, key);
|
||||
segmentPlaylistUri = segmentPlaylistUri + "?hmac=" + hmac;
|
||||
}
|
||||
LOG.debug("Downloading segments");
|
||||
downloadSegments(segmentPlaylistUri, false);
|
||||
LOG.debug("Waiting for merge thread to finish");
|
||||
|
@ -82,6 +92,8 @@ public class MergedHlsDownload extends AbstractHlsDownload {
|
|||
throw new IOException("Couldn't parse HLS playlist", e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("Couldn't wait for write thread to finish. Recording might be cut off", e);
|
||||
} catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e) {
|
||||
throw new IOException("Couldn't add HMAC to playlist url", e);
|
||||
} finally {
|
||||
alive = false;
|
||||
streamer.stop();
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package ctbrec.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Hmac;
|
||||
import ctbrec.OS;
|
||||
import ctbrec.Recording;
|
||||
import ctbrec.io.DevNull;
|
||||
|
@ -81,6 +83,14 @@ public class Player {
|
|||
}
|
||||
playerProcess = rt.exec(Config.getInstance().getSettings().mediaPlayer + " " + file, OS.getEnvironment(), dir);
|
||||
} else {
|
||||
if(Config.getInstance().getSettings().requireAuthentication) {
|
||||
URL u = new URL(url);
|
||||
String path = u.getPath();
|
||||
byte[] key = Config.getInstance().getSettings().key;
|
||||
String hmac = Hmac.calculate(path, key);
|
||||
url = url + "?hmac=" + hmac;
|
||||
}
|
||||
LOG.debug("Playing {}", url);
|
||||
playerProcess = rt.exec(Config.getInstance().getSettings().mediaPlayer + " " + url);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue