Пример #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
timestampIt(GTDataHash *hash)
{
	int r = GT_OK;
	GTTimestamp *timestamp = NULL;
	unsigned char *der = NULL;
	char *sigFile = "logsigner.TIMESTAMP";
	size_t der_len;

	/* Get the timestamp. */
	r = GTHTTP_createTimestampHash(hash,
		"http://stamper.guardtime.net/gt-signingservice", &timestamp);

	if(r != GT_OK) {
		fprintf(stderr, "GTHTTP_createTimestampHash() failed: %d (%s)\n",
				r, GTHTTP_getErrorString(r));
		goto done;
	}

	/* Encode timestamp. */
	r = GTTimestamp_getDEREncoded(timestamp, &der, &der_len);
	if(r != GT_OK) {
		fprintf(stderr, "GTTimestamp_getDEREncoded() failed: %d (%s)\n",
				r, GT_getErrorString(r));
		goto done;
	}

	/* Save DER-encoded timestamp to file. */
	r = GT_saveFile(sigFile, der, der_len);
	if(r != GT_OK) {
		fprintf(stderr, "Cannot save timestamp to file %s: %d (%s)\n",
				sigFile, r, GT_getErrorString(r));
		if(r == GT_IO_ERROR) {
			fprintf(stderr, "\t%d (%s)\n", errno, strerror(errno));
		}
		goto done;
	}
	printf("Timestamping succeeded!\n");
done:
	GT_free(der);
	GTTimestamp_free(timestamp);
}