鲲鹏社区首页
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

密码应用开发的接口调用

接口调用demo演示

  1. 下载本模块的接口头文件。
    git clone https://gitee.com/openeuler/itrustee_sdk.git
  2. 在代码中引用sdf.h头文件,即可进行应用开发,以获取设备信息为例。
    vim test_sdf.c

    创建test_sdf.c源文件,添加如下内容。

    #include <stdio.h>
    #include "sdf.h"
    
    int main()
    {
        int ret = -1;
        void *hDeviceHandle = NULL;
        void *hSessionHandle = NULL;
        DEVICEINFO info = {0};
        ret = SDF_OpenDevice(&hDeviceHandle);
        if (ret != SDR_OK) {
            printf("sdf open device failed, ret = 0x%x\n", ret);
            return ret;
        }
        ret = SDF_OpenSession(hDeviceHandle, &hSessionHandle);
        if (ret != SDR_OK) {
            printf("sdf open session failed, ret = 0x%x\n", ret);
            return ret;
        }
        printf("sdf open device and session success\n");
        ret = SDF_GetDeviceInfo(hSessionHandle, &info);
        if (ret != SDR_OK) {
            printf("sdf get device info failed, ret = 0x%x\n", ret);
            return ret;
        }
        printf("sdf get device info success\n");
        printf("Device Name: %s\n", info.DeviceName);
        return 0;
    }
  3. 完毕后可参考如下命令编译:
    gcc test_sdf.c -lsdf -ldl  -I/path/to/itrustee_sdk/include/SDF/ -o test_sdf
  4. 执行应用,可成功打印设备名字。

容器内应用部署

普通容器使能商密应用,只需将部分设备文件映射到容器里,以及将libsdf.so集成容器里即可。

  1. 参考TrustZone特性指南中升级TEE OS章节,升级CCOS。
  2. 启动容器。
    1
    2
    docker run -it --mount type=bind,source=/var/itrustee/teecd,target=/var/itrustee/teecd,readonly --device /dev/teelog:/dev/teelog:wr --device /dev/tc_ns_cvm:/dev/tc_ns_cvm:wr -d <demo_image>
    docker logs -f <container_id>
    
    • 要使能容器支持运行密码模块,需将如下设备映射到容器内。
      • --mount type=bind,source=/var/itrustee/teecd,target=/var/itrustee/teecd,readonly
      • --device /dev/teelog:/dev/teelog:wr
      • --device /dev/tc_ns_cvm:/dev/tc_ns_cvm:wr
    • 其中demo_image为客户容器镜像,例如选择最基本的openEuler容器镜像。
  3. 拷贝必要的文件到容器内。
    docker cp /lib64/libsdf.so <container_id>:/lib64/
    docker cp /lib64/libteec.so <container_id>:/lib64/
    docker cp /lib64/libboundscheck.so <container_id>:/lib64/
    docker cp /bin/tlogcat <container_id>:/bin/
  4. 容器内即可运行密码模块应用,与host侧运行无异。