免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 14762 | 回复: 0
打印 上一主题 下一主题

[操作系统] VxWorks 7 之用户管理 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2022-04-03 21:36 |只看该作者 |倒序浏览
本帖最后由 myforever 于 2022-04-03 21:48 编辑

前言
VxWorks 7.0 整合了过往版本对用户管理的功能,通过Layer 管理系统用户,以支持Target Shell、SSH、FTP、Telnet等用户交互场景。
本文章介绍用户管理组件的配置方法和使用相关。
用户认证和管理
即:User Authentication and Management
如何配置用户认证功能?1. VSB配置
选择 USER_MANAGEMENT
并可选择性配置其下安全策略:
  • USER_MANAGEMENT_POLICY
  • USER_MANAGEMENT_USER_PRIVILEGES
  • USER_MANAGEMENT_LDAP
注意:为了降低用户管理功能失败的风险,以上3个可选项不用配置。配置后,可能会出现无法增加用户的问题。
2. VIP配置
1)通过组件 SELECT_USER_AUTHENTICATION_BACKEND 选择身份验证后端以使能用户管理,默认配置为本用户认证 INCLUDE_LOCAL_AUTH。
2)配置组件 INCLUDE_SEC_VAULT_KEP_OBFUSCATOR,第一次配置时会报错,这是因为SEC_VAULT_KEY_ENCRYPTING_PW参数未设置。此参数应配置为至少40字节长的随机字符串,示例如下:
  1. "2QEciN7Ua1StundNG8WFiOSlCUVFSUCZvrS4VlQR"
复制代码

3)增加组件INCLUDE_USER_DATABASE,设置用户数据文件路径配置参数UDB_STORAGE_PATH,存储设备应为本地非易失性存储磁盘,例如: "/mmc2a/vxLoginUsers.txt"
设置UDB_HASH_KEY:
  1. #define UDB_HASH_KEY "\x48\x61\x6d\x6c\x65\x74\x2e\x20\x54\x6f\x20\x62\x65\x2c\x20\x6f\x72\x20\x6e\x6f\x74\x20\x74\x6f\x20\x62\x65\x2d\x20\x74\x68\x61\x74\x20\x69\x73\x20\x74\x68\x65\x20\x71\x75\x65\x73\x74\x69\x6f\x6e\x3a\x0a\x57\x68\x65\x74\x68\x65\x72\x20\x27\x74\x69\x73\x20\x6e\x6f\x62\x6c\x65\x72\x20\x69\x6e\x20\x74\x68\x65\x20\x6d\x69\x6e\x64\x20\x74\x6f\x20\x73\x75\x66\x66\x65\x72\x0a\x54\x68\x65\x20\x73\x6c\x69\x6e\x67\x73\x20\x61\x6e\x64\x20\x61\x72\x72\x6f\x77\x73\x20\x6f\x66\x20\x6f\x75\x74\x72\x61\x67\x65\x6f\x75\x73\x20\x66\x6f\x72\x74\x75\x6e\x65\x0a\x4f\x72\x20\x74\x6f\x20\x74\x61\x6b\x65\x20\x61\x72\x6d\x73\x20\x61\x67\x61\x69\x6e\x73\x74\x20\x61\x20\x73\x65\x61\x20\x6f\x66\x20\x74\x72\x6f\x75\x62\x6c\x65\x73\x2c\x0a\x41\x6e\x64\x20\x62\x79\x20\x6f\x70\x70\x6f\x73\x69\x6e\x67\x20\x65\x6e\x64\x20\x74\x68\x65\x6d\x2e\x20\x54\x6f\x20\x64\x69\x65\x2d\x20\x74\x6f\x20\x73\x6c\x65\x65\x70\x2d\x0a\x4e\x6f\x20\x6d\x6f\x72\x65\x3b\x20\x61\x6e\x64\x20\x62\x79\x20\x61\x20\x73\x6c\x65\x65\x70\x20\x74\x6f\x20\x73\x61\x79\x20\x77"
复制代码


3. 运行时配置
目标板启动后,本地命令行下增加/注册新用户:


  1. -> userAdd "user","password"
  2. -> udbInfoShow
  3. User database:
  4. - storage path: /mmc2:1/vxLoginUsers.txt
  5. - version: 3
  6. - number of records: 2
  7. value = 0 = 0x0
复制代码


远程telnet、rlogin登录目标板时,要求输入用户名和密码,使用已注册的用户登录即可。
4. FTP server 认证配置
增加用户管理功能后,FTP server也要求用户认证。设置FTPS_AUTH_CALLBACK_HOOK,实现响应的回调函数。示例如下:

  1. int ipftps_authenticate_ccu(Ipftps_session *session, char *password)
  2. {
  3. int retVal = 0;

  4. if (systemSecurityIsEnabled == FALSE)
  5. {
  6. if (ipcom_strcmp(session->username, "anonymous") == 0)
  7. {
  8. session->readonly = 1;
  9. }
  10. }
  11. else if ((ipcom_strcmp(session->username, "ccu_ftp") != 0) \
  12. || (ipcom_strcmp(password, "vxworks") != 0))
  13. {
  14. printf("Invalid FTP user or password!\n");
  15. retVal = 1;
  16. }

  17. return retVal;
  18. }
复制代码

5. SSH 配置
VxWorks 7 支持 ssh server和 ssh client。
1)Configure VIP for Key Store and Key Commands 设置 SEC_VAULT_FILE_ROOT为本地存储设备,例如,"/mmc2a",用于保存key 文件。 包含以下组件:
  • INCLUDE_SEC_KEY_STORE_CMD for the keyStore management commands.
  • INCLUDE_GENRSA_CMD for the OpenSSL genrsa command.
  • INCLUDE_GENDSA_CMD for the OpenSSL gendsa command.
  • INCLUDE_DSAPARAM_CMD for the OpenSSL dsaparam command.
