Пример #1
0
void test_P2pRequest_dnm()
{
	/// Building a P2pRequest ///
	int ret;
	uint8_t macAddrSrc[ETH_ALEN] = { 0xe6, 0x1b, 0x23, 0x0c, 0x0c, 0x5d };
	uint8_t macAddrDst[ETH_ALEN] = { 0xe6, 0x1b, 0x23, 0x0c, 0x0c, 0x5d };

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dnm);	// Dynamic Network Message

	DNMessage_set_seqNumber(msg, 801);
	DNMessage_set_ackNumber(msg, 0);
	DNMessage_set_operation(msg, dnop_PR_p2pRequest);

	P2pRequest_set_ipAddrDst(msg, "66.55.44.33");
	P2pRequest_set_port(msg, 9000);
	P2pRequest_set_side(msg, P2pSide_client);
	P2pRequest_set_macAddrDst(msg, macAddrDst);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #2
0
void test_P2pResponse_dnm()
{
	/// Building a P2pRequest ///

	uint8_t macAddrDst[ETH_ALEN] = { 0xaf, 0xbe, 0xcd, 0xdc, 0xeb, 0xfa };

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dnm);	// Dynamic Network Message

	DNMessage_set_seqNumber(msg, 0);
	DNMessage_set_ackNumber(msg, 801);
	DNMessage_set_operation(msg, dnop_PR_p2pResponse);

	P2pResponse_set_macAddrDst(msg, macAddrDst);
	P2pResponse_set_result(msg, DNDSResult_success);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #3
0
void test_ModifyResponse()
{
	/// Building a ModifyResponse ///

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 0);
	DSMessage_set_ackNumber(msg, 300);
	DSMessage_set_operation(msg, dsop_PR_modifyResponse);

	ModifyResponse_set_result(msg, DNDSResult_success);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #4
0
void test_DelRequest()
{
#if 0
	/// Building a DelRequest ///

	DNDSMessage_t *msg;	// a DNDS Message
	DNDSObject_t *objAcl;	// a DNDS Object

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);	// Directory Service Message

	DSMessage_set_seqNumber(msg, 200);
	DSMessage_set_ackNumber(msg, 0);
	DSMessage_set_operation(msg, dsop_PR_delRequest);

	DelRequest_set_objectType(msg, DNDSObject_PR_acl, &objAcl);

	Acl_set_id(objAcl, 1);
	Acl_set_contextId(objAcl, 2);
	Acl_set_description(objAcl, "une description", 15);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
#endif
}
Пример #5
0
void test_ModifyRequest()
{
#if 0
	/// Building a ModifyRequest ///

	DNDSMessage_t *msg;		// a DNDS Message
	DNDSObject_t *objAclGroup;

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 300);
	DSMessage_set_ackNumber(msg, 0);
	DSMessage_set_operation(msg, dsop_PR_modifyRequest);

	ModifyRequest_set_objectType(msg, DNDSObject_PR_aclgroup, &objAclGroup);

	AclGroup_set_id(objAclGroup, 1);
	AclGroup_set_contextId(objAclGroup, 1);
	AclGroup_set_name(objAclGroup, "group-name", 10);
	AclGroup_set_description(objAclGroup, "a description", 13);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
#endif
}
Пример #6
0
void test_AuthResponse_dnm()
{
	/// Building an AuthRequest ///

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dnm);	// Dynamic Network Message

	DNMessage_set_seqNumber(msg, 0);
	DNMessage_set_ackNumber(msg, 100);
	DNMessage_set_operation(msg, dnop_PR_authResponse);

	AuthResponse_set_result(msg, DNDSResult_success);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #7
0
void test_AuthRequest()
{
	/// Building an AuthRequest ///

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);	// Directory Service Message

	DSMessage_set_seqNumber(msg, 100);
	DSMessage_set_ackNumber(msg, 0);
	DSMessage_set_operation(msg, dnop_PR_authRequest);

	AuthRequest_set_certName(msg, "nib@1", 5);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #8
