2012-01-13

Python / Twisted / WebSocket / Protobuf on Windows 7 (64bit)





Python Basic
============


- Install 32-bit Python 2.7.2


- Install setuptool-0.6c11.win32-py2.7.exe (easy_install)


Twisted Framework and SSL support
=================================


- Install Twisted-11.1.0 from source code ( it installs zope interface automatically from internet)


    unzip Twisted-11.1.0.tar.bz2
    cd Twisted-11.1.0
    setup.py install


- Install Win32OpenSSL 32bit 1.0.0e 


- Install pyOpenSSL (Twisted SSL support needs this)


    cd c:\python2.7\scripts
    easy_install pyopenssl


WebSocket Autobahn
==================


- Install Autobahn from source code


    unzip autobahn
    cd autobahn\lib\python 
    setup.py install


  Test the Autobahn installation


    cd autobahn\demo\echo
    echo_server.py


    In another DOS window


    cd autobahn\demo\echo
    echo_client.py


  Test the SSL support of WebSocket and Twisted


    cd autobahn\demo\echo_tls
    echo_tls_server.py


    In another DOS window
    
    cd autobahn\demo\echo_tls
    echo_tls_client.py -u wss://localhost:9000
  
Protobuf and Protobuf.socketrpc
===============================


- Install protobuf Python library from source code


    unzip protobuf-2.4.1-win32.zip
    cd protobuf-2.4.1\python
    setup.py install
    
- Install protobuf compiler Windows binary


    create d:\temp\protoc
    add d:\temp\protoc to PATH
    put protoc.exe into d:\temp\protoc


- Install protobuf.socketrpc from source code


    unzip protobuf.socketrpc-1.3.2.tar.gz
    cd protobuf.socketrpc-1.3.2
    setup.py install


  Test the protobuf.socketrpc


    cd protobuf.socketrpc-1.3.2\src\protobuf\socketrpc\examples\helloworld
    run_server.py


    In another DOS windows


    cd protobuf.socketrpc-1.3.2\src\protobuf\socketrpc\examples\helloworld
    run_client.py




  
  

IIS 7.5 HTTPS Configuration and Certificate Installation





How to Generate a Server Certificate for the IIS server 7.5?
============================================================


Background
----------


There're different ways to generate server certificate for IIS server 7.5. Here's 
a way to use a private CA to sign the server certificate. 


The private CA here is a openssl based CA. To set up the CA, you have to run a Linux
with openssl installed. There're couple of shell scripts to help create the CA and 
sign certificate request. 


For this testing, the private CA is running on Aric's Ubuntu Linux. The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FHPBt
Q+dhFLDvnu3ZwgU0iSaZVmEzyclDAbgnrde3rzofHoFX/c/4MZJf2NYg992REiOO
TNp9wuN/yxlRcCxZQYRzLoqkBoYGQwFj705Um83DX7jOGVwdFF2o7GVN0QnvXHBY
2JsGjKthN6VDWi2jZjzaLPBot9hilA==
-----END CERTIFICATE-----


The CA certificate might be needed on the client side in order to verify the certificates
signed by this CA. If needed, just copy above CA contents (including begin and end lines)
to a text file, and import it into the client system. It might be different about how to 
import the CA certificate on different systems.


Steps to Create Server Certificate for IIS 7.5
----------------------------------------------


1. Create certificate request on IIS 7.5




   a. Open IIS Manager;


   b. Select the server you are going to create certificate;


   c. In the 'Features View', double click 'Server Certificates'. It shows a list of the 
      certificates installed for this server;


   d. In the 'Actions' panel, click 'Create Certificate Request...';


   e. In the new dialog box, enter the information required. Could use the server name as the
      'Common Name'. Click 'Next';


   f. Choose 'Microsoft RSA SChannel Cryptographic Provider' and '1024' bit length. Click
      'Next';


   g. Click the browse button to select a folder and file name to save the certificate request.
      Click 'Finish'.


