Testing of Key Security Modules with pre-generated SPC

Hi All,


We are working on integrating FairplayStreaming KSM with our key management server.

We followed the programing guide and finished the steps, but are having issues when testing each function with the provided binaries. (we haven't got the deploy package yet.)

We are blocked at the step of decrypting SPC payload from the pre-generated spc.

The previous step to decrypt spc key using the development private key was successful.

But the decrypted key hex value is not matching to what is showing if we use the verify_ckc utility tool to parse the same spc file.

On the other side, there is a file in the package "spc_internal_values_v2.txt". It shows the same SPCK value as what we decrypted.

So which one is correct and what is the proper way to use the pre-gen spc blocks?

And which SPCK should be used to AES128-CBC decrypt the payload from those spc files?

Did we miss something or the provided spc files were just not meant to be parsed? If it's not meant to be parsed, do we have to hard code every pieces of information into our code to test the CKC generation?

It seems a lot of people here have completed the integration. How did you get pass with this?

Suggestions or hints on this would be really appreciated.


Thank you.

Best,


Lu

Replies

Here are the spck values comparison.

But even two of our values match to what was shown from spc_internal_values_v2.txt, the spc payload was not able to be decrypted with either of the values...


From verify_ckcFrom spc_internal_values_v2.txtFrom our implementation
spc1926648b9861ec0471ba21758851c3ddaDD7139EAFACEED7CDA9F25DA8AA915EAdd7139eafaceed7cda9f25da8aa915ea
spc21f603470489dde55fbd21790662905f9DD7139EAFACEED7CDA9F25DA8AA915EA3333c8c3bc52aa2eb0d94e0faa356b1b
spc3602352c2e6eefc0a1486870f48e7a4e6DD7139EAFACEED7CDA9F25DA8AA915EAdd7139eafaceed7cda9f25da8aa915ea


The spc.bin files are the ones under Development/Key Server Module/Testing/CKC Verification Tool/SPC CKC Tests/FPS/.

Could someone help to provide some information about how you managed to test with those spc.bin and ckc.bin files?


Thanks.

Best,


Lu

Hi,


The "SPC Encryption Key" shown when using verify_ckc on spc1.bin is just the raw value when parsing the bytes of the file from byte 24 to 24+16. While the SPCK in the file spc_internal_values_v2.txt is the actual SPCK, that is after the "SPC Encryption Key" is decrypted with the private key. The SPCK then is what you will use to decrypt the SPC Payload.



Regards,

Post not yet marked as solved Up vote reply of yep Down vote reply of yep

Hi yep,


Thank you much for your response.

It seems two out of three of the spcks we decrypted were matching to the values that were shown in spc_internal_v2.txt.

However, when we tried to use those values to decrypt SPC payload, which we subtracted all the bytes after position 176 according to the Programming guide, the keys were not able to decrypt those bytes.

Were you able to complete the testing with your implementation with these vector blocks?

I wonder if we oversighted something at this part since it should have been a straight forward step.

We referenced the provided C code and implemented our steps in PHP because our key system was written in PHP.

Please also bear with my little knowledge of C language.

The payload value being passed into the AES decrypt method in the reference code is:

serverPlaybackCtx + spcContainer->spcDataOffset

Which is a pointer plus integer. Does that mean moving the pointer to spcDataOffset position of serverPlaybackCtx?

I wonder how that can be translated into PHP. Is that different to just extract the byte values after position 176 like what we did?

Any suggestion or hint would be really appreciated.


Best,


Lu

Hi yep,


I actually went back to the documentation and it made me more confused.

I did see the raw value you mentioned in spc1.bin, but in the programming guid doc it clearly states:


SPCK = RSA_OAEP d([SPCK])Prv where
[SPCK] represents the value of SPC message bytes 24-151.

Prv represents the server's private key.


So do you or anyone in the forum happen to know what this actually represents from verify_ckc?

verify_ckc on spc1.bin is just the raw value when parsing the bytes of the file from byte 24 to 24+16


Thanks.


Lu

Hi Lu,


We have also implemented FPS in PHP. There could be many things that could go wrong but in our implementation we did it as simple as this:



//get private key pem (For anything that have something to do with certificate, we used openssl libs)
$privateKey = openssl_pkey_get_private("file:///etc/FairplayKeys/privatekey_clear.pem");
//decode SPC Key, IV and Payload
$spck;
$spcIV = substr($spc, 8, 16);
$spcKey = substr($spc, 24, 128);
$spcPayload = substr($spc, 176);
//decrypt spc key with private key using openssl_private_decrypt (Couldn't make mycrypt_decrypt work on this. The results were always wierd, maybe
//this is where you are also having trouble. So again we used openssl)
$success = openssl_private_decrypt($spcKey, $spck, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);
//decrypt the payload of SPC (Here we use mycrypt_decrypt. Its simplier)
$spcPayloadClear = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $spck, $spcPayload, MCRYPT_MODE_CBC, $spcIV);
//Now all you have to do is extract the TTLVs from $spcPayloadClear


Hope that helps.

Post not yet marked as solved Up vote reply of yep Down vote reply of yep

Hi yep,

Thank you so much yep for the information!

That's actually very the same as my implementation except I used openssl_decrypt instead.

I actually managed to edit and compile the C files provided in the SDK and got it all went through and generated the CKC.

Some questions still remain...

I outputted the spc payload from the compiled C program in hex and compared it to the values that were substr() in PHP like what you did in line 07.

There are actually 16 more bytes from the values generated from the C program. (which passed the decryption)

The extra values in hex are d87ce7a26081de2e8eb8acef3a6dc179.

With that counted in, the actual SPC payload length becomes 2704 but not the number presented in spc 2688.

I am not sure where those bytes came from. I wonder if it's because of the way we read the .bin file.

We just used the simplest way as:

$fp = fopen($path, "rb");

to read the file in.

Could you possibly help to elaborate how you read the file in in your PHP program?

Hi Lu,


I never tried reading the SPC directly from a file, I send it instead to the PHP using POST from curl command which in my opinion is more "realistic". Then I read th POST like normal.


$spc = file_get_contents('php://input');
Post not yet marked as solved Up vote reply of yep Down vote reply of yep

Hi yep,

Thank you much for your info.

It turned out to be the openssl_decrypt method in the newer PHP version was not able to properly AES128 decrypt the payload with the IV in CBC mode.

Not sure if I did anything wrong or it's just the library not working properly. (as it's really a straight forward one line code, I couldn't think of anything wrong...)

After setting up mcrypt and switched to use it I am getting the proper result.

The extra bytes I mentioned earlier I believe was my mistake. It was the ASk and I probably included it in the print output somehow...

That concludes to:

* The outputs from C and PHP should be the same.

* It seems to me either reading from the file directly or HTTP posting it into an API should get the same binary input.

* Whether it's on purpose or not, the outputs from verify_ckc to read a pre-gen spc file and the spc_internal_values_v2.txt are not necessery correct. (At least the spck part.)

Hope this provides some hints for people who have similar issues while implementing.


Really appreicate your input and help with this!!


Best,

Lu