NaCl: Networking and Cryptography library

Introduction

NaCl (pronounced “salt”) is a new easy-to-use high-speed software library for network communication, encryption, decryption, signatures, etc. NaCl’s goal is to provide all of the core operations needed to build higher-level cryptographic tools.

Of course, other libraries already exist for these core operations. NaCl advances the state of the art by improving security, by improving usability, and by improving speed.

继续阅读

Install windows7 onto iscsi target: Server Setup

A PC (IP=192.168.127.88) with ubuntu/debian installed is used as:

TFTP server

        HTTP Server

        CIFS Server

        ISCSI Server (Target)

 

TFTP server

#  Setup tftp server

apt-get install tftpd-hpa

/etc/init.d/tftpd-hpa start

 

#  Testing tftp server

apt-get install tftp

uname -a >/srv/tftp/test

tftp 127.0.0.1

>get test

>quit

diff test /srv/tftp/test

 

# Install syslinux 4.x  (SYSLINUX 4.0.1 debian-20100714)

apt-get install syslinux

cp /usr/lib/syslinux/pxelinux.0 /srv/tftp/

# copy other interested support files
cp /usr/lib/syslinux/menu.c32 /srv/tftp
cp /usr/lib/syslinux/memdisk /srv/tftp
cp /usr/lib/syslinux/mboot.c32 /srv/tftp
cp /usr/lib/syslinux/chain.c32 /srv/tftp
mkdir -pv /srv/tftp/pxelinux.cfg

To simplify the script across ubuntu and debian,  create the /tftp linkto the actual tftp root directory (/srv/tftp in case)

 

 

Install windows7 onto iscsi target: Route

A tp-link TL-841N route with ddwrt firmware (build 24160) is used in the test:

Route Config:

Route IP = 192.168.127.2

DNSMasq  = Enable

Local DNS = Enable

No DNS Rebind = Enable

Additional DNSMasq Options

dhcp-boot=pxe/pxelinux.0,lzheng-ubuntu-10,192.168.127.88
dhcp-option=44,172.24.63.201,172.24.63.202         dhcp-option=6,172.24.63.212,172.24.63.211,172.24.63.163,172.24.63.161,172.24.63.162

 

************************************************************************

Note

      dhcp-boot,               specified pxe boot file and the tftp server

dhcp-option=44,       specified wins server

dhcp-option=6,       specified upstream DNS server

Install windows7 onto iscsi target: Overview

Target:

Install windows7 from ISO file on Cifs server, onto to the iscsi target.

With the help of the following software:

   pxe/ipxe

   http

   cifs

   winpe

 

 

Test Environment:

Server:      Linux PC,  IP_Server=192.168.127.88

Including tftp/samba/iscsc server

Client:       Diskless Virtual Box on window7

Router:     DDWRT with IP_router=192.168.127.2

 

继续阅读

Economic VPS

Due to the security issue of micolog on Gogle App Engine,  I have to move the blog to VPS with WordPress.

ComfortHost low end vps is most suitable for my case, compare with several VPS I used before:

yardvps, ==> one year more, xen based, price hither

bluevm vps ==> unable to support L2TP vps

Good technology & support , reasonable cost, support OpenVPN/PPTP/L2PE on my 128M openVZ vps.(blog.zhenglei.net, UK)

Just purchase 11$/year 256M VPS (US IP) to try IP SEC on it.

http://www.comforthost.net/billing/cart.php?a=confproduct&i=0

Following:

http://www.lowendbox.com/blog/spotvps-10-99year-256mb-openvz-vps-in-4-us-locations/

 

 

 

 

Android mount sdcard

===>  execute_media_format
android/packages/apps/Settings/src/com/android/settings/MediaFormat.java

===>  mountService.formatVolume(extStoragePath);
android/frameworks/base/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java

====>  formatVolume
====>  doFormatVolume
android/frameworks/base/services/java/com/android/server/MountService.java

===> int CommandListener::VolumeCmd::runCommand
===> rc = vm->formatVolume(argv[2]);
android/system/vold/CommandListener.cpp

==> int VolumeManager::formatVolume
==> mVolumes = new VolumeCollection();
==> return v->formatVol()
android/system/vold/VolumeManager.h
android/system/vold/VolumeManager.cpp

===> int Volume::formatVol
===> Fat::format(devicePath, 0))
android/system/vold/Volume.cpp

===> int Fat::format(const char *fsPath, unsigned int numSectors)
===> static char MKDOSFS_PATH[] = “/system/bin/newfs_msdos”
android/system/vold/Fat.cpp

android/frameworks/base/services/java/com/android/server/NativeDaemonConnector.java

# C code
android/system/vold

# Launch sd formater in setting
adb shell
am start -n com.android.settings/.MediaFormat

##############################################################################

以下是打开“无线和网络设置”界面:

