void parcJSONValue_Display(const PARCJSONValue *value, int indentation) { parcDisplayIndented_PrintLine(indentation, "PARCJSONValue@%p {", value); if (value != NULL) { parcDisplayIndented_PrintLine(indentation + 1, ".type=%d", value->type); switch (value->type) { case PARCJSONValueType_Boolean: _displayBoolean(value, indentation + 1); break; case PARCJSONValueType_String: parcBuffer_Display(value->value.string, indentation + 1); break; case PARCJSONValueType_Number: _displayNumber(value, indentation + 1); break; case PARCJSONValueType_Array: parcJSONArray_Display(value->value.array, indentation + 1); break; case PARCJSONValueType_JSON: parcJSON_Display(value->value.object, indentation + 1); break; case PARCJSONValueType_Null: parcDisplayIndented_PrintLine(indentation + 1, ".value=null"); break; default: trapIllegalValue(value->type, "Unknown PARCJSONValue type %d", value->type); } } parcDisplayIndented_PrintLine(indentation, "}"); }
/** * Create a PKCS12 signing context for use in ccnx_Signing from the provided key. It is destroyed * by parc_Signing when the signing context is destroyed. * * Example: * @code * <#example#> * @endcode */ PARCSigningInterface * parcSymmetricSignerFileStore_Create(PARCBuffer *secret_key, PARCCryptoHashType hmacHashType) { _PARCAesSignerFileStore *keystore = parcMemory_AllocateAndClear(sizeof(_PARCAesSignerFileStore)); assertNotNull(keystore, "parcMemory_AllocateAndClear(%zu) returned NULL, cannot allocate keystore", sizeof(_PARCAesSignerFileStore)); keystore->hashType = hmacHashType; switch (hmacHashType) { case PARC_HASH_SHA256: keystore->hashLength = SHA256_DIGEST_LENGTH; keystore->opensslMd = EVP_sha256(); break; case PARC_HASH_SHA512: keystore->hashLength = SHA512_DIGEST_LENGTH; keystore->opensslMd = EVP_sha512(); break; default: parcBuffer_Release(&secret_key); parcMemory_Deallocate((void **) &keystore); trapIllegalValue(hmacHashType, "Unknown HMAC hash type: %d", hmacHashType); } keystore->secretKey = parcBuffer_Acquire(secret_key); // the signer key digest is SHA256, independent of the HMAC digest PARCCryptoHasher *hasher = parcCryptoHasher_Create(PARC_HASH_SHA256); parcCryptoHasher_Init(hasher); parcCryptoHasher_UpdateBuffer(hasher, secret_key); keystore->secretKeyHash = parcCryptoHasher_Finalize(hasher); parcCryptoHasher_Release(&hasher); // create the functor from the template then specialize it to this keystore. // This depends on keystore->secret_key being set. It will cause a callback // into hmac_setup() keystore->hasherFunctor = functor_hmac; keystore->hasherFunctor.functor_env = keystore; keystore->hasher = parcCryptoHasher_CustomHasher(keystore->hashType, keystore->hasherFunctor); PARCSigningInterface *signer = parcMemory_AllocateAndClear(sizeof(PARCSigningInterface)); assertNotNull(signer, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(PARCSigningInterface)); *signer = aeskeystoreinterface; signer->interfaceContext = keystore; return signer; }
bool ccnxValidationHmacSha256_Test(const CCNxTlvDictionary *message) { switch (ccnxTlvDictionary_GetSchemaVersion(message)) { case CCNxTlvDictionary_SchemaVersion_V1: { if (ccnxTlvDictionary_IsValueInteger(message, CCNxCodecSchemaV1TlvDictionary_ValidationFastArray_CRYPTO_SUITE)) { uint64_t cryptosuite = ccnxTlvDictionary_GetInteger(message, CCNxCodecSchemaV1TlvDictionary_ValidationFastArray_CRYPTO_SUITE); return (cryptosuite == PARCCryptoSuite_HMAC_SHA256); } return false; } default: trapIllegalValue(message, "Unknown schema version: %d", ccnxTlvDictionary_GetSchemaVersion(message)); } return false; }
/** * Sets the Validation algorithm to HMAC with SHA-256 hash * * Sets the validation algorithm to be HMAC with a SHA-256 digest. Optionally includes * a KeyId with the message. * * @param [in] message The message dictionary * @param [in] keyid (Optional) The KEYID to include the the message * * @return <#value#> <#explanation#> * * Example: * @code * <#example#> * @endcode */ bool ccnxValidationHmacSha256_Set(CCNxTlvDictionary *message, const PARCBuffer *keyid) { bool success = true; switch (ccnxTlvDictionary_GetSchemaVersion(message)) { case CCNxTlvDictionary_SchemaVersion_V1: { success &= ccnxTlvDictionary_PutInteger(message, CCNxCodecSchemaV1TlvDictionary_ValidationFastArray_CRYPTO_SUITE, PARCCryptoSuite_HMAC_SHA256); if (keyid) { success &= ccnxTlvDictionary_PutBuffer(message, CCNxCodecSchemaV1TlvDictionary_ValidationFastArray_KEYID, keyid); } break; } default: trapIllegalValue(message, "Unknown schema version: %d", ccnxTlvDictionary_GetSchemaVersion(message)); } return success; }
PARCCryptoHashType parcCryptoSuite_GetCryptoHash(PARCCryptoSuite suite) { switch (suite) { case PARCCryptoSuite_DSA_SHA256: // fallthrough case PARCCryptoSuite_HMAC_SHA256: // fallthrough case PARCCryptoSuite_RSA_SHA256: // fallthrough case PARCCryptoSuite_EC_SECP_256K1: return PARCCryptoHashType_SHA256; case PARCCryptoSuite_HMAC_SHA512: // fallthrough case PARCCryptoSuite_RSA_SHA512: return PARCCryptoHashType_SHA512; case PARCCryptoSuite_NULL_CRC32C: return PARCCryptoHashType_CRC32C; default: trapIllegalValue(suite, "Unknown crypto suite: %d", suite); } }
CpiMessageType controlPlaneInterface_GetCPIMessageType(PARCJSON *json) { assertNotNull(json, "Invalid state, got NULL json from control message"); PARCJSONValue *value = parcJSON_GetValueByName(json, cpiResponse); if (value != NULL) { return CPI_RESPONSE; } value = parcJSON_GetValueByName(json, cpiRequest); if (value != NULL) { return CPI_REQUEST; } value = parcJSON_GetValueByName(json, cpiAck); if (value != NULL) { return CPI_ACK; } trapIllegalValue(json, "Expected CpiMessageType, actual %s", parcJSON_ToString(json)); }
PARCSymmetricKeySigner * parcSymmetricKeySigner_Create(PARCSymmetricKeyStore *keyStore, PARCCryptoHashType hmacHashType) { PARCSymmetricKeySigner *result = parcObject_CreateInstance(PARCSymmetricKeySigner); if (result != NULL) { result->hashType = hmacHashType; switch (hmacHashType) { case PARC_HASH_SHA256: result->hashLength = SHA256_DIGEST_LENGTH; result->opensslMd = EVP_sha256(); break; case PARC_HASH_SHA512: result->hashLength = SHA512_DIGEST_LENGTH; result->opensslMd = EVP_sha512(); break; default: parcObject_Release((void **) &result); trapIllegalValue(hmacHashType, "Unknown HMAC hash type: %d", hmacHashType); } // the signer key digest is SHA256, independent of the HMAC digest result->secretKeyHash = parcSymmetricKeyStore_GetVerifierKeyDigest(keyStore); result->keyStore = parcSymmetricKeyStore_Acquire(keyStore); result->generalKeyStore = parcKeyStore_Create(result->keyStore, PARCSymmetricKeyStoreAsKeyStore); // create the functor from the template then specialize it to this keystore. // This depends on keystore->secret_key being set. It will cause a callback // into hmac_setup() result->hasherFunctor = functor_hmac; result->hasherFunctor.functor_env = result; result->hasher = parcCryptoHasher_CustomHasher(hmacHashType, result->hasherFunctor); } return result; }
PARCBufferComposer * parcJSONValue_BuildString(const PARCJSONValue *value, PARCBufferComposer *composer, bool compact) { parcJSONValue_OptionalAssertValid(value); if (value->type == PARCJSONValueType_Boolean) { parcBufferComposer_PutString(composer, value->value.boolean ? "true" : "false"); } else if (value->type == PARCJSONValueType_String) { _buildStringString(value, composer, compact); } else if (value->type == PARCJSONValueType_Number) { _buildStringNumber(value, composer); } else if (value->type == PARCJSONValueType_Array) { parcJSONArray_BuildString(value->value.array, composer, compact); } else if (value->type == PARCJSONValueType_JSON) { parcJSON_BuildString(value->value.object, composer, compact); } else if (value->type == PARCJSONValueType_Null) { parcBufferComposer_PutString(composer, "null"); } else { trapIllegalValue(value->type, "Unknown value type: %d", value->type); } return composer; }
PARCEventQueue * metisDispatcher_StreamBufferConnect(MetisDispatcher *dispatcher, const MetisAddressPair *pair) { const CPIAddress *localAddress = metisAddressPair_GetLocal(pair); const CPIAddress *remoteAddress = metisAddressPair_GetRemote(pair); // they must be of the same address family if (cpiAddress_GetType(localAddress) != cpiAddress_GetType(remoteAddress)) { char message[2048]; char *localAddressString = cpiAddress_ToString(localAddress); char *remoteAddressString = cpiAddress_ToString(remoteAddress); snprintf(message, 2048, "Remote address not same type as local address, expected %d got %d\nlocal %s remote %s", cpiAddress_GetType(localAddress), cpiAddress_GetType(remoteAddress), localAddressString, remoteAddressString); parcMemory_Deallocate((void **) &localAddressString); parcMemory_Deallocate((void **) &remoteAddressString); assertTrue(cpiAddress_GetType(localAddress) == cpiAddress_GetType(remoteAddress), "%s", message); } switch (cpiAddress_GetType(localAddress)) { case cpiAddressType_INET: return metisDispatcher_StreamBufferConnect_INET(dispatcher, localAddress, remoteAddress); break; case cpiAddressType_INET6: return metisDispatcher_StreamBufferConnect_INET6(dispatcher, localAddress, remoteAddress); break; default: trapIllegalValue(pair, "local address unsupported CPI address type: %d", cpiAddress_GetType(localAddress)); } }
/** * Calls the confguration routine for each component in the stack * * Builds an array list of everything in the JSON configuration, then * calls its configuation routine. * * The connecting event queues are disabled at this point. * * @param [in,out] stack The Protocol Stack to operate on * * Example: * @code * <#example#> * @endcode */ static void rtaProtocolStack_ConfigureComponents(RtaProtocolStack *stack) { PARCArrayList *componentNameList; componentNameList = protocolStack_GetComponentNameArray(stack->params); assertTrue(parcArrayList_Size(componentNameList) < MAX_STACK_DEPTH, "Too many components in a stack size %zu\n", parcArrayList_Size(componentNameList)); for (int i = 0; i < parcArrayList_Size(componentNameList); i++) { // match it to a component type const char *comp_name = parcArrayList_Get(componentNameList, i); RtaComponents comp_type = getComponentTypeFromName(comp_name); // this could be sped up slightly by putting the ops structures // in an array switch (comp_type) { case API_CONNECTOR: configure_ApiConnector(stack, comp_type, api_ops); break; case FC_NONE: trapIllegalValue(comp_type, "Null flowcontroller no longer supported"); break; case FC_VEGAS: configure_Component(stack, comp_type, flow_vegas_ops); break; case FC_PIPELINE: abort(); break; case CODEC_NONE: trapIllegalValue(comp_type, "Null codec no longer supported"); break; case CODEC_TLV: configure_Component(stack, comp_type, codec_tlv_ops); break; case FWD_NONE: abort(); break; case FWD_LOCAL: configure_FwdConnector(stack, comp_type, fwd_local_ops); break; case FWD_METIS: configure_FwdConnector(stack, comp_type, fwd_metis_ops); break; case TESTING_UPPER: // fallthrough case TESTING_LOWER: configure_Component(stack, comp_type, testing_null_ops); break; default: fprintf(stderr, "%s unsupported component type %s\n", __func__, comp_name); abort(); } } parcArrayList_Destroy(&componentNameList); }
CpiOperation cpi_getCPIOperation2(const PARCJSON *json) { PARCJSONValue *cpi_value = parcJSON_GetValueByName(json, cpiRequest); if (cpi_value == NULL) { cpi_value = parcJSON_GetValueByName(json, cpiResponse); } assertNotNull(cpi_value, "Could not get Request or response"); PARCJSON *cpi_json = parcJSONValue_GetJSON(cpi_value); /* * The JSON is defined as { REQUEST : { SEQUENCE: xxx, <OPERATION>: xxx } } * so we want to get the key of the 2nd item (index 1) of the array of objects * under the request */ PARCJSONPair *item1Pair = parcJSON_GetPairByIndex(cpi_json, 1); PARCBuffer *name = parcJSONPair_GetName(item1Pair); const char *p = parcBuffer_Overlay(name, 0); if (strncasecmp(p, cpiForwarding_AddRouteJsonTag(), strlen(cpiForwarding_AddRouteJsonTag())) == 0) { return CPI_REGISTER_PREFIX; } if (strncasecmp(p, cpiForwarding_RemoveRouteJsonTag(), strlen(cpiForwarding_RemoveRouteJsonTag())) == 0) { return CPI_UNREGISTER_PREFIX; } if (strncasecmp(p, cpiPause, strlen(cpiPause)) == 0) { return CPI_PAUSE; } if (strncasecmp(p, cpiFlush, strlen(cpiFlush)) == 0) { return CPI_FLUSH; } if (strncasecmp(p, cpiCancelFlow_CancelFlowJsonTag(), strlen(cpiCancelFlow_CancelFlowJsonTag())) == 0) { return CPI_CANCEL_FLOW; } if (strncasecmp(p, cpiLinks_InterfaceListJsonTag(), strlen(cpiLinks_InterfaceListJsonTag())) == 0) { return CPI_INTERFACE_LIST; } if (strncasecmp(p, cpiForwarding_RouteListJsonTag(), strlen(cpiForwarding_RouteListJsonTag())) == 0) { return CPI_PREFIX_REGISTRATION_LIST; } if (strncasecmp(p, cpiLinks_CreateTunnelJsonTag(), strlen(cpiLinks_CreateTunnelJsonTag())) == 0) { return CPI_CREATE_TUNNEL; } if (strncasecmp(p, cpiLinks_RemoveTunnelJsonTag(), strlen(cpiLinks_RemoveTunnelJsonTag())) == 0) { return CPI_REMOVE_TUNNEL; } if (strncasecmp(p, cpiLinks_ConnectionListJsonTag(), strlen(cpiLinks_ConnectionListJsonTag())) == 0) { return CPI_CONNECTION_LIST; } if (strncasecmp(p, cpiLinks_AddEtherConnectionJasonTag(), strlen(cpiLinks_AddEtherConnectionJasonTag())) == 0) { return (CPI_ADD_ETHER_CONNECTION); } // Refactor, case 1026 if (strncasecmp(p, "AddConnEther", strlen("AddConnEther")) == 0) { return CPI_ADD_CONNECTION_ETHERNET; } // Refactor, case 1026 if (strncasecmp(p, "RemoveConnEther", strlen("RemoveConnEther")) == 0) { return CPI_REMOVE_CONNECTION_ETHERNET; } // Refactor, case 1026 if (strncasecmp(p, "AddListener", strlen("AddListener")) == 0) { return CPI_ADD_LISTENER; } // Refactor, case 1026 if (strncasecmp(p, "RemoveListener", strlen("RemoveListener")) == 0) { return CPI_REMOVE_LISTENER; } trapIllegalValue(json, "Could not parse: %s\n", parcJSON_ToString(json)); }