Guardtime KSI c SDK
ksi.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2015 Guardtime, Inc.
3  *
4  * This file is part of the Guardtime client SDK.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License").
7  * You may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  * http://www.apache.org/licenses/LICENSE-2.0
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES, CONDITIONS, OR OTHER LICENSES OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  * "Guardtime" and "KSI" are trademarks or registered trademarks of
16  * Guardtime, Inc., and no license to trademarks is granted; Guardtime
17  * reserves and retains all trademark rights.
18  */
19 
20 #ifndef _KSI_BASE_H_
21 #define _KSI_BASE_H_
22 
23 #include <stdio.h>
24 #include <stdint.h>
25 
26 #include "version.h"
27 #include "types.h"
28 #include "hash.h"
29 #include "publicationsfile.h"
30 #include "log.h"
31 #include "signature.h"
32 #include "verification.h"
33 #include "policy.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
48 /* RETURN CODES WHICH ARE NOT ERRORS */
49  KSI_OK = 0,
50 
71 
72 /* SYNTAX ERRORS */
120 
121 /* SYSTEM ERRORS */
129  KSI_IO_ERROR = 0x201,
149  KSI_HTTP_ERROR = 0x206,
176 
181 
186 
191 
196 
201 
202  /* Generic service errors */
203 
232 
233  /* Aggregator errors */
234 
256 
261 
262  /* Extender status codes. */
263 
284 
289 
294 
299 
300  /* Async status codes. */
301 
306 
311 
312 
317 };
318 
322 #define KSI_PDU_VERSION_1 1
323 #define KSI_PDU_VERSION_2 2
324 
325 
332 typedef int (*KSI_Config_Callback)(KSI_CTX *ctx, KSI_Config *conf);
333 
334 typedef enum KSI_Option_en {
347 
360 
365 
380 
382 } KSI_Option;
383 
389 const char *KSI_getVersion(void);
390 
400 const char *KSI_getErrorString(int statusCode);
401 
413 int KSI_CTX_new(KSI_CTX **ctx);
414 
422 void KSI_CTX_free(KSI_CTX *ctx);
423 
438 int KSI_CTX_registerGlobals(KSI_CTX *ctx, int (*initFn)(void), void (*cleanupFn)(void));
439 
448 int KSI_ERR_statusDump(KSI_CTX *ctx, FILE *f);
449 
458 char *KSI_ERR_toString(KSI_CTX *ctx, char *buf, size_t buf_len);
459 
472 int KSI_ERR_getBaseErrorMessage(KSI_CTX *ctx, char *buf, size_t len, int *error, int *ext);
473 
481 void *KSI_malloc(size_t size);
482 
491 void *KSI_calloc(size_t num, size_t size);
492 
497 void KSI_free(void *ptr);
498 
508 
509 #define KSI_sendSignRequest(ctx, request, handle) KSI_sendAggregatorRequest(ctx, request, handle)
510 
519 int KSI_sendExtenderRequest(KSI_CTX *ctx, KSI_ExtendReq *request, KSI_RequestHandle **handle);
520 
521 #define KSI_sendExtendRequest(ctx, request, handle) KSI_sendExtenderRequest(ctx, request, handle)
522 
532 int KSI_sendPublicationRequest(KSI_CTX *ctx, const unsigned char *request, size_t request_length, KSI_RequestHandle **handle);
533 
545 
554 
562 
569 int KSI_receiveExtenderConfig(KSI_CTX *ctx, KSI_Config **config);
570 
579 
588 int KSI_verifyDataHash(KSI_CTX *ctx, KSI_Signature *sig, const KSI_DataHash *hsh);
598 int KSI_createSignature(KSI_CTX *ctx, KSI_DataHash *dataHash, KSI_Signature **sig);
599 
612 int KSI_extendSignatureWithPolicy(KSI_CTX *ctx, const KSI_Signature *sig, const KSI_Policy *policy, KSI_VerificationContext *context, KSI_Signature **extended);
613 
614 #define KSI_extendSignature(ctx, sig, extended) KSI_extendSignatureWithPolicy(ctx, sig, KSI_VERIFICATION_POLICY_INTERNAL, NULL, extended)
615 
624 int KSI_CTX_setLogLevel(KSI_CTX *ctx, int level);
625 
637 int KSI_CTX_setLoggerCallback(KSI_CTX *ctx, KSI_LoggerCallback cb, void *logCtx);
638 
648 
655 int KSI_CTX_setPublicationUrl(KSI_CTX *ctx, const char *uri);
656 
665 int KSI_CTX_setExtender(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key);
666 
675 int KSI_CTX_setAggregator(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key);
676 
686 int KSI_CTX_setOption(KSI_CTX *ctx, KSI_Option opt, void *param);
687 
688 #define KSI_CTX_setAggregatorHmacAlgorithm(ctx, alg_id) KSI_CTX_setOption(ctx, KSI_OPT_AGGR_HMAC_ALGORITHM, (void*)(alg_id))
689 #define KSI_CTX_setExtenderHmacAlgorithm(ctx, alg_id) KSI_CTX_setOption(ctx, KSI_OPT_EXT_HMAC_ALGORITHM, (void*)(alg_id))
690 
695 #define KSI_CTX_FLAG_AGGR_PDU_VER KSI_OPT_AGGR_PDU_VER
696 #define KSI_CTX_FLAG_EXT_PDU_VER KSI_OPT_EXT_PDU_VER
697 #define KSI_CtxFlag KSI_Option_en
698 #define KSI_CTX_setFlag(ctx, flag, param) KSI_CTX_setOption((ctx), (flag), (param))
699 
706 int KSI_CTX_setTransferTimeoutSeconds(KSI_CTX *ctx, int timeout);
707 
714 int KSI_CTX_setConnectionTimeoutSeconds(KSI_CTX *ctx, int timeout);
715 
723 
731 
739 
741 
742 #define KSI_CERT_EMAIL "1.2.840.113549.1.9.1"
743 #define KSI_CERT_COMMON_NAME "2.5.4.3"
744 #define KSI_CERT_COUNTRY "2.5.4.6"
745 #define KSI_CERT_ORGANIZATION "2.5.4.10"
746 
767 
775 
783 
792 int KSI_CTX_getPublicationCertEmail(KSI_CTX *ctx, const char **address);
793 
801 int KSI_CTX_getLastFailedSignature(KSI_CTX *ctx, KSI_Signature **lastFailedSignature);
802 
806 #ifdef __cplusplus
807 }
808 #endif
809 
810 #endif
Definition: ksi.h:95
Definition: ksi.h:195
Definition: ksi.h:133
Definition: ksi.h:145
int KSI_receiveAggregatorConfig(KSI_CTX *ctx, KSI_Config **config)
enum KSI_Option_en KSI_Option
Definition: ksi.h:161
Definition: ksi.h:129
int KSI_CTX_getPublicationsFile(KSI_CTX *ctx, KSI_PublicationsFile **var)
int KSI_CTX_setRequestHeaderCallback(KSI_CTX *ctx, KSI_RequestHeaderCallback cb)
const char * KSI_getVersion(void)
Definition: ksi.h:185
int KSI_sendAggregatorRequest(KSI_CTX *ctx, KSI_AggregationReq *request, KSI_RequestHandle **handle)
char * KSI_ERR_toString(KSI_CTX *ctx, char *buf, size_t buf_len)
int KSI_CTX_getPKITruststore(KSI_CTX *ctx, KSI_PKITruststore **pki)
Definition: ksi.h:125
int KSI_CTX_registerGlobals(KSI_CTX *ctx, int(*initFn)(void), void(*cleanupFn)(void))
Definition: ksi.h:49
int KSI_CTX_setConnectionTimeoutSeconds(KSI_CTX *ctx, int timeout)
Definition: ksi.h:305
Definition: ksi.h:54
struct KSI_PublicationsFile_st KSI_PublicationsFile
Definition: publicationsfile.h:45
Definition: ksi.h:137
Definition: ksi.h:359
Definition: ksi.h:107
KSI_StatusCode
Definition: ksi.h:47
struct KSI_NetHandle_st KSI_RequestHandle
Definition: types.h:115
int KSI_sendPublicationRequest(KSI_CTX *ctx, const unsigned char *request, size_t request_length, KSI_RequestHandle **handle)
int KSI_CTX_setTransferTimeoutSeconds(KSI_CTX *ctx, int timeout)
int KSI_verifySignature(KSI_CTX *ctx, KSI_Signature *sig)
void KSI_CTX_free(KSI_CTX *ctx)
int KSI_extendSignatureWithPolicy(KSI_CTX *ctx, const KSI_Signature *sig, const KSI_Policy *policy, KSI_VerificationContext *context, KSI_Signature **extended)
const char * KSI_getErrorString(int statusCode)
int KSI_CTX_setAggregator(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key)
struct KSI_ExtendReq_st KSI_ExtendReq
Definition: types.h:54
Definition: ksi.h:207
int KSI_verifyPublicationsFile(KSI_CTX *ctx, const KSI_PublicationsFile *pubFile)
void * KSI_malloc(size_t size)
#define KSI_CERT_EMAIL
Definition: ksi.h:742
int KSI_CTX_getPublicationCertEmail(KSI_CTX *ctx, const char **address)
Definition: ksi.h:165
int KSI_sendExtenderRequest(KSI_CTX *ctx, KSI_ExtendReq *request, KSI_RequestHandle **handle)
struct KSI_DataHash_st KSI_DataHash
Definition: hash.h:50
int KSI_ERR_statusDump(KSI_CTX *ctx, FILE *f)
struct KSI_AggregationReq_st KSI_AggregationReq
Definition: types.h:51
Definition: ksi.h:115
int KSI_CTX_setPublicationCertEmail(KSI_CTX *ctx, const char *email)
Definition: ksi.h:381
int(* KSI_RequestHeaderCallback)(KSI_Header *hdr)
Definition: types.h:83
int KSI_CTX_setNetworkProvider(KSI_CTX *ctx, KSI_NetworkClient *net)
int KSI_CTX_new(KSI_CTX **ctx)
#define KSI_FN_DEPRECATED(decl, comment)
Definition: common.h:43
void * KSI_calloc(size_t num, size_t size)
Definition: ksi.h:346
Definition: ksi.h:316
struct KSI_Config_st KSI_Config
Definition: types.h:50
int KSI_CTX_setOption(KSI_CTX *ctx, KSI_Option opt, void *param)
Definition: ksi.h:227
void KSI_free(void *ptr)
Definition: ksi.h:141
Definition: ksi.h:58
int KSI_CTX_setLogLevel(KSI_CTX *ctx, int level)
Definition: ksi.h:353
int KSI_CTX_setExtender(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key)
Definition: ksi.h:310
Definition: types.h:148
Definition: ksi.h:175
struct KSI_Signature_st KSI_Signature
Definition: types.h:67
Definition: ksi.h:99
int KSI_CTX_setLoggerCallback(KSI_CTX *ctx, KSI_LoggerCallback cb, void *logCtx)
Definition: policy.h:31
Definition: ksi.h:231
Definition: ksi.h:103
int KSI_CTX_setPublicationsFile(KSI_CTX *ctx, KSI_PublicationsFile *var)
Definition: ksi.h:111
struct KSI_Policy_st KSI_Policy
Definition: types.h:70
Definition: ksi.h:364
int KSI_createSignature(KSI_CTX *ctx, KSI_DataHash *dataHash, KSI_Signature **sig)
KSI_Option_en
Definition: ksi.h:334
int KSI_ERR_getBaseErrorMessage(KSI_CTX *ctx, char *buf, size_t len, int *error, int *ext)
Definition: ksi.h:190
struct KSI_CTX_st KSI_CTX
Definition: types_base.h:124
Definition: ksi.h:223
int KSI_receivePublicationsFile(KSI_CTX *ctx, KSI_PublicationsFile **pubFile)
int KSI_CTX_setDefaultPubFileCertConstraints(KSI_CTX *ctx, const KSI_CertConstraint *arr)
Definition: ksi.h:200
Definition: ksi.h:149
struct KSI_PKITruststore_st KSI_PKITruststore
Definition: types.h:103
Definition: ksi.h:119
Definition: ksi.h:251
Definition: ksi.h:219
int(* KSI_Config_Callback)(KSI_CTX *ctx, KSI_Config *conf)
Definition: ksi.h:332
struct KSI_NetworkClient_st KSI_NetworkClient
Definition: types.h:121
Definition: ksi.h:82
Definition: ksi.h:215
int KSI_CTX_getLastFailedSignature(KSI_CTX *ctx, KSI_Signature **lastFailedSignature)
Definition: ksi.h:87
int KSI_receiveExtenderConfig(KSI_CTX *ctx, KSI_Config **config)
Definition: ksi.h:91
Definition: ksi.h:153
Definition: ksi.h:180
Definition: ksi.h:340
int KSI_verifyDataHash(KSI_CTX *ctx, KSI_Signature *sig, const KSI_DataHash *hsh)
int KSI_CTX_setPublicationUrl(KSI_CTX *ctx, const char *uri)
int KSI_CTX_setPKITruststore(KSI_CTX *ctx, KSI_PKITruststore *pki)
Definition: ksi.h:70
int(* KSI_LoggerCallback)(void *logCtx, int level, const char *message)
Definition: types_base.h:115
Definition: ksi.h:77