Intent intent = new Intent(“/”);
ComponentName cm = new ComponentName(“com.android.settings”,”com.android.settings.WirelessSettings”);
intent.setComponent(cm);
intent.setAction(“android.intent.action.VIEW”);
activity.startActivityForResult( intent , 0);

以下是可以直接打开的系统界面:

com.android.settings.AccessibilitySettings 辅助功能设置
com.android.settings.ActivityPicker 选择活动
com.android.settings.ApnSettings APN设置
com.android.settings.ApplicationSettings 应用程序设置
com.android.settings.BandMode 设置GSM/UMTS波段
com.android.settings.BatteryInfo 电池信息
com.android.settings.DateTimeSettings 日期和时间设置
com.android.settings.DateTimeSettingsSetupWizard 日期和时间设置
com.android.settings.DevelopmentSettings 应用程序设置=》开发设置
com.android.settings.DeviceAdminSettings 设备管理器
com.android.settings.DeviceInfoSettings 关于手机
com.android.settings.Display 显示——设置显示字体大小及预览
com.android.settings.DisplaySettings 显示设置
com.android.settings.DockSettings 底座设置
com.android.settings.IccLockSettings SIM卡锁定设置
com.android.settings.InstalledAppDetails 语言和键盘设置
com.android.settings.LanguageSettings 语言和键盘设置
com.android.settings.LocalePicker 选择手机语言
com.android.settings.LocalePickerInSetupWizard 选择手机语言
com.android.settings.ManageApplications 已下载(安装)软件列表
com.android.settings.MasterClear 恢复出厂设置
com.android.settings.MediaFormat 格式化手机闪存
com.android.settings.PhysicalKeyboardSettings 设置键盘
com.android.settings.PrivacySettings 隐私设置
com.android.settings.ProxySelector 代理设置
com.android.settings.RadioInfo 手机信息
com.android.settings.RunningServices 正在运行的程序(服务)
com.android.settings.SecuritySettings 位置和安全设置
com.android.settings.Settings 系统设置
com.android.settings.SettingsSafetyLegalActivity 安全信息
com.android.settings.SoundSettings 声音设置
com.android.settings.TestingSettings 测试——显示手机信息、电池信息、使用情况统计、Wifi information、服务信息
com.android.settings.TetherSettings 绑定与便携式热点
com.android.settings.TextToSpeechSettings 文字转语音设置
com.android.settings.UsageStats 使用情况统计
com.android.settings.UserDictionarySettings 用户词典
com.android.settings.VoiceInputOutputSettings 语音输入与输出设置
com.android.settings.WirelessSettings 无线和网络设置

##############################################################################
Generate SD Card Image file

#64G:
dd if=/dev/zero of=64G.img  count=0 seek=128M

#8G:
dd if=/dev/zero of=64G.img  count=0 seek=16M

#8G (with zero filled)
dd if=/dev/zero of=64G.img count=16M

##############################################################################
Loop device

#List loop devices:
losetup -a

#Add a loop device
losetup /dev/loop1 8G_zero.img

#Delete loop device
losetup -d /dev/loop1

find . -type f |xargs grep sd_format
find . -name *.java |xargs grep sd_format

###################################################################
Modify sd_format of android/packages/apps/Settings/res/values, impact on:

target R.java/Manifest.java: Settings (out/target/common/obj/APPS/Settings_intermediates/src/R.stamp)
target Java: Settings (out/target/common/obj/APPS/Settings_intermediates/classes)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Copying: out/target/common/obj/APPS/Settings_intermediates/classes-jarjar.jar
Copying: out/target/common/obj/APPS/Settings_intermediates/emma_out/lib/classes-jarjar.jar
Copying: out/target/common/obj/APPS/Settings_intermediates/classes.jar
Copying: out/target/common/obj/APPS/Settings_intermediates/noproguard.classes.jar
target Dex: Settings
Copying: out/target/common/obj/APPS/Settings_intermediates/noproguard.classes.dex
target Package: Settings (out/target/product/generic/obj/APPS/Settings_intermediates/package.apk)
‘out/target/common/obj/APPS/Settings_intermediates/classes.dex’ as ‘classes.dex’…
Processing target/product/generic/obj/APPS/Settings_intermediates/package.apk
Done!
Install: out/target/product/generic/system/app/Settings.odex
Install: out/target/product/generic/system/app/Settings.apk
Finding NOTICE files: out/target/product/generic/obj/NOTICE_FILES/hash-timestamp
Combining NOTICE files: out/target/product/generic/obj/NOTICE.html
target Java: SettingsTests (out/target/common/obj/APPS/SettingsTests_intermediates/classes)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Installed file list: out/target/product/generic/installed-files.txt
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img
Install system fs image: out/target/product/generic/system.img

******************************************************
SD FORMAT

