Discussion:
[libdvdcss-devel] try again: patch for negative caching of keys
Marc Espie
2011-08-28 10:23:17 UTC
Permalink
I sent this a few weeks ago. I haven't gotten any useful feedback from it.
(I'm french, if you really have trouble expressing yourself in english).

I really would like to see negative caching in dvdcss.

My goal was to make things as simple as possible: other keys are cached
in separate files. Doing negative caching should involve creating the exact
same files.

Possibly, the configure.ac part should be a separate patch. As it stands,
libdvdcss does not contain a proper configure script, since AC_INIT is
stumped.

I believe storing the PACKAGE_VERSION is the simplest thing to do, in case
someone figures out a bug that means key cracking was actually incorrect
later.

I'm willing to spend a bit more time working on that patch, but GIVE ME
CONCRETE DIRECTIONS, not some fuzzy things like "I would do that differently"
(with about NO INDICATION of what should be done differently) or "this
should be separate patches" (I'll make a wild guess at: configure.ac separated
from the css code proper).

--- configure.ac.orig Fri Aug 29 20:59:00 2008
+++ configure.ac Wed Aug 17 11:51:22 2011
@@ -1,4 +1,4 @@
-AC_INIT(src/libdvdcss.c)
+AC_INIT(libdvdcss, 1.2.10)

AC_PREREQ(2.50)
AC_CONFIG_AUX_DIR(.auto)
--- src/css.c.orig Fri Aug 29 20:42:47 2008
+++ src/css.c Wed Aug 17 11:52:49 2011
@@ -172,10 +172,13 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
{
char psz_key[KEY_SIZE * 3];
unsigned int k0, k1, k2, k3, k4;
+ int n;

- psz_key[KEY_SIZE * 3 - 1] = '\0';
+ memset(psz_key, 0, sizeof psz_key);
+ n = read( i_fd, psz_key, KEY_SIZE * 3 - 1 );
+ close( i_fd );

- if( read( i_fd, psz_key, KEY_SIZE * 3 - 1 ) == KEY_SIZE * 3 - 1
+ if( n == KEY_SIZE * 3 - 1
&& sscanf( psz_key, "%x:%x:%x:%x:%x",
&k0, &k1, &k2, &k3, &k4 ) == 5 )
{
@@ -189,9 +192,15 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
/* Don't try to save it again */
b_cache = 0;
i_ret = 1;
- }
+ }
+#if defined PACKAGE_VERSION
+ else if (n > 0 && strcmp(psz_key, PACKAGE_VERSION "\n") == 0)
+ {
+ /* didn't crack it, negative caching */
+ return -1;
+ }
+#endif

- close( i_fd );
}
}

