Problem with custom Authentication Token
Jan 17, 2012 7:13 AM
Tags: none (add) #osmf #flash_access #drm #action_script #custom_authHello,
I'm trying to use custom authentication token, but i don't manage to get the OSMF based player to send the token to the server.
I will describe the whole process that we use to achieve this.
the java code to create the policy for custom authentication:
import com.adobe.flashaccess.sdk.policy.LicenseServerInfo;
import com.adobe.flashaccess.sdk.policy.Policy;
import com.adobe.flashaccess.sdk.policy.PolicyException;
import com.adobe.flashaccess.sdk.policy.ServerInfo.AuthenticationType;
import com.adobe.flashaccess.sdk.rights.PlayRight;
import com.adobe.flashaccess.sdk.rights.Right;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class CreatePolicy
{
public static void main(String[] args) {
Policy policy = new Policy(false);
policy.setName("custom_policy");
policy.setLicenseServerInfo(new LicenseServerInfo(AuthenticationType.Custom));
PlayRight play = new PlayRight();
List<Right> rightsList = new ArrayList<Right>();
rightsList.add(play);
policy.setRights(rightsList);
try
{
// Serialize the policy
byte[] policyBytes = policy.getBytes();
System.out.println("Created policy with ID: " + policy.getId());
// Write policy to a file. Alternatively, the policy could be stored in a database.
FileOutputStream out = new FileOutputStream("custom.pol");
out.write(policyBytes);
out.close();
} catch (PolicyException e) {
// The policy could not be created, because required fields were not set.
e.printStackTrace();
} catch (IOException e) {
// Error writing policy to file
e.printStackTrace();
}
}
}
Here is the output of Adobe Policy Manager for this policy:
Adobe(R) Flash Access Policy Manager
version 2.0.2.0061
=======================
Policy Report:
=============
Policy ID: 2B765152-4833-3E5E-8C78-B2488E4C987C
Policy Name: custom_policy
Revision: 1
License Server Authentication: custom
Unlimited License Caching
Right: Play
Then we modify this policy to add some metadata and use it to package a standard mp4 file.
Here is the output of Adobe(R) Flash Access Media Packager for this packaged mp4 file:
Adobe(R) Flash Access Media Packager
version 2.0.2.0061
=======================
Source file: mp4_h264_aac_fa2-1326491966.mp4
License Server: http://lic.dev.int.secret.net
License ID: 9EC8E136-9D2D-3D12-B042-7EC97212C1D3
Content ID: 4e6f6bbddede83536f000000.4f10b739dede83376c000000
Packager: CN=MyCorp-PKG-20111123,OU=Adobe Flash Access,OU=Packager,O=Adobe Systems Incorporated,C=US
Packaging time: Fri Jan 13 23:59:25 CET 2012
Policies:
Policy ID: 2B765152-4833-3E5E-8C78-B2488E4C987C
Policy Name: custom_policy
Revision: 2
License Server Authentication: custom
License Caching Duration: 1440 minutes (1 day)
Right: Application Defined Right
media_id =
4f10b739dede83376c000000
user_id =
4e6f6bbddede83536f000000
Right: Play
CustomProperties:
media_id =
4f10b739dede83376c000000
user_id =
4e6f6bbddede83536f000000
SUCCESS
The file is stored on a standard HTTP server.
Here is the code of the OSMF 1.6 based video player:
package
{
import flash.display.Sprite;
import flash.utils.ByteArray;
import org.osmf.events.MediaPlayerStateChangeEvent;
import org.osmf.media.DefaultMediaFactory;
import org.osmf.media.MediaElement;
import org.osmf.media.MediaPlayerSprite;
import org.osmf.media.MediaPlayerState;
import org.osmf.media.MediaResourceBase;
import org.osmf.media.URLResource;
import org.osmf.metadata.MetadataNamespaces;
import org.osmf.net.StreamingURLResource;
import org.osmf.traits.DRMTrait;
import org.osmf.traits.MediaTraitType;
import org.osmf.events.DRMEvent;
import org.osmf.traits.DRMState;
public class MyPlayer extends Sprite
{
private var protectedMP4:String = "http://secret.net/mp4_h264_aac_fa2-1326491966.mp4";
private var player:MediaPlayerSprite = null;
private var streamingResource:StreamingURLResource = null;
public function MyPlayer()
{
var factory:DefaultMediaFactory = new DefaultMediaFactory();
streamingResource = new StreamingURLResource(protectedMP4);
var mediaElement:MediaElement = factory.createMediaElement(streamingResource);
player = new MediaPlayerSprite();
addChild(player);
player.mediaPlayer.addEventListener(DRMEvent.DRM_STATE_CHANGE, this.onDRMStateChange);
player.mediaPlayer.autoPlay = true;
player.mediaPlayer.media = mediaElement;
}
protected function onDRMStateChange(event : DRMEvent) : void
{
trace('onDRMStateChange ' + event.drmState);
if (event.drmState == DRMState.AUTHENTICATING)
{
//player.mediaPlayer.authenticateWithToken("token");
var drmTrait:DRMTrait = player.mediaPlayer.media.getTrait(MediaTraitType.DRM) as DRMTrait;
drmTrait.authenticateWithToken("token");
}
}
}
}
This code is heavily based on code found in another forum thread about custom token and OSMF
the problem is that we don t really know when to use authenticateWithToken() if we call it on the DRMState.AUTHENTICATING event it will loop and stack overflow because calling authenticateWithToken will trigger the AUTHENTICATING event so it will loop until it will stack overflow.
I also tried to call it in AUTHENCATION_NEEDED (i had to modify to server code to return this event) but then custom Token is never recieved by the server.
For completness here is the part of the server code where i'd like to retrieve the raw authentication token, this code is heavily based on the reference implementation
LicenseHandler licenseHandler = null;
try {
ServletInputStream in = request.getInputStream();
ServletOutputStream out = response.getOutputStream();
HandlerConfiguration context = getHandlerContext();
ServerCredential licenseServerCred = getLicenseParams().getLicenseServerCred();
licenseHandler = new LicenseHandler(context, in, out, licenseServerCred);
licenseHandler.parseRequest();
List<? extends LicenseRequestMessage> requests = licenseHandler.getRequests();
// Multiple request in one message is not supported in FAXS 2.0 client.
for (LicenseRequestMessage licenseReq : requests)
{
try {
if (licenseReq.getRawAuthenticationToken() != null)
{
LOG.info("We have a auth token");
LOG.info(licenseReq.getAuthenticationToken());
}
else
{
LOG.info("No auth token :(");
licenseReq.setErrorData(AdobeErrorData.LACQ_AUTHENTICATION_REQUIRED);
}
V2ContentMetaData metadata = licenseReq.getContentInfo().getContentMetadata();
ApplicationProperties applicationProperties = null;
String usageModelString = null;
if (metadata != null)
{
applicationProperties = metadata.getCustomProperties();
if (applicationProperties != null)
{
//usageModelString = applicationProperties.getSingleValueAsUTF8String(DEMOMODE);
}
}
License license = null;
license = generateLicense(licenseReq);
// If desired, modify the expiration or rights in the license
if (license != null)
{
logLicenseInformation(license);
} else {
// No license and no error set.
LOG.error("Unknown error while generating license");
licenseReq.setErrorData(AdobeErrorData.SERVER_ERROR);
}
licenseReq.getRawAuthenticationToken() always return null, and i checked in the log that this is the good policy that we recieve as the policy id is the same.
What are we doing wrong?
Thanx



