void load_statement(sqlite3_stmt *stmt, Row_t *row, Table_t *table) { guint32 i, max; if (table->header.list.count <= 0) /* Lazy header loading */ load_table_header(stmt, table); if (!row->fields) /* Lazy memory allocation */ row->fields = calloc(1, sizeof(struct RowFieldSequence)); for (i=0,max=sqlite3_data_count(stmt); i<max ;i++) { struct RowField *rf = calloc(1, sizeof(*rf)); asn_uint32_to_INTEGER(&(rf->pos), i); rf->value.present = RowFieldValue_PR_n; switch (sqlite3_column_type(stmt, i)) { case SQLITE_NULL: rf->value.present = RowFieldValue_PR_n; break; case SQLITE_INTEGER: do { gint64 i64 = sqlite3_column_int64(stmt, i); asn_int64_to_INTEGER(&(rf->value.choice.i), i64); rf->value.present = RowFieldValue_PR_i; } while (0); break; case SQLITE_FLOAT: do { gdouble d = sqlite3_column_double(stmt, i); asn_double2REAL(&(rf->value.choice.f), d); rf->value.present = RowFieldValue_PR_f; } while (0); break; case SQLITE_TEXT: do { const guint8 *t = sqlite3_column_text(stmt, i); gsize tsize = sqlite3_column_bytes(stmt, i); OCTET_STRING_fromBuf(&(rf->value.choice.s), (char*)t, tsize); rf->value.present = RowFieldValue_PR_s; } while (0); break; case SQLITE_BLOB: do { const void *b = sqlite3_column_blob(stmt, i); gsize bsize = sqlite3_column_bytes(stmt, i); OCTET_STRING_fromBuf(&(rf->value.choice.b), (char*)b, bsize); rf->value.present = RowFieldValue_PR_b; } while (0); break; default: rf->value.present = RowFieldValue_PR_n; break; } asn_sequence_add(&(row->fields->list), rf); } }
static Fulfillment_t *ed25519ToFulfillment(const CC *cond) { if (!cond->signature) { return NULL; } Fulfillment_t *ffill = calloc(1, sizeof(Fulfillment_t)); ffill->present = Fulfillment_PR_ed25519Sha256; Ed25519Sha512Fulfillment_t *ed2 = &ffill->choice.ed25519Sha256; OCTET_STRING_fromBuf(&ed2->publicKey, cond->publicKey, 32); OCTET_STRING_fromBuf(&ed2->signature, cond->signature, 64); return ffill; }
void metautils_message_add_field(MESSAGE m, const char *n, const void *v, gsize vs) { EXTRA_ASSERT (m!=NULL); EXTRA_ASSERT (n!=NULL); if (!v || !vs) return ; Parameter_t *pMember = calloc(1, sizeof(Parameter_t)); OCTET_STRING_fromBuf(&(pMember->name), n, strlen(n)); OCTET_STRING_fromBuf(&(pMember->value), v, vs); asn_set_add(&(m->content.list), pMember); }
struct msgb *rua_new_udt(struct msgb *inmsg) { RUA_ConnectionlessTransfer_t out; RUA_ConnectionlessTransferIEs_t ies; struct msgb *msg; int rc; memset(&ies, 0, sizeof(ies)); OCTET_STRING_fromBuf(&ies.ranaP_Message, inmsg->data, msgb_length(inmsg)); msgb_free(inmsg); memset(&out, 0, sizeof(out)); rc = rua_encode_connectionlesstransferies(&out, &ies); if (rc < 0) return NULL; msg = rua_generate_initiating_message(RUA_ProcedureCode_id_ConnectionlessTransfer, RUA_Criticality_reject, &asn_DEF_RUA_ConnectionlessTransfer, &out); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_ConnectionlessTransfer, &out); DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); msgb_sctp_ppid(msg) = IUH_PPI_RUA; return msg; }
/*liczony jest strot z przekazywanych danych funkcja SHA-1, jesli countHashFlag=CCPD_COUNT_HASH */ long _add_to_Data__CCPD( GenBuf_t *data_for_hash, Data_t *data, long countHashFlag) { bmd_crypt_ctx_t *hash_context = NULL; GenBuf_t *hash = NULL; char oid_sha1_tab[] = { OID_HASH_FUNCTION_SHA1 }; long ret_val = 0; if(data_for_hash == NULL) { BMD_FOK(-1); } if(data_for_hash->buf == NULL) { BMD_FOK(-2); } if(data == NULL) { BMD_FOK(-3); } //w przypadku skrotu na wejsciu, dopuszczalna jest tylko funkcja SHA-1, a wiec 160 bitow (20 bajtow) if(countHashFlag == BMDDVCS_HASH_AT_INPUT && data_for_hash->size != 20) { { BMD_FOK(-6); } } data->present=Data_PR_messageImprint; //oid SHA-1 ret_val=OBJECT_IDENTIFIER_set_arcs(&(data->choice.messageImprint.digestAlgorithm.algorithm), oid_sha1_tab, sizeof(oid_sha1_tab[0]), sizeof(oid_sha1_tab)/sizeof(oid_sha1_tab[0])); if(ret_val != 0) { BMD_FOK(-4); } // serdecznie pierdole data->choice.messageImprint.digestAlgorithm.parameters=(ANY_t*)calloc(1, sizeof(ANY_t)); data->choice.messageImprint.digestAlgorithm.parameters->size=2; data->choice.messageImprint.digestAlgorithm.parameters->buf=(uint8_t*)calloc(2, sizeof(uint8_t)); data->choice.messageImprint.digestAlgorithm.parameters->buf[1]=0x00; data->choice.messageImprint.digestAlgorithm.parameters->buf[0]=0x05; if(countHashFlag == BMDDVCS_COUNT_HASH) { //liczenie skrotu z danych za pomoca SHA-1 bmd_set_ctx_hash(&hash_context,BMD_HASH_ALGO_SHA1); bmd_hash_data(data_for_hash, &hash_context, &hash, NULL); bmd_ctx_destroy(&hash_context); } else { hash=data_for_hash; } ret_val=OCTET_STRING_fromBuf(&(data->choice.messageImprint.digest), (char *)hash->buf, hash->size); if(countHashFlag == BMDDVCS_COUNT_HASH) { free_gen_buf(&hash); } else { hash = NULL; } if(ret_val != 0) { BMD_FOK(-5); } return 0; }
int main() { asn_TYPE_descriptor_t *td = &asn_DEF_UserIdentifier; UserIdentifier_t user; UserIdentifier_t user_new; int ret; memset(&user, 0, sizeof user); memset(&user_new, 0, sizeof user_new); user.present = UserIdentifier_PR_phoneNumber; OCTET_STRING_fromBuf( &user.choice.phoneNumber, "0123456789", -1); /* Save->Load must succeed */ save_object(&user, td); ret = load_object(&user_new, td); assert(user_new.present == UserIdentifier_PR_phoneNumber); assert(ret == 0); printf("OK\n"); return ret; }
/* funkcja koduje do DER strukture DVCSRequest i wynik kodowania umieszcza w OCTET_STRING */ long _encode_DVCSRequest_to_eContent(DVCSRequest_t *req, OCTET_STRING_t **econtent) { OCTET_STRING_t *octet=NULL; GenBuf_t *tmp_buf=NULL; long status; if(req == NULL) { return -1; } if(econtent == NULL) { return -2; } if(*econtent != NULL) { return -3; } octet=(OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t)); if(octet == NULL) { return -4; } status=asn1_encode(&asn_DEF_DVCSRequest,req, NULL, &tmp_buf); if( status != BMD_OK ) return -5; status=OCTET_STRING_fromBuf(octet,(const char *)tmp_buf->buf,tmp_buf->size); free_gen_buf(&tmp_buf); if( status != 0 ) return -6; *econtent=octet; return 0; }
struct msgb *rua_new_dt(int is_ps, uint32_t context_id, struct msgb *inmsg) { RUA_DirectTransfer_t out; RUA_DirectTransferIEs_t ies; struct msgb *msg; uint32_t ctxidbuf; int rc; memset(&ies, 0, sizeof(ies)); if (is_ps) ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; else ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); OCTET_STRING_fromBuf(&ies.ranaP_Message, inmsg->data, msgb_length(inmsg)); msgb_free(inmsg); memset(&out, 0, sizeof(out)); rc = rua_encode_directtransferies(&out, &ies); if (rc < 0) return NULL; msg = rua_generate_initiating_message(RUA_ProcedureCode_id_DirectTransfer, RUA_Criticality_reject, &asn_DEF_RUA_DirectTransfer, &out); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_DirectTransfer, &out); DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); msgb_sctp_ppid(msg) = IUH_PPI_RUA; return msg; }
// Umieszczenie danych zaszyfrowanych i informacji o algorytmie // szyfrujacym w strukturze // WYKONYWANE SA KOPIE iv oraz data long EnvelopedData_set_EncryptedData(EnvelopedData_t *envData,GenBuf_t *iv,GenBuf_t *data,bmd_encryption_params_t *options) { long OID_id_data[] = {OID_CMS_ID_DATA_LONG}; /*long OID_id_DES_CBC[] = {1,3,14,3,2,7};*/ long OID_id_DES_EDE3_CBC[] = {1,2,840,113549,3,7}; long *oid; long oidsize; long err = 0; OCTET_STRING_t *oiv = NULL; // set data OID err = OBJECT_IDENTIFIER_set_arcs(&(envData->encryptedContentInfo.contentType),OID_id_data, sizeof(OID_id_data[0]), sizeof(OID_id_data)/sizeof(OID_id_data[0])); if ( err ) return err; // set Algorithm OID if ( options->encryption_algo == BMD_CRYPT_ALGO_DES3 ) { oid = OID_id_DES_EDE3_CBC; oidsize = sizeof(OID_id_DES_EDE3_CBC)/sizeof(OID_id_DES_EDE3_CBC[0]); } else return BMD_ERR_UNIMPLEMENTED; err = AlgorithmIdentifier_set_OID(&(envData->encryptedContentInfo.contentEncryptionAlgorithm),oid, oidsize); if ( err ) return err; // set Algorithm IV oiv = mallocStructure(sizeof(OCTET_STRING_t)); OCTET_STRING_fromBuf(oiv,(char *)iv->buf, iv->size); envData->encryptedContentInfo.contentEncryptionAlgorithm.parameters = mallocStructure(sizeof(ANY_t)); err = ANY_fromType(envData->encryptedContentInfo.contentEncryptionAlgorithm.parameters, &asn_DEF_OCTET_STRING, oiv); if ( err ) return ERR_OPERATION_FAILED; asn_DEF_OCTET_STRING.free_struct(&asn_DEF_OCTET_STRING,oiv, 0); if( options->encryption_type==BMD_CMS_ENV_INTERNAL ) { // set Encrypted Data envData->encryptedContentInfo.encryptedContent = mallocStructure(sizeof(EncryptedContent_t)); OCTET_STRING_fromBuf(envData->encryptedContentInfo.encryptedContent,(char *)data->buf, data->size); } return err; }
static unsigned char *prefixFingerprint(const CC *cond) { PrefixFingerprintContents_t *fp = calloc(1, sizeof(PrefixFingerprintContents_t)); //fprintf(stderr,"prefixfinger %p %p\n",fp,cond->prefix); asnCondition(cond->subcondition, &fp->subcondition); // TODO: check asnCondition for safety fp->maxMessageLength = cond->maxMessageLength; OCTET_STRING_fromBuf(&fp->prefix, cond->prefix, cond->prefixLength); return hashFingerprintContents(&asn_DEF_PrefixFingerprintContents, fp); }
static void _os_set (OCTET_STRING_t **pos, const void *s, gsize sSize) { if (*pos) OCTET_STRING_fromBuf(*pos, s, sSize); else *pos = OCTET_STRING_new_fromBuf(&asn_DEF_OCTET_STRING, s, sSize); }
int s1ap_eNB_generate_s1_setup_request(struct s1ap_eNB_description_s* eNB_ref) { SupportedTAs_Item_t ta; PLMNidentity_t plmnIdentity; S1SetupRequestIEs_t s1SetupRequest; char tac[] = { 0x00, 0x01 }; char identity[] = { 0x02, 0x08, 0x34 }; char eNBname[150]; int eNBnameLength = 0; uint8_t *buffer; uint32_t len; if (eNB_ref == NULL) return -1; memset((void *)&s1SetupRequest, 0, sizeof(S1SetupRequestIEs_t)); s1SetupRequest.global_ENB_ID.eNB_ID.present = ENB_ID_PR_macroENB_ID; s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.buf = calloc(1,3); s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.buf[0] = eNB_ref->eNB_id; s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.size = 3; s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.bits_unused = 4; OCTET_STRING_fromBuf(&s1SetupRequest.global_ENB_ID.pLMNidentity, identity, 3); eNBnameLength = sprintf(eNBname, "eNB %d Eurecom", eNB_ref->eNB_id); if (eNBnameLength > 0) { s1SetupRequest.presenceMask |= S1SETUPREQUESTIES_ENBNAME_PRESENT; OCTET_STRING_fromBuf(&s1SetupRequest.eNBname, eNBname, eNBnameLength); } memset((void *)&ta, 0, sizeof(SupportedTAs_Item_t)); memset((void *)&plmnIdentity, 0, sizeof(PLMNidentity_t)); OCTET_STRING_fromBuf(&ta.tAC, tac, 2); OCTET_STRING_fromBuf(&plmnIdentity, identity, 3); ASN_SEQUENCE_ADD(&ta.broadcastPLMNs, &plmnIdentity); ASN_SEQUENCE_ADD(&s1SetupRequest.supportedTAs, &ta); s1SetupRequest.defaultPagingDRX = PagingDRX_v64; if (s1ap_eNB_encode_s1_setup_request(&s1SetupRequest, &buffer, &len) < 0) return -1; eNB_ref->state |= S1AP_ENB_STATE_WAITING; return sctp_send_msg(eNB_ref->assocId, 0, buffer, len); }
static LDAPMessage_t *search_result_done(int messageId, LDAPDN_t *dn) { LDAPMessage_t *msg = calloc(1, sizeof *msg); SearchResultDone_t *done; msg->messageID = messageId; msg->protocolOp.present = LDAPMessage__protocolOp_PR_searchResDone; done = &msg->protocolOp.choice.searchResDone; asn_long2INTEGER(&done->resultCode, LDAPResult__resultCode_success); OCTET_STRING_fromBuf(&done->matchedDN, dn->buf, dn->size); OCTET_STRING_fromString(&done->diagnosticMessage, "OK"); return msg; }
int main ( int argc, char *argv[]) { asn_enc_rval_t retVal; uint8_t *buffer; uint32_t len; SupportedTAs_Item_t ta; PLMNidentity_t plmnIdentity; asn_debug = 0; asn1_xer_print = 0; S1SetupRequestIEs s1SetupRequest; memset (&s1SetupRequest, 0, sizeof (S1SetupRequestIEs)); s1SetupRequest.global_ENB_ID.eNB_ID.present = ENB_ID_PR_macroENB_ID; s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.buf = id; s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.size = 3; s1SetupRequest.global_ENB_ID.eNB_ID.choice.macroENB_ID.bits_unused = 4; OCTET_STRING_fromBuf (&s1SetupRequest.global_ENB_ID.pLMNidentity, identity, 3); s1SetupRequest.presenceMask |= S1SETUPREQUESTIES_ENBNAME_PRESENT; OCTET_STRING_fromBuf (&s1SetupRequest.eNBname, "ENB 1 eurecom", strlen ("ENB 1 eurecom")); memset (&ta, 0, sizeof (SupportedTAs_Item_t)); memset (&plmnIdentity, 0, sizeof (PLMNidentity_t)); OCTET_STRING_fromBuf (&ta.tAC, tac, 2); OCTET_STRING_fromBuf (&plmnIdentity, identity, 3); ASN_SEQUENCE_ADD (&ta.broadcastPLMNs, &plmnIdentity); ASN_SEQUENCE_ADD (&s1SetupRequest.supportedTAs, &ta); s1SetupRequest.defaultPagingDRX = PagingDRX_v64; s1ap_eNB_encode_s1setuprequest (&s1SetupRequest, &buffer, &len); assoc[0] = sctp_connect_to_remote_host (ip_addr, 36412, &recv_callback); sctp_send_msg (0, 0, buffer, len); free (buffer); // generateUplinkNASTransport(&buffer, &len); // sctp_send_msg(assoc[0], 0, buffer, len); // s1ap_mme_decode_pdu(buffer, len); pthread_join (sctp_get_receiver_thread (assoc[0]), NULL); return (0); }
static void load_table_header(sqlite3_stmt *stmt, Table_t *t) { guint32 i, max; for (i=0,max=sqlite3_data_count(stmt); i<max ;i++) { const char *cname = sqlite3_column_name(stmt, i); struct RowName *rname = calloc(1, sizeof(*rname)); asn_uint32_to_INTEGER(&(rname->pos), i); OCTET_STRING_fromBuf(&(rname->name), cname, strlen(cname)); asn_sequence_add(&(t->header.list), rname); } }
static LDAPMessage_t *bind_response_ok(int messageId, LDAPDN_t *dn) { LDAPMessage_t *msg = calloc(1, sizeof *msg); BindResponse_t *resp; msg->messageID = messageId; msg->protocolOp.present = LDAPMessage__protocolOp_PR_bindResponse; resp = &msg->protocolOp.choice.bindResponse; asn_long2INTEGER(&resp->resultCode, BindResponse__resultCode_success); OCTET_STRING_fromBuf(&resp->matchedDN, dn->buf, dn->size); OCTET_STRING_fromString(&resp->diagnosticMessage, "OK"); return msg; }
// Ustawienie pola z sygnatura struktury SignerInfo // Wykonywana jest kopia sygnatury long SignerInfo_set_Signature( SignerInfo_t *signerInfo, GenBuf_t *signature) { long err = 0; if ( signerInfo == NULL ) return ERR_WRONG_ARGUMENT; err = OCTET_STRING_fromBuf(&(signerInfo->signature), (char *)signature->buf, signature->size); if ( err != 0 ) return err; return 0; }
static Fulfillment_t *prefixToFulfillment(const CC *cond) { Fulfillment_t *ffill = asnFulfillmentNew(cond->subcondition); if (!ffill) { return NULL; } PrefixFulfillment_t *pf = calloc(1, sizeof(PrefixFulfillment_t)); OCTET_STRING_fromBuf(&pf->prefix, cond->prefix, cond->prefixLength); pf->maxMessageLength = cond->maxMessageLength; pf->subfulfillment = ffill; ffill = calloc(1, sizeof(Fulfillment_t)); ffill->present = Fulfillment_PR_prefixSha256; ffill->choice.prefixSha256 = pf; return ffill; }
void ldap_bind(int msgid, BindRequest_t *req, ev_loop *loop, ev_io *watcher) { ev_tstamp delay = 0.0; LDAPMessage_t *res = XNEW0(LDAPMessage_t, 1); res->messageID = msgid; res->protocolOp.present = LDAPMessage__protocolOp_PR_bindResponse; BindResponse_t *bindResponse = &res->protocolOp.choice.bindResponse; OCTET_STRING_fromBuf(&bindResponse->matchedDN, (const char *)req->name.buf, req->name.size); if (setting_anonymous && req->name.size == 0) { /* allow anonymous */ asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_success); } else if (req->authentication.present == AuthenticationChoice_PR_simple) { /* simple auth */ char *user = cn2name((const char *)req->name.buf); char *pw = (char *)req->authentication.choice.simple.buf; char *status = NULL; if (!user) { asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_invalidDNSyntax); } else if (PAM_SUCCESS != auth_pam(user, pw, &status, &delay)) { asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_invalidCredentials); OCTET_STRING_fromString(&bindResponse->diagnosticMessage, status); } else { /* Success! */ asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_success); } free(user); free(status); } else { /* sasl or anonymous auth */ asn_long2INTEGER(&bindResponse->resultCode, BindResponse__resultCode_authMethodNotSupported); } if (delay > 0.0) { ev_timer *delay_timer = XNEW(ev_timer, 1); delay_data_t *data = XNEW(delay_data_t, 1); data->message = res; data->watcher = watcher; ev_timer_init(delay_timer, delay_cb, delay, 0.0); delay_timer->data = data; /* Stop the connection watcher to stop other requests while delayed. */ ev_io_stop(loop, watcher); ev_timer_start(loop, delay_timer); } else { ldap_send(res, loop, watcher); ldapmessage_free(res); } }
GByteArray* sqlx_pack_QUERY_single(struct sqlx_name_s *name, const gchar *query, gboolean autocreate) { EXTRA_ASSERT(name != NULL); EXTRA_ASSERT(query != NULL); struct Table *t = calloc(1, sizeof(Table_t)); OCTET_STRING_fromBuf(&(t->name), query, strlen(query)); struct TableSequence *ts = calloc(1, sizeof(TableSequence_t)); asn_sequence_add(&(ts->list), t); GByteArray *req = sqlx_pack_QUERY(name, query, ts, autocreate); asn_DEF_TableSequence.free_struct(&asn_DEF_TableSequence, ts, FALSE); return req; }
// ustawienie danych struktury SignedData // wykonywana jest kopia na podstawie tworzenia OCTET_STRING // z przekazanych danych long SignedData_set_Content( SignedData_t *sigData, GenBuf_t *buf) { long err = 0; if ((sigData == NULL) || (buf == NULL)) return ERR_WRONG_ARGUMENT; sigData->encapContentInfo.eContent = mallocStructure(sizeof(OCTET_STRING_t)); if ( sigData->encapContentInfo.eContent == NULL ) return ERR_NO_MEMORY; // memset(sigData->encapContentInfo.eContent, 0, sizeof(OCTET_STRING_t)); err = OCTET_STRING_fromBuf(sigData->encapContentInfo.eContent, (char *)buf->buf, buf->size); if ( err != 0 ) return err; return err; }
GByteArray* version_encode(GTree *t) { asn_enc_rval_t rv; GByteArray *encoded; struct BaseVersion bv; gboolean runner(gpointer _k, gpointer _v, gpointer _u) { (void) _u; if (_k && _v && hashstr_len(_k) > 0) { struct object_version_s *v = _v; struct TableVersion *tv = g_malloc0(sizeof(*tv)); OCTET_STRING_fromBuf(&(tv->name), hashstr_str(_k), hashstr_len(_k)); asn_int64_to_INTEGER(&(tv->version), v->version); asn_int64_to_INTEGER(&(tv->when), v->when); asn_sequence_add(&(bv.list), tv); } return FALSE; }
//dodawanie danych w przypadku uslugi- wrzucany DER z dowolnej zawartosci (DER w GenBuf) long _add_to_Data_CPD(GenBuf_t *der, Data_t *data) { long ret_val=0; if(der == NULL) { return -1; } if(der->buf == NULL) { return -2; } if(data == NULL) { return -3; } data->present=Data_PR_message; ret_val=OCTET_STRING_fromBuf(&(data->choice.message), (char *)der->buf, der->size); if(ret_val != 0) { return -4; } return 0; }
struct msgb *rua_new_disc(int is_ps, uint32_t context_id, struct msgb *inmsg) { RUA_Disconnect_t out; RUA_DisconnectIEs_t ies; struct msgb *msg; uint32_t ctxidbuf; int rc; memset(&ies, 0, sizeof(ies)); if (is_ps) ies.cN_DomainIndicator = RUA_CN_DomainIndicator_ps_domain; else ies.cN_DomainIndicator = RUA_CN_DomainIndicator_cs_domain; asn1_u24_to_bitstring(&ies.context_ID, &ctxidbuf, context_id); /* FIXME: make cause configurable */ ies.cause.present = RUA_Cause_PR_radioNetwork; ies.cause.choice.radioNetwork = RUA_CauseRadioNetwork_normal; if (inmsg && inmsg->data&& msgb_length(inmsg)) { ies.presenceMask |= DISCONNECTIES_RUA_RANAP_MESSAGE_PRESENT; OCTET_STRING_fromBuf(&ies.ranaP_Message, inmsg->data, msgb_length(inmsg)); } msgb_free(inmsg); memset(&out, 0, sizeof(out)); rc = rua_encode_disconnecties(&out, &ies); if (rc < 0) return NULL; msg = rua_generate_initiating_message(RUA_ProcedureCode_id_Disconnect, RUA_Criticality_reject, &asn_DEF_RUA_Disconnect, &out); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RUA_Disconnect, &out); DEBUGP(DMAIN, "transmitting RUA payload of %u bytes\n", msgb_length(msg)); msgb_sctp_ppid(msg) = IUH_PPI_RUA; return msg; }
static void check_serialize() { LogLine_t ll; VariablePartSet_t *vps; VariablePart_t *vp; VisibleString_t *vpart; asn_enc_rval_t erval; int i; memset(&ll, 0, sizeof(ll)); vps = calloc(1, sizeof(*vps)); vp = calloc(1, sizeof(*vp)); vpart = OCTET_STRING_new_fromBuf(&asn_DEF_VisibleString, "123", 3); vp->present = VariablePart_PR_vset; ASN_SET_ADD(&vp->choice.vset, vpart); vps->resolution.accept_as = accept_as_unknown; ASN_SEQUENCE_ADD(&vps->vparts, vp); ASN_SEQUENCE_ADD(&ll.varsets, vps); OCTET_STRING_fromBuf(&ll.line_digest, "zzz\007", 4); asn_fprint(stderr, &asn_DEF_LogLine, &ll); buf_size = 128; uint8_t scratch[buf_size]; buf = scratch; erval = der_encode(&asn_DEF_LogLine, &ll, buf_fill, 0); assert(erval.encoded > 1); fprintf(stderr, "Encoded in %zd bytes\n", erval.encoded); fprintf(stderr, "\n"); for(i = 0; i < buf_pos; i++) { fprintf(stderr, "%d ", buf[i]); } fprintf(stderr, "\n\n"); assert(erval.encoded == sizeof(buf0)); assert(memcmp(buf0, buf, sizeof(buf0)) == 0); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LogLine, &ll); return; }
GByteArray* sqlx_pack_QUERY_single(struct sqlx_name_s *name, const gchar *query, gboolean autocreate) { EXTRA_ASSERT(name != NULL); EXTRA_ASSERT(query != NULL); MESSAGE req = make_request(NAME_MSGNAME_SQLX_QUERY, name); guint8 ac = (guint8) autocreate; do { Table_t *t = g_malloc0(sizeof(Table_t)); OCTET_STRING_fromBuf(&(t->name), query, strlen(query)); TableSequence_t *ts = g_malloc0(sizeof(TableSequence_t)); asn_sequence_add(&(ts->list), t); metautils_message_add_body_unref(req, sqlx_encode_TableSequence(ts, NULL)); metautils_message_add_field(req, NAME_MSGKEY_AUTOCREATE, &ac, 1); asn_DEF_TableSequence.free_struct(&asn_DEF_TableSequence, ts, FALSE); } while (0); return message_marshall_gba_and_clean(req); }
GByteArray* sqlx_pack_QUERY_single(struct sqlxsrv_name_s *name, const gchar *query, gboolean autocreate) { struct message_s *req = NULL; guint8 ac = (guint8) autocreate; EXTRA_ASSERT(name != NULL); EXTRA_ASSERT(query != NULL); req = make_srv_request("SQLX_QUERY", name); g_assert(req != NULL); do { Table_t *t; TableSequence_t *ts; GByteArray *body; t = g_malloc0(sizeof(Table_t)); g_assert(t != NULL); ts = g_malloc0(sizeof(TableSequence_t)); g_assert(ts != NULL); OCTET_STRING_fromBuf(&(t->name), query, strlen(query)); asn_sequence_add(&(ts->list), t); body = sqlx_encode_TableSequence(ts, NULL); g_assert(body != NULL); message_set_BODY(req, body->data, body->len, NULL); message_add_field(req, "AUTOCREATE", 10, &ac, 1, NULL); asn_DEF_TableSequence.free_struct(&asn_DEF_TableSequence, ts, FALSE); g_byte_array_free(body, TRUE); } while (0); return message_marshall_gba_and_clean(req); }
static int s1ap_eNB_generate_s1_setup_request( s1ap_eNB_instance_t *instance_p, s1ap_eNB_mme_data_t *s1ap_mme_data_p) { s1ap_message message; S1ap_S1SetupRequestIEs_t *s1SetupRequest_p; S1ap_PLMNidentity_t plmnIdentity; S1ap_SupportedTAs_Item_t ta; uint8_t *buffer; uint32_t len; int ret = 0; DevAssert(instance_p != NULL); DevAssert(s1ap_mme_data_p != NULL); memset(&message, 0, sizeof(s1ap_message)); message.direction = S1AP_PDU_PR_initiatingMessage; message.procedureCode = S1ap_ProcedureCode_id_S1Setup; message.criticality = S1ap_Criticality_reject; s1SetupRequest_p = &message.msg.s1ap_S1SetupRequestIEs; memset((void *)&plmnIdentity, 0, sizeof(S1ap_PLMNidentity_t)); memset((void *)&ta, 0, sizeof(S1ap_SupportedTAs_Item_t)); s1ap_mme_data_p->state = S1AP_ENB_STATE_WAITING; s1SetupRequest_p->global_ENB_ID.eNB_ID.present = S1ap_ENB_ID_PR_macroENB_ID; MACRO_ENB_ID_TO_BIT_STRING(instance_p->eNB_id, &s1SetupRequest_p->global_ENB_ID.eNB_ID.choice.macroENB_ID); MCC_MNC_TO_PLMNID(instance_p->mcc, instance_p->mnc, instance_p->mnc_digit_length, &s1SetupRequest_p->global_ENB_ID.pLMNidentity); S1AP_INFO("%d -> %02x%02x%02x\n", instance_p->eNB_id, s1SetupRequest_p->global_ENB_ID.eNB_ID.choice.macroENB_ID.buf[0], s1SetupRequest_p->global_ENB_ID.eNB_ID.choice.macroENB_ID.buf[1], s1SetupRequest_p->global_ENB_ID.eNB_ID.choice.macroENB_ID.buf[2]); INT16_TO_OCTET_STRING(instance_p->tac, &ta.tAC); MCC_MNC_TO_TBCD(instance_p->mcc, instance_p->mnc, instance_p->mnc_digit_length, &plmnIdentity); ASN_SEQUENCE_ADD(&ta.broadcastPLMNs.list, &plmnIdentity); ASN_SEQUENCE_ADD(&s1SetupRequest_p->supportedTAs.list, &ta); s1SetupRequest_p->defaultPagingDRX = instance_p->default_drx; if (instance_p->eNB_name != NULL) { s1SetupRequest_p->presenceMask |= S1AP_S1SETUPREQUESTIES_ENBNAME_PRESENT; OCTET_STRING_fromBuf(&s1SetupRequest_p->eNBname, instance_p->eNB_name, strlen(instance_p->eNB_name)); } if (s1ap_eNB_encode_pdu(&message, &buffer, &len) < 0) { S1AP_ERROR("Failed to encode S1 setup request\n"); return -1; } /* Non UE-Associated signalling -> stream = 0 */ s1ap_eNB_itti_send_sctp_data_req(instance_p->instance, s1ap_mme_data_p->assoc_id, buffer, len, 0); return ret; }
int main() { /* Initialize values which can't use static initializers. */ asn_long2INTEGER(&otp_format, 2); /* Alphanumeric */ OBJECT_IDENTIFIER_set_arcs(&alg_sha256.algorithm, sha256_arcs, sizeof(*sha256_arcs), sizeof(sha256_arcs) / sizeof(*sha256_arcs)); OBJECT_IDENTIFIER_set_arcs(&alg_sha1.algorithm, sha1_arcs, sizeof(*sha1_arcs), sizeof(sha1_arcs) / sizeof(*sha1_arcs)); OBJECT_IDENTIFIER_set_arcs(&other_info.algorithmID.algorithm, krb5_arcs, sizeof(*krb5_arcs), sizeof(krb5_arcs) / sizeof(*krb5_arcs)); printf("PrincipalName:\n"); der_encode(&asn_DEF_PrincipalName, &princ, consume, NULL); printbuf(); /* Print this encoding and also use it to initialize two fields of * other_info. */ printf("\nKRB5PrincipalName:\n"); der_encode(&asn_DEF_KRB5PrincipalName, &krb5princ, consume, NULL); OCTET_STRING_fromBuf(&other_info.partyUInfo, buf, buf_pos); OCTET_STRING_fromBuf(&other_info.partyVInfo, buf, buf_pos); printbuf(); printf("\nOtherInfo:\n"); der_encode(&asn_DEF_OtherInfo, &other_info, consume, NULL); printbuf(); free(other_info.partyUInfo.buf); free(other_info.partyVInfo.buf); printf("\nPkinitSuppPubInfo:\n"); der_encode(&asn_DEF_PkinitSuppPubInfo, &supp_pub_info, consume, NULL); printbuf(); printf("\nMinimal OTP-TOKEN-INFO:\n"); der_encode(&asn_DEF_OTP_TOKENINFO, &token_info_1, consume, NULL); printbuf(); printf("\nMaximal OTP-TOKEN-INFO:\n"); der_encode(&asn_DEF_OTP_TOKENINFO, &token_info_2, consume, NULL); printbuf(); printf("\nMinimal PA-OTP-CHALLENGE:\n"); der_encode(&asn_DEF_PA_OTP_CHALLENGE, &challenge_1, consume, NULL); printbuf(); printf("\nMaximal PA-OTP-CHALLENGE:\n"); der_encode(&asn_DEF_PA_OTP_CHALLENGE, &challenge_2, consume, NULL); printbuf(); printf("\nMinimal PA-OTP-REQUEST:\n"); der_encode(&asn_DEF_PA_OTP_REQUEST, &request_1, consume, NULL); printbuf(); printf("\nMaximal PA-OTP-REQUEST:\n"); der_encode(&asn_DEF_PA_OTP_REQUEST, &request_2, consume, NULL); printbuf(); printf("\nPA-OTP-ENC-REQUEST:\n"); der_encode(&asn_DEF_PA_OTP_ENC_REQUEST, &enc_request, consume, NULL); printbuf(); printf("\n"); return 0; }
static unsigned char *ed25519Fingerprint(const CC *cond) { Ed25519FingerprintContents_t *fp = calloc(1, sizeof(Ed25519FingerprintContents_t)); //fprintf(stderr,"ed25519 fingerprint %p %p\n",fp,cond->publicKey); OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, 32); return hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp); }