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 */
124  /*
125  * The hash algorithm has been marked as deprecated at given time.
126  */
128  /*
129  * The hash algorithm has been marked as obsolete at given time.
130  */
132 /* SYSTEM ERRORS */
140  KSI_IO_ERROR = 0x201,
160  KSI_HTTP_ERROR = 0x206,
187 
192 
197 
202 
207 
212 
213  /* Generic service errors. */
214 
243 
244  /* Aggregator errors. */
245 
267 
272 
273  /* Extender status codes. */
274 
295 
300 
305 
310 
311  /* Async status codes. */
312 
317 
322 
323 
328 };
329 
333 #define KSI_PDU_VERSION_1 1
334 #define KSI_PDU_VERSION_2 2
335 
336 #define KSI_CTX_PUBFILE_CACHE_DEFAULT_TTL (8 * 60 * 60)
337 
344 typedef int (*KSI_Config_Callback)(KSI_CTX *ctx, KSI_Config *conf);
345 
346 typedef enum KSI_Option_en {
359 
370 
376 
391 
400 
402 } KSI_Option;
403 
409 const char *KSI_getVersion(void);
410 
420 const char *KSI_getErrorString(int statusCode);
421 
433 int KSI_CTX_new(KSI_CTX **ctx);
434 
442 void KSI_CTX_free(KSI_CTX *ctx);
443 
458 int KSI_CTX_registerGlobals(KSI_CTX *ctx, int (*initFn)(void), void (*cleanupFn)(void));
459 
468 int KSI_ERR_statusDump(KSI_CTX *ctx, FILE *f);
469 
478 char *KSI_ERR_toString(KSI_CTX *ctx, char *buf, size_t buf_len);
479 
492 int KSI_ERR_getBaseErrorMessage(KSI_CTX *ctx, char *buf, size_t len, int *error, int *ext);
493 
501 void *KSI_malloc(size_t size);
502 
511 void *KSI_calloc(size_t num, size_t size);
512 
517 void KSI_free(void *ptr);
518 
528 
529 #define KSI_sendSignRequest(ctx, request, handle) KSI_sendAggregatorRequest(ctx, request, handle)
530 
539 int KSI_sendExtenderRequest(KSI_CTX *ctx, KSI_ExtendReq *request, KSI_RequestHandle **handle);
540 
541 #define KSI_sendExtendRequest(ctx, request, handle) KSI_sendExtenderRequest(ctx, request, handle)
542 
552 int KSI_sendPublicationRequest(KSI_CTX *ctx, const unsigned char *request, size_t request_length, KSI_RequestHandle **handle);
553 
571 
580 
588 
595 int KSI_receiveExtenderConfig(KSI_CTX *ctx, KSI_Config **config);
596 
605 
614 int KSI_verifyDataHash(KSI_CTX *ctx, KSI_Signature *sig, const KSI_DataHash *hsh);
624 int KSI_createSignature(KSI_CTX *ctx, KSI_DataHash *dataHash, KSI_Signature **sig);
625 
638 int KSI_extendSignatureWithPolicy(KSI_CTX *ctx, const KSI_Signature *sig, const KSI_Policy *policy, KSI_VerificationContext *context, KSI_Signature **extended);
639 
640 #define KSI_extendSignature(ctx, sig, extended) KSI_extendSignatureWithPolicy(ctx, sig, KSI_VERIFICATION_POLICY_INTERNAL, NULL, extended)
641 
650 int KSI_CTX_setLogLevel(KSI_CTX *ctx, int level);
651 
663 int KSI_CTX_setLoggerCallback(KSI_CTX *ctx, KSI_LoggerCallback cb, void *logCtx);
664 
674 
682 int KSI_CTX_setPublicationUrl(KSI_CTX *ctx, const char *uri);
683 
692 int KSI_CTX_setExtender(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key);
693 
702 int KSI_CTX_setAggregator(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key);
703 
713 int KSI_CTX_setOption(KSI_CTX *ctx, KSI_Option opt, void *param);
714 
715 #define KSI_CTX_setAggregatorHmacAlgorithm(ctx, alg_id) KSI_CTX_setOption(ctx, KSI_OPT_AGGR_HMAC_ALGORITHM, (void*)(alg_id))
716 #define KSI_CTX_setExtenderHmacAlgorithm(ctx, alg_id) KSI_CTX_setOption(ctx, KSI_OPT_EXT_HMAC_ALGORITHM, (void*)(alg_id))
717 
722 #define KSI_CTX_FLAG_AGGR_PDU_VER KSI_OPT_AGGR_PDU_VER
723 #define KSI_CTX_FLAG_EXT_PDU_VER KSI_OPT_EXT_PDU_VER
724 #define KSI_CtxFlag KSI_Option_en
725 #define KSI_CTX_setFlag(ctx, flag, param) KSI_CTX_setOption((ctx), (flag), (param))
726 
733 int KSI_CTX_setTransferTimeoutSeconds(KSI_CTX *ctx, int timeout);
734 
741 int KSI_CTX_setConnectionTimeoutSeconds(KSI_CTX *ctx, int timeout);
742 
750 
758 
766 
768 
769 #define KSI_CERT_EMAIL "1.2.840.113549.1.9.1"
770 #define KSI_CERT_COMMON_NAME "2.5.4.3"
771 #define KSI_CERT_COUNTRY "2.5.4.6"
772 #define KSI_CERT_ORGANIZATION "2.5.4.10"
773 
794 
802 
810 
819 int KSI_CTX_getPublicationCertEmail(KSI_CTX *ctx, const char **address);
820 
828 int KSI_CTX_getLastFailedSignature(KSI_CTX *ctx, KSI_Signature **lastFailedSignature);
829 
833 #ifdef __cplusplus
834 }
835 #endif
836 
837 #endif
Definition: ksi.h:95
Definition: ksi.h:206
Definition: ksi.h:144
Definition: ksi.h:156
int KSI_receiveAggregatorConfig(KSI_CTX *ctx, KSI_Config **config)
enum KSI_Option_en KSI_Option
Definition: ksi.h:172
Definition: ksi.h:140
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:196
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:136
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:316
Definition: ksi.h:54
struct KSI_PublicationsFile_st KSI_PublicationsFile
Definition: publicationsfile.h:45
Definition: ksi.h:123
Definition: ksi.h:148
Definition: ksi.h:369
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:218
int KSI_verifyPublicationsFile(KSI_CTX *ctx, const KSI_PublicationsFile *pubFile)
Definition: ksi.h:131
void * KSI_malloc(size_t size)
#define KSI_CERT_EMAIL
Definition: ksi.h:769
int KSI_CTX_getPublicationCertEmail(KSI_CTX *ctx, const char **address)
Definition: ksi.h:176
int KSI_sendExtenderRequest(KSI_CTX *ctx, KSI_ExtendReq *request, KSI_RequestHandle **handle)
struct KSI_DataHash_st KSI_DataHash
Definition: hash.h:52
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:401
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:50
void * KSI_calloc(size_t num, size_t size)
Definition: ksi.h:358
Definition: ksi.h:327
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:238
void KSI_free(void *ptr)
Definition: ksi.h:152
Definition: ksi.h:58
int KSI_CTX_setLogLevel(KSI_CTX *ctx, int level)
Definition: ksi.h:364
int KSI_CTX_setExtender(KSI_CTX *ctx, const char *uri, const char *loginId, const char *key)
Definition: ksi.h:321
Definition: types.h:148
Definition: ksi.h:186
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:242
Definition: ksi.h:103
int KSI_CTX_setPublicationsFile(KSI_CTX *ctx, KSI_PublicationsFile *var)
Definition: ksi.h:127
Definition: ksi.h:111
struct KSI_Policy_st KSI_Policy
Definition: types.h:70
Definition: ksi.h:375
int KSI_createSignature(KSI_CTX *ctx, KSI_DataHash *dataHash, KSI_Signature **sig)
KSI_Option_en
Definition: ksi.h:346
int KSI_ERR_getBaseErrorMessage(KSI_CTX *ctx, char *buf, size_t len, int *error, int *ext)
Definition: ksi.h:201
struct KSI_CTX_st KSI_CTX
Definition: types_base.h:124
Definition: ksi.h:234
int KSI_receivePublicationsFile(KSI_CTX *ctx, KSI_PublicationsFile **pubFile)
int KSI_CTX_setDefaultPubFileCertConstraints(KSI_CTX *ctx, const KSI_CertConstraint *arr)
Definition: ksi.h:211
Definition: ksi.h:160
struct KSI_PKITruststore_st KSI_PKITruststore
Definition: types.h:103
Definition: ksi.h:119
Definition: ksi.h:262
Definition: ksi.h:230
int(* KSI_Config_Callback)(KSI_CTX *ctx, KSI_Config *conf)
Definition: ksi.h:344
struct KSI_NetworkClient_st KSI_NetworkClient
Definition: types.h:121
Definition: ksi.h:82
Definition: ksi.h:226
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:164
Definition: ksi.h:191
Definition: ksi.h:352
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