/** * The signature verifies if: * 0) we know the key for keyid * 1) the signing algorithm of the key corresponding to keyid is same as CCNxSignature * 2) The hash of the locallyComputedHash is the same type as the content object's ciphersuite * 3) the signature verifies * * Example: * @code * <#example#> * @endcode */ static bool _parcInMemoryVerifier_VerifyDigest(void *interfaceContext, PARCKeyId *keyid, PARCCryptoHash *locallyComputedHash, PARCCryptoSuite suite, PARCSignature *objectSignature) { PARCInMemoryVerifier *verifier = (PARCInMemoryVerifier *) interfaceContext; const PARCKey *key = parcCryptoCache_GetKey(verifier->key_cache, keyid); if (key == NULL) { return false; } assertTrue(_parcInMemoryVerifier_AllowedCryptoSuite(interfaceContext, keyid, suite), "Invalid crypto suite for keyid"); if (parcKey_GetSigningAlgorithm(key) != parcSignature_GetSigningAlgorithm(objectSignature)) { fprintf(stdout, "Signatured failed, signing algorithms do not match: key %s sig %s\n", parcSigningAlgorithm_ToString(parcKey_GetSigningAlgorithm(key)), parcSigningAlgorithm_ToString(parcSignature_GetSigningAlgorithm(objectSignature))); return false; } if (parcCryptoHash_GetDigestType(locallyComputedHash) != parcCryptoSuite_GetCryptoHash(suite)) { fprintf(stdout, "Signatured failed, digest algorithms do not match: digest %s suite %s\n", parcCryptoHashType_ToString(parcCryptoHash_GetDigestType(locallyComputedHash)), parcCryptoHashType_ToString(parcCryptoSuite_GetCryptoHash(suite))); return false; } switch (parcSignature_GetSigningAlgorithm(objectSignature)) { case PARCSigningAlgorithm_RSA: return _parcInMemoryVerifier_RSAKey_Verify(verifier, locallyComputedHash, objectSignature, parcKey_GetKey(key)); case PARCSigningAlgorithm_DSA: trapNotImplemented("DSA not supported"); break; case PARCSigningAlgorithm_HMAC: trapNotImplemented("HMAC not supported"); break; default: trapUnexpectedState("Unknown signing algorithm: %d", parcSignature_GetSigningAlgorithm(objectSignature)); } return false; }
const CCNxName * ccnxManifest_GetName(const CCNxManifest *manifest) { CCNxManifestInterface *impl = ccnxManifestInterface_GetInterface(manifest); const CCNxName *result = NULL; if (impl->getName != NULL) { result = impl->getName(manifest); } else { trapNotImplemented("ccnxManifest_GetName"); } return result; }
char * ccnxContentObject_ToString(const CCNxContentObject *contentObject) { ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); char *result = NULL; if (impl->toString != NULL) { result = impl->toString(contentObject); } else { trapNotImplemented("ccnxContentObject_ToString"); } return result; }
bool ccnxContentObject_SetFinalChunkNumber(CCNxContentObject *contentObject, const uint64_t finalChunkNumber) { ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); bool result = false; if (impl->setFinalChunkNumber != NULL) { result = impl->setFinalChunkNumber(contentObject, finalChunkNumber); } else { trapNotImplemented("ccnxContentObject_SetFinalChunkNumber"); } return result; }
bool ccnxContentObject_SetExpiryTime(CCNxContentObject *contentObject, const uint64_t expiryTIme) { bool result = false; ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); if (impl->setExpiryTime != NULL) { result = impl->setExpiryTime(contentObject, expiryTIme); } else { trapNotImplemented("ccnxContentObject_SetExpiryTime"); } return result; }
PARCBuffer * parcJSONParser_ParseString(PARCJSONParser *parser) { PARCBuffer *result = NULL; PARCBuffer *buffer = _getBuffer(parser); if (parcBuffer_GetUint8(buffer) == '"') { // skip the initial '"' character starting the string. PARCBufferComposer *composer = parcBufferComposer_Create(); while (parcBuffer_Remaining(buffer)) { uint8_t c = parcBuffer_GetUint8(buffer); if (c == '"') { // This is the only successful way to exit this while loop. result = parcBufferComposer_ProduceBuffer(composer); break; } else if (c == '\\') { c = parcBuffer_GetUint8(buffer); if (c == '"') { // this special character passes directly into the composed string. } else if (c == '\\') { // this special character passes directly into the composed string. } else if (c == '/') { // this special character passes directly into the composed string. } else if (c == 'b') { c = '\b'; } else if (c == 'f') { c = '\f'; } else if (c == 'n') { c = '\n'; } else if (c == 'r') { c = '\r'; } else if (c == 't') { c = '\t'; } else if (c == 'u') { // Not supporting unicode at this point. trapNotImplemented("Unicode is not supported."); } } else if (iscntrl(c)) { // !! Syntax Error. break; } parcBufferComposer_PutChar(composer, c); } parcBufferComposer_Release(&composer); } return result; }
static CCNxManifest * _ccnxManifest_InternalCreate(const CCNxManifestInterface *impl, const CCNxName *name) { CCNxManifest *result = NULL; if (impl->create != NULL) { result = impl->create(name); // And set the dictionary's interface pointer to the one we just used to create this. ccnxTlvDictionary_SetMessageInterface(result, impl); } else { trapNotImplemented("Manifest implementations must implement create()"); } return result; }
uint64_t ccnxContentObject_GetFinalChunkNumber(const CCNxContentObject *contentObject) { ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); if (impl->hasFinalChunkNumber != NULL && !impl->hasFinalChunkNumber((CCNxTlvDictionary *) contentObject)) { trapUnexpectedState("ContentObject has no final chunk number. Call ccnxContentObject_HasFinalChunkNumber() first."); } if (impl->getFinalChunkNumber != NULL) { return impl->getFinalChunkNumber(contentObject); } else { trapNotImplemented("ccnxContentObject_GetFinalChunkNumber"); } }
uint64_t ccnxContentObject_GetExpiryTime(const CCNxContentObject *contentObject) { ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); if (impl->hasExpiryTime != NULL && !impl->hasExpiryTime((CCNxTlvDictionary *) contentObject)) { trapUnexpectedState("ContentObject has no ExpiryTime. Call HasExpiryTime() first."); } if (impl->getExpiryTime != NULL) { return impl->getExpiryTime(contentObject); } else { trapNotImplemented("ccnxContentObject_HasExpiryTime"); } }
bool ccnxContentObject_SetPayload(CCNxContentObject *contentObject, CCNxPayloadType payloadType, const PARCBuffer *payload) { ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); bool result = false;; if (impl->setPayload != NULL) { result = impl->setPayload(contentObject, payloadType, payload);; } else { trapNotImplemented("ccnxContentObject_SetPayload"); } return result; }
CCNxPayloadType ccnxContentObject_GetPayloadType(const CCNxContentObject *contentObject) { ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); CCNxPayloadType result = CCNxPayloadType_DATA; if (impl->getPayloadType != NULL) { result = impl->getPayloadType(contentObject); } else { trapNotImplemented("ccnxContentObject_GetPayloadType"); } return result; }
PARCBuffer * ccnxContentObject_GetPayload(const CCNxContentObject *contentObject) { ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); PARCBuffer *result = NULL; if (impl->getPayload != NULL) { result = impl->getPayload(contentObject); } else { trapNotImplemented("ccnxContentObject_GetPayload"); } return result; }
CCNxName * ccnxContentObject_GetName(const CCNxContentObject *contentObject) { ccnxContentObject_OptionalAssertValid(contentObject); CCNxContentObjectInterface *impl = ccnxContentObjectInterface_GetInterface(contentObject); CCNxName *result = NULL; if (impl->getName != NULL) { result = impl->getName(contentObject); } else { trapNotImplemented("ccnxContentObject_GetName"); } return result; }
bool ccnxContentObject_Equals(const CCNxContentObject *objectA, const CCNxContentObject *objectB) { CCNxContentObjectInterface *implA = ccnxContentObjectInterface_GetInterface(objectA); CCNxContentObjectInterface *implB = ccnxContentObjectInterface_GetInterface(objectB); assertNotNull(implA, "ContentObject must have an valid implementation pointer."); assertNotNull(implB, "ContentObject must have an valid implementation pointer."); if (implA != implB) { return false; } if (implA->equals != NULL) { return implA->equals(objectA, objectB); } else { trapNotImplemented("ccnxContentObject_Equals"); } }
CCNxContentObject * ccnxContentObject_CreateWithImplAndPayload(const CCNxContentObjectInterface *impl, const CCNxName *contentName, const CCNxPayloadType payloadType, const PARCBuffer *payload) { CCNxContentObject *result = NULL; if (impl->createWithNameAndPayload != NULL) { if (contentName == NULL) { result = impl->createWithPayload(payloadType, payload); } else { result = impl->createWithNameAndPayload(contentName, payloadType, payload); } // And set the dictionary's interface pointer to the one we just used to create this. ccnxTlvDictionary_SetMessageInterface(result, impl); } else { trapNotImplemented("ContentObject implementations must implement createWithNameAndPayload()"); } return result; }
PARCVerifier * ccnxValidationHmacSha256_CreateVerifier(PARCBuffer *secretKey) { trapNotImplemented("not finished yet"); }