2. Send the certificate request to the CA to sign it


   Just copy the file you saved above and send to Aric.


3. The CA signs the certificate


   Aric will sign this certificate request and send back the certificate.


4. Install the certificate on IIS 7.5


   a. Save the signed certificate into a folder on the server;


   b. Open IIS Manager, select the server you are going to create certificate;


   c. In the 'Features View', double click 'Server Certificates'. It shows a list of the 
      certificates installed for this server;


   d. In the 'Actions' panel, click 'Complete Certificate Request...';


   e. In the new dialog box, click the browse button to find the certificate file just saved;
      Note you may need to set the filter to '*.*' rather than '*.cer' if the certificate is 
      saved with a different suffix from '.cer'.


   f. In 'Friendly name' field, enter something, i.e. Aric signed certificate. Click 'OK'.


   g. If everything is ok, now you have installed the certificate on IIS 7.5;


5. Enable HTTPS for the web site


   a. Open IIS Manager;


   b. Select the server you are going to create certificate;


   c. Navigate to the web site you want to enable HTTPS;


   d. In 'Features View', under 'Actions' panel, click 'Bindings...';


   e. If there's no https binding enabled, you click 'Add...' to add it. If it already exists, 
      click 'Edit...' to modify it;


   f. In the new dialog box, choose the 'https' Type, enter your port number in 'Port'. Under
      'SSL certificate:', select the certificate you just installed in step 4. Click 'OK' to 
      finish. There might come up with some warnings, just click OK to finish it.


   g. Now back to 'Site Bindings' dialog, click 'Close';


   h. Restart the web site by clicking 'Restart' under the 'Actions' panel.


6. Now your web site should work with HTTPS. You can open a browser to test it.



Makefile example 2

#
# Introduction
#
# This is a Makefile example which can be used to build library or program from
# given directories. These directories could be at the same folder of the Makefile
# itself, or they could exist in other levels of the Makefile, sub-folders or
# parent-folders. 
#
# The Makefile searches all the .cpp files in the given folders and compile them
# into object files and link them into library or program. It generates dependency
# files automatically so that it can catch any change or the source files or 
# related header files.
#
# All the output of the make process is put in $(ODIR) folder. The default value
# is 'Build', but can be overriden with 'ODIR=xxx' when executing 'make'.   
#
# This makefile example contains a example to search folders and sub-folders for
# source file, and then collect all the folders.
#


PWD := $(abspath $(shell pwd))
TOP_DIR := $(abspath ../../..)
ODIR ?= Build


#
# The final targat. Should define only one of them: PROG or LIB
#
PROG := 
LIB := libapclient.a


#
# Find all the directories containing any generated CPP file.
#
GENERATED_TOP_DIR := $(TOP_DIR)/Dingo/Client/AccessPoint/GeneratedServices
GENERATED_CPP_FILES := $(shell find $(GENERATED_TOP_DIR) -name *.cpp)
GENERATED_CPP_DIRS := $(sort $(dir $(GENERATED_CPP_FILES)))


#
# The modules (directories) that need to be built. All the .cpp files in these
# directories will be built automatically.
#
MODULES   := \
  $(TOP_DIR)/Dingo/Client/AccessPoint/TinyXML \
    $(TOP_DIR)/Dingo/Gateway/Siemens.Gateway.Linux.Client \
    $(TOP_DIR)/Dingo/Gateway/PlatformSpecific/Linux \
  $(GENERATED_CPP_DIRS)

# CFLAGS for compiling
CFLAGS := -MD -MP -g \
-I. \
-I$(TOP_DIR)/Dingo/Client/AccessPoint/GatewayClient \
-I$(TOP_DIR)/Dingo/Client/AccessPoint/GatewayProxy \
-I$(TOP_DIR)/Dingo/Client/AccessPoint/GatewayProxy/gSoap \
-I$(TOP_DIR)/Dingo/Client/AccessPoint/TinyXML \
-I$(TOP_DIR)/Dingo/Gateway \
-I$(TOP_DIR)/Dingo/Gateway/PlatformSpecific/Linux \
-I$(TOP_DIR)/Dingo/Client/AccessPoint/GeneratedServices \


