Tomcat 下配置 HTTPS 数字证书

March 20th, 2010 lennydou No comments

在Tomcat下配置HTTPS的证书, 用户第一次访问需要下载安装证书,然后以后访问就可以以安全连接的方式访问了.配置过程首先需要使用JDK自带的keytool来生成一个keystore文件,然后从keystore文件导出一个certreq文件,然后使用该文件到www.freeca.cn 生成一个证书文件,再把该证书文件导入JVM就OK了.

具体配置过程如下:

( 我的参数如下: IP地址192.168.2.101,用户名是lenny,密码是123456,组织都是buaa,城市是Beijing,使用的操作系统是win7 )

1. 打开 cmd ,生成keystore文件lenny

keytool -genkey -alias lenny -keyalg RSA  -keystore C:\lenny -validity 36500 -keysize 512

其中lenny是别名,可以随便取;-keyalg RSA是加密算法;-keystore C:\lenny 是生成的文件(在C盘下);       -validity 36500是有效期为10年;-keysize 512生成的密钥是512位的。

( 注意: 填写具体信息时,”名字和姓氏”一定是你的域名或IP地址,比如我在实验室没有域名,IP地址为192.168.2.101,所以我的”名字和姓氏”填写的是192.168.2.101,所以实验室的其他电脑也可以使用https访问我的Web应用程序  )

 

2. 使用 keytool -certreq 命令生成certreq文件 C:\serverreq

keytool -certreq -keystore c:\lenny -alias lenny -file c:\serverreq  

3. 从C:\lenny.文件中生成了CSR文件C:\serverreq文件, 然后使用notepad++打开c:\serverreq文件。把里面的内容复制出来,我的文件serverreq内容大概是

—–BEGIN NEW CERTIFICATE REQUEST—–
MIIBITCBzAIBADBnMQswCQYDVQQGEwJjbjEQMA4GA1UECBMHQmVpamluZzEQMA4GA1UEBxMHQmVp
amluZzEPMA0GA1UEChMGYmVlbHVuMQ8wDQYDVQQLEwZiZWVsdW4xEjAQBgNVBAMTCWxvY2FsaG9z
dDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCYIMDa/LxbGBbdL3jEa8zMzBMKQdtNVib0rO4rVz4J
FiDfZzpsMRPaCCNR7dMN92da/hnnhrYbMQTknrMlj6dxAgMBAAGgADANBgkqhkiG9w0BAQUFAANB
AGUFd9d9FHNH6oFLMmL6s5RBW7tVa4v8j4pS5vQNGE/4DFbRv+MyyVyZvNcetlNaLjuFcyoN7PB8
N9L33Y/D9to=
—–END NEW CERTIFICATE REQUEST—–

然后打开 http://www.freeca.cn 网站,然后在申请证书Tab里面选择 CSR 申请方式,把上述内容粘贴到文本框中,然后验证 CSR,网站会让你选择一个邮箱,然后会把内容发到你邮箱里。第一封邮件是让你确认你要申请数字证书,确认后会收到第二封邮件,把里面的内容拷贝到记事本,然后保存并把后缀名改成 .cer。我取得名字是lenny.cer。

 

4. 把之前生成的C:\lenny 中的密码信息导入到 C:\lenny.cer文件中

keytool -export -keystore c:\lenny -alias lenny -file C:\lenny.cer

 

5. 把从邮箱中拷贝出的文字生成的C:\lenny.cer文件导入到JVM。导入的方法如下:

cd C:\Program Files\Java\jdk1.7.0\jre\lib\

keytool -import -keystore .\security\cacerts -alias lenny -file c:\lenny.cer

 ( 切记: 这一步需要输入密码,这个密码是 changeit,之前的密码都是创建keystore时的密码123456 )

 

6. 然后设置Tomcat根目录下面的/conf/server.xml,然后修改为

<Connector protocol=”org.apache.coyote.http11.Http11Protocol”
           port=”8443″ minSpareThreads=”5″ maxSpareThreads=”75″
           enableLookups=”true” disableUploadTimeout=”true”
           acceptCount=”100″  maxThreads=”200″
           scheme=”https” secure=”true” SSLEnabled=”true”
           keystoreFile=”C:\lenny” keystorePass=”123456″
           clientAuth=”false” sslProtocol=”TLS”/>

 

7. 然后在网页里输入https://192.168.2.101:8080/ 就可以访问了。第一次访问的时候,还会弹出Certificate Error页面。这是可以安装证书,然后以后访问就可以使用安全连接的方式了。

 ( 注意: 浏览器访问https时,第一次需要安装证书,记得把证书安装到Trusted Root(根)位置 )

 

Categories: Chinese - 中文 Tags: , ,

Tomcat6下配置HTTPS

February 27th, 2010 lennydou No comments

