line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OMA::Download::DRM; |
2
|
1
|
|
|
1
|
|
45459
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
1
|
|
|
1
|
|
319
|
$OMA::Download::DRM::VERSION = '1.00.07'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
OMA::Download::DRM - Perl extension for packing DRM objects according to the OMA DRM 1.0 specification |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This module encodes data objects according to the Open Mobile Alliance Digital Rights Management 1.0 specification in order to control how the end user uses these objects. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use OMA::Download::DRM; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 new |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $drm = OMA::Download::DRM->new(%args); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
1
|
|
|
1
|
1
|
398
|
my ($class, %arg)=@_; |
28
|
1
|
|
33
|
|
|
65
|
my $self={ |
|
|
|
50
|
|
|
|
|
29
|
|
|
|
|
|
|
'content-type' => $arg{'content-type'}, |
30
|
|
|
|
|
|
|
data => $arg{data}, |
31
|
|
|
|
|
|
|
key => $arg{key}, |
32
|
|
|
|
|
|
|
uid => $arg{'uid'} || rand(999999999), |
33
|
|
|
|
|
|
|
domain => $arg{domain} || 'example.com', |
34
|
|
|
|
|
|
|
#method => $arg{method}, |
35
|
|
|
|
|
|
|
boundary => undef, |
36
|
|
|
|
|
|
|
mime => undef |
37
|
|
|
|
|
|
|
}; |
38
|
1
|
|
|
|
|
4
|
$self=bless $self, $class; |
39
|
1
|
|
|
|
|
29
|
$self->{boundary} = 'mime-boundary/'.$self->{uid}.'/'.time; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
5
|
$self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
=head1 PROPERTIES |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 uid |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Returns download object uid |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
print $drm->uid; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
sub uid { |
53
|
0
|
|
|
0
|
1
|
0
|
return $_[0]->{uid}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 mime |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Returns the MIME type |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
print $drm->mime; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
sub mime { |
64
|
0
|
|
|
0
|
1
|
0
|
$_[0]->{mime}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 METHODS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 fw_lock |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Forward-lock delivery |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $drm = OMA::Download::DRM->new( |
74
|
|
|
|
|
|
|
'content-type' => 'image/gif', # Content MIME type |
75
|
|
|
|
|
|
|
'data' => \$data, # GIF image binary data reference |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
print "Content-type: ".$drm->mime."\n\n"; # Appropriate MIME type |
78
|
|
|
|
|
|
|
print $drm->fw_lock(); # Forward lock |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
sub fw_lock { |
82
|
0
|
|
|
0
|
1
|
0
|
my ($self)=@_; |
83
|
0
|
|
|
|
|
0
|
my $res=''; |
84
|
0
|
|
|
|
|
0
|
$res.='--'.$self->{boundary}."\r\n"; |
85
|
0
|
|
|
|
|
0
|
$res.= 'Content-Type: '.$self->{'content-type'}."\r\n"; |
86
|
0
|
|
|
|
|
0
|
$res.= 'Content-Transfer-Encoding: binary'."\r\n\r\n"; |
87
|
0
|
|
|
|
|
0
|
$res.= ${$self->{data}}; |
|
0
|
|
|
|
|
0
|
|
88
|
0
|
|
|
|
|
0
|
$res.= "\r\n"; |
89
|
0
|
|
|
|
|
0
|
$res.='--'.$self->{boundary}."--"; |
90
|
0
|
|
|
|
|
0
|
$self->{mime}='application/vnd.oma.drm.message; boundary='.$self->{boundary}; |
91
|
0
|
|
|
|
|
0
|
return $res; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 combined |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Combined delivery |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $drm = OMA::Download::DRM->new( |
99
|
|
|
|
|
|
|
'content-type' => 'image/gif', # Content MIME type |
100
|
|
|
|
|
|
|
'data' => \$data, # GIF image binary data reference |
101
|
|
|
|
|
|
|
'domain' => 'example.com' |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
print "Content-type: ".$drm->mime."\n\n"; # Appropriate MIME type |
104
|
|
|
|
|
|
|
print $drm->combined($permission, %constraint); # Combined delivery. See OMA::Download::DRM::REL. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
sub combined { |
108
|
1
|
|
|
1
|
1
|
7
|
my ($self, $permission, %constraint)=@_; |
109
|
1
|
|
|
|
|
3
|
my $res=''; |
110
|
1
|
|
|
|
|
6
|
$res.='--'.$self->{boundary}."\r\n"; |
111
|
1
|
|
|
1
|
|
446
|
use OMA::Download::DRM::REL::XML; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
317
|
|
112
|
1
|
|
33
|
|
|
26
|
my $rel = OMA::Download::DRM::REL::XML->new( |
113
|
|
|
|
|
|
|
'permission' => $permission, |
114
|
|
|
|
|
|
|
'uid' => 'cid:'.$self->{uid}.'@'.$self->{domain}, |
115
|
|
|
|
|
|
|
%constraint || () |
116
|
|
|
|
|
|
|
); |
117
|
1
|
|
|
|
|
5
|
$res.= 'Content-Type: '.$rel->mime."\r\n"; |
118
|
1
|
|
|
|
|
21
|
$res.= 'Content-Transfer-Encoding: binary'."\r\n\r\n"; |
119
|
1
|
|
|
|
|
6
|
$res.= $rel->packit; |
120
|
1
|
|
|
|
|
3
|
$res.= "\r\n\r\n"; |
121
|
1
|
|
|
|
|
4
|
$res.='--'.$self->{boundary}."\r\n"; |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
4
|
$res.= 'Content-Type: '.$self->{'content-type'}."\r\n"; |
124
|
1
|
|
|
|
|
8
|
$res.= 'Content-ID: <'.$self->{uid}.'@'.$self->{domain}.">\r\n"; |
125
|
1
|
|
|
|
|
2
|
$res.= 'Content-Transfer-Encoding: binary'."\r\n\r\n"; |
126
|
1
|
|
|
|
|
2
|
$res.= ${$self->{data}}; |
|
1
|
|
|
|
|
19
|
|
127
|
1
|
|
|
|
|
2
|
$res.= "\r\n"; |
128
|
1
|
|
|
|
|
4
|
$res.='--'.$self->{boundary}."--"; |
129
|
1
|
|
|
|
|
3
|
$self->{mime}='application/vnd.oma.drm.message; boundary='.$self->{boundary}; |
130
|
1
|
|
|
|
|
26
|
return $res; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 separate_content |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Separate delivery. Content encryption and packing. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $drm = OMA::Download::DRM->new( |
139
|
|
|
|
|
|
|
'content-type' => 'image/gif', # Content MIME type |
140
|
|
|
|
|
|
|
'data' => \$data, # GIF image binary data reference |
141
|
|
|
|
|
|
|
'domain' => 'example.com', |
142
|
|
|
|
|
|
|
'key' => '128bit ascii key' |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
print "Content-type: ".$drm->mime."\n"; # Appropriate MIME type |
145
|
|
|
|
|
|
|
print "X-Oma-Drm-Separate-Delivery: 12\n"; # The terminal expects WAP push 12 seconds later |
146
|
|
|
|
|
|
|
print $drm->separate_content($rights_issuer, $content_name); # Encrypted content |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
You then need to send the rights object separately |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
sub separate_content { |
152
|
1
|
|
|
1
|
1
|
757
|
my ($self, $rights_issuer, $content_name)=@_; |
153
|
1
|
50
|
|
|
|
5
|
die "Need $rights_issuer" unless $rights_issuer; |
154
|
1
|
50
|
|
|
|
3
|
die "Need $content_name" unless $content_name; |
155
|
1
|
|
|
1
|
|
472
|
use OMA::Download::DRM::CF; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
210
|
|
156
|
1
|
|
|
|
|
19
|
my $cf = OMA::Download::DRM::CF->new( |
157
|
|
|
|
|
|
|
### Mandatory |
158
|
|
|
|
|
|
|
'key' => $self->{'key'}, |
159
|
|
|
|
|
|
|
'data' => $self->{data}, |
160
|
|
|
|
|
|
|
'content-type' => $self->{'content-type'}, |
161
|
|
|
|
|
|
|
'content-uri' => 'cid:'.$self->{uid}.'@'.$self->{domain}, |
162
|
|
|
|
|
|
|
'Rights-Issuer' => $rights_issuer, |
163
|
|
|
|
|
|
|
'Content-Name' => $content_name, |
164
|
|
|
|
|
|
|
); |
165
|
1
|
|
|
|
|
5
|
$self->{mime}=$cf->mime; |
166
|
1
|
|
|
|
|
5
|
return $cf->packit; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 separate_rights |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Separate delivery. Rights object packing. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $rights = $drm->separate_rights($permission, %constraint) # you have to send this rights object via WAP Push. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
sub separate_rights { |
178
|
1
|
|
|
1
|
1
|
1423
|
my ($self, $permission, %constraint)=@_; |
179
|
1
|
|
|
1
|
|
863
|
use OMA::Download::DRM::REL::WBXML; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
101
|
|
180
|
1
|
|
|
|
|
41
|
my $rel = OMA::Download::DRM::REL::WBXML->new( |
181
|
|
|
|
|
|
|
'key' => $self->{'key'}, |
182
|
|
|
|
|
|
|
'permission' => $permission, |
183
|
|
|
|
|
|
|
'uid' => 'cid:'.$self->{uid}.'@'.$self->{domain}, |
184
|
|
|
|
|
|
|
%constraint |
185
|
|
|
|
|
|
|
); |
186
|
1
|
|
|
|
|
6
|
$self->{mime}=$rel->mime; |
187
|
1
|
|
|
|
|
4
|
return $rel->packit; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
1; |
190
|
|
|
|
|
|
|
__END__ |