General NAS-Central Forums

Welcome to the NAS community
It is currently Fri Jul 30, 2010 4:59 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: check_key
PostPosted: Tue Jun 24, 2008 7:28 pm 
Offline

Joined: Mon Jun 16, 2008 10:45 am
Posts: 344
In /etc/init.d/rcS there is this scriptlet:
Code:
any_usb=`sg_map -x -i|grep -v " 0 0 0 0"|grep -v " 1 0 0 0"|awk '{print $7}'`
echo "${any_usb}"
if [ -n "${any_usb}" ]; then
        for usb in ${any_usb}
        do
                mount "${usb}"1 /mnt
                /sbin/check_key /mnt/nsa220_check_file
                if [ $? == 0 ] ; then
                        /mnt/usb_key_func.sh
                        test $? -eq 0 && exit 0
                fi
                umount /mnt
        done
fi
When /sbin/check_key returns 0, the script usb_key_func.sh on the root of an usb stick is executed on boot. I downloaded the sources on ftp://opensource.zyxel.com (btw, the mirror on http://gpl.nas-central.org/ZYXEL/NSA220_GPL/ seems to be corrupt) to find out what check_key does. Unfortunately the only reference I could find is in nsa220build/nsa220/Makefile:
Code:
# Makefile for NSA-220

# system tools
CP=/bin/cp -rfl
RM=/bin/rm
FIND=/usr/bin/find
MKDIR=mkdir
MODEL=NSA220

# toolchain path
export PATH=/opt/montavista/pro/devkit/arm/v5t_le/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:${HOME}/bin

export CROSS=arm_v5t_le-

export CROSS_CC=${CROSS}gcc
export CROSS_CXX=${CROSS}cpp
export CROSS_AR=${CROSS}ar
export CROSS_LD=${CROSS}ld
export CROSS_RANLIB=${CROSS}ranlib
export CROSS_STRIP=${CROSS}strip

export HOST_CC=gcc

# for configure --build=$PLATFORM_BUILD --host=$PLATFORM_HOST
export PLATFORM_BUILD=i386-linux
export PLATFORM_HOST=arm-linux
export PLATFORM_TARGET=arm-linux
export PLATFORM_PREFIX=/opt/montavista/pro/devkit/arm/v5t_le/target

# path for build
export PRODUCT_ROOT=${PWD}
export SYSAPPS_PATH=${PRODUCT_ROOT}/sysapps
export DEST_PATH=${PRODUCT_ROOT}/build/apptarget
export RAS_PATH=${PRODUCT_ROOT}/build/fs

# the kernel from MontaVista. Some special header files and definitions are here.
export MV_KERNEL_PATH=/opt/montavista/pro/devkit/lsp/arm-versatile926ejs-arm_v5t_le/linux-2.6.10_mv1401

# the kernel for system
kversion=2.6.18.6
ifeq ($(kernel), 2.6.12)
kversion=2.6.12.6-1.10.3
else
kernel=2.6.18
endif
export KERNEL_PATH=${PRODUCT_ROOT}/linux-${kversion}

# specify root file system
# Allowable value: ext2, squash
rfs=squash
ifeq ($(rootfs), ext2)
rfs=ext2
endif

# native target path which contains a native environment
export TARGET_PATH=/opt/montavista/pro/devkit/arm/v5t_le/target

.PHONY: help

help:
   @echo "make          - Thi help menu."
   @echo ""
   @echo "make all - Build everything and create RAS image file."
   @echo ""
   @echo "make world [kernel=] - Build everything."
   @echo ""
#   @echo "make clean       - Clean all object files; this is not available now."
#   @echo ""
   @echo "make buildkernel [kernel=] - Build kernel image."
   @echo ""
   @echo "make <package>       - Build the package."
   @echo "      package list : busybox samba zysh nduagent uam fauthd mlogin ntpdate"
   @echo "                     syslog-ng libzyboot"
   @echo "                     zysh-cgi file_export file_upload file_download"
   @echo "                     htp lm-sensors btnd backdoor mtd-util check_key"
   @echo ""
   @echo "make ras [kernel=] [rootfs=] - Create RAS image file."
   @echo "                     Make sure you already make world."
   @echo ""
   @echo "[kernel=] : "
   @echo "      to specify kernel version, by using kernel=kernel_version, "
   @echo "      default is 2.6.18, allowable value are 2.6.18, 2.6.12"
   @echo "      e.g."
   @echo "      make buildkernel kernel=2.6.12, build kernel 2.6.12.6-1.10.3"
   @echo "      make ras , build kernel 2.6.18.6"
   @echo "[rootfs=]: "
   @echo "      to specify root file system type"
   @echo "      default is squash, allowable value are squash, ext2"
   @echo "      e.g."
   @echo "      make ras rootfs=ext2 to make EXT2 root file system"
   @echo "Some environment variables:"
   @echo "  CROSS_CC=${CROSS_CC}"
   @echo "  DEST_PATH=${DEST_PATH}"
   @echo "  RAS_PATH=${RAS_PATH}"


world: prebuild buildkernel busybox dev
   @echo "==> The end of the world!"

clean: kernel.clean busybox.clean