0
static void on_secure(netc_t *netc)
{
	struct session *session;
	session = netc->ext_ptr;

	if (session->state == SESSION_STATE_WAIT_STEPUP) {

		/* Set the session as authenticated */
		session->state = SESSION_STATE_AUTHED;

		/* Send a message to acknowledge the client */
		DNDSMessage_t *msg = NULL;
		DNDSMessage_new(&msg);
		DNDSMessage_set_channel(msg, 0);
		DNDSMessage_set_pdu(msg, pdu_PR_dnm);

		DNMessage_set_seqNumber(msg, 1);
		DNMessage_set_ackNumber(msg, 0);
		DNMessage_set_operation(msg, dnop_PR_authResponse);

		AuthResponse_set_result(msg, DNDSResult_success);
		net_send_msg(session->netc, msg);
		DNDSMessage_del(msg);

		context_add_session(session->context, session);
		jlog(L_DEBUG, "session id: %d", session->id);
	}
}
Пример #9
0
void test_SearchRequest_context()
{
	/// Building a SearchRequest context ///
	int ret;

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);	// Directory Service Message

	DSMessage_set_seqNumber(msg, 800);
	DSMessage_set_ackNumber(msg, 0);
	DSMessage_set_operation(msg, dsop_PR_searchRequest);

	SearchRequest_set_searchType(msg, SearchType_all);
	SearchRequest_set_objectName(msg, ObjectName_context);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);

}
Пример #10
0
void test_NodeConnectInfo()
{
	/// Building a NodeConnectInfo ///
	int ret;

	DNDSMessage_t *msg;

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);	// Directory Service Message

	DSMessage_set_seqNumber(msg, 800);
	DSMessage_set_ackNumber(msg, 0);
	//DSMessage_set_operation(msg, dsop_PR_nodeConnectInfo);

	//NodeConnectInfo_set_certName(msg, "unique_name@context", 19);
	//NodeConnectInfo_set_ipAddr(msg, "44.128.0.1");
	//NodeConnectInfo_set_state(msg, ConnectState_connected);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #11
0
test_AddRequest_node()
{
	/// Building node AddRequest ///

	DNDSMessage_t *msg;
	DNDSObject_t *obj;

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 0);
	DSMessage_set_ackNumber(msg, 0);
	DSMessage_set_operation(msg, dsop_PR_addRequest);

	AddRequest_set_objectType(msg, DNDSObject_PR_node, &obj);

	Node_set_contextId(obj, 100);
	Node_set_description(obj, "voip node 1", 11);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #12
0
test_AddRequest_context()
{
	/// Building context AddRequest ///

	DNDSMessage_t *msg;
	DNDSObject_t *obj;

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 0);
	DSMessage_set_ackNumber(msg, 0);
	DSMessage_set_operation(msg, dsop_PR_addRequest);

	AddRequest_set_objectType(msg, DNDSObject_PR_context, &obj);

	Context_set_clientId(obj, 100);
	Context_set_description(obj, "home network1", 13);
	Context_set_network(obj, "44.128.0.0");
	Context_set_netmask(obj, "255.255.255.0");

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #13
0
void test_NetinfoResponse()
{
	/// Building a NetinfoResponse ///

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dnm);

	DNMessage_set_seqNumber(msg, 0);
	DNMessage_set_ackNumber(msg, 600);
	DNMessage_set_operation(msg, dnop_PR_netinfoResponse);

	NetinfoResponse_set_ipAddress(msg, "192.168.10.5");
	NetinfoResponse_set_netmask(msg, "255.255.255.0");
	NetinfoResponse_set_result(msg, DNDSResult_success);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #14
