obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

obs-ffmpeg: Direct setting of encryption & auth for SRT & RIST

Open pkviet opened this issue 2 years ago • 1 comments

Description

This allows the direct use of:

  • encryption passphrase (SRT & RIST),
  • username + password (RIST),
  • as well as streamid (SRT). Previously, these parameters had to be set in the URL in the form: URL?option1=value1&option2=value2.

They can now be set directly in the Settings/Stream menu. The encryption passphrase for SRT & RIST can be set in the stream key field of custom rtmp service. The username field of custom rtmp service is used as the SRT streamid. Indeed, per libsrt guidelines [1], the streamid is used to identify a publisher; so we do likewise. For RIST, the srp_username & srp_password are provided by the username & password fields [2]. Additionally, some error logging has been added when there's a disconnect caused by a wrong password. Also this solves a bug when auto-reconnect is set and a wrong passphrase is provided for srt; the output would keep trying to reconnect. With this commit, an OBS_OUTPUT_INVALID_STREAM signal is emitted and the stream is immediately stopped.

[1] https://github.com/Haivision/srt/blob/master/docs/features/access-control.md [2] https://code.videolan.org/rist/librist/-/wikis/Authentication-and-the-ristsrppasswd-Utility

Motivation and Context

Allow better support for srt services. Currently, srt can be used in services but streamid & passphrase can't be set by the service because the info is not pulled by the output. So I've modified the ffmpeg-mpegts-output to be able to use those settings. This stemmed from a request on dev channel on discord from a service inquiring about srt support.

How Has This Been Tested?

  • encryption passphrase tested against wowza server (SRT) + ffplay (SRT, RIST).
  • tested that services.json work with an srt service and can use passphrase.

Types of changes

  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • [x] My code has been run through clang-format.
  • [x] I have read the contributing document.
  • [x] My code is not on the master branch.
  • [x] The code has been tested.
  • [x] All commit messages are properly formatted and commits squashed where appropriate.
  • [x] I have included updates to all appropriate documentation.

pkviet avatar Aug 19 '22 12:08 pkviet

Bug fixed for the current srt output:

when auto-reconnect is set and a wrong passphrase is provided for srt, the output would keep trying to reconnect. With this commit, an OBS_OUTPUT_INVALID_STREAM signal is emitted and the stream is immediately stopped.

pkviet avatar Aug 31 '22 14:08 pkviet

Wouldn't it make more sense to use the streaming key field for the SRT streamid parameter, and the password field for the encryption passphrase?

niklaskorz avatar Oct 30 '22 08:10 niklaskorz

Wouldn't it make more sense to use the streaming key field for the SRT streamid parameter, and the password field for the encryption passphrase? I did consider the alternative.

  1. Why I picked the current option is answered in the PR description. Per libsrt, the streamid identifies the publisher.
  2. You're also just thinking of SRT and not RIST. Both have passwords but in the case of RIST there's an associated user-id. So RIST makes more sense to use the id/password fields for the srp_user/srp_password pair. Since SRT has a similar passphrase param in addition to stream-id, it wouldn't have made sense to use a different field.

pkviet avatar Oct 30 '22 09:10 pkviet

The problem I see with using the streaming key as encryption phrase instead of stream id is that the predefined "rtmp services" can only make use of the stream id field and are not able to provide a username. Predefined services that want to make use of SRT would thus be unable to identify the stream.

niklaskorz avatar Oct 30 '22 10:10 niklaskorz

The problem I see with using the streaming key as encryption phrase instead of stream id is that the predefined "rtmp services" can only make use of the stream id field and are not able to provide a username. Predefined services that want to make use of SRT would thus be unable to identify the stream.

~~The streamkey is NOT used at all in this PR. You misunderstand.~~ edit: fuck i forgot what i coded, my bad

pkviet avatar Oct 30 '22 10:10 pkviet

It is not used?

The encryption passphrase for SRT & RIST can be set in the stream key field of custom rtmp service.

		context->passphrase = NULL;
		if (stream->ff_data.config.key != NULL) {
			if (strlen(stream->ff_data.config.key))
				context->passphrase =
					av_strdup(stream->ff_data.config.key);
		}

niklaskorz avatar Oct 30 '22 10:10 niklaskorz

It is not used?

The encryption passphrase for SRT & RIST can be set in the stream key field of custom rtmp service.

		context->passphrase = NULL;
		if (stream->ff_data.config.key != NULL) {
			if (strlen(stream->ff_data.config.key))
				context->passphrase =
					av_strdup(stream->ff_data.config.key);
		}

damnit, sorry. I've forgotten how i coded that. So :

  • RIST has: encryption passphrase, srp_user, srp_password
  • SRT has: encryption passphrase, stream_id

I get your concern. I would have to either (1) modify the services to support username/password setting; that's do-able, (2) or follow your suggestion, which is not ideal because srt and rist have the passphrase dealt differently then. I'll think about it a bit before picking up an option.

pkviet avatar Oct 30 '22 10:10 pkviet

Update

  • SRT stream_id is now set as the stream key.
  • SRT encryption passphrase is set in the password auth field. This will facilitate integration by services. Tooltips have been added to help users as to what needs to be entered where, depending on the protocol. It would have been better to change the labels from Stream key to Stream key / SRT stream_id / RIST passphrase. But R1ch felt the labels were turning too long. Ideally, there should be a separate MPEGTS service for srt/rist where these fields are explicitly displayed. This will wait for the service/output/protocol overhaul planned in later obs versions.

pkviet avatar Oct 30 '22 13:10 pkviet

For the tooltip, it was suggested to use the question mark pattern here:

GeorgesStavracas avatar Oct 31 '22 21:10 GeorgesStavracas

For the tooltip, it was suggested to use the question mark pattern here:

how ? your screen cap leverages the Properties API

pkviet avatar Oct 31 '22 21:10 pkviet

Note: you will also need to bump the version in the services json files itself and ensure the validator script still works.

derrod avatar Oct 31 '22 22:10 derrod

Note: you will also need to bump the version in the services json files itself and ensure the validator script still works.

ah thx, didn't think of that. Will do

pkviet avatar Oct 31 '22 22:10 pkviet

For the tooltip, it was suggested to use the question mark pattern here:

@GeorgesStavracas i implemented your suggestion; it was less a hassle than I expected, I just had to copy a few lines. The screenshots have been updated.

pkviet avatar Oct 31 '22 23:10 pkviet

This one should be updated too: https://github.com/obsproject/obs-studio/blob/master/plugins/rtmp-services/rtmp-format-ver.h

tytan652 avatar Nov 01 '22 05:11 tytan652

This one should be updated too: https://github.com/obsproject/obs-studio/blob/master/plugins/rtmp-services/rtmp-format-ver.h

done thx

pkviet avatar Nov 01 '22 12:11 pkviet

Update Removed one extra \n in the stream key tooltip. For the UI/UX part, got the approval of Warchamp.

pkviet avatar Nov 02 '22 20:11 pkviet

My only nitpick here would be the tooltip texts "type the username, "type the password" etc. No one is typing those, they are probably pasting. "Enter the username" or "Provide the username" or just "Username" etc. might be better.

notr1ch avatar Nov 11 '22 21:11 notr1ch

My only nitpick here would be the tooltip texts "type the username, "type the password" etc. No one is typing those, they are probably pasting. "Enter the username" or "Provide the username" or just "Username" etc. might be better.

done

pkviet avatar Nov 11 '22 21:11 pkviet