Exemplo n.º 1
0
int main() {
	char *buf;
	int ret;
	TCMessage_t msg;
	ComponentPortion_t cp;
	Component_t *cmp_arr;
	Component_t cmp;
	ConnectArg_t ca;
	CalledPartyNumber_t *cpn_arr;
	CalledPartyNumber_t cpn;

	memset(&msg, 0, sizeof(msg));
	memset(&cp, 0, sizeof(cp));
	memset(&cmp, 0, sizeof(cmp));
	memset(&ca, 0, sizeof(ca));
	memset(&cpn, 0, sizeof(cpn));

	msg.present = TCMessage_PR_begin;
	msg.choice.begin.components = &cp;

	cp.list.count = 1;
	cmp_arr = &cmp;
	cp.list.array = &cmp_arr;

	cmp.present = Component_PR_invoke;
	cmp.choice.invoke.opCode.present = OPERATION_PR_localValue;
	asn_long2INTEGER(&cmp.choice.invoke.opCode.choice.localValue, 20); // connect

	ca.destinationRoutingAddress.list.count = 1;
	cpn_arr = &cpn;
	ca.destinationRoutingAddress.list.array = &cpn_arr;

	cpn.buf = "1234567890";
	cpn.size = 10;

	cmp.choice.invoke.parameter = ANY_new_fromType(&asn_DEF_ConnectArg, &ca);

	ret = tcap_encode(&buf, &msg);
	fprintf(stderr, "ret: %i\n", ret);
	fwrite(buf, ret, 1, stdout);

	free(buf);
	asn_DEF_ANY.free_struct(&asn_DEF_ANY, cmp.choice.invoke.parameter, 0);
	asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, &cmp.choice.invoke.opCode.choice.localValue, 0);

	return 0;
}
void getCADESSigningTime(Attribute_t **at_ext, struct tm *local){
    
    /** SINGING TIME **/
    //AtributeValue
    int ret;
    Attribute_t *atSigningTime;
    atSigningTime = calloc(1, sizeof(*atSigningTime));
    
    atSigningTime -> type = makeOID(SIGNING_TIME_OID);    
    AttributeValue_t *atSigningTimeValue;
    atSigningTimeValue = calloc(1,sizeof( *atSigningTimeValue));

    UTCTime_t *time;
    time = calloc (1, sizeof(*time));
    asn_time2UT(time, local, 1);
    
    atSigningTimeValue = ANY_new_fromType(&asn_DEF_UTCTime, time); 
    ret = ASN_SET_ADD(&atSigningTime-> values, atSigningTimeValue);
    
    *at_ext = atSigningTime;
    
    /** FIN SIGNING TIME **/
    
}
Exemplo n.º 3
0
void getSignedDataStructure(SignedData_t **sig_dat,
                            X509 *certificateX509,
                            char *contentData,
                            const char *certBuffer,
                            int certLenght,
                            char *dataSigned,
                            int lengthdataSigned,
                            char *messageDigest,
                            int  lengthMessageDigest,
                            char *contentDescription,
                            char *policyOID,
                            char *policyHash,
                            char *policyHashAlg,
                            char *policyUri,
                            char *certHash,                            
                            int lengthCertHash,
                            char *hashAlgorithm,
                            int signingCertificateV2,
                            char *signAlgorithm,
                            struct tm *local){
    
    int rec;
    //creamos el objeto signedData
    SignedData_t *signedData;
    signedData = calloc(1, sizeof(*signedData));
    
    /*****VERSION SIGNEDDATA*****/
    //creamos el objeto CMSVersion
    CMSVersion_t *version;
    version = calloc(1, sizeof(*version));
    version = CMSVersion_v1;
    signedData -> version = version;
    
    /*****DIGEST ALGORITHMS*****/
    DigestAlgorithmIdentifiers_t *digestAlgorithms;
    digestAlgorithms = calloc(1, sizeof(*digestAlgorithms));
    DigestAlgorithmIdentifier_t *digestAlgorithm;
    digestAlgorithm = calloc(1, sizeof(*digestAlgorithm));
    digestAlgorithm -> algorithm = makeOID(hashAlgorithm);
    NULL_t *null;
    null = calloc(1, sizeof(*null));
    digestAlgorithm -> parameters = ANY_new_fromType(&asn_DEF_NULL, null);
    
    rec = ASN_SET_ADD(&digestAlgorithms ->list, digestAlgorithm);
    
    signedData -> digestAlgorithms = *digestAlgorithms;
    
    
    /*****ENCAPCONTENTINFO*****/
    EncapsulatedContentInfo_t *encapsulatedContentInfo;
    encapsulatedContentInfo = calloc(1, sizeof(*encapsulatedContentInfo));
    
    ContentType_t *eContentType;
    eContentType = calloc(1,sizeof(*eContentType));
    *eContentType = makeOID(DATA_OID);
    
    encapsulatedContentInfo->eContentType = *eContentType;
    
    //NSString *contentData= @"datos";
    //NSString *contentData= NULL;
    
    if (contentData != NULL){
        OCTET_STRING_t *osContentData;
        osContentData = calloc(1,sizeof(*osContentData));
        OCTET_STRING_fromString(osContentData,contentData);
        encapsulatedContentInfo->eContent = osContentData;
    }
    
    signedData -> encapContentInfo = *encapsulatedContentInfo;
    
    /*****CERTIFICATES (OPTIONAL)*****/
    CertificateSet_t *certificateSet;
    certificateSet = calloc(1, sizeof(*certificateSet));
    certificateSet = ANY_new_fromBuf(certBuffer, certLenght);
    signedData -> certificates = certificateSet;
    
    
    /*****SIGNERINFO******/
    SignerInfos_t *CADESSignerInfos;
    getCADESSignerInfos(&CADESSignerInfos,
                        certificateX509,
                        dataSigned,
                        lengthdataSigned,
                        messageDigest,
                        lengthMessageDigest,
                        contentDescription,
                        policyOID,
                        policyHash,
                        policyHashAlg,
                        policyUri,
                        certHash,
                        lengthCertHash,
                        hashAlgorithm,
                        signingCertificateV2,
                        signAlgorithm,
                        local);
    signedData-> signerInfos = *CADESSignerInfos;
    
    *sig_dat = signedData;    
    
}