0
void test_DNDS_ethernet()
{
	/// Building an message ethernet frame ///

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_ethernet);	// ethernet frame

	uint8_t *frame = strdup("0110101010101");
	size_t frame_size = 13;

	DNDSMessage_set_ethernet(msg, frame, frame_size);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	// XXX free(frame)
	DNDSMessage_del(msg);
}
Пример #15
0
void test_TerminateRequest()
{
	/// Building a TerminateRequest ///

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 0);
	DSMessage_set_ackNumber(msg, 400);
	DSMessage_set_operation(msg, dsop_PR_terminateRequest);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #16
0
void test_NetinfoRequest()
{
	/// Building a NetinfoRequest ///

	DNDSMessage_t *msg;	// a DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dnm);

	DNMessage_set_seqNumber(msg, 600);
	DNMessage_set_ackNumber(msg, 0);
	DNMessage_set_operation(msg, dnop_PR_netinfoRequest);

	uint8_t macAddr[ETH_ALEN] = { 0xd, 0xe, 0xa, 0xd, 0xb, 0xe };

	NetinfoRequest_set_ipLocal(msg, "192.168.10.10");
	NetinfoRequest_set_macAddr(msg, macAddr);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #17
0
void test_SearchResponse()
{

	printf("TEST SEARCH RESPONSE\n");

	/// Building a SearchResponse

	DNDSMessage_t *msg;	// A DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 0);
	DSMessage_set_ackNumber(msg, 1);
	DSMessage_set_action(msg, action_listNode);
	DSMessage_set_operation(msg, dsop_PR_searchResponse);

	SearchResponse_set_result(msg, DNDSResult_success);
	SearchResponse_set_searchType(msg, SearchType_object);
/*
/// objContext
	DNDSObject_t *objContext;
	DNDSObject_new(&objContext);
	DNDSObject_set_objectType(objContext, DNDSObject_PR_context);

	Context_set_id(objContext, 40);
	SearchResponse_add_object(msg, objContext);
*/
/// Node
	DNDSObject_t *objNode;
	DNDSObject_new(&objNode);
	DNDSObject_set_objectType(objNode, DNDSObject_PR_node);

//	Node_set_contextId(objNode, 10);
	Node_set_description(objNode, "yo", strlen("yo"));
	Node_set_uuid(objNode, "abc", strlen("abc"));
	Node_set_certificate(objNode, "certificate", 11);
	Node_set_certificateKey(objNode, "key", 3);
	Node_set_status(objNode, 2);

	SearchResponse_add_object(msg, objNode);


	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #18
0
void transmit_netinfo_response(netc_t *netc)
{
	struct session *session = netc->ext_ptr;

	DNDSMessage_t *msg = NULL;
	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dnm);

	DNMessage_set_seqNumber(msg, 1);
	DNMessage_set_ackNumber(msg, 0);
	DNMessage_set_operation(msg, dnop_PR_netinfoResponse);

	net_send_msg(session->netc, msg);
	DNDSMessage_del(msg);
	transmit_node_connectinfo(ConnectState_connected,
				session->ip, session->cert_name);
}
Пример #19
0
void test_SearchResponse_context()
{
	/// Building a SearchResponse

	DNDSMessage_t *msg;	// A DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 0);
	DSMessage_set_ackNumber(msg, 400);
	DSMessage_set_operation(msg, dsop_PR_searchResponse);

	SearchResponse_set_result(msg, DNDSResult_success);

	DNDSObject_t *objContext;
	DNDSObject_new(&objContext);
	DNDSObject_set_objectType(objContext, DNDSObject_PR_context);

	Context_set_id(objContext, 10);
	Context_set_topology(objContext, Topology_mesh);
	Context_set_description(objContext, "home network", 12);
	Context_set_network(objContext, "44.128.0.0");
	Context_set_netmask(objContext, "255.255.0.0");
	Context_set_serverCert(objContext, "serverCert", 10);
	Context_set_serverPrivkey(objContext, "serverPrivkey", 13);
	Context_set_trustedCert(objContext, "trustedCert", 11);

	SearchResponse_add_object(msg, objContext);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);

}
Пример #20
0
void test_AddRequest()
{
	/// Building a AddRequest ///

	DNDSMessage_t *msg;		// a DNDS Message
	DNDSObject_t *objClient;	// a DS Object

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);	// Directory Service Message

	DSMessage_set_seqNumber(msg, 4034);
	DSMessage_set_ackNumber(msg, 0);	// seq XOR ack
	DSMessage_set_operation(msg, dsop_PR_addRequest);

	AddRequest_set_objectType(msg, DNDSObject_PR_client, &objClient);

	Client_set_id(objClient, 987);
	Client_set_firstname(objClient, "firstname", 9);
	Client_set_lastname(objClient, "lastname", 8);
	Client_set_email(objClient, "*****@*****.**", 15);
	Client_set_password(objClient, "password", 8);
	Client_set_company(objClient, "mycompany", 9);
	Client_set_phone(objClient, "thephone", 8);
	Client_set_country(objClient, "mycountry", 9);
	Client_set_stateProvince(objClient, "stateProvince", 13);
	Client_set_city(objClient, "mycity", 6);
	Client_set_postalCode(objClient, "postalCode", 10);
	Client_set_status(objClient, 0);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}