2)Configure VIP for User Database
1. Add the INCLUDE_USER_IDENTIFICATION component. This component provides support for creating and deleting user accounts, for updating passwords, and so on.
2. Optionally, change the configuration parameters DEFAULT_PRIMARY_GROUP_ID and VXWORKS_LOGIN_PROMPT.
3. Add INCLUDE_USER_DATABASE.
4. Set UDB_STORAGE_PATH to a location and file name for the user database. For example, with VxSim and the host file system, you could use "host:C:/tmp/myUserDb.txt".
5. Set the secret hash key that will be used for computing the HMAC with the UDB_HASH_KEY parameter. The hash key should have a minimum of 256 random bits (40 ASCII characters), encoded in \xnn format, where nn can vary from 00 to ff. The longer the hash key, the higher the quality of cryptographic hashing. For example, the following could be assigned to UDB_HASH_KEY (without line breaks): "\x48\x61\x6d\x6c\x65\x74\x2e\x20\x54\x6f\x20\x62\x65\x2c\x20\x6f\x72\x20\x6e\x6f\x74\x20\x74\x6f\x20\x62\x65\x2d\x20\x74\x68\x61\x74\x20\x69\x73\x20\x74\x68\x65"
6. Set the UDB_HASH_KEY_LEN parameter, or use the default value of 256 (the minimum value).
7. Add components for file system storage, and code for file system initialization at boot time.
8. Add INCLUDE_DISK_UTIL for the standard set of file system utilities (cd, copy, ll, mkdir, and so on).
9. Build your VIP.
3)Generate RSA and DSA Keys and Add to Key Store
1. Boot your target system with VxWorks.
2.Change to the command interpreter and use genrsa to create the RSA key file.



  1. ->cmd
  2. [vxWorks *]# cd /mmc2a
  3. [vxWorks *]# genrsa -out default_rsa.pem 2048
复制代码


The file default_rsa.pem is created in the current directory.
3. Use dsaparam to generate the DSA parameters.


  1. [vxWorks *]# dsaparam -out dsaparam.pem 2048
复制代码


4. Use gendsa to generate a DSA key.
  1. gendsa -out default_dsa.pem dsaparam.pem
复制代码


5. Use the keystore import command to add the keys to the key store.

  1. [vxWorks *]# keyStore import default_rsa default_rsa.pem
  2. [vxWorks *]# keyStore import default_dsa default_dsa.pem
  3. [vxWorks *]# ls keys/
  4. keys/.
  5. keys/..
  6. keys/default_rsa
  7. keys/default_dsa
复制代码

4)启动目标板,运行时,可能会打印以下信息:


  1. ipssh_load_dsa_key :: failed to get key_id default_dsa
  2. Thu Jan 1 00:00:00 1970: ipssh[203bf300]: Error: ipssh_get_srv_config :: ipssh_load_dsa_key_cb() failed
  3. Thu Jan 1 00:00:00 1970: ipssh[203bf300]: Error: ipssh :: ipssh_get_srv_config() failed
  4. Thu Jan 1 00:00:00 1970: ipcom[20342010]: Crit: ipcom_create_ipproduct :: failed to start 'ipssh', err = -1000
复制代码


这是由于ssh server启动时,相关存储设备文件系统还没加载完成。
不过没关系,在命令行执行或者程序调用 ipssh_start() 即可 ,重新启动ssh 服务即可。
5)远程ssh登录目标板,使用已经创建的用户信息。
6. User Database (UDB) 延时启动
通常来说,本地存储设备挂载文件系统,要在系统启动完成后一段时间内才完成,约2秒钟。而user database 文件要求存储到本地存储设备,系统启动时运行UDB初始化,此时用户信息并不可用。
可使用组件参数UDB_DELAY_INITIALIZATION配置UDB延时初始化,即有用户自定义初始化时刻。
实现以下代码片段, 可在usrAppInit文件中等待本地存储设备文件系统加载完成以后调用:


  1. #if (UDB_DELAY_INITIALIZATION == TRUE)
  2. #include "udbMgr.h"

  3. IMPORT void udbCustomTamperingPolicyHdlr (UDB_EVENT_INFO event);
  4. extern void usrUdbMgrInit
  5. (
  6. char * storagePath,
  7. const char * key,
  8. int keyLen,
  9. UDB_TAMPER_POLICY_RTN customHdlr,
  10. BOOL promptInitialUser,
  11. BOOL delayedInitialization
  12. );
  13. #endif

  14. #if (UDB_DELAY_INITIALIZATION == TRUE)
  15. usrUdbMgrInit (UDB_STORAGE_PATH, UDB_HASH_KEY, UDB_HASH_KEY_LEN, UDB_CUSTOM_TAMPERING_POLICY_RTN, UDB_PROMPT_INITIAL_USER,0);
  16. #endif
复制代码


7. Security Shell
本地shell可配置用户登录安全模式,即使用UDB注册的用户信息登录,否则shell不可用。
增加组件 INCLUDE_SHELL_SECURITY 即可配置安全模式。
配置安全模式,会引入问题:在系统启动阶段,UDB不可用,将会导致security shell加载失败,即使系统运行一段时间后,也无法登录。解决办法如下:
  • 1)配置UDB延时初始化,即UDB_DELAY_INITIALIZATION为TRUE;
  • 2)问题解决。
注释:
即使配置了security shell,在usrAppInit中调用用户脚本文件不受安全配置的影响,使用usrStartupScript()加载脚本文件即可。

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP