예제 #1
0
파일: license.c 프로젝트: inevity/ebgn
EC_BOOL lic_cfg_make(LIC_CFG *lic_cfg, const char *mac_str,
                            const char *start_date_str, const char *end_date_str,
                            const char *user_name_str, const char *user_email_str)
{
    if(EC_FALSE == lic_mac_make(LIC_CFG_MAC(lic_cfg), mac_str))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_make: make mac from %s failed\n", mac_str);
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_date_make(LIC_CFG_DATE(lic_cfg), start_date_str, end_date_str))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_make: make date from start date %s to end date %s failed\n", start_date_str, end_date_str);
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_chars_make(LIC_CFG_USER_NAME(lic_cfg), LIC_USER_NAME_MAX_SIZE, user_name_str))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_make: make user name from %s failed\n", user_name_str);
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_chars_make(LIC_CFG_USER_EMAIL(lic_cfg), LIC_USER_EMAIL_MAX_SIZE, user_email_str))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_make: make user email from %s failed\n", user_name_str);
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_chars_make(LIC_CFG_VENDOR_NAME(lic_cfg), LIC_VENDOR_NAME_MAX_SIZE, g_lic_vendor_name))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_make: make vendor name from %s failed\n", g_lic_vendor_name);
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_chars_make(LIC_CFG_VENDOR_EMAIL(lic_cfg), LIC_VENDOR_EMAIL_MAX_SIZE, g_lic_vendor_email))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_make: make vendor email from %s failed\n", g_lic_vendor_email);
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_chars_make(LIC_CFG_VERSION(lic_cfg), LIC_VERSION_MAX_SIZE, g_lic_version))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_make: make software version from %s failed\n", g_lic_version);
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_prikey_make(LIC_CFG_PRIVATE_KEY(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_make: make private key failed\n");
        return (EC_FALSE);
    }

    return (EC_TRUE);
}
예제 #2
0
파일: license.c 프로젝트: inevity/ebgn
EC_BOOL lic_cfg_init(LIC_CFG *lic_cfg)
{
    lic_chars_init(LIC_CFG_VERSION(lic_cfg)     , LIC_VERSION_MAX_SIZE);
    lic_mac_init(LIC_CFG_MAC(lic_cfg));

    lic_date_init(LIC_CFG_DATE(lic_cfg));

    lic_chars_init(LIC_CFG_USER_NAME(lic_cfg)   , LIC_USER_NAME_MAX_SIZE);
    lic_chars_init(LIC_CFG_USER_EMAIL(lic_cfg)  , LIC_USER_EMAIL_MAX_SIZE);
    lic_chars_init(LIC_CFG_VENDOR_NAME(lic_cfg) , LIC_VENDOR_NAME_MAX_SIZE);
    lic_chars_init(LIC_CFG_VENDOR_EMAIL(lic_cfg), LIC_VENDOR_EMAIL_MAX_SIZE);

    return (EC_TRUE);
}
예제 #3
0
파일: license.c 프로젝트: inevity/ebgn
void lic_cfg_print(LOG *log, const LIC_CFG *lic_cfg)
{
    sys_log(log, "version     : %s\n", LIC_CFG_VERSION(lic_cfg));
    lic_mac_print(log, LIC_CFG_MAC(lic_cfg));
    lic_date_print(log, LIC_CFG_DATE(lic_cfg));
    sys_log(log, "user name   : %s\n", LIC_CFG_USER_NAME(lic_cfg));
    sys_log(log, "user email  : %s\n", LIC_CFG_USER_EMAIL(lic_cfg));

    sys_log(log, "vendor name : %s\n", LIC_CFG_VENDOR_NAME(lic_cfg));
    sys_log(log, "vendor email: %s\n", LIC_CFG_VENDOR_EMAIL(lic_cfg));

    lic_prikey_print(log, LIC_CFG_PRIVATE_KEY(lic_cfg));
    lic_signature_print(log, LIC_CFG_SIGNATURE(lic_cfg));
    return;
}
예제 #4
0
파일: license.c 프로젝트: inevity/ebgn
EC_BOOL lic_check()
{
    LIC_CFG lic_cfg;

    struct tm *cur_time;

    UINT32 year;
    UINT32 month;
    UINT32 day;

    LIC_DATE   *lic_date;

    int fd;

    lic_cfg_init(&lic_cfg);

    fd = c_file_open(g_lic_file_name, O_RDONLY, 0666);
    if(-1 == fd)
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_check: open license file %s failed\n", g_lic_file_name);
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_cfg_load(fd, &lic_cfg))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_check: load license file %s failed\n", g_lic_file_name);
        close(fd);
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    /*check signature*/
    if(EC_FALSE == lic_cfg_verify(&lic_cfg))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_check: verify signature failed\n");
        close(fd);
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    close(fd);

    /*check mac addr*/
    if(EC_FALSE == lic_mac_verify(LIC_CFG_MAC(&lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_check: verify mac addr failed\n");
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    /*check version*/
    if(EC_FALSE == lic_version_verify((char *)LIC_CFG_VERSION(&lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_check: verify version failed\n");
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    /*check vendor*/
    if(EC_FALSE == lic_vendor_verify((char *)LIC_CFG_VENDOR_NAME(&lic_cfg), (char *)LIC_CFG_VENDOR_EMAIL(&lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_check: verify vendor failed\n");
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    /*check expiration*/
    cur_time = c_localtime_r(NULL_PTR);

    year  = cur_time->tm_year + 1900;
    month = cur_time->tm_mon + 1;
    day   = cur_time->tm_mday;

    lic_date = LIC_CFG_DATE(&lic_cfg);

    if(LIC_DATE_END_YEAR(lic_date) > year)
    {
        lic_cfg_clean(&lic_cfg);
        return (EC_TRUE);
    }

    if(LIC_DATE_END_YEAR(lic_date) < year)
    {
        dbg_log(SEC_0060_LICENSE, 1)(LOGSTDOUT, "warn:lic_check: license is expired\n");
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    /*now year == end year*/
    if(LIC_DATE_END_MONTH(lic_date) > month)
    {
        lic_cfg_clean(&lic_cfg);
        return (EC_TRUE);
    }

    if(LIC_DATE_END_MONTH(lic_date) < month)
    {
        dbg_log(SEC_0060_LICENSE, 1)(LOGSTDOUT, "warn:lic_check: license is expired\n");
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    /*now month == end month*/
    if(LIC_DATE_END_DAY(lic_date) < day)
    {
        dbg_log(SEC_0060_LICENSE, 1)(LOGSTDOUT, "warn:lic_check: license is expired\n");
        lic_cfg_clean(&lic_cfg);
        return (EC_FALSE);
    }

    if(LIC_DATE_END_DAY(lic_date) < day + 15)
    {
        dbg_log(SEC_0060_LICENSE, 1)(LOGSTDOUT, "warn:lic_check: license will be expired in %ld days. please contact %s/%s to renew.\n",
                            LIC_DATE_END_DAY(lic_date) - day,
                            g_lic_vendor_name, g_lic_vendor_email);
    }

    lic_cfg_clean(&lic_cfg);
    return (EC_TRUE);
}
예제 #5
0
파일: license.c 프로젝트: inevity/ebgn
EC_BOOL lic_cfg_flush(int fd, const LIC_CFG *lic_cfg)
{
    UINT32 offset;

    offset = 0;

    if(EC_FALSE == lic_buff_flush(fd, &offset, LIC_VERSION_MAX_SIZE, LIC_CFG_VERSION(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush version failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_flush(fd, &offset, sizeof(LIC_MAC), (UINT8 *)LIC_CFG_MAC(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush mac failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_flush(fd, &offset, sizeof(LIC_DATE), (UINT8 *)LIC_CFG_DATE(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush date failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_flush(fd, &offset, LIC_USER_NAME_MAX_SIZE, LIC_CFG_USER_NAME(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush user name failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_flush(fd, &offset, LIC_USER_EMAIL_MAX_SIZE, LIC_CFG_USER_EMAIL(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush user email failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_flush(fd, &offset, LIC_VENDOR_NAME_MAX_SIZE, LIC_CFG_VENDOR_NAME(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush vendor name failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_flush(fd, &offset, LIC_VENDOR_EMAIL_MAX_SIZE, LIC_CFG_VENDOR_EMAIL(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush vendor email failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_flush(fd, &offset, sizeof(BIGINT), (UINT8 *)LIC_CFG_PRIVATE_KEY(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush private key failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_flush(fd, &offset, sizeof(ECC_SIGNATURE), (UINT8 *)LIC_CFG_SIGNATURE(lic_cfg)))
    {
        dbg_log(SEC_0060_LICENSE, 0)(LOGSTDOUT, "error:lic_cfg_flush: flush signature failed\n");
        return (EC_FALSE);
    }

    return (EC_TRUE);
}
예제 #6
0
파일: license.c 프로젝트: okayman/ebgn
EC_BOOL lic_cfg_load(int fd, LIC_CFG *lic_cfg)
{
    UINT32 offset;

    offset = 0;

    if(EC_FALSE == lic_buff_load(fd, &offset, LIC_VERSION_MAX_SIZE, LIC_CFG_VERSION(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load version failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_load(fd, &offset, sizeof(LIC_MAC), (UINT8 *)LIC_CFG_MAC(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load mac failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_load(fd, &offset, sizeof(LIC_DATE), (UINT8 *)LIC_CFG_DATE(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load date failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_load(fd, &offset, LIC_USER_NAME_MAX_SIZE, LIC_CFG_USER_NAME(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load user name failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_load(fd, &offset, LIC_USER_EMAIL_MAX_SIZE, LIC_CFG_USER_EMAIL(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load user email failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_load(fd, &offset, LIC_VENDOR_NAME_MAX_SIZE, LIC_CFG_VENDOR_NAME(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load vendor name failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_load(fd, &offset, LIC_VENDOR_EMAIL_MAX_SIZE, LIC_CFG_VENDOR_EMAIL(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load vendor email failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_load(fd, &offset, sizeof(BIGINT), (UINT8 *)LIC_CFG_PRIVATE_KEY(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load private key failed\n");
        return (EC_FALSE);
    }

    if(EC_FALSE == lic_buff_load(fd, &offset, sizeof(ECC_SIGNATURE), (UINT8 *)LIC_CFG_SIGNATURE(lic_cfg)))
    {
        sys_log(LOGSTDOUT, "error:lic_cfg_load: load signature failed\n");
        return (EC_FALSE);
    }

    return (EC_TRUE);
}