2008年12月18日 星期四

設定 IIS 6.0 的 HTTPS 服務

若要在用戶端電腦和伺服器之間使用安全的通訊通道來交換資訊時,就必須啟用 Secure Sockets Layer (SSL) 功能。本文將說明如何在 Internet Information Services (IIS) 6.0 中設定 SSL / HTTPS 服務。

1. 從 IIS 網站伺服器中產生憑証申請要求
在【目錄安全設定】選項中點擊【伺服器憑證】按鈕,【下一步】,【建立新憑證】,【現在準備憑證請求】,【下一步】,輸入【名稱】,輸入【單位】和【部門】,輸入【公用名稱】,選擇【國家】並且輸入【省】和【市縣】並【下一步】,【下一步】,【下一步】,【完成】,最後儲存在 C:\certraq.txt 。

2. 準備 OpenSSL 工作環境
把 OpenSSL v0.9.8i (編譯後的 Win32 版本)安裝至系統中,在 bin 目錄下建立目錄 demoCA,在 demoCA 下建立 private 和 newcerts 目錄,並新建 index.txt,如果沒有 serial 檔案,則到OpenSSL 網站上下載 openssl 的源檔案,解壓後,到 apps\demoCA 下,拷貝 serial 檔案過來,兩個目錄兩個檔案都放到新建的 demoCA 下。

3. 使用 OpenSSL 建立專有憑證中心的私有金鑰與簽證檔



C:\OpenSSL\bin>openssl req -x509 -newkey rsa:1024 -keyout cakey.pem -out cacert.pem -days 3650 -config openssl.cfg
WARNING: can't open config file: openssl.cnf
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
...............++++++
..++++++
writing new private key to 'cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:TAIWAN
Locality Name (eg, city) []:TAIPEI
Organization Name (eg, company) [Internet Widgits Pty Ltd]:COMPANY
Organizational Unit Name (eg, section) []:UNIT
Common Name (eg, YOUR name) []:NAME
Email Address []:email@hinet.net


這時候會產生 CA 的私有金鑰 (cakey.pem) 與 CA 的簽證檔 (cacert.pem) 兩檔案,再將 cakey.pem 拷貝到 \demoCA\private 目錄下,把 cacert.pem 拷貝到 \demoCA 目錄下。

4. 使用 CA 簽證檔 (cacert.pem) 為 IIS 的憑証申請要求 (certreq.txt) 簽發憑証


C:\OpenSSL\bin>openssl ca -in certreq.txt -out server.pem -config openssl.cfg
WARNING: can't open config file: openssl.cnf
Using configuration from openssl.cfg
Loading 'screen' into random state - done
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 286 (0x11e)
Validity
Not Before: Dec 9 05:24:00 2008 GMT
Not After : Dec 9 05:24:00 2009 GMT
Subject:
countryName = TW
stateOrProvinceName = TAIWAN
organizationName = COMPANY
organizationalUnitName = UNIT
commonName = NAME
emailAddress = email@hinet.net
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
94:C0:17:C7:CC:5B:9F:E7:80:08:CF:7B:38:F7:65:3D:EF:8F:41:13
X509v3 Authority Key Identifier:
keyid:5C:E3:71:BC:C1:22:87:24:58:E4:D0:07:65:3C:5B:39:B5:63:0C:23

