[libdvdcss-devel] try again: patch for negative caching of keys

Marc Espie espie at nerim.net
Sun Aug 28 15:28:50 CEST 2011


On Sun, Aug 28, 2011 at 02:59:01PM +0200, Diego Biurrun wrote:
> On Sun, Aug 28, 2011 at 12:23:17PM +0200, Marc Espie wrote:
> > 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.



> > 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).

> > --- 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.

> > --- 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.
> > +#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;
         }
 


More information about the libdvdcss-devel mailing list