#
# -DDEBUG to enable logging of gSoap library
#
ifeq ($(DEBUG),yes)
CFLAGS += -DDEBUG
endif


ifeq ($(OPENSSL),yes)
CFLAGS += -DWITH_OPENSSL
endif


ifeq ($(ARM),yes)
CFLAGS += -I$(TOP_DIR)/../application/include
endif


#
# LDFLAGS for linking PROG
#
LDFLAGS :=


#
# Common Part
#
ifneq ($(ARM),yes)
CROSS_COMPILE
endif


SRC_DIRS  := $(MODULES)
INC_DIRS := $(MODULES)
BUILD_DIRS:= $(addprefix $(ODIR),$(subst $(TOP_DIR),,$(MODULES)))


SRCS      := $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.cpp))
OBJS := $(patsubst %.cpp,%.o,$(addprefix $(ODIR),$(subst $(TOP_DIR),,$(SRCS))))
DEPS      := $(OBJS:.o=.d)
INCLUDES  := $(addprefix -I,$(INC_DIRS))


CFLAGS += $(INCLUDES)


CC        := $(CROSS_COMPILE)g++
LD        := $(CROSS_COMPILE)g++
AR := $(CROSS_COMPILE)ar
ECHO := echo
MKDIR := mkdir -p
RM := rm -rf
LN := ln -sf


vpath %.cpp $(SRC_DIRS)


define make-goal
$1/%.o : %.cpp
@$(ECHO) "CC   $$<"
@$(CC) $(CFLAGS) -c $$< -o $$@


endef


.PHONY: all checkdirs clean 


all: checkdirs $(ODIR)/$(LIB) $(ODIR)/$(PROG) 


ifneq ($(PROG),)
$(ODIR)/$(PROG): $(OBJS)
@$(ECHO) "LD   $@"
@$(LD) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
endif


ifneq ($(LIB),)
$(ODIR)/$(LIB): $(OBJS)
@$(ECHO) "AR   $@"
@$(AR) crs $@ $(OBJS)
endif


checkdirs: $(BUILD_DIRS)

$(BUILD_DIRS):
@$(ECHO) "MKDIR  $@"
@$(MKDIR) -p $@


clean:
@$(RM) $(BUILD_DIRS) $(ODIR) $(TOP_DIR)/Dingo/Client/AccessPoint/TinyXML


$(foreach bdir,$(BUILD_DIRS),$(eval $(call make-goal,$(bdir))))


-include $(DEPS)


test:
@echo $(GENERATED_CPP_DIRS)

Makefile example 1

#
# Introduction
#
# This is a Makefile example which can be used to build library or program from
# given directories. These directories could be at the same folder of the Makefile
# itself, or they could exist in other levels of the Makefile, sub-folders or
# parent-folders. 
#
# The Makefile searches all the .cpp files in the given folders and compile them
# into object files and link them into library or program. It generates dependency
# files automatically so that it can catch any change or the source files or 
# related header files.
#
# All the output of the make process is put in $(ODIR) folder. The default value
# is 'Build', but can be overriden with 'ODIR=xxx' when executing 'make'.   
#
#

# The folder where the Makefile exists
PWD := $(abspath $(shell pwd))

# A common folder which is parent-folder of all given folders in $(MODULES)
TOP_DIR := $(abspath ../../..)

# The default output folder, could be overriden with 'ODIR=xxx' when 'make'.
ODIR ?= Build

# The final targat. Should define only one of them: PROG or LIB
PROG := 
LIB := libapclient.a