Certificate is to be certified until Dec 9 05:24:00 2009 GMT (365 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

C:\OpenSSL\bin>



5. 把剛剛產生的 server.pem 轉換成 x509 格式


openssl x509 -in server.pem -out server.cer


然後將 server.cer 搬移至 C 碟的根目錄下 (C:\server.cer)。

6. 在 IIS 上安裝憑證 (server.cer)
在有憑證要求的網站上按一下滑鼠右鍵,點擊【內容】,點擊【目錄安全設定】索引標籤,點擊【伺服器憑證】按鈕,點擊【下一步】,點選【處理擱置要求及安裝憑證】,再點擊【下一步】,輸入CA回應之「憑證授權的檔案」的路徑與名稱,選取C碟的憑證即可 (C:\server.cer),點擊【下一步】,輸入網站使用的SSL連接埠,可採預設值443即可,【下一步】,【完成】,【確定】。

Read more...

2008年11月25日 星期二

Unexpected Multithreading on Spring2 IoC Container

目前小弟我在執行的工作案是使用Spring2 + Hibernate3 + Flex3 + BPM + Multithreading技術的環境,有一天客戶提出的Scenario是需要用到Multithreading的,因為沒有注意到Multithreading這個條件,所以,就跟以往一樣開始撰寫Java程式和設定Spring XML configuration,在整個開發過程中都有進行單元測試,而且都很順利。但是,最後進行整合測試時,竟然發現有些模組會出現前一次執行的結果,而不會產生現在所要的結果,這下可頭大了。只好從頭開始將每個可能發生錯誤的模組進行測試,結果跟開發時一樣都沒有問題,最後只好使用Debug模式一行一行Trace程式碼,就在此時發現透過Spring的IoC注入模組並不會產生新的結果,而是直接回覆舊有的資料,因此就發現到可能是這個模組被設定成Singleton模式,因此,小弟我就立刻去翻閱Spring 2的文件,在Spring BeanFactory的XML Configuration章節中有提到,所有Spring beans的內定值都是Singletons,所以,當你想要定義一個Prototype Bean,就要在 XML 的設定檔中註明 scope="prototype",範例如下:



<bean id="studentDao" class="com.spring.service.StudentDaoImpl" scope="prototype">


Reference: http://static.springframework.org/spring/docs/2.0.x/reference/index.html

Read more...

2008年11月5日 星期三

在Vista中設定3.5G網卡

自從Vista系統開賣以來,大家都覺得Vista不好用,導致微軟縮短了Vista的生命週期,積極推出下一代Windows 7的作業系統,但是小弟我針對網路連線的功能部分卻覺得它比XP的好多了,怎麼說呢?一般使用XP的網路連線時,只要有安裝新的網路卡或設備,就會在右下角的工作列中多一個網路連線的示意圖,如果安裝了五種網路,哇!那就有五個小icon在那裏,可是Vista就有個優點,會全部將這些網路都放在『網路和共用中心』裡納管,只要將滑鼠移至『網路和共用中心』的小icon上,就會全部列出目前的連線網路,如圖所示。

其實,小弟我要說的重點是在使用3.5G網卡上網時,並不用像HiNet說明書所說的那樣,需安裝『HiNet無線上網連線軟體』與『華為連線軟體』才可連線。只要在第一次使用時,安裝網卡的驅動程式,讓『網路和共用中心』知道有這個數據機可以撥號上網就好,之後都直接在『網路和共用中心』使用『連線到網路』功能,直接撥號連線即可,不用再透過這兩套軟體,是不是方便多了呢?

Read more...

2008年9月24日 星期三

Free cPanel Web Hosting with PHP5/Mysql - no advertising!

They can offer you a free web hosting package packed with advanced features for hosting & building professional dynamic websites. They provide secure free web space with all the web hosting tools you could possibly ever need.

Free Web Hosting with Website Builder

Their package includes:
- 350 MB of Disk Space, 100 GB Bandwidth
- Host your own domain (http://www.yourdomain.com)
- cPanel Powered Hosting (you will love it)
- Over 500 website templates ready to download
- Easy to use website builder
- Free POP3 Email Box with Webmail access
- FTP and Web based File Manager
- PHP, MySQL, Perl, CGI, Ruby.
- And many more..

Click here to Register now: http://www.000webhost.com/

Read more...

Java語言中的 interface 和 abstract class 的比較

如果你有在開發 Java 程式語言的話,應該常常會遇到什麼狀況應該使用 abstract class ,什麼狀況應該使用 interface , 還是兩者都一起用呢? Interface 和 abstract class 表面上好像提供幾乎相同的能力,那如何決定使用哪個呢?
什麼時機使用 Interfaces
An interface allows somebody to start from scratch to implement your interface or implement your interface in some other code whose original or primary purpose was quite different from your interface. To them, your interface is only incidental, something that have to add on to the their code to be able to use your package.
什麼時機使用Abstract classes
An abstract class, in contrast, provides more structure. It usually defines some default implementations and provides some tools useful for a full implementation.
The catch is, code using it must use your class as the base. That may be highly inconvenient if the other programmers wanting to use your package have already developed their own class hierarchy independently. In Java, a class can inherit from only one base class.
什麼時機使用兩者一起使用
You can offer the best of both worlds, an interface and an abstract class. Implementors can ignore your abstract class if they choose. The only drawback of doing that is calling methods via their interface name is slightly slower than calling them via their abstract class name.
比較表



Interfaces vs Abstract Classes
feature
interface
abstract class
multiple inheritanceA class may implement several interfaces.A class may extend only one abstract class.
default implementationAn interface cannot provide any code at all, much less default code.An abstract class can provide complete code, default code, and/or just stubs that have to be overridden.
constantsStatic final constants only, can use them without qualification in classes that implement the interface. On the other paw, these unqualified names pollute the namespace. You can use them and it is not obvious where they are coming from since the qualification is optional.Both instance and static constants are possible. Both static and instance intialiser code are also possible to compute the constants.
third party convenienceAn interface implementation may be added to any existing third party class.A third party class must be rewritten to extend only from the abstract class.
is-a vs -able or can-doInterfaces are often used to describe the peripheral abilities of a class, not its central identity, e.g. an Automobile class might implement the Recyclable interface, which could apply to many otherwise totally unrelated objects.An abstract class defines the core identity of its descendants. If you defined a Dog abstract class then Dalmatian descendants are Dogs, they are not merely dogable. Implemented interfaces enumerate the general things a class can do, not the things a class is. In a Java context, users should typically implement the Runnable interface rather than extending Thread, because they’re not really interested in providing some new Thread functionality, they normally just want some code to have the capability of running independently. They want to create something that can be run in a thread, not a new kind of thread.The similar is-a vs has-a debate comes up when you decide to inherit or delegate.
plug-inYou can write a new replacement module for an interface that contains not one stick of code in common with the existing implementations. When you implement the interface, you start from scratch without any default implementation. You have to obtain your tools from other classes; nothing comes with the interface other than a few constants. This gives you freedom to implement a radically different internal design.You must use the abstract class as-is for the code base, with all its attendant baggage, good or bad. The abstract class author has imposed structure on you. Depending on the cleverness of the author of the abstract class, this may be good or bad.
homogeneityIf all the various implementations share is the method signatures, then an interface works best.If the various implementations are all of a kind and share a common status and behaviour, usually an abstract class works best. Another issue that’s important is what I call "heterogeneous vs. homogeneous." If implementors/subclasses are homogeneous, tend towards an abstract base class. If they are heterogeneous, use an interface. (Now all I have to do is come up with a good definition of hetero/homo-geneous in this context.) If the various objects are all of-a-kind, and share a common state and behavior, then tend towards a common base class. If all they share is a set of method signatures, then tend towards an interface.
maintenanceIf your client code talks only in terms of an interface, you can easily change the concrete implementation behind it, using a factory method.Just like an interface, if your client code talks only in terms of an abstract class, you can easily change the concrete implementation behind it, using a factory method.
speedSlow, requires extra indirection to find the corresponding method in the actual class. Modern JVMs are discovering ways to reduce this speed penalty.Fast
tersenessThe constant declarations in an interface are all presumed public static final, so you may leave that part out. You can’t call any methods to compute the initial values of your constants. You need not declare individual methods of an interface abstract. They are all presumed so.You can put shared code into an abstract class, where you cannot into an interface. If interfaces want to share code, you will have to write other bubblegum to arrange that. You may use methods to compute the initial values of your constants and variables, both instance and static. You must declare all the individual methods of an abstract class abstract.
adding functionalityIf you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method.If you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change.

Reference:
interface vs abstract class : Java Glossary

Read more...

2008年9月21日 星期日

會自動產生 autorun.inf 的 kavo 病毒

昨天朋友送來一部中毒的筆電,請我幫他解毒,看他似乎非常地灰心,所以還附上還原光碟給我,說最後手段就是重灌。可是常用電腦工作的人都知道,重灌作業系統是一件很可怕的事情,因為花費在恢復到以前工作環境的時間會比重灌作業系統的時間多上很多,而且還有可能會把資料給弄丟了,所以,基本上還是朝著把病毒清乾淨的目標前進。
我把電腦開機後發現桌面上怎麼有一堆殺 kavo 病毒的清毒工具,直覺上就猜想到這部電腦應該中了 kavo 相關的病毒,而且應該有人試著去解毒。因為之前我有解過這個病毒經驗,知道這個不好解,所以他們應該都試不成功吧!當然要檢查是否中了 kavo 病毒,在網路上有一篇的文章,寫得蠻詳細,可參考一下。
接著在 c:\windows\system32\ 目錄底下,用 dir /hs 的指令去查詢是否有 kavo 病毒的相關檔案,哇!如下面所列的真的好多!
kavo.exe
kxvo.exe
kevo1.dll
j3ewro.exe
jwedsfdo1.dll
解毒過程中,基本上都是使用進入作業系統的安全模式下,將這些檔案一一刪除,就完成解毒了,但是,不知道這部筆電是怎麼了,就是進不了安全模式,等了老半天螢幕還是黑的,硬碟沒有任何動靜,最後,想到一招,就是用 windows XP 的光碟片開機,用 R 修復功能進入控制台,就是像以前 DOS 一樣黑底白字的命令提示字元。然後進入 c:\windows\system32\ 目錄底下,先將這些病毒檔案的屬性改掉,然後就可一一刪除檔案,最後再重新開機就大功告成了!
Reference:
五個步驟,檢查你是否中了kavo病毒

Read more...

2008年9月19日 星期五

九和汽車委託代檢公司

我開的車子已經滿五年,所以要開始去驗車了,第一次是去南港區的良友代檢廠驗車,雖然服務態度也算不錯,可是針對沒驗過車的我還要自己開車,對準那對準這的,對這些檢驗過程真的很生疏,因此,第二次就想說找另外一家代檢廠,看會不會只要去繳完規費後就可以直接領車走人。因此,這一次就試著在台北市代驗地點網頁去找另外一家,發現九和汽車這一家似乎不錯,所以馬上就打電話確認是否有額滿,九和回覆下午五點前都OK,當然就馬上拿起鑰匙去驗車了。到了現場,服務人員就請我下車先去繳規費,然後給他收據後,他就請我在旁邊的椅子坐一下,就立刻幫我驗車,車子往前移動不到20公尺就都完成了,真的很不錯!
Reference:
台北市代驗地點網址
九和汽車

Read more...

2008年9月5日 星期五

可用遠端桌面登入Vista Home Premium

相信大家都知道微軟提供的遠端桌面連線功能是非常好用,只是會突然忘記有些OS版本是不提供遠端桌面的Server端功能,只提供Client端功能,這時大家都會覺得比爾蓋茲怎麼這麼小氣哩!不過沒關係,這時上網google一下,看有沒有網友提供解法,果真,大家都遇到相同的問題,當然也有提供完整的解法,真的太感謝這些高手了。

Steps to Add Remote Desktop to Vista Home Premium:

1. Download termsrv.zip here
2. Extract Termsrv.zip to a temp directory
3. Start “Command Prompt” in Administrator mode (Run As Administrator)
4. Run the corresponding batch file for your Vista edition
5. Allow TCP Port 3389 on Windows Firewall or any other firewall product.
6. Done

Reference: Enable Remote Desktop Connection on Vista Home Premium

Read more...

2008年8月28日 星期四

Support Memory Remapping Technology

由於最近記憶體的價格非常地便宜,所以打算將主機 (ASUS P5B-VM) 的記憶體升級至 4GB,此時,赫然發現主機板的 BIOS 竟然只能識別出 2816MB 而已,好奇怪喔!其餘的記憶體竟然消失不見了,以為買到壞掉的記憶體。後來去詢問 ASUS 原廠後,才發現 Intel 的 965 晶片組有這個硬體上的問題。不過還好有解,只要將 BIOS 更新到最新版後就會發現有一個 Memory remapping 的功能,再將它設成 enable 就可以了。但是,在 32 bit 的 OS 中還是只能用到3070MB的記憶體,這是 OS 的定址功能問題,與硬體無關,除非將作業系統換成 64 bit 就OK了。


參考資料:

The system memory that is reported in the System Information dialog box in Windows Vista is less than you expect if 4 GB of RAM is installed

Read more...

2008年7月21日 星期一

Upgrade To IIS 6 From IIS 5

由於微軟不再繼續維護Windows 2000 Server的作業系統,所以,必須將原本在IIS 5上執行的ASP程式移植到Windows 2003 Server的IIS 6上,結果真的如預期地遇到了一些問題。
微軟為了在IIS 6的版本增加安全性,所以關閉啟用上層路徑功能"../..",因此在程式中使用 Include 路徑的上層路徑功能來呼叫此目錄以外的程式來使用,結果就造成下面的錯誤訊息:
ASP error 0131 The include file function.inc cannot contain '..' to indicate the parent directory. /path/function.inc, line 2
The Page Cannot Be Displayed
HTTP 500-Internal server error

Reference:Enable Parent Paths Is Disabled by Default in IIS 6.0
撰寫的ASP程式可以透過 Include 功能來組合需要的功能模組,而這些程式碼都是用單純的文字格式存檔,在執行時是透過直譯器直接讀取ASP程式碼、翻譯、編譯及執行,因此,一個ASP程式會由多個文字檔案組成的,而這些文字檔若不是用同一編碼格式存檔,如ANSI、UTF-8,會造成IIS 6傳給瀏覽器的資料會是亂碼,這又是IIS 6比IIS 5限制多一點的地方。

Read more...

2008年7月20日 星期日

兩個百萬夜景

世界三大夜景:日本函館、香港、義大利拿坡里,已經收集到了兩個,只剩義大利拿坡里了。


日本函館山

函館位於北海道南部、渡島半島的尖端,是個歷史悠久的海港城市,由於它的特殊扇形地形,造就了獨一無二的雙區弧線自然美景,所以,在夏天的夜晚可以從標高三百三十四公尺的函館山上欣賞萬家燈火在腳下閃爍,讓人驚艷的夜景。


香港太平山

香港的夜景是從港島的太平山頂上往下俯瞰港島、維多利亞港、九龍半島甚至遙遠的新界也清晰在目。

最後還沒收集到的世界三大夜景-拿坡里,據說是像上帝遺忘的珍珠,散落在介於義大利半島和突尼西亞之間的海面,蔚藍的天空、湛藍的海水和潔白的屋子。真的讓人期待...

Read more...

2008年7月7日 星期一

第一次在日本住民宿

這次到日本北海道旅行時,有特意安排兩晚居住當地富良野的民宿,這個經驗真的非常特別,也體會到日本人的工作態度。

富良野的清晨

這間民宿是在北海道中富良野車站附近的Yamasan Pension,它是一棟兩層樓的木造建築,室內格局有明顯區分出民宿主人的私人空間與房客的公共空間,公共空間部份有舒適乾淨的客房五間(可容納13位房客),有挑高兩層樓的客廳,有可遠眺富良野的餐廳,有提供房客專用的浴室與廁所,雖然民宿的木質地板是不穿拖鞋的,可是卻不會讓你的白色襪子變成灰色的,乾淨吧!Pension的收費方式是以人為單位,一個人是$7000日幣而且是一泊二食。

雙人房

Room Key

在用餐時,更是讓我覺得Yamasan的用心,他的擺盤方式與色香味都不輸外面專業餐廳,重點是這些都是他自己構想出來的,厲害吧!另外,Yamasan會一直站在廚房邊觀望我們用餐,剛開始還有點不習慣,以為他在監視我們、暗示我們要用餐快一點,他才可以早一點休息,最後才知道他是一直到晚上11點才吃飯休息的,所以,他是站在廚房邊注意我們的狀況,是否吃完了沒,是否要準備上甜點,有點像Waiter一樣,讓我們有點不好意思。

在晚上8、9點後,Yamasan也不會跑回自己的私人空間休息,而是坐在餐桌上用筆電上網,看看有沒有人寄email給他,此時,他也會與同在餐廳的房客閒聊,說說富良野、美英有哪些不錯的景點,另外,他還會推薦給你他的私房景點,這些都是旅遊雜誌上不會寫的。在與Yamasan閒聊過程中發現到最令人訝異的是這間木造房子的屋齡,因為看起來非常新,原本以為只有兩三年的屋齡,沒想到已經18年了...嗯~~維護的真好。

Read more...

2008年6月13日 星期五

Java Threads Programming - MyDaemon.java

Java程式語言中提供了二種方法來撰寫Thread程式:
1. extents java.lang.Thread class
2. implements java.lang.Runnable interface
由於Java程式語言採用類別單一繼承方式,如果我們的類別已經繼承某個類別,那麼就不能再繼承Thread類別,也就是說,繼承了Thread類別,就不能再繼承其它類別。因此,還可以利用第二種方式來實現Thread功能,此方式需實作在Runnable介面中定義的run()方法,然後在new一個Thread物件時,傳入一個實作Runnable介面的物件作為引數,Thread物件會利用Runnable物件的run()方法,進而執行當中所定義的程式碼。所以,基本上是建議以實作Runnable的方式讓物件具有執行緒功能,也保留日後修改的彈性,而且利用Runnable介面來撰寫執行緒,程式較有一致性,當其他程式要用到時,可以有共同介面的標準,也比較符合OO的精神。
使用Runnable方式的程式碼如下:


Daemon.java
public abstract class Daemon implements Runnable {
protected Object executeObject = null;
Thread thread = null;

public Daemon(Object executeObject) {
this.executeObject = executeObject;
thread = new Thread(this);
}

public void run(){
doRun();
}

public abstract void doRun();

public void terminate() {
doTerminate();
}

public void doTerminate(){
}

public void start(){
thread.start();
}

public void stop() {
thread.interrupt();
}
}


MyDaemon.java
public class MyDaemon extends Daemon {

public MyDaemon(Object executeObject) {
super(executeObject);
// TODO Auto-generated constructor stub
}

@Override
public void doRun() {
// TODO Auto-generated method stub
SomeJob object = (SomeJob) this.executeObject;
object.run();
}
}


SomeJob.java
public class SsomeJobThread {
private int var1;

public void run() {
// do something ...
}

public int getVar1() {
return var1;
}

public void setVar1(int Var1) {
this.Var1 = var1;
}
}

呼叫方法如下:

SomeJob job = new SomeJob();
job.setVar1(123);
MyDaemon daemon = new MyDaemon(job);
daemon.start();

這個Daemon物件會自動幫我產生一個thread去執行我定義的工作,執行完後就自動消失了,不錯吧!

Read more...

2008年6月8日 星期日

台北七星山主峰

不知道什麼原因,突然大家約一約要去爬七星山,到了陽明公園後,做個簡單的暖身後就開始攻頂了。經過了一個小時的埋頭苦幹,終於到了七星山主峰,由於當日天氣不錯,居然可以看見遠方的雲海。






Read more...

  © Blogger template Spain by Ourblogtemplates.com 2008

Back to TOP