@@ -203,6 +212,17 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
if( i_ret < 0 )
{
print_error( dvdcss, "fatal error in vts css key" );
+#if defined PACKAGE_VERSION
+ i_fd = open( dvdcss->psz_cachefile, O_RDWR|O_CREAT, 0644 );
+ if( i_fd >= 0 )
+ {
+ char message[sizeof(PACKAGE_VERSION) + 3];
+
+ sprintf( message, "%s\n", PACKAGE_VERSION);
+ write( i_fd, message, strlen(message) );
+ close( i_fd );
+ }
+#endif
return i_ret;
}
Diego Biurrun
2011-08-28 12:59:01 UTC
Permalink
Post by Marc Espie
I sent this a few weeks ago. I haven't gotten any useful feedback from it.
(I'm french, if you really have trouble expressing yourself in english).
I had email troubles in between, but I did not see any previous emails
from you.
Post by Marc Espie
I really would like to see negative caching in dvdcss.
What is negative caching?
Post by Marc Espie
I believe storing the PACKAGE_VERSION is the simplest thing to do, in case
someone figures out a bug that means key cracking was actually incorrect
later.
Hmmm...
Post by Marc Espie
I'm willing to spend a bit more time working on that patch, but GIVE ME
CONCRETE DIRECTIONS, not some fuzzy things like "I would do that differently"
(with about NO INDICATION of what should be done differently) or "this
should be separate patches" (I'll make a wild guess at: configure.ac separated
from the css code proper).
I'm not a libdvdcss developer, but here are some comments anyway..
Post by Marc Espie
--- configure.ac.orig Fri Aug 29 20:59:00 2008
+++ configure.ac Wed Aug 17 11:51:22 2011
@@ -1,4 +1,4 @@
-AC_INIT(src/libdvdcss.c)
+AC_INIT(libdvdcss, 1.2.10)
The AC_INIT syntax changed between autoconf versions, you are using the
newer one. I'm not sure what the policy for supporting old autotools
versions is for libdvdcss.
Post by Marc Espie
--- src/css.c.orig Fri Aug 29 20:42:47 2008
+++ src/css.c Wed Aug 17 11:52:49 2011
@@ -172,10 +172,13 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
{
char psz_key[KEY_SIZE * 3];
unsigned int k0, k1, k2, k3, k4;
+ int n;
- psz_key[KEY_SIZE * 3 - 1] = '\0';
+ memset(psz_key, 0, sizeof psz_key);
+ n = read( i_fd, psz_key, KEY_SIZE * 3 - 1 );
+ close( i_fd );
- if( read( i_fd, psz_key, KEY_SIZE * 3 - 1 ) == KEY_SIZE * 3 - 1
+ if( n == KEY_SIZE * 3 - 1
You add tabs to a file with only spaces used for indentation, same below.
Post by Marc Espie
@@ -189,9 +192,15 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
/* Don't try to save it again */
b_cache = 0;
i_ret = 1;
- }
+ }
trailing whitespace
Post by Marc Espie
+#if defined PACKAGE_VERSION
+ else if (n > 0 && strcmp(psz_key, PACKAGE_VERSION "\n") == 0)
+ {
+ /* didn't crack it, negative caching */
+ return -1;
+ }
+#endif
What you want to achieve with the #ifdef is a mystery to me.
PACKAGE_VERSION should always be set after your configure.ac change,
so the condition will always be true and thus superfluous.

Diego
Marc Espie
2011-08-28 13:28:50 UTC
Permalink
Post by Diego Biurrun
Post by Marc Espie
I sent this a few weeks ago. I haven't gotten any useful feedback from it.
(I'm french, if you really have trouble expressing yourself in english).
I had email troubles in between, but I did not see any previous emails
from you.
My previous series of emails was sent to videolan@

As an external developer, there is no obvious indication about libdvdcss-devel.
First videolan@ is mentioned as a contact address, not a mailing-list (hence
a quick simple stop when you just want to work on a specific patch). Second,
neither the libdvdcss tarball nor the videolan page about libdvdcss mention
the libdvdcss-devel mailing-list.
Post by Diego Biurrun
Post by Marc Espie
I really would like to see negative caching in dvdcss.
What is negative caching?
Not trying to re-crack keys that it couldn't crack the first time.

Over the last few years, I've been running into quite a few dvds where
some keys do not crack, without any ill effect on playing the dvd itself.
I suspect DVD manufacturers are purposely adding fake, unused keys in order
to try to make decrypting css more difficult/slower... and it kind of works,
since those dvds will spend a few minutes in libdvdcss each time you try
to crack them.

For negative caching, I store a simple PACKAGE_VERSION string into the
key file. This allows for subsequent versions of libdvdcss to do better
(for instance, if not cracking the key was due to a bug instead of actual
bogus keys on the dvd, the new version would automatically retry).
Post by Diego Biurrun
Post by Marc Espie
--- configure.ac.orig Fri Aug 29 20:59:00 2008
+++ configure.ac Wed Aug 17 11:51:22 2011
@@ -1,4 +1,4 @@
-AC_INIT(src/libdvdcss.c)
+AC_INIT(libdvdcss, 1.2.10)
The AC_INIT syntax changed between autoconf versions, you are using the
newer one. I'm not sure what the policy for supporting old autotools
versions is for libdvdcss.
This syntax has been around for a long time, and libdvdcss, as shipped,
contains a configure script anyways, so I don't think that's an issue.
Post by Diego Biurrun
Post by Marc Espie
--- src/css.c.orig Fri Aug 29 20:42:47 2008
+++ src/css.c Wed Aug 17 11:52:49 2011
@@ -172,10 +172,13 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
{
char psz_key[KEY_SIZE * 3];
unsigned int k0, k1, k2, k3, k4;
+ int n;
- psz_key[KEY_SIZE * 3 - 1] = '\0';
+ memset(psz_key, 0, sizeof psz_key);
+ n = read( i_fd, psz_key, KEY_SIZE * 3 - 1 );
+ close( i_fd );
- if( read( i_fd, psz_key, KEY_SIZE * 3 - 1 ) == KEY_SIZE * 3 - 1
+ if( n == KEY_SIZE * 3 - 1
You add tabs to a file with only spaces used for indentation, same below.
That I can fix, thanks.
Post by Diego Biurrun
Post by Marc Espie
+#if defined PACKAGE_VERSION
+ else if (n > 0 && strcmp(psz_key, PACKAGE_VERSION "\n") == 0)
+ {
+ /* didn't crack it, negative caching */
+ return -1;
+ }
+#endif
What you want to achieve with the #ifdef is a mystery to me.
PACKAGE_VERSION should always be set after your configure.ac change,
so the condition will always be true and thus superfluous.
I try to get things to work even if the above configure.ac patch is not
applied, but yeah, I can get rid of that.

Thank you for your comments.

--- src/css.c.orig Fri Aug 29 20:42:47 2008
+++ src/css.c Sun Aug 28 15:26:39 2011
@@ -172,10 +172,13 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
{
char psz_key[KEY_SIZE * 3];
unsigned int k0, k1, k2, k3, k4;
+ int n;

- psz_key[KEY_SIZE * 3 - 1] = '\0';
+ memset(psz_key, 0, sizeof psz_key);
+ n = read( i_fd, psz_key, KEY_SIZE * 3 - 1 );
+ close( i_fd );

- if( read( i_fd, psz_key, KEY_SIZE * 3 - 1 ) == KEY_SIZE * 3 - 1
+ if( n == KEY_SIZE * 3 - 1
&& sscanf( psz_key, "%x:%x:%x:%x:%x",
&k0, &k1, &k2, &k3, &k4 ) == 5 )
{
@@ -189,9 +192,12 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
/* Don't try to save it again */
b_cache = 0;
i_ret = 1;
+ }
+ else if (n > 0 && strcmp(psz_key, PACKAGE_VERSION "\n") == 0)
+ {
+ /* didn't crack it, negative caching */
+ return -1;
}
-
- close( i_fd );
}
}

@@ -203,6 +209,15 @@ int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
if( i_ret < 0 )
{
print_error( dvdcss, "fatal error in vts css key" );
+ i_fd = open( dvdcss->psz_cachefile, O_RDWR|O_CREAT, 0644 );
+ if( i_fd >= 0 )
+ {
+ char message[sizeof(PACKAGE_VERSION) + 3];
+
+ sprintf( message, "%s\n", PACKAGE_VERSION);
+ write( i_fd, message, strlen(message) );
+ close( i_fd );
+ }
return i_ret;
}

Loading...