我使用的JDK版本为JDK7,使用的的Tomcat版本为6.0.24;配置Tomcat下的HTTPS其实很简单,只需要完成两步工作就可以了;操作系统为Windows 7。

一、生成“服务器证书文件”

我把生成的“服务器证书文件”取名为tomcat.key(也可以取成abc.keystore,随自己喜欢就好)。简单起见,我把tomcat.key放在C盘根目录下面(我的配置环境为windows,linux类似)。
首先使用JDK自带的工具keytool生成一个“服务器证书”,取名为tomcat.key。

C:\Users\Administrator>keytool -genkey -alias tomcat -keyalg RSA -keystore C:\to
mcat.key
输入keystore密码:
再次输入新密码:
您的名字与姓氏是什么?
[Unknown]:  beelun
您的组织单位名称是什么?
[Unknown]:  beelun
您的组织名称是什么?
[Unknown]:  beelun
您所在的城市或区域名称是什么?
[Unknown]:  beijing
您所在的州或省份名称是什么?
[Unknown]:  beijing
该单位的两字母国家代码是什么
[Unknown]:  cn
CN=beelun, OU=beelun, O=beelun, L=beijing, ST=beijing, C=cn 正确吗?
[否]:  y

输入<tomcat>的主密码
(如果和 keystore 密码相同,按回车):

C:\Users\Administrator>jdk -version
‘jdk’ is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Administrator>java -version
java version “1.7.0-ea”
Java(TM) SE Runtime Environment (build 1.7.0-ea-b23)
Java HotSpot(TM) Client VM (build 12.0-b01, mixed mode, sharing)

C:\Users\Administrator>

按照提示,输入密码。我输入的密码为123456(注意:此密码在配置server.xml时需要)。其他信息按照提示输入就可以,在输入tomcat主密码时,我直接键入回车,使其和keystore的密码保持一致。

此时,在C盘下面就生成了一个PCKS1.2格式的数字证书文件C:\tomcat.key。

二、配置server.xml文件

修改tomcat\conf目录下面的server.xml文件,添加一项:

<Connector protocol=”org.apache.coyote.http11.Http11Protocol”
port=”8443″ minSpareThreads=”5″ maxSpareThreads=”75″
enableLookups=”true” disableUploadTimeout=”true”
acceptCount=”100″  maxThreads=”200″
scheme=”https” secure=”true” SSLEnabled=”true”
keystoreFile=”C:\tomcat.key” keystorePass=”123456″
clientAuth=”false” sslProtocol=”TLS”/>

需要注意一行“keystoreFile=”C:\tomcat.key” keystorePass=”123456″”,其中keystorefile是你生成的“服务器证书文件”,keystorePass是该服务证书文件的密码。

三、在浏览器地址栏里输入 https://localhost:8443/ 检验一下就OK了。

Update
From http://forums.java.net/jive/message.jspa?messageID=282519

I found some hints on the web that
CN should be the fully-qualified domain name of your server host

I replaced “localhost” with “pc_name”.”domain_name”
and it worked. They (pc_name and domain_name) are concatenated by dot.

Note:
My “domain_name” contains dots too.

I tested certificates on the same PC, but maybe this help you.

Categories: Chinese - 中文 Tags: , ,

Install MySQL from source in a Linux box

February 20th, 2010 Bali 1 comment

I had a CentOS Linux box bundled with a MySQL with Latin as default charset. As time goes by, I need

a) utf-8 everywhere(client, server, collation, everywhere) to support Chinese.

b) Innodb as default engine

Here is what I did:

1) Download latest source(mysql-5.1.44) from MySQL site

2) rpm -i xxx.src.rpm to install the source. By default, the source will be installed to /usr/src/redhat/SOURCES/mysql-5.1.44.

3) Go the root dir of source, run:

CFLAGS=”-O3″ CXX=gcc CXXFLAGS=”-O3 -felide-constructors \
-fno-exceptions -fno-rtti” ./configure \
–prefix=/usr/local/mysql –enable-assembler \
–with-mysqld-ldflags=-all-static \
–with-charset=utf8 \
–with-collation=utf8_general_ci \
–with-plugins=all

Explain: use gcc as compiler; install mysql to /usr/local/mysql; utf8 as default char set; install all plugins including innodb.

During this process, you may see errors saying “I need this, I need that”, use ‘yum‘ to install them.

And ./configure –help will show all possible options.

4) make

5) make install

And /usr/local/mysql will be the rool dir of new mysql installation.

6) Modify /etc/my.cnf. /usr/src/redhat/SOURCES/mysql-5.1.44/support-files/ contains sample configuration files. Note to set below:

[mysqld]

default-storage-engine = INNODB

7) Modify /etc/init.d/mysqld. You may need sym-link to new mysql installation.

Done. Below message should prove the installation is fine:

mysql> show engines;
+————+———+—————————————————————-+————–+——+————+
| Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |
+————+———+—————————————————————-+————–+——+————+
| ndbcluster | NO      | Clustered, fault-tolerant tables                               | NULL         | NULL | NULL       |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| FEDERATED  | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| ARCHIVE    | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| InnoDB     | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| MyISAM     | YES     | Default engine as of MySQL 3.23 with great performance         | NO           | NO   | NO         |
+————+———+—————————————————————-+————–+——+————+
9 rows in set (0.00 sec)

mysql> show variables like ‘%char%’;
+————————–+—————————————-+
| Variable_name            | Value                                  |
+————————–+—————————————-+
| character_set_client     | utf8                                   |
| character_set_connection | utf8                                   |
| character_set_database   | utf8                                   |
| character_set_filesystem | binary                                 |
| character_set_results    | utf8                                   |
| character_set_server     | utf8                                   |
| character_set_system     | utf8                                   |
| character_sets_dir       | /usr/local/mysql/share/mysql/charsets/ |
+————————–+—————————————-+
8 rows in set (0.00 sec)

mysql> show variables like ‘%colla%’;
+———————-+—————–+
| Variable_name        | Value           |
+———————-+—————–+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+———————-+—————–+
3 rows in set (0.00 sec)

Categories: English - 英文 Tags: ,

Graduate from Microsoft

January 8th, 2010 Bali 4 comments

(Keep in touch. My msn: baocun_hld AT hotmail DOT com, email: bill.z.li AT gmail DOT com)

My dear friends,

Today is my last working day in Microsoft, and it is time for me to start a long-awaited adventure. During past 3 years, many folks impressed me deeply and I hope have a slice of knowledge/skills you have.  After working in such a wonderful place, I possessed enough confidence to face any subtle difficulties ahead. What I got are much more than what I contributed to this company.

What I learned

  • How to tackle the most complex problems in the world as a team.
  • How to attract most smart people
  • How to inspire people
  • How to make a great place to work
  • How to build the right software right as a team
  • How to deliver good news
  • How to deliver bad news(This one is harder)
  • How to deliver good/bad reviews(One of hardest part of people management)
  • How to deliver a speech
  • How to handle *angry* customers
  • How to educate customers
  • How to learn what customers want
  • How to sit down with customers and close a deal
  • How to run a team of different size in different stage with different goals
  • How to make friends(Pop quiz: Do ICs need friends? Are they all about diagram and code?)
  • How to approach people and win their support
  • How to win an email argument
  • How to response to the competition news
  • How to beat competitors
  • How to build ecosystem
  • How to build up a giant company from scratch (If I can say)
  • The way how MSFT encourages knowledge sharing – Discussion loop, brown bag, online learning center, in-person training, marc polo, silk road, mentorship, mentor ring, code review, spec review …
  • Share ideas – think week paper, idea exchange, …
  • The most easy one – How to reply to all with a “good job” message after a product ship :-)
  • And many more…

I won’t claim I am a guru in any of areas above because I see what the highest standards are in this company. And I just reach the good(to me) level of combination of these ingredients.

People

  • So many great folks including leadership, developer, tester, PM, marketing, sales, support… I can’t say your names since this is public post, but I will memorize how you changed my mind.

and also something unique about me…

In addition to taking part in shipping 3 products…

  • Win FOOL(group alias ‘FOOL’) award. I am probably the only person who has this award in greater Asia.(If not, let me know. Maybe we can talk about that.)
  • Win Best Business Value award in a startup team
  • Win largest number of valid bugs in first team wide bug bash
  • Deliver a presentation to the whole STBC in all hands meeting. (Enwei is even listening to me:-)
  • Enter final list with a mobile phone innovation idea(Finally it is so smart that one team in US is on the way of building it quietly.)
  • Board number of of STBC citizenship committee
  • Organizer of Junior Achievement program in STBC
  • Posted a question which a technical fellow answered(MSFT have less than 20 technical fellows which are highest technical title one can achieve.)
  • Regular guest speaker of SJTU software institution
  • Probably the best Java learner in a .NET world
  • Probably the developer with most deep business minds, or business man with strong technical background(I call it “Think globally, act locally” as my blog slogan.)

Almost everyone asked about where I am going. This world is undertaking dramatic changes, especially this country. I can’t stay in this huge market to build software for anywhere else except here forever. Life is short, and I won’t forgive myself if time just passes by as “yet another year” way. Pursuing a fair ROI is another factor which won’t be achieved by working for any company. I am happy to complete engagement with Microsoft roughly on schedule.

2010 will be a new exciting start. I will enjoy in any event.

Good luck to us all! (And luck is actually where preparations meet opportunities.)

Bill

Categories: English - 英文 Tags:

鸟瞰淘宝开放平台

November 12th, 2009 Bali No comments