==> StorageVolumePreferenceCategory
==> mAllowFormat = mStorageVolume != null && !mStorageVolume.isEmulated()
android/packages/apps/Settings/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java

SD Card Mount

=> “Preparing SD card”
=> “Damaged SD card”
==> ext_media_checking_notification_title
==> ext_media_unmountable_notification_title
frameworks/base/core/res/res/values/strings.xml
frameworks/base/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
===>MEDIA_UNMOUNTABLE

*****************************************************

#/system/etc/vold.fatab
#/system/etc/vold.conf

=>fatab
==>system/vold/main.cpp
===>process_config
====>VolumeManager
=====>system/vold/VolumeManager.cpp
=======>CommandListener
========>system/vold/CommandListener.cpp

********************************
FAT
===> system/vold/Fat.cpp
====> FSCK_MSDOS_PATH
=====> Fat::check
======>system/vold/Volume.cpp
=======>createDeviceNode
=========>Volume::mountVol
=========>DirectVolume::handleBlockEvent

Volume::mountVol
==> No impact on SDCard Mount, just for security fs

DirectVolume::handleBlockEvent
==>NetlinkEvent
===>system/core/include/sysutils/NetlinkEvent.h
=====>NetlinkEvent.mSubsystem==”block”, send to volume manage ==> DirectVolume::handleBlockEvent
======>NlActionAdd
========>system/core/libsysutils/src/NetlinkEvent.cpp

==========>system/core/libsysutils/src/NetlinkListener.cpp
==========>NetlinkListener::onDataAvailable

============>system/core/libsysutils/src/SocketListener.cpp
============>system/core/include/sysutils/NetlinkListener.h
============>class NetlinkListener : public SocketListener

***************************************************************************************
*** Triger of  NlActionAdd ***

“add”:
=>NetlinkEvent::parseAsciiNetlinkMessage,    system/core/libsysutils/src/NetlinkEvent.cpp
==>NetlinkEvent::decode
===>NetlinkListener::onDataAvailable,        system/core/libsysutils/src/NetlinkListener.cpp
====>SocketListener::runListener,            system/core/libsysutils/src/SocketListener.cpp
=====>SocketListener::threadStart,           system/core/libsysutils/src/SocketListener.cpp
======>SocketListener::startListener,        system/core/libsysutils/src/SocketListener.cpp
=======>main,                                system/vold/main.cpp
=======>NetlinkHandler::start,               system/vold/NetlinkHandler.cpp

*** Handle of NlActionAdd ***

“NlActionAdd”
=>DirectVolume::handleBlockEvent,            system/vold/DirectVolume.cpp
==>VolumeManager::handleBlockEvent,          system/vold/VolumeManager.cpp
==>NetlinkHandler::onEvent,                  system/vold/NetlinkHandler.cpp

**************************************************************************
Framework:   MountService

frameworks/base/services/java/com/android/server/SystemServer.java
=>public MountService(Context context),     frameworks/base/services/java/com/android/server/MountService.java
==>mContext.registerReceiver(mBroadcastReceiver, filter, null, null);
===>BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver()
====>action.equals(Intent.ACTION_BOOT_COMPLETED)
=====>if (state.equals(Environment.MEDIA_UNMOUNTED)) {
int rc = doMountVolume(path);
if (rc != StorageResultCode.OperationSucceeded) {
Slog.e(TAG, String.format(“Boot-time mount failed (%d)”,
rc));
}
======>private int doMountVolume(String path)
=======>mConnector.doCommand(String.format(“volume mount %s”, path));

==>mConnector = new NativeDaemonConnector
===>class NativeDaemonConnector,    frameworks/base/services/java/com/android/server/NativeDaemonConnector
====>public void run(),             frameworks/base/services/java/com/android/server/NativeDaemonConnector.java
=====>listenToSocket,               frameworks/base/services/java/com/android/server/NativeDaemonConnector.java
======>mCallbacks.onDaemonConnected();     (mCallbacks=MountService)
=======>onDaemonConnected()         frameworks/base/services/java/com/android/server/MountService.java

**********************************************************************************
Sd Card Mount Summary:

frameworks/base/services/java/com/android/server/MountService.java:
private int doMountVolume(String path):

Use case of doMountVolume

Case 1:  private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver()
===> Boot up SD Card mount

Case 2:  public boolean onEvent(int code, String raw, String[] cooked)
===>frameworks/base/services/java/com/android/server/NativeDaemonConnector.java
===>Callback
===>public boolean handleMessage(Message msg)
===> SD Card Insert mount

Case 3: public int mountVolume(String path)
==> packages/apps/Settings/src/com/android/settings/deviceinfo/Memory.java
==> User Setting/Mount

Case 4: public int mountVolume(String path)
===> frameworks/base/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java
===> Factory Reset