| | |
| | | #include "pc-identifiers.h" |
| | | #include <stdlib.h> |
| | | #include <stdbool.h> |
| | | #include "base/base64.h" |
| | | |
| | | static FUNCTION_RETURN generate_default_pc_id(PcIdentifier * identifiers, |
| | | unsigned int * num_identifiers) { |
| | |
| | | for (i = 0; i < disk_num; i++) { |
| | | for (j = 0; j < adapter_num; i++) { |
| | | for (k = 0; k < 6; k++) |
| | | identifiers[i * adapter_num + j][k] = diskInfos[i].disk_sn[k |
| | | + 2] ^ adapterInfos[j].mac_address[k + 2]; |
| | | identifiers[i * adapter_num + j][k] = |
| | | diskInfos[i].disk_sn[k + 2] |
| | | ^ adapterInfos[j].mac_address[k + 2]; |
| | | } |
| | | } |
| | | |
| | |
| | | result = generate_default_pc_id(identifiers, array_size); |
| | | break; |
| | | case ETHERNET: |
| | | result = generate_ethernet_pc_id(identifiers, array_size, false); |
| | | result = generate_ethernet_pc_id(identifiers, array_size, true); |
| | | break; |
| | | case IP_ADDRESS: |
| | | result = generate_ethernet_pc_id(identifiers, array_size, false); |
| | |
| | | result = generate_disk_pc_id(identifiers, array_size, false); |
| | | break; |
| | | case DISK_LABEL: |
| | | result = generate_disk_pc_id(identifiers, array_size, false); |
| | | result = generate_disk_pc_id(identifiers, array_size, true); |
| | | break; |
| | | default: |
| | | return ERROR; |
| | |
| | | * @param str_code: the code in the string format XXXX-XXXX-XXXX-XXXX |
| | | * @return |
| | | */ |
| | | int decode_pc_id(PcIdentifier* identifier1_out, PcIdentifier* identifier2_out, |
| | | UserPcIdentifier str_code) { |
| | | static FUNCTION_RETURN decode_pc_id(PcIdentifier* identifier1_out, |
| | | PcIdentifier* identifier2_out, UserPcIdentifier str_code) { |
| | | |
| | | } |
| | | |
| | | static IDENTIFICATION_STRATEGY strategy_from_pc_id(PcIdentifier identifier) { |
| | | return (IDENTIFICATION_STRATEGY) identifier[0] >> 5; |
| | | } |
| | | |
| | | EVENT_TYPE validate_user_pc_identifier(UserPcIdentifier str_code) { |
| | | PcIdentifier user_identifiers[2]; |
| | | FUNCTION_RETURN result; |
| | | IDENTIFICATION_STRATEGY previous_strategy_id, current_strategy_id; |
| | | PcIdentifier* calculated_identifiers; |
| | | size_t calc_identifiers_size; |
| | | int i, j; |
| | | bool found; |
| | | |
| | | result = decode_pc_id(&user_identifiers[0], &user_identifiers[1], str_code); |
| | | if (result != OK) { |
| | | return result; |
| | | } |
| | | previous_strategy_id = STRATEGY_UNKNOWN; |
| | | found = false; |
| | | for (i = 0; i < 2; i++) { |
| | | current_strategy_id = strategy_from_pc_id(user_identifiers[i]); |
| | | if (current_strategy_id == STRATEGY_UNKNOWN) { |
| | | return LICENSE_MALFORMED; |
| | | } |
| | | if (current_strategy_id != previous_strategy_id) { |
| | | if (calculated_identifiers != NULL) { |
| | | free(calculated_identifiers); |
| | | } |
| | | current_strategy_id = previous_strategy_id; |
| | | generate_pc_id(NULL, &calc_identifiers_size, current_strategy_id); |
| | | calculated_identifiers = (PcIdentifier *) malloc( |
| | | sizeof(PcIdentifier) * calc_identifiers_size); |
| | | generate_pc_id(calculated_identifiers, &calc_identifiers_size, |
| | | current_strategy_id); |
| | | } |
| | | //maybe skip the byte 0 |
| | | for (j = 0; j < calc_identifiers_size; j++) { |
| | | if (!memcmp(user_identifiers[i], calculated_identifiers[j], |
| | | sizeof(PcIdentifier))) { |
| | | free(calculated_identifiers); |
| | | return LICENSE_OK; |
| | | } |
| | | } |
| | | } |
| | | free(calculated_identifiers); |
| | | return IDENTIFIERS_MISMATCH; |
| | | } |