亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? whiteboardservlet.java

?? J2ME MIDP_Example_Applications
?? JAVA
字號:
// Copyright 2003 Nokia Corporation.
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Corporation
// retains the right to make changes to this source code at
// any time, without notice. This source code is provided for informational
// purposes only.
//
// Nokia and Nokia Connecting People are registered trademarks of Nokia
// Corporation.
// Java and all Java-based marks are trademarks or registered trademarks of
// Sun Microsystems, Inc.
// Other product and company names mentioned herein may be trademarks or
// trade names of their respective owners.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
package whiteboard;

import java.io.*;
import java.security.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;

import org.bouncycastle.crypto.*;
import org.bouncycastle.crypto.digests.*;

import org.bouncycastle.crypto.engines.*;
import org.bouncycastle.crypto.paddings.*;
import org.bouncycastle.crypto.params.*;
import org.bouncycastle.util.encoders.Hex;

// Simple servlet serving GET and POST requests
// Version 1.4: Custom security and encryption of HTTP body
public class WhiteboardServlet
     extends HttpServlet
{

    private Whiteboard whiteboard;
    private ServletConfig context;
    private DateFormat format = null;
    private String key = null;
    private UserDatabase userDB = null;
    private long internalKey, counter;
    private SecureRandom random;


    public void init()
    {
        context = getServletConfig();
        String dateformat = context.getInitParameter("dateformat");
        key = context.getInitParameter("masterkey");
        if (dateformat != null)
        {
            try
            {
                format = new SimpleDateFormat(dateformat);
            }
            catch (Exception e)
            {
                // ignore, we'll check it later
            }
        }
        if (format == null)
        {
            format = DateFormat.getTimeInstance(DateFormat.SHORT);
        }

        // init the whiteboard data structure
        whiteboard = Whiteboard.getInstance();
        userDB = new UserDatabase();
        // insert a mock up user
        userDB.createUser("guest", "password");

        try
        {
            random = SecureRandom.getInstance("SHA1PRNG");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        internalKey = random.nextLong();
    }


    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, java.io.IOException
    {
        String username = authenticateUsername(req, resp, "GET");
        if (username != null)
        {
            String response = buildResponse();
            String nonce = createNonce();
            resp.setHeader("X-Crypto-Nonce", nonce);
            String cipherText = null;
            try
            {
                cipherText = doEncryption(response, userDB.getUser(username).getPassword(), nonce);
            }
            catch (Exception e)
            {
                resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                return;
            }
            resp.setContentType("text/plain");
            ServletOutputStream out = resp.getOutputStream();
            out.print(cipherText);
        }
    }


    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, java.io.IOException
    {
        String username = authenticateUsername(req, resp, "POST");
        if (username != null)
        {
            ServletInputStream in = req.getInputStream();
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            int i = -1;
            while ((i = in.read()) != -1)
            {
                buffer.write(i);
            }
            String msg = null;
            boolean error = false;
            try
            {
                msg = decodeMessage(buffer.toByteArray(), userDB.getUser(username).getPassword(),
                    req.getHeader("X-Crypto-Nonce"));
                if (msg == null || !msg.startsWith("msg="))
                {
                    error = true;
                }
                else
                {
                    msg = msg.substring(4).trim();
                }
            }
            catch (InvalidCipherTextException e)
            {
                error = true;
            }
            catch (Throwable e)
            {
                error = true;
                e.printStackTrace();
            }
            if (!error)
            {
                whiteboard.addMessage(new Message(username, new Date(), msg));
                String nonce = createNonce();
                resp.setHeader("X-Crypto-Nonce", nonce);
                String cipherText = null;
                String response = buildResponse();
                try
                {
                    cipherText = doEncryption(response, userDB.getUser(username).getPassword(), nonce);
                }
                catch (Exception e)
                {
                    resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                    return;
                }
                resp.setContentType("text/plain");
                ServletOutputStream out = resp.getOutputStream();
                out.print(cipherText);
            }
            else
            {
                resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    "Missing msg parameter");
            }
        }
    }


    private String doEncryption(String plainText, String password, String nonce)
        throws InvalidCipherTextException
    {
        // this should be long enough for a DES key
        String compundKey = password + ":" + nonce;
        Digest digest = new MD5Digest();
        byte[] key = new byte[digest.getDigestSize()];
        digest.update(compundKey.getBytes(), 0, compundKey.getBytes().length);
        digest.doFinal(key, 0);

        byte content[] = plainText.getBytes();

        BufferedBlockCipher cipherEngine = new PaddedBufferedBlockCipher(new DESEngine());
        cipherEngine.init(true, new KeyParameter(key));

        byte[] cipherText = new byte[cipherEngine.getOutputSize(content.length)];

        int cipherTextLength = cipherEngine.processBytes(content, 0, content.length,
            cipherText, 0);
        cipherEngine.doFinal(cipherText, cipherTextLength);

        return new String(Hex.encode(cipherText));
    }


    private String decodeMessage(byte[] content, String password, String nonce)
        throws InvalidCipherTextException
    {
        String compundKey = password + ":" + nonce;
        Digest digest = new MD5Digest();
        byte[] key = new byte[digest.getDigestSize()];
        digest.update(compundKey.getBytes(), 0, compundKey.getBytes().length);
        digest.doFinal(key, 0);

        byte cipherText[] = Hex.decode(content);

        BufferedBlockCipher cipherEngine = new PaddedBufferedBlockCipher(new DESEngine());
        cipherEngine.init(false, new KeyParameter(key));

        byte[] plainText = new byte[cipherEngine.getOutputSize(cipherText.length)];

        int plainTextLength = cipherEngine.processBytes(cipherText, 0, cipherText.length,
            plainText, 0);
        cipherEngine.doFinal(plainText, plainTextLength);

        return new String(plainText);
    }


    private String authenticateUsername(HttpServletRequest req, HttpServletResponse resp, String method)
        throws IOException
    {
        String username = null;
        if (req.getHeader("X-Authorization") == null)
        {
            resp.setHeader("X-WWW-Authenticate", createDigestChallenge());
            resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        }
        else
        {
            String xauth = req.getHeader("X-Authorization");
            username = validateDigestResponse(xauth, method);
            if (username == null)
            {
                resp.setHeader("X-WWW-Authenticate", createDigestChallenge());
                resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
            }
        }
        return username;
    }


    private String createDigestChallenge()
    {
        StringBuffer challenge = new StringBuffer("X-Digest realm=\"").append(getServletName()).append("\", qop=\"auth\", ");
        String nonce = createNonce();
        challenge.append("nonce=\"").append(nonce).append("\", ");

        Digest digest = new MD5Digest();
        byte[] result = new byte[digest.getDigestSize()];
        String opaque = "" + random.nextLong();
        digest.update(opaque.getBytes(), 0, opaque.getBytes().length);
        digest.doFinal(result, 0);
        opaque = new String(Hex.encode(result));
        challenge.append("opaque=\"").append(opaque).append("\"");

        return challenge.toString();
    }


    private synchronized String createNonce()
    {
        String nonce = (System.currentTimeMillis() + counter++) + ":" + internalKey;
        Digest digest = new MD5Digest();
        byte[] result = new byte[digest.getDigestSize()];
        digest.update(nonce.getBytes(), 0, nonce.getBytes().length);
        digest.doFinal(result, 0);
        // the string is at least result.length characters long
        nonce = new String(Hex.encode(result));
        return nonce;
    }



    private String validateDigestResponse(String challengeResponse, String method)
    {
        if (!challengeResponse.startsWith("X-Digest"))
        {
            return null;
        }
        challengeResponse = challengeResponse.substring(8).trim();
        StringTokenizer tokenizer = new StringTokenizer(challengeResponse, ",");
        String nonce = null;
        String realm = null;
        String opaque = null;
        String uri = null;
        String username = null;
        String response = null;
        while (tokenizer.hasMoreTokens())
        {
            String nextToken = tokenizer.nextToken().trim();
            if (nextToken.startsWith("nonce"))
            {
                nonce = nextToken.substring(7, nextToken.length() - 1);
            }
            if (nextToken.startsWith("opaque"))
            {
                opaque = nextToken.substring(8, nextToken.length() - 1);
            }
            if (nextToken.startsWith("uri"))
            {
                uri = nextToken.substring(5, nextToken.length() - 1);
            }
            if (nextToken.startsWith("username"))
            {
                username = nextToken.substring(10, nextToken.length() - 1);
            }
            if (nextToken.startsWith("response"))
            {
                response = nextToken.substring(10, nextToken.length() - 1);
            }
            if (nextToken.startsWith("realm"))
            {
                realm = nextToken.substring(7, nextToken.length() - 1);
            }

        }
        if (realm == null || nonce == null || opaque == null || uri == null || username == null || response == null)
        {
            return null;
        }
        if (!realm.equals(getServletName()))
        {
            return null;
        }
        User user = userDB.getUser(username);
        if (user == null)
        {
            return null;
        }
        String A1 = username + ":" + realm + ":" + user.getPassword();
        Digest digest = new MD5Digest();
        int size = digest.getDigestSize();
        byte[] allbytes = A1.getBytes();
        byte[] result = new byte[size];
        digest.update(allbytes, 0, allbytes.length);
        digest.doFinal(result, 0);
        A1 = new String(Hex.encode(result));
        String A2 = method + ":" + uri;
        allbytes = A2.getBytes();
        digest.update(allbytes, 0, allbytes.length);
        digest.doFinal(result, 0);
        A2 = new String(Hex.encode(result));
        String calculatedResponse = A1 + ":" + nonce + ":" + A2;
        allbytes = calculatedResponse.getBytes();
        digest.update(allbytes, 0, allbytes.length);
        digest.doFinal(result, 0);
        calculatedResponse = new String(Hex.encode(result));
        if (calculatedResponse.equals(response))
        {
            return username;
        }

        return null;
    }


    // Creates the response containing a list of messages
    private String buildResponse()
    {
        Collection messages = whiteboard.getMessages();
        // if no count parameter or error during parsing
        if (messages == null)
        {
            messages = whiteboard.getMessages();
        }

        ValueGenerator generator = new ValueGenerator();
        generator.addValue("" + messages.size());
        Iterator i = messages.iterator();
        while (i.hasNext())
        {
            Message msg = (Message) i.next();
            generator.addValue(msg.getUser());
            generator.addValue(format.format(msg.getTimestamp()));
            generator.addValue(msg.getContent());
        }

        // print the text
        return generator.getString();
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩不卡在线| 狠狠色丁香久久婷婷综合_中 | 精品日本一线二线三线不卡| 欧美午夜片在线观看| 成人免费看黄yyy456| 国产麻豆精品久久一二三| 极品瑜伽女神91| 老司机精品视频导航| 久久精品国产亚洲高清剧情介绍| 亚洲国产裸拍裸体视频在线观看乱了| 国产精品久久久久影视| 国产日韩亚洲欧美综合| 日韩一区中文字幕| 亚洲激情中文1区| 丝袜美腿一区二区三区| 激情欧美一区二区| 不卡av在线网| 欧美三级午夜理伦三级中视频| 欧美麻豆精品久久久久久| 日韩欧美一区二区不卡| 久久亚洲捆绑美女| 一区二区视频在线| 免费xxxx性欧美18vr| 国产乱人伦精品一区二区在线观看| 国产一区二区成人久久免费影院| 成人精品视频一区| 欧美另类一区二区三区| 国产亚洲精品bt天堂精选| 亚洲色图色小说| 蜜臂av日日欢夜夜爽一区| 黑人巨大精品欧美一区| av不卡免费在线观看| 4438成人网| 亚洲欧洲av另类| 麻豆成人91精品二区三区| 99国产麻豆精品| 精品国一区二区三区| 亚洲日本在线观看| 国产精品自产自拍| 欧美日韩国产在线观看| 国产欧美一区二区三区网站| 亚洲影视在线播放| 成人综合日日夜夜| 日韩手机在线导航| 亚洲一区在线视频| 成人a区在线观看| 日韩女优电影在线观看| 亚洲欧美国产毛片在线| 久久 天天综合| 欧美久久久久久久久久| 中文字幕五月欧美| 国产精一品亚洲二区在线视频| 欧美在线免费视屏| 中文字幕一区在线观看| 国产一区在线看| 国产精品88888| 91玉足脚交白嫩脚丫在线播放| 精品国产三级a在线观看| 日本一区二区三区dvd视频在线| 国产欧美中文在线| 午夜久久福利影院| 欧美三级一区二区| 亚洲一区二区成人在线观看| 成人中文字幕电影| 久久久亚洲高清| 奇米影视7777精品一区二区| 在线国产电影不卡| 亚洲欧美日韩在线不卡| 99久久er热在这里只有精品15| 精品久久久久久久久久久久久久久| 亚洲午夜在线视频| 欧美影视一区在线| 亚洲一区二区美女| 欧洲亚洲精品在线| 一区二区三区在线免费观看| 95精品视频在线| 亚洲天堂久久久久久久| 91丨九色丨国产丨porny| 精品精品国产高清一毛片一天堂| 午夜精品久久久久久久久久久 | 亚洲影院免费观看| 成人av网站在线观看免费| 日韩一区二区三区观看| 日韩高清一区在线| 欧美日韩在线观看一区二区 | 国产一区二区三区免费看| 欧美zozozo| 国产一区二区三区最好精华液| 欧美乱熟臀69xxxxxx| 天堂成人免费av电影一区| 日韩一区二区三区免费观看| 热久久国产精品| 久久在线观看免费| 成人精品电影在线观看| 亚洲色图视频网站| 3751色影院一区二区三区| 久久99精品国产麻豆婷婷| 国产视频不卡一区| 99国内精品久久| 日本不卡视频在线观看| 26uuu久久天堂性欧美| aaa亚洲精品一二三区| 五月天国产精品| 久久久精品天堂| 99在线热播精品免费| 日韩av高清在线观看| 久久久不卡影院| 在线观看日韩精品| 久久99国产精品成人| 亚洲欧美日韩在线| 日韩欧美国产精品一区| 暴力调教一区二区三区| 婷婷一区二区三区| 国产精品久久久久久久久免费相片| 欧美在线观看视频一区二区三区| 免费黄网站欧美| 欧美极品美女视频| 在线电影院国产精品| 不卡的av在线播放| 美国毛片一区二区| 一区二区三区国产| 中文字幕不卡在线播放| 欧美一区二区在线看| 色婷婷久久综合| 国产精品88av| 久久精品国产99| 亚洲五码中文字幕| 亚洲天堂网中文字| 中文字幕第一区综合| 精品国产露脸精彩对白| 97se亚洲国产综合自在线不卡| 秋霞影院一区二区| 亚洲午夜日本在线观看| 亚洲人成网站在线| 欧美国产乱子伦 | 欧美另类久久久品| 在线观看日韩av先锋影音电影院| 韩国女主播成人在线观看| 婷婷亚洲久悠悠色悠在线播放| 亚洲欧美电影一区二区| 国产偷国产偷精品高清尤物| 日韩免费观看高清完整版在线观看| 色哟哟亚洲精品| 99r国产精品| 97久久人人超碰| 99久久国产免费看| av亚洲精华国产精华精华| 国产成人午夜电影网| 国产乱人伦偷精品视频不卡| 另类小说视频一区二区| 麻豆精品久久久| 免费成人小视频| 黄色精品一二区| 国产一区二区不卡在线| 国产成人精品午夜视频免费| 国产精品自拍三区| 成人一区二区在线观看| fc2成人免费人成在线观看播放| 国产精品一区不卡| 国产大陆亚洲精品国产| 国产激情一区二区三区四区| 国产精品一区久久久久| 国产在线视频不卡二| 丁香一区二区三区| 一本到高清视频免费精品| 欧美羞羞免费网站| 欧美一区2区视频在线观看| 精品国产免费久久| 欧美韩国日本综合| 亚洲品质自拍视频| 图片区小说区国产精品视频| 精品一区二区三区视频在线观看 | 成人av影院在线| 在线免费亚洲电影| 日本韩国一区二区三区视频| www.亚洲在线| 色综合久久88色综合天天免费| 国产成人午夜99999| 久国产精品韩国三级视频| 91在线国内视频| 久久99久久99| 国产乱码精品一区二区三区五月婷| 久久久另类综合| 成人性生交大片免费看在线播放| 盗摄精品av一区二区三区| 国产1区2区3区精品美女| 91理论电影在线观看| 色悠久久久久综合欧美99| 日韩丝袜情趣美女图片| 国产精品久久久久一区二区三区| 国产精品久久久久一区| 免费不卡在线视频| 一本色道久久加勒比精品| 欧美日韩国产中文| 国产精品乱码久久久久久 | 91精品国产高清一区二区三区| 欧美成人午夜电影| 亚洲伦理在线精品| 久久精品久久精品| 欧美自拍丝袜亚洲|