Пример #21
0
void test_SearchRequest()
{
	/// Building a SearchRequest()

	DNDSMessage_t *msg;	// a DNDS Message
	DNDSObject_t *objNode; // a DNDS Object

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 400);
	DSMessage_set_ackNumber(msg, 0);
	DSMessage_set_operation(msg, dsop_PR_searchRequest);

	SearchRequest_set_searchType(msg, SearchType_object);


	DNDSObject_new(&objNode);
	DNDSObject_set_objectType(objNode, DNDSObject_PR_node);

	Node_set_contextId(objNode, 0);
	Node_set_provCode(objNode, "secret-prov-code", strlen("secret-prov-code"));
	Node_set_ipAddress(objNode, "127.0.0.1");

	SearchRequest_set_object(msg, objNode);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);

}
Пример #22
0
void test_AddRequest()
{
	/// Building a AddRequest ///

	DNDSMessage_t *msg;		// a DNDS Message
	DNDSObject_t *objClient;	// a DS Object

	DNDSMessage_new(&msg);
//	DNDSMessage_set_version(msg, 1);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);	// Directory Service Message

	DSMessage_set_seqNumber(msg, 1);
	DSMessage_set_ackNumber(msg, 1);	// seq XOR ack
	DSMessage_set_operation(msg, dsop_PR_addRequest);
//	DSMessage_set_action(msg, action_addClient);

	AddRequest_set_objectType(msg, DNDSObject_PR_client, &objClient);

//	Client_set_id(objClient, 987);
	Client_set_email(objClient, "test@test", 9);
	Client_set_password(objClient, "test", 4);
//	Client_set_status(objClient, 0);

	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	asn_fprint(stdout, &asn_DEF_DNDSMessage, msg);


	DNDSMessage_del(msg);
}
Пример #23
0
int
provisioning(json_t *jmsg)
{
	char		*cert;
	char		*ipaddr;
	char		*pkey;
	char		*response;
	char		*tcert;
	char		*tid;
	json_t		*node;
	struct session	*session;

	if (json_unpack(jmsg, "{s:s}", "response", &response) == -1) {
		jlog(L_ERROR, "json_unpack failed");
		return -1;
	}

	if (strcmp(response, "success") != 0) {
		jlog(L_ERROR, "provisioning != success");
		return -1;
	}

	if (json_unpack(jmsg, "{s:s}", "tid", &tid) == -1) {
		jlog(L_ERROR, "json_unpack failed");
		return -1;
	}

	if ((node = json_object_get(jmsg, "node")) == NULL) {
		jlog(L_ERROR, "json_object_get failed");
		return -1;
	}

	if (json_unpack(node, "{s:s}", "cert", &cert) == -1 ||
	    json_unpack(node, "{s:s}", "pkey", &pkey) == -1 ||
	    json_unpack(node, "{s:s}", "tcert", &tcert) == -1 ||
	    json_unpack(node, "{s:s}", "ipaddr", &ipaddr) == -1) {
		jlog(L_ERROR, "NULL parameter");
		return -1;
	}

	DNDSMessage_t *new_msg;
	DNDSMessage_new(&new_msg);
	DNDSMessage_set_channel(new_msg, 0);
	DNDSMessage_set_pdu(new_msg, pdu_PR_dnm);

	DNMessage_set_operation(new_msg, dnop_PR_provResponse);

	ProvResponse_set_certificate(new_msg, cert, strlen(cert));
	ProvResponse_set_certificateKey(new_msg, (uint8_t*)pkey, strlen(pkey));
	ProvResponse_set_trustedCert(new_msg, (uint8_t*)tcert, strlen(tcert));
	ProvResponse_set_ipAddress(new_msg, ipaddr);

	session = session_tracking_table[atoi(tid) % MAX_SESSION];
	session_tracking_table[atoi(tid) % MAX_SESSION] = NULL;
	if (session)
		net_send_msg(session->netc, new_msg);
	DNDSMessage_del(new_msg);

	/* XXX
	 * If the provisioning is not a success,
	 * we must disconnect the client.
	 */

	return 0;
}
Пример #24
0
/* Authentication Request from the node */
int
authRequest(struct session *session, DNDSMessage_t *req_msg)
{
	char		*certName = NULL;
	size_t	 	 length = 0;

	struct session *old_session = NULL;

	if (session->state != SESSION_STATE_NOT_AUTHED) {
		jlog(L_WARNING, "authRequest duplicate");
		return -1;
	}

	DNDSMessage_t *msg = NULL;

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dnm);

	DNMessage_set_seqNumber(msg, 1);
	DNMessage_set_ackNumber(msg, 0);
	DNMessage_set_operation(msg, dnop_PR_authResponse);

	AuthRequest_get_certName(req_msg, &certName, &length);

	jlog(L_DEBUG, "URI:%s", certName);
	session->node_info = cn2node_info(certName);
	if (session->node_info == NULL) {
		jlog(L_WARNING, "cn2node_info failed");
		DNDSMessage_del(msg);
		return -1;
	}

