annotate dvdauth.c @ 986:fadb8eeff7a8

commitus interruptus
author gabucino
date Mon, 04 Jun 2001 08:06:20 +0000
parents 6fbd39309b87
children e5fc7ec51fa3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
1 /* (C)2001 by LGB (Gabor Lenart), based on example programs in libcss
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
2 lgb@lgb.hu */
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
3
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
4 /* don't do anything with this source if css support was not requested */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
5 #include "config.h"
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
6 #ifdef HAVE_LIBCSS
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
7
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
8 #include <stdio.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
9 #include <stdlib.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
10 #include <linux/cdrom.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
11 // FIXME #include <string.h> conflicts with #include <linux/fs.h> (below)
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
12 //#include <string.h> // FIXME this conflicts with #include <linux/fs.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
13 #include <unistd.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
14 #include <fcntl.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
15 #include <sys/types.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
16 #include <sys/ioctl.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
17 #include <sys/stat.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
18
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
19 #include <css.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
20
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
21 #include "dvdauth.h"
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
22
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
23 char *dvd_device=NULL;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
24 unsigned char key_disc[2048];
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
25 unsigned char key_title[5];
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
26 unsigned char *dvdimportkey=NULL;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
27 int descrambling=0;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
28
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
29
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
30 #include <linux/fs.h>
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
31
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
32 #ifndef FIBMAP
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
33 #define FIBMAP 1
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
34 #endif
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
35
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
36
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
37 static int path_to_lba ( int fd )
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
38 {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
39 int lba = 0;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
40 if (ioctl(fd, FIBMAP, &lba) < 0) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
41 perror ("ioctl FIBMAP");
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
42 fprintf(stderr,"Hint: run mplayer as root!\n");
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
43 // close(fd);
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
44 return -1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
45 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
46 return lba;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
47 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
48
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
49
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
50
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
51 static void reset_agids ( int fd )
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
52 {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
53 dvd_authinfo ai;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
54 int i;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
55 for (i = 0; i < 4; i++) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
56 memset(&ai, 0, sizeof(ai));
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
57 ai.type = DVD_INVALIDATE_AGID;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
58 ai.lsa.agid = i;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
59 ioctl(fd, DVD_AUTH, &ai);
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
60 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
61 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
62
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
63
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
64 int dvd_import_key ( unsigned char *hexkey )
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
65 {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
66 unsigned char *t=key_title;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
67 int digit=4,len;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
68 bzero(key_title,sizeof(key_title));
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
69 // printf("DVD key: %s\n",hexkey);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
70 for (len=0;len<10;len++) {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
71 // printf("-> %c\n",*hexkey);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
72 if (!*hexkey) return 1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
73 if (*hexkey>='A'&&*hexkey<='F') *t|=(*hexkey-'A'+10)<<digit;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
74 else if (*hexkey>='0'&&*hexkey<='9') *t|=(*hexkey-'0')<<digit;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
75 else return 1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
76 if (digit) digit=0; else {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
77 digit=4;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
78 t++;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
79 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
80 hexkey++;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
81 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
82 if (*hexkey) return 1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
83 printf("DVD key (requested): %02X%02X%02X%02X%02X\n",key_title[0],key_title[1],key_title[2],key_title[3],key_title[4]);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
84 descrambling=1;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
85 return 0;
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
86 }
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
87
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
88
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
89
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
90 int dvd_auth ( char *dev , int fd )
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
91 {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
92 int devfd; /* FD of DVD device */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
93 int lba;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
94
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
95
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
96 if ((devfd=open(dev,O_RDONLY))<0) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
97 fprintf(stderr,"DVD: cannot open DVD device \"%s\".\n",dev);
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
98 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
99 }
559
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
100
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
101 if (!CSSisEncrypted(devfd)) {
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
102 printf("DVD is unencrypted! Skipping authentication!\n(note: you should not use -dvd switch for unencrypted discs!)\n");
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
103 return 0;
6fbd39309b87 Detect unencrypted DVDs and not try to auth them
lgb
parents: 546
diff changeset
104 } else printf("DVD is encrypted, issuing authentication ...\n");
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
105
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
106 /* reset AGIDs */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
107 reset_agids(devfd);
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
108
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
109 /* authenticate disc */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
110 if (CSSAuthDisc(devfd,key_disc)) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
111 fprintf(stderr,"DVD: CSSAuthDisc() failed.\n");
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
112 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
113 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
114
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
115 /* authenticate title */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
116 lba=path_to_lba(fd);
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
117 if (lba==-1) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
118 fprintf(stderr,"DVD: path_to_lba() failed.\n");
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
119 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
120 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
121 if (CSSAuthTitle(devfd,key_title,lba)) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
122 fprintf(stderr,"DVD: CSSAuthTitle() failed.\n");
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
123 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
124 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
125
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
126 /* decrypting title */
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
127 if (CSSDecryptTitleKey (key_title, key_disc) < 0) {
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
128 fprintf(stderr,"DVD: CSSDecryptTitleKey() failed.\n");
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
129 return 1;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
130 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
131
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
132 close(devfd);
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
133 printf("DVD title key is: %02X%02X%02X%02X%02X\n",key_title[0],key_title[1],key_title[2],key_title[3],key_title[4]);
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 492
diff changeset
134 descrambling=1;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
135 return 0;
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
136 }
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
137
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
138
888a85621f50 preliminary DVD support using libcss
lgb
parents:
diff changeset
139 #endif