概述

Taobao Open Platform(TOP),淘宝开放平台,是淘宝将一些(不是全部)数据(店铺,商品等)通过编程接口开放给开发者。说简单点是这样,一般我们大家都是在网页里面点点点,来装修店铺,买卖东西的,是人肉通过鼠标和键盘完成的。TOP API,可以帮助大家用程序来完成同样的事情。

目标

该文主要回答一下几个问题:

1) 淘宝为什么开放平台?对于开发者意味着什么?

2) 开放了些什么东东?

3) 如何写一个简单的基于开放平台应用?

淘宝开放的缘由

Taobao经过几年的发展,已经成为国内X2C的头块品牌。它发起并完善了广大的网商,用户,以及与之相关的支付,物流,信用等系统。现在基本无人不淘宝。我的一位同事,所有的东西基本上都在taobao上买,还有一位朋友一大爱好就是周末在taobao上买东西。

但淘宝已经差不多到了不得不开放的地步。在内部,大的卖家渴望走出去,店主渴望以某种方式在300w个网店中脱颖而出,各种购买方式层出不穷,团购、限时拍卖等;在外部,社区、sns、购物搜索已经开始直接或间接涉足X2C市场。面对这么多元化的需求,淘宝自己去满足,肯定会力不从心;视而不见,那会引起积怨,累计到一定程度,必然有后来者取而代之。那怎么办?简单。既然这个钱,我不想赚,那就帮别人去赚,但你们得围绕着我来玩。开放应运而生。如果要看fancy版本的同样解释,请看博文:

小前端、大后台 路鹏(淘宝副总裁)

业务方向

现在淘宝主推三大业务方向:独立网店、社区电子商务化、第三方开发的工具海。

· 淘宝不讳言独立网店,真是很令人佩服。独立网店的样品工程就是优衣库,基本思路就是网站的域名和UI是独立网店的,其他的东西都是淘宝的,比如用户、支付、商品信息等。ShopEx在这方面是淘宝的合作伙伴。

· 社区电子商务化。简单来说,就是在bbs(如天涯)和sns(如人人网)中通过TOP API展示淘宝上商品,一但成交,大家分钱。

· 工具海。做垂直行业的商家管理工具,卖给旺铺卖家。

当然还有其他。参考:TOP业务方向

盈利模式

光炒概念,没有盈利模式的事情,我一向是只看不碰。那大多只是烧钱者的游戏,一般人玩儿不起。淘宝开放还是有比较清楚的变现模式的(包括但不限于):

· 淘宝客佣金。淘宝客是按成交计费的,CPA模式。而且API中允许用户加入一些自定义数据,用于确定购买行为过程中的贡献方,使得分享利润成为可能。以前写过篇文章,就提到分享利润的一个应用

· 插件分成。插件分为店铺管理插件和淘江湖SNS平台插件。前者是方便管理店铺用的,后者偏重娱乐性,概念类似Facebook的应用

· 软件销售。C/S模式,或者ShopEx独立网店大多属于这种模式。

· 传统广告。比如你调用淘宝API生成网页,加Google AdSense进入,也是可以的。

参考:TOP盈利模式

API

参考:TOP API文档

API/角色

六个基本角色,权限从低到高依次为:公开查询应用、买家应用、卖家应用、商家应用、高级应用、专业应用。较高角色的权限包含较低角色的权限。

还有三个独立角色,社区应用、媒体应用、淘宝客应用。相互独立,与六个基本角色不存在依赖关系。

API/分类

API操作的对象,有如下11种:用户,产品,类目,商品,交易,评价,物流,店铺,淘宝客,淘江湖(v=2.0),图片空间。

API基本的命名规则是<namespace>.<object>.<action>,如taobao.item.get用于获取单个商品的详细信息。

API/如何进行API调用

基于REST协议的API。调用接口地址是:

测试环境地址:http://gw.api.tbsandbox.com/router/rest

正式环境地址:http://gw.api.taobao.com/router/rest

TOP会给每个应用分配app_keyapp_secret,相当于该应用的用户名和密码。API调用传入的参数分为系统参数(每个API都需要,且格式相同)和API专有参数(随API不同而不同)两类。系统参数中,app_key由系统分配所得,session通过下列方法获得,而sign是根据签名规则生成,其实就是通过一个hash函数完成了加密和校验的双重功能。这和Facebook的那一套东西很像。

参考:TOP API系统级参数定义 How Facebook Authenticates Your Application

Demo

TOP开放的是基于RESTAPI,和编程语言无关的。下面用Java语言为例,写个hello world

不用TOP Java SDKdemohttp://open.taobao.com/demo/javaDemo.zip

TOP SDKdemo: http://wiki.open.taobao.com/index.php/FAQ

注意:SDK给的其实Java源文件,需要copy到源文件的目录下,进行编译。