//	jlog(L_DEBUG, "type: %s", session->node_info->type);
	jlog(L_DEBUG, "uuid: %s", session->node_info->uuid);
	jlog(L_DEBUG, "network_uuid: %s", session->node_info->network_uuid);
	jlog(L_DEBUG, "network_id: %s", session->node_info->network_id);
	jlog(L_DEBUG, "v: %d", session->node_info->v);

	if (session->node_info->v == 1) {
		session->vnetwork = vnetwork_lookup_id(session->node_info->network_id);
		if (session->vnetwork != NULL) {
			strncpy(session->node_info->network_uuid, session->vnetwork->uuid, 36);
			session->node_info->network_uuid[36] = '\0';
		}
	} else
		session->vnetwork = vnetwork_lookup(session->node_info->network_uuid);

	if (session->vnetwork == NULL) {
		AuthResponse_set_result(msg, DNDSResult_noRight);
		net_send_msg(session->netc, msg);
		DNDSMessage_del(msg);
		return -1;
	}

	/* check if the node's uuid is known
	if (ctable_find(session->context->atable, session->node_info->uuid) == NULL) {
		AuthResponse_set_result(msg, DNDSResult_noRight);
		net_send_msg(session->netc, msg);
		DNDSMessage_del(msg);
		jlog(L_ERROR, "authentication failed, invalid certificate");
		return -1;
	}
	*/

	/* check if the node is already connected */
	old_session = ctable_find(session->vnetwork->ctable, session->node_info->uuid);
//	if (old_session == NULL) {
		ctable_insert(session->vnetwork->ctable, session->node_info->uuid, session);
