Пример #1
0
int GTHTTP_createTimestampData(const unsigned char *data, size_t data_len,
                               const char *url, GTTimestamp **timestamp)
{
    int res = GT_UNKNOWN_ERROR;
    GTDataHash *hash = NULL;

    if (data == NULL || url == NULL || timestamp == NULL) {
        res = GT_INVALID_ARGUMENT;
        goto cleanup;
    }

    res = GTDataHash_create(GT_HASHALG_DEFAULT, data, data_len, &hash);
    if (res != GT_OK) {
        goto cleanup;
    }

    res = GTHTTP_createTimestampHash(hash, url, timestamp);
    if (res != GT_OK) {
        goto cleanup;
    }

cleanup:

    GTDataHash_free(hash);

    return res;
}
Пример #2
0
void
sign(const char *buf, const size_t len)
{
	int r;
	GTDataHash *hash = NULL;

	printf("hash for '%s' is ", buf);
	r = GTDataHash_create(GT_HASHALG_SHA256, (const unsigned char*)buf, len, &hash);
	if(r != GT_OK) {
		fprintf(stderr, "GTTDataHash_create() failed: %d (%s)\n",
				r, GT_getErrorString(r));
		goto done;
	}
	outputhash(hash);
	timestampIt(hash); /* of course, this needs to be moved to once at end ;) */
done:	GTDataHash_free(hash);
}
Пример #3
0
int GTHTTP_verifyTimestampData(const GTTimestamp *ts,
                               const unsigned char *data, size_t data_len,
                               const char *ext_url, GTTimestamp **ext_ts,
                               const GTPublicationsFile *pub, const char *pub_url,
                               int parse, GTVerificationInfo **ver)
{
    int res = GT_UNKNOWN_ERROR;
    int algo;
    GTDataHash *hash = NULL;

    if (ts == NULL || data == NULL || ver == NULL) {
        res = GT_INVALID_ARGUMENT;
        goto cleanup;
    }
    if ((pub != NULL) + (pub_url != NULL) != 1) {
        res = GT_INVALID_ARGUMENT;
        goto cleanup;
    }

    res = GTTimestamp_getAlgorithm(ts, &algo);
    if (res != GT_OK) {
        goto cleanup;
    }
    res = GTDataHash_create(algo, data, data_len, &hash);
    if (res != GT_OK) {
        goto cleanup;
    }

    res = GTHTTP_verifyTimestampHash(ts, hash,
                                     ext_url, ext_ts, pub, pub_url, parse, ver);

cleanup:

    GTDataHash_free(hash);

    return res;
}