# The modules (directories) that need to be built. All the .cpp files in these
# directories will be built automatically. They should be specified with prefix 
# of$(TOP_DIR).
MODULES   := \
  $(TOP_DIR)/Dingo/Client/AccessPoint/ServiceProxy \
  $(TOP_DIR)/Dingo/Client/AccessPoint/ServiceProxy/gSoap \
  $(TOP_DIR)/Dingo/Client/AccessPoint/Services/IncomingEventService/Source/DataObjects \
  $(TOP_DIR)/Dingo/Client/AccessPoint/Services/IncomingEventService/Source/MetadataObjects \
  $(TOP_DIR)/Dingo/Client/AccessPoint/Services/IncomingEventService/Source/Services \
$(TOP_DIR)/Dingo/Gateway/Siemens.Gateway.Linux.Client \
$(TOP_DIR)/Dingo/Client/AccessPoint/TinyXML
# The external libs need to be linked. This is used when build program.
LIBS :=

# CFLAGS for compiling. -MD -MP must be kept.
CFLAGS := -MD -MP -g -I. \
-I$(TOP_DIR)/Dingo/Gateway \
 -I$(TOP_DIR)/Dingo/Gateway/PlatformSpecific/CPP \
-I$(TOP_DIR)/Dingo/Client/AccessPoint/Services/IncomingEventService \
-I$(TOP_DIR)/Dingo/Client/AccessPoint/TinyXML

# LDFLAGS for linking. It's only used when build program.
LDFLAGS :=

# Cross compile option 
ifneq ($(ARM),yes)
CROSS_COMPILE
endif

################################################################################
# Below part should be considered as standard and normally don't need to change!
################################################################################

SRC_DIRS  := $(MODULES)
BUILD_DIRS:= $(addprefix $(ODIR),$(subst $(TOP_DIR),,$(MODULES)))

SRCS      := $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.cpp))
OBJS := $(patsubst %.cpp,%.o,$(addprefix $(ODIR),$(subst $(TOP_DIR),,$(SRCS))))
DEPS      := $(OBJS:.o=.d)

INCLUDES  := $(addprefix -I,$(SRC_DIRS))
CFLAGS += $(INCLUDES)

CC        := $(CROSS_COMPILE)g++
LD        := $(CROSS_COMPILE)g++
AR := $(CROSS_COMPILE)ar
ECHO := echo
MKDIR := mkdir -p
RM := rm -rf
LN := ln -sf

vpath %.cpp $(SRC_DIRS)

define make-goal
$1/%.o : %.cpp
@$(ECHO) "CC   $$<"
@$(CC) $(CFLAGS) -c $$< -o $$@

endef

.PHONY: all checkdirs clean 

all: checkdirs $(ODIR)/$(LIB) $(ODIR)/$(PROG)

ifneq ($(PROG),)
$(ODIR)/$(PROG): $(OBJS)
@$(ECHO) "LD   $@"
@$(LD) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
endif

ifneq ($(LIB),)
$(ODIR)/$(LIB): $(OBJS)
@$(ECHO) "AR   $@"
@$(AR) crs $@ $(OBJS)
endif

checkdirs: $(BUILD_DIRS)
$(BUILD_DIRS):
@$(ECHO) "MKDIR  $@"
@$(MKDIR) -p $@

clean:
@$(RM) $(BUILD_DIRS) $(ODIR)

$(foreach bdir,$(BUILD_DIRS),$(eval $(call make-goal,$(bdir))))

-include $(DEPS)

VMWare Player

1. Share folder

Share folder is a better option in order to share files between Windows and virtual machine Linux. It's better than  use Samba. In order to use Share folder, you don't have to have any virtual network.

2. Virtual network:

The host-only network is not necessary. You can use NATed interface to allow the virtual machine to access outside world. Give the host VMnet interface an IP address of the same segment of virtual machine, then the host can access virtual machine. For NATed interface, there's always a special IP address reserved as the gateway for the network segment.