/*
	} else {
		// that node is already connected, if the new session is from the same IP
		// disconnect the old session, and let this one connect
		if (old_session->ip == NULL) {
			net_disconnect(old_session->netc);
			ctable_insert(session->vnetwork->ctable, session->node_info->uuid, session);
		} else if (strcmp(old_session->ip, session->ip) == 0) {
			net_disconnect(old_session->netc);
			ctable_insert(session->vnetwork->ctable, session->node_info->uuid, session);
		}
	}
*/

	session->cert_name = strdup(certName);
	if (session->netc->security_level == NET_UNSECURE) {

		AuthResponse_set_result(msg, DNDSResult_success);
		net_send_msg(session->netc, msg);

		session->state = SESSION_STATE_AUTHED;
		session->netc->on_secure(session->netc);

	} else {

		AuthResponse_set_result(msg, DNDSResult_secureStepUp);
		net_send_msg(session->netc, msg);

		krypt_add_passport(session->netc->kconn, session->vnetwork->passport);
		session->state = SESSION_STATE_WAIT_STEPUP;
		net_step_up(session->netc);
	}

	DNDSMessage_del(msg);

	return 0;
}
Пример #25
0
void test_SearchResponse()
{
	/// Building a SearchResponse

	DNDSMessage_t *msg;	// A DNDS Message

	DNDSMessage_new(&msg);
	DNDSMessage_set_channel(msg, 0);
	DNDSMessage_set_pdu(msg, pdu_PR_dsm);

	DSMessage_set_seqNumber(msg, 0);
	DSMessage_set_ackNumber(msg, 400);
	DSMessage_set_operation(msg, dsop_PR_searchResponse);

	SearchResponse_set_result(msg, DNDSResult_success);

/// objContext
	DNDSObject_t *objContext;
	DNDSObject_new(&objContext);
	DNDSObject_set_objectType(objContext, DNDSObject_PR_context);

	Context_set_id(objContext, 40);
	SearchResponse_add_object(msg, objContext);

/// Node
	DNDSObject_t *objNode;
	DNDSObject_new(&objNode);
	DNDSObject_set_objectType(objNode, DNDSObject_PR_node);

	Node_set_contextId(objNode, 10);
	Node_set_certificate(objNode, "certificate", 11);
	Node_set_certificateKey(objNode, "key", 3);
	Node_set_status(objNode, 2);

	SearchResponse_add_object(msg, objNode);
/*
/// User1
	DNDSObject_t *objUser1;	// A User Object
	DNDSObject_new(&objUser1);
	DNDSObject_set_objectType(objUser1, DNDSObject_PR_user);

	User_set_id(objUser1, 1);
	User_set_contextId(objUser1, 1);
	User_set_name(objUser1, "1icboul", 7);
	User_set_password(objUser1, "1wd1wd", 6);
	User_set_firstname(objUser1, "1icolas", 7);
	User_set_lastname(objUser1, "1ouliane", 8);
	User_set_email(objUser1, "*****@*****.**", 15);
	User_set_role(objUser1, 0);
	User_set_status(objUser1, 0);

	SearchResponse_add_object(msg, objUser1);

/// User2
	DNDSObject_t *objUser2;	// A User Object
	DNDSObject_new(&objUser2);
	DNDSObject_set_objectType(objUser2, DNDSObject_PR_user);

	User_set_id(objUser2, 2);
	User_set_contextId(objUser2, 2);
	User_set_name(objUser2, "2icboul", 6);
	User_set_password(objUser2, "2wd2wd", 6);
	User_set_firstname(objUser2, "2icolas", 7);
	User_set_lastname(objUser2, "2ouliane", 8);
	User_set_email(objUser2, "*****@*****.**", 15);
	User_set_role(objUser2, 0);
	User_set_status(objUser2, 0);

	SearchResponse_add_object(msg, objUser2);
*/
	/// Encoding part

	asn_enc_rval_t ec;	// Encoder return value
	FILE *fp = fopen("dnds.ber", "wb"); // BER output
	ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp);
	fclose(fp);

	xer_fprint(stdout, &asn_DEF_DNDSMessage, msg);

	DNDSMessage_del(msg);
}