예제 #1
0
static bool write_negTokenTarg(ASN1_DATA *asn1, negTokenTarg_t *token)
{
	asn1_push_tag(asn1, ASN1_CONTEXT(1));
	asn1_push_tag(asn1, ASN1_SEQUENCE(0));

	asn1_push_tag(asn1, ASN1_CONTEXT(0));
	asn1_write_enumerated(asn1, token->negResult);
	asn1_pop_tag(asn1);

	if (token->supportedMech) {
		asn1_push_tag(asn1, ASN1_CONTEXT(1));
		asn1_write_OID(asn1, token->supportedMech);
		asn1_pop_tag(asn1);
	}

	if (token->responseToken.data) {
		asn1_push_tag(asn1, ASN1_CONTEXT(2));
		asn1_write_OctetString(asn1, token->responseToken.data,
				       token->responseToken.length);
		asn1_pop_tag(asn1);
	}

	if (token->mechListMIC.data) {
		asn1_push_tag(asn1, ASN1_CONTEXT(3));
		asn1_write_OctetString(asn1, token->mechListMIC.data,
				      token->mechListMIC.length);
		asn1_pop_tag(asn1);
	}

	asn1_pop_tag(asn1);
	asn1_pop_tag(asn1);

	return !asn1->has_error;
}
예제 #2
0
/*
  generate a minimal SPNEGO response packet.  Doesn't contain much.
*/
DATA_BLOB spnego_gen_auth_response_and_mic(TALLOC_CTX *ctx,
        NTSTATUS nt_status,
        const char *mechOID,
        DATA_BLOB *reply,
        DATA_BLOB *mechlistMIC)
{
    ASN1_DATA *data;
    DATA_BLOB ret;
    uint8 negResult;

    if (NT_STATUS_IS_OK(nt_status)) {
        negResult = SPNEGO_ACCEPT_COMPLETED;
    } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
        negResult = SPNEGO_ACCEPT_INCOMPLETE;
    } else {
        negResult = SPNEGO_REJECT;
    }

    data = asn1_init(talloc_tos());
    if (data == NULL) {
        return data_blob_null;
    }

    asn1_push_tag(data, ASN1_CONTEXT(1));
    asn1_push_tag(data, ASN1_SEQUENCE(0));
    asn1_push_tag(data, ASN1_CONTEXT(0));
    asn1_write_enumerated(data, negResult);
    asn1_pop_tag(data);

    if (mechOID) {
        asn1_push_tag(data,ASN1_CONTEXT(1));
        asn1_write_OID(data, mechOID);
        asn1_pop_tag(data);
    }

    if (reply && reply->data != NULL) {
        asn1_push_tag(data,ASN1_CONTEXT(2));
        asn1_write_OctetString(data, reply->data, reply->length);
        asn1_pop_tag(data);
    }

    if (mechlistMIC && mechlistMIC->data != NULL) {
        asn1_push_tag(data, ASN1_CONTEXT(3));
        asn1_write_OctetString(data,
                               mechlistMIC->data,
                               mechlistMIC->length);
        asn1_pop_tag(data);
    }

    asn1_pop_tag(data);
    asn1_pop_tag(data);

    ret = data_blob_talloc(ctx, data->data, data->length);
    asn1_free(data);
    return ret;
}
예제 #3
0
파일: clispnego.c 프로젝트: hajuuk/R7000
/*
  generate a minimal SPNEGO response packet.  Doesn't contain much.
*/
DATA_BLOB spnego_gen_auth_response(DATA_BLOB *reply, NTSTATUS nt_status,
				   const char *mechOID)
{
	ASN1_DATA data;
	DATA_BLOB ret;
	uint8 negResult;

	if (NT_STATUS_IS_OK(nt_status)) {
		negResult = SPNEGO_NEG_RESULT_ACCEPT;
	} else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
		negResult = SPNEGO_NEG_RESULT_INCOMPLETE; 
	} else {
		negResult = SPNEGO_NEG_RESULT_REJECT; 
	}

	ZERO_STRUCT(data);

	asn1_push_tag(&data, ASN1_CONTEXT(1));
	asn1_push_tag(&data, ASN1_SEQUENCE(0));
	asn1_push_tag(&data, ASN1_CONTEXT(0));
	asn1_write_enumerated(&data, negResult);
	asn1_pop_tag(&data);

	if (reply->data != NULL) {
		asn1_push_tag(&data,ASN1_CONTEXT(1));
		asn1_write_OID(&data, mechOID);
		asn1_pop_tag(&data);
		
		asn1_push_tag(&data,ASN1_CONTEXT(2));
		asn1_write_OctetString(&data, reply->data, reply->length);
		asn1_pop_tag(&data);
	}

	asn1_pop_tag(&data);
	asn1_pop_tag(&data);

	ret = data_blob(data.data, data.length);
	asn1_free(&data);
	return ret;
}
예제 #4
0
파일: spnego_parse.c 프로젝트: gojdic/samba
static bool write_negTokenTarg(struct asn1_data *asn1, struct spnego_negTokenTarg *token)
{
    asn1_push_tag(asn1, ASN1_CONTEXT(1));
    asn1_push_tag(asn1, ASN1_SEQUENCE(0));

    if (token->negResult != SPNEGO_NONE_RESULT) {
        asn1_push_tag(asn1, ASN1_CONTEXT(0));
        asn1_write_enumerated(asn1, token->negResult);
        asn1_pop_tag(asn1);
    }

    if (token->supportedMech) {
        asn1_push_tag(asn1, ASN1_CONTEXT(1));
        asn1_write_OID(asn1, token->supportedMech);
        asn1_pop_tag(asn1);
    }

    if (token->responseToken.data) {
        asn1_push_tag(asn1, ASN1_CONTEXT(2));
        asn1_write_OctetString(asn1, token->responseToken.data,
                               token->responseToken.length);
        asn1_pop_tag(asn1);
    }

    if (token->mechListMIC.data) {
        asn1_push_tag(asn1, ASN1_CONTEXT(3));
        asn1_write_OctetString(asn1, token->mechListMIC.data,
                               token->mechListMIC.length);
        asn1_pop_tag(asn1);
    }

    asn1_pop_tag(asn1);
    asn1_pop_tag(asn1);

    return !asn1->has_error;
}
예제 #5
0
/*
  do a cldap netlogon query
*/
static int send_cldap_netlogon(int sock, const char *domain, 
			       const char *hostname, unsigned ntversion)
{
	ASN1_DATA data;
	char ntver[4];
#ifdef CLDAP_USER_QUERY
	char aac[4];

	SIVAL(aac, 0, 0x00000180);
#endif
	SIVAL(ntver, 0, ntversion);

	memset(&data, 0, sizeof(data));

	asn1_push_tag(&data,ASN1_SEQUENCE(0));
	asn1_write_Integer(&data, 4);
	asn1_push_tag(&data, ASN1_APPLICATION(3));
	asn1_write_OctetString(&data, NULL, 0);
	asn1_write_enumerated(&data, 0);
	asn1_write_enumerated(&data, 0);
	asn1_write_Integer(&data, 0);
	asn1_write_Integer(&data, 0);
	asn1_write_BOOLEAN2(&data, False);
	asn1_push_tag(&data, ASN1_CONTEXT(0));

	if (domain) {
		asn1_push_tag(&data, ASN1_CONTEXT(3));
		asn1_write_OctetString(&data, "DnsDomain", 9);
		asn1_write_OctetString(&data, domain, strlen(domain));
		asn1_pop_tag(&data);
	}

	asn1_push_tag(&data, ASN1_CONTEXT(3));
	asn1_write_OctetString(&data, "Host", 4);
	asn1_write_OctetString(&data, hostname, strlen(hostname));
	asn1_pop_tag(&data);

#ifdef CLDAP_USER_QUERY
	asn1_push_tag(&data, ASN1_CONTEXT(3));
	asn1_write_OctetString(&data, "User", 4);
	asn1_write_OctetString(&data, "SAMBA$", 6);
	asn1_pop_tag(&data);

	asn1_push_tag(&data, ASN1_CONTEXT(3));
	asn1_write_OctetString(&data, "AAC", 4);
	asn1_write_OctetString(&data, aac, 4);
	asn1_pop_tag(&data);
#endif

	asn1_push_tag(&data, ASN1_CONTEXT(3));
	asn1_write_OctetString(&data, "NtVer", 5);
	asn1_write_OctetString(&data, ntver, 4);
	asn1_pop_tag(&data);

	asn1_pop_tag(&data);

	asn1_push_tag(&data,ASN1_SEQUENCE(0));
	asn1_write_OctetString(&data, "NetLogon", 8);
	asn1_pop_tag(&data);
	asn1_pop_tag(&data);
	asn1_pop_tag(&data);

	if (data.has_error) {
		DEBUG(2,("Failed to build cldap netlogon at offset %d\n", (int)data.ofs));
		asn1_free(&data);
		return -1;
	}

	if (write(sock, data.data, data.length) != (ssize_t)data.length) {
		DEBUG(2,("failed to send cldap query (%s)\n", strerror(errno)));
		asn1_free(&data);
		return -1;
	}

	asn1_free(&data);

	return 0;
}