prebuild:
   @echo "==> $@"
   ${MKDIR} -p ${RAS_PATH}
   ${RM} -rf ${RAS_PATH}/*
   ${CP} --preserve=all ${PRODUCT_ROOT}/basicfs/* ${RAS_PATH}
   ${CP} --preserve=all ${PRODUCT_ROOT}/basicfs/.mtoolsrc ${RAS_PATH}
   ${FIND} ${RAS_PATH} -name .svn | xargs rm -rf
   chmod 777 ${RAS_PATH}/tmp
   chmod 777 ${RAS_PATH}/tmp/users/home
   chmod 777 ${RAS_PATH}/tmp/users/shares

   @echo "==> Clear tmporary build dir"
   ${RM} -rf ${DEST_PATH}/bin/*
   ${RM} -rf ${DEST_PATH}/sbin/*
   ${RM} -rf ${DEST_PATH}/usr/bin/*
   ${RM} -rf ${DEST_PATH}/usr/sbin/*
   ${RM} -rf ${DEST_PATH}/lib/*
   ${RM} -rf ${DEST_PATH}/usr/lib/*
   ${RM} -rf ${DEST_PATH}/usr/include/*
   ${RM} -rf ${DEST_PATH}/util/*
   ${RM} -rf ${DEST_PATH}/root/*


ras:
   @echo "==> $@"
   ${RM} -rf ${RAS_PATH}/lib/modules
   ${RM} -rf ${RAS_PATH}/lib/modules_kernel_2.6.12
ifeq ($(kernel), 2.6.12)
   ${CP} --preserve=all ${PRODUCT_ROOT}/basicfs/lib/modules_kernel_2.6.12 ${RAS_PATH}/lib/modules
else
   ${CP} --preserve=all ${PRODUCT_ROOT}/basicfs/lib/modules ${RAS_PATH}/lib/modules
endif
   ${FIND} ${RAS_PATH} -name .svn | xargs rm -rf
   cd build ; ./makeras.sh -k ${kernel} -f ${rfs} -b "${beta_ver}" -c "${fcs_ver}"

buildkernel:
   @echo "==> $@, Kernel version is ${kernel}"
   make -C ${KERNEL_PATH} zImage
   ${CP} --remove-destination ${KERNEL_PATH}/arch/arm/boot/zImage ${PRODUCT_ROOT}/build

all: world ras
    @echo "==> The end of the all!"

kernel.clean:
   @echo "==> $@"
   make -C ${KERNEL_PATH} clean

busybox:
   @echo "==> $@"
   cd ${SYSAPPS_PATH}/busybox-1.1.1 ; make install
   chmod +s ${RAS_PATH}/bin/busybox

busybox.clean:
   @echo "==> $@"
   cd ${SYSAPPS_PATH}/busybox-1.1.1 ; make clean
   # DO NOT make distclean

dev:
   @echo "==> $@"
   ./makedev.sh
In section help is mentioned that you can 'make check_key'. Can anybody tell me what this file does when you run 'make check_key'?

Another possibly related thing I found: In nsa220build/nsa220/build/zytools/USB_KEY there is a tree:
nsa220_check_file
nsa220/function/usb_key_func.sh
nsa220/function/run_htp_external
nsa220/upgrade/usb_key_func.sh
nsa220/upgrade/ras.bin
nsa220/upgrade/Upgrade

the contents of nsa220_check_file:
Code:
/mnt/nsa220/upgrade/usb_key_func.sh
/mnt/nsa220/upgrade/ras.bin
/mnt/nsa220/upgrade/Upgrade
The contents of Upgrade and run_htp_external looks like an MD5 checksum, but if so I couldn't find out from what. ras.bin seems to be a complete firmware binary (15MB).


Top
 Profile  
 
 Post subject: Re: check_key
PostPosted: Thu Jun 26, 2008 5:29 pm 
Offline

Joined: Thu Mar 06, 2008 12:23 pm
Posts: 58
Location: Vienna
info: updated the gpl sources at http://gpl.nas-central.org/ZYXEL/NSA220 ... .10AFB0C0/

EDIT: downloads are broken again. seems as if zyxel does not allow many concurrent connections. thats exactly the reason why a mirror makes sense btw.


Top
 Profile  
 
 Post subject: Re: check_key
PostPosted: Thu Jul 17, 2008 9:34 am 
Offline

Joined: Mon Jun 16, 2008 10:45 am
Posts: 344
I have found what '/sbin/check_key /mnt/nsa220_check_file' does. nsa220_check_file can be a textfile containing 2 or 3 lines, each containing a filename. Let's say those files are line1 and line2. In that case '/sbin/check_key /mnt/nsa220_check_file' does:
Code:
cp line1 /mnt/usb_key_func.sh
cat /etc/Zy_Private line1 | md5sum -c line2

The contents of /etc/ZyPrivate is 52103jeenajevol8290i\n, in hex: 35323130336A65656E616A65766F6C38323930690A.

When nsa220_check_file contains 3 lines, eg line1, line2 and line3:
Code:
cp line1 /mnt/usb_key_func.sh
cp line2 /mnt/ras.bin
cat /etc/Zy_Private line1 /mnt/ras.bin | md5sum -c line3

A bit inconsequent, I know. A bit inefficient too. The 3 line version seems to be designed to flash new firmware in the device. In that case /mnt/ras.bin is a 14 MB file, which is only copied to add a static filename to the cat command?

I've written some more information plus a sample in this thread.

I tried to add an attachment, but it seems impossible to upload an attachment which is not a picture.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group