SoftBank 3GCの転送不可設定

SoftBank3GC端末では、何種類かの方法で画像や動画などの再配布を禁止することができます。その1つにOMAのDRM仕様に基づいた「Forward Lock」を使用する方法があります。

この方法を利用すると画像や動画などの再配布を比較的簡単に防ぐことができます。

詳細な仕様はOMAの仕様書SoftBank技術資料(HTTP編)などをご確認ください。

サンプルプログラム

以下は「Forward Lock」を使用したServletのサンプルです。リクエストがあると、対応するファイルを読み込み、OMA DRM Message形式のレスポンスを返します。実際のファイル(jpg,png,3gpなど)は mountPoint初期化パラメータで指定されるディレクトリに保存しておきます。

このサンプルでは Mime Typeをサーブレットコンテナの設定から取得します。このため、3gpなどを利用する場合には mime-mapping が適切に設定されていることを確認してください。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.File;
import java.io.FileInputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ForwardLockServlet extends HttpServlet{

    protected static final String ENC = "ISO-8859-1";
    protected static final byte[] CRLF = { 0xd, 0xa };
    protected static final String BOUNDARY = "-boundary-";

    protected static final int BUFSIZE = 1024 * 4;
    protected static String FS =
                    System.getProperty("file.separator");

    protected String  mountPoint;
    protected boolean debug;

    public void init() throws ServletException{

        mountPoint = getInitParameter("mountPoint");
        if (mountPoint == null || mountPoint.length() == 0){
            throw new ServletException("mountPoint: invalid init parameter.");
        }
        if (mountPoint.endsWith(FS) && mountPoint.length() != FS.length()){
            mountPoint = mountPoint.substring(0, mountPoint.length() -
                                FS.length());
        }

        debug = new Boolean(getInitParameter("debug")).booleanValue();

        log("initialized: mountPoint=" + mountPoint +
            " debug=" + debug);
    }

    public void doGet(
            HttpServletRequest request,
            HttpServletResponse response)
                    throws IOException, ServletException{

        String ru = request.getRequestURI();
        int n = ru.lastIndexOf("/");
        String filename = ru.substring(n+1);

        if (debug){
            log("request=" + ru + " filename=" + filename);
        }

        File file = new File(mountPoint + FS + filename);
        if (! file.exists()){
            log("file does not exists." + file);
            sendError(response);
            return;
        }

        String mimeType = getServletContext().getMimeType(filename);
        if (mimeType == null){
            log("no mime-type defined." + filename);
            sendError(response);
            return;
        }

        response.setContentType(
                "application/vnd.oma.drm.message; boundary=" +
                BOUNDARY);

        OutputStream os = response.getOutputStream();
        put(os, file, mimeType);
        os.close();
    }

    protected void sendError(HttpServletResponse response) throws IOException{
        response.sendError(response.SC_NOT_FOUND);
    }

    public void put(OutputStream os, File file, String mimeType)
                        throws IOException{

        os.write(("--" + BOUNDARY).getBytes(ENC));
        os.write(CRLF);
        os.write(("Content-type: " + mimeType).getBytes(ENC));
        os.write(CRLF);
        os.write("Content-Transfer-Encoding: binary".getBytes(ENC));
        os.write(CRLF);
        os.write(CRLF);

        InputStream is = new FileInputStream(file);
        byte[] bytes = new byte[BUFSIZE];
        int n;
        while (true){
            if ((n = is.read(bytes)) == -1){
                break;
            }
            os.write(bytes, 0, n);
        }
        is.close();

        os.write(CRLF);
        os.write(("--" + BOUNDARY + "--").getBytes(ENC));
    }
}

注意点

SoftBank技術資料(HTTP編)に記載されていますが、「Forward Lock」を使って htmlやxhtmlコンテンツを配信することはできないようです。また「OMA Download」のと併用にも注意点がありますので仕様